@cdc/chart 4.26.2 → 4.26.3

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 (70) hide show
  1. package/LICENSE +201 -0
  2. package/dist/cdcchart.js +35674 -32430
  3. package/examples/data/data-with-metadata.json +10 -0
  4. package/examples/feature/pie/planet-pie-example-config.json +2 -1
  5. package/examples/metadata-variables.json +58 -0
  6. package/package.json +3 -3
  7. package/src/CdcChart.tsx +8 -4
  8. package/src/CdcChartComponent.tsx +321 -288
  9. package/src/_stories/Chart.CustomColors.stories.tsx +74 -0
  10. package/src/_stories/Chart.Defaults.stories.tsx +95 -0
  11. package/src/_stories/Chart.SmallestLeftAxisMax.stories.tsx +64 -0
  12. package/src/_stories/Chart.stories.tsx +36 -2
  13. package/src/_stories/ChartBar.Editor.stories.tsx +97 -38
  14. package/src/_stories/ChartBrush.Editor.stories.tsx +11 -25
  15. package/src/_stories/ChartEditor.Editor.stories.tsx +1 -1
  16. package/src/_stories/_mock/paired-bar-abbr.json +421 -0
  17. package/src/_stories/_mock/pie_custom_colors.json +268 -0
  18. package/src/_stories/_mock/smallest_left_axis_max.json +104 -0
  19. package/src/components/Annotations/components/AnnotationDraggable.styles.css +10 -10
  20. package/src/components/Annotations/components/AnnotationDropdown.styles.css +1 -1
  21. package/src/components/Annotations/components/AnnotationList.styles.css +11 -11
  22. package/src/components/Axis/BottomAxis.tsx +10 -3
  23. package/src/components/Axis/PairedBarAxis.tsx +10 -4
  24. package/src/components/BarChart/components/BarChart.Horizontal.tsx +12 -28
  25. package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +12 -30
  26. package/src/components/BarChart/components/BarChart.StackedVertical.tsx +12 -31
  27. package/src/components/BarChart/components/BarChart.Vertical.tsx +12 -28
  28. package/src/components/BarChart/helpers/getPatternUrl.ts +94 -0
  29. package/src/components/BarChart/helpers/tests/getPatternUrl.test.ts +134 -0
  30. package/src/components/BarChart/helpers/useBarChart.ts +3 -0
  31. package/src/components/Brush/BrushSelector.tsx +2 -1
  32. package/src/components/Brush/MiniChartPreview.tsx +21 -26
  33. package/src/components/EditorPanel/EditorPanel.tsx +56 -43
  34. package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +9 -9
  35. package/src/components/EditorPanel/components/Panels/Panel.ForestPlotSettings.tsx +0 -78
  36. package/src/components/EditorPanel/components/Panels/Panel.General.tsx +39 -1
  37. package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +24 -42
  38. package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +83 -2
  39. package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +45 -42
  40. package/src/components/EditorPanel/editor-panel.scss +1 -1
  41. package/src/components/ForestPlot/ForestPlot.tsx +26 -22
  42. package/src/components/Legend/LegendGroup/LegendGroup.styles.css +4 -4
  43. package/src/components/Legend/helpers/createFormatLabels.tsx +3 -2
  44. package/src/components/LinearChart/tests/LinearChart.test.tsx +77 -0
  45. package/src/components/LinearChart/tests/mockConfigContext.ts +2 -0
  46. package/src/components/LinearChart.tsx +26 -6
  47. package/src/components/PieChart/PieChart.tsx +19 -4
  48. package/src/components/RadarChart/RadarChart.tsx +1 -1
  49. package/src/components/Regions/components/Regions.tsx +6 -6
  50. package/src/components/Sankey/components/Sankey.tsx +3 -3
  51. package/src/components/Sankey/sankey.scss +1 -1
  52. package/src/components/SmallMultiples/SmallMultiples.css +5 -5
  53. package/src/components/Sparkline/index.scss +4 -2
  54. package/src/components/WarmingStripes/WarmingStripesGradientLegend.css +8 -8
  55. package/src/data/initial-state.js +23 -14
  56. package/src/data/legacy-defaults.ts +18 -0
  57. package/src/helpers/abbreviateNumber.ts +24 -17
  58. package/src/helpers/getChartPatternId.ts +17 -0
  59. package/src/helpers/getMinMax.ts +16 -2
  60. package/src/helpers/seriesColumnSettings.ts +114 -0
  61. package/src/helpers/tests/countNumOfTicks.test.ts +77 -0
  62. package/src/helpers/tests/seriesColumnSettings.test.ts +84 -0
  63. package/src/hooks/useRightAxis.ts +14 -0
  64. package/src/hooks/useScales.ts +92 -56
  65. package/src/hooks/useTooltip.tsx +20 -3
  66. package/src/scss/main.scss +152 -79
  67. package/src/test/CdcChart.test.jsx +2 -2
  68. package/src/types/ChartConfig.ts +4 -0
  69. package/tests/fixtures/chart-config-with-metadata.json +29 -0
  70. package/tests/fixtures/data-with-metadata.json +10 -0
