@cdc/chart 4.24.11 → 4.24.12-2
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.js +32134 -32039
- package/examples/feature/sankey/sankey-example-data.json +126 -13
- package/examples/feature/tests-date-exclusions/date-exclusions-config.json +372 -12
- package/examples/private/DEV-8850-2.json +493 -0
- package/examples/private/DEV-9822.json +574 -0
- package/examples/private/DEV-9840.json +553 -0
- package/examples/private/DEV-9850-3.json +461 -0
- package/examples/private/chart.json +1084 -0
- package/examples/private/ci_formatted.json +202 -0
- package/examples/private/ci_issue.json +3016 -0
- package/examples/private/completed.json +634 -0
- package/examples/private/dem-data-long.csv +20 -0
- package/examples/private/dem-data-long.json +36 -0
- package/examples/private/demographic_data.csv +157 -0
- package/examples/private/demographic_data.json +2654 -0
- package/examples/private/demographic_dynamic.json +443 -0
- package/examples/private/demographic_standard.json +560 -0
- package/examples/private/ehdi.json +29939 -0
- package/examples/private/test.json +448 -20047
- package/index.html +9 -6
- package/package.json +2 -2
- package/src/CdcChart.tsx +62 -82
- package/src/_stories/Chart.Anchors.stories.tsx +31 -0
- package/src/_stories/Chart.DynamicSeries.stories.tsx +8 -1
- package/src/_stories/Chart.stories.tsx +32 -0
- package/src/_stories/ChartAxisLabels.stories.tsx +4 -1
- package/{examples/feature/area/area-chart-date-city-temperature.json → src/_stories/_mock/area_chart_stacked.json} +125 -27
- package/src/_stories/_mock/line_chart_dynamic_ci.json +493 -0
- package/src/_stories/_mock/line_chart_non_dynamic_ci.json +522 -0
- package/src/_stories/_mock/short_dates.json +288 -0
- package/src/components/AreaChart/components/AreaChart.Stacked.jsx +15 -3
- package/src/components/Axis/Categorical.Axis.tsx +2 -2
- package/src/components/BarChart/components/BarChart.Horizontal.tsx +46 -37
- package/src/components/BarChart/components/BarChart.Vertical.tsx +28 -40
- package/src/components/BarChart/helpers/getBarData.ts +28 -0
- package/src/components/BarChart/helpers/tests/getBarData.test.ts +74 -0
- package/src/components/BoxPlot/BoxPlot.tsx +12 -70
- package/src/components/BoxPlot/helpers/index.ts +54 -0
- package/src/components/BrushChart.tsx +23 -26
- package/src/components/EditorPanel/EditorPanel.tsx +55 -79
- package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +1 -0
- package/src/components/EditorPanel/useEditorPermissions.ts +5 -1
- package/src/components/Legend/Legend.Component.tsx +2 -2
- package/src/{hooks/useLegendClasses.ts → components/Legend/helpers/getLegendClasses.ts} +5 -5
- package/src/components/Legend/helpers/index.ts +2 -1
- package/src/components/Legend/tests/getLegendClasses.test.ts +115 -0
- package/src/components/LineChart/components/LineChart.Circle.tsx +1 -1
- package/src/components/LineChart/helpers.ts +1 -0
- package/src/components/LineChart/index.tsx +47 -1
- package/src/components/LinearChart.tsx +180 -172
- package/src/components/PieChart/PieChart.tsx +7 -1
- package/src/components/Sankey/components/ColumnList.tsx +19 -0
- package/src/components/Sankey/components/Sankey.tsx +479 -0
- package/src/components/Sankey/helpers/getSankeyTooltip.tsx +33 -0
- package/src/components/Sankey/index.tsx +1 -510
- package/src/components/Sankey/sankey.scss +16 -16
- package/src/components/Sankey/types/index.ts +1 -1
- package/src/data/initial-state.js +4 -3
- package/src/helpers/countNumOfTicks.ts +57 -0
- package/src/helpers/getQuartiles.ts +15 -18
- package/src/hooks/useMinMax.ts +18 -4
- package/src/hooks/useScales.ts +38 -4
- package/src/hooks/useTooltip.tsx +5 -1
- package/src/scss/DataTable.scss +5 -0
- package/src/scss/main.scss +6 -2
|
@@ -15,7 +15,8 @@ export const getMarginTop = (isBottomOrSmallViewport, config) => {
|
|
|
15
15
|
return '0px'
|
|
16
16
|
}
|
|
17
17
|
if (isBottomOrSmallViewport && config.brush?.active) {
|
|
18
|
-
|
|
18
|
+
const BRUSH_HEIGHT_MULTIPLIER = 1.5
|
|
19
|
+
return `${config.brush.height * BRUSH_HEIGHT_MULTIPLIER}px`
|
|
19
20
|
}
|
|
20
21
|
return '20px'
|
|
21
22
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { getLegendClasses } from './../helpers/getLegendClasses'
|
|
3
|
+
import { ChartConfig } from '../../../types/ChartConfig'
|
|
4
|
+
|
|
5
|
+
describe('getLegendClasses', () => {
|
|
6
|
+
it('should return correct classes for left position', () => {
|
|
7
|
+
const config: ChartConfig = {
|
|
8
|
+
legend: {
|
|
9
|
+
position: 'left',
|
|
10
|
+
singleRow: false,
|
|
11
|
+
reverseLabelOrder: false,
|
|
12
|
+
verticalSorted: false,
|
|
13
|
+
hideBorder: { side: false, topBottom: false }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const result = getLegendClasses(config)
|
|
17
|
+
expect(result.containerClasses).toContain('left')
|
|
18
|
+
// Left Position Charts can't have single row...
|
|
19
|
+
expect(result.innerClasses).not.toContain('single-row')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('should return correct classes for right position', () => {
|
|
23
|
+
const config: ChartConfig = {
|
|
24
|
+
legend: {
|
|
25
|
+
position: 'right',
|
|
26
|
+
singleRow: false,
|
|
27
|
+
reverseLabelOrder: false,
|
|
28
|
+
verticalSorted: false,
|
|
29
|
+
hideBorder: { side: false, topBottom: false }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const result = getLegendClasses(config)
|
|
33
|
+
expect(result.containerClasses).toContain('right')
|
|
34
|
+
// Right Position Charts can't have single row...
|
|
35
|
+
expect(result.innerClasses).not.toContain('single-row')
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('should return correct classes for bottom position with single row', () => {
|
|
39
|
+
const config: ChartConfig = {
|
|
40
|
+
legend: {
|
|
41
|
+
position: 'bottom',
|
|
42
|
+
singleRow: true,
|
|
43
|
+
reverseLabelOrder: false,
|
|
44
|
+
verticalSorted: false,
|
|
45
|
+
hideBorder: { side: false, topBottom: false }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const result = getLegendClasses(config)
|
|
49
|
+
expect(result.containerClasses).toContain('bottom')
|
|
50
|
+
expect(result.innerClasses).toContain('double-column')
|
|
51
|
+
expect(result.innerClasses).toContain('bottom')
|
|
52
|
+
expect(result.innerClasses).toContain('single-row')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('should return correct classes for top position with vertical sorting', () => {
|
|
56
|
+
const config: ChartConfig = {
|
|
57
|
+
legend: {
|
|
58
|
+
position: 'top',
|
|
59
|
+
singleRow: false,
|
|
60
|
+
reverseLabelOrder: false,
|
|
61
|
+
verticalSorted: true,
|
|
62
|
+
hideBorder: { side: false, topBottom: false }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const result = getLegendClasses(config)
|
|
66
|
+
expect(result.containerClasses).toContain('top')
|
|
67
|
+
expect(result.innerClasses).toContain('double-column')
|
|
68
|
+
expect(result.innerClasses).toContain('top')
|
|
69
|
+
expect(result.innerClasses).toContain('vertical-sorted')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('should return correct classes for reverse label order', () => {
|
|
73
|
+
const config: ChartConfig = {
|
|
74
|
+
legend: {
|
|
75
|
+
position: 'bottom',
|
|
76
|
+
singleRow: false,
|
|
77
|
+
reverseLabelOrder: true,
|
|
78
|
+
verticalSorted: false,
|
|
79
|
+
hideBorder: { side: false, topBottom: false }
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const result = getLegendClasses(config)
|
|
83
|
+
expect(result.innerClasses).toContain('d-flex')
|
|
84
|
+
expect(result.innerClasses).toContain('flex-column-reverse')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('should return correct classes for hide border side', () => {
|
|
88
|
+
const config: ChartConfig = {
|
|
89
|
+
legend: {
|
|
90
|
+
position: 'left',
|
|
91
|
+
singleRow: false,
|
|
92
|
+
reverseLabelOrder: false,
|
|
93
|
+
verticalSorted: false,
|
|
94
|
+
hideBorder: { side: true, topBottom: false }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const result = getLegendClasses(config)
|
|
98
|
+
expect(result.containerClasses).toContain('border-0')
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('should return correct classes for hide border topBottom', () => {
|
|
102
|
+
const config: ChartConfig = {
|
|
103
|
+
legend: {
|
|
104
|
+
position: 'top',
|
|
105
|
+
singleRow: false,
|
|
106
|
+
reverseLabelOrder: false,
|
|
107
|
+
verticalSorted: false,
|
|
108
|
+
hideBorder: { side: false, topBottom: true }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const result = getLegendClasses(config)
|
|
112
|
+
expect(result.containerClasses).toContain('border-0')
|
|
113
|
+
expect(result.containerClasses).toContain('p-0')
|
|
114
|
+
})
|
|
115
|
+
})
|
|
@@ -82,7 +82,7 @@ const LineChartCircle = (props: LineChartCircleProps) => {
|
|
|
82
82
|
const isMatch = circleData?.some(
|
|
83
83
|
cd => cd[config.xAxis.dataKey] === d[config.xAxis.dataKey] && cd[seriesKey] === d[seriesKey]
|
|
84
84
|
)
|
|
85
|
-
if (isMatch) {
|
|
85
|
+
if (isMatch || !filtered) {
|
|
86
86
|
return <></>
|
|
87
87
|
}
|
|
88
88
|
return (
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataItem, StyleProps, Style } from './LineChartProps'
|
|
2
2
|
import { PreliminaryDataItem } from '../../types/ChartConfig'
|
|
3
|
+
import { getTextWidth } from '@cdc/core/helpers/getTextWidth'
|
|
3
4
|
import _ from 'lodash'
|
|
4
5
|
export const createStyles = (props: StyleProps): Style[] => {
|
|
5
6
|
const { preliminaryData, data, stroke, strokeWidth, handleLineType, lineType, seriesKey } = props
|
|
@@ -3,7 +3,7 @@ import React, { useContext } from 'react'
|
|
|
3
3
|
// VisX library imports
|
|
4
4
|
import * as allCurves from '@visx/curve'
|
|
5
5
|
import { Group } from '@visx/group'
|
|
6
|
-
import { LinePath, Bar, SplitLinePath } from '@visx/shape'
|
|
6
|
+
import { LinePath, Bar, SplitLinePath, AreaClosed } from '@visx/shape'
|
|
7
7
|
import { Text } from '@visx/text'
|
|
8
8
|
|
|
9
9
|
// CDC core components
|
|
@@ -252,6 +252,52 @@ const LineChart = (props: LineChartProps) => {
|
|
|
252
252
|
</>
|
|
253
253
|
) : (
|
|
254
254
|
<>
|
|
255
|
+
{/* Confidence Interval Band */}
|
|
256
|
+
{config.confidenceKeys &&
|
|
257
|
+
config.series.map((seriesData, seriesKey) => {
|
|
258
|
+
if (seriesData.dynamicCategory) {
|
|
259
|
+
// Get unique categories from the data
|
|
260
|
+
const uniqueCategories = [...new Set(data.map(d => d[seriesData.dynamicCategory]))]
|
|
261
|
+
|
|
262
|
+
return uniqueCategories.map((category, categoryIndex) => {
|
|
263
|
+
const categoryData = data.filter(d => d[seriesData.dynamicCategory] === category)
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<AreaClosed
|
|
267
|
+
key={`area-closed-${seriesKey}-${categoryIndex}`}
|
|
268
|
+
data={categoryData}
|
|
269
|
+
x={d => xPos(d)}
|
|
270
|
+
y0={d => yScale(d[config.confidenceKeys.lower])} // Lower bound of the confidence interval
|
|
271
|
+
y1={d => yScale(d[config.confidenceKeys.upper])} // Upper bound of the confidence interval
|
|
272
|
+
opacity={0.5}
|
|
273
|
+
fill={colorScale(category)} // Optional: Color based on category
|
|
274
|
+
yScale={yScale}
|
|
275
|
+
curve={allCurves[seriesData.lineType as keyof typeof allCurves]}
|
|
276
|
+
/>
|
|
277
|
+
)
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Default behavior for non-dynamic categories
|
|
282
|
+
return (
|
|
283
|
+
<AreaClosed
|
|
284
|
+
key={`area-closed-${seriesKey}`}
|
|
285
|
+
data={data}
|
|
286
|
+
x={d => xPos(d)}
|
|
287
|
+
y0={d => yScale(d[config.confidenceKeys.lower])}
|
|
288
|
+
y1={d => yScale(d[config.confidenceKeys.upper])}
|
|
289
|
+
opacity={0.5}
|
|
290
|
+
fill={colorScale(
|
|
291
|
+
config.runtime.seriesLabels
|
|
292
|
+
? config.runtime.seriesLabels[seriesData.dataKey]
|
|
293
|
+
: seriesData.dataKey
|
|
294
|
+
)}
|
|
295
|
+
yScale={yScale}
|
|
296
|
+
curve={allCurves[seriesData.lineType as keyof typeof allCurves]}
|
|
297
|
+
/>
|
|
298
|
+
)
|
|
299
|
+
})}
|
|
300
|
+
|
|
255
301
|
{/* STANDARD LINE */}
|
|
256
302
|
<LinePath
|
|
257
303
|
curve={allCurves[seriesData.lineType]}
|