@haniffalab/cherita-react 1.3.0-dev.2025-06-06.9f7ff5ad → 1.3.0-dev.2025-06-06.7dfb207c

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.
@@ -155,8 +155,12 @@ function CategoricalItem(_ref) {
155
155
  pct: null
156
156
  },
157
157
  isSliced,
158
+ colors = null,
158
159
  showColor = true
159
160
  } = _ref;
161
+ const {
162
+ useUnsColors
163
+ } = (0, _DatasetContext.useDataset)();
160
164
  const {
161
165
  getColor
162
166
  } = (0, _colorHelper.useColor)();
@@ -241,7 +245,7 @@ function CategoricalItem(_ref) {
241
245
  y: "0",
242
246
  width: "10",
243
247
  height: "10",
244
- fill: "rgb(".concat(getColor({
248
+ fill: "rgb(".concat(getColor(_objectSpread({
245
249
  value: (code - min) / (max - min),
246
250
  categorical: true,
247
251
  grayOut: isOmitted,
@@ -249,7 +253,9 @@ function CategoricalItem(_ref) {
249
253
  alpha: 1
250
254
  },
251
255
  colorEncoding: "obs"
252
- }), ")")
256
+ }, useUnsColors ? {
257
+ colorscale: colors
258
+ } : {})), ")")
253
259
  }))) : null))));
254
260
  }
255
261
  function CategoricalObs(_ref2) {
@@ -291,9 +297,10 @@ function CategoricalObs(_ref2) {
291
297
  value_counts: (filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.value_counts[obs.values[index]]) || 0,
292
298
  pct: (filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.pct[obs.values[index]]) || 0
293
299
  },
294
- isSliced: isSliced
300
+ isSliced: isSliced,
301
+ colors: obs.colors
295
302
  };
296
- }, [settings.colorEncoding, filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.pct, filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.value_counts, isSliced, obs.codes, obs.omit, obs.value_counts, obs.values, obsHistograms.fetchedData, obsHistograms.isPending, totalCounts]);
303
+ }, [obs.values, obs.codes, obs.value_counts, obs.omit, obs.colors, totalCounts, settings.colorEncoding, obsHistograms.fetchedData, obsHistograms.isPending, isSliced, filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.value_counts, filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.pct]);
297
304
  showColor &= settings.colorEncoding === _constants.COLOR_ENCODINGS.OBS;
