@cdc/chart 4.24.1 → 4.24.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.
Files changed (58) hide show
  1. package/dist/cdcchart.js +30014 -29757
  2. package/examples/feature/line/line-chart-preliminary.json +84 -37
  3. package/examples/feature/regions/index.json +9 -5
  4. package/index.html +4 -2
  5. package/package.json +2 -2
  6. package/src/CdcChart.tsx +41 -24
  7. package/src/_stories/ChartEditor.stories.tsx +1 -1
  8. package/src/_stories/_mock/pie_config.json +4 -3
  9. package/src/components/AreaChart/components/AreaChart.jsx +1 -25
  10. package/src/components/BarChart/components/BarChart.StackedVertical.tsx +7 -5
  11. package/src/components/BarChart/components/BarChart.Vertical.tsx +12 -13
  12. package/src/components/BoxPlot/BoxPlot.jsx +9 -8
  13. package/src/components/EditorPanel/EditorPanel.tsx +1563 -1959
  14. package/src/components/EditorPanel/EditorPanelContext.ts +40 -0
  15. package/src/components/EditorPanel/components/Panels/Panel.BoxPlot.tsx +148 -0
  16. package/src/components/EditorPanel/components/{Panel.ForestPlotSettings.tsx → Panels/Panel.ForestPlotSettings.tsx} +16 -7
  17. package/src/components/EditorPanel/components/Panels/Panel.General.tsx +160 -0
  18. package/src/components/EditorPanel/components/{Panel.Regions.tsx → Panels/Panel.Regions.tsx} +5 -5
  19. package/src/components/EditorPanel/components/{Panel.Series.tsx → Panels/Panel.Series.tsx} +4 -4
  20. package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +297 -0
  21. package/src/components/EditorPanel/components/Panels/index.tsx +17 -0
  22. package/src/components/EditorPanel/editor-panel.scss +1 -13
  23. package/src/components/EditorPanel/useEditorPermissions.js +5 -0
  24. package/src/components/Legend/Legend.Component.tsx +199 -0
  25. package/src/components/Legend/Legend.tsx +5 -324
  26. package/src/components/Legend/helpers/createFormatLabels.tsx +140 -0
  27. package/src/components/LineChart/LineChartProps.ts +1 -1
  28. package/src/components/LineChart/components/LineChart.Circle.tsx +85 -52
  29. package/src/components/LineChart/helpers.ts +2 -2
  30. package/src/components/LineChart/index.tsx +97 -21
  31. package/src/components/LinearChart.jsx +3 -3
  32. package/src/components/PairedBarChart.jsx +4 -2
  33. package/src/components/PieChart/PieChart.tsx +78 -25
  34. package/src/components/Regions/components/Regions.tsx +14 -5
  35. package/src/data/initial-state.js +5 -2
  36. package/src/helpers/computeMarginBottom.ts +2 -2
  37. package/src/hooks/useHighlightedBars.js +1 -1
  38. package/src/hooks/useMinMax.ts +3 -3
  39. package/src/hooks/useScales.ts +18 -5
  40. package/src/hooks/useTooltip.tsx +11 -7
  41. package/src/scss/main.scss +0 -67
  42. package/src/types/ChartConfig.ts +17 -8
  43. package/src/types/ChartContext.ts +10 -4
  44. package/src/types/Label.ts +7 -0
  45. package/examples/private/chart-t.json +0 -3740
  46. package/examples/private/combo.json +0 -369
  47. package/examples/private/epi-data.csv +0 -13
  48. package/examples/private/epi-data.json +0 -62
  49. package/examples/private/epi.json +0 -403
  50. package/examples/private/occupancy.json +0 -109283
  51. package/examples/private/prod-line-config.json +0 -401
  52. package/examples/private/region-data.json +0 -822
  53. package/examples/private/region-testing.json +0 -312
  54. package/examples/private/scaling.json +0 -45325
  55. package/examples/private/testing-data.json +0 -1739
  56. package/examples/private/testing.json +0 -816
  57. package/src/components/EditorPanel/components/Panel.DateHighlighting.tsx +0 -109
  58. package/src/components/EditorPanel/components/Panels.tsx +0 -13
