@cdc/chart 4.25.8 → 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 (145) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/dist/{cdcchart-1a1724a1.es.js → cdcchart-dgT_1dIT.es.js} +136 -151
  3. package/dist/cdcchart.js +44236 -40355
  4. package/examples/feature/__data__/planet-example-data.json +0 -30
  5. package/examples/feature/boxplot/valid-boxplot.csv +38 -17
  6. package/examples/grouped-bar-test.json +400 -0
  7. package/examples/private/DEV-11825.json +573 -0
  8. package/examples/private/d.json +382 -0
  9. package/examples/private/example-2.json +49784 -0
  10. package/examples/private/f2.json +1 -0
  11. package/examples/private/f4.json +1577 -0
  12. package/examples/private/forecast.json +1180 -0
  13. package/examples/private/lollipop.json +468 -0
  14. package/examples/private/na.json +913 -0
  15. package/examples/private/new.json +48756 -0
  16. package/examples/private/pie-chart-legend.json +904 -0
  17. package/examples/private/test-data.csv +28 -0
  18. package/examples/suppressed_tooltip.json +480 -0
  19. package/index.html +2 -133
  20. package/package.json +25 -7
  21. package/src/CdcChart.tsx +9 -13
  22. package/src/CdcChartComponent.tsx +403 -92
  23. package/src/_stories/Chart.Anchors.stories.tsx +2 -2
  24. package/src/_stories/Chart.BoxPlot.stories.tsx +1 -1
  25. package/src/_stories/Chart.CI.stories.tsx +1 -1
  26. package/src/_stories/Chart.Combo.stories.tsx +18 -0
  27. package/src/_stories/Chart.CustomColors.stories.tsx +1 -1
  28. package/src/_stories/Chart.DynamicSeries.stories.tsx +2 -2
  29. package/src/_stories/Chart.Filters.stories.tsx +2 -2
  30. package/src/_stories/Chart.Forecast.stories.tsx +36 -0
  31. package/src/_stories/Chart.HTMLInDataTable.stories.tsx +520 -0
  32. package/src/_stories/Chart.Legend.Gradient.stories.tsx +2 -2
  33. package/src/_stories/Chart.Patterns.stories.tsx +20 -0
  34. package/src/_stories/Chart.PreserveDecimals.stories.tsx +220 -0
  35. package/src/_stories/Chart.ScatterPlot.stories.tsx +1 -1
  36. package/src/_stories/Chart.SmallMultiples.stories.tsx +47 -0
  37. package/src/_stories/Chart.stories.tsx +8 -5
  38. package/src/_stories/Chart.tooltip.stories.tsx +1 -1
  39. package/src/_stories/ChartAnnotation.stories.tsx +7 -4
  40. package/src/_stories/ChartAxisLabels.stories.tsx +2 -2
  41. package/src/_stories/ChartAxisTitles.stories.tsx +2 -2
  42. package/src/_stories/ChartBar.Editor.stories.tsx +3580 -0
  43. package/src/_stories/ChartEditor.Editor.stories.tsx +658 -0
  44. package/src/_stories/ChartEditor.stories.tsx +59 -60
  45. package/src/_stories/ChartLine.Suppression.stories.tsx +1 -1
  46. package/src/_stories/ChartLine.Symbols.stories.tsx +1 -1
  47. package/src/_stories/ChartPrefixSuffix.stories.tsx +2 -2
  48. package/src/_stories/_mock/combo.json +451 -0
  49. package/src/_stories/_mock/editor-test-configs.json +376 -0
  50. package/src/_stories/_mock/editor-test-datasets.json +477 -0
  51. package/src/_stories/_mock/editor-tests/bar-chart-editor-test.json +255 -0
  52. package/src/_stories/_mock/editor-tests/bar-chart-general-test.json +267 -0
  53. package/src/_stories/_mock/editor-tests/bar-chart-test.json +237 -0
  54. package/src/_stories/_mock/forecast_combo_with_gaps.json +913 -0
  55. package/src/_stories/_mock/pie_config.json +257 -62
  56. package/src/_stories/_mock/small_multiples/small_multiples_bars.json +1944 -0
  57. package/src/_stories/_mock/small_multiples/small_multiples_big_data_bars.json +1114 -0
  58. package/src/_stories/_mock/small_multiples/small_multiples_lines.json +2646 -0
  59. package/src/_stories/_mock/small_multiples/small_multiples_lines_colors.json +1305 -0
  60. package/src/_stories/_mock/small_multiples/small_multiples_stacked_bars.json +1936 -0
  61. package/src/_stories/_mock/stacked-pattern-test.json +520 -0
  62. package/src/components/Annotations/components/AnnotationDraggable.tsx +1 -0
  63. package/src/components/Annotations/components/AnnotationDropdown.tsx +1 -1
  64. package/src/components/Annotations/components/findNearestDatum.ts +6 -41
  65. package/src/components/AreaChart/components/AreaChart.Stacked.jsx +10 -6
  66. package/src/components/AreaChart/index.tsx +1 -2
  67. package/src/components/BarChart/components/BarChart.Horizontal.tsx +161 -22
  68. package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +138 -5
  69. package/src/components/BarChart/components/BarChart.StackedVertical.tsx +215 -73
  70. package/src/components/BarChart/components/BarChart.Vertical.tsx +155 -22
  71. package/src/components/BarChart/helpers/index.ts +43 -4
  72. package/src/components/BarChart/helpers/lollipopColors.ts +27 -0
  73. package/src/components/BarChart/helpers/useBarChart.ts +25 -3
  74. package/src/components/BoxPlot/BoxPlot.Vertical.tsx +2 -1
  75. package/src/components/BoxPlot/helpers/index.ts +3 -3
  76. package/src/components/Brush/BrushChart.tsx +1 -1
  77. package/src/components/DeviationBar.jsx +9 -6
  78. package/src/components/EditorPanel/EditorPanel.tsx +563 -229
  79. package/src/components/EditorPanel/EditorPanelContext.ts +3 -0
  80. package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +96 -111
  81. package/src/components/EditorPanel/components/Panels/Panel.General.tsx +19 -1
  82. package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +461 -0
  83. package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +80 -67
  84. package/src/components/EditorPanel/components/Panels/Panel.SmallMultiples.tsx +422 -0
  85. package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +188 -139
  86. package/src/components/EditorPanel/components/Panels/index.tsx +5 -1
  87. package/src/components/EditorPanel/components/Panels/panelVisual.styles.css +0 -8
  88. package/src/components/EditorPanel/editor-panel.scss +0 -20
  89. package/src/components/EditorPanel/helpers/updateFieldRankByValue.ts +49 -48
  90. package/src/components/EditorPanel/useEditorPermissions.ts +7 -15
  91. package/src/components/Forecasting/Forecasting.tsx +175 -27
  92. package/src/components/ForestPlot/ForestPlot.tsx +11 -7
  93. package/src/components/ForestPlot/ForestPlotProps.ts +1 -1
  94. package/src/components/Legend/Legend.Component.tsx +114 -14
  95. package/src/components/Legend/helpers/createFormatLabels.tsx +230 -171
  96. package/src/components/Legend/helpers/getLegendClasses.ts +0 -1
  97. package/src/components/LegendWrapper.tsx +1 -1
  98. package/src/components/LineChart/LineChartProps.ts +0 -3
  99. package/src/components/LineChart/components/LineChart.Circle.tsx +2 -2
  100. package/src/components/LineChart/helpers.ts +1 -1
  101. package/src/components/LineChart/index.tsx +38 -15
  102. package/src/components/LinearChart.tsx +96 -84
  103. package/src/components/PairedBarChart.jsx +6 -4
  104. package/src/components/PieChart/PieChart.tsx +170 -54
  105. package/src/components/Regions/components/Regions.tsx +3 -24
  106. package/src/components/Sankey/components/Sankey.tsx +7 -1
  107. package/src/components/Sankey/types/index.ts +1 -1
  108. package/src/components/ScatterPlot/ScatterPlot.jsx +32 -4
  109. package/src/components/SmallMultiples/SmallMultipleTile.tsx +198 -0
  110. package/src/components/SmallMultiples/SmallMultiples.css +32 -0
  111. package/src/components/SmallMultiples/SmallMultiples.tsx +271 -0
  112. package/src/components/SmallMultiples/index.ts +2 -0
  113. package/src/data/initial-state.js +327 -293
  114. package/src/helpers/buildForecastPaletteMappings.ts +112 -0
  115. package/src/helpers/buildForecastPaletteOptions.ts +71 -0
  116. package/src/helpers/getColorScale.ts +82 -8
  117. package/src/{hooks/useMinMax.ts → helpers/getMinMax.ts} +14 -7
  118. package/src/helpers/getNewRuntime.ts +1 -1
  119. package/src/helpers/getTransformedData.ts +1 -1
  120. package/src/helpers/getYAxisAutoPadding.ts +53 -0
  121. package/src/helpers/smallMultiplesHelpers.ts +529 -0
  122. package/src/hooks/useChartHoverAnalytics.tsx +44 -0
  123. package/src/hooks/useProgrammaticTooltip.ts +96 -0
  124. package/src/hooks/useReduceData.ts +105 -70
  125. package/src/hooks/useScales.ts +88 -34
  126. package/src/hooks/useSmallMultipleSynchronization.ts +59 -0
  127. package/src/hooks/useTooltip.tsx +116 -29
  128. package/src/index.jsx +0 -2
  129. package/src/scss/main.scss +13 -80
  130. package/src/store/chart.actions.ts +2 -0
  131. package/src/store/chart.reducer.ts +5 -1
  132. package/src/test/CdcChart.test.jsx +8 -3
  133. package/src/types/ChartConfig.ts +53 -11
  134. package/src/types/ChartContext.ts +4 -0
  135. package/vite.config.js +1 -1
  136. package/vitest.config.ts +16 -0
  137. package/src/_stories/_mock/pie_data.json +0 -218
  138. package/src/components/AreaChart/components/AreaChart.jsx +0 -109
  139. package/src/coreStyles_chart.scss +0 -3
  140. package/src/helpers/configHelpers.ts +0 -28
  141. package/src/helpers/generateColorsArray.ts +0 -8
  142. package/src/helpers/sort.ts +0 -7
  143. package/src/hooks/useActiveElement.js +0 -19
  144. package/src/hooks/useChartClasses.js +0 -41
  145. package/src/hooks/useColorPalette.js +0 -76