298
305
  return /*#__PURE__*/_react.default.createElement(_reactBootstrap.ListGroup, {
299
306
  variant: "flush",
@@ -16,6 +16,7 @@ var _reactBootstrap = require("react-bootstrap");
16
16
  var _SpatialControls = require("./SpatialControls");
17
17
  var _Toolbox = require("./Toolbox");
18
18
  var _constants = require("../../constants/constants");
19
+ var _DatasetContext = require("../../context/DatasetContext");
19
20
  var _FilterContext = require("../../context/FilterContext");
20
21
  var _SettingsContext = require("../../context/SettingsContext");
21
22
  var _ZarrDataContext = require("../../context/ZarrDataContext");
@@ -42,13 +43,16 @@ const INITIAL_VIEW_STATE = {
42
43
  bearing: 0
43
44
  };
44
45
  function Scatterplot(_ref) {
45
- var _settings$selectedObs2, _settings$selectedObs5, _features$features2, _obsmData$serverError, _xData$serverError, _obsData$serverError, _labelObsData$serverE, _settings$selectedVar, _settings$selectedObs6, _data$positions;
46
+ var _settings$selectedObs2, _settings$selectedObs5, _settings$selectedObs8, _features$features2, _obsmData$serverError, _xData$serverError, _obsData$serverError, _labelObsData$serverE, _settings$selectedVar, _settings$selectedObs9, _data$positions;
46
47
  let {
47
48
  radius = null,
48
49
  setShowObs,
49
50
  setShowVars,
50
51
  isFullscreen = false
51
52
  } = _ref;
53
+ const {
54
+ useUnsColors
55
+ } = (0, _DatasetContext.useDataset)();
52
56
  const settings = (0, _SettingsContext.useSettings)();
53
57
  const {
54
58
  obsIndices,
@@ -69,6 +73,7 @@ function Scatterplot(_ref) {
69
73
  positions: [],
70
74
  values: []
71
75
  });
76
+ const [coordsError, setCoordsError] = (0, _react.useState)(null);
72
77
 
73
78
  // EditableGeoJsonLayer
74
79
  const [mode, setMode] = (0, _react.useState)(() => _editModes.ViewMode);
@@ -106,8 +111,22 @@ function Scatterplot(_ref) {
106
111
  } else if (settings.colorEncoding === _constants.COLOR_ENCODINGS.OBS) {
107
112
  values = !obsData.serverError ? obsData.data : values;
108
113
  }
114
+ if (!obsmData.serverError && obsmData.data) {
115
+ if (obsmData.data[0].length !== 2) {
116
+ setCoordsError("Invalid coordinates. Expected 2D coordinates");
117
+ return {
118
+ positions: [],
119
+ values: []
120
+ };
121
+ }
122
+ setCoordsError(null);
123
+ return {
124
+ positions: obsmData.data,
125
+ values: values
126
+ };
127
+ }
109
128
  return {
110
- positions: !obsmData.serverError ? obsmData.data : d.positions,
129
+ positions: d.positions,
111
130
  values: values
112
131
  };
113
132
  });
@@ -207,16 +226,19 @@ function Scatterplot(_ref) {
207
226
  max: settings.controls.range[1] * (valueMax - valueMin) + valueMin
208
227
  };
209
228
  const getFillColor = (0, _react.useCallback)((_d, _ref2) => {
229
+ var _settings$selectedObs6, _settings$selectedObs7;
210
230
  let {
211
231
  index
212
232
  } = _ref2;
213
233
  const grayOut = isPending || sortedObsIndices && !sortedObsIndices.has(index);
214
- return getColor({
234
+ return getColor(_objectSpread({
215
235
  value: (sortedData.values[index] - min) / (max - min),
216
236
  categorical: isCategorical,
217
237
  grayOut: grayOut
218
- }) || [0, 0, 0, 100];
219
- }, [isPending, sortedObsIndices, getColor, sortedData.values, min, max, isCategorical]);
238
+ }, useUnsColors && settings.colorEncoding === _constants.COLOR_ENCODINGS.OBS && (_settings$selectedObs6 = settings.selectedObs) !== null && _settings$selectedObs6 !== void 0 && _settings$selectedObs6.colors ? {
239
+ colorscale: (_settings$selectedObs7 = settings.selectedObs) === null || _settings$selectedObs7 === void 0 ? void 0 : _settings$selectedObs7.colors
240
+ } : {})) || [0, 0, 0, 100];
241
+ }, [isPending, sortedObsIndices, getColor, sortedData.values, min, max, isCategorical, useUnsColors, settings.colorEncoding, (_settings$selectedObs8 = settings.selectedObs) === null || _settings$selectedObs8 === void 0 ? void 0 : _settings$selectedObs8.colors]);
220
242
 
221
243
  // @TODO: add support for pseudospatial hover to reflect in radius
222
244
  const getRadius = (0, _react.useCallback)((_d, _ref3) => {
@@ -344,7 +366,7 @@ function Scatterplot(_ref) {
344
366
  }
345
367
  };
346
368
  };
