@haniffalab/cherita-react 0.2.0-dev.2024-09-26.775b9a06 → 0.2.0-dev.2024-09-26.1ea62883

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.
Files changed (32) hide show
  1. package/dist/App.scss +77 -8
  2. package/dist/components/Offcanvas/index.js +6 -2
  3. package/dist/components/dotplot/Dotplot.js +22 -5
  4. package/dist/components/dotplot/DotplotControls.js +11 -10
  5. package/dist/components/heatmap/Heatmap.js +22 -5
  6. package/dist/components/matrixplot/Matrixplot.js +22 -5
  7. package/dist/components/matrixplot/MatrixplotControls.js +8 -7
  8. package/dist/components/obs-list/ObsItem.js +394 -0
  9. package/dist/components/obs-list/ObsList.js +116 -299
  10. package/dist/components/obs-list/ObsToolbar.js +76 -0
  11. package/dist/components/scatterplot/Legend.js +4 -3
  12. package/dist/components/scatterplot/Scatterplot.js +129 -61
  13. package/dist/components/scatterplot/Toolbox.js +3 -2
  14. package/dist/components/search-bar/SearchBar.js +18 -2
  15. package/dist/components/search-bar/SearchResults.js +8 -8
  16. package/dist/components/var-list/VarItem.js +316 -0
  17. package/dist/components/var-list/VarList.js +167 -149
  18. package/dist/components/var-list/VarSet.js +214 -0
  19. package/dist/components/violin/Violin.js +46 -13
  20. package/dist/components/violin/ViolinControls.js +13 -18
  21. package/dist/constants/constants.js +41 -29
  22. package/dist/context/DatasetContext.js +91 -31
  23. package/dist/context/FilterContext.js +76 -0
  24. package/dist/helpers/map-helper.js +20 -15
  25. package/dist/helpers/zarr-helper.js +35 -13
  26. package/dist/index.js +7 -0
  27. package/dist/utils/VirtualizedList.js +69 -0
  28. package/dist/utils/requests.js +2 -2
  29. package/dist/utils/search.js +3 -56
  30. package/dist/utils/string.js +18 -0
  31. package/package.json +3 -2
  32. package/dist/components/obs-list/ObsValueList.js +0 -101
@@ -5,63 +5,30 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ObsColsList = ObsColsList;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
- var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
9
- var _reactFontawesome = require("@fortawesome/react-fontawesome");
10
8
  var _lodash = _interopRequireDefault(require("lodash"));
11
9
  var _reactBootstrap = require("react-bootstrap");
12
- var _ObsValueList = require("./ObsValueList");
10
+ var _ObsItem = require("./ObsItem");
13
11
  var _constants = require("../../constants/constants");
14
12
  var _DatasetContext = require("../../context/DatasetContext");
15
- var _colorHelper = require("../../helpers/color-helper");
16
13
  var _LoadingIndicators = require("../../utils/LoadingIndicators");
17
14
  var _requests = require("../../utils/requests");
18
15
  var _jsxRuntime = require("react/jsx-runtime");
