@redsift/dashboard 11.5.0 → 11.6.0-alpha.0
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.
- package/_internal/ChartEmptyState.js +2 -0
- package/_internal/ChartEmptyState.js.map +1 -0
- package/_internal/ChartEmptyState2.js +154 -0
- package/_internal/ChartEmptyState2.js.map +1 -0
- package/_internal/CrossfilterRegistry.js +2 -0
- package/_internal/CrossfilterRegistry.js.map +1 -0
- package/_internal/CrossfilterRegistry2.js +23 -0
- package/_internal/CrossfilterRegistry2.js.map +1 -0
- package/_internal/Dashboard.js +4 -0
- package/_internal/Dashboard.js.map +1 -0
- package/_internal/Dashboard2.js +101 -0
- package/_internal/Dashboard2.js.map +1 -0
- package/_internal/PdfExportButton.js +2 -0
- package/_internal/PdfExportButton.js.map +1 -0
- package/_internal/PdfExportButton2.js +417 -0
- package/_internal/PdfExportButton2.js.map +1 -0
- package/_internal/TimeSeriesBarChart.js +2 -0
- package/_internal/TimeSeriesBarChart.js.map +1 -0
- package/_internal/TimeSeriesBarChart2.js +474 -0
- package/_internal/TimeSeriesBarChart2.js.map +1 -0
- package/_internal/WithFilters.js +2 -0
- package/_internal/WithFilters.js.map +1 -0
- package/_internal/WithFilters2.js +701 -0
- package/_internal/WithFilters2.js.map +1 -0
- package/_internal/context.js +102 -0
- package/_internal/context.js.map +1 -0
- package/_internal/types.js +23 -0
- package/_internal/types.js.map +1 -0
- package/index.js +8 -1949
- package/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
import { _ as _objectSpread2, D as DashboardContext, b as _extends } from './context.js';
|
|
2
|
+
import React, { useRef, useMemo, useContext, useState, useEffect, isValidElement } from 'react';
|
|
3
|
+
import { useId, isComponent } from '@redsift/design-system';
|
|
4
|
+
import { C as CrossfilterRegistry } from './CrossfilterRegistry2.js';
|
|
5
|
+
import { D as DashboardReducerActionType } from './types.js';
|
|
6
|
+
import { C as ChartEmptyState } from './ChartEmptyState2.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hook to give to a chart the roles, events and attributes of a listbox.
|
|
10
|
+
*/
|
|
11
|
+
const useCategoricalChartAsListbox = _ref => {
|
|
12
|
+
let {
|
|
13
|
+
id,
|
|
14
|
+
ref,
|
|
15
|
+
type,
|
|
16
|
+
ndxGroup,
|
|
17
|
+
orientation = 'horizontal'
|
|
18
|
+
} = _ref;
|
|
19
|
+
const currentIndexRef = useRef(0);
|
|
20
|
+
const props = useMemo(() => {
|
|
21
|
+
const numberOfGroups = ndxGroup === null || ndxGroup === void 0 ? void 0 : ndxGroup.all().filter(datum => datum.value).length;
|
|
22
|
+
if (ref && numberOfGroups) {
|
|
23
|
+
const getCurrentOption = () => ref.current.querySelector(`._${currentIndexRef.current}`);
|
|
24
|
+
const next = () => {
|
|
25
|
+
getCurrentOption().classList.remove('focused');
|
|
26
|
+
const index = currentIndexRef.current === numberOfGroups - 1 ? 0 : currentIndexRef.current + 1;
|
|
27
|
+
currentIndexRef.current = index;
|
|
28
|
+
ref.current.setAttribute('aria-activedescendant', `id${id}__${type}-${currentIndexRef.current}`);
|
|
29
|
+
getCurrentOption().classList.add('focused');
|
|
30
|
+
};
|
|
31
|
+
const previous = () => {
|
|
32
|
+
getCurrentOption().classList.remove('focused');
|
|
33
|
+
const index = currentIndexRef.current === 0 ? numberOfGroups - 1 : currentIndexRef.current - 1;
|
|
34
|
+
currentIndexRef.current = index;
|
|
35
|
+
ref.current.setAttribute('aria-activedescendant', `id${id}__${type}-${currentIndexRef.current}`);
|
|
36
|
+
getCurrentOption().classList.add('focused');
|
|
37
|
+
};
|
|
38
|
+
const focus = () => {
|
|
39
|
+
ref.current.setAttribute('aria-activedescendant', `id${id}__${type}-0`);
|
|
40
|
+
getCurrentOption().classList.add('focused');
|
|
41
|
+
};
|
|
42
|
+
const blur = () => {
|
|
43
|
+
getCurrentOption().classList.remove('focused');
|
|
44
|
+
currentIndexRef.current = 0;
|
|
45
|
+
ref.current.setAttribute('aria-activedescendant', '');
|
|
46
|
+
};
|
|
47
|
+
const keydown = e => {
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
switch (e.code) {
|
|
50
|
+
case 'ArrowRight':
|
|
51
|
+
if (orientation === 'horizontal') {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
next();
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 'ArrowLeft':
|
|
57
|
+
if (orientation === 'horizontal') {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
previous();
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
case 'ArrowDown':
|
|
63
|
+
if (orientation === 'vertical') {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
next();
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
case 'ArrowUp':
|
|
69
|
+
if (orientation === 'vertical') {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
previous();
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case 'Enter':
|
|
75
|
+
case 'Space':
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
getCurrentOption().dispatchEvent(new Event('click'));
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
'aria-activedescendant': '',
|
|
83
|
+
'aria-multiselectable': 'true',
|
|
84
|
+
'aria-orientation': orientation,
|
|
85
|
+
role: 'listbox',
|
|
86
|
+
tabIndex: 0,
|
|
87
|
+
onFocus: focus,
|
|
88
|
+
onBlur: blur,
|
|
89
|
+
onMouseDown: event => event.preventDefault(),
|
|
90
|
+
onMouseLeave: blur,
|
|
91
|
+
onKeyDown: keydown
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}, [ref, ref.current, ndxGroup, JSON.parse(JSON.stringify((ndxGroup === null || ndxGroup === void 0 ? void 0 : ndxGroup.all()) || ''))]);
|
|
95
|
+
return props;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const FilterableBarChart = props => {
|
|
99
|
+
const {
|
|
100
|
+
children,
|
|
101
|
+
datagridCategoryDimFilter,
|
|
102
|
+
dimension,
|
|
103
|
+
group,
|
|
104
|
+
id: propsId,
|
|
105
|
+
isDimensionArray,
|
|
106
|
+
isResetable,
|
|
107
|
+
localeText,
|
|
108
|
+
onFilter
|
|
109
|
+
} = props;
|
|
110
|
+
const [_id] = useId();
|
|
111
|
+
const id = propsId !== null && propsId !== void 0 ? propsId : _id;
|
|
112
|
+
const ref = useRef();
|
|
113
|
+
const {
|
|
114
|
+
emptyChartTitle,
|
|
115
|
+
emptyChartSubtitle,
|
|
116
|
+
emptyChartResetLabel
|
|
117
|
+
} = _objectSpread2({}, localeText);
|
|
118
|
+
const {
|
|
119
|
+
data,
|
|
120
|
+
dispatch,
|
|
121
|
+
toggleUpdateContext,
|
|
122
|
+
state: {
|
|
123
|
+
tableFilters
|
|
124
|
+
}
|
|
125
|
+
} = useContext(DashboardContext);
|
|
126
|
+
const [ndxDimension, setNdxDimension] = useState();
|
|
127
|
+
const [ndxGroup, setNdxGroup] = useState();
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
const computedNdxDimension = CrossfilterRegistry.get(data).dimension(dimension, isDimensionArray);
|
|
130
|
+
const computedNdxGroup = group ? group(computedNdxDimension) : computedNdxDimension.group();
|
|
131
|
+
setNdxDimension(computedNdxDimension);
|
|
132
|
+
setNdxGroup(computedNdxGroup);
|
|
133
|
+
return function cleanup() {
|
|
134
|
+
computedNdxDimension.filterAll();
|
|
135
|
+
};
|
|
136
|
+
}, [dimension, data, group]);
|
|
137
|
+
const [filters, setFilters] = useState([]);
|
|
138
|
+
const handleFilter = category => {
|
|
139
|
+
let newFilters;
|
|
140
|
+
if (filters.includes(category)) {
|
|
141
|
+
newFilters = filters.filter(f => f !== category);
|
|
142
|
+
} else {
|
|
143
|
+
newFilters = [...filters, category];
|
|
144
|
+
}
|
|
145
|
+
setFilters(newFilters);
|
|
146
|
+
if (newFilters.length) {
|
|
147
|
+
ndxDimension.filter(d => newFilters.includes(d));
|
|
148
|
+
} else {
|
|
149
|
+
ndxDimension.filterAll();
|
|
150
|
+
}
|
|
151
|
+
toggleUpdateContext === null || toggleUpdateContext === void 0 ? void 0 : toggleUpdateContext();
|
|
152
|
+
if (datagridCategoryDimFilter) {
|
|
153
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
154
|
+
type: DashboardReducerActionType.FilterTable,
|
|
155
|
+
filter: {
|
|
156
|
+
id: id,
|
|
157
|
+
field: datagridCategoryDimFilter.field,
|
|
158
|
+
operator: datagridCategoryDimFilter.operator,
|
|
159
|
+
value: newFilters
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (onFilter) {
|
|
164
|
+
onFilter(newFilters);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const resetFilters = () => {
|
|
168
|
+
setFilters([]);
|
|
169
|
+
ndxDimension.filterAll();
|
|
170
|
+
toggleUpdateContext === null || toggleUpdateContext === void 0 ? void 0 : toggleUpdateContext();
|
|
171
|
+
if (datagridCategoryDimFilter) {
|
|
172
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
173
|
+
type: DashboardReducerActionType.ResetFilter,
|
|
174
|
+
filter: {
|
|
175
|
+
id: id,
|
|
176
|
+
field: datagridCategoryDimFilter.field,
|
|
177
|
+
operator: datagridCategoryDimFilter.operator
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (onFilter) {
|
|
182
|
+
onFilter();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
var _tableFilters$find;
|
|
187
|
+
if (!datagridCategoryDimFilter) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const updatedFilters = (_tableFilters$find = tableFilters.find(filter => filter.field === datagridCategoryDimFilter.field && filter.operator === datagridCategoryDimFilter.operator)) === null || _tableFilters$find === void 0 ? void 0 : _tableFilters$find.value;
|
|
191
|
+
if (updatedFilters && updatedFilters !== filters && ndxDimension) {
|
|
192
|
+
setFilters(updatedFilters);
|
|
193
|
+
if (updatedFilters.length) {
|
|
194
|
+
ndxDimension.filter(d => updatedFilters.includes(d));
|
|
195
|
+
} else {
|
|
196
|
+
ndxDimension.filterAll();
|
|
197
|
+
}
|
|
198
|
+
toggleUpdateContext === null || toggleUpdateContext === void 0 ? void 0 : toggleUpdateContext();
|
|
199
|
+
}
|
|
200
|
+
}, [tableFilters]);
|
|
201
|
+
const emptyComponent = /*#__PURE__*/React.createElement(ChartEmptyState, {
|
|
202
|
+
title: emptyChartTitle,
|
|
203
|
+
subtitle: emptyChartSubtitle,
|
|
204
|
+
resetLabel: emptyChartResetLabel,
|
|
205
|
+
onReset: resetFilters
|
|
206
|
+
});
|
|
207
|
+
const chartProps = useCategoricalChartAsListbox({
|
|
208
|
+
id,
|
|
209
|
+
ref: ref,
|
|
210
|
+
type: 'bar',
|
|
211
|
+
ndxGroup,
|
|
212
|
+
orientation: 'vertical'
|
|
213
|
+
});
|
|
214
|
+
const filterProps = {
|
|
215
|
+
barProps: {
|
|
216
|
+
tabIndex: -1
|
|
217
|
+
},
|
|
218
|
+
barRole: 'option',
|
|
219
|
+
role: 'listbox',
|
|
220
|
+
chartProps: chartProps,
|
|
221
|
+
chartRef: ref,
|
|
222
|
+
data: ndxGroup ? JSON.parse(JSON.stringify(ndxGroup.all())) : undefined,
|
|
223
|
+
emptyComponent,
|
|
224
|
+
id,
|
|
225
|
+
isBarSelected: datum => {
|
|
226
|
+
return filters.length === 0 || filters.includes(Array.isArray(datum.data.key) ? datum.data.key[1] : datum.data.key);
|
|
227
|
+
},
|
|
228
|
+
onBarClick: datum => {
|
|
229
|
+
handleFilter(Array.isArray(datum.data.key) ? datum.data.key[1] : datum.data.key);
|
|
230
|
+
},
|
|
231
|
+
onReset: isResetable ? resetFilters : undefined
|
|
232
|
+
};
|
|
233
|
+
if ( /*#__PURE__*/isValidElement(children)) {
|
|
234
|
+
return /*#__PURE__*/React.cloneElement(children, _objectSpread2({}, filterProps));
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const FilterableDataGrid = props => {
|
|
240
|
+
const {
|
|
241
|
+
children,
|
|
242
|
+
onFilter
|
|
243
|
+
} = props;
|
|
244
|
+
const {
|
|
245
|
+
state,
|
|
246
|
+
data,
|
|
247
|
+
dispatch,
|
|
248
|
+
dataGridApiRef
|
|
249
|
+
} = useContext(DashboardContext);
|
|
250
|
+
const {
|
|
251
|
+
tableFilters
|
|
252
|
+
} = state;
|
|
253
|
+
const [filterModel, setFilterModel] = useState();
|
|
254
|
+
useEffect(() => {
|
|
255
|
+
setFilterModel(_objectSpread2(_objectSpread2({}, filterModel), {}, {
|
|
256
|
+
items: tableFilters
|
|
257
|
+
}));
|
|
258
|
+
}, [tableFilters]);
|
|
259
|
+
const updateChartFilters = filterModel => {
|
|
260
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
261
|
+
type: DashboardReducerActionType.FilterTableBatch,
|
|
262
|
+
filter: filterModel.items
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
if ( /*#__PURE__*/isValidElement(children)) {
|
|
266
|
+
var _children$props$apiRe;
|
|
267
|
+
const filterProps = {
|
|
268
|
+
apiRef: (_children$props$apiRe = children.props.apiRef) !== null && _children$props$apiRe !== void 0 ? _children$props$apiRe : dataGridApiRef,
|
|
269
|
+
rows: data || [],
|
|
270
|
+
filterModel,
|
|
271
|
+
onFilterModelChange: filterModel => {
|
|
272
|
+
if (onFilter) {
|
|
273
|
+
onFilter(filterModel);
|
|
274
|
+
}
|
|
275
|
+
updateChartFilters(filterModel);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
return /*#__PURE__*/React.cloneElement(children, _objectSpread2({}, filterProps));
|
|
279
|
+
}
|
|
280
|
+
return null;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const FilterablePieChart = props => {
|
|
284
|
+
var _tableFilters$find;
|
|
285
|
+
const {
|
|
286
|
+
children,
|
|
287
|
+
datagridCategoryDimFilter,
|
|
288
|
+
dimension,
|
|
289
|
+
group,
|
|
290
|
+
id: propsId,
|
|
291
|
+
isDimensionArray,
|
|
292
|
+
isResetable,
|
|
293
|
+
localeText,
|
|
294
|
+
onFilter
|
|
295
|
+
} = props;
|
|
296
|
+
const [_id] = useId();
|
|
297
|
+
const id = propsId !== null && propsId !== void 0 ? propsId : _id;
|
|
298
|
+
const ref = useRef();
|
|
299
|
+
const {
|
|
300
|
+
emptyChartTitle,
|
|
301
|
+
emptyChartSubtitle,
|
|
302
|
+
emptyChartResetLabel
|
|
303
|
+
} = _objectSpread2({}, localeText);
|
|
304
|
+
const {
|
|
305
|
+
data,
|
|
306
|
+
dispatch,
|
|
307
|
+
toggleUpdateContext,
|
|
308
|
+
state: {
|
|
309
|
+
tableFilters
|
|
310
|
+
}
|
|
311
|
+
} = useContext(DashboardContext);
|
|
312
|
+
const [ndxDimension, setNdxDimension] = useState();
|
|
313
|
+
const [ndxGroup, setNdxGroup] = useState();
|
|
314
|
+
useEffect(() => {
|
|
315
|
+
const computedNdxDimension = CrossfilterRegistry.get(data).dimension(dimension, isDimensionArray);
|
|
316
|
+
const computedNdxGroup = group ? group(computedNdxDimension) : computedNdxDimension.group();
|
|
317
|
+
setNdxDimension(computedNdxDimension);
|
|
318
|
+
setNdxGroup(computedNdxGroup);
|
|
319
|
+
return function cleanup() {
|
|
320
|
+
computedNdxDimension.filterAll();
|
|
321
|
+
};
|
|
322
|
+
}, [dimension, data, group]);
|
|
323
|
+
const [filters, setFilters] = useState([]);
|
|
324
|
+
const handleFilter = category => {
|
|
325
|
+
let newFilters;
|
|
326
|
+
if (filters.includes(category)) {
|
|
327
|
+
newFilters = filters.filter(f => f !== category);
|
|
328
|
+
} else {
|
|
329
|
+
newFilters = [...filters, category];
|
|
330
|
+
}
|
|
331
|
+
setFilters(newFilters);
|
|
332
|
+
if (newFilters.length) {
|
|
333
|
+
ndxDimension.filter(d => newFilters.includes(d));
|
|
334
|
+
} else {
|
|
335
|
+
ndxDimension.filterAll();
|
|
336
|
+
}
|
|
337
|
+
toggleUpdateContext === null || toggleUpdateContext === void 0 ? void 0 : toggleUpdateContext();
|
|
338
|
+
if (datagridCategoryDimFilter) {
|
|
339
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
340
|
+
type: DashboardReducerActionType.FilterTable,
|
|
341
|
+
filter: {
|
|
342
|
+
id: id,
|
|
343
|
+
field: datagridCategoryDimFilter.field,
|
|
344
|
+
operator: datagridCategoryDimFilter.operator,
|
|
345
|
+
value: newFilters
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
if (onFilter) {
|
|
350
|
+
onFilter(newFilters);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
const resetFilters = () => {
|
|
354
|
+
setFilters([]);
|
|
355
|
+
ndxDimension.filterAll();
|
|
356
|
+
toggleUpdateContext === null || toggleUpdateContext === void 0 ? void 0 : toggleUpdateContext();
|
|
357
|
+
if (datagridCategoryDimFilter) {
|
|
358
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
359
|
+
type: DashboardReducerActionType.ResetFilter,
|
|
360
|
+
filter: {
|
|
361
|
+
id: id,
|
|
362
|
+
field: datagridCategoryDimFilter.field,
|
|
363
|
+
operator: datagridCategoryDimFilter.operator
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
if (onFilter) {
|
|
368
|
+
onFilter();
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
const updatedFilters = datagridCategoryDimFilter ? (_tableFilters$find = tableFilters.find(filter => filter.field === datagridCategoryDimFilter.field && filter.operator === datagridCategoryDimFilter.operator)) === null || _tableFilters$find === void 0 ? void 0 : _tableFilters$find.value : null;
|
|
372
|
+
useEffect(() => {
|
|
373
|
+
if (updatedFilters && updatedFilters !== filters && ndxDimension) {
|
|
374
|
+
setFilters(updatedFilters);
|
|
375
|
+
if (updatedFilters.length) {
|
|
376
|
+
ndxDimension.filter(d => updatedFilters.includes(d));
|
|
377
|
+
} else {
|
|
378
|
+
ndxDimension.filterAll();
|
|
379
|
+
}
|
|
380
|
+
toggleUpdateContext === null || toggleUpdateContext === void 0 ? void 0 : toggleUpdateContext();
|
|
381
|
+
}
|
|
382
|
+
}, [updatedFilters]);
|
|
383
|
+
const emptyComponent = /*#__PURE__*/React.createElement(ChartEmptyState, {
|
|
384
|
+
title: emptyChartTitle,
|
|
385
|
+
subtitle: emptyChartSubtitle,
|
|
386
|
+
resetLabel: emptyChartResetLabel,
|
|
387
|
+
onReset: resetFilters
|
|
388
|
+
});
|
|
389
|
+
const chartProps = useCategoricalChartAsListbox({
|
|
390
|
+
id,
|
|
391
|
+
ref: ref,
|
|
392
|
+
type: 'bar',
|
|
393
|
+
ndxGroup,
|
|
394
|
+
orientation: 'horizontal'
|
|
395
|
+
});
|
|
396
|
+
const legendProps = {
|
|
397
|
+
onLegendItemClick: datum => {
|
|
398
|
+
handleFilter(datum.data.key);
|
|
399
|
+
},
|
|
400
|
+
isLegendItemSelected: datum => {
|
|
401
|
+
return filters.length === 0 || filters.includes(datum.data.key);
|
|
402
|
+
},
|
|
403
|
+
legendItemRole: 'option',
|
|
404
|
+
role: 'group'
|
|
405
|
+
};
|
|
406
|
+
const filterProps = {
|
|
407
|
+
sliceProps: {
|
|
408
|
+
tabIndex: -1
|
|
409
|
+
},
|
|
410
|
+
sliceRole: 'option',
|
|
411
|
+
role: 'listbox',
|
|
412
|
+
chartProps,
|
|
413
|
+
legendProps,
|
|
414
|
+
chartRef: ref,
|
|
415
|
+
data: ndxGroup ? JSON.parse(JSON.stringify(ndxGroup.all())) : undefined,
|
|
416
|
+
emptyComponent,
|
|
417
|
+
id,
|
|
418
|
+
isSliceSelected: datum => {
|
|
419
|
+
return filters.length === 0 || filters.includes(datum.data.key);
|
|
420
|
+
},
|
|
421
|
+
onSliceClick: datum => {
|
|
422
|
+
handleFilter(datum.data.key);
|
|
423
|
+
},
|
|
424
|
+
onReset: isResetable ? resetFilters : undefined
|
|
425
|
+
};
|
|
426
|
+
if ( /*#__PURE__*/isValidElement(children)) {
|
|
427
|
+
return /*#__PURE__*/React.cloneElement(children, _objectSpread2({}, filterProps));
|
|
428
|
+
}
|
|
429
|
+
return null;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
const filter = (legendFilters, brushFilters) => d => {
|
|
433
|
+
if (legendFilters && legendFilters.length && brushFilters) {
|
|
434
|
+
return d[0] >= brushFilters.minX && d[0] <= brushFilters.maxX && d[1] >= brushFilters.minY && d[1] <= brushFilters.maxY && legendFilters.includes(d[2]);
|
|
435
|
+
} else if (legendFilters && legendFilters.length) {
|
|
436
|
+
return legendFilters.includes(d[2]);
|
|
437
|
+
} else if (brushFilters) {
|
|
438
|
+
return d[0] >= brushFilters.minX && d[0] <= brushFilters.maxX && d[1] >= brushFilters.minY && d[1] <= brushFilters.maxY;
|
|
439
|
+
} else {
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
const isFiltered = (legendFilters, brushFilters) => datum => {
|
|
444
|
+
if (legendFilters && legendFilters.length && brushFilters) {
|
|
445
|
+
return datum.data.key[0] >= brushFilters.minX && datum.data.key[0] <= brushFilters.maxX && datum.data.key[1] >= brushFilters.minY && datum.data.key[1] <= brushFilters.maxY && legendFilters.includes(datum.data.key[2]);
|
|
446
|
+
} else if (legendFilters && legendFilters.length) {
|
|
447
|
+
return legendFilters.includes(datum.data.key[2]);
|
|
448
|
+
} else if (brushFilters) {
|
|
449
|
+
return datum.data.key[0] >= brushFilters.minX && datum.data.key[0] <= brushFilters.maxX && datum.data.key[1] >= brushFilters.minY && datum.data.key[1] <= brushFilters.maxY;
|
|
450
|
+
} else {
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
const FilterableScatterPlot = props => {
|
|
455
|
+
const {
|
|
456
|
+
children,
|
|
457
|
+
datagridCoordinatesCategoryDimFilter,
|
|
458
|
+
dimension,
|
|
459
|
+
group,
|
|
460
|
+
id: propsId,
|
|
461
|
+
isDimensionArray,
|
|
462
|
+
isResetable,
|
|
463
|
+
localeText,
|
|
464
|
+
onFilter
|
|
465
|
+
} = props;
|
|
466
|
+
const [_id] = useId();
|
|
467
|
+
const id = propsId !== null && propsId !== void 0 ? propsId : _id;
|
|
468
|
+
const {
|
|
469
|
+
emptyChartTitle,
|
|
470
|
+
emptyChartSubtitle,
|
|
471
|
+
emptyChartResetLabel
|
|
472
|
+
} = _objectSpread2({}, localeText);
|
|
473
|
+
const {
|
|
474
|
+
data,
|
|
475
|
+
dispatch,
|
|
476
|
+
toggleUpdateContext
|
|
477
|
+
// state: { tableFilters },
|
|
478
|
+
} = useContext(DashboardContext);
|
|
479
|
+
const [ndxDimension, setNdxDimension] = useState();
|
|
480
|
+
const [ndxGroup, setNdxGroup] = useState();
|
|
481
|
+
useEffect(() => {
|
|
482
|
+
const computedNdxDimension = CrossfilterRegistry.get(data).dimension(dimension, isDimensionArray);
|
|
483
|
+
const computedNdxGroup = group ? group(computedNdxDimension) : computedNdxDimension.group();
|
|
484
|
+
setNdxDimension(computedNdxDimension);
|
|
485
|
+
setNdxGroup(computedNdxGroup);
|
|
486
|
+
return function cleanup() {
|
|
487
|
+
computedNdxDimension.filterAll();
|
|
488
|
+
};
|
|
489
|
+
}, [dimension, data, group]);
|
|
490
|
+
const [brushFilters, setBrushFilters] = useState();
|
|
491
|
+
const [legendFilters, setLegendFilters] = useState([]);
|
|
492
|
+
const handleBrushFilter = newFilters => {
|
|
493
|
+
setBrushFilters(newFilters);
|
|
494
|
+
ndxDimension.filter(d => filter(legendFilters, newFilters)(d));
|
|
495
|
+
toggleUpdateContext === null || toggleUpdateContext === void 0 ? void 0 : toggleUpdateContext();
|
|
496
|
+
if (datagridCoordinatesCategoryDimFilter) {
|
|
497
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
498
|
+
type: DashboardReducerActionType.FilterTable,
|
|
499
|
+
filter: {
|
|
500
|
+
id: `${id}-x`,
|
|
501
|
+
field: datagridCoordinatesCategoryDimFilter[0].field,
|
|
502
|
+
operator: datagridCoordinatesCategoryDimFilter[0].operator,
|
|
503
|
+
value: [newFilters.minX, newFilters.maxX]
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
507
|
+
type: DashboardReducerActionType.FilterTable,
|
|
508
|
+
filter: {
|
|
509
|
+
id: `${id}-y`,
|
|
510
|
+
field: datagridCoordinatesCategoryDimFilter[1].field,
|
|
511
|
+
operator: datagridCoordinatesCategoryDimFilter[1].operator,
|
|
512
|
+
value: [newFilters.minY, newFilters.maxY]
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
if (onFilter) {
|
|
517
|
+
onFilter(newFilters);
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
const handleLegendFilter = category => {
|
|
521
|
+
let newFilters;
|
|
522
|
+
if (legendFilters.includes(category)) {
|
|
523
|
+
newFilters = legendFilters.filter(f => f !== category);
|
|
524
|
+
} else {
|
|
525
|
+
newFilters = [...legendFilters, category];
|
|
526
|
+
}
|
|
527
|
+
setLegendFilters(newFilters);
|
|
528
|
+
ndxDimension.filter(d => filter(newFilters, brushFilters)(d));
|
|
529
|
+
toggleUpdateContext === null || toggleUpdateContext === void 0 ? void 0 : toggleUpdateContext();
|
|
530
|
+
if ((datagridCoordinatesCategoryDimFilter === null || datagridCoordinatesCategoryDimFilter === void 0 ? void 0 : datagridCoordinatesCategoryDimFilter.length) === 3) {
|
|
531
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
532
|
+
type: DashboardReducerActionType.FilterTable,
|
|
533
|
+
filter: {
|
|
534
|
+
id: `${id}-category`,
|
|
535
|
+
field: datagridCoordinatesCategoryDimFilter[2].field,
|
|
536
|
+
operator: datagridCoordinatesCategoryDimFilter[2].operator,
|
|
537
|
+
value: newFilters
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
if (onFilter) {
|
|
542
|
+
onFilter(newFilters);
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
const resetFilters = function () {
|
|
546
|
+
let brush = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
547
|
+
let legend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
548
|
+
if (brush) {
|
|
549
|
+
setBrushFilters(undefined);
|
|
550
|
+
}
|
|
551
|
+
if (legend) {
|
|
552
|
+
setLegendFilters([]);
|
|
553
|
+
}
|
|
554
|
+
ndxDimension.filter(d => filter(legend ? [] : legendFilters, brush ? undefined : brushFilters)(d));
|
|
555
|
+
toggleUpdateContext === null || toggleUpdateContext === void 0 ? void 0 : toggleUpdateContext();
|
|
556
|
+
if (datagridCoordinatesCategoryDimFilter) {
|
|
557
|
+
if (brush) {
|
|
558
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
559
|
+
type: DashboardReducerActionType.ResetFilter,
|
|
560
|
+
filter: {
|
|
561
|
+
id: `${id}-x`,
|
|
562
|
+
field: datagridCoordinatesCategoryDimFilter[0].field,
|
|
563
|
+
operator: datagridCoordinatesCategoryDimFilter[0].operator
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
567
|
+
type: DashboardReducerActionType.ResetFilter,
|
|
568
|
+
filter: {
|
|
569
|
+
id: `${id}-y`,
|
|
570
|
+
field: datagridCoordinatesCategoryDimFilter[1].field,
|
|
571
|
+
operator: datagridCoordinatesCategoryDimFilter[1].operator
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
if (legend && datagridCoordinatesCategoryDimFilter.length === 3) {
|
|
576
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch({
|
|
577
|
+
type: DashboardReducerActionType.ResetFilter,
|
|
578
|
+
filter: {
|
|
579
|
+
id: `${id}-category`,
|
|
580
|
+
field: datagridCoordinatesCategoryDimFilter[2].field,
|
|
581
|
+
operator: datagridCoordinatesCategoryDimFilter[2].operator
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (onFilter) {
|
|
587
|
+
onFilter();
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
// useEffect(() => {
|
|
592
|
+
// if (!datagridCoordinatesCategoryDimFilter) {
|
|
593
|
+
// return;
|
|
594
|
+
// }
|
|
595
|
+
|
|
596
|
+
// const updatedXFilters = tableFilters.find(
|
|
597
|
+
// (filter) =>
|
|
598
|
+
// filter.field === datagridCoordinatesCategoryDimFilter[0].field &&
|
|
599
|
+
// filter.operator ===
|
|
600
|
+
// datagridCoordinatesCategoryDimFilter[0].operator
|
|
601
|
+
// )?.value;
|
|
602
|
+
// const updatedYFilters = tableFilters.find(
|
|
603
|
+
// (filter) =>
|
|
604
|
+
// filter.field === datagridCoordinatesCategoryDimFilter[1].field &&
|
|
605
|
+
// filter.operator ===
|
|
606
|
+
// datagridCoordinatesCategoryDimFilter[1].operator
|
|
607
|
+
// )?.value;
|
|
608
|
+
// console.log(updatedXFilters, updatedYFilters, brushFilters);
|
|
609
|
+
// const updatedFilters = {
|
|
610
|
+
// minX: Number(updatedXFilters[0]),
|
|
611
|
+
// maxX: Number(updatedXFilters[0]),
|
|
612
|
+
// minY: Number(updatedYFilters[1]),
|
|
613
|
+
// maxY: Number(updatedYFilters[1]),
|
|
614
|
+
// }
|
|
615
|
+
// if (updatedFilters && JSON.stringify(updatedFilters) !== JSON.stringify(brushFilters)) {
|
|
616
|
+
// }
|
|
617
|
+
// }, [tableFilters]);
|
|
618
|
+
|
|
619
|
+
const emptyComponent = /*#__PURE__*/React.createElement(ChartEmptyState, {
|
|
620
|
+
title: emptyChartTitle,
|
|
621
|
+
subtitle: emptyChartSubtitle,
|
|
622
|
+
resetLabel: emptyChartResetLabel,
|
|
623
|
+
onReset: resetFilters
|
|
624
|
+
});
|
|
625
|
+
const legendProps = {
|
|
626
|
+
onLegendItemClick: datum => {
|
|
627
|
+
handleLegendFilter(datum.data.key);
|
|
628
|
+
},
|
|
629
|
+
isLegendItemSelected: datum => {
|
|
630
|
+
return legendFilters.length === 0 || legendFilters.includes(datum.data.key);
|
|
631
|
+
},
|
|
632
|
+
legendItemRole: 'option',
|
|
633
|
+
role: 'group'
|
|
634
|
+
};
|
|
635
|
+
const filterProps = {
|
|
636
|
+
isBrushable: true,
|
|
637
|
+
data: ndxGroup ? JSON.parse(JSON.stringify(ndxGroup.all())) : undefined,
|
|
638
|
+
dotRole: 'option',
|
|
639
|
+
role: 'listbox',
|
|
640
|
+
emptyComponent,
|
|
641
|
+
id,
|
|
642
|
+
legendProps,
|
|
643
|
+
onBrush: (selection, scaleX, scaleY) => {
|
|
644
|
+
if (selection) {
|
|
645
|
+
setBrushFilters({
|
|
646
|
+
minX: scaleX.invert(selection[0][0]),
|
|
647
|
+
minY: scaleY.invert(selection[1][1]),
|
|
648
|
+
maxX: scaleX.invert(selection[1][0]),
|
|
649
|
+
maxY: scaleY.invert(selection[0][1])
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
},
|
|
653
|
+
onBrushEnd: (selection, scaleX, scaleY) => {
|
|
654
|
+
if (selection && scaleX && scaleY) {
|
|
655
|
+
handleBrushFilter({
|
|
656
|
+
minX: scaleX.invert(selection[0][0]),
|
|
657
|
+
minY: scaleY.invert(selection[1][1]),
|
|
658
|
+
maxX: scaleX.invert(selection[1][0]),
|
|
659
|
+
maxY: scaleY.invert(selection[0][1])
|
|
660
|
+
});
|
|
661
|
+
} else {
|
|
662
|
+
resetFilters(true, false);
|
|
663
|
+
}
|
|
664
|
+
},
|
|
665
|
+
onReset: isResetable ? resetFilters : undefined,
|
|
666
|
+
isDotSelected: datum => isFiltered(legendFilters, brushFilters)(datum)
|
|
667
|
+
};
|
|
668
|
+
if ( /*#__PURE__*/isValidElement(children)) {
|
|
669
|
+
return /*#__PURE__*/React.cloneElement(children, _objectSpread2({}, filterProps));
|
|
670
|
+
}
|
|
671
|
+
return null;
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
const WithFilters = props => {
|
|
675
|
+
if (isComponent('DataGrid')(props.children)) {
|
|
676
|
+
return /*#__PURE__*/React.createElement(FilterableDataGrid, props);
|
|
677
|
+
}
|
|
678
|
+
const {
|
|
679
|
+
dimension
|
|
680
|
+
} = props;
|
|
681
|
+
if (!dimension) {
|
|
682
|
+
return null;
|
|
683
|
+
}
|
|
684
|
+
if (isComponent('BarChart')(props.children)) {
|
|
685
|
+
return /*#__PURE__*/React.createElement(FilterableBarChart, _extends({}, props, {
|
|
686
|
+
dimension: dimension
|
|
687
|
+
}));
|
|
688
|
+
} else if (isComponent('PieChart')(props.children)) {
|
|
689
|
+
return /*#__PURE__*/React.createElement(FilterablePieChart, _extends({}, props, {
|
|
690
|
+
dimension: dimension
|
|
691
|
+
}));
|
|
692
|
+
} else if (isComponent('ScatterPlot')(props.children)) {
|
|
693
|
+
return /*#__PURE__*/React.createElement(FilterableScatterPlot, _extends({}, props, {
|
|
694
|
+
dimension: dimension
|
|
695
|
+
}));
|
|
696
|
+
}
|
|
697
|
+
return /*#__PURE__*/React.isValidElement(props.children) ? props.children : null;
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
export { WithFilters as W };
|
|
701
|
+
//# sourceMappingURL=WithFilters2.js.map
|