@cdc/chart 4.22.10 → 4.22.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.
- package/README.md +5 -5
- package/dist/cdcchart.js +4 -4
- package/examples/age-adjusted-rates.json +1486 -1218
- package/examples/case-rate-example-config.json +1 -1
- package/examples/covid-confidence-example-config.json +33 -33
- package/examples/covid-example-config.json +34 -34
- package/examples/covid-example-data-confidence.json +30 -30
- package/examples/covid-example-data.json +20 -20
- package/examples/cutoff-example-config.json +36 -36
- package/examples/cutoff-example-data.json +36 -36
- package/examples/date-exclusions-config.json +1 -1
- package/examples/dynamic-legends.json +124 -124
- package/examples/gallery/bar-chart-horizontal/horizontal-bar-chart-with-numbers-on-bar.json +191 -197
- package/examples/gallery/bar-chart-horizontal/horizontal-bar-chart.json +230 -240
- package/examples/gallery/bar-chart-horizontal/horizontal-stacked.json +239 -247
- package/examples/gallery/bar-chart-vertical/combo-line-chart.json +136 -136
- package/examples/gallery/bar-chart-vertical/vertical-bar-chart-categorical.json +79 -79
- package/examples/gallery/bar-chart-vertical/vertical-bar-chart-stacked.json +80 -80
- package/examples/gallery/bar-chart-vertical/vertical-bar-chart-with-confidence.json +67 -67
- package/examples/gallery/bar-chart-vertical/vertical-bar-chart.json +110 -110
- package/examples/gallery/lollipop/lollipop-style-horizontal.json +215 -219
- package/examples/gallery/paired-bar/paired-bar-chart.json +195 -195
- package/examples/horizontal-chart.json +35 -35
- package/examples/horizontal-stacked-bar-chart.json +34 -34
- package/examples/line-chart.json +75 -75
- package/examples/paired-bar-data.json +16 -14
- package/examples/paired-bar-example.json +48 -48
- package/examples/paired-bar-formatted.json +36 -36
- package/examples/planet-chart-horizontal-example-config.json +33 -33
- package/examples/planet-combo-example-config.json +34 -31
- package/examples/planet-example-config.json +35 -33
- package/examples/planet-example-data.json +56 -56
- package/examples/planet-pie-example-config.json +28 -28
- package/examples/private/filters.json +170 -0
- package/examples/private/line-test-data.json +21 -21
- package/examples/private/line-test-two.json +209 -215
- package/examples/private/line-test.json +101 -101
- package/examples/private/new.json +48800 -0
- package/examples/private/shawn.json +1105 -1295
- package/examples/private/test.json +10123 -10123
- package/examples/private/yaxis-test.json +4 -3
- package/examples/private/yaxis.json +26 -26
- package/examples/stacked-vertical-bar-example.json +1 -1
- package/examples/temp-example-config.json +61 -54
- package/examples/temp-example-data.json +1 -1
- package/package.json +2 -2
- package/src/CdcChart.tsx +339 -380
- package/src/components/BarChart.tsx +425 -469
- package/src/components/DataTable.tsx +164 -195
- package/src/components/EditorPanel.js +1009 -710
- package/src/components/Legend.js +279 -329
- package/src/components/LineChart.tsx +90 -79
- package/src/components/LinearChart.tsx +376 -434
- package/src/components/PairedBarChart.tsx +197 -213
- package/src/components/PieChart.tsx +95 -151
- package/src/components/SparkLine.js +179 -201
- package/src/components/useIntersectionObserver.tsx +17 -20
- package/src/context.tsx +3 -3
- package/src/data/initial-state.js +37 -16
- package/src/hooks/useActiveElement.js +13 -13
- package/src/hooks/useChartClasses.js +34 -28
- package/src/hooks/useColorPalette.ts +56 -63
- package/src/hooks/useLegendClasses.js +18 -10
- package/src/hooks/useReduceData.ts +62 -78
- package/src/hooks/useRightAxis.js +25 -0
- package/src/hooks/useTopAxis.js +6 -0
- package/src/index.html +45 -45
- package/src/index.tsx +13 -16
- package/src/scss/DataTable.scss +5 -4
- package/src/scss/editor-panel.scss +71 -69
- package/src/scss/main.scss +157 -114
- package/src/scss/variables.scss +1 -1
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import React, { useContext } from 'react'
|
|
1
|
+
import React, { useContext } from 'react'
|
|
2
2
|
|
|
3
|
-
import * as allCurves from '@visx/curve'
|
|
4
|
-
import { Group } from '@visx/group'
|
|
5
|
-
import { LinePath } from '@visx/shape'
|
|
6
|
-
import { Text } from '@visx/text'
|
|
3
|
+
import * as allCurves from '@visx/curve'
|
|
4
|
+
import { Group } from '@visx/group'
|
|
5
|
+
import { LinePath } from '@visx/shape'
|
|
6
|
+
import { Text } from '@visx/text'
|
|
7
7
|
|
|
8
|
-
import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
|
|
8
|
+
import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
|
|
9
9
|
|
|
10
|
-
import Context from '../context'
|
|
10
|
+
import Context from '../context'
|
|
11
|
+
|
|
12
|
+
import useRightAxis from '../hooks/useRightAxis'
|
|
11
13
|
|
|
12
14
|
export default function LineChart({ xScale, yScale, getXAxisData, getYAxisData, xMax, yMax, seriesStyle = 'Line' }) {
|
|
13
|
-
const { colorPalettes, transformedData: data, colorScale, seriesHighlight, config, formatNumber,formatDate,parseDate } = useContext<any>(Context)
|
|
15
|
+
const { colorPalettes, transformedData: data, colorScale, seriesHighlight, config, formatNumber, formatDate, parseDate, updateConfig } = useContext<any>(Context)
|
|
16
|
+
const { yScaleRight } = useRightAxis({ config, yMax, data, updateConfig })
|
|
14
17
|
|
|
15
|
-
const handleLineType =
|
|
16
|
-
switch(lineType) {
|
|
18
|
+
const handleLineType = lineType => {
|
|
19
|
+
switch (lineType) {
|
|
17
20
|
case 'dashed-sm':
|
|
18
21
|
return '5 5'
|
|
19
22
|
case 'dashed-md':
|
|
@@ -21,96 +24,104 @@ export default function LineChart({ xScale, yScale, getXAxisData, getYAxisData,
|
|
|
21
24
|
case 'dashed-lg':
|
|
22
25
|
return '15 5'
|
|
23
26
|
default:
|
|
24
|
-
return 0
|
|
27
|
+
return 0
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
console.log('seriesStyle', seriesStyle)
|
|
29
|
-
|
|
30
31
|
return (
|
|
31
|
-
<ErrorBoundary component=
|
|
32
|
+
<ErrorBoundary component='LineChart'>
|
|
32
33
|
<Group left={config.runtime.yAxis.size}>
|
|
33
|
-
{
|
|
34
|
+
{(config.runtime.lineSeriesKeys || config.runtime.seriesKeys).map((seriesKey, index) => {
|
|
34
35
|
let lineType = config.series.filter(item => item.dataKey === seriesKey)[0].type
|
|
36
|
+
const seriesData = config.series.filter(item => item.dataKey === seriesKey)
|
|
37
|
+
const seriesAxis = seriesData[0].axis ? seriesData[0].axis : 'left'
|
|
38
|
+
|
|
35
39
|
return (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
<Group
|
|
41
|
+
key={`series-${seriesKey}`}
|
|
42
|
+
opacity={config.legend.behavior === 'highlight' && seriesHighlight.length > 0 && seriesHighlight.indexOf(seriesKey) === -1 ? 0.5 : 1}
|
|
43
|
+
display={config.legend.behavior === 'highlight' || (seriesHighlight.length === 0 && !config.legend.dynamicLegend) || seriesHighlight.indexOf(seriesKey) !== -1 ? 'block' : 'none'}
|
|
44
|
+
>
|
|
45
|
+
{data.map((d, dataIndex) => {
|
|
46
|
+
let seriesAxis = config.series.filter(s => s.dataKey === seriesKey)[0].axis
|
|
47
|
+
const xAxisValue = config.runtime.xAxis.type === 'date' ? formatDate(parseDate(d[config.runtime.xAxis.dataKey])) : d[config.runtime.xAxis.dataKey]
|
|
48
|
+
const yAxisValue = formatNumber(getYAxisData(d, seriesKey));
|
|
49
|
+
let yAxisTooltip = config.runtime.yAxis.isLegendValue ? `${seriesKey}: ${yAxisValue} ` : config.runtime.yAxis.label ? `${config.runtime.yAxis.label}: ${yAxisValue}` : yAxisValue;
|
|
50
|
+
let xAxisTooltip = config.runtime.xAxis.label ? `${config.runtime.xAxis.label}: ${xAxisValue}` : xAxisValue
|
|
51
|
+
if (seriesAxis === 'Left') {
|
|
52
|
+
yAxisTooltip = config.runtime.yAxis.label ? `${config.runtime.yAxis.label}: ${formatNumber(getYAxisData(d, seriesKey))}` : formatNumber(getYAxisData(d, seriesKey))
|
|
53
|
+
} else {
|
|
54
|
+
yAxisTooltip = config.runtime.yAxis.rightLabel ? `${config.runtime.yAxis.rightLabel}: ${formatNumber(getYAxisData(d, seriesKey))}` : formatNumber(getYAxisData(d, seriesKey))
|
|
55
|
+
}
|
|
56
|
+
const tooltip = `<div>
|
|
57
|
+
${yAxisTooltip}<br />
|
|
58
|
+
${xAxisTooltip}<br />
|
|
59
|
+
${config.seriesLabel ? `${config.seriesLabel}: ${seriesKey}` : ''}
|
|
60
|
+
</div>`
|
|
61
|
+
let circleRadii = 4.5
|
|
62
|
+
return (
|
|
63
|
+
d[seriesKey] !== undefined &&
|
|
64
|
+
d[seriesKey] !== '' &&
|
|
65
|
+
d[seriesKey] !== null && (
|
|
66
|
+
<Group key={`series-${seriesKey}-point-${dataIndex}`}>
|
|
67
|
+
<Text
|
|
68
|
+
display={config.labels ? 'block' : 'none'}
|
|
69
|
+
x={xScale(getXAxisData(d))}
|
|
70
|
+
y={seriesAxis === 'Right' ? yScaleRight(getYAxisData(d, seriesKey)) : yScale(getYAxisData(d, seriesKey))}
|
|
71
|
+
fill={colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey) : '#000'}
|
|
72
|
+
textAnchor='middle'
|
|
73
|
+
>
|
|
74
|
+
{formatNumber(d[seriesKey])}
|
|
75
|
+
</Text>
|
|
45
76
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
77
|
+
<circle
|
|
78
|
+
key={`${seriesKey}-${dataIndex}`}
|
|
79
|
+
r={circleRadii}
|
|
80
|
+
cx={xScale(getXAxisData(d))}
|
|
81
|
+
cy={seriesAxis === 'Right' ? yScaleRight(getYAxisData(d, seriesKey)) : yScale(getYAxisData(d, seriesKey))}
|
|
82
|
+
fill={colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey) : '#000'}
|
|
83
|
+
style={{ fill: colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey) : '#000' }}
|
|
84
|
+
data-tip={tooltip}
|
|
85
|
+
data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
|
|
86
|
+
/>
|
|
87
|
+
</Group>
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
})}
|
|
51
91
|
|
|
52
|
-
let circleRadii = 4.5
|
|
53
|
-
return (d[seriesKey] !== undefined && d[seriesKey] !== "") && (
|
|
54
|
-
<Group key={`series-${seriesKey}-point-${dataIndex}`}>
|
|
55
|
-
|
|
56
|
-
<Text
|
|
57
|
-
display={config.labels ? 'block' : 'none'}
|
|
58
|
-
x={xScale(getXAxisData(d))}
|
|
59
|
-
y={yScale(getYAxisData(d, seriesKey))}
|
|
60
|
-
fill={colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey) : '#000'}
|
|
61
|
-
textAnchor="middle">
|
|
62
|
-
{formatNumber(d[seriesKey])}
|
|
63
|
-
</Text>
|
|
64
|
-
|
|
65
|
-
<circle
|
|
66
|
-
key={`${seriesKey}-${dataIndex}`}
|
|
67
|
-
r={circleRadii}
|
|
68
|
-
cx={xScale(getXAxisData(d))}
|
|
69
|
-
cy={yScale(getYAxisData(d, seriesKey))}
|
|
70
|
-
fill={colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey) : '#000'}
|
|
71
|
-
style={{fill: colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey) : '#000'}}
|
|
72
|
-
data-tip={tooltip}
|
|
73
|
-
data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
|
|
74
|
-
/>
|
|
75
|
-
</Group>
|
|
76
|
-
)
|
|
77
|
-
})}
|
|
78
92
|
<LinePath
|
|
79
93
|
curve={allCurves.curveLinear}
|
|
80
94
|
data={data}
|
|
81
|
-
x={
|
|
82
|
-
y={(d)
|
|
83
|
-
stroke={
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
95
|
+
x={d => xScale(getXAxisData(d))}
|
|
96
|
+
y={d => (seriesAxis === 'Right' ? yScaleRight(getYAxisData(d, seriesKey)) : yScale(getYAxisData(d, seriesKey)))}
|
|
97
|
+
stroke={
|
|
98
|
+
colorScale && !config.legend.dynamicLegend
|
|
99
|
+
? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[seriesKey] : seriesKey)
|
|
100
|
+
: // is dynamic legend
|
|
101
|
+
config.legend.dynamicLegend
|
|
102
|
+
? colorPalettes[config.palette][index]
|
|
103
|
+
: // fallback
|
|
104
|
+
'#000'
|
|
88
105
|
}
|
|
89
106
|
strokeWidth={2}
|
|
90
107
|
strokeOpacity={1}
|
|
91
|
-
shapeRendering=
|
|
108
|
+
shapeRendering='geometricPrecision'
|
|
92
109
|
strokeDasharray={lineType ? handleLineType(lineType) : 0}
|
|
93
110
|
defined={(item,i) => {
|
|
94
|
-
return item[config.runtime.seriesLabels[seriesKey]] !== "";
|
|
111
|
+
return item[config.runtime.seriesLabels[seriesKey]] !== "" && item[config.runtime.seriesLabels[seriesKey]] !== null;
|
|
95
112
|
}}
|
|
96
113
|
/>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
114
|
+
</Group>
|
|
115
|
+
)
|
|
116
|
+
})}
|
|
117
|
+
|
|
101
118
|
{/* Message when dynamic legend and nothing has been picked */}
|
|
102
|
-
{
|
|
103
|
-
<Text
|
|
104
|
-
|
|
105
|
-
y={yMax / 2}
|
|
106
|
-
fill="black"
|
|
107
|
-
textAnchor="middle"
|
|
108
|
-
color='black'
|
|
109
|
-
>
|
|
110
|
-
{config.legend.dynamicLegendChartMessage}
|
|
119
|
+
{config.legend.dynamicLegend && seriesHighlight.length === 0 && (
|
|
120
|
+
<Text x={xMax / 2} y={yMax / 2} fill='black' textAnchor='middle' color='black'>
|
|
121
|
+
{config.legend.dynamicLegendChartMessage}
|
|
111
122
|
</Text>
|
|
112
|
-
}
|
|
123
|
+
)}
|
|
113
124
|
</Group>
|
|
114
125
|
</ErrorBoundary>
|
|
115
|
-
)
|
|
126
|
+
)
|
|
116
127
|
}
|