19
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
17
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
21
18
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
- const N_BINS = 5;
23
- function binContinuous(data) {
24
- let nBins = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : N_BINS;
25
- const binSize = (data.max - data.min) * (1 / nBins);
26
- const thresholds = _lodash.default.range(nBins + 1).map(b => {
27
- return data.min + binSize * b;
28
- });
29
- const bins = {
30
- nBins: nBins,
31
- binSize: binSize,
32
- thresholds: thresholds
33
- };
34
- return {
35
- ...data,
36
- ...bins
37
- };
38
- }
39
- function binDiscrete(data) {
40
- let nBins = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : N_BINS;
41
- const binSize = _lodash.default.round(data.n_values * (1 / nBins));
42
- const bins = {
43
- nBins: nBins,
44
- binSize: binSize
45
- };
46
- return {
47
- ...data,
48
- ...bins
49
- };
50
- }
51
- function ObsColsList() {
52
- var _dataset$selectedObs, _dataset$selectedObs4, _dataset$selectedObs6;
19
+ function ObsColsList(_ref) {
20
+ var _dataset$selectedObs;
21
+ let {
22
+ showColor = true
23
+ } = _ref;
53
24
  const ENDPOINT = "obs/cols";
54
25
  const dataset = (0, _DatasetContext.useDataset)();
55
26
  const dispatch = (0, _DatasetContext.useDatasetDispatch)();
56
- const [obsCols, setObsCols] = (0, _react.useState)({});
57
- const [updatedObsCols, setupdatedObsCols] = (0, _react.useState)(false);
27
+ const [obsCols, setObsCols] = (0, _react.useState)(null);
58
28
  const [active, setActive] = (0, _react.useState)((_dataset$selectedObs = dataset.selectedObs) === null || _dataset$selectedObs === void 0 ? void 0 : _dataset$selectedObs.name);
59
29
  const [params, setParams] = (0, _react.useState)({
60
30
  url: dataset.url
61
31
  });
62
- const {
63
- getColor
64
- } = (0, _colorHelper.useColor)();
65
32
  (0, _react.useEffect)(() => {
66
33
  setParams(p => {
67
34
  return {
@@ -77,58 +44,40 @@ function ObsColsList() {
77
44
  } = (0, _requests.useFetch)(ENDPOINT, params, {
78
45
  refetchOnMount: false
79
46
  });
80
- const validateSelection = (0, _react.useCallback)(obs => {
81
- if (!_lodash.default.isEqual(_lodash.default.omit(obsCols[obs.name], ["omit"]), _lodash.default.omit(obs, ["omit"]))) return false;
82
- if (!_lodash.default.isEqual(obsCols[obs.name].omit, obs.omit)) {
83
- setObsCols(o => {
84
- return {
85
- ...o,
86
- [obs.name]: {
87
- ...o[obs.name],
88
- omit: obs.omit
89
- }
90
- };
91
- });
92
- }
93
- return true;
94
- }, [obsCols]);
95
- (0, _react.useEffect)(() => {
96
- if (updatedObsCols) {
97
- if (dataset.selectedObs) {
98
- if (validateSelection(dataset.selectedObs)) {
99
- setActive(dataset.selectedObs.name);
100
- } else {
101
- dispatch({
102
- type: "select.obs",
103
- obs: null
104
- });
105
- setActive(null);
106
- }
107
- } else {
108
- setActive(null);
109
- }
110
- }
111
- }, [dataset.selectedObs, dispatch, updatedObsCols, validateSelection]);
112
-
113
- // @TODO: change api to return all obs and truncate here
114
47
  (0, _react.useEffect)(() => {
115
48
  if (!isPending && !serverError) {
116
49
  setObsCols(_lodash.default.keyBy(_lodash.default.map(fetchedData, d => {
117
- if (d.type === _constants.OBS_TYPES.CONTINUOUS) {
118
- d = binContinuous(d);
119
- } else if (d.type === _constants.OBS_TYPES.DISCRETE) {
120
- d = binDiscrete(d);
121
- }
122
50
  return {
123
51
  ...d,
52
+ codesMap: _lodash.default.invert(d.codes),
124
53
  omit: []
125
54
  };
126
55
  }), "name"));
127
- setupdatedObsCols(true);
128
56
  }
129
57
  }, [fetchedData, isPending, serverError]);
130
- const toggleAll = (0, _react.useCallback)((item, checked, active) => {
131
- const omit = checked ? [] : _lodash.default.map(item.values, v => item.codes[v]);
58
+
59
+ // @TODO: fix re-rendering performance issue
60
+ (0, _react.useEffect)(() => {
61
+ if (obsCols) {
62
+ var _dataset$selectedObs2;
63
+ if (obsCols[(_dataset$selectedObs2 = dataset.selectedObs) === null || _dataset$selectedObs2 === void 0 ? void 0 : _dataset$selectedObs2.name]) {
64
+ var _dataset$selectedObs3;
65
+ setActive((_dataset$selectedObs3 = dataset.selectedObs) === null || _dataset$selectedObs3 === void 0 ? void 0 : _dataset$selectedObs3.name);
66
+ } else {
67
+ setActive(null);
68
+ }
69
+ }
70
+ }, [dataset.selectedObs, obsCols]);
71
+ const updateObs = updatedObs => {
72
+ setObsCols(o => {
73
+ return {
74
+ ...o,
75
+ [updatedObs.name]: updatedObs
76
+ };
77
+ });
78
+ };
79
+ const toggleAll = item => {
80
+ const omit = item.omit.length ? [] : _lodash.default.map(item.values, v => item.codes[v]);
132
81
  setObsCols(o => {
133
82
  return {
134
83
  ...o,
@@ -147,230 +96,98 @@ function ObsColsList() {
147
96
  }
148
97
  });
149
98
  }
150
- }, [dispatch]);
151
- const categoricalList = (0, _react.useCallback)(function (item) {
152
- var _dataset$selectedObs2, _dataset$selectedObs3;
153
- let active = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
154
- const codesMap = _lodash.default.invert(item.codes);
155
- const inLabelObs = _lodash.default.some(dataset.labelObs, i => _lodash.default.isEqual(i, {
156
- name: item.name,
157
- type: item.type,
158
- codesMap: codesMap
159
- }));
160
- const min = _lodash.default.min(_lodash.default.values(item.codes));
161
- const max = _lodash.default.max(_lodash.default.values(item.codes));
162
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Accordion.Item, {
163
- eventKey: item.name,
164
- className: item.name === active ? "cherita-accordion-active" : "",
165
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Accordion.Header, {
166
- children: item.name
167
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Accordion.Body, {
168
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.ListGroup, {
169
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.ListGroup.Item, {
170
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
171
- className: "d-flex",
172
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
173
- className: "flex-grow-1",
174
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Form.Check, {
175
- // prettier-ignore
176
- type: "switch",
177
- id: "custom-switch",
178
- label: "Toggle all",
179
- checked: !item.omit.length,
180
- onChange: () => {
181
- toggleAll(item, !!item.omit.length, active);
182
- }
183
- })
184
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
185
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.ButtonGroup, {
186
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
187
- variant: inLabelObs ? "primary" : "outline-primary",
188
- size: "sm",
189
- onClick: () => {
190
- if (inLabelObs) {
191
- dispatch({
192
- type: "remove.label.obs",
193
- obsName: item.name
194
- });
195
- } else {
196
- dispatch({
197
- type: "add.label.obs",
198
- obs: {
199
- name: item.name,
200
- type: item.type,
201
- codesMap: codesMap
202
- }
203
- });
204
- }
205
- },
206
- title: "Add to tooltip",
207
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFontawesome.FontAwesomeIcon, {
208
- icon: _freeSolidSvgIcons.faFont
209
- })
210
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
211
- variant: dataset.sliceBy.obs && ((_dataset$selectedObs2 = dataset.selectedObs) === null || _dataset$selectedObs2 === void 0 ? void 0 : _dataset$selectedObs2.name) === item.name ? "primary" : "outline-primary",
212
- size: "sm",
213
- onClick: () => {
214
- dispatch({
215
- type: "toggle.slice.obs",
216
- obs: item
217
- });
218
- },
219
- title: "Slice to selected",
220
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFontawesome.FontAwesomeIcon, {
221
- icon: _freeSolidSvgIcons.faEye
222
- })
223
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
224
- variant: dataset.colorEncoding === _constants.COLOR_ENCODINGS.OBS && ((_dataset$selectedObs3 = dataset.selectedObs) === null || _dataset$selectedObs3 === void 0 ? void 0 : _dataset$selectedObs3.name) === item.name ? "primary" : "outline-primary",
225
- size: "sm",
226
- onClick: () => {
227
- dispatch({
228
- type: "select.obs",
229
- obs: item
230
- });
231
- dispatch({
232
- type: "set.colorEncoding",
233
- value: "obs"
234
- });
235
- },
236
- title: "Set as color encoding",
237
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFontawesome.FontAwesomeIcon, {
238
- icon: _freeSolidSvgIcons.faDroplet
239
- })
240
- })]
241
- })
242
- })]
243
- })
244
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ObsValueList.ObsValueList, {
245
- item: item,
246
- onChange: value => {
247
- const newItem = {
248
- ...item,
249
- omit: !_lodash.default.includes(item.omit, item.codes[value]) ? [...item.omit, item.codes[value]] : _lodash.default.filter(item.omit, o => o !== item.codes[value])
250
- };
251
- setObsCols(o => {
252
- return {
253
- ...o,
254
- [item.name]: newItem
255
- };
256
- });
257
- if (active === item.name) {
258
- dispatch({
259
- type: "select.obs",
260
- obs: newItem
261
- });
262
- }
263
- },
264
- getFillColor: value => {
265
- return "rgb(".concat(getColor((item.codes[value] - min) / (max - min), true, _lodash.default.includes(item.omit, item.codes[value]), {
266
- alpha: 1
267
- }, "obs"), ")");
268
- }
269
- })]
270
- })
271
- })]
272
- }, item.name);
273
- }, [dataset.labelObs, dataset.sliceBy.obs, (_dataset$selectedObs4 = dataset.selectedObs) === null || _dataset$selectedObs4 === void 0 ? void 0 : _dataset$selectedObs4.name, dataset.colorEncoding, toggleAll, dispatch, getColor]);
274
- const continuousList = (0, _react.useCallback)(function (item) {
275
- var _dataset$selectedObs5;
276
- let active = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
277
- const inLabelObs = _lodash.default.some(dataset.labelObs, i => _lodash.default.isEqual(i, {
278
- name: item.name,
279
- type: item.type
280
- }));
281
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Accordion.Item, {
282
- eventKey: item.name,
283
- className: item.name === active ? "cherita-accordion-active" : "",
284
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Accordion.Header, {
285
- children: item.name
286
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Accordion.Body, {
287
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.ListGroup, {
288
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.ListGroup.Item, {
289
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
290
- className: "d-flex justify-content-end",
291
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.ButtonGroup, {
292
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
293
- variant: inLabelObs ? "primary" : "outline-primary",
294
- size: "sm",
295
- onClick: () => {
296
- if (inLabelObs) {
297
- dispatch({
298
- type: "remove.label.obs",
299
- obsName: item.name
300
- });
301
- } else {
302
- dispatch({
303
- type: "add.label.obs",
304
- obs: {
305
- name: item.name,
306
- type: item.type
307
- }
308
- });
309
- }
310
- },
311
- title: "Add to tooltip",
312
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFontawesome.FontAwesomeIcon, {
313
- icon: _freeSolidSvgIcons.faFont
314
- })
315
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
316
- variant: dataset.colorEncoding === _constants.COLOR_ENCODINGS.OBS && ((_dataset$selectedObs5 = dataset.selectedObs) === null || _dataset$selectedObs5 === void 0 ? void 0 : _dataset$selectedObs5.name) === item.name ? "primary" : "outline-primary",
317
- size: "sm",
318
- onClick: key => {
319
- if (key != null) {
320
- dispatch({
321
- type: "select.obs",
322
- obs: item
323
- });
324
- dispatch({
325
- type: "set.colorEncoding",
326
- value: "obs"
327
- });
328
- }
329
- },
330
- title: "Set as color encoding",
331
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFontawesome.FontAwesomeIcon, {
332
- icon: _freeSolidSvgIcons.faDroplet
333
- })
334
- })]
335
- })
336
- })
337
- })
338
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
339
- children: ["Min: ", item.min]
340
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
341
- children: ["Max: ", item.max]
342
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
343
- children: ["Mean: ", item.mean]
344
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
345
- children: ["Median: ", item.median]
346
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
347
- children: ["NBins: ", item.nBins]
348
- })]
349
- })]
350
- }, item.name);
351
- }, [dataset.colorEncoding, dataset.labelObs, (_dataset$selectedObs6 = dataset.selectedObs) === null || _dataset$selectedObs6 === void 0 ? void 0 : _dataset$selectedObs6.name, dispatch]);
352
- const otherList = (0, _react.useCallback)(function (item) {
353
- let active = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
99
+ };
100
+ const toggleLabel = item => {
101
+ const inLabelObs = _lodash.default.some(dataset.labelObs, i => i.name === item.name);
102
+ if (inLabelObs) {
103
+ dispatch({
104
+ type: "remove.label.obs",
105
+ obsName: item.name
106
+ });
107
+ } else {
108
+ dispatch({
109
+ type: "add.label.obs",
110
+ obs: {
111
+ name: item.name,
112
+ type: item.type,
113
+ codesMap: item.codesMap
114
+ }
115
+ });
116
+ }
117
+ };
118
+ const toggleSlice = item => {
119
+ dispatch({
120
+ type: "toggle.slice.obs",
121
+ obs: item
122
+ });
123
+ };
124
+ const toggleColor = item => {
125
+ dispatch({
126
+ type: "select.obs",
127
+ obs: item
128
+ });
129
+ dispatch({
130
+ type: "set.colorEncoding",
131
+ value: "obs"
132
+ });
133
+ };
134
+ const toggleObs = (item, value) => {
135
+ let omit;
136
+ if (_lodash.default.includes(item.omit, item.codes[value])) {
137
+ omit = item.omit.filter(i => i !== item.codes[value]);
138
+ } else {
139
+ omit = [...item.omit, item.codes[value]];
140
+ }
141
+ setObsCols(o => {
142
+ return {
143
+ ...o,
144
+ [item.name]: {
145
+ ...item,
146
+ omit: omit
147
+ }
148
+ };
149
+ });
150
+ if (active === item.name) {
151
+ dispatch({
152
+ type: "select.obs",
153
+ obs: {
154
+ ...item,
155
+ omit: omit
156
+ }
157
+ });
158
+ }
159
+ };
160
+ const obsList = _lodash.default.map(obsCols, item => {
161
+ if (item.type === _constants.OBS_TYPES.DISCRETE) {
162
+ return null;
163
+ }
354
164
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.Accordion.Item, {
355
165
  eventKey: item.name,
356
- className: item.name === active ? "cherita-accordion-active" : "",
166
+ className: active === item.name && "cherita-accordion-active",
357
167
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Accordion.Header, {
358
168
  children: item.name
359
169
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Accordion.Body, {
360
- children: item.type
170
+ children: item.type === _constants.OBS_TYPES.CATEGORICAL || item.type === _constants.OBS_TYPES.BOOLEAN ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_ObsItem.CategoricalObs, {
171
+ obs: item,
172
+ updateObs: updateObs,
173
+ toggleAll: () => toggleAll(item),
174
+ toggleObs: value => toggleObs(item, value),
175
+ toggleLabel: () => toggleLabel(item),
176
+ toggleSlice: () => toggleSlice(item),
177
+ toggleColor: () => toggleColor(item),
178
+ showColor: showColor
179
+ }, item.name) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_ObsItem.ContinuousObs, {
180
+ obs: item,
181
+ updateObs: updateObs,
182
+ toggleAll: () => toggleAll(item),
183
+ toggleObs: value => toggleObs(item, value),
184
+ toggleLabel: () => toggleLabel(item),
185
+ toggleSlice: () => toggleSlice(item),
186
+ toggleColor: () => toggleColor(item)
187
+ }, item.name)
361
188
  })]
362
189
  }, item.name);
