@cdc/chart 4.25.3 → 4.25.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.
Files changed (86) hide show
  1. package/dist/cdcchart.js +46641 -42561
  2. package/index.html +130 -129
  3. package/package.json +22 -27
  4. package/src/CdcChartComponent.tsx +75 -35
  5. package/src/_stories/Chart.CI.stories.tsx +10 -0
  6. package/src/_stories/Chart.DynamicSeries.stories.tsx +68 -49
  7. package/src/_stories/Chart.stories.tsx +99 -86
  8. package/src/_stories/ChartPrefixSuffix.stories.tsx +29 -32
  9. package/{examples/private/line-issue.json → src/_stories/_mock/barchart_labels.mock.json} +150 -35
  10. package/src/_stories/_mock/dynamic_series_bar_config.json +1 -1
  11. package/src/_stories/_mock/dynamic_series_suppression_mock.json +610 -0
  12. package/{examples/private/not-loading.json → src/_stories/_mock/pie_calculated_area.json} +152 -95
  13. package/src/components/Annotations/components/AnnotationDropdown.tsx +2 -2
  14. package/src/components/AreaChart/components/AreaChart.jsx +33 -5
  15. package/src/components/Axis/Categorical.Axis.tsx +2 -2
  16. package/src/components/BarChart/components/BarChart.Horizontal.tsx +38 -37
  17. package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +18 -8
  18. package/src/components/BarChart/components/BarChart.StackedVertical.tsx +8 -8
  19. package/src/components/BarChart/components/BarChart.Vertical.tsx +47 -36
  20. package/src/components/BarChart/components/{BarChart.jsx → BarChart.tsx} +23 -5
  21. package/src/components/BarChart/components/context.tsx +20 -2
  22. package/src/components/BarChart/helpers/getBarHeights.ts +47 -0
  23. package/src/components/BarChart/helpers/index.ts +5 -2
  24. package/src/components/BarChart/helpers/tests/getBarHeights.test.ts +83 -0
  25. package/src/{hooks → components/BarChart/helpers}/useBarChart.ts +9 -46
  26. package/src/components/BoxPlot/BoxPlot.tsx +2 -1
  27. package/src/components/Brush/BrushChart.tsx +73 -0
  28. package/src/components/Brush/BrushController..tsx +39 -0
  29. package/src/components/DeviationBar.jsx +2 -2
  30. package/src/components/EditorPanel/EditorPanel.tsx +232 -147
  31. package/src/components/EditorPanel/components/Panels/Panel.General.tsx +36 -36
  32. package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +52 -25
  33. package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +12 -4
  34. package/src/components/EditorPanel/components/Panels/panelVisual.styles.css +8 -0
  35. package/src/components/EditorPanel/useEditorPermissions.ts +5 -5
  36. package/src/components/ForestPlot/ForestPlot.tsx +2 -2
  37. package/src/components/HoverLine/HoverLine.tsx +74 -0
  38. package/src/components/Legend/Legend.Component.tsx +1 -1
  39. package/src/components/Legend/Legend.Suppression.tsx +59 -25
  40. package/src/components/Legend/helpers/createFormatLabels.tsx +28 -0
  41. package/src/components/Legend/helpers/index.ts +1 -1
  42. package/src/components/LineChart/LineChartProps.ts +3 -1
  43. package/src/components/LineChart/components/LineChart.Circle.tsx +72 -119
  44. package/src/components/LineChart/helpers.ts +133 -56
  45. package/src/components/LineChart/index.tsx +106 -55
  46. package/src/components/LinearChart.tsx +178 -198
  47. package/src/components/PairedBarChart.jsx +3 -2
  48. package/src/components/PieChart/PieChart.tsx +127 -102
  49. package/src/components/ScatterPlot/ScatterPlot.jsx +5 -0
  50. package/src/components/Sparkline/components/SparkLine.tsx +80 -18
  51. package/src/data/initial-state.js +11 -6
  52. package/src/helpers/countNumOfTicks.ts +1 -1
  53. package/src/helpers/dataHelpers.ts +23 -2
  54. package/src/helpers/getNewRuntime.ts +35 -0
  55. package/src/helpers/getPiePercent.ts +22 -0
  56. package/src/helpers/getTransformedData.ts +22 -0
  57. package/src/helpers/sizeHelpers.ts +1 -1
  58. package/src/helpers/tests/getNewRuntime.test.ts +82 -0
  59. package/src/helpers/tests/getPiePercent.test.ts +38 -0
  60. package/src/hooks/useMinMax.ts +21 -28
  61. package/src/hooks/useRightAxis.ts +5 -3
  62. package/src/hooks/useScales.ts +15 -6
  63. package/src/hooks/useTooltip.tsx +218 -203
  64. package/src/index.jsx +2 -2
  65. package/src/scss/main.scss +13 -6
  66. package/src/store/chart.actions.ts +2 -6
  67. package/src/store/chart.reducer.ts +23 -23
  68. package/src/types/ChartConfig.ts +11 -3
  69. package/src/types/ChartContext.ts +0 -2
  70. package/examples/private/DEV-8850-2.json +0 -493
  71. package/examples/private/DEV-9822.json +0 -574
  72. package/examples/private/DEV-9840.json +0 -553
  73. package/examples/private/DEV-9850-3.json +0 -461
  74. package/examples/private/chart.json +0 -1084
  75. package/examples/private/ci_formatted.json +0 -202
  76. package/examples/private/ci_issue.json +0 -3016
  77. package/examples/private/completed.json +0 -634
  78. package/examples/private/dem-data-long.csv +0 -20
  79. package/examples/private/dem-data-long.json +0 -36
  80. package/examples/private/demographic_data.csv +0 -157
  81. package/examples/private/demographic_data.json +0 -2654
  82. package/examples/private/demographic_dynamic.json +0 -443
  83. package/examples/private/demographic_standard.json +0 -560
  84. package/examples/private/ehdi.json +0 -29939
  85. package/examples/private/test.json +0 -493
  86. package/src/components/ZoomBrush.tsx +0 -251