@@ -121,7 +121,12 @@ export const BrushDefaultSelectionTests: Story = {
121
121
  const getBrushSelectionState = () => {
122
122
  // The brush selection is represented by the visx-brush extent rect
123
123
  const brushExtent = canvasElement.querySelector('.visx-brush rect[class*="selection"]') as SVGRectElement
124
- const brushSvg = canvasElement.querySelector('svg[style*="border: 1px solid"]') as SVGSVGElement
124
+ const brushSvg =
125
+ (brushExtent?.closest('svg') as SVGSVGElement) ||
126
+ (canvasElement.querySelector('.visx-brush svg') as SVGSVGElement)
127
+ const brushWidthAttr = brushSvg ? parseFloat(brushSvg.getAttribute('width') || '0') : 0
128
+ const totalBrushWidth = brushSvg ? brushSvg.clientWidth || brushWidthAttr : 0
129
+ const countInput = canvasElement.querySelector('input[id*="brushDefaultRecentDateCount"]') as HTMLInputElement
125
130
 
126
131
  // Get the visible data points in the main chart (lines or bars)
127
132
  const chartSvg = canvasElement.querySelector('.linear-chart svg, .cove-chart svg') as SVGSVGElement
@@ -130,11 +135,12 @@ export const BrushDefaultSelectionTests: Story = {
130
135
  return {
131
136
  brushWidth: brushExtent ? parseFloat(brushExtent.getAttribute('width') || '0') : 0,
132
137
  brushX: brushExtent ? parseFloat(brushExtent.getAttribute('x') || '0') : 0,
133
- totalBrushWidth: brushSvg ? brushSvg.clientWidth : 0,
138
+ totalBrushWidth,
134
139
  visibleDataPoints: dataPointsInChart,
140
+ defaultRecentDateCountValue: countInput?.value || '',
135
141
  selectionPercentage:
136
- brushExtent && brushSvg
137
- ? (parseFloat(brushExtent.getAttribute('width') || '0') / brushSvg.clientWidth) * 100
142
+ brushExtent && totalBrushWidth > 0
143
+ ? (parseFloat(brushExtent.getAttribute('width') || '0') / totalBrushWidth) * 100
138
144
  : 0
139
145
  }
140
146
  }
@@ -176,7 +182,7 @@ export const BrushDefaultSelectionTests: Story = {
176
182
  },
177
183
  (before, after) => {
178
184
  // Changing from 30 to 50 should expand the brush width
179
- return after.brushWidth > before.brushWidth
185
+ return after.defaultRecentDateCountValue === '50' && after.brushWidth > before.brushWidth
180
186
  }
181
187
  )
182
188
 
@@ -226,26 +232,6 @@ export const BrushDefaultSelectionTests: Story = {
226
232
  expect(afterSettingCount.dataPointCount).toBeGreaterThan(0)
227
233
  expect(afterSettingCount.dataPointCount).toBeLessThanOrEqual(35) // 30 + tolerance
228
234
  }
229
-
230
- // ============================================================================
231
- // TEST: Clear Recent Date Count Returns to Default 35%
232
- // Verifies: When the count is cleared, brush returns to percentage-based default
233
- // ============================================================================
234
-
235
- await performAndAssert(
236
- 'Clear Default Recent Date Count (return to 35%)',
237
- getBrushSelectionState,
238
- async () => {
239
- await userEvent.clear(recentDateCountInput)
240
- await userEvent.tab()
241
- },
242
- (before, after) => {
243
- // The selection should return to approximately 35% of the total width
244
- // Since we had set it to 30 points (~9% with 329 data points),
245
- // clearing should expand it back to ~35%
246
- return after.brushWidth > before.brushWidth || after.selectionPercentage > before.selectionPercentage
247
- }
248
- )
249
235
  }
250
236
  }
251
237
 