363
- }, []);
364
- const obsList = (0, _react.useMemo)(() => _lodash.default.keys(obsCols).map(o => {
365
- const item = obsCols[o];
366
- if (item.type === _constants.OBS_TYPES.CATEGORICAL) {
367
- return categoricalList(item, active);
368
- } else if (item.type === _constants.OBS_TYPES.CONTINUOUS) {
369
- return continuousList(item, active);
370
- } else {
371
- return otherList(item, active);
372
- }
373
- }), [obsCols, categoricalList, active, continuousList, otherList]);
190
+ });
374
191
  if (!serverError) {
375
192
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
376
193
  className: "position-relative h-100",
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ObsToolbar = ObsToolbar;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _freeSolidSvgIcons = require("@fortawesome/free-solid-svg-icons");
9
+ var _reactFontawesome = require("@fortawesome/react-fontawesome");
10
+ var _lodash = _interopRequireDefault(require("lodash"));
11
+ var _reactBootstrap = require("react-bootstrap");
12
+ var _constants = require("../../constants/constants");
13
+ var _DatasetContext = require("../../context/DatasetContext");
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ function ObsToolbar(_ref) {
17
+ var _dataset$selectedObs, _dataset$selectedObs2;
18
+ let {
19
+ item,
20
+ showToggleAllObs = true,
21
+ showLabel = true,
22
+ showSlice = true,
23
+ showColor = true,
24
+ onToggleAllObs,
25
+ onToggleLabel,
26
+ onToggleSlice,
27
+ onToggleColor
28
+ } = _ref;
29
+ const dataset = (0, _DatasetContext.useDataset)();
30
+ const allToggledOn = !item.omit.length;
31
+ const inLabelObs = _lodash.default.some(dataset.labelObs, i => i.name === item.name);
32
+ const inSliceObs = dataset.sliceBy.obs && ((_dataset$selectedObs = dataset.selectedObs) === null || _dataset$selectedObs === void 0 ? void 0 : _dataset$selectedObs.name) === item.name;
33
+ const isColorEncoding = dataset.colorEncoding === _constants.COLOR_ENCODINGS.OBS && ((_dataset$selectedObs2 = dataset.selectedObs) === null || _dataset$selectedObs2 === void 0 ? void 0 : _dataset$selectedObs2.name) === item.name;
34
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
35
+ className: "d-flex",
36
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
37
+ className: "flex-grow-1",
38
+ children: showToggleAllObs && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Form.Check, {
39
+ // prettier-ignore
40
+ type: "switch",
41
+ id: "custom-switch",
42
+ label: "Toggle all",
43
+ checked: allToggledOn,
44
+ onChange: onToggleAllObs
45
+ })
46
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
47
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactBootstrap.ButtonGroup, {
48
+ children: [showLabel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
49
+ variant: inLabelObs ? "primary" : "outline-primary",
50
+ size: "sm",
51
+ onClick: onToggleLabel,
52
+ title: "Add to tooltip",
53
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFontawesome.FontAwesomeIcon, {
54
+ icon: _freeSolidSvgIcons.faFont
55
+ })
56
+ }), showSlice && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
57
+ variant: inSliceObs ? "primary" : "outline-primary",
58
+ size: "sm",
59
+ onClick: onToggleSlice,
60
+ title: "Slice to selected",
61
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFontawesome.FontAwesomeIcon, {
62
+ icon: _freeSolidSvgIcons.faEye
63
+ })
64
+ }), showColor && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactBootstrap.Button, {
65
+ variant: isColorEncoding ? "primary" : "outline-primary",
66
+ size: "sm",
67
+ onClick: onToggleColor,
68
+ title: "Set as color encoding",
69
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFontawesome.FontAwesomeIcon, {
70
+ icon: _freeSolidSvgIcons.faDroplet
71
+ })
72
+ })]
73
+ })
74
+ })]
75
+ });
76
+ }
@@ -9,6 +9,7 @@ var _lodash = _interopRequireDefault(require("lodash"));
9
9
  var _constants = require("../../constants/constants");
