@vitessce/neuroglancer 4.0.0-test.0 → 4.0.0-test.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import React__default from "react";
2
- import { g as getDefaultExportFromCjs, c as commonjsGlobal, d as diffCameraState } from "./index-DZhbMDug.js";
2
+ import { g as getDefaultExportFromCjs, c as commonjsGlobal, d as diffCameraState } from "./index-DslldtW7.js";
3
3
  var es6_object_assign = {};
4
4
  var _global = { exports: {} };
5
5
  var hasRequired_global;
@@ -31538,9 +31538,7 @@ const svg_bin = '<svg role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0
31538
31538
  function makeDeleteButton(options = {}) {
31539
31539
  const icon = makeIcon(_Object$assign({ svg: svg_bin }, options));
31540
31540
  const svg = icon.firstElementChild;
31541
- if (svg) {
31542
- svg.style.fill = "white";
31543
- }
31541
+ if (svg) svg.style.fill = "white";
31544
31542
  return icon;
31545
31543
  }
31546
31544
  var es6_string_raw = {};
@@ -47185,6 +47183,18 @@ class DataManagementContext extends RefCounted {
47185
47183
  this.frameNumberCounter = frameNumberCounter;
47186
47184
  const chunk_worker_url = bundleRoot + "chunk_worker.bundle.js";
47187
47185
  this.worker = typeof bundleRoot === "string" ? new Worker(chunk_worker_url) : bundleRoot;
47186
+ if (typeof bundleRoot !== "string") {
47187
+ this.worker.addEventListener("message", (msg) => {
47188
+ if (msg.data?.functionName === "Worker" && msg.data?.path === "async_computation.bundle.js") {
47189
+ msg.stopImmediatePropagation();
47190
+ const AsyncWorker = bundleRoot.AsyncComputationWorker;
47191
+ if (AsyncWorker) {
47192
+ const asyncWorker = new AsyncWorker();
47193
+ asyncWorker.postMessage({ port: msg.data.port }, [msg.data.port]);
47194
+ }
47195
+ }
47196
+ }, true);
47197
+ }
47188
47198
  this.chunkQueueManager = this.registerDisposer(new ChunkQueueManager(new RPC(this.worker), this.gl, this.frameNumberCounter, {
47189
47199
  gpuMemory: new CapacitySpecification({ defaultItemLimit: 1e6, defaultSizeLimit: 1e9 }),
47190
47200
  systemMemory: new CapacitySpecification({ defaultItemLimit: 1e7, defaultSizeLimit: 2e9 }),
@@ -66836,6 +66846,7 @@ class Neuroglancer extends React__default.Component {
66836
66846
  onVisibleChanged: null,
66837
66847
  onSelectionDetailsStateChanged: null,
66838
66848
  onViewerStateChanged: null,
66849
+ onLayerLoadingChange: null,
66839
66850
  key: null,
66840
66851
  callbacks: [],
66841
66852
  ngServer: "https://neuroglancer-demo.appspot.com/"
@@ -66850,7 +66861,7 @@ class Neuroglancer extends React__default.Component {
66850
66861
  this.disposers = [];
66851
66862
  this.prevColorOverrides = /* @__PURE__ */ new Set();
66852
66863
  this.overrideColorsById = /* @__PURE__ */ Object.create(null);
66853
- this.allKnownIds = /* @__PURE__ */ new Set();
66864
+ this.allKnownIdsByLayer = {};
66854
66865
  }
66855
66866
  minimalPoseSnapshot = () => {
66856
66867
  const v = this.viewer;
@@ -66897,21 +66908,24 @@ class Neuroglancer extends React__default.Component {
66897
66908
  return JSON.stringify(prevLayers) !== JSON.stringify(nextLayers);
66898
66909
  };
66899
66910
  /* To add colors to the segments, turning unselected to grey */
66900
- applyColorsAndVisibility = (cellColorMapping) => {
66911
+ applyColorsAndVisibility = (cellColorMappingByLayer) => {
66901
66912
  if (!this.viewer) return;
66902
- const selected = { ...cellColorMapping || {} };
66903
- for (const id of Object.keys(selected)) this.allKnownIds.add(id);
66904
- if (this.allKnownIds.size === 0) {
66905
- const init = this.props.viewerState?.layers?.[0]?.segmentColors || {};
66906
- for (const id of Object.keys(init)) this.allKnownIds.add(id);
66907
- }
66908
- const fullSegmentColors = {};
66909
- for (const id of this.allKnownIds) {
66910
- fullSegmentColors[id] = selected[id] || GREY_HEX;
66911
- }
66912
66913
  const baseLayers = this.props.viewerState?.layers ?? (this.viewer.state.toJSON().layers || []);
66913
- const newLayers = baseLayers.map((layer, idx) => {
66914
- if (idx === 0 || layer?.type === "segmentation") {
66914
+ const newLayers = baseLayers.map((layer) => {
66915
+ const layerScope = Object.keys(cellColorMappingByLayer).find((scope) => layer.name?.includes(scope));
66916
+ const selected = { ...cellColorMappingByLayer[layerScope]?.colors || {} };
66917
+ if (!this.allKnownIdsByLayer) this.allKnownIdsByLayer = {};
66918
+ if (!this.allKnownIdsByLayer[layerScope]) {
66919
+ this.allKnownIdsByLayer[layerScope] = /* @__PURE__ */ new Set();
66920
+ }
66921
+ for (const id of Object.keys(selected)) {
66922
+ this.allKnownIdsByLayer[layerScope].add(id);
66923
+ }
66924
+ const fullSegmentColors = {};
66925
+ for (const id of this.allKnownIdsByLayer[layerScope] || []) {
66926
+ fullSegmentColors[id] = selected[id] || GREY_HEX;
66927
+ }
66928
+ if (layer.type === "segmentation") {
66915
66929
  return { ...layer, segmentColors: fullSegmentColors };
66916
66930
  }
66917
66931
  return layer;
@@ -66960,9 +66974,39 @@ class Neuroglancer extends React__default.Component {
66960
66974
  } else {
66961
66975
  viewerNoKey = this.viewer;
66962
66976
  }
66977
+ const { visibleChunksChanged } = this.viewer.chunkQueueManager;
66978
+ let firstChunkLoaded = false;
66979
+ this.disposers.push(visibleChunksChanged.add(() => {
66980
+ if (!firstChunkLoaded) {
66981
+ for (const layer of this.viewer.layerManager.managedLayers) {
66982
+ if (layer.layer instanceof SegmentationUserLayer) {
66983
+ const hasVisibleChunk = layer.layer.renderLayers?.some((rl) => {
66984
+ const {
66985
+ numVisibleChunksAvailable,
66986
+ numVisibleChunksNeeded
66987
+ } = rl.layerChunkProgressInfo || {};
66988
+ if (!numVisibleChunksNeeded || !numVisibleChunksAvailable) return false;
66989
+ return numVisibleChunksAvailable / numVisibleChunksNeeded > 0.25;
66990
+ });
66991
+ if (hasVisibleChunk) {
66992
+ firstChunkLoaded = true;
66993
+ requestAnimationFrame(() => {
66994
+ requestAnimationFrame(() => {
66995
+ this.props.onLayerLoadingChange?.(true);
66996
+ });
66997
+ });
66998
+ return;
66999
+ }
67000
+ }
67001
+ }
67002
+ }
67003
+ }));
67004
+ this.disposers.push(() => {
67005
+ firstChunkLoaded = false;
67006
+ });
66963
67007
  }
66964
67008
  componentDidUpdate(prevProps, prevState) {
66965
- const { viewerState, cellColorMapping } = this.props;
67009
+ const { viewerState, cellColorMapping: cellColorMappingByLayer } = this.props;
66966
67010
  const selectedSegments = {};
66967
67011
  for (const layer of this.viewer.layerManager.managedLayers) {
66968
67012
  if (layer.layer instanceof SegmentationUserLayer) {
@@ -66974,6 +67018,24 @@ class Neuroglancer extends React__default.Component {
66974
67018
  if (layer.layer instanceof SegmentationUserLayer) {
66975
67019
  const { segmentSelectionState } = layer.layer.displayState;
66976
67020
  segmentSelectionState.set(selectedSegments[layer.name]);
67021
+ const layerScope = Object.keys(cellColorMappingByLayer).find(
67022
+ (scope) => layer.name?.includes(scope)
67023
+ );
67024
+ if (layerScope) {
67025
+ const opacity = cellColorMappingByLayer[layerScope]?.opacity ?? 1;
67026
+ layer.layer.displayState.objectAlpha.value = opacity;
67027
+ }
67028
+ }
67029
+ if (layer.layer instanceof AnnotationUserLayer) {
67030
+ const matchingLayer = (viewerState?.layers || []).find(
67031
+ (l) => l.name === layer.name
67032
+ );
67033
+ if (matchingLayer?.shader) {
67034
+ const currentShader = layer.layer.annotationDisplayState.shader.value_;
67035
+ if (currentShader !== matchingLayer.shader) {
67036
+ layer.layer.annotationDisplayState.shader.value = matchingLayer.shader;
67037
+ }
67038
+ }
66977
67039
  }
66978
67040
  }
66979
67041
  if (!viewerState) return;
@@ -66994,22 +67056,22 @@ class Neuroglancer extends React__default.Component {
66994
67056
  this.withoutEmitting(() => {
66995
67057
  const layers = Array.isArray(viewerState.layers) ? viewerState.layers : [];
66996
67058
  this.viewer.state.restoreState({ layers });
66997
- if (cellColorMapping && Object.keys(cellColorMapping).length) {
66998
- this.applyColorsAndVisibility(cellColorMapping);
67059
+ if (cellColorMappingByLayer && Object.keys(cellColorMappingByLayer).length) {
67060
+ this.applyColorsAndVisibility(cellColorMappingByLayer);
66999
67061
  }
67000
67062
  });
67001
67063
  }
67002
- const prevSize = prevProps.cellColorMapping ? Object.keys(prevProps.cellColorMapping).length : 0;
67003
- const currSize = cellColorMapping ? Object.keys(cellColorMapping).length : 0;
67004
- const mappingRefChanged = prevProps.cellColorMapping !== cellColorMapping;
67064
+ const prevSize = prevProps.cellColorMapping ? Object.values(prevProps.cellColorMapping).reduce((acc, v) => acc + Object.keys(v?.colors || {}).length, 0) : 0;
67065
+ const currSize = cellColorMappingByLayer ? Object.values(cellColorMappingByLayer).reduce((acc, v) => acc + Object.keys(v?.colors || {}).length, 0) : 0;
67066
+ const mappingRefChanged = prevProps.cellColorMapping !== this.props.cellColorMapping;
67005
67067
  if (!this.didLayersChange(prevVS, viewerState) && (mappingRefChanged || prevSize !== currSize)) {
67006
67068
  this.withoutEmitting(() => {
67007
- this.applyColorsAndVisibility(cellColorMapping);
67069
+ this.applyColorsAndVisibility(cellColorMappingByLayer);
67008
67070
  });
67009
67071
  }
67010
67072
  const stripSegFields = (layers) => (layers || []).map((l) => {
67011
67073
  if (!l) return l;
67012
- const { segments, segmentColors, ...rest } = l;
67074
+ const { segments, segmentColors, objectAlpha, ...rest } = l;
67013
67075
  return rest;
67014
67076
  });
67015
67077
  const prevLayers = prevProps.viewerState?.layers;