@cdc/chart 4.22.10 → 4.22.11
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/README.md +5 -5
- package/dist/cdcchart.js +4 -4
- package/examples/age-adjusted-rates.json +1486 -1218
- package/examples/case-rate-example-config.json +1 -1
- package/examples/covid-confidence-example-config.json +33 -33
- package/examples/covid-example-config.json +34 -34
- package/examples/covid-example-data-confidence.json +30 -30
- package/examples/covid-example-data.json +20 -20
- package/examples/cutoff-example-config.json +36 -36
- package/examples/cutoff-example-data.json +36 -36
- package/examples/date-exclusions-config.json +1 -1
- package/examples/dynamic-legends.json +124 -124
- package/examples/gallery/bar-chart-horizontal/horizontal-bar-chart-with-numbers-on-bar.json +191 -197
- package/examples/gallery/bar-chart-horizontal/horizontal-bar-chart.json +230 -240
- package/examples/gallery/bar-chart-horizontal/horizontal-stacked.json +239 -247
- package/examples/gallery/bar-chart-vertical/combo-line-chart.json +136 -136
- package/examples/gallery/bar-chart-vertical/vertical-bar-chart-categorical.json +79 -79
- package/examples/gallery/bar-chart-vertical/vertical-bar-chart-stacked.json +80 -80
- package/examples/gallery/bar-chart-vertical/vertical-bar-chart-with-confidence.json +67 -67
- package/examples/gallery/bar-chart-vertical/vertical-bar-chart.json +110 -110
- package/examples/gallery/lollipop/lollipop-style-horizontal.json +215 -219
- package/examples/gallery/paired-bar/paired-bar-chart.json +195 -195
- package/examples/horizontal-chart.json +35 -35
- package/examples/horizontal-stacked-bar-chart.json +34 -34
- package/examples/line-chart.json +75 -75
- package/examples/paired-bar-data.json +16 -14
- package/examples/paired-bar-example.json +48 -48
- package/examples/paired-bar-formatted.json +36 -36
- package/examples/planet-chart-horizontal-example-config.json +33 -33
- package/examples/planet-combo-example-config.json +34 -31
- package/examples/planet-example-config.json +35 -33
- package/examples/planet-example-data.json +56 -56
- package/examples/planet-pie-example-config.json +28 -28
- package/examples/private/filters.json +170 -0
- package/examples/private/line-test-data.json +21 -21
- package/examples/private/line-test-two.json +209 -215
- package/examples/private/line-test.json +101 -101
- package/examples/private/new.json +48800 -0
- package/examples/private/shawn.json +1105 -1295
- package/examples/private/test.json +10123 -10123
- package/examples/private/yaxis-test.json +4 -3
- package/examples/private/yaxis.json +26 -26
- package/examples/stacked-vertical-bar-example.json +1 -1
- package/examples/temp-example-config.json +61 -54
- package/examples/temp-example-data.json +1 -1
- package/package.json +2 -2
- package/src/CdcChart.tsx +339 -380
- package/src/components/BarChart.tsx +425 -469
- package/src/components/DataTable.tsx +164 -195
- package/src/components/EditorPanel.js +1009 -710
- package/src/components/Legend.js +279 -329
- package/src/components/LineChart.tsx +90 -79
- package/src/components/LinearChart.tsx +376 -434
- package/src/components/PairedBarChart.tsx +197 -213
- package/src/components/PieChart.tsx +95 -151
- package/src/components/SparkLine.js +179 -201
- package/src/components/useIntersectionObserver.tsx +17 -20
- package/src/context.tsx +3 -3
- package/src/data/initial-state.js +37 -16
- package/src/hooks/useActiveElement.js +13 -13
- package/src/hooks/useChartClasses.js +34 -28
- package/src/hooks/useColorPalette.ts +56 -63
- package/src/hooks/useLegendClasses.js +18 -10
- package/src/hooks/useReduceData.ts +62 -78
- package/src/hooks/useRightAxis.js +25 -0
- package/src/hooks/useTopAxis.js +6 -0
- package/src/index.html +45 -45
- package/src/index.tsx +13 -16
- package/src/scss/DataTable.scss +5 -4
- package/src/scss/editor-panel.scss +71 -69
- package/src/scss/main.scss +157 -114
- package/src/scss/variables.scss +1 -1
package/src/components/Legend.js
CHANGED
|
@@ -1,334 +1,284 @@
|
|
|
1
|
-
import React, { useContext, useEffect } from 'react'
|
|
2
|
-
import Context from '../context'
|
|
3
|
-
import parse from 'html-react-parser'
|
|
4
|
-
import { LegendOrdinal, LegendItem, LegendLabel } from '@visx/legend'
|
|
5
|
-
import LegendCircle from '@cdc/core/components/LegendCircle'
|
|
6
|
-
|
|
7
|
-
import useLegendClasses from './../hooks/useLegendClasses';
|
|
1
|
+
import React, { useContext, useEffect } from 'react'
|
|
2
|
+
import Context from '../context'
|
|
3
|
+
import parse from 'html-react-parser'
|
|
4
|
+
import { LegendOrdinal, LegendItem, LegendLabel } from '@visx/legend'
|
|
5
|
+
import LegendCircle from '@cdc/core/components/LegendCircle'
|
|
8
6
|
|
|
7
|
+
import useLegendClasses from './../hooks/useLegendClasses'
|
|
9
8
|
|
|
10
9
|
const Legend = () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
let palette = colorPalettes[config.palette];
|
|
284
|
-
|
|
285
|
-
// Filter excluded data keys from legend
|
|
286
|
-
if (config.exclusions.active && config.exclusions.keys?.includes(itemName)) {
|
|
287
|
-
return
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (config.runtime.seriesLabels && !config.legend.dynamicLegend) {
|
|
291
|
-
let index = config.runtime.seriesLabelsAll.indexOf(itemName)
|
|
292
|
-
itemName = config.runtime.seriesKeys[index]
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (seriesHighlight.length > 0 && !seriesHighlight.includes(itemName)) {
|
|
296
|
-
className.push('inactive')
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if(seriesHighlight.length === 0 && config.legend.dynamicLegend) {
|
|
300
|
-
className.push('inactive')
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
return (
|
|
304
|
-
<>
|
|
305
|
-
<LegendItem
|
|
306
|
-
className={className.join(' ')}
|
|
307
|
-
tabIndex={0}
|
|
308
|
-
key={`dynamic-legend-item-${i}`}
|
|
309
|
-
alignItems="center"
|
|
310
|
-
|
|
311
|
-
>
|
|
312
|
-
<button
|
|
313
|
-
className="btn-wrapper"
|
|
314
|
-
onClick={() => {
|
|
315
|
-
highlight(label);
|
|
316
|
-
}}
|
|
317
|
-
>
|
|
318
|
-
<LegendCircle fill={palette[i]} config={config} />
|
|
319
|
-
<LegendLabel align="space-between" margin="4px 0 0 4px">
|
|
320
|
-
{label.text}
|
|
321
|
-
</LegendLabel>
|
|
322
|
-
</button>
|
|
323
|
-
<button onClick={() => removeDynamicLegendItem(label)}>x</button>
|
|
324
|
-
</LegendItem>
|
|
325
|
-
</>
|
|
326
|
-
)
|
|
327
|
-
})}
|
|
328
|
-
</div>
|
|
329
|
-
{seriesHighlight.length < dynamicLegendItems.length && <button className={`legend-reset legend-reset--dynamic ${config.theme}`} onClick={highlightReset} tabIndex={0}>Reset</button>}
|
|
330
|
-
</aside>
|
|
331
|
-
)
|
|
10
|
+
const { config, legend, colorScale, seriesHighlight, highlight, highlightReset, setSeriesHighlight, dynamicLegendItems, setDynamicLegendItems, transformedData: data, setFilteredData, colorPalettes, rawData, setConfig } = useContext(Context)
|
|
11
|
+
|
|
12
|
+
const { innerClasses, containerClasses } = useLegendClasses(config)
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (dynamicLegendItems.length === 0) return
|
|
16
|
+
|
|
17
|
+
let itemsToHighlight = dynamicLegendItems.map(item => item.text)
|
|
18
|
+
|
|
19
|
+
setSeriesHighlight(itemsToHighlight)
|
|
20
|
+
|
|
21
|
+
let colsToKeep = [...itemsToHighlight]
|
|
22
|
+
let tmpLabels = []
|
|
23
|
+
|
|
24
|
+
rawData.map(dataItem => {
|
|
25
|
+
let tmp = {}
|
|
26
|
+
colsToKeep.map(col => {
|
|
27
|
+
tmp[col] = isNaN(dataItem[col]) ? dataItem[col] : dataItem[col]
|
|
28
|
+
})
|
|
29
|
+
return tmp
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
colsToKeep.map(col => {
|
|
33
|
+
tmpLabels[col] = col
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
if (dynamicLegendItems.length > 0) {
|
|
37
|
+
setConfig({
|
|
38
|
+
...config,
|
|
39
|
+
runtime: {
|
|
40
|
+
...config.runtime,
|
|
41
|
+
seriesKeys: colsToKeep,
|
|
42
|
+
seriesLabels: tmpLabels
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}, [dynamicLegendItems])
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (dynamicLegendItems.length === 0) {
|
|
50
|
+
// loop through all labels and add keys
|
|
51
|
+
let resetSeriesNames = [...config.runtime.seriesLabelsAll]
|
|
52
|
+
let tmpLabels = []
|
|
53
|
+
config.runtime.seriesLabelsAll.map(item => {
|
|
54
|
+
resetSeriesNames.map(col => {
|
|
55
|
+
tmpLabels[col] = col
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
setConfig({
|
|
60
|
+
...config,
|
|
61
|
+
runtime: {
|
|
62
|
+
...config.runtime,
|
|
63
|
+
seriesKeys: config.runtime.seriesLabelsAll,
|
|
64
|
+
seriesLabels: tmpLabels
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
}, [dynamicLegendItems])
|
|
69
|
+
|
|
70
|
+
const removeDynamicLegendItem = label => {
|
|
71
|
+
let newLegendItems = dynamicLegendItems.filter(item => item.text !== label.text)
|
|
72
|
+
let newLegendItemsText = newLegendItems.map(item => item.text)
|
|
73
|
+
setDynamicLegendItems(newLegendItems)
|
|
74
|
+
setSeriesHighlight(newLegendItemsText)
|
|
75
|
+
}
|
|
76
|
+
const handleDynamicLegendChange = e => {
|
|
77
|
+
setDynamicLegendItems([...dynamicLegendItems, JSON.parse(e.target.value)])
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const createLegendLabels = (data, defaultLabels) => {
|
|
81
|
+
const colorCode = config.legend?.colorCode
|
|
82
|
+
if (config.visualizationType !== 'Bar' || config.visualizationSubType !== 'regular' || !colorCode || config.series?.length > 1) {
|
|
83
|
+
return defaultLabels
|
|
84
|
+
}
|
|
85
|
+
let palette = colorPalettes[config.palette]
|
|
86
|
+
|
|
87
|
+
while (data.length > palette.length) {
|
|
88
|
+
palette = palette.concat(palette)
|
|
89
|
+
}
|
|
90
|
+
palette = palette.slice(0, data.length)
|
|
91
|
+
//store uniq values to Set by colorCode
|
|
92
|
+
const set = new Set()
|
|
93
|
+
|
|
94
|
+
data.forEach(d => set.add(d[colorCode]))
|
|
95
|
+
|
|
96
|
+
// create labels with uniq values
|
|
97
|
+
const uniqeLabels = Array.from(set).map((val, i) => {
|
|
98
|
+
const newLabel = {
|
|
99
|
+
datum: val,
|
|
100
|
+
index: i,
|
|
101
|
+
text: val,
|
|
102
|
+
value: palette[i]
|
|
103
|
+
}
|
|
104
|
+
return newLabel
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
return uniqeLabels
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!legend) return
|
|
111
|
+
|
|
112
|
+
if (!legend.dynamicLegend)
|
|
113
|
+
return (
|
|
114
|
+
<aside id='legend' className={containerClasses.join(' ')} role='region' aria-label='legend' tabIndex={0}>
|
|
115
|
+
{legend.label && <h2>{parse(legend.label)}</h2>}
|
|
116
|
+
{legend.description && <p>{parse(legend.description)}</p>}
|
|
117
|
+
<LegendOrdinal scale={colorScale} itemDirection='row' labelMargin='0 20px 0 0' shapeMargin='0 10px 0'>
|
|
118
|
+
{labels => (
|
|
119
|
+
<div className={innerClasses.join(' ')}>
|
|
120
|
+
{createLegendLabels(data, labels).map((label, i) => {
|
|
121
|
+
let className = 'legend-item'
|
|
122
|
+
let itemName = label.datum
|
|
123
|
+
|
|
124
|
+
// Filter excluded data keys from legend
|
|
125
|
+
if (config.exclusions.active && config.exclusions.keys?.includes(itemName)) {
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (config.runtime.seriesLabels) {
|
|
130
|
+
let index = config.runtime.seriesLabelsAll.indexOf(itemName)
|
|
131
|
+
itemName = config.runtime.seriesKeys[index]
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (seriesHighlight.length > 0 && false === seriesHighlight.includes(itemName)) {
|
|
135
|
+
className += ' inactive'
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<LegendItem
|
|
140
|
+
className={className}
|
|
141
|
+
tabIndex={0}
|
|
142
|
+
key={`legend-quantile-${i}`}
|
|
143
|
+
onKeyPress={e => {
|
|
144
|
+
if (e.key === 'Enter') {
|
|
145
|
+
highlight(label)
|
|
146
|
+
}
|
|
147
|
+
}}
|
|
148
|
+
onClick={() => {
|
|
149
|
+
highlight(label)
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
<LegendCircle fill={label.value} />
|
|
153
|
+
<LegendLabel align='left' margin='0 0 0 4px'>
|
|
154
|
+
{label.text}
|
|
155
|
+
</LegendLabel>
|
|
156
|
+
</LegendItem>
|
|
157
|
+
)
|
|
158
|
+
})}
|
|
159
|
+
{seriesHighlight.length > 0 && (
|
|
160
|
+
<button className={`legend-reset ${config.theme}`} onClick={labels => highlightReset(labels)} tabIndex={0}>
|
|
161
|
+
Reset
|
|
162
|
+
</button>
|
|
163
|
+
)}
|
|
164
|
+
</div>
|
|
165
|
+
)}
|
|
166
|
+
</LegendOrdinal>
|
|
167
|
+
</aside>
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<aside id='legend' className={containerClasses.join(' ')} role='region' aria-label='legend' tabIndex={0}>
|
|
172
|
+
{legend.label && <h2>{parse(legend.label)}</h2>}
|
|
173
|
+
{legend.description && <p>{parse(legend.description)}</p>}
|
|
174
|
+
|
|
175
|
+
<LegendOrdinal scale={colorScale} itemDirection='row' labelMargin='0 20px 0 0' shapeMargin='0 10px 0'>
|
|
176
|
+
{labels => {
|
|
177
|
+
if (
|
|
178
|
+
Number(config.legend.dynamicLegendItemLimit) > dynamicLegendItems.length && // legend items are less than limit
|
|
179
|
+
dynamicLegendItems.length !== config.runtime.seriesLabelsAll.length
|
|
180
|
+
) {
|
|
181
|
+
// legend items are equal to series length
|
|
182
|
+
return (
|
|
183
|
+
<select className='dynamic-legend-dropdown' onChange={e => handleDynamicLegendChange(e)}>
|
|
184
|
+
<option className={'all'} tabIndex={0} value={JSON.stringify({ text: config.legend.dynamicLegendDefaultText })}>
|
|
185
|
+
{config.legend.dynamicLegendDefaultText}
|
|
186
|
+
</option>
|
|
187
|
+
{labels.map((label, i) => {
|
|
188
|
+
let className = 'legend-item'
|
|
189
|
+
let itemName = label.datum
|
|
190
|
+
let inDynamicList = false
|
|
191
|
+
|
|
192
|
+
// Filter excluded data keys from legend
|
|
193
|
+
if (config.exclusions.active && config.exclusions.keys?.includes(itemName)) {
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (config.runtime.seriesLabels) {
|
|
198
|
+
let index = config.runtime.seriesLabelsAll.indexOf(itemName)
|
|
199
|
+
itemName = config.runtime.seriesKeys[index]
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (seriesHighlight.length > 0 && false === seriesHighlight.includes(itemName)) {
|
|
203
|
+
className += ' inactive'
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
dynamicLegendItems.map(listItem => {
|
|
207
|
+
if (listItem.text === label.text) {
|
|
208
|
+
inDynamicList = true
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
if (inDynamicList) return true
|
|
213
|
+
let palette = colorPalettes[config.palette]
|
|
214
|
+
|
|
215
|
+
label.value = palette[dynamicLegendItems.length]
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<option className={className} tabIndex={0} value={JSON.stringify(label)}>
|
|
219
|
+
{label.text}
|
|
220
|
+
</option>
|
|
221
|
+
)
|
|
222
|
+
})}
|
|
223
|
+
</select>
|
|
224
|
+
)
|
|
225
|
+
} else {
|
|
226
|
+
return config.legend.dynamicLegendItemLimitMessage
|
|
227
|
+
}
|
|
228
|
+
}}
|
|
229
|
+
</LegendOrdinal>
|
|
230
|
+
|
|
231
|
+
<div className='dynamic-legend-list'>
|
|
232
|
+
{dynamicLegendItems.map((label, i) => {
|
|
233
|
+
let className = ['legend-item']
|
|
234
|
+
let itemName = label.text
|
|
235
|
+
let palette = colorPalettes[config.palette]
|
|
236
|
+
|
|
237
|
+
// Filter excluded data keys from legend
|
|
238
|
+
if (config.exclusions.active && config.exclusions.keys?.includes(itemName)) {
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (config.runtime.seriesLabels && !config.legend.dynamicLegend) {
|
|
243
|
+
let index = config.runtime.seriesLabelsAll.indexOf(itemName)
|
|
244
|
+
itemName = config.runtime.seriesKeys[index]
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (seriesHighlight.length > 0 && !seriesHighlight.includes(itemName)) {
|
|
248
|
+
className.push('inactive')
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (seriesHighlight.length === 0 && config.legend.dynamicLegend) {
|
|
252
|
+
className.push('inactive')
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<>
|
|
257
|
+
<LegendItem className={className.join(' ')} tabIndex={0} key={`dynamic-legend-item-${i}`} alignItems='center'>
|
|
258
|
+
<button
|
|
259
|
+
className='btn-wrapper'
|
|
260
|
+
onClick={() => {
|
|
261
|
+
highlight(label)
|
|
262
|
+
}}
|
|
263
|
+
>
|
|
264
|
+
<LegendCircle fill={palette[i]} config={config} />
|
|
265
|
+
<LegendLabel align='space-between' margin='4px 0 0 4px'>
|
|
266
|
+
{label.text}
|
|
267
|
+
</LegendLabel>
|
|
268
|
+
</button>
|
|
269
|
+
<button onClick={() => removeDynamicLegendItem(label)}>x</button>
|
|
270
|
+
</LegendItem>
|
|
271
|
+
</>
|
|
272
|
+
)
|
|
273
|
+
})}
|
|
274
|
+
</div>
|
|
275
|
+
{seriesHighlight.length < dynamicLegendItems.length && (
|
|
276
|
+
<button className={`legend-reset legend-reset--dynamic ${config.theme}`} onClick={highlightReset} tabIndex={0}>
|
|
277
|
+
Reset
|
|
278
|
+
</button>
|
|
279
|
+
)}
|
|
280
|
+
</aside>
|
|
281
|
+
)
|
|
332
282
|
}
|
|
333
283
|
|
|
334
|
-
export default Legend
|
|
284
|
+
export default Legend
|