@cdc/chart 4.26.5 → 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 +12 -8
- package/dist/{cdcchart-DQ00cQCm.es.js → cdcchart-BWVIUcAF.es.js} +5 -55
- package/dist/cdcchart.js +34093 -32767
- package/examples/feature/heatmap/average-age-categorical.json +1 -1
- package/examples/feature/heatmap/calendar-heatmap.json +1 -1
- package/examples/feature/heatmap/sparse-aggregation.json +1 -1
- package/examples/private/bad-y-axis.json +543 -0
- package/examples/private/bar-chart-negative-value.json +455 -0
- package/package.json +3 -3
- package/src/CdcChart.tsx +5 -4
- package/src/CdcChartComponent.tsx +32 -9
- package/src/_stories/Chart.SeriesColorAssignments.stories.tsx +183 -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/_mock/annotation_event-line_mock.json +1064 -0
- package/src/_stories/_mock/heatmap-average-age-categorical.json +1 -1
- package/src/_stories/_mock/heatmap.json +1 -1
- package/src/components/Annotations/components/AnnotationDraggable.styles.css +22 -1
- package/src/components/Annotations/components/AnnotationDraggable.tsx +219 -119
- package/src/components/Annotations/tests/AnnotationDraggable.test.tsx +198 -0
- package/src/components/Axis/LeftAxis.tsx +3 -0
- package/src/components/Axis/LeftAxisGridlines.tsx +8 -1
- package/src/components/Axis/RightAxis.tsx +3 -0
- package/src/components/Axis/tests/AxisTickValues.test.tsx +86 -0
- package/src/components/EditorPanel/EditorPanel.tsx +367 -136
- package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +101 -52
- 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 +3 -0
- 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 +6 -2
- package/src/components/EditorPanel/helpers/tests/getVisualizationTypeConfigUpdate.test.ts +20 -2
- package/src/components/EditorPanel/useEditorPermissions.test.tsx +256 -11
- package/src/components/EditorPanel/useEditorPermissions.ts +41 -5
- package/src/components/HeatMap/components/HeatMap.tsx +22 -17
- package/src/components/HeatMap/components/HeatMapGradientLegend.tsx +29 -15
- package/src/components/HeatMap/heatmap.css +15 -1
- package/src/components/HeatMap/tests/HeatMap.test.tsx +39 -7
- 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/helpers.test.ts +230 -1
- package/src/components/LineChart/helpers.ts +26 -13
- package/src/components/LineChart/index.tsx +21 -4
- package/src/components/LinearChart/tests/LinearChart.test.tsx +30 -0
- package/src/components/LinearChart.tsx +50 -15
- package/src/components/ScatterPlot/ScatterPlot.jsx +3 -3
- package/src/components/SmallMultiples/SmallMultipleTile.tsx +3 -0
- package/src/components/SmallMultiples/SmallMultiples.tsx +38 -9
- package/src/components/SmallMultiples/tests/SmallMultiples.test.tsx +170 -0
- package/src/data/initial-state.js +1 -0
- package/src/helpers/calculateLeftYAxisWidth.ts +9 -3
- package/src/helpers/colorAssignmentHelpers.ts +102 -0
- package/src/helpers/dataHelpers.ts +11 -1
- 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 +24 -22
- package/src/helpers/getYAxisDomainData.ts +38 -0
- package/src/helpers/getYAxisFinalizationEligibility.ts +40 -0
- package/src/helpers/hasSpacedInlineLabel.ts +10 -0
- package/src/helpers/seriesColumnSettings.ts +5 -4
- package/src/helpers/smallMultiplesHelpers.ts +5 -0
- package/src/helpers/tests/calculateLeftYAxisWidth.test.ts +38 -0
- package/src/helpers/tests/dataHelpers.test.ts +135 -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/{getYAxisAutoPaddingMode.test.ts → hasSpacedInlineLabel.test.ts} +17 -32
- package/src/helpers/tests/seriesColumnSettings.test.ts +16 -2
- 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 +307 -29
- package/src/hooks/useRightAxis.ts +30 -13
- package/src/hooks/useScales.ts +45 -28
- package/src/hooks/useTooltip.tsx +3 -1
- package/src/test/CdcChart.dataTable.test.tsx +122 -0
- package/src/types/ChartConfig.ts +6 -1
- package/src/types/ChartContext.ts +3 -0
- package/src/helpers/getYAxisAutoPadding.ts +0 -55
- package/src/helpers/getYAxisAutoPaddingMode.ts +0 -17
- package/src/helpers/tests/getYAxisAutoPadding.test.ts +0 -37
|
@@ -28,6 +28,7 @@ interface LeftAxisProps {
|
|
|
28
28
|
xMax: number
|
|
29
29
|
yAxisWidth: number
|
|
30
30
|
numTicks: number
|
|
31
|
+
tickValues?: number[]
|
|
31
32
|
tickLabelFontSize: number
|
|
32
33
|
axisLabelFontSize: number
|
|
33
34
|
handleLeftTickFormatting: (tick: any, index: number, ticks: any[]) => string
|
|
@@ -45,6 +46,7 @@ const LeftAxis: React.FC<LeftAxisProps> = ({
|
|
|
45
46
|
xMax,
|
|
46
47
|
yAxisWidth,
|
|
47
48
|
numTicks,
|
|
49
|
+
tickValues,
|
|
48
50
|
tickLabelFontSize,
|
|
49
51
|
axisLabelFontSize,
|
|
50
52
|
handleLeftTickFormatting,
|
|
@@ -71,6 +73,7 @@ const LeftAxis: React.FC<LeftAxisProps> = ({
|
|
|
71
73
|
stroke='#333'
|
|
72
74
|
tickFormat={handleLeftTickFormatting}
|
|
73
75
|
numTicks={numTicks}
|
|
76
|
+
{...(tickValues ? { tickValues } : {})}
|
|
74
77
|
>
|
|
75
78
|
{props => {
|
|
76
79
|
const axisCenter =
|
|
@@ -10,6 +10,7 @@ interface LeftAxisGridlinesProps {
|
|
|
10
10
|
xMax: number
|
|
11
11
|
yAxisWidth: number
|
|
12
12
|
numTicks: number
|
|
13
|
+
tickValues?: number[]
|
|
13
14
|
axisLabelFontSize: number
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -18,6 +19,7 @@ const LeftAxisGridlines: React.FC<LeftAxisGridlinesProps> = ({
|
|
|
18
19
|
xMax,
|
|
19
20
|
yAxisWidth,
|
|
20
21
|
numTicks,
|
|
22
|
+
tickValues,
|
|
21
23
|
axisLabelFontSize
|
|
22
24
|
}) => {
|
|
23
25
|
const { config } = useContext(ConfigContext)
|
|
@@ -27,7 +29,12 @@ const LeftAxisGridlines: React.FC<LeftAxisGridlinesProps> = ({
|
|
|
27
29
|
const showSideTitle = config.yAxis.titlePlacement !== 'top'
|
|
28
30
|
|
|
29
31
|
return (
|
|
30
|
-
<AxisLeft
|
|
32
|
+
<AxisLeft
|
|
33
|
+
scale={yScale}
|
|
34
|
+
left={yAxisWidth - config.yAxis.axisPadding}
|
|
35
|
+
numTicks={numTicks}
|
|
36
|
+
{...(tickValues ? { tickValues } : {})}
|
|
37
|
+
>
|
|
31
38
|
{props => {
|
|
32
39
|
const axisCenter =
|
|
33
40
|
config.orientation === 'horizontal'
|
|
@@ -15,6 +15,7 @@ type RightAxisProps = {
|
|
|
15
15
|
yMax: number
|
|
16
16
|
xMax: number
|
|
17
17
|
yAxisWidth: number
|
|
18
|
+
tickValues?: number[]
|
|
18
19
|
tickLabelFontSize: number
|
|
19
20
|
axisLabelFontSize: number
|
|
20
21
|
}
|
|
@@ -29,6 +30,7 @@ export const RightAxis: React.FC<RightAxisProps> = ({
|
|
|
29
30
|
yMax,
|
|
30
31
|
xMax,
|
|
31
32
|
yAxisWidth,
|
|
33
|
+
tickValues,
|
|
32
34
|
tickLabelFontSize,
|
|
33
35
|
axisLabelFontSize
|
|
34
36
|
}) => {
|
|
@@ -45,6 +47,7 @@ export const RightAxis: React.FC<RightAxisProps> = ({
|
|
|
45
47
|
label={config.yAxis.rightLabel}
|
|
46
48
|
tickFormat={tick => formatNumber(tick, 'right')}
|
|
47
49
|
numTicks={runtime.yAxis.rightNumTicks || undefined}
|
|
50
|
+
{...(tickValues ? { tickValues } : {})}
|
|
48
51
|
labelOffset={45}
|
|
49
52
|
>
|
|
50
53
|
{props => {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { render, screen } from '@testing-library/react'
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
+
import ConfigContext from '../../../ConfigContext'
|
|
5
|
+
import { createMockChartContext, createMockConfig } from '../../LinearChart/tests/mockConfigContext'
|
|
6
|
+
|
|
7
|
+
vi.mock('@visx/axis', () => ({
|
|
8
|
+
AxisLeft: ({ tickValues }: { tickValues?: number[] }) => (
|
|
9
|
+
<div data-testid='axis-left' data-tick-values={JSON.stringify(tickValues ?? null)} />
|
|
10
|
+
),
|
|
11
|
+
AxisRight: ({ tickValues }: { tickValues?: number[] }) => (
|
|
12
|
+
<div data-testid='axis-right' data-tick-values={JSON.stringify(tickValues ?? null)} />
|
|
13
|
+
)
|
|
14
|
+
}))
|
|
15
|
+
|
|
16
|
+
import LeftAxis from '../LeftAxis'
|
|
17
|
+
import LeftAxisGridlines from '../LeftAxisGridlines'
|
|
18
|
+
import RightAxis from '../RightAxis'
|
|
19
|
+
|
|
20
|
+
const tickValues = [0, 5, 10, 15]
|
|
21
|
+
|
|
22
|
+
const renderWithContext = (children: React.ReactNode) => {
|
|
23
|
+
const config = createMockConfig({
|
|
24
|
+
runtime: {
|
|
25
|
+
...createMockConfig().runtime,
|
|
26
|
+
yAxis: {
|
|
27
|
+
...createMockConfig().runtime.yAxis,
|
|
28
|
+
rightNumTicks: 4
|
|
29
|
+
}
|
|
30
|
+
} as any
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
return render(<ConfigContext.Provider value={createMockChartContext(config)}>{children}</ConfigContext.Provider>)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('axis tick values', () => {
|
|
37
|
+
it('passes supplied tick values to the left axis', () => {
|
|
38
|
+
renderWithContext(
|
|
39
|
+
<LeftAxis
|
|
40
|
+
yScale={{}}
|
|
41
|
+
xScale={{}}
|
|
42
|
+
yMax={100}
|
|
43
|
+
xMax={300}
|
|
44
|
+
yAxisWidth={50}
|
|
45
|
+
numTicks={4}
|
|
46
|
+
tickValues={tickValues}
|
|
47
|
+
tickLabelFontSize={16}
|
|
48
|
+
axisLabelFontSize={16}
|
|
49
|
+
handleLeftTickFormatting={tick => String(tick)}
|
|
50
|
+
/>
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
expect(JSON.parse(screen.getByTestId('axis-left').dataset.tickValues || 'null')).toEqual(tickValues)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('passes supplied tick values to left-axis gridlines', () => {
|
|
57
|
+
renderWithContext(
|
|
58
|
+
<LeftAxisGridlines
|
|
59
|
+
yScale={{}}
|
|
60
|
+
xMax={300}
|
|
61
|
+
yAxisWidth={50}
|
|
62
|
+
numTicks={4}
|
|
63
|
+
tickValues={tickValues}
|
|
64
|
+
axisLabelFontSize={16}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
expect(JSON.parse(screen.getByTestId('axis-left').dataset.tickValues || 'null')).toEqual(tickValues)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('passes supplied tick values to the right axis', () => {
|
|
72
|
+
renderWithContext(
|
|
73
|
+
<RightAxis
|
|
74
|
+
yScaleRight={{} as any}
|
|
75
|
+
yMax={100}
|
|
76
|
+
xMax={300}
|
|
77
|
+
yAxisWidth={50}
|
|
78
|
+
tickValues={tickValues}
|
|
79
|
+
tickLabelFontSize={16}
|
|
80
|
+
axisLabelFontSize={16}
|
|
81
|
+
/>
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
expect(JSON.parse(screen.getByTestId('axis-right').dataset.tickValues || 'null')).toEqual(tickValues)
|
|
85
|
+
})
|
|
86
|
+
})
|