347
- const error = settings.selectedObsm && ((_obsmData$serverError = obsmData.serverError) === null || _obsmData$serverError === void 0 ? void 0 : _obsmData$serverError.length) || settings.colorEncoding === _constants.COLOR_ENCODINGS.VAR && ((_xData$serverError = xData.serverError) === null || _xData$serverError === void 0 ? void 0 : _xData$serverError.length) || settings.colorEncoding === _constants.COLOR_ENCODINGS.OBS && ((_obsData$serverError = obsData.serverError) === null || _obsData$serverError === void 0 ? void 0 : _obsData$serverError.length) || settings.labelObs.length && ((_labelObsData$serverE = labelObsData.serverError) === null || _labelObsData$serverE === void 0 ? void 0 : _labelObsData$serverE.length);
369
+ const error = settings.selectedObsm && ((_obsmData$serverError = obsmData.serverError) === null || _obsmData$serverError === void 0 ? void 0 : _obsmData$serverError.length) || settings.colorEncoding === _constants.COLOR_ENCODINGS.VAR && ((_xData$serverError = xData.serverError) === null || _xData$serverError === void 0 ? void 0 : _xData$serverError.length) || settings.colorEncoding === _constants.COLOR_ENCODINGS.OBS && ((_obsData$serverError = obsData.serverError) === null || _obsData$serverError === void 0 ? void 0 : _obsData$serverError.length) || settings.labelObs.length && ((_labelObsData$serverE = labelObsData.serverError) === null || _labelObsData$serverE === void 0 ? void 0 : _labelObsData$serverE.length) || coordsError;
348
370
  return /*#__PURE__*/_react.default.createElement("div", {
349
371
  className: "cherita-container-scatterplot"
350
372
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -396,7 +418,7 @@ function Scatterplot(_ref) {
396
418
  }, /*#__PURE__*/_react.default.createElement(_reactFontawesome.FontAwesomeIcon, {
397
419
  icon: _freeSolidSvgIcons.faTriangleExclamation
398
420
  }), "\xA0Error loading data"), /*#__PURE__*/_react.default.createElement(_Toolbox.Toolbox, {
399
- mode: settings.colorEncoding === _constants.COLOR_ENCODINGS.VAR ? (_settings$selectedVar = settings.selectedVar) === null || _settings$selectedVar === void 0 ? void 0 : _settings$selectedVar.name : settings.colorEncoding === _constants.COLOR_ENCODINGS.OBS ? (_settings$selectedObs6 = settings.selectedObs) === null || _settings$selectedObs6 === void 0 ? void 0 : _settings$selectedObs6.name : null,
421
+ mode: settings.colorEncoding === _constants.COLOR_ENCODINGS.VAR ? (_settings$selectedVar = settings.selectedVar) === null || _settings$selectedVar === void 0 ? void 0 : _settings$selectedVar.name : settings.colorEncoding === _constants.COLOR_ENCODINGS.OBS ? (_settings$selectedObs9 = settings.selectedObs) === null || _settings$selectedObs9 === void 0 ? void 0 : _settings$selectedObs9.name : null,
400
422
  obsLength: parseInt((_data$positions = data.positions) === null || _data$positions === void 0 ? void 0 : _data$positions.length),
401
423
  slicedLength: parseInt(slicedLength)
402
424
  })), /*#__PURE__*/_react.default.createElement(_Legend.Legend, {
@@ -69,7 +69,8 @@ const initialDataset = {
69
69
  obsGroups: null,
70
70
  imageUrl: null,
71
71
  defaultSettings: {},
72
- canOverrideSettings: true
72
+ canOverrideSettings: true,
73
+ useUnsColors: false
73
74
  };
74
75
  function DatasetProvider(_ref2) {
75
76
  let {
@@ -147,8 +147,12 @@ function CategoricalItem(_ref) {
147
147
  pct: null
148
148
  },
149
149
  isSliced,
150
+ colors = null,
150
151
  showColor = true
151
152
  } = _ref;
153
+ const {
154
+ useUnsColors
155
+ } = useDataset();
152
156
  const {
153
157
  getColor
154
158
  } = useColor();
@@ -233,7 +237,7 @@ function CategoricalItem(_ref) {
233
237
  y: "0",
234
238
  width: "10",
235
239
  height: "10",
236
- fill: "rgb(".concat(getColor({
240
+ fill: "rgb(".concat(getColor(_objectSpread({
237
241
  value: (code - min) / (max - min),
238
242
  categorical: true,
239
243
  grayOut: isOmitted,
@@ -241,7 +245,9 @@ function CategoricalItem(_ref) {
241
245
  alpha: 1
242
246
  },
243
247
  colorEncoding: "obs"
244
- }), ")")
248
+ }, useUnsColors ? {
249
+ colorscale: colors
250
+ } : {})), ")")
245
251
  }))) : null))));
246
252
  }
247
253
  export function CategoricalObs(_ref2) {
@@ -283,9 +289,10 @@ export function CategoricalObs(_ref2) {
283
289
  value_counts: (filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.value_counts[obs.values[index]]) || 0,
284
290
  pct: (filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.pct[obs.values[index]]) || 0
285
291
  },
286
- isSliced: isSliced
292
+ isSliced: isSliced,
293
+ colors: obs.colors
287
294
  };
288
- }, [settings.colorEncoding, filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.pct, filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.value_counts, isSliced, obs.codes, obs.omit, obs.value_counts, obs.values, obsHistograms.fetchedData, obsHistograms.isPending, totalCounts]);
295
+ }, [obs.values, obs.codes, obs.value_counts, obs.omit, obs.colors, totalCounts, settings.colorEncoding, obsHistograms.fetchedData, obsHistograms.isPending, isSliced, filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.value_counts, filteredObsData === null || filteredObsData === void 0 ? void 0 : filteredObsData.pct]);
289
296
  showColor &= settings.colorEncoding === COLOR_ENCODINGS.OBS;
