@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
@@ -1,218 +0,0 @@
1
- [
2
- {
3
- "location": "united_states",
4
- "age": "all_ages",
5
- "use": "excessive_alcohol_use",
6
- "data_group": "sex",
7
- "data_sub_group": null,
8
- "overall": "104,557",
9
- "males": "97,182",
10
- "females": "43,375",
11
- "0-19": null,
12
- "20-34": null,
13
- "35-49": null,
14
- "50-64": null,
15
- "65+": null,
16
- "cause_type": "all_causes",
17
- "cause_category": "summary",
18
- "row_type": "row_group_total"
19
- },
20
- {
21
- "location": "united_states",
22
- "age": "all_ages",
23
- "use": "excessive_alcohol_use",
24
- "data_group": "age",
25
- "data_sub_group": "overall",
26
- "overall": null,
27
- "males": null,
28
- "females": null,
29
- "0-19": "123",
30
- "20-34": "123",
31
- "35-49": "123",
32
- "50-64": "123",
33
- "65+": "123",
34
- "cause_type": "all_causes",
35
- "cause_category": "summary",
36
- "row_type": "row_group_total"
37
- },
38
- {
39
- "location": "united_states",
40
- "age": "all_ages",
41
- "use": "excessive_alcohol_use",
42
- "data_group": "age",
43
- "data_sub_group": "male_only",
44
- "overall": null,
45
- "males": null,
46
- "females": null,
47
- "0-19": "123",
48
- "20-34": "123",
49
- "35-49": "123",
50
- "50-64": "123",
51
- "65+": "123",
52
- "cause_type": "all_causes",
53
- "cause_category": "summary",
54
- "row_type": "row_group_total"
55
- },
56
- {
57
- "location": "united_states",
58
- "age": "all_ages",
59
- "use": "excessive_alcohol_use",
60
- "data_group": "age",
61
- "data_sub_group": "female_only",
62
- "overall": null,
63
- "males": null,
64
- "females": null,
65
- "0-19": "123",
66
- "20-34": "123",
67
- "35-49": "123",
68
- "50-64": "123",
69
- "65+": "123",
70
- "cause_type": "all_causes",
71
- "cause_category": "summary",
72
- "row_type": "row_group_total"
73
- },
74
- {
75
- "location": "united_states",
76
- "age": "all_ages",
77
- "use": "excessive_alcohol_use",
78
- "data_group": "sex",
79
- "data_sub_group": null,
80
- "overall": "58,277",
81
- "males": "43,063",
82
- "females": "15,214",
83
- "0-19": null,
84
- "20-34": null,
85
- "35-49": null,
86
- "50-64": null,
87
- "65+": null,
88
- "cause_type": "acute_causes",
89
- "cause_category": "summary",
90
- "row_type": null
91
- },
92
- {
93
- "location": "united_states",
94
- "age": "all_ages",
95
- "use": "excessive_alcohol_use",
96
- "data_group": "age",
97
- "data_sub_group": "overall",
98
- "overall": null,
99
- "males": null,
100
- "females": null,
101
- "0-19": "123",
102
- "20-34": "123",
103
- "35-49": "123",
104
- "50-64": "123",
105
- "65+": "123",
106
- "cause_type": "acute_causes",
107
- "cause_category": "summary",
108
- "row_type": null
109
- },
110
- {
111
- "location": "united_states",
112
- "age": "all_ages",
113
- "use": "excessive_alcohol_use",
114
- "data_group": "age",
115
- "data_sub_group": "male_only",
116
- "overall": null,
117
- "males": null,
118
- "females": null,
119
- "0-19": "123",
120
- "20-34": "123",
121
- "35-49": "123",
122
- "50-64": "123",
123
- "65+": "123",
124
- "cause_type": "acute_causes",
125
- "cause_category": "summary",
126
- "row_type": null
127
- },
128
- {
129
- "location": "united_states",
130
- "age": "all_ages",
131
- "use": "excessive_alcohol_use",
132
- "data_group": "age",
133
- "data_sub_group": "female_only",
134
- "overall": null,
135
- "males": null,
136
- "females": null,
137
- "0-19": "123",
138
- "20-34": "123",
139
- "35-49": "123",
140
- "50-64": "123",
141
- "65+": "123",
142
- "cause_type": "acute_causes",
143
- "cause_category": "summary",
144
- "row_type": null
145
- },
146
- {
147
- "location": "united_states",
148
- "age": "all_ages",
149
- "use": "excessive_alcohol_use",
150
- "data_group": "sex",
151
- "data_sub_group": null,
152
- "overall": "82,279",
153
- "males": "54,119",
154
- "females": "28,161",
155
- "0-19": null,
156
- "20-34": null,
157
- "35-49": null,
158
- "50-64": null,
159
- "65+": null,
160
- "cause_type": "chronic_causes",
161
- "cause_category": "summary",
162
- "row_type": null
163
- },
164
- {
165
- "location": "united_states",
166
- "age": "all_ages",
167
- "use": "excessive_alcohol_use",
168
- "data_group": "age",
169
- "data_sub_group": "overall",
170
- "overall": null,
171
- "males": null,
172
- "females": null,
173
- "0-19": "123",
174
- "20-34": "123",
175
- "35-49": "123",
176
- "50-64": "123",
177
- "65+": "123",
178
- "cause_type": "chronic_causes",
179
- "cause_category": "summary",
180
- "row_type": null
181
- },
182
- {
183
- "location": "united_states",
184
- "age": "all_ages",
185
- "use": "excessive_alcohol_use",
186
- "data_group": "age",
187
- "data_sub_group": "male_only",
188
- "overall": null,
189
- "males": null,
190
- "females": null,
191
- "0-19": "123",
192
- "20-34": "123",
193
- "35-49": "123",
194
- "50-64": "123",
195
- "65+": "123",
196
- "cause_type": "chronic_causes",
197
- "cause_category": "summary",
198
- "row_type": null
199
- },
200
- {
201
- "location": "united_states",
202
- "age": "all_ages",
203
- "use": "excessive_alcohol_use",
204
- "data_group": "age",
205
- "data_sub_group": "female_only",
206
- "overall": null,
207
- "males": null,
208
- "females": null,
209
- "0-19": "123",
210
- "20-34": "123",
211
- "35-49": "123",
212
- "50-64": "123",
213
- "65+": "123",
214
- "cause_type": "chronic_causes",
215
- "cause_category": "summary",
216
- "row_type": null
217
- }
218
- ]
@@ -1,109 +0,0 @@
1
- import React, { useContext, memo } from 'react'
2
-
3
- // cdc
4
- import ConfigContext from '../../../ConfigContext'
5
- import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
6
- import { isDateScale } from '@cdc/core/helpers/cove/date'
7
-
8
- // visx & d3
9
- import * as allCurves from '@visx/curve'
10
- import { AreaClosed, LinePath, Bar } from '@visx/shape'
11
- import { Group } from '@visx/group'
12
-
13
- const AreaChart = props => {
14
- const { xScale, yScale, yMax, xMax, handleTooltipMouseOver, handleTooltipMouseOff } = props
15
- // import data from context
16
- let {
17
- transformedData: data,
18
- config,
19
- handleLineType,
20
- parseDate,
21
-
22
- seriesHighlight,
23
- colorScale,
24
- rawData
25
- } = useContext(ConfigContext)
26
-
27
- if (!data) return
28
-
29
- const handleX = d => {
30
- return (
31
- (isDateScale(config.xAxis)
32
- ? xScale(parseDate(d[config.xAxis.dataKey], false))
33
- : xScale(d[config.xAxis.dataKey])) + (xScale.bandwidth ? xScale.bandwidth() / 2 : 0)
34
- )
35
- }
36
-
37
- const handleY = (d, index, s = undefined) => {
38
- return yScale(d[s.dataKey])
39
- }
40
-
41
- return (
42
- data && (
43
- <svg>
44
- <ErrorBoundary component='AreaChart'>
45
- <Group className='area-chart' key='area-wrapper' left={Number(config.yAxis.size)}>
46
- {(config.runtime.areaSeriesKeys || config.series).map((s, index) => {
47
- let seriesData = data.map(d => {
48
- return {
49
- [config.xAxis.dataKey]: d[config.xAxis.dataKey],
50
- [s.dataKey]: d[s.dataKey]
51
- }
52
- })
53
-
54
- let curveType = allCurves[s.lineType]
55
- let transparentArea =
56
- config.legend.behavior === 'highlight' &&
57
- seriesHighlight.length > 0 &&
58
- seriesHighlight.indexOf(s.dataKey) === -1
59
- let displayArea =
60
- config.legend.behavior === 'highlight' ||
61
- seriesHighlight.length === 0 ||
62
- seriesHighlight.indexOf(s.dataKey) !== -1
63
-
64
- return (
65
- <React.Fragment key={index}>
66
- {/* prettier-ignore */}
67
- <LinePath
68
- data={seriesData}
69
- x={d => handleX(d)}
70
- y={d => handleY(d, index, s)}
71
- stroke={displayArea ? colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[s.dataKey] : s.dataKey) : '#000' : 'transparent'}
72
- strokeWidth={2}
73
- strokeOpacity={1}
74
- shapeRendering='geometricPrecision'
75
- curve={curveType}
76
- strokeDasharray={s.type ? handleLineType(s.type) : 0}
77
- />
78
-
79
- {/* prettier-ignore */}
80
- <AreaClosed
81
- key={'area-chart'}
82
- fill={displayArea ? colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[s.dataKey] : s.dataKey) : '#000' : 'transparent'}
83
- fillOpacity={transparentArea ? 0.25 : 0.5}
84
- data={seriesData}
85
- x={d => handleX(d)}
86
- y={d => handleY(d, index, s)}
87
- yScale={yScale}
88
- curve={curveType}
89
- strokeDasharray={s.type ? handleLineType(s.type) : 0}
90
- />
91
- </React.Fragment>
92
- )
93
- })}
94
- <Bar
95
- width={Number(xMax)}
96
- height={Number(yMax)}
97
- fill={'transparent'}
98
- fillOpacity={0.05}
99
- onMouseMove={e => handleTooltipMouseOver(e, rawData)}
100
- onMouseLeave={handleTooltipMouseOff}
101
- />
102
- </Group>
103
- </ErrorBoundary>
104
- </svg>
105
- )
106
- )
107
- }
108
-
109
- export default memo(AreaChart)
@@ -1,7 +0,0 @@
1
- export const sortAsc = (a, b) => {
2
- return a.toString().localeCompare(b.toString(), 'en', { numeric: true })
3
- }
4
-
5
- export const sortDesc = (a, b) => {
6
- return b.toString().localeCompare(a.toString(), 'en', { numeric: true })
7
- }
@@ -1,19 +0,0 @@
1
- import { useState, useEffect } from 'react'
2
- // Use for accessibility testing
3
- const useActiveElement = () => {
4
- const [active, setActive] = useState(document.activeElement)
5
-
6
- const handleFocusIn = e => {
7
- setActive(document.activeElement)
8
- }
9
-
10
- useEffect(() => {
11
- document.addEventListener('focusin', handleFocusIn)
12
- return () => {
13
- document.removeEventListener('focusin', handleFocusIn)
14
- }
15
- }, [])
16
-
17
- return active
18
- }
19
- export default useActiveElement
@@ -1,41 +0,0 @@
1
- export default function useChartClasses(config) {
2
- let lineDatapointClass = ''
3
- let barBorderClass = ''
4
-
5
- if (config.lineDatapointStyle === 'hover') {
6
- lineDatapointClass = ' chart-line--hover'
7
- }
8
- if (config.lineDatapointStyle === 'always show') {
9
- lineDatapointClass = ' chart-line--always'
10
- }
11
- if (config.barHasBorder === 'false') {
12
- barBorderClass = ' chart-bar--no-border'
13
- }
14
-
15
- let innerContainerClasses = ['cove-component__inner']
16
- config.title && innerContainerClasses.push('component--has-title')
17
- config.subtext && innerContainerClasses.push('component--has-subtext')
18
- config.biteStyle && innerContainerClasses.push(`bite__style--${config.biteStyle}`)
19
- config.general?.isCompactStyle && innerContainerClasses.push(`component--isCompactStyle`)
20
-
21
- let contentClasses = ['cove-component__content']
22
- config.visualizationType === 'Spark Line' && contentClasses.push('sparkline')
23
- !config.visual?.border && contentClasses.push('no-borders')
24
- config.visual?.borderColorTheme && contentClasses.push('component--has-borderColorTheme')
25
- config.visual?.accent && contentClasses.push('component--has-accent')
26
- config.visual?.background && contentClasses.push('component--has-background')
27
- config.visual?.hideBackgroundColor && contentClasses.push('component--hideBackgroundColor')
28
-
29
- let sparkLineStyles = {
30
- width: '100%',
31
- height: '100px'
32
- }
33
-
34
- return {
35
- barBorderClass,
36
- lineDatapointClass,
37
- contentClasses,
38
- innerContainerClasses,
39
- sparkLineStyles
40
- }
41
- }