Skip to content

Commit d01d018

Browse files
refactor!: rename _meshes and _volumes, remove id
meshes and volumes attributes are now public. This is a breaking change; accessing `nv._meshes` and `nv._volumes` will no longer work. Additionally, the useless NiiVue.id attribute has been removed. The NiiVue JS lib doesn't have an id for each NiiVue object so this mirrors NiiVue's structure.
1 parent 9779e5c commit d01d018

File tree

6 files changed

+14
-30
lines changed

6 files changed

+14
-30
lines changed

examples/basic_multiplanar.ipynb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@
8686
"nv.opts.view_mode_hot_key = \"KeyN\""
8787
]
8888
},
89-
{
90-
"cell_type": "code",
91-
"execution_count": null,
92-
"metadata": {},
93-
"outputs": [],
94-
"source": [
95-
"nv.id"
96-
]
97-
},
9889
{
9990
"cell_type": "code",
10091
"execution_count": null,

examples/colormaps.ipynb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@
345345
"# Display for prints\n",
346346
"display(out)"
347347
]
348+
},
349+
{
350+
"cell_type": "code",
351+
"execution_count": null,
352+
"id": "339bc7d4-7138-4a66-a4f2-b473492bad54",
353+
"metadata": {},
354+
"outputs": [],
355+
"source": [
356+
"nv"
357+
]
348358
}
349359
],
350360
"metadata": {},

examples/mosaic.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
"nvols = nib.load(example4d).shape[-1]\n",
296296
"init_cols = np.ceil(np.sqrt(nib.load(example4d).shape[2]))\n",
297297
"\n",
298-
"nv3.slice_mosaic_string = full_mosaic(coords4d, ncols=init_cols)\n",
298+
"nv3.opts.slice_mosaic_string = full_mosaic(coords4d, ncols=init_cols)\n",
299299
"\n",
300300
"column_slider4d = widgets.IntSlider(\n",
301301
" min=0, max=20, value=init_cols, description=\"Columns\"\n",
@@ -307,7 +307,7 @@
307307
"def update_mosaic4d(*args):\n",
308308
" \"\"\"Update mosaic string.\"\"\"\n",
309309
" nv3.volumes[0].frame4D = vol_slider4d.value\n",
310-
" nv3.slice_mosaic_string = full_mosaic(coords4d, ncols=column_slider4d.value)\n",
310+
" nv3.opts.slice_mosaic_string = full_mosaic(coords4d, ncols=column_slider4d.value)\n",
311311
"\n",
312312
"\n",
313313
"def update_view4d(*args):\n",

js/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export type MeshLayerModel = AnyModel<{
7878
}>;
7979

8080
export type Model = AnyModel<{
81-
id: string;
8281
height: number;
8382
volumes: Array<string>;
8483
meshes: Array<string>;

js/widget.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
} from "./types.ts";
1212
import { render_volumes } from "./volume.ts";
1313

14-
const nvMap = new Map<string, niivue.Niivue>();
14+
let nv: niivue.Niivue;
1515

1616
function deserializeOptions(
1717
options: Partial<Record<keyof niivue.NVConfigOptions, unknown>>,
@@ -518,18 +518,13 @@ function attachCanvasEventHandlers(nv: niivue.Niivue, model: Model) {
518518

519519
export default {
520520
async initialize({ model }: { model: Model }) {
521-
const id = model.get("id");
522-
console.log("Initializing called on model:", id);
523521
const disposer = new Disposer();
524522

525-
let nv = nvMap.get(model.get("id"));
526-
527523
if (!nv) {
528524
console.log("Creating new Niivue instance");
529525
const serializedOpts = model.get("opts") ?? {};
530526
const opts = deserializeOptions(serializedOpts);
531527
nv = new niivue.Niivue(opts);
532-
nvMap.set(model.get("id"), nv);
533528
}
534529

535530
// Attach model event handlers
@@ -553,15 +548,11 @@ export default {
553548
model.off("change:draw_lut");
554549
model.off("change:draw_opacity");
555550
model.off("change:change:draw_fill_overwrites");
556-
557-
// remove the nv instance
558-
nvMap.delete(model.get("id"));
559551
};
560552
},
561553
async render({ model, el }: { model: Model; el: HTMLElement }) {
562-
const nv = nvMap.get(model.get("id"));
563554
if (!nv) {
564-
console.error("Niivue instance not found for model", model.get("id"));
555+
console.error("Niivue instance not found for model", model);
565556
return;
566557
}
567558

src/ipyniivue/widget.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import math
1313
import pathlib
1414
import typing
15-
import uuid
1615
import warnings
1716

1817
import anywidget
@@ -331,8 +330,6 @@ class NiiVue(anywidget.AnyWidget):
331330

332331
_esm = pathlib.Path(__file__).parent / "static" / "widget.js"
333332

334-
id = t.Unicode(read_only=True).tag(sync=True)
335-
336333
height = t.Int().tag(sync=True)
337334
opts = t.Instance(ConfigOptions).tag(
338335
sync=True, to_json=serialize_options, from_json=deserialize_options
@@ -357,10 +354,6 @@ class NiiVue(anywidget.AnyWidget):
357354
draw_opacity = t.Float(0.8).tag(sync=True)
358355
draw_fill_overwrites = t.Bool(True).tag(sync=True)
359356

360-
@t.default("id")
361-
def _default_id(self):
362-
return str(uuid.uuid4())
363-
364357
def __init__(self, height: int = 300, **options): # noqa: D417
365358
r"""
366359
Initialize the NiiVue widget.

0 commit comments

Comments
 (0)