290
297
  return /*#__PURE__*/React.createElement(ListGroup, {
291
298
  variant: "flush",
@@ -15,6 +15,7 @@ import { Alert } from "react-bootstrap";
15
15
  import { SpatialControls } from "./SpatialControls";
16
16
  import { Toolbox } from "./Toolbox";
17
17
  import { COLOR_ENCODINGS, OBS_TYPES, SELECTED_POLYGON_FILLCOLOR, UNSELECTED_POLYGON_FILLCOLOR } from "../../constants/constants";
18
+ import { useDataset } from "../../context/DatasetContext";
18
19
  import { useFilteredData } from "../../context/FilterContext";
19
20
  import { useSettings, useSettingsDispatch } from "../../context/SettingsContext";
20
21
  import { useZarrData } from "../../context/ZarrDataContext";
@@ -34,13 +35,16 @@ const INITIAL_VIEW_STATE = {
34
35
  bearing: 0
35
36
  };
36
37
  export function Scatterplot(_ref) {
37
- var _settings$selectedObs2, _settings$selectedObs5, _features$features2, _obsmData$serverError, _xData$serverError, _obsData$serverError, _labelObsData$serverE, _settings$selectedVar, _settings$selectedObs6, _data$positions;
38
+ var _settings$selectedObs2, _settings$selectedObs5, _settings$selectedObs8, _features$features2, _obsmData$serverError, _xData$serverError, _obsData$serverError, _labelObsData$serverE, _settings$selectedVar, _settings$selectedObs9, _data$positions;
38
39
  let {
39
40
  radius = null,
40
41
  setShowObs,
41
42
  setShowVars,
42
43
  isFullscreen = false
43
44
  } = _ref;
45
+ const {
46
+ useUnsColors
47
+ } = useDataset();
44
48
  const settings = useSettings();
45
49
  const {
46
50
  obsIndices,
@@ -61,6 +65,7 @@ export function Scatterplot(_ref) {
61
65
  positions: [],
62
66
  values: []
63
67
  });
68
+ const [coordsError, setCoordsError] = useState(null);
64
69
 
65
70
  // EditableGeoJsonLayer
66
71
  const [mode, setMode] = useState(() => ViewMode);
@@ -98,8 +103,22 @@ export function Scatterplot(_ref) {
98
103
  } else if (settings.colorEncoding === COLOR_ENCODINGS.OBS) {
99
104
  values = !obsData.serverError ? obsData.data : values;
100
105
  }
106
+ if (!obsmData.serverError && obsmData.data) {
107
+ if (obsmData.data[0].length !== 2) {
108
+ setCoordsError("Invalid coordinates. Expected 2D coordinates");
109
+ return {
110
+ positions: [],
111
+ values: []
112
+ };
113
+ }
114
+ setCoordsError(null);
115
+ return {
116
+ positions: obsmData.data,
117
+ values: values
118
+ };
119
+ }
101
120
  return {
102
- positions: !obsmData.serverError ? obsmData.data : d.positions,
121
+ positions: d.positions,
103
122
  values: values
104
123
  };
105
124
  });
@@ -199,16 +218,19 @@ export function Scatterplot(_ref) {
199
218
  max: settings.controls.range[1] * (valueMax - valueMin) + valueMin
200
219
  };
201
220
  const getFillColor = useCallback((_d, _ref2) => {
221
+ var _settings$selectedObs6, _settings$selectedObs7;
202
222
  let {
203
223
  index
204
224
  } = _ref2;
205
225
  const grayOut = isPending || sortedObsIndices && !sortedObsIndices.has(index);
206
- return getColor({
226
+ return getColor(_objectSpread({
207
227
  value: (sortedData.values[index] - min) / (max - min),
208
228
  categorical: isCategorical,
209
229
  grayOut: grayOut
210
- }) || [0, 0, 0, 100];
211
- }, [isPending, sortedObsIndices, getColor, sortedData.values, min, max, isCategorical]);
230
+ }, useUnsColors && settings.colorEncoding === COLOR_ENCODINGS.OBS && (_settings$selectedObs6 = settings.selectedObs) !== null && _settings$selectedObs6 !== void 0 && _settings$selectedObs6.colors ? {
231
+ colorscale: (_settings$selectedObs7 = settings.selectedObs) === null || _settings$selectedObs7 === void 0 ? void 0 : _settings$selectedObs7.colors
232
+ } : {})) || [0, 0, 0, 100];
233
+ }, [isPending, sortedObsIndices, getColor, sortedData.values, min, max, isCategorical, useUnsColors, settings.colorEncoding, (_settings$selectedObs8 = settings.selectedObs) === null || _settings$selectedObs8 === void 0 ? void 0 : _settings$selectedObs8.colors]);
212
234
 
