@cdc/chart 4.25.10 → 4.26.1
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/dist/{cdcchart-1a1724a1.es.js → cdcchart-dgT_1dIT.es.js} +136 -151
- package/dist/cdcchart.js +44003 -43518
- package/examples/feature/__data__/planet-example-data.json +1 -1
- package/examples/feature/boxplot/valid-boxplot.csv +38 -17
- package/examples/feature/pie/planet-pie-example-config.json +48 -2
- package/examples/private/DEV-11825.json +573 -0
- package/examples/private/DEV-12100.json +1303 -0
- package/examples/private/cat-y.json +1235 -0
- package/examples/private/data-points.json +228 -0
- package/examples/private/height.json +3915 -0
- package/examples/private/links.json +569 -0
- package/examples/private/na.json +913 -0
- package/examples/private/quadrant.txt +30 -0
- package/examples/private/test-data.csv +28 -0
- package/examples/private/test-forecast.json +5510 -0
- package/examples/private/warming-stripe-test.json +2578 -0
- package/examples/private/warming-stripes.json +4763 -0
- package/examples/tech-adoption-with-links.json +560 -0
- package/index.html +16 -140
- package/package.json +6 -5
- package/preview.html +1616 -0
- package/src/CdcChart.tsx +8 -11
- package/src/CdcChartComponent.tsx +329 -124
- package/src/_stories/Chart.Combo.stories.tsx +18 -0
- package/src/_stories/Chart.Forecast.stories.tsx +36 -0
- package/src/_stories/Chart.HTMLInDataTable.stories.tsx +520 -0
- package/src/_stories/Chart.Patterns.stories.tsx +2 -1
- package/src/_stories/Chart.PreserveDecimals.stories.tsx +220 -0
- package/src/_stories/Chart.Regions.Categorical.stories.tsx +148 -0
- package/src/_stories/Chart.Regions.DateScale.stories.tsx +197 -0
- package/src/_stories/Chart.Regions.DateTimeScale.stories.tsx +297 -0
- package/src/_stories/Chart.SmallMultiples.stories.tsx +47 -0
- package/src/_stories/Chart.stories.tsx +8 -0
- package/src/_stories/ChartAnnotation.stories.tsx +6 -3
- package/src/_stories/ChartBar.Editor.stories.tsx +3585 -0
- package/src/_stories/ChartBrush.Editor.stories.tsx +295 -0
- package/src/_stories/ChartBrush.stories.tsx +50 -0
- package/src/_stories/ChartEditor.Editor.stories.tsx +656 -0
- package/src/_stories/ChartEditor.stories.tsx +1 -2
- package/src/_stories/TechAdoptionWithLinks.stories.tsx +27 -0
- package/src/_stories/_mock/brush_enabled.json +326 -0
- package/src/_stories/_mock/brush_mock.json +2 -69
- package/src/_stories/_mock/combo.json +451 -0
- package/src/_stories/_mock/editor-test-configs.json +376 -0
- package/src/_stories/_mock/editor-test-datasets.json +477 -0
- package/src/_stories/_mock/editor-tests/bar-chart-editor-test.json +255 -0
- package/src/_stories/_mock/editor-tests/bar-chart-general-test.json +267 -0
- package/src/_stories/_mock/editor-tests/bar-chart-test.json +237 -0
- package/src/_stories/_mock/forecast_combo_with_gaps.json +913 -0
- package/src/_stories/_mock/horizontal-bars-dynamic-y-axis.json +413 -0
- package/src/_stories/_mock/pie_config.json +257 -62
- package/src/_stories/_mock/small_multiples/small_multiples_bars.json +1944 -0
- package/src/_stories/_mock/small_multiples/small_multiples_big_data_bars.json +1114 -0
- package/src/_stories/_mock/small_multiples/small_multiples_lines.json +2646 -0
- package/src/_stories/_mock/small_multiples/small_multiples_lines_colors.json +1305 -0
- package/src/_stories/_mock/small_multiples/small_multiples_stacked_bars.json +1936 -0
- package/src/components/Annotations/components/findNearestDatum.ts +6 -41
- package/src/components/AreaChart/components/AreaChart.Stacked.jsx +10 -7
- package/src/components/AreaChart/index.tsx +1 -2
- package/src/components/Axis/Categorical.Axis.tsx +6 -7
- package/src/components/BarChart/components/BarChart.Horizontal.tsx +181 -27
- package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +3 -1
- package/src/components/BarChart/components/BarChart.StackedVertical.tsx +1 -0
- package/src/components/BarChart/components/BarChart.Vertical.tsx +8 -9
- package/src/components/BarChart/components/context.tsx +1 -0
- package/src/components/BarChart/helpers/useBarChart.ts +14 -2
- package/src/components/BoxPlot/helpers/index.ts +3 -3
- package/src/components/Brush/BrushSelector.tsx +1258 -0
- package/src/components/Brush/MiniChartPreview.tsx +283 -0
- package/src/components/DeviationBar.jsx +9 -7
- package/src/components/EditorPanel/EditorPanel.tsx +2720 -2586
- package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +96 -111
- package/src/components/EditorPanel/components/Panels/Panel.ForestPlotSettings.tsx +56 -34
- package/src/components/EditorPanel/components/Panels/Panel.General.tsx +76 -31
- package/src/components/EditorPanel/components/Panels/Panel.PatternSettings.tsx +104 -55
- package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +54 -49
- package/src/components/EditorPanel/components/Panels/Panel.SmallMultiples.tsx +427 -0
- package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +96 -48
- package/src/components/EditorPanel/components/Panels/index.tsx +3 -1
- package/src/components/EditorPanel/editor-panel.scss +0 -20
- package/src/components/EditorPanel/useEditorPermissions.ts +36 -31
- package/src/components/Forecasting/Forecasting.tsx +139 -21
- package/src/components/Legend/Legend.Component.tsx +16 -9
- package/src/components/Legend/Legend.tsx +3 -2
- package/src/components/Legend/helpers/createFormatLabels.tsx +325 -176
- package/src/components/Legend/helpers/getLegendClasses.ts +0 -1
- package/src/components/Legend/helpers/index.ts +10 -6
- package/src/components/LineChart/LineChartProps.ts +0 -3
- package/src/components/LineChart/helpers.ts +1 -1
- package/src/components/LineChart/index.tsx +36 -13
- package/src/components/LinearChart.tsx +559 -499
- package/src/components/PairedBarChart.jsx +20 -3
- package/src/components/Regions/components/Regions.tsx +366 -144
- package/src/components/Sankey/types/index.ts +1 -1
- package/src/components/ScatterPlot/ScatterPlot.jsx +2 -2
- package/src/components/SmallMultiples/SmallMultipleTile.tsx +202 -0
- package/src/components/SmallMultiples/SmallMultiples.css +32 -0
- package/src/components/SmallMultiples/SmallMultiples.tsx +271 -0
- package/src/components/SmallMultiples/index.ts +2 -0
- package/src/components/WarmingStripes/WarmingStripes.tsx +160 -0
- package/src/components/WarmingStripes/WarmingStripesGradientLegend.css +35 -0
- package/src/components/WarmingStripes/WarmingStripesGradientLegend.tsx +104 -0
- package/src/components/WarmingStripes/index.tsx +3 -0
- package/src/data/initial-state.js +16 -2
- package/src/helpers/buildForecastPaletteOptions.ts +0 -38
- package/src/helpers/calculateHorizontalBarCategoryLabelWidth.ts +57 -0
- package/src/helpers/getColorScale.ts +10 -0
- package/src/{hooks/useMinMax.ts → helpers/getMinMax.ts} +26 -14
- package/src/helpers/getYAxisAutoPadding.ts +53 -0
- package/src/helpers/sizeHelpers.ts +0 -20
- package/src/helpers/smallMultiplesHelpers.ts +529 -0
- package/src/hooks/useChartHoverAnalytics.tsx +10 -9
- package/src/hooks/useProgrammaticTooltip.ts +96 -0
- package/src/hooks/useScales.ts +98 -34
- package/src/hooks/useSmallMultipleSynchronization.ts +59 -0
- package/src/hooks/useTooltip.tsx +91 -25
- package/src/scss/DataTable.scss +0 -4
- package/src/scss/main.scss +18 -83
- package/src/store/chart.actions.ts +2 -0
- package/src/store/chart.reducer.ts +4 -0
- package/src/test/CdcChart.test.jsx +1 -1
- package/src/types/ChartConfig.ts +27 -6
- package/src/types/ChartContext.ts +3 -0
- package/src/types/Label.ts +1 -0
- package/src/utils/analyticsTracking.ts +19 -0
- package/LICENSE +0 -201
- package/src/_stories/_mock/pie_data.json +0 -218
- package/src/components/AreaChart/components/AreaChart.jsx +0 -109
- package/src/components/Brush/BrushChart.tsx +0 -128
- package/src/components/Brush/BrushController.tsx +0 -71
- package/src/components/Brush/types.tsx +0 -8
- package/src/components/BrushChart.tsx +0 -223
- package/src/helpers/sort.ts +0 -7
- package/src/hooks/useActiveElement.js +0 -19
- package/src/hooks/useChartClasses.js +0 -41
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import { within, userEvent, expect } from 'storybook/test'
|
|
3
|
+
import Chart from '../CdcChartComponent'
|
|
4
|
+
|
|
5
|
+
// Import testing helpers following best practices document
|
|
6
|
+
import { openAccordion, performAndAssert, waitForEditor, waitForPresence } from '@cdc/core/helpers/testing'
|
|
7
|
+
|
|
8
|
+
// Import working brush configuration
|
|
9
|
+
import brushEnabledConfig from './_mock/brush_enabled.json'
|
|
10
|
+
|
|
11
|
+
const meta: Meta<typeof Chart> = {
|
|
12
|
+
title: 'Components/Templates/Chart/Editor Tests/Brush',
|
|
13
|
+
component: Chart
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default meta
|
|
17
|
+
type Story = StoryObj<typeof Chart>
|
|
18
|
+
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// BRUSH CHART EDITOR TESTS
|
|
21
|
+
// Tests the Brush Slider features in the Date/Category Axis accordion section
|
|
22
|
+
// Following best practices:
|
|
23
|
+
// - Tests visualization output changes, not control state
|
|
24
|
+
// - Uses performAndAssert pattern for all interactions
|
|
25
|
+
// - Tests specific visual changes in the brush selection
|
|
26
|
+
// ============================================================================
|
|
27
|
+
|
|
28
|
+
export const BrushDefaultSelectionTests: Story = {
|
|
29
|
+
name: 'Default Selection Mode Tests',
|
|
30
|
+
parameters: {
|
|
31
|
+
test: {
|
|
32
|
+
timeout: 30000
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
args: {
|
|
36
|
+
config: {
|
|
37
|
+
...brushEnabledConfig,
|
|
38
|
+
xAxis: {
|
|
39
|
+
...brushEnabledConfig.xAxis,
|
|
40
|
+
brushActive: true,
|
|
41
|
+
// New property: when set, shows last X data points instead of 35%
|
|
42
|
+
brushDefaultRecentDateCount: undefined
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
isEditor: true
|
|
46
|
+
},
|
|
47
|
+
play: async ({ canvasElement }) => {
|
|
48
|
+
const canvas = within(canvasElement)
|
|
49
|
+
await waitForEditor(canvas)
|
|
50
|
+
await openAccordion(canvas, 'Date/Category Axis')
|
|
51
|
+
|
|
52
|
+
// ============================================================================
|
|
53
|
+
// TEST: Brush Slider Toggle
|
|
54
|
+
// Verifies: Brush slider appears/disappears in the visualization
|
|
55
|
+
// ============================================================================
|
|
56
|
+
|
|
57
|
+
const getBrushVisibility = () => {
|
|
58
|
+
const brushSvg = canvasElement.querySelector('svg[style*="border: 1px solid"]')
|
|
59
|
+
const brushRect = canvasElement.querySelector('.visx-brush rect')
|
|
60
|
+
return {
|
|
61
|
+
hasBrushSvg: !!brushSvg,
|
|
62
|
+
hasBrushRect: !!brushRect,
|
|
63
|
+
brushContainerVisible: !!canvasElement.querySelector('[class*="brush"]')
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Verify brush is initially visible since config has brushActive: true
|
|
68
|
+
const initialBrushState = getBrushVisibility()
|
|
69
|
+
expect(initialBrushState.hasBrushSvg || initialBrushState.brushContainerVisible).toBe(true)
|
|
70
|
+
|
|
71
|
+
// Find and toggle the brush checkbox
|
|
72
|
+
const brushCheckbox = canvas.getByLabelText(/show brush slider/i) as HTMLInputElement
|
|
73
|
+
expect(brushCheckbox).toBeTruthy()
|
|
74
|
+
expect(brushCheckbox.checked).toBe(true)
|
|
75
|
+
|
|
76
|
+
// Toggle brush off and verify it disappears from visualization
|
|
77
|
+
await performAndAssert(
|
|
78
|
+
'Brush Slider Toggle Off',
|
|
79
|
+
getBrushVisibility,
|
|
80
|
+
async () => await userEvent.click(brushCheckbox),
|
|
81
|
+
(before, after) => {
|
|
82
|
+
// Either brush SVG or brush container should disappear
|
|
83
|
+
return (
|
|
84
|
+
(before.hasBrushSvg && !after.hasBrushSvg) || (before.brushContainerVisible && !after.brushContainerVisible)
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
// Toggle brush back on
|
|
90
|
+
await performAndAssert(
|
|
91
|
+
'Brush Slider Toggle On',
|
|
92
|
+
getBrushVisibility,
|
|
93
|
+
async () => await userEvent.click(brushCheckbox),
|
|
94
|
+
(before, after) => {
|
|
95
|
+
return (
|
|
96
|
+
(!before.hasBrushSvg && after.hasBrushSvg) || (!before.brushContainerVisible && after.brushContainerVisible)
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
// ============================================================================
|
|
102
|
+
// TEST: Default Recent Date Count Input
|
|
103
|
+
// Verifies: When "Show last X dates" is set, the brush selection changes
|
|
104
|
+
// to show exactly X data points instead of the default 35%
|
|
105
|
+
// ============================================================================
|
|
106
|
+
|
|
107
|
+
// This control should appear when brush is enabled
|
|
108
|
+
// Look for the new "Show last X dates by default" input
|
|
109
|
+
const recentDateCountInput = canvas.getByLabelText(/show last.*dates.*default/i) as HTMLInputElement
|
|
110
|
+
|
|
111
|
+
// If the control doesn't exist yet (TDD - test before implementation),
|
|
112
|
+
// the test will fail here, indicating we need to implement this feature
|
|
113
|
+
expect(recentDateCountInput).toBeTruthy()
|
|
114
|
+
expect(recentDateCountInput).toHaveAttribute('type', 'number')
|
|
115
|
+
|
|
116
|
+
// ============================================================================
|
|
117
|
+
// TEST: Setting Recent Date Count Dynamically Updates Brush Selection
|
|
118
|
+
// Verifies: Changing the value in the editor immediately updates the brush
|
|
119
|
+
// ============================================================================
|
|
120
|
+
|
|
121
|
+
const getBrushSelectionState = () => {
|
|
122
|
+
// The brush selection is represented by the visx-brush extent rect
|
|
123
|
+
const brushExtent = canvasElement.querySelector('.visx-brush rect[class*="selection"]') as SVGRectElement
|
|
124
|
+
const brushSvg = canvasElement.querySelector('svg[style*="border: 1px solid"]') as SVGSVGElement
|
|
125
|
+
|
|
126
|
+
// Get the visible data points in the main chart (lines or bars)
|
|
127
|
+
const chartSvg = canvasElement.querySelector('.linear-chart svg, .cove-chart svg') as SVGSVGElement
|
|
128
|
+
const dataPointsInChart = chartSvg?.querySelectorAll('circle, rect:not([fill="transparent"])').length || 0
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
brushWidth: brushExtent ? parseFloat(brushExtent.getAttribute('width') || '0') : 0,
|
|
132
|
+
brushX: brushExtent ? parseFloat(brushExtent.getAttribute('x') || '0') : 0,
|
|
133
|
+
totalBrushWidth: brushSvg ? brushSvg.clientWidth : 0,
|
|
134
|
+
visibleDataPoints: dataPointsInChart,
|
|
135
|
+
selectionPercentage:
|
|
136
|
+
brushExtent && brushSvg
|
|
137
|
+
? (parseFloat(brushExtent.getAttribute('width') || '0') / brushSvg.clientWidth) * 100
|
|
138
|
+
: 0
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const initialSelectionState = getBrushSelectionState()
|
|
143
|
+
|
|
144
|
+
// Default is ~35% of the width
|
|
145
|
+
// With 329 data points in brush_enabled.json, 35% would be ~115 points
|
|
146
|
+
// Setting to 30 should make the selection much narrower AND update immediately
|
|
147
|
+
await performAndAssert(
|
|
148
|
+
'Set Default Recent Date Count to 30 - Brush Updates Dynamically',
|
|
149
|
+
getBrushSelectionState,
|
|
150
|
+
async () => {
|
|
151
|
+
await userEvent.clear(recentDateCountInput)
|
|
152
|
+
await userEvent.type(recentDateCountInput, '30')
|
|
153
|
+
// Trigger change/blur to apply the value - this should update the brush immediately
|
|
154
|
+
await userEvent.tab()
|
|
155
|
+
},
|
|
156
|
+
(before, after) => {
|
|
157
|
+
// The brush selection width should decrease when we set a smaller count
|
|
158
|
+
// Since we have ~329 data points and default is 35% (~115 points),
|
|
159
|
+
// setting to 30 points should make the selection narrower
|
|
160
|
+
return after.brushWidth < before.brushWidth || after.selectionPercentage < before.selectionPercentage
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
// ============================================================================
|
|
165
|
+
// TEST: Changing Value Again Updates Selection Again
|
|
166
|
+
// Verifies: Multiple changes continue to update the brush dynamically
|
|
167
|
+
// ============================================================================
|
|
168
|
+
|
|
169
|
+
await performAndAssert(
|
|
170
|
+
'Change to 50 dates - Brush Expands Dynamically',
|
|
171
|
+
getBrushSelectionState,
|
|
172
|
+
async () => {
|
|
173
|
+
await userEvent.clear(recentDateCountInput)
|
|
174
|
+
await userEvent.type(recentDateCountInput, '50')
|
|
175
|
+
await userEvent.tab()
|
|
176
|
+
},
|
|
177
|
+
(before, after) => {
|
|
178
|
+
// Changing from 30 to 50 should expand the brush width
|
|
179
|
+
return after.brushWidth > before.brushWidth
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
// ============================================================================
|
|
184
|
+
// TEST: Verify Exact Data Point Count in Selection
|
|
185
|
+
// Verifies: The number of selected data points matches the input value
|
|
186
|
+
// ============================================================================
|
|
187
|
+
|
|
188
|
+
// The brush selection should now show exactly 30 data points
|
|
189
|
+
// We can verify this by checking the filtered data in the visualization
|
|
190
|
+
const getSelectedDataPointCount = () => {
|
|
191
|
+
// When brush is active, only the selected data points are rendered in the main chart
|
|
192
|
+
// Look for the number of data points (circles, bars, or line path points)
|
|
193
|
+
const chartContainer = canvasElement.querySelector('.linear-chart, .cove-chart')
|
|
194
|
+
const svg = chartContainer?.querySelector('svg')
|
|
195
|
+
|
|
196
|
+
// For line charts, count the line path data points
|
|
197
|
+
const linePaths = svg?.querySelectorAll('path[class*="line"], .visx-linepath')
|
|
198
|
+
let dataPointCount = 0
|
|
199
|
+
|
|
200
|
+
if (linePaths && linePaths.length > 0) {
|
|
201
|
+
// Count points in the path by looking at the rendered circles
|
|
202
|
+
const circles = svg?.querySelectorAll('circle')
|
|
203
|
+
dataPointCount = circles?.length || 0
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// For bar charts
|
|
207
|
+
const bars = svg?.querySelectorAll('rect[class*="bar"]')
|
|
208
|
+
if (bars && bars.length > 0) {
|
|
209
|
+
dataPointCount = bars.length
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
dataPointCount,
|
|
214
|
+
hasData: dataPointCount > 0
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// After setting to 30, the chart should show ~30 data points
|
|
219
|
+
// (exact count may vary based on how brush boundaries align with data points)
|
|
220
|
+
const afterSettingCount = getSelectedDataPointCount()
|
|
221
|
+
|
|
222
|
+
// The count should be close to 30 (allowing some tolerance for edge cases)
|
|
223
|
+
// Note: This assertion helps verify the feature works - if it fails,
|
|
224
|
+
// the implementation needs adjustment
|
|
225
|
+
if (afterSettingCount.hasData) {
|
|
226
|
+
expect(afterSettingCount.dataPointCount).toBeGreaterThan(0)
|
|
227
|
+
expect(afterSettingCount.dataPointCount).toBeLessThanOrEqual(35) // 30 + tolerance
|
|
228
|
+
}
|
|
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
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ============================================================================
|
|
253
|
+
// BRUSH SECTION ACCESSIBILITY TEST
|
|
254
|
+
// Verifies the brush controls are properly labeled and accessible
|
|
255
|
+
// ============================================================================
|
|
256
|
+
|
|
257
|
+
export const BrushAccessibilityTests: Story = {
|
|
258
|
+
name: 'Accessibility Tests',
|
|
259
|
+
parameters: {
|
|
260
|
+
test: {
|
|
261
|
+
timeout: 20000
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
args: {
|
|
265
|
+
config: {
|
|
266
|
+
...brushEnabledConfig,
|
|
267
|
+
xAxis: {
|
|
268
|
+
...brushEnabledConfig.xAxis,
|
|
269
|
+
brushActive: true
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
isEditor: true
|
|
273
|
+
},
|
|
274
|
+
play: async ({ canvasElement }) => {
|
|
275
|
+
const canvas = within(canvasElement)
|
|
276
|
+
await waitForEditor(canvas)
|
|
277
|
+
await openAccordion(canvas, 'Date/Category Axis')
|
|
278
|
+
|
|
279
|
+
// ============================================================================
|
|
280
|
+
// TEST: Brush Controls Have Proper Labels
|
|
281
|
+
// ============================================================================
|
|
282
|
+
|
|
283
|
+
// The brush slider checkbox should be findable by its label
|
|
284
|
+
const brushCheckbox = canvas.getByLabelText(/show brush slider/i)
|
|
285
|
+
expect(brushCheckbox).toBeTruthy()
|
|
286
|
+
expect(brushCheckbox).toHaveAttribute('type', 'checkbox')
|
|
287
|
+
|
|
288
|
+
// The recent date count input should have a descriptive label
|
|
289
|
+
const recentDateLabel = canvas.getByLabelText(/show last.*dates.*default/i)
|
|
290
|
+
|
|
291
|
+
// If this test fails, it indicates the control needs a proper accessible label
|
|
292
|
+
expect(recentDateLabel).toBeTruthy()
|
|
293
|
+
expect(recentDateLabel).toHaveAttribute('type', 'number')
|
|
294
|
+
}
|
|
295
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import Chart from '../CdcChartComponent'
|
|
3
|
+
import brushEnabledConfig from './_mock/brush_enabled.json'
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Chart> = {
|
|
6
|
+
title: 'Components/Templates/Chart/BrushSlider',
|
|
7
|
+
component: Chart,
|
|
8
|
+
parameters: {
|
|
9
|
+
docs: {
|
|
10
|
+
description: {
|
|
11
|
+
component:
|
|
12
|
+
'Brush Slider feature allows users to interactively filter data by dragging handles along the x-axis. Only works with date/time-based x-axis and vertical orientation.'
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type Story = StoryObj<typeof Chart>
|
|
19
|
+
|
|
20
|
+
export const BrushSliderEnabled: Story = {
|
|
21
|
+
args: {
|
|
22
|
+
config: brushEnabledConfig,
|
|
23
|
+
isEditor: false
|
|
24
|
+
},
|
|
25
|
+
parameters: {
|
|
26
|
+
docs: {
|
|
27
|
+
description: {
|
|
28
|
+
story:
|
|
29
|
+
'Line chart with brush slider enabled. Drag the handles on the slider below the chart to filter the data range.'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const BrushSliderInEditor: Story = {
|
|
36
|
+
args: {
|
|
37
|
+
config: brushEnabledConfig,
|
|
38
|
+
isEditor: true
|
|
39
|
+
},
|
|
40
|
+
parameters: {
|
|
41
|
+
docs: {
|
|
42
|
+
description: {
|
|
43
|
+
story:
|
|
44
|
+
'Brush slider in editor mode. You can toggle the "Brush Slider" checkbox in the X-Axis section to enable/disable it.'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default meta
|