@cdc/chart 4.25.10 → 4.25.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.
Files changed (85) hide show
  1. package/dist/{cdcchart-1a1724a1.es.js → cdcchart-dgT_1dIT.es.js} +136 -151
  2. package/dist/cdcchart.js +36258 -34658
  3. package/examples/feature/__data__/planet-example-data.json +1 -1
  4. package/examples/feature/boxplot/valid-boxplot.csv +38 -17
  5. package/examples/private/DEV-11825.json +573 -0
  6. package/examples/private/na.json +913 -0
  7. package/examples/private/test-data.csv +28 -0
  8. package/index.html +2 -121
  9. package/package.json +4 -4
  10. package/src/CdcChart.tsx +8 -11
  11. package/src/CdcChartComponent.tsx +256 -87
  12. package/src/_stories/Chart.Combo.stories.tsx +18 -0
  13. package/src/_stories/Chart.Forecast.stories.tsx +36 -0
  14. package/src/_stories/Chart.HTMLInDataTable.stories.tsx +520 -0
  15. package/src/_stories/Chart.Patterns.stories.tsx +2 -1
  16. package/src/_stories/Chart.PreserveDecimals.stories.tsx +220 -0
  17. package/src/_stories/Chart.SmallMultiples.stories.tsx +47 -0
  18. package/src/_stories/ChartAnnotation.stories.tsx +6 -3
  19. package/src/_stories/ChartBar.Editor.stories.tsx +3580 -0
  20. package/src/_stories/ChartEditor.Editor.stories.tsx +658 -0
  21. package/src/_stories/ChartEditor.stories.tsx +1 -2
  22. package/src/_stories/_mock/combo.json +451 -0
  23. package/src/_stories/_mock/editor-test-configs.json +376 -0
  24. package/src/_stories/_mock/editor-test-datasets.json +477 -0
  25. package/src/_stories/_mock/editor-tests/bar-chart-editor-test.json +255 -0
  26. package/src/_stories/_mock/editor-tests/bar-chart-general-test.json +267 -0
  27. package/src/_stories/_mock/editor-tests/bar-chart-test.json +237 -0
  28. package/src/_stories/_mock/forecast_combo_with_gaps.json +913 -0
  29. package/src/_stories/_mock/pie_config.json +257 -62
  30. package/src/_stories/_mock/small_multiples/small_multiples_bars.json +1944 -0
  31. package/src/_stories/_mock/small_multiples/small_multiples_big_data_bars.json +1114 -0
  32. package/src/_stories/_mock/small_multiples/small_multiples_lines.json +2646 -0
  33. package/src/_stories/_mock/small_multiples/small_multiples_lines_colors.json +1305 -0
  34. package/src/_stories/_mock/small_multiples/small_multiples_stacked_bars.json +1936 -0
  35. package/src/components/Annotations/components/findNearestDatum.ts +6 -41
  36. package/src/components/AreaChart/components/AreaChart.Stacked.jsx +10 -6
  37. package/src/components/AreaChart/index.tsx +1 -2
  38. package/src/components/BarChart/components/BarChart.Horizontal.tsx +4 -4
  39. package/src/components/BarChart/components/BarChart.Vertical.tsx +3 -2
  40. package/src/components/BoxPlot/helpers/index.ts +3 -3
  41. package/src/components/Brush/BrushChart.tsx +1 -1
  42. package/src/components/EditorPanel/EditorPanel.tsx +199 -190
  43. package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +96 -111
  44. package/src/components/EditorPanel/components/Panels/Panel.General.tsx +19 -1
  45. package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +102 -55
  46. package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +54 -49
  47. package/src/components/EditorPanel/components/Panels/Panel.SmallMultiples.tsx +422 -0
  48. package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +75 -21
  49. package/src/components/EditorPanel/components/Panels/index.tsx +3 -1
  50. package/src/components/EditorPanel/editor-panel.scss +0 -20
  51. package/src/components/EditorPanel/useEditorPermissions.ts +7 -15
  52. package/src/components/Forecasting/Forecasting.tsx +139 -21
  53. package/src/components/Legend/Legend.Component.tsx +16 -9
  54. package/src/components/Legend/helpers/createFormatLabels.tsx +181 -181
  55. package/src/components/Legend/helpers/getLegendClasses.ts +0 -1
  56. package/src/components/LineChart/LineChartProps.ts +0 -3
  57. package/src/components/LineChart/helpers.ts +1 -1
  58. package/src/components/LineChart/index.tsx +36 -13
  59. package/src/components/LinearChart.tsx +75 -80
  60. package/src/components/Regions/components/Regions.tsx +3 -24
  61. package/src/components/Sankey/types/index.ts +1 -1
  62. package/src/components/SmallMultiples/SmallMultipleTile.tsx +198 -0
  63. package/src/components/SmallMultiples/SmallMultiples.css +32 -0
  64. package/src/components/SmallMultiples/SmallMultiples.tsx +271 -0
  65. package/src/components/SmallMultiples/index.ts +2 -0
  66. package/src/data/initial-state.js +13 -1
  67. package/src/helpers/buildForecastPaletteOptions.ts +0 -38
  68. package/src/helpers/getColorScale.ts +10 -0
  69. package/src/{hooks/useMinMax.ts → helpers/getMinMax.ts} +14 -7
  70. package/src/helpers/getYAxisAutoPadding.ts +53 -0
  71. package/src/helpers/smallMultiplesHelpers.ts +529 -0
  72. package/src/hooks/useProgrammaticTooltip.ts +96 -0
  73. package/src/hooks/useScales.ts +88 -34
  74. package/src/hooks/useSmallMultipleSynchronization.ts +59 -0
  75. package/src/hooks/useTooltip.tsx +60 -15
  76. package/src/scss/main.scss +1 -80
  77. package/src/store/chart.actions.ts +2 -0
  78. package/src/store/chart.reducer.ts +4 -0
  79. package/src/types/ChartConfig.ts +24 -6
  80. package/src/types/ChartContext.ts +3 -0
  81. package/src/_stories/_mock/pie_data.json +0 -218
  82. package/src/components/AreaChart/components/AreaChart.jsx +0 -109
  83. package/src/helpers/sort.ts +0 -7
  84. package/src/hooks/useActiveElement.js +0 -19
  85. package/src/hooks/useChartClasses.js +0 -41