213
235
  // @TODO: add support for pseudospatial hover to reflect in radius
214
236
  const getRadius = useCallback((_d, _ref3) => {
@@ -336,7 +358,7 @@ export function Scatterplot(_ref) {
336
358
  }
337
359
  };
338
360
  };
339
- const error = settings.selectedObsm && ((_obsmData$serverError = obsmData.serverError) === null || _obsmData$serverError === void 0 ? void 0 : _obsmData$serverError.length) || settings.colorEncoding === COLOR_ENCODINGS.VAR && ((_xData$serverError = xData.serverError) === null || _xData$serverError === void 0 ? void 0 : _xData$serverError.length) || settings.colorEncoding === COLOR_ENCODINGS.OBS && ((_obsData$serverError = obsData.serverError) === null || _obsData$serverError === void 0 ? void 0 : _obsData$serverError.length) || settings.labelObs.length && ((_labelObsData$serverE = labelObsData.serverError) === null || _labelObsData$serverE === void 0 ? void 0 : _labelObsData$serverE.length);
361
+ const error = settings.selectedObsm && ((_obsmData$serverError = obsmData.serverError) === null || _obsmData$serverError === void 0 ? void 0 : _obsmData$serverError.length) || settings.colorEncoding === COLOR_ENCODINGS.VAR && ((_xData$serverError = xData.serverError) === null || _xData$serverError === void 0 ? void 0 : _xData$serverError.length) || settings.colorEncoding === COLOR_ENCODINGS.OBS && ((_obsData$serverError = obsData.serverError) === null || _obsData$serverError === void 0 ? void 0 : _obsData$serverError.length) || settings.labelObs.length && ((_labelObsData$serverE = labelObsData.serverError) === null || _labelObsData$serverE === void 0 ? void 0 : _labelObsData$serverE.length) || coordsError;
340
362
  return /*#__PURE__*/React.createElement("div", {
341
363
  className: "cherita-container-scatterplot"
342
364
  }, /*#__PURE__*/React.createElement("div", {
@@ -388,7 +410,7 @@ export function Scatterplot(_ref) {
388
410
  }, /*#__PURE__*/React.createElement(FontAwesomeIcon, {
389
411
  icon: faTriangleExclamation
390
412
  }), "\xA0Error loading data"), /*#__PURE__*/React.createElement(Toolbox, {
391
- mode: settings.colorEncoding === COLOR_ENCODINGS.VAR ? (_settings$selectedVar = settings.selectedVar) === null || _settings$selectedVar === void 0 ? void 0 : _settings$selectedVar.name : settings.colorEncoding === COLOR_ENCODINGS.OBS ? (_settings$selectedObs6 = settings.selectedObs) === null || _settings$selectedObs6 === void 0 ? void 0 : _settings$selectedObs6.name : null,
413
+ mode: settings.colorEncoding === COLOR_ENCODINGS.VAR ? (_settings$selectedVar = settings.selectedVar) === null || _settings$selectedVar === void 0 ? void 0 : _settings$selectedVar.name : settings.colorEncoding === COLOR_ENCODINGS.OBS ? (_settings$selectedObs9 = settings.selectedObs) === null || _settings$selectedObs9 === void 0 ? void 0 : _settings$selectedObs9.name : null,
392
414
  obsLength: parseInt((_data$positions = data.positions) === null || _data$positions === void 0 ? void 0 : _data$positions.length),
393
415
  slicedLength: parseInt(slicedLength)
394
416
  })), /*#__PURE__*/React.createElement(Legend, {
@@ -59,7 +59,8 @@ const initialDataset = {
59
59
  obsGroups: null,
60
60
  imageUrl: null,
61
61
  defaultSettings: {},
62
- canOverrideSettings: true
62
+ canOverrideSettings: true,
63
+ useUnsColors: false
63
64
  };
64
65
  export function DatasetProvider(_ref2) {
65
66
  let {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haniffalab/cherita-react",
3
- "version": "1.3.0-dev.2025-06-06.9f7ff5ad",
3
+ "version": "1.3.0-dev.2025-06-06.7dfb207c",
4
4
  "author": "Haniffa Lab",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -127,5 +127,5 @@
127
127
  "url": "https://github.com/haniffalab/cherita-react/issues"
128
128
  },
129
129
  "homepage": "https://github.com/haniffalab/cherita-react#readme",
130
- "prereleaseSha": "9f7ff5ad72d373bccc11058ca146ba13811cfa70"
130
+ "prereleaseSha": "7dfb207c69d972eecfa5d3a8bf564dd6546fd0f8"
131
131
  }