@@ -472,7 +472,7 @@ export const SmallMultiplesSectionTests: Story = {
472
472
  // ============================================================================
473
473
 
474
474
  const getChartCounts = () => {
475
- const chartContainer = canvasElement.querySelector('.cove-component__content, .chart-container, .visualization')
475
+ const chartContainer = canvasElement.querySelector('.cove-visualization__body, .chart-container, .visualization')
476
476
  const tiles = canvasElement.querySelectorAll('.small-multiple-tile, [class*="tile"]')
477
477
  const svgElements = chartContainer?.querySelectorAll('svg[role="img"], svg.chart') || []
478
478
 
@@ -0,0 +1,421 @@
1
+ {
2
+ "annotations": [],
3
+ "type": "chart",
4
+ "debugSvg": false,
5
+ "chartMessage": {
6
+ "noData": "No Data Available"
7
+ },
8
+ "title": "",
9
+ "showTitle": true,
10
+ "showDownloadMediaButton": false,
11
+ "theme": "theme-blue",
12
+ "animate": false,
13
+ "fontSize": "medium",
14
+ "lineDatapointStyle": "hover",
15
+ "lineDatapointColor": "Same as Line",
16
+ "barHasBorder": "false",
17
+ "isLollipopChart": false,
18
+ "lollipopShape": "circle",
19
+ "lollipopColorStyle": "two-tone",
20
+ "visualizationSubType": "regular",
21
+ "barStyle": "",
22
+ "roundingStyle": "standard",
23
+ "tipRounding": "top",
24
+ "isResponsiveTicks": false,
25
+ "general": {
26
+ "annotationDropdownText": "Annotations",
27
+ "showDownloadButton": false,
28
+ "showMissingDataLabel": true,
29
+ "showSuppressedSymbol": true,
30
+ "hideNullValue": true
31
+ },
32
+ "padding": {
33
+ "left": 5,
34
+ "right": 5
35
+ },
36
+ "preliminaryData": [],
37
+ "yAxis": {
38
+ "hideAxis": false,
39
+ "displayNumbersOnBar": false,
40
+ "hideLabel": false,
41
+ "hideTicks": false,
42
+ "size": 50,
43
+ "gridLines": false,
44
+ "enablePadding": false,
45
+ "min": "",
46
+ "max": "",
47
+ "labelColor": "#333",
48
+ "tickLabelColor": "#333",
49
+ "tickColor": "#333",
50
+ "rightHideAxis": true,
51
+ "rightAxisSize": 0,
52
+ "rightLabel": "",
53
+ "rightLabelOffsetSize": 0,
54
+ "rightAxisLabelColor": "#333",
55
+ "rightAxisTickLabelColor": "#333",
56
+ "rightAxisTickColor": "#333",
57
+ "numTicks": "",
58
+ "axisPadding": 0,
59
+ "scalePadding": 10,
60
+ "tickRotation": "40",
61
+ "anchors": [],
62
+ "shoMissingDataLabel": true,
63
+ "showMissingDataLine": true,
64
+ "categories": [],
65
+ "label": "X Axis Title"
66
+ },
67
+ "boxplot": {
68
+ "plots": [],
69
+ "borders": "true",
70
+ "firstQuartilePercentage": 25,
71
+ "thirdQuartilePercentage": 75,
72
+ "boxWidthPercentage": 40,
73
+ "plotOutlierValues": false,
74
+ "plotNonOutlierValues": true,
75
+ "legend": {
76
+ "showHowToReadText": false,
77
+ "howToReadText": ""
78
+ },
79
+ "labels": {
80
+ "q1": "Lower Quartile",
81
+ "q2": "q2",
82
+ "q3": "Upper Quartile",
83
+ "q4": "q4",
84
+ "minimum": "Minimum",
85
+ "maximum": "Maximum",
86
+ "mean": "Mean",
87
+ "median": "Median",
88
+ "sd": "Standard Deviation",
89
+ "iqr": "Interquartile Range",
90
+ "total": "Total",
91
+ "outliers": "Outliers",
92
+ "values": "Values",
93
+ "lowerBounds": "Lower Bounds",
94
+ "upperBounds": "Upper Bounds"
95
+ }
96
+ },
97
+ "topAxis": {
98
+ "hasLine": false
99
+ },
100
+ "isLegendValue": false,
101
+ "barThickness": "0.37",
102
+ "barHeight": 25,
103
+ "barSpace": 15,
104
+ "heights": {
105
+ "vertical": 300,
106
+ "horizontal": 280
107
+ },
108
+ "xAxis": {
109
+ "sortDates": false,
110
+ "anchors": [],
111
+ "type": "categorical",
112
+ "showTargetLabel": true,
113
+ "targetLabel": "Target",
114
+ "hideAxis": false,
115
+ "hideLabel": false,
116
+ "hideTicks": false,
117
+ "size": 75,
118
+ "tickRotation": 0,
119
+ "min": "",
120
+ "max": "",
121
+ "labelColor": "#333",
122
+ "tickLabelColor": "#333",
123
+ "tickColor": "#333",
124
+ "numTicks": 5,
125
+ "labelOffset": 0,
126
+ "axisPadding": 200,
127
+ "target": 0,
128
+ "maxTickRotation": 45,
129
+ "padding": 0,
130
+ "dataKey": "Year"
131
+ },
132
+ "table": {
133
+ "label": "Data Table",
134
+ "expanded": true,
135
+ "limitHeight": false,
136
+ "height": "",
137
+ "caption": "",
138
+ "showDownloadUrl": false,
139
+ "showDataTableLink": true,
140
+ "showDownloadLinkBelow": true,
141
+ "indexLabel": "",
142
+ "download": true,
143
+ "showVertical": true,
144
+ "dateDisplayFormat": "",
145
+ "showMissingDataLabel": true,
146
+ "showSuppressedSymbol": true,
147
+ "show": true
148
+ },
149
+ "orientation": "horizontal",
150
+ "color": "pinkpurple",
151
+ "columns": {},
152
+ "legend": {
153
+ "hide": false,
154
+ "behavior": "isolate",
155
+ "axisAlign": true,
156
+ "singleRow": true,
157
+ "colorCode": "",
158
+ "reverseLabelOrder": false,
159
+ "description": "",
160
+ "dynamicLegend": false,
161
+ "dynamicLegendDefaultText": "Show All",
162
+ "dynamicLegendItemLimit": 5,
163
+ "dynamicLegendItemLimitMessage": "Dynamic Legend Item Limit Hit.",
164
+ "dynamicLegendChartMessage": "Select Options from the Legend",
165
+ "label": "",
166
+ "lineMode": false,
167
+ "verticalSorted": false,
168
+ "highlightOnHover": false,
169
+ "hideSuppressedLabels": false,
170
+ "hideSuppressionLink": false,
171
+ "seriesHighlight": [],
172
+ "style": "circles",
173
+ "subStyle": "linear blocks",
174
+ "tickRotation": "",
175
+ "hideBorder": {
176
+ "side": false,
177
+ "topBottom": true
178
+ }
179
+ },
180
+ "brush": {
181
+ "height": 25,
182
+ "active": false
183
+ },
184
+ "exclusions": {
185
+ "active": false,
186
+ "keys": []
187
+ },
188
+ "palette": "qualitative-bold",
189
+ "isPaletteReversed": false,
190
+ "twoColor": {
191
+ "palette": "monochrome-1",
192
+ "isPaletteReversed": false
193
+ },
194
+ "labels": false,
195
+ "dataFormat": {
196
+ "commas": false,
197
+ "prefix": "",
198
+ "suffix": "",
199
+ "abbreviated": true,
200
+ "bottomSuffix": "",
201
+ "bottomPrefix": "",
202
+ "bottomAbbreviated": false
203
+ },
204
+ "confidenceKeys": {},
205
+ "visual": {
206
+ "border": true,
207
+ "accent": true,
208
+ "background": true,
209
+ "verticalHoverLine": false,
210
+ "horizontalHoverLine": false
211
+ },
212
+ "useLogScale": false,
213
+ "filterBehavior": "Filter Change",
214
+ "highlightedBarValues": [],
215
+ "series": [
216
+ {
217
+ "dataKey": "Male",
218
+ "type": "Paired Bar",
219
+ "axis": "Left",
220
+ "tooltip": true
221
+ },
222
+ {
223
+ "dataKey": "Female",
224
+ "type": "Paired Bar",
225
+ "axis": "Left",
226
+ "tooltip": true
227
+ }
228
+ ],
229
+ "tooltips": {
230
+ "opacity": 90,
231
+ "singleSeries": false,
232
+ "dateDisplayFormat": ""
233
+ },
234
+ "forestPlot": {
235
+ "startAt": 0,
236
+ "colors": {
237
+ "line": "",
238
+ "shape": ""
239
+ },
240
+ "lineOfNoEffect": {
241
+ "show": true
242
+ },
243
+ "type": "",
244
+ "pooledResult": {
245
+ "diamondHeight": 5,
246
+ "column": ""
247
+ },
248
+ "estimateField": "",
249
+ "estimateRadius": "",
250
+ "shape": "square",
251
+ "rowHeight": 20,
252
+ "description": {
253
+ "show": true,
254
+ "text": "description",
255
+ "location": 0
256
+ },
257
+ "result": {
258
+ "show": true,
259
+ "text": "result",
260
+ "location": 100
261
+ },
262
+ "radius": {
263
+ "min": 2,
264
+ "max": 10,
265
+ "scalingColumn": ""
266
+ },
267
+ "regression": {
268
+ "lower": 0,
269
+ "upper": 0,
270
+ "estimateField": 0
271
+ },
272
+ "leftWidthOffset": 0,
273
+ "rightWidthOffset": 0,
274
+ "showZeroLine": false,
275
+ "leftLabel": "",
276
+ "rightLabel": ""
277
+ },
278
+ "area": {
279
+ "isStacked": false
280
+ },
281
+ "sankey": {
282
+ "title": {
283
+ "defaultColor": "black"
284
+ },
285
+ "iterations": 1,
286
+ "rxValue": 0.9,
287
+ "overallSize": {
288
+ "width": 900,
289
+ "height": 700
290
+ },
291
+ "margin": {
292
+ "margin_y": 25,
293
+ "margin_x": 0
294
+ },
295
+ "nodeSize": {
296
+ "nodeWidth": 26,
297
+ "nodeHeight": 40
298
+ },
299
+ "nodePadding": 55,
300
+ "nodeFontColor": "black",
301
+ "nodeColor": {
302
+ "default": "#ff8500",
303
+ "inactive": "#808080"
304
+ },
305
+ "linkColor": {
306
+ "default": "#ffc900",
307
+ "inactive": "#D3D3D3"
308
+ },
309
+ "opacity": {
310
+ "nodeOpacityDefault": 1,
311
+ "nodeOpacityInactive": 0.1,
312
+ "LinkOpacityDefault": 1,
313
+ "LinkOpacityInactive": 0.1
314
+ },
315
+ "storyNodeFontColor": "#006778",
316
+ "storyNodeText": [],
317
+ "nodeValueStyle": {
318
+ "textBefore": "(",
319
+ "textAfter": ")"
320
+ },
321
+ "data": []
322
+ },
323
+ "datasets": {},
324
+ "visualizationType": "Paired Bar",
325
+ "data": [
326
+ {
327
+ "Year": "2018",
328
+ "Age Group": "65",
329
+ "Male": "4200",
330
+ "Female": "3000"
331
+ },
332
+ {
333
+ "Year": "2019",
334
+ "Age Group": "<15",
335
+ "Male": "3900",
336
+ "Female": "2800"
337
+ },
338
+ {
339
+ "Year": "2020",
340
+ "Age Group": "15-24",
341
+ "Male": "3100",
342
+ "Female": "2100"
343
+ },
344
+ {
345
+ "Year": "2021",
346
+ "Age Group": "25-34",
347
+ "Male": "2600",
348
+ "Female": "1800"
349
+ },
350
+ {
351
+ "Year": "2022",
352
+ "Age Group": "35-44",
353
+ "Male": "1800",
354
+ "Female": "1200"
355
+ },
356
+ {
357
+ "Year": "2023",
358
+ "Age Group": "45-54",
359
+ "Male": "1200",
360
+ "Female": "700"
361
+ },
362
+ {
363
+ "Year": "2024",
364
+ "Age Group": "55-64",
365
+ "Male": "800",
366
+ "Female": "500"
367
+ }
368
+ ],
369
+ "dataFileName": "paired-bar-formatted.json",
370
+ "dataFileSourceType": "file",
371
+ "formattedData": [
372
+ {
373
+ "Year": "2018",
374
+ "Age Group": "65",
375
+ "Male": "4200",
376
+ "Female": "3000"
377
+ },
378
+ {
379
+ "Year": "2019",
380
+ "Age Group": "<15",
381
+ "Male": "3900",
382
+ "Female": "2800"
383
+ },
384
+ {
385
+ "Year": "2020",
386
+ "Age Group": "15-24",
387
+ "Male": "3100",
388
+ "Female": "2100"
389
+ },
390
+ {
391
+ "Year": "2021",
392
+ "Age Group": "25-34",
393
+ "Male": "2600",
394
+ "Female": "1800"
395
+ },
396
+ {
397
+ "Year": "2022",
398
+ "Age Group": "35-44",
399
+ "Male": "1800",
400
+ "Female": "1200"
401
+ },
402
+ {
403
+ "Year": "2023",
404
+ "Age Group": "45-54",
405
+ "Male": "1200",
406
+ "Female": "700"
407
+ },
408
+ {
409
+ "Year": "2024",
410
+ "Age Group": "55-64",
411
+ "Male": "800",
412
+ "Female": "500"
413
+ }
414
+ ],
415
+ "dataDescription": {
416
+ "horizontal": false,
417
+ "series": true,
418
+ "singleRow": true
419
+ },
420
+ "version": "4.24.10"
421
+ }