@@ -73,7 +73,10 @@ export const BarChartVertical = () => {
73
73
  data={data}
74
74
  keys={config.runtime.barSeriesKeys || config.runtime.seriesKeys}
75
75
  height={yMax}
76
- x0={d => d[config.runtime.originalXAxis.dataKey]}
76
+ x0={d => {
77
+ const rawXValue = d[config.runtime.originalXAxis.dataKey]
78
+ return config.runtime.xAxis.type === 'date' ? parseDate(rawXValue) : rawXValue
79
+ }}
77
80
  x0Scale={xScale}
78
81
  x1Scale={seriesScale}
79
82
  yScale={yScale}
@@ -83,7 +86,7 @@ export const BarChartVertical = () => {
83
86
  >
84
87
  {barGroups => {
85
88
  return barGroups.map((barGroup, index) => (
86
- <Group className={`bar-group-${barGroup.index}-${barGroup.x0}--${index} ${config.orientation}`} key={`bar-group-${barGroup.index}-${barGroup.x0}--${index}`} id={`bar-group-${barGroup.index}-${barGroup.x0}--${index}`} left={(xMax / barGroups.length) * barGroup.index}>
89
+ <Group className={`bar-group-${barGroup.index}-${barGroup.x0}--${index} ${config.orientation}`} key={`bar-group-${barGroup.index}-${barGroup.x0}--${index}`} id={`bar-group-${barGroup.index}-${barGroup.x0}--${index}`} left={barGroup.x0}>
87
90
  {barGroup.bars.map((bar, index) => {
88
91
  const scaleVal = config.useLogScale ? 0.1 : 0
89
92
  const suppresedBarHeight = 20
@@ -96,14 +99,10 @@ export const BarChartVertical = () => {
96
99
  const supprssedBarY = bar.value >= 0 && isNumber(bar.value) ? yScale(scaleVal) - suppresedBarHeight : yScale(0)
97
100
  const barY = config.suppressedData.some(d => bar.key === d.column && String(bar.value) === String(d.value)) ? supprssedBarY : barYBase
98
101
 
99
- let barGroupWidth = (xMax / barGroups.length) * (config.barThickness || 0.8)
100
- let offset = ((xMax / barGroups.length) * (1 - (config.barThickness || 0.8))) / 2
101
- // configure left side offset of lollipop bars
102
- if (config.isLollipopChart) {
103
- offset = xMax / barGroups.length / 2 - lollipopBarWidth / 2
104
- }
102
+ let barGroupWidth = seriesScale.range()[1]
105
103
 
106
104
  let barWidth = config.isLollipopChart ? lollipopBarWidth : barGroupWidth / barGroup.bars.length
105
+ let barX = bar.x + (config.isLollipopChart ? (((barGroupWidth / barGroup.bars.length) - lollipopBarWidth) / 2) : 0) - (config.xAxis.type === 'date' && config.xAxis.sortDates ? barGroupWidth / 2 : 0)
107
106
  setBarWidth(barWidth)
108
107
  setTotalBarsInGroup(barGroup.bars.length)
109
108
 
@@ -227,7 +226,7 @@ export const BarChartVertical = () => {
227
226
  style={{ overflow: 'visible', transition: 'all 0.2s linear' }}
228
227
  id={`barGroup${barGroup.index}`}
229
228
  key={`bar-group-bar-${barGroup.index}-${bar.index}-${bar.value}-${bar.key}`}
230
- x={barWidth * bar.index + offset}
229
+ x={barX}
231
230
  y={barY}
232
231
  width={barWidth}
233
232
  height={barHeight}
@@ -252,7 +251,7 @@ export const BarChartVertical = () => {
252
251
  <Text // prettier-ignore
253
252
  display={config.labels && displayBar ? 'block' : 'none'}
254
253
  opacity={transparentBar ? 0.5 : 1}
255
- x={barWidth * (bar.index + 0.5) + offset}
254
+ x={barX + barWidth / 2}
256
255
  y={barY - 5}
257
256
  fill={labelColor}
258
257
  textAnchor='middle'
@@ -263,7 +262,7 @@ export const BarChartVertical = () => {
263
262
  {config.isLollipopChart && config.lollipopShape === 'circle' && (
264
263
  <circle
265
264
  display={displaylollipopShape}
266
- cx={barWidth * (barGroup.bars.length - bar.index - 1) + offset + lollipopShapeSize / 3.5}
265
+ cx={barX + lollipopShapeSize / 3.5}
267
266
  cy={bar.y}
268
267
  r={lollipopShapeSize / 2}
269
268
  fill={barColor}
@@ -276,7 +275,7 @@ export const BarChartVertical = () => {
276
275
  {config.isLollipopChart && config.lollipopShape === 'square' && (
277
276
  <rect
278
277
  display={displaylollipopShape}
279
- x={offset - lollipopBarWidth / 2}
278
+ x={barX - lollipopBarWidth / 2}
280
279
  y={barY}
281
280
  width={lollipopShapeSize}
282
281
  height={lollipopShapeSize}
@@ -304,7 +303,7 @@ export const BarChartVertical = () => {
304
303
  let upperPos
305
304
  let lowerPos
306
305
  let tickWidth = 5
307
- xPos = xScale(getXAxisData(d))
306
+ xPos = xScale(getXAxisData(d)) + (config.xAxis.type !== 'date' || !config.xAxis.sortDates ? seriesScale.range()[1] / 2 : 0)
308
307
  upperPos = yScale(getYAxisData(d, config.confidenceKeys.lower))
309
308
  lowerPos = yScale(getYAxisData(d, config.confidenceKeys.upper))
310
309
  return (
@@ -7,6 +7,7 @@ import { colorPalettesChart } from '@cdc/core/data/colorPalettes'
7
7
 
8
8
  const CoveBoxPlot = ({ xScale, yScale }) => {
9
9
  const { config, setConfig } = useContext(ConfigContext)
10
+ const { boxplot } = config
10
11
 
11
12
  useEffect(() => {
12
13
  if (config.legend.hide === false) {
@@ -25,10 +26,10 @@ const CoveBoxPlot = ({ xScale, yScale }) => {
25
26
  const handleTooltip = d => {
26
27
  return `
27
28
  <strong>${d.columnCategory}</strong></br>
28
- ${config.boxplot.labels.q1}: ${d.columnFirstQuartile}<br/>
29
- ${config.boxplot.labels.q3}: ${d.columnThirdQuartile}<br/>
30
- ${config.boxplot.labels.iqr}: ${d.columnIqr}<br/>
31
- ${config.boxplot.labels.median}: ${d.columnMedian}
29
+ ${boxplot.labels.q1}: ${d.columnFirstQuartile}<br/>
30
+ ${boxplot.labels.q3}: ${d.columnThirdQuartile}<br/>
31
+ ${boxplot.labels.iqr}: ${d.columnIqr}<br/>
32
+ ${boxplot.labels.median}: ${d.columnMedian}
32
33
  `
33
34
  }
34
35
 
@@ -46,12 +47,12 @@ const CoveBoxPlot = ({ xScale, yScale }) => {
46
47
  return (
47
48
  <ErrorBoundary component='BoxPlot'>
48
49
  <Group className='boxplot' key={`boxplot-group`}>
49
- {config.boxplot.plots.map((d, i) => {
50
+ {boxplot.plots.map((d, i) => {
50
51
  const offset = boxWidth - constrainedWidth
51
52
  const radius = 4
52
53
  return (
53
54
  <Group key={`boxplotplot-${i}`}>
54
- {config.boxplot.plotNonOutlierValues &&
55
+ {boxplot.plotNonOutlierValues &&
55
56
  d.nonOutlierValues.map((value, index) => {
56
57
  return <circle cx={xScale(d.columnCategory) + Number(config.yAxis.size) + boxWidth / 2} cy={yScale(value)} r={radius} fill={'#ccc'} style={{ opacity: 1, fillOpacity: 1, stroke: 'black' }} key={`boxplot-${i}--circle-${index}`} />
57
58
  })}
@@ -69,7 +70,7 @@ const CoveBoxPlot = ({ xScale, yScale }) => {
69
70
  fillOpacity={fillOpacity}
70
71
  stroke='black'
71
72
  valueScale={yScale}
72
- outliers={config.boxplot.plotOutlierValues ? d.columnOutliers : []}
73
+ outliers={boxplot.plotOutlierValues ? d.columnOutliers : []}
73
74
  outlierProps={{
74
75
  style: {
75
76
  fill: `${color_0}`,
@@ -84,7 +85,7 @@ const CoveBoxPlot = ({ xScale, yScale }) => {
84
85
  boxProps={{
85
86
  style: {
86
87
  stroke: 'black',
87
- strokeWidth: config.boxplot.borders === 'true' ? 1 : 0
88
+ strokeWidth: boxplot.borders === 'true' ? 1 : 0
88
89
  }
89
90
  }}
90
91
  maxProps={{