@@ -28,7 +28,6 @@ const LineChart = (props: LineChartProps) => {
28
28
  const {
29
29
  getXAxisData,
30
30
  getYAxisData,
31
- handleTooltipClick,
32
31
  handleTooltipMouseOff,
33
32
  handleTooltipMouseOver,
34
33
  tooltipData,
@@ -36,53 +35,50 @@ const LineChart = (props: LineChartProps) => {
36
35
  xScale,
37
36
  yMax,
38
37
  yScale,
39
- } = props
38
+ } = props
40
39
 
41
40
  // prettier-ignore
42
- const { colorScale, config, formatNumber, handleLineType, parseDate, seriesHighlight, tableData, transformedData, updateConfig, brushConfig,clean } = useContext<ChartContext>(ConfigContext)
43
- const { yScaleRight } = useRightAxis({ config, yMax, data: transformedData, updateConfig })
41
+ const { colorScale, config, formatNumber, handleLineType, parseDate, seriesHighlight, tableData, transformedData:data, updateConfig, } = useContext<ChartContext>(ConfigContext)
42
+ const { yScaleRight } = useRightAxis({ config, yMax, data, updateConfig })
43
+ const showSingleSeries = config.tooltips.singleSeries
44
44
  if (!handleTooltipMouseOver) return
45
45
 
46
46
  const DEBUG = false
47
47
  const { lineDatapointStyle, showLineSeriesLabels, legend } = config
48
- let data = transformedData
49
- let tableD = tableData
50
- // if brush on use brush data and clean
51
- if (brushConfig.data.length > 0 && config.brush?.active) {
52
- data = clean(brushConfig.data)
53
- tableD = clean(brushConfig.data)
54
- }
55
48
 
56
49
  const xPos = d => {
57
50
  return xScale(getXAxisData(d)) + (xScale.bandwidth ? xScale.bandwidth() / 2 : 0)
58
51
  }
59
52
 
53
+ const tooltipPoints = []
54
+
60
55
  return (
61
56
  <ErrorBoundary component='LineChart'>
62
- <Group left={Number(config.runtime.yAxis.size)}>
63
- {' '}
57
+ <Group left={Number(config.runtime.yAxis.size)} className='line-chart-group'>
64
58
  {/* left - expects a number not a string */}
65
59
  {(config.runtime.lineSeriesKeys || config.runtime.seriesKeys).map((seriesKey, index) => {
66
60
  const seriesData = config.runtime.series.find(item => item.dataKey === seriesKey)
61
+ const _seriesKey = seriesData.dynamicCategory ? seriesData.originalDataKey : seriesKey
67
62
  const lineType = seriesData.type
68
63
  const seriesAxis = seriesData.axis || 'left'
69
64
  const displayArea =
70
65
  legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(seriesKey) !== -1
71
66
 
72
- const suppressedSegments = createDataSegments(
73
- tableData,
67
+ const suppressedSegments = createDataSegments({
68
+ data: tableData,
74
69
  seriesKey,
75
- config.preliminaryData,
76
- config.xAxis.dataKey
77
- )
70
+ preliminaryData: config.preliminaryData,
71
+ dynamicCategory: seriesData.dynamicCategory,
72
+ originalSeriesKey: _seriesKey,
73
+ colorScale
74
+ })
78
75
  const isSplitLine =
79
76
  config?.preliminaryData?.filter(pd => pd.style && !pd.style.includes('Circles')).length > 0
80
77
 
81
78
  const _data = seriesData.dynamicCategory
82
79
  ? data.filter(d => d[seriesData.dynamicCategory] === seriesKey)
83
80
  : data
84
- const _seriesKey = seriesData.dynamicCategory ? seriesData.originalDataKey : seriesKey
85
- const circleData = filterCircles(config?.preliminaryData, tableD, _seriesKey)
81
+ const circleData = filterCircles(config?.preliminaryData, tableData, _seriesKey)
86
82
  return (
87
83
  <Group
88
84
  key={`series-${seriesKey}-${index}`}
@@ -108,11 +104,15 @@ const LineChart = (props: LineChartProps) => {
108
104
  height={Number(yMax)}
109
105
  fill={DEBUG ? 'red' : 'transparent'}
110
106
  fillOpacity={0.05}
111
- onMouseMove={e => handleTooltipMouseOver(e, tableData)}
112
- onMouseOut={handleTooltipMouseOff}
113
- onClick={e => handleTooltipClick(e, data)}
114
107
  />
115
108
  {_data.map((d, dataIndex) => {
109
+ tooltipPoints.push({
110
+ color: colorScale(config.runtime.seriesLabels[seriesKey]),
111
+ seriesKey: _seriesKey,
112
+ seriesIndex: index,
113
+ xValue: d[config.xAxis.dataKey],
114
+ yValue: d[_seriesKey]
115
+ })
116
116
  return (
117
117
  isNumber(d[_seriesKey]) && (
118
118
  <React.Fragment key={`series-${seriesKey}-point-${dataIndex}`}>
@@ -136,7 +136,6 @@ const LineChart = (props: LineChartProps) => {
136
136
  <LineChartCircle
137
137
  mode='ALWAYS_SHOW_POINTS'
138
138
  dataIndex={dataIndex}
139
- circleData={circleData}
140
139
  tableData={tableData}
141
140
  data={_data}
142
141
  d={d}
@@ -155,18 +154,37 @@ const LineChart = (props: LineChartProps) => {
155
154
  />
156
155
  )}
157
156
 
157
+ {(lineDatapointStyle === 'hover' || lineDatapointStyle === 'hidden') && (
158
+ <LineChartCircle
159
+ mode='HOVER_POINTS'
160
+ dataIndex={dataIndex}
161
+ tableData={tableData}
162
+ data={_data}
163
+ d={d}
164
+ config={config}
165
+ seriesKey={_seriesKey}
166
+ displayArea={displayArea}
167
+ xScale={xScale}
168
+ yScale={yScale}
169
+ colorScale={colorScale}
170
+ parseDate={parseDate}
171
+ yScaleRight={yScaleRight}
172
+ seriesAxis={seriesAxis}
173
+ seriesIndex={index}
174
+ key={`line-hover-circle--${dataIndex}`}
175
+ />
176
+ )}
177
+
158
178
  <LineChartCircle
159
179
  mode='ISOLATED_POINTS'
160
180
  seriesIndex={index}
161
181
  dataIndex={dataIndex}
162
182
  tableData={tableData}
163
- circleData={circleData}
164
183
  data={_data}
165
184
  d={d}
166
185
  config={config}
167
186
  seriesKey={_seriesKey}
168
187
  displayArea={displayArea}
169
- tooltipData={tooltipData}
170
188
  xScale={xScale}
171
189
  yScale={yScale}
172
190
  colorScale={colorScale}
@@ -179,28 +197,6 @@ const LineChart = (props: LineChartProps) => {
179
197
  )
180
198
  )
181
199
  })}
182
- <>
183
- {lineDatapointStyle === 'hover' && (
184
- <LineChartCircle
185
- seriesIndex={index}
186
- tableData={tableData}
187
- dataIndex={0}
188
- mode='HOVER_POINTS'
189
- circleData={circleData}
190
- data={_data}
191
- config={config}
192
- seriesKey={seriesKey}
193
- displayArea={displayArea}
194
- tooltipData={tooltipData}
195
- xScale={xScale}
196
- yScale={yScale}
197
- colorScale={colorScale}
198
- parseDate={parseDate}
199
- yScaleRight={yScaleRight}
200
- seriesAxis={seriesAxis}
201
- />
202
- )}
203
- </>
204
200
 
205
201
  {/* SPLIT LINE */}
206
202
  {isSplitLine ? (
@@ -217,15 +213,17 @@ const LineChart = (props: LineChartProps) => {
217
213
  }
218
214
  styles={createStyles({
219
215
  preliminaryData: config.preliminaryData,
220
- data: tableD,
216
+ data: tableData,
221
217
  stroke: colorScale(config.runtime.seriesLabels[seriesKey]),
222
218
  strokeWidth: seriesData.weight || 2,
223
219
  handleLineType,
224
220
  lineType,
225
- seriesKey
221
+ seriesKey,
222
+ dynamicCategory: seriesData.dynamicCategory,
223
+ originalSeriesKey: _seriesKey
226
224
  })}
227
225
  defined={(item, i) => {
228
- return item[seriesKey] !== '' && item[seriesKey] !== null && item[seriesKey] !== undefined
226
+ return item[_seriesKey] !== '' && item[_seriesKey] !== null && item[_seriesKey] !== undefined
229
227
  }}
230
228
  />
231
229
 
@@ -238,16 +236,22 @@ const LineChart = (props: LineChartProps) => {
238
236
  x={d => xPos(d)}
239
237
  y={d =>
240
238
  seriesAxis === 'Right'
241
- ? yScaleRight(getYAxisData(d, seriesKey))
242
- : yScale(Number(getYAxisData(d, seriesKey)))
239
+ ? yScaleRight(getYAxisData(d, _seriesKey))
240
+ : yScale(Number(getYAxisData(d, _seriesKey)))
241
+ }
242
+ stroke={
243
+ seriesData.dynamicCategory
244
+ ? segment.color
245
+ : colorScale(config.runtime.seriesLabels[seriesKey])
243
246
  }
244
- stroke={colorScale(config.runtime.seriesLabels[seriesKey])}
245
247
  strokeWidth={seriesData[0]?.weight || 2}
246
248
  strokeOpacity={1}
247
249
  shapeRendering='geometricPrecision'
248
250
  strokeDasharray={handleLineType(segment.style)}
249
251
  defined={(item, i) => {
250
- return item[seriesKey] !== '' && item[seriesKey] !== null && item[seriesKey] !== undefined
252
+ return (
253
+ item[_seriesKey] !== '' && item[_seriesKey] !== null && item[_seriesKey] !== undefined
254
+ )
251
255
  }}
252
256
  />
253
257
  )
@@ -269,6 +273,7 @@ const LineChart = (props: LineChartProps) => {
269
273
  return (
270
274
  <AreaClosed
271
275
  key={`area-closed-${seriesKey}-${categoryIndex}`}
276
+ className='confidence-interval'
272
277
  data={categoryData}
273
278
  x={d => xPos(d)}
274
279
  y0={d => yScale(d[config.confidenceKeys.lower])} // Lower bound of the confidence interval
@@ -432,6 +437,52 @@ const LineChart = (props: LineChartProps) => {
432
437
  </Text>
433
438
  )}
434
439
  </Group>
440
+ <Group left={Number(config.runtime.yAxis.size)} className='glyph-tooltip-group'>
441
+ <Group key={`tooltip-group`} display={'block'}>
442
+ {/* tooltips */}
443
+ <Bar
444
+ key={'tooltip bars'}
445
+ width={Number(xMax)}
446
+ height={Number(yMax)}
447
+ fill={DEBUG ? 'red' : 'transparent'}
448
+ fillOpacity={0.05}
449
+ onMouseMove={e => {
450
+ if (showSingleSeries) return
451
+ handleTooltipMouseOver(e, tableData)
452
+ }}
453
+ onMouseOut={handleTooltipMouseOff}
454
+ />
455
+ {tooltipPoints.map((d, dataIndex) => {
456
+ const { _data, seriesKey, seriesIndex, color } = d
457
+ return (
458
+ <React.Fragment key={`series-${seriesKey}-point-${dataIndex}`}>
459
+ <LineChartCircle
460
+ mode='TOOLTIP_POINTS'
461
+ dataIndex={dataIndex}
462
+ tooltipPoint={d}
463
+ tableData={tableData}
464
+ data={_data}
465
+ d={d}
466
+ config={config}
467
+ seriesKey={seriesKey}
468
+ displayArea={true}
469
+ tooltipData={tooltipData}
470
+ xScale={xScale}
471
+ yScale={yScale}
472
+ colorScale={colorScale}
473
+ parseDate={parseDate}
474
+ yScaleRight={yScaleRight}
475
+ seriesAxis={'[circle]'}
476
+ seriesIndex={seriesIndex}
477
+ key={`line-circle--${dataIndex}`}
478
+ handleTooltipMouseOver={handleTooltipMouseOver}
479
+ handleTooltipMouseOff={handleTooltipMouseOff}
480
+ />
481
+ </React.Fragment>
482
+ )
483
+ })}
484
+ </Group>
485
+ </Group>
435
486
  {config.visualizationType === 'Bump Chart' && (
436
487
  <LineChartBumpCircle config={config} xScale={xScale} yScale={yScale} />
437
488
  )}