@cdc/chart 4.26.4 → 4.26.6
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/CONFIG.md +353 -29
- package/LICENSE +201 -0
- package/dist/{cdcchart-DQ00cQCm.es.js → cdcchart-BWVIUcAF.es.js} +5 -55
- package/dist/cdcchart.js +37885 -35117
- package/examples/feature/heatmap/average-age-categorical.json +313 -0
- package/examples/feature/heatmap/calendar-heatmap.json +134 -0
- package/examples/feature/heatmap/cell-values-bottom-axis.json +181 -0
- package/examples/feature/heatmap/sparse-aggregation.json +158 -0
- package/examples/private/bad-y-axis.json +543 -0
- package/examples/private/bar-chart-negative-value.json +455 -0
- package/examples/private/bump-chart.json +1116 -0
- package/examples/private/test-123.json +624 -0
- package/package.json +4 -3
- package/src/CdcChart.tsx +5 -4
- package/src/CdcChartComponent.tsx +166 -62
- package/src/_stories/Chart.AltText.stories.tsx +136 -0
- package/src/_stories/Chart.HeatMap.stories.tsx +187 -0
- package/src/_stories/Chart.Sankey.smoke.stories.tsx +62 -0
- package/src/_stories/Chart.SeriesColorAssignments.stories.tsx +183 -0
- package/src/_stories/Chart.SmallMultiples.smoke.stories.tsx +29 -0
- package/src/_stories/Chart.YAxisAutoMaxStrategy.stories.tsx +52 -0
- package/src/_stories/Chart.YAxisFilterDomain.stories.tsx +90 -0
- package/src/_stories/ChartAnnotation.smoke.stories.tsx +10 -0
- package/src/_stories/ChartAxisTitles.smoke.stories.tsx +13 -0
- package/src/_stories/ChartBar.Editor.stories.tsx +63 -0
- package/src/_stories/ChartBrush.Interaction.stories.tsx +112 -0
- package/src/_stories/ChartBrush.smoke.stories.tsx +13 -4
- package/src/_stories/_mock/alt_text_metadata.json +38 -0
- package/src/_stories/_mock/annotation_event-line_mock.json +1064 -0
- package/src/_stories/_mock/heatmap-average-age-categorical.json +315 -0
- package/src/_stories/_mock/heatmap.json +156 -0
- package/src/_stories/_mock/reported_pertussis_cases.json +1643 -0
- package/src/_stories/_mock/sankey_mock.json +78 -0
- package/src/_stories/_mock/small_multiples/small_multiples_lines.json +1 -1
- package/src/components/Annotations/components/AnnotationDraggable.styles.css +22 -1
- package/src/components/Annotations/components/AnnotationDraggable.tsx +220 -120
- package/src/components/Annotations/components/AnnotationDropdown.tsx +5 -2
- package/src/components/Annotations/tests/AnnotationDraggable.test.tsx +198 -0
- package/src/components/Axis/LeftAxis.tsx +17 -11
- package/src/components/Axis/LeftAxisGridlines.tsx +22 -12
- package/src/components/Axis/RightAxis.tsx +3 -0
- package/src/components/Axis/tests/AxisTickValues.test.tsx +86 -0
- package/src/components/Brush/BrushSelector.tsx +88 -187
- package/src/components/Brush/brushInteraction.ts +22 -0
- package/src/components/Brush/tests/brushInteraction.test.ts +38 -0
- package/src/components/EditorPanel/EditorPanel.tsx +677 -185
- package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +114 -52
- package/src/components/EditorPanel/components/Panels/Panel.General.tsx +105 -13
- package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +1 -0
- package/src/components/EditorPanel/components/Panels/Panel.Regions.tsx +5 -0
- package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +2 -2
- package/src/components/EditorPanel/components/Panels/Panel.SmallMultiples.test.tsx +98 -0
- package/src/components/EditorPanel/components/Panels/Panel.SmallMultiples.tsx +10 -0
- package/src/components/EditorPanel/components/Panels/Panel.Visual.test.tsx +484 -0
- package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +4 -1
- package/src/components/EditorPanel/components/Panels/SeriesColorAssignments.tsx +262 -0
- package/src/components/EditorPanel/components/Panels/panelVisual.styles.css +32 -0
- package/src/components/EditorPanel/components/panels.scss +10 -0
- package/src/components/EditorPanel/editor-panel.scss +47 -0
- package/src/components/EditorPanel/helpers/getVisualizationTypeConfigUpdate.ts +61 -0
- package/src/components/EditorPanel/helpers/tests/getVisualizationTypeConfigUpdate.test.ts +74 -0
- package/src/components/EditorPanel/useEditorPermissions.test.tsx +315 -0
- package/src/components/EditorPanel/useEditorPermissions.ts +77 -21
- package/src/components/HeatMap/components/HeatMap.tsx +767 -0
- package/src/components/HeatMap/components/HeatMapGradientLegend.tsx +128 -0
- package/src/components/HeatMap/heatmap.constants.ts +13 -0
- package/src/components/HeatMap/heatmap.css +85 -0
- package/src/components/HeatMap/helpers/index.ts +261 -0
- package/src/components/HeatMap/index.tsx +5 -0
- package/src/components/HeatMap/tests/HeatMap.test.tsx +1072 -0
- package/src/components/HeatMap/tests/helpers.test.ts +167 -0
- package/src/components/Legend/Legend.Component.tsx +2 -2
- package/src/components/Legend/helpers/createFormatLabels.test.ts +88 -0
- package/src/components/Legend/helpers/createFormatLabels.tsx +6 -1
- package/src/components/LineChart/components/LineChart.BumpCircle.tsx +19 -22
- package/src/components/LineChart/helpers.test.ts +574 -0
- package/src/components/LineChart/helpers.ts +39 -16
- package/src/components/LineChart/index.tsx +28 -5
- package/src/components/LinearChart/tests/LinearChart.test.tsx +137 -33
- package/src/components/LinearChart/tests/mockConfigContext.ts +1 -0
- package/src/components/LinearChart.tsx +103 -47
- package/src/components/PieChart/PieChart.tsx +4 -1
- package/src/components/RadarChart/RadarChart.tsx +3 -1
- package/src/components/Regions/components/Regions.tsx +195 -41
- package/src/components/Sankey/components/Sankey.tsx +7 -3
- package/src/components/Sankey/helpers/getSankeyTooltip.tsx +7 -6
- package/src/components/ScatterPlot/ScatterPlot.jsx +3 -3
- package/src/components/SmallMultiples/SmallMultipleTile.tsx +33 -3
- package/src/components/SmallMultiples/SmallMultiples.css +12 -0
- package/src/components/SmallMultiples/SmallMultiples.tsx +50 -15
- package/src/components/SmallMultiples/tests/SmallMultipleTile.test.tsx +152 -0
- package/src/components/SmallMultiples/tests/SmallMultiples.test.tsx +170 -0
- package/src/components/Sparkline/components/SparkLine.tsx +4 -9
- package/src/components/WarmingStripes/WarmingStripesGradientLegend.css +1 -1
- package/src/components/WarmingStripes/WarmingStripesGradientLegend.tsx +2 -2
- package/src/data/initial-state.js +12 -0
- package/src/helpers/axisLabelFontSize.ts +8 -0
- package/src/helpers/bumpChartTooltip.ts +54 -0
- package/src/helpers/calculateLeftYAxisWidth.ts +13 -3
- package/src/helpers/colorAssignmentHelpers.ts +102 -0
- package/src/helpers/dataHelpers.ts +11 -1
- package/src/helpers/ensureSpecialChartAxisTypes.ts +11 -0
- package/src/helpers/getAxisMaxOverride.ts +16 -0
- package/src/helpers/getCleanTopTickMax.ts +64 -0
- package/src/helpers/getColorScale.ts +18 -9
- package/src/helpers/getHasBoundarySuppression.ts +26 -0
- package/src/helpers/getMinMax.ts +26 -25
- package/src/helpers/getYAxisDomainData.ts +38 -0
- package/src/helpers/getYAxisFinalizationEligibility.ts +40 -0
- package/src/helpers/handleChartAriaLabels.ts +23 -10
- package/src/helpers/hasSpacedInlineLabel.ts +10 -0
- package/src/helpers/seriesColumnSettings.ts +5 -4
- package/src/helpers/seriesHighlight.ts +26 -0
- package/src/helpers/smallMultiplesHelpers.ts +5 -0
- package/src/helpers/tests/axisLabelFontSize.test.ts +15 -0
- package/src/helpers/tests/bumpChartTooltip.test.ts +75 -0
- package/src/helpers/tests/calculateLeftYAxisWidth.test.ts +38 -0
- package/src/helpers/tests/dataHelpers.test.ts +135 -0
- package/src/helpers/tests/ensureSpecialChartAxisTypes.test.ts +30 -0
- package/src/helpers/tests/getAxisMaxOverride.test.ts +36 -0
- package/src/helpers/tests/getCleanTopTickMax.test.ts +165 -0
- package/src/helpers/tests/getColorScale.test.ts +197 -0
- package/src/helpers/tests/getMinMax.test.ts +211 -0
- package/src/helpers/tests/getYAxisDomainData.test.ts +119 -0
- package/src/helpers/tests/getYAxisFinalizationEligibility.test.ts +185 -0
- package/src/helpers/tests/handleChartAriaLabels.test.ts +71 -0
- package/src/helpers/tests/hasSpacedInlineLabel.test.ts +75 -0
- package/src/helpers/tests/seriesColumnSettings.test.ts +16 -2
- package/src/helpers/tests/seriesHighlight.test.ts +61 -0
- package/src/helpers/tests/smallMultiplesHelpers.test.ts +99 -0
- package/src/hooks/tests/useRightAxis.test.tsx +127 -0
- package/src/hooks/tests/useScales.test.tsx +383 -0
- package/src/hooks/useRightAxis.ts +30 -13
- package/src/hooks/useScales.ts +48 -21
- package/src/hooks/useTooltip.tsx +3 -1
- package/src/index.jsx +5 -2
- package/src/scss/main.scss +32 -49
- package/src/test/CdcChart.dataTable.test.tsx +122 -0
- package/src/types/ChartConfig.ts +24 -1
- package/src/types/ChartContext.ts +5 -0
- package/src/helpers/getYAxisAutoPadding.ts +0 -53
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Accordion } from 'react-accessible-accordion'
|
|
3
|
+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import ConfigContext from '../../../../ConfigContext'
|
|
6
|
+
import EditorPanelContext from '../../EditorPanelContext'
|
|
7
|
+
import PanelVisual from './Panel.Visual'
|
|
8
|
+
import { createMockChartContext, createMockConfig } from '../../../LinearChart/tests/mockConfigContext'
|
|
9
|
+
import { ChartConfig } from '../../../../types/ChartConfig'
|
|
10
|
+
|
|
11
|
+
vi.mock('@cdc/core/hooks/useColorPalette', () => ({
|
|
12
|
+
useColorPalette: () => ({
|
|
13
|
+
twoColorPalettes: [],
|
|
14
|
+
sequential: [],
|
|
15
|
+
nonSequential: [],
|
|
16
|
+
accessibleColors: []
|
|
17
|
+
})
|
|
18
|
+
}))
|
|
19
|
+
|
|
20
|
+
vi.mock('@cdc/core/components/PaletteSelector', () => ({
|
|
21
|
+
PaletteSelector: () => <div data-testid='palette-selector' />,
|
|
22
|
+
DeveloperPaletteRollback: () => null
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
vi.mock('@cdc/core/components/HeaderThemeSelector', () => ({
|
|
26
|
+
HeaderThemeSelector: () => null
|
|
27
|
+
}))
|
|
28
|
+
|
|
29
|
+
vi.mock('@cdc/core/components/ui/Icon', () => ({
|
|
30
|
+
default: () => <span data-testid='icon' />
|
|
31
|
+
}))
|
|
32
|
+
|
|
33
|
+
const buildConfig = (overrides: Partial<ChartConfig> = {}) =>
|
|
34
|
+
createMockConfig({
|
|
35
|
+
visualizationType: 'Line',
|
|
36
|
+
visualizationSubType: 'regular',
|
|
37
|
+
general: {
|
|
38
|
+
palette: {
|
|
39
|
+
customColors: ['#111111', '#222222']
|
|
40
|
+
}
|
|
41
|
+
} as any,
|
|
42
|
+
series: [
|
|
43
|
+
{ dataKey: 'series_a', name: 'Alpha', type: 'Line' },
|
|
44
|
+
{ dataKey: 'series_b', name: 'Beta', type: 'Line' }
|
|
45
|
+
] as any,
|
|
46
|
+
runtime: {
|
|
47
|
+
...createMockConfig().runtime,
|
|
48
|
+
seriesKeys: ['series_a', 'series_b'],
|
|
49
|
+
seriesLabels: {
|
|
50
|
+
series_a: 'Alpha',
|
|
51
|
+
series_b: 'Beta'
|
|
52
|
+
},
|
|
53
|
+
seriesLabelsAll: ['Alpha', 'Beta']
|
|
54
|
+
} as any,
|
|
55
|
+
visual: {
|
|
56
|
+
lineDatapointSymbol: 'none',
|
|
57
|
+
verticalHoverLine: false,
|
|
58
|
+
horizontalHoverLine: false
|
|
59
|
+
} as any,
|
|
60
|
+
...overrides
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const renderPanel = (
|
|
64
|
+
config: ChartConfig,
|
|
65
|
+
colorPalettes = {
|
|
66
|
+
qualitative_standard: ['#111111', '#222222']
|
|
67
|
+
}
|
|
68
|
+
) => {
|
|
69
|
+
const updateConfig = vi.fn()
|
|
70
|
+
const renderTree = (panelConfig: ChartConfig) => {
|
|
71
|
+
const context = createMockChartContext(panelConfig, {
|
|
72
|
+
updateConfig,
|
|
73
|
+
colorPalettes,
|
|
74
|
+
twoColorPalette: {
|
|
75
|
+
v2: {}
|
|
76
|
+
}
|
|
77
|
+
} as any)
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<ConfigContext.Provider value={context}>
|
|
81
|
+
<EditorPanelContext.Provider
|
|
82
|
+
value={{
|
|
83
|
+
updateField: vi.fn(),
|
|
84
|
+
setLollipopShape: vi.fn(),
|
|
85
|
+
handlePaletteSelection: vi.fn(),
|
|
86
|
+
handleTwoColorPaletteSelection: vi.fn()
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
<Accordion allowZeroExpanded>
|
|
90
|
+
<PanelVisual name='Visual' />
|
|
91
|
+
</Accordion>
|
|
92
|
+
</EditorPanelContext.Provider>
|
|
93
|
+
</ConfigContext.Provider>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const view = render(renderTree(config))
|
|
98
|
+
|
|
99
|
+
fireEvent.click(screen.getByRole('button', { name: 'Visual' }))
|
|
100
|
+
return {
|
|
101
|
+
updateConfig,
|
|
102
|
+
rerenderPanel: (newConfig: ChartConfig) => view.rerender(renderTree(newConfig))
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
describe('PanelVisual series color assignments', () => {
|
|
107
|
+
it('seeds assignment rows from current colors when by-value mode is enabled', () => {
|
|
108
|
+
const { updateConfig } = renderPanel(buildConfig())
|
|
109
|
+
|
|
110
|
+
fireEvent.change(screen.getByLabelText('Color Assignment Mode'), { target: { value: 'by-value' } })
|
|
111
|
+
|
|
112
|
+
expect(updateConfig).toHaveBeenCalledWith(
|
|
113
|
+
expect.objectContaining({
|
|
114
|
+
general: expect.objectContaining({
|
|
115
|
+
palette: expect.objectContaining({
|
|
116
|
+
colorAssignmentMode: 'by-value',
|
|
117
|
+
colorAssignments: [
|
|
118
|
+
{ key: 'series_a', color: '#111111' },
|
|
119
|
+
{ key: 'series_b', color: '#222222' }
|
|
120
|
+
]
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('syncs missing current series assignments while by-value mode is active', async () => {
|
|
128
|
+
const { updateConfig } = renderPanel(
|
|
129
|
+
buildConfig({
|
|
130
|
+
general: {
|
|
131
|
+
palette: {
|
|
132
|
+
customColors: ['#111111', '#222222'],
|
|
133
|
+
colorAssignmentMode: 'by-value',
|
|
134
|
+
colorAssignments: [{ key: 'series_a', color: '#111111' }]
|
|
135
|
+
}
|
|
136
|
+
} as any
|
|
137
|
+
})
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
await waitFor(() => {
|
|
141
|
+
expect(updateConfig).toHaveBeenCalledWith(
|
|
142
|
+
expect.objectContaining({
|
|
143
|
+
general: expect.objectContaining({
|
|
144
|
+
palette: expect.objectContaining({
|
|
145
|
+
colorAssignmentMode: 'by-value',
|
|
146
|
+
colorAssignments: [
|
|
147
|
+
{ key: 'series_a', color: '#111111' },
|
|
148
|
+
{ key: 'series_b', color: '#222222' }
|
|
149
|
+
]
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
)
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('syncs assignments when a new series is added while by-value mode is active', async () => {
|
|
158
|
+
const initialConfig = buildConfig({
|
|
159
|
+
general: {
|
|
160
|
+
palette: {
|
|
161
|
+
customColors: ['#111111', '#222222'],
|
|
162
|
+
colorAssignmentMode: 'by-value',
|
|
163
|
+
colorAssignments: [{ key: 'series_a', color: '#111111' }]
|
|
164
|
+
}
|
|
165
|
+
} as any,
|
|
166
|
+
series: [{ dataKey: 'series_a', name: 'Alpha', type: 'Line' }] as any,
|
|
167
|
+
runtime: {
|
|
168
|
+
...createMockConfig().runtime,
|
|
169
|
+
seriesKeys: ['series_a'],
|
|
170
|
+
seriesLabels: {
|
|
171
|
+
series_a: 'Alpha'
|
|
172
|
+
},
|
|
173
|
+
seriesLabelsAll: ['Alpha']
|
|
174
|
+
} as any
|
|
175
|
+
})
|
|
176
|
+
const { updateConfig, rerenderPanel } = renderPanel(initialConfig)
|
|
177
|
+
|
|
178
|
+
updateConfig.mockClear()
|
|
179
|
+
rerenderPanel(
|
|
180
|
+
buildConfig({
|
|
181
|
+
general: {
|
|
182
|
+
palette: {
|
|
183
|
+
customColors: ['#111111', '#222222'],
|
|
184
|
+
colorAssignmentMode: 'by-value',
|
|
185
|
+
colorAssignments: [{ key: 'series_a', color: '#111111' }]
|
|
186
|
+
}
|
|
187
|
+
} as any
|
|
188
|
+
})
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
await waitFor(() => {
|
|
192
|
+
expect(updateConfig).toHaveBeenCalledWith(
|
|
193
|
+
expect.objectContaining({
|
|
194
|
+
general: expect.objectContaining({
|
|
195
|
+
palette: expect.objectContaining({
|
|
196
|
+
colorAssignments: [
|
|
197
|
+
{ key: 'series_a', color: '#111111' },
|
|
198
|
+
{ key: 'series_b', color: '#222222' }
|
|
199
|
+
]
|
|
200
|
+
})
|
|
201
|
+
})
|
|
202
|
+
})
|
|
203
|
+
)
|
|
204
|
+
})
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
it('updates the color for the matching assignment key and drops stale assignment keys', () => {
|
|
208
|
+
const { updateConfig } = renderPanel(
|
|
209
|
+
buildConfig({
|
|
210
|
+
general: {
|
|
211
|
+
palette: {
|
|
212
|
+
customColors: ['#111111', '#222222'],
|
|
213
|
+
colorAssignmentMode: 'by-value',
|
|
214
|
+
colorAssignments: [
|
|
215
|
+
{ key: 'series_a', color: '#111111' },
|
|
216
|
+
{ key: 'series_b', color: '#222222' },
|
|
217
|
+
{ key: 'stale_series', color: '#333333' }
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
} as any
|
|
221
|
+
})
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
const alphaRow = screen.getByText('Alpha').closest('.series-color-assignments__row') as HTMLElement
|
|
225
|
+
fireEvent.click(within(alphaRow).getByRole('button', { name: 'Color for Alpha' }))
|
|
226
|
+
fireEvent.click(screen.getAllByTitle('#222222').find(element => element.getAttribute('role') === 'option')!)
|
|
227
|
+
|
|
228
|
+
expect(updateConfig).toHaveBeenCalledWith(
|
|
229
|
+
expect.objectContaining({
|
|
230
|
+
general: expect.objectContaining({
|
|
231
|
+
palette: expect.objectContaining({
|
|
232
|
+
colorAssignmentMode: 'by-value',
|
|
233
|
+
colorAssignments: expect.arrayContaining([
|
|
234
|
+
{ key: 'series_a', color: '#222222' },
|
|
235
|
+
{ key: 'series_b', color: '#222222' }
|
|
236
|
+
])
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
)
|
|
241
|
+
expect(updateConfig.mock.calls[0][0].general.palette.colorAssignments).toHaveLength(2)
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it('lets assignments choose from the full active palette, not only distributed series colors', () => {
|
|
245
|
+
const fullPalette = [
|
|
246
|
+
'#0057B7',
|
|
247
|
+
'#722161',
|
|
248
|
+
'#00B1CE',
|
|
249
|
+
'#D94E5F',
|
|
250
|
+
'#5A8E3F',
|
|
251
|
+
'#FFB24D',
|
|
252
|
+
'#FB7E38',
|
|
253
|
+
'#032659',
|
|
254
|
+
'#975722'
|
|
255
|
+
]
|
|
256
|
+
const { updateConfig } = renderPanel(
|
|
257
|
+
buildConfig({
|
|
258
|
+
general: {
|
|
259
|
+
palette: {
|
|
260
|
+
name: 'qualitative_standard',
|
|
261
|
+
version: '2.0',
|
|
262
|
+
colorAssignmentMode: 'by-value',
|
|
263
|
+
colorAssignments: [
|
|
264
|
+
{ key: 'series_a', color: '#0057B7' },
|
|
265
|
+
{ key: 'series_b', color: '#00B1CE' },
|
|
266
|
+
{ key: 'series_c', color: '#5A8E3F' }
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
} as any,
|
|
270
|
+
series: [
|
|
271
|
+
{ dataKey: 'series_a', name: 'Alpha', type: 'Line' },
|
|
272
|
+
{ dataKey: 'series_b', name: 'Beta', type: 'Line' },
|
|
273
|
+
{ dataKey: 'series_c', name: 'Gamma', type: 'Line' }
|
|
274
|
+
] as any,
|
|
275
|
+
runtime: {
|
|
276
|
+
...createMockConfig().runtime,
|
|
277
|
+
seriesKeys: ['series_a', 'series_b', 'series_c'],
|
|
278
|
+
seriesLabels: {
|
|
279
|
+
series_a: 'Alpha',
|
|
280
|
+
series_b: 'Beta',
|
|
281
|
+
series_c: 'Gamma'
|
|
282
|
+
},
|
|
283
|
+
seriesLabelsAll: ['Alpha', 'Beta', 'Gamma']
|
|
284
|
+
} as any
|
|
285
|
+
}),
|
|
286
|
+
{
|
|
287
|
+
qualitative_standard: fullPalette
|
|
288
|
+
}
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
const alphaRow = screen.getByText('Alpha').closest('.series-color-assignments__row') as HTMLElement
|
|
292
|
+
fireEvent.click(within(alphaRow).getByRole('button', { name: 'Color for Alpha' }))
|
|
293
|
+
fireEvent.click(screen.getAllByTitle('#722161').find(element => element.getAttribute('role') === 'option')!)
|
|
294
|
+
|
|
295
|
+
expect(updateConfig).toHaveBeenCalledWith(
|
|
296
|
+
expect.objectContaining({
|
|
297
|
+
general: expect.objectContaining({
|
|
298
|
+
palette: expect.objectContaining({
|
|
299
|
+
colorAssignments: expect.arrayContaining([{ key: 'series_a', color: '#722161' }])
|
|
300
|
+
})
|
|
301
|
+
})
|
|
302
|
+
})
|
|
303
|
+
)
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
it('resets assignments when the selected palette changes without custom colors', () => {
|
|
307
|
+
const initialConfig = buildConfig({
|
|
308
|
+
general: {
|
|
309
|
+
palette: {
|
|
310
|
+
name: 'qualitative_standard',
|
|
311
|
+
version: '2.0',
|
|
312
|
+
colorAssignmentMode: 'by-value',
|
|
313
|
+
colorAssignments: [
|
|
314
|
+
{ key: 'series_a', color: '#0057B7' },
|
|
315
|
+
{ key: 'series_b', color: '#00B1CE' },
|
|
316
|
+
{ key: 'stale_series', color: '#333333' }
|
|
317
|
+
]
|
|
318
|
+
}
|
|
319
|
+
} as any
|
|
320
|
+
})
|
|
321
|
+
const { updateConfig, rerenderPanel } = renderPanel(initialConfig, {
|
|
322
|
+
qualitative_standard: [
|
|
323
|
+
'#0057B7',
|
|
324
|
+
'#722161',
|
|
325
|
+
'#00B1CE',
|
|
326
|
+
'#D94E5F',
|
|
327
|
+
'#5A8E3F',
|
|
328
|
+
'#FFB24D',
|
|
329
|
+
'#FB7E38',
|
|
330
|
+
'#032659',
|
|
331
|
+
'#975722'
|
|
332
|
+
],
|
|
333
|
+
sequential_blue: [
|
|
334
|
+
'#DBE8F7',
|
|
335
|
+
'#BED5ED',
|
|
336
|
+
'#99BCE1',
|
|
337
|
+
'#73A1D5',
|
|
338
|
+
'#4E88C7',
|
|
339
|
+
'#1E6BC0',
|
|
340
|
+
'#0057B7',
|
|
341
|
+
'#01418D',
|
|
342
|
+
'#032659'
|
|
343
|
+
]
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
updateConfig.mockClear()
|
|
347
|
+
rerenderPanel(
|
|
348
|
+
buildConfig({
|
|
349
|
+
general: {
|
|
350
|
+
palette: {
|
|
351
|
+
name: 'sequential_blue',
|
|
352
|
+
version: '2.0',
|
|
353
|
+
colorAssignmentMode: 'by-value',
|
|
354
|
+
colorAssignments: [
|
|
355
|
+
{ key: 'series_a', color: '#0057B7' },
|
|
356
|
+
{ key: 'series_b', color: '#00B1CE' },
|
|
357
|
+
{ key: 'stale_series', color: '#333333' }
|
|
358
|
+
]
|
|
359
|
+
}
|
|
360
|
+
} as any
|
|
361
|
+
})
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
expect(updateConfig).toHaveBeenCalledWith(
|
|
365
|
+
expect.objectContaining({
|
|
366
|
+
general: expect.objectContaining({
|
|
367
|
+
palette: expect.objectContaining({
|
|
368
|
+
colorAssignments: [
|
|
369
|
+
{ key: 'series_a', color: '#DBE8F7' },
|
|
370
|
+
{ key: 'series_b', color: '#032659' }
|
|
371
|
+
]
|
|
372
|
+
})
|
|
373
|
+
})
|
|
374
|
+
})
|
|
375
|
+
)
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
it('does not reset assignments when custom colors change', () => {
|
|
379
|
+
const initialConfig = buildConfig({
|
|
380
|
+
general: {
|
|
381
|
+
palette: {
|
|
382
|
+
customColors: ['#111111', '#222222'],
|
|
383
|
+
colorAssignmentMode: 'by-value',
|
|
384
|
+
colorAssignments: [
|
|
385
|
+
{ key: 'series_a', color: '#111111' },
|
|
386
|
+
{ key: 'series_b', color: '#222222' }
|
|
387
|
+
]
|
|
388
|
+
}
|
|
389
|
+
} as any
|
|
390
|
+
})
|
|
391
|
+
const { updateConfig, rerenderPanel } = renderPanel(initialConfig)
|
|
392
|
+
|
|
393
|
+
updateConfig.mockClear()
|
|
394
|
+
rerenderPanel(
|
|
395
|
+
buildConfig({
|
|
396
|
+
general: {
|
|
397
|
+
palette: {
|
|
398
|
+
customColors: ['#aaaaaa', '#bbbbbb'],
|
|
399
|
+
colorAssignmentMode: 'by-value',
|
|
400
|
+
colorAssignments: [
|
|
401
|
+
{ key: 'series_a', color: '#111111' },
|
|
402
|
+
{ key: 'series_b', color: '#222222' }
|
|
403
|
+
]
|
|
404
|
+
}
|
|
405
|
+
} as any
|
|
406
|
+
})
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
expect(updateConfig).not.toHaveBeenCalled()
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
it('resets assignments when custom colors are removed while by-value mode is active', () => {
|
|
413
|
+
const initialConfig = buildConfig({
|
|
414
|
+
general: {
|
|
415
|
+
palette: {
|
|
416
|
+
name: 'qualitative_standard',
|
|
417
|
+
version: '2.0',
|
|
418
|
+
customColors: ['#111111', '#222222'],
|
|
419
|
+
colorAssignmentMode: 'by-value',
|
|
420
|
+
colorAssignments: [
|
|
421
|
+
{ key: 'series_a', color: '#111111' },
|
|
422
|
+
{ key: 'series_b', color: '#222222' }
|
|
423
|
+
]
|
|
424
|
+
}
|
|
425
|
+
} as any
|
|
426
|
+
})
|
|
427
|
+
const { updateConfig, rerenderPanel } = renderPanel(initialConfig, {
|
|
428
|
+
qualitative_standard: [
|
|
429
|
+
'#0057B7',
|
|
430
|
+
'#722161',
|
|
431
|
+
'#00B1CE',
|
|
432
|
+
'#D94E5F',
|
|
433
|
+
'#5A8E3F',
|
|
434
|
+
'#FFB24D',
|
|
435
|
+
'#FB7E38',
|
|
436
|
+
'#032659',
|
|
437
|
+
'#975722'
|
|
438
|
+
]
|
|
439
|
+
})
|
|
440
|
+
|
|
441
|
+
updateConfig.mockClear()
|
|
442
|
+
rerenderPanel(
|
|
443
|
+
buildConfig({
|
|
444
|
+
general: {
|
|
445
|
+
palette: {
|
|
446
|
+
name: 'qualitative_standard',
|
|
447
|
+
version: '2.0',
|
|
448
|
+
colorAssignmentMode: 'by-value',
|
|
449
|
+
colorAssignments: [
|
|
450
|
+
{ key: 'series_a', color: '#111111' },
|
|
451
|
+
{ key: 'series_b', color: '#222222' }
|
|
452
|
+
]
|
|
453
|
+
}
|
|
454
|
+
} as any
|
|
455
|
+
})
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
expect(updateConfig).toHaveBeenCalledWith(
|
|
459
|
+
expect.objectContaining({
|
|
460
|
+
general: expect.objectContaining({
|
|
461
|
+
palette: expect.objectContaining({
|
|
462
|
+
colorAssignments: [
|
|
463
|
+
{ key: 'series_a', color: '#0057B7' },
|
|
464
|
+
{ key: 'series_b', color: '#5A8E3F' }
|
|
465
|
+
]
|
|
466
|
+
})
|
|
467
|
+
})
|
|
468
|
+
})
|
|
469
|
+
)
|
|
470
|
+
})
|
|
471
|
+
|
|
472
|
+
it('hides assignments for single-series bars colored by category', () => {
|
|
473
|
+
renderPanel(
|
|
474
|
+
buildConfig({
|
|
475
|
+
visualizationType: 'Bar',
|
|
476
|
+
visualizationSubType: 'regular',
|
|
477
|
+
legend: { colorCode: 'category' } as any,
|
|
478
|
+
series: [{ dataKey: 'series_a', name: 'Alpha', type: 'Bar' }] as any
|
|
479
|
+
})
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
expect(screen.queryByLabelText('Color Assignment Mode')).not.toBeInTheDocument()
|
|
483
|
+
})
|
|
484
|
+
})
|
|
@@ -32,6 +32,7 @@ import { HeaderThemeSelector } from '@cdc/core/components/HeaderThemeSelector'
|
|
|
32
32
|
import { CustomColorsEditor } from '@cdc/core/components/CustomColorsEditor'
|
|
33
33
|
import StyleTreatmentSection from '@cdc/core/components/EditorPanel/sections/StyleTreatmentSection'
|
|
34
34
|
import { getColorScale } from '../../../../helpers/getColorScale'
|
|
35
|
+
import SeriesColorAssignments from './SeriesColorAssignments'
|
|
35
36
|
import { ENABLE_CHART_MAP_TP5_TREATMENT_SELECTION, ENABLE_CHART_VISUAL_SETTINGS } from '@cdc/core/helpers/constants'
|
|
36
37
|
import '@cdc/core/components/EditorPanel/editor.scss'
|
|
37
38
|
import './panelVisual.styles.css'
|
|
@@ -306,7 +307,7 @@ const PanelVisual: FC<PanelProps> = props => {
|
|
|
306
307
|
/>
|
|
307
308
|
</>
|
|
308
309
|
)}
|
|
309
|
-
{(
|
|
310
|
+
{(visSupportsSequentialPallete() || visSupportsNonSequentialPallete()) && (
|
|
310
311
|
<>
|
|
311
312
|
<label>
|
|
312
313
|
<span className='edit-label'>Chart Color Palette</span>
|
|
@@ -457,6 +458,8 @@ const PanelVisual: FC<PanelProps> = props => {
|
|
|
457
458
|
)}
|
|
458
459
|
</>
|
|
459
460
|
)}
|
|
461
|
+
|
|
462
|
+
<SeriesColorAssignments config={config} updateConfig={updateConfig} colorPalettes={colorPalettes} />
|
|
460
463
|
</>
|
|
461
464
|
)}
|
|
462
465
|
{config.visualizationType === 'Sankey' && (
|