@@ -0,0 +1,520 @@
1
+ import { Meta, StoryObj } from '@storybook/react-vite'
2
+ import CdcChart from '../CdcChartComponent'
3
+
4
+ const meta: Meta<typeof CdcChart> = {
5
+ title: 'Components/Templates/Chart/HTML in Data Table',
6
+ component: CdcChart,
7
+ parameters: {
8
+ docs: {
9
+ description: {
10
+ component:
11
+ 'Demonstrates charts with HTML content rendered in data table columns, including footnotes, links, and formatted text.'
12
+ }
13
+ }
14
+ }
15
+ }
16
+
17
+ export default meta
18
+
19
+ type Story = StoryObj<typeof CdcChart>
20
+
21
+ // Sample data with HTML footnotes as a column
22
+ const sampleDataWithHTMLFootnotes = [
23
+ {
24
+ State: 'California',
25
+ VaccinationRate: 82.4,
26
+ Year: 2023,
27
+ Category: 'High',
28
+ Footnote: 'Data from <strong>CDC National Immunization Survey</strong>'
29
+ },
30
+ {
31
+ State: 'Connecticut',
32
+ VaccinationRate: 85.6,
33
+ Year: 2023,
34
+ Category: 'High',
35
+ Footnote: 'Coverage rate includes <em>all age groups</em>'
36
+ },
37
+ {
38
+ State: 'Massachusetts',
39
+ VaccinationRate: 87.3,
40
+ Year: 2023,
41
+ Category: 'High',
42
+ Footnote: 'Highest rate in <strong>2023</strong> survey'
43
+ },
44
+ {
45
+ State: 'New York',
46
+ VaccinationRate: 81.2,
47
+ Year: 2023,
48
+ Category: 'High',
49
+ Footnote: 'See <a href="https://www.cdc.gov" target="_blank">CDC.gov</a> for details'
50
+ },
51
+ {
52
+ State: 'Washington',
53
+ VaccinationRate: 80.5,
54
+ Year: 2023,
55
+ Category: 'High',
56
+ Footnote: 'Rate increased <strong>5%</strong> from previous year'
57
+ },
58
+ {
59
+ State: 'Alabama',
60
+ VaccinationRate: 72.5,
61
+ Year: 2023,
62
+ Category: 'Medium',
63
+ Footnote: 'Medium coverage: <em>60-79%</em> range'
64
+ },
65
+ {
66
+ State: 'Arizona',
67
+ VaccinationRate: 75.8,
68
+ Year: 2023,
69
+ Category: 'Medium',
70
+ Footnote: 'Improving from <strong>previous surveys</strong>'
71
+ },
72
+ {
73
+ State: 'Colorado',
74
+ VaccinationRate: 79.1,
75
+ Year: 2023,
76
+ Category: 'Medium',
77
+ Footnote: 'Near <em>high coverage</em> threshold'
78
+ }
79
+ ]
80
+
81
+ // Base chart configuration
82
+ const baseChartConfig: any = {
83
+ type: 'chart',
84
+ visualizationType: 'Bar',
85
+ title: 'State Vaccination Coverage Rates',
86
+ showTitle: true,
87
+ theme: 'theme-blue',
88
+ fontSize: 'medium',
89
+ orientation: 'vertical',
90
+ filterBehavior: 'Filter Change',
91
+ filters: [],
92
+ xAxis: {
93
+ label: 'State',
94
+ dataKey: 'State',
95
+ type: 'categorical'
96
+ },
97
+ yAxis: {
98
+ label: 'Vaccination Rate (%)',
99
+ dataKey: 'VaccinationRate',
100
+ type: 'linear'
101
+ },
102
+ series: [
103
+ {
104
+ dataKey: 'VaccinationRate',
105
+ type: 'Bar',
106
+ name: 'Coverage Rate'
107
+ }
108
+ ],
109
+ table: {
110
+ label: 'Data Table',
111
+ expanded: true,
112
+ show: true,
113
+ download: true
114
+ },
115
+ dataFormat: {
116
+ commas: false,
117
+ abbreviated: false,
118
+ roundTo: 1
119
+ },
120
+ data: sampleDataWithHTMLFootnotes
121
+ }
122
+
123
+ // Story 1: Basic HTML in footnote column
124
+ export const BasicHTMLInFootnoteColumn: Story = {
125
+ name: 'Basic HTML in Footnote Column',
126
+ args: {
127
+ config: {
128
+ ...baseChartConfig,
129
+ columns: {
130
+ State: {
131
+ name: 'State',
132
+ label: 'State',
133
+ dataTable: true
134
+ },
135
+ VaccinationRate: {
136
+ name: 'VaccinationRate',
137
+ label: 'Vaccination Rate (%)',
138
+ dataTable: true,
139
+ suffix: '%',
140
+ roundToPlace: 1
141
+ },
142
+ Footnote: {
143
+ name: 'Footnote',
144
+ label: 'Notes',
145
+ dataTable: true,
146
+ tooltips: false
147
+ }
148
+ }
149
+ },
150
+ isEditor: true
151
+ }
152
+ }
153
+
154
+ // Story 2: HTML with links and formatting
155
+ export const HTMLWithLinksAndFormatting: Story = {
156
+ name: 'HTML with Links and Formatting',
157
+ args: {
158
+ config: {
159
+ ...baseChartConfig,
160
+ data: [
161
+ {
162
+ State: 'California',
163
+ VaccinationRate: 82.4,
164
+ Footnote:
165
+ 'Source: <strong>CDC</strong> - <a href="https://www.cdc.gov/vaccines" target="_blank">Vaccine Data</a>\nReporting Period: January - December 2023'
166
+ },
167
+ {
168
+ State: 'Connecticut',
169
+ VaccinationRate: 85.6,
170
+ Footnote: 'Includes <em>all demographics</em>\nContact: <a href="mailto:health@ct.gov">health@ct.gov</a>'
171
+ },
172
+ {
173
+ State: 'Massachusetts',
174
+ VaccinationRate: 87.3,
175
+ Footnote:
176
+ '<strong style="color: #005ea2;">Leading state</strong> in vaccination coverage\nHighest rate in region'
177
+ },
178
+ {
179
+ State: 'New York',
180
+ VaccinationRate: 81.2,
181
+ Footnote: 'Data validated by <em>NYS Department of Health</em>\nSee full report for methodology'
182
+ },
183
+ {
184
+ State: 'Texas',
185
+ VaccinationRate: 69.8,
186
+ Footnote:
187
+ 'More info: <a href="https://dshs.texas.gov" target="_blank">TX DSHS</a>\nOutreach programs available'
188
+ }
189
+ ],
190
+ columns: {
191
+ State: {
192
+ name: 'State',
193
+ label: 'State',
194
+ dataTable: true
195
+ },
196
+ VaccinationRate: {
197
+ name: 'VaccinationRate',
198
+ label: 'Coverage Rate (%)',
199
+ dataTable: true,
200
+ suffix: '%',
201
+ roundToPlace: 1
202
+ },
203
+ Footnote: {
204
+ name: 'Footnote',
205
+ label: 'Additional Information',
206
+ dataTable: true
207
+ }
208
+ }
209
+ },
210
+ isEditor: true
211
+ }
212
+ }
213
+
214
+ // Story 3: HTML with line breaks
215
+ export const HTMLWithLineBreaks: Story = {
216
+ name: 'HTML with Line Breaks',
217
+ args: {
218
+ config: {
219
+ ...baseChartConfig,
220
+ data: [
221
+ {
222
+ State: 'California',
223
+ VaccinationRate: 82.4,
224
+ Footnote: '<strong>Data Source:</strong> CDC Survey<br><em>Collection Period:</em> Jan-Dec 2023'
225
+ },
226
+ {
227
+ State: 'Connecticut',
228
+ VaccinationRate: 85.6,
229
+ Footnote: 'Coverage includes:<br>• Ages 6 months+<br>• All vaccine types'
230
+ },
231
+ {
232
+ State: 'Massachusetts',
233
+ VaccinationRate: 87.3,
234
+ Footnote: 'Leading state for:<br>1. Overall coverage<br>2. Equity metrics'
235
+ },
236
+ {
237
+ State: 'New York',
238
+ VaccinationRate: 81.2,
239
+ Footnote: '<strong>Note:</strong> Excludes NYC<br>See separate report'
240
+ },
241
+ {
242
+ State: 'Washington',
243
+ VaccinationRate: 80.5,
244
+ Footnote: 'Trend: ↑ 5% YoY<br>Target: <strong>85%</strong> by 2024'
245
+ }
246
+ ],
247
+ columns: {
248
+ State: {
249
+ name: 'State',
250
+ label: 'State',
251
+ dataTable: true
252
+ },
253
+ VaccinationRate: {
254
+ name: 'VaccinationRate',
255
+ label: 'Rate (%)',
256
+ dataTable: true,
257
+ suffix: '%',
258
+ roundToPlace: 1
259
+ },
260
+ Footnote: {
261
+ name: 'Footnote',
262
+ label: 'Detailed Notes',
263
+ dataTable: true
264
+ }
265
+ }
266
+ },
267
+ isEditor: true
268
+ }
269
+ }
270
+
271
+ // Story 4: Complex HTML with lists
272
+ export const ComplexHTMLWithLists: Story = {
273
+ name: 'Complex HTML with Lists',
274
+ args: {
275
+ config: {
276
+ ...baseChartConfig,
277
+ data: [
278
+ {
279
+ State: 'California',
280
+ VaccinationRate: 82.4,
281
+ Footnote:
282
+ '<strong>Program Details:</strong><ul style="margin:0;padding-left:20px;"><li>State-funded clinics</li><li>Mobile vaccination units</li></ul>'
283
+ },
284
+ {
285
+ State: 'Connecticut',
286
+ VaccinationRate: 85.6,
287
+ Footnote:
288
+ '<em>Success Factors:</em><br><ol style="margin:0;padding-left:20px;"><li>Community outreach</li><li>School programs</li></ol>'
289
+ },
290
+ {
291
+ State: 'Massachusetts',
292
+ VaccinationRate: 87.3,
293
+ Footnote:
294
+ 'Achievements:<ul style="margin:0;padding-left:20px;"><li><strong>Highest rate</strong> in region</li><li>Improved <em>accessibility</em></li></ul>'
295
+ }
296
+ ],
297
+ columns: {
298
+ State: {
299
+ name: 'State',
300
+ label: 'State',
301
+ dataTable: true
302
+ },
303
+ VaccinationRate: {
304
+ name: 'VaccinationRate',
305
+ label: 'Coverage (%)',
306
+ dataTable: true,
307
+ suffix: '%',
308
+ roundToPlace: 1
309
+ },
310
+ Footnote: {
311
+ name: 'Footnote',
312
+ label: 'Program Information',
313
+ dataTable: true
314
+ }
315
+ }
316
+ },
317
+ isEditor: true
318
+ }
319
+ }
320
+
321
+ // Story 5: HTML with inline styles
322
+ export const HTMLWithInlineStyles: Story = {
323
+ name: 'HTML with Inline Styles',
324
+ args: {
325
+ config: {
326
+ ...baseChartConfig,
327
+ data: [
328
+ {
329
+ State: 'California',
330
+ VaccinationRate: 82.4,
331
+ Footnote:
332
+ '<span style="color: #005ea2; font-weight: bold;">High Priority State</span> - Continued improvement needed'
333
+ },
334
+ {
335
+ State: 'Connecticut',
336
+ VaccinationRate: 85.6,
337
+ Footnote: '<span style="background-color: #f0f0f0; padding: 2px 5px;">Exemplary Performance</span>'
338
+ },
339
+ {
340
+ State: 'Massachusetts',
341
+ VaccinationRate: 87.3,
342
+ Footnote: '<strong style="color: #2e8540;">✓ Target Achieved</strong> - Maintaining high coverage'
343
+ },
344
+ {
345
+ State: 'Texas',
346
+ VaccinationRate: 69.8,
347
+ Footnote: '<span style="color: #d54309;">⚠ Below Target</span> - Outreach initiatives underway'
348
+ }
349
+ ],
350
+ columns: {
351
+ State: {
352
+ name: 'State',
353
+ label: 'State',
354
+ dataTable: true
355
+ },
356
+ VaccinationRate: {
357
+ name: 'VaccinationRate',
358
+ label: 'Rate (%)',
359
+ dataTable: true,
360
+ suffix: '%',
361
+ roundToPlace: 1
362
+ },
363
+ Footnote: {
364
+ name: 'Footnote',
365
+ label: 'Status',
366
+ dataTable: true
367
+ }
368
+ }
369
+ },
370
+ isEditor: true
371
+ }
372
+ }
373
+
374
+ // Story 6: Line chart with HTML footnotes
375
+ export const LineChartWithHTMLFootnotes: Story = {
376
+ name: 'Line Chart with HTML Footnotes',
377
+ args: {
378
+ config: {
379
+ ...baseChartConfig,
380
+ visualizationType: 'Line',
381
+ title: 'Vaccination Rate Trends',
382
+ data: [
383
+ {
384
+ Year: '2019',
385
+ Rate: 72.5,
386
+ Footnote: 'Baseline year - <strong>Pre-pandemic</strong> data'
387
+ },
388
+ {
389
+ Year: '2020',
390
+ Rate: 68.3,
391
+ Footnote: '<em style="color: #d54309;">Pandemic impact</em> - Reduced access to healthcare'
392
+ },
393
+ {
394
+ Year: '2021',
395
+ Rate: 75.8,
396
+ Footnote: 'Recovery begins - <strong>Vaccination campaigns</strong> launched'
397
+ },
398
+ {
399
+ Year: '2022',
400
+ Rate: 80.1,
401
+ Footnote: 'Significant improvement - See <a href="https://www.cdc.gov" target="_blank">CDC report</a>'
402
+ },
403
+ {
404
+ Year: '2023',
405
+ Rate: 82.4,
406
+ Footnote: '<strong style="color: #2e8540;">Target exceeded</strong> - Continued success'
407
+ }
408
+ ],
409
+ xAxis: {
410
+ label: 'Year',
411
+ dataKey: 'Year',
412
+ type: 'categorical'
413
+ },
414
+ yAxis: {
415
+ label: 'Vaccination Rate (%)',
416
+ dataKey: 'Rate',
417
+ type: 'linear'
418
+ },
419
+ series: [
420
+ {
421
+ dataKey: 'Rate',
422
+ type: 'Line',
423
+ name: 'Coverage Rate'
424
+ }
425
+ ],
426
+ columns: {
427
+ Year: {
428
+ name: 'Year',
429
+ label: 'Year',
430
+ dataTable: true
431
+ },
432
+ Rate: {
433
+ name: 'Rate',
434
+ label: 'Rate (%)',
435
+ dataTable: true,
436
+ suffix: '%',
437
+ roundToPlace: 1
438
+ },
439
+ Footnote: {
440
+ name: 'Footnote',
441
+ label: 'Context & Notes',
442
+ dataTable: true
443
+ }
444
+ }
445
+ },
446
+ isEditor: true
447
+ }
448
+ }
449
+
450
+ // Story 7: Pie chart with HTML footnotes
451
+ export const PieChartWithHTMLFootnotes: Story = {
452
+ name: 'Pie Chart with HTML Footnotes',
453
+ args: {
454
+ config: {
455
+ type: 'chart',
456
+ visualizationType: 'Pie',
457
+ title: 'Coverage by Category',
458
+ showTitle: true,
459
+ theme: 'theme-blue',
460
+ fontSize: 'medium',
461
+ filterBehavior: 'Filter Change',
462
+ filters: [],
463
+ data: [
464
+ {
465
+ Category: 'High Coverage',
466
+ Count: 5,
467
+ Percentage: 42,
468
+ Footnote: '<strong>5 states</strong> with ≥80% coverage<br>Leading examples: <em>MA, CT, NY</em>'
469
+ },
470
+ {
471
+ Category: 'Medium Coverage',
472
+ Count: 7,
473
+ Percentage: 58,
474
+ Footnote: '<strong>7 states</strong> with 60-79% coverage<br>Target: Move to <em>high category</em>'
475
+ }
476
+ ],
477
+ series: [
478
+ {
479
+ dataKey: 'Percentage',
480
+ type: 'Pie',
481
+ name: 'Coverage Distribution'
482
+ }
483
+ ],
484
+ table: {
485
+ label: 'Coverage Distribution Data',
486
+ expanded: true,
487
+ show: true,
488
+ download: true
489
+ },
490
+ columns: {
491
+ Category: {
492
+ name: 'Category',
493
+ label: 'Coverage Category',
494
+ dataTable: true
495
+ },
496
+ Count: {
497
+ name: 'Count',
498
+ label: 'Number of States',
499
+ dataTable: true
500
+ },
501
+ Percentage: {
502
+ name: 'Percentage',
503
+ label: 'Percentage',
504
+ dataTable: true,
505
+ suffix: '%'
506
+ },
507
+ Footnote: {
508
+ name: 'Footnote',
509
+ label: 'Details',
510
+ dataTable: true
511
+ }
512
+ },
513
+ dataFormat: {
514
+ commas: false,
515
+ abbreviated: false
516
+ }
517
+ },
518
+ isEditor: true
519
+ }
520
+ }
@@ -12,7 +12,8 @@ type Story = StoryObj<typeof Chart>
12
12
 
13
13
  export const Stacked_Bar_Pattern: Story = {
14
14
  args: {
15
- config: StackedPattern
15
+ config: StackedPattern,
16
+ isEditor: true
16
17
  }
17
18
  }
18
19