@@ -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,3 +0,0 @@
1
- @import '@cdc/core/styles/base';
2
- @import '@cdc/core/styles/heading-colors';
3
- @import '@cdc/core/styles/v2/themes/color-definitions';
@@ -1,28 +0,0 @@
1
- import { cloneDeep } from 'lodash'
2
- import { ChartConfig } from '../types/ChartConfig'
3
-
4
- /* editConfigKeys
5
- * Add edit or update config keys
6
- * keyUpdates: { path: string[], value: any }[]
7
- * path is the array of keys needed to reach the value to be updated
8
- * value is the new value to be set
9
- * if the key does not exist, it will be created
10
- */
11
- export function editConfigKeys(config: ChartConfig, keyUpdates: { path: string[]; value: any }[]): ChartConfig {
12
- const configDeepCopy = cloneDeep(config)
13
-
14
- const newConfig = keyUpdates.reduce((acc, { path, value }) => {
15
- const pathCopy = [...path]
16
- const lastKey = pathCopy.pop()
17
- const target = pathCopy.reduce((target, key) => {
18
- if (!target[key]) {
19
- target[key] = {}
20
- }
21
- return target[key]
22
- }, acc)
23
- target[lastKey] = value
24
- return acc
25
- }, configDeepCopy)
26
-
27
- return newConfig
28
- }
@@ -1,8 +0,0 @@
1
- import chroma from 'chroma-js'
2
-
3
- export const generateColorsArray = (color = '#000000', special = false) => {
4
- let colorObj = chroma(color)
5
- let hoverColor = special ? colorObj.brighten(0.5).hex() : colorObj.saturate(1.3).hex()
6
-
7
- return [color, hoverColor, colorObj.darken(0.3).hex()]
8
- }
@@ -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
- }
@@ -1,76 +0,0 @@
1
- import { colorPalettesChart, twoColorPalette } from '@cdc/core/data/colorPalettes'
2
- import { useEffect } from 'react'
3
-
4
- export const useColorPalette = (config, updateConfig) => {
5
- let twoColorPalettes = []
6
- let sequential = []
7
- let nonSequential = []
8
- const accessibleColors = []
9
-
10
- // Get two color palettes if visualization type is Paired Bar
11
- if (config.visualizationType === 'Paired Bar' || config.visualizationType === 'Deviation Bar') {
12
- const isReversed = config.twoColor.isPaletteReversed
13
- twoColorPalettes = Object.keys(twoColorPalette).filter(name =>
14
- isReversed ? name.endsWith('reverse') : !name.endsWith('reverse')
15
- )
16
- } else {
17
- // Get sequential and non-sequential palettes for other visualization types
18
- const seqPalettes = []
19
- const nonSeqPalettes = []
20
-
21
- for (const paletteName in colorPalettesChart) {
22
- const isSequential = paletteName.startsWith('sequential')
23
- const isQualitative = paletteName.startsWith('qualitative')
24
- const colorblindsafe = paletteName.startsWith('colorblindsafe')
25
- const isReversed = paletteName.endsWith('reverse')
26
-
27
- if (isSequential && ((!config.isPaletteReversed && !isReversed) || (config.isPaletteReversed && isReversed))) {
28
- seqPalettes.push(paletteName)
29
- }
30
-
31
- if (isQualitative && ((!config.isPaletteReversed && !isReversed) || (config.isPaletteReversed && isReversed))) {
32
- nonSeqPalettes.push(paletteName)
33
- }
34
- if (colorblindsafe && ((!config.isPaletteReversed && !isReversed) || (config.isPaletteReversed && isReversed))) {
35
- accessibleColors.push(paletteName)
36
- }
37
- }
38
-
39
- sequential = seqPalettes
40
- nonSequential = nonSeqPalettes
41
- }
42
-
43
- // Update pairedBar.palette based on isPaletteReversed
44
- useEffect(() => {
45
- let palette = ''
46
-
47
- if (config.twoColor.isPaletteReversed && !config.twoColor.palette.endsWith('reverse')) {
48
- palette = config.twoColor.palette + 'reverse'
49
- }
50
-
51
- if (!config.twoColor.isPaletteReversed && config.twoColor.palette.endsWith('reverse')) {
52
- palette = config.twoColor.palette.slice(0, -7)
53
- }
54
-
55
- updateConfig({ ...config, twoColor: { ...config.twoColor, palette: palette } })
56
- }, [config.twoColor.isPaletteReversed])
57
-
58
- // Update palette based on isPaletteReversed
59
- useEffect(() => {
60
- let palette = ''
61
-
62
- if (config.isPaletteReversed && !config.palette.endsWith('reverse')) {
63
- palette = config.palette + 'reverse'
64
- }
65
-
66
- if (!config.isPaletteReversed && config.palette.endsWith('reverse')) {
67
- palette = config.palette.slice(0, -7)
68
- }
69
-
70
- updateConfig({ ...config, palette: palette })
71
- }, [config.isPaletteReversed])
72
-
73
- // Return all palettes
74
-
75
- return { twoColorPalettes, sequential, nonSequential, accessibleColors }
76
- }