Skip to content

Commit

Permalink
Use Pick where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Jan 30, 2024
1 parent c24d6e4 commit d56dcd2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/NiivueCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const NiivueCanvas: React.FC<NiivueCanvasProps> = ({
setup().then(() => setReady(true));
}, []);

return (<canvas ref={canvasRef} />);
return <canvas ref={canvasRef} />;
};

export type { NiivueCanvasProps };
Expand Down
46 changes: 17 additions & 29 deletions src/model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NiiVueOptions } from "./reexport.ts";
import { Niivue, NVImage, NVMeshFromUrlOptions } from "@niivue/niivue";

type HasUrlObject = { [key: string]: any; url: string };

Expand All @@ -21,46 +22,33 @@ type NVRMeshLayer = {
/**
* A mesh (e.g. white-matter surface) in Niivue.
*/
type NVRMesh = {
url: string;
name?: string;
opacity?: number;
visible?: boolean;
rgba255?: number[];
/**
* Map keys must be some kind of unique ID. For example, given `NVRMeshLayer[]`:
*
* ```typescript
* (layers: NVRMeshLayer[]) => Object.fromEntries(layers.map((layer) => [layer.url, layer]))
* ```
*/
layers?: { [key: string]: NVRMeshLayer };
colorbarVisible?: boolean;
};
type NVRMesh = { url: string } & Pick<
NVMeshFromUrlOptions,
"name" | "opacity" | "visible" | "rgba255" | "colorbarVisible"
>;

/**
* Options of a volume which are directly compatible with `ImageFromUrlOptions` and `NVImage`, meaning:
*
* - properties are supported by `Niivue.loadVolumes`
* - properties can be changed by mutating `nv.volumes[*].*`
*/
type LoadableVolumeOptions = {
opacity?: number;
colormap?: string;
colormapNegative?: string;
cal_min?: number;
cal_max?: number;
trustCalMinMax?: boolean;
visible?: boolean;
colorbarVisible?: boolean;
};
type LoadableVolumeOptions = Pick<
NVImage,
| "opacity"
| "colormap"
| "colormapNegative"
| "cal_min"
| "cal_max"
| "trustCalMinMax"
| "visible"
| "colorbarVisible"
>;

/**
* Options of a volume which are directly compatible with `NVImage`.
*/
type ImageOptions = LoadableVolumeOptions & {
modulateAlpha?: number;
};
type ImageOptions = LoadableVolumeOptions & Pick<NVImage, "modulateAlpha">;

/**
* Special options of a volume which are supported handled differently in `niivue-react` and Niivue,
Expand Down
4 changes: 2 additions & 2 deletions src/reexport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Type definitions copy-pasted from `niivue` since they are not public.
*/

import {DRAG_MODE, SLICE_TYPE} from "@niivue/niivue";
import { DRAG_MODE, SLICE_TYPE } from "@niivue/niivue";

/**
* Niivue options.
Expand Down Expand Up @@ -99,7 +99,7 @@ type NiiVueOptions = {
thumbnail?: string;

// from NVConfigOptions
sliceType?: SLICE_TYPE
sliceType?: SLICE_TYPE;
};

export type { NiiVueOptions };
2 changes: 1 addition & 1 deletion src/setters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function optionUpdateFunctionMap(nv: Niivue): OptionUpdateFunctionMap {
crosshairWidth: nv.setCrosshairWidth,
crosshairColor: nv.setCrosshairColor,
sliceType: nv.setSliceType,
isSliceMM: nv.setSliceMM
isSliceMM: nv.setSliceMM,
};
return bindAllValues(nv, mapping);
}
Expand Down

0 comments on commit d56dcd2

Please sign in to comment.