10
10
  var _DatasetContext = require("../../context/DatasetContext");
11
11
  var _colorHelper = require("../../helpers/color-helper");
12
+ var _string = require("../../utils/string");
12
13
  var _jsxRuntime = require("react/jsx-runtime");
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
15
  function Legend(_ref) {
@@ -43,13 +44,13 @@ function Legend(_ref) {
43
44
  children: dataset.colorEncoding === _constants.COLOR_ENCODINGS.VAR ? (_dataset$selectedVar = dataset.selectedVar) === null || _dataset$selectedVar === void 0 ? void 0 : _dataset$selectedVar.name : (_dataset$selectedObs = dataset.selectedObs) === null || _dataset$selectedObs === void 0 ? void 0 : _dataset$selectedObs.name
44
45
  }), spanList, /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
45
46
  className: "domain-min",
46
- children: min.toFixed(1)
47
+ children: (0, _string.prettyNumerical)(min)
47
48
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
48
49
  className: "domain-med",
49
- children: ((min + max) * 0.5).toFixed(1)
50
+ children: (0, _string.prettyNumerical)((min + max) * 0.5)
50
51
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
51
52
  className: "domain-max",
52
- children: max.toFixed(1)
53
+ children: (0, _string.prettyNumerical)(max)
53
54
  })]
54
55
  })
55
56
  });