@cdc/chart 4.23.11 → 4.24.1

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 (103) hide show
  1. package/dist/cdcchart.js +30220 -29764
  2. package/examples/feature/bar/additional-column-tooltip.json +446 -0
  3. package/examples/feature/bar/tall-data.json +98 -0
  4. package/examples/feature/forest-plot/forest-plot.json +63 -19
  5. package/examples/feature/forest-plot/linear.json +52 -3
  6. package/examples/feature/forest-plot/log.json +26 -0
  7. package/examples/feature/forest-plot/logarithmic.json +0 -35
  8. package/examples/feature/line/line-chart-preliminary.json +346 -0
  9. package/examples/feature/scatterplot/scatterplot.json +272 -33
  10. package/examples/private/chart-t.json +3740 -0
  11. package/examples/private/combo.json +369 -0
  12. package/examples/private/epi-data.csv +13 -0
  13. package/examples/private/epi-data.json +62 -0
  14. package/examples/private/epi.json +403 -0
  15. package/examples/private/occupancy.json +109283 -0
  16. package/examples/private/prod-line-config.json +401 -0
  17. package/examples/private/region-data.json +822 -0
  18. package/examples/private/region-testing.json +312 -0
  19. package/examples/private/scaling.json +45325 -0
  20. package/examples/private/testing-data.json +1739 -0
  21. package/examples/private/testing.json +816 -0
  22. package/index.html +7 -7
  23. package/package.json +2 -2
  24. package/src/CdcChart.tsx +29 -210
  25. package/src/ConfigContext.tsx +6 -0
  26. package/src/_stories/ChartEditor.stories.tsx +22 -0
  27. package/src/_stories/ChartLine.preliminary.tsx +19 -0
  28. package/src/_stories/_mock/pie_config.json +191 -0
  29. package/src/_stories/_mock/pie_data.json +218 -0
  30. package/src/_stories/_mock/preliminary_mock.json +346 -0
  31. package/src/components/{AreaChart.Stacked.jsx → AreaChart/components/AreaChart.Stacked.jsx} +2 -2
  32. package/src/components/{AreaChart.jsx → AreaChart/components/AreaChart.jsx} +1 -1
  33. package/src/components/AreaChart/index.tsx +4 -0
  34. package/src/components/{BarChart.Horizontal.tsx → BarChart/components/BarChart.Horizontal.tsx} +8 -8
  35. package/src/components/{BarChart.StackedHorizontal.tsx → BarChart/components/BarChart.StackedHorizontal.tsx} +37 -7
  36. package/src/components/BarChart/components/BarChart.StackedVertical.tsx +106 -0
  37. package/src/components/{BarChart.Vertical.tsx → BarChart/components/BarChart.Vertical.tsx} +41 -57
  38. package/src/components/BarChart/components/BarChart.jsx +39 -0
  39. package/src/components/{BarChartType.jsx → BarChart/components/BarChartType.jsx} +0 -2
  40. package/src/components/BarChart/components/context.tsx +13 -0
  41. package/src/components/BarChart/index.tsx +3 -0
  42. package/src/components/{BoxPlot.jsx → BoxPlot/BoxPlot.jsx} +1 -1
  43. package/src/components/BoxPlot/index.tsx +3 -0
  44. package/src/components/{EditorPanel.jsx → EditorPanel/EditorPanel.tsx} +667 -851
  45. package/src/components/EditorPanel/components/Panel.DateHighlighting.tsx +109 -0
  46. package/src/components/{ForestPlotSettings.jsx → EditorPanel/components/Panel.ForestPlotSettings.tsx} +87 -166
  47. package/src/components/EditorPanel/components/Panel.Regions.tsx +168 -0
  48. package/src/components/{Series.jsx → EditorPanel/components/Panel.Series.tsx} +1 -1
  49. package/src/components/EditorPanel/components/PanelProps.ts +3 -0
  50. package/src/components/EditorPanel/components/Panels.tsx +13 -0
  51. package/src/components/EditorPanel/components/panels.scss +72 -0
  52. package/src/components/EditorPanel/editor-panel.scss +751 -0
  53. package/src/components/EditorPanel/index.tsx +3 -0
  54. package/src/{hooks → components/EditorPanel}/useEditorPermissions.js +29 -2
  55. package/src/components/{Forecasting.jsx → Forecasting/Forecasting.jsx} +1 -1
  56. package/src/components/Forecasting/index.tsx +3 -0
  57. package/src/components/ForestPlot/ForestPlot.tsx +254 -0
  58. package/src/components/ForestPlot/ForestPlotProps.ts +7 -0
  59. package/src/components/ForestPlot/index.tsx +1 -209
  60. package/src/components/{Legend.jsx → Legend/Legend.tsx} +150 -113
  61. package/src/components/Legend/index.tsx +3 -0
  62. package/src/components/LineChart/LineChartProps.ts +29 -0
  63. package/src/components/LineChart/{LineChart.Circle.tsx → components/LineChart.Circle.tsx} +12 -3
  64. package/src/components/LineChart/helpers.ts +45 -0
  65. package/src/components/LineChart/index.tsx +20 -8
  66. package/src/components/LinearChart.jsx +52 -69
  67. package/src/components/{PieChart.jsx → PieChart/PieChart.tsx} +16 -7
  68. package/src/components/PieChart/index.tsx +3 -0
  69. package/src/components/Regions/components/Regions.tsx +135 -0
  70. package/src/components/Regions/index.tsx +3 -0
  71. package/src/components/{ScatterPlot.jsx → ScatterPlot/ScatterPlot.jsx} +3 -3
  72. package/src/components/ScatterPlot/index.tsx +3 -0
  73. package/src/components/{SparkLine.jsx → Sparkline/SparkLine.jsx} +2 -2
  74. package/src/components/Sparkline/index.tsx +3 -0
  75. package/src/data/initial-state.js +5 -6
  76. package/src/helpers/abbreviateNumber.ts +17 -0
  77. package/src/helpers/computeMarginBottom.ts +55 -0
  78. package/src/helpers/filterData.ts +18 -0
  79. package/src/helpers/generateColorsArray.ts +8 -0
  80. package/src/helpers/getQuartiles.ts +30 -0
  81. package/src/helpers/handleChartAriaLabels.ts +19 -0
  82. package/src/helpers/handleLineType.ts +18 -0
  83. package/src/helpers/lineOptions.ts +18 -0
  84. package/src/helpers/sort.ts +7 -0
  85. package/src/helpers/tests/computeMarginBottom.test.ts +20 -0
  86. package/src/hooks/useBarChart.js +7 -6
  87. package/src/hooks/useScales.ts +1 -1
  88. package/src/hooks/{useTooltip.jsx → useTooltip.tsx} +23 -21
  89. package/src/scss/main.scss +67 -3
  90. package/src/types/ChartConfig.ts +158 -23
  91. package/src/types/ChartContext.ts +26 -10
  92. package/src/types/ForestPlot.ts +7 -14
  93. package/examples/feature/scatterplot/scatterplot-continuous.csv +0 -17
  94. package/src/ConfigContext.jsx +0 -5
  95. package/src/components/BarChart.StackedVertical.tsx +0 -91
  96. package/src/components/BarChart.jsx +0 -30
  97. package/src/components/ForestPlot/Readme.md +0 -0
  98. package/src/scss/LinearChart.scss +0 -0
  99. package/src/scss/editor-panel.scss +0 -745
  100. package/src/scss/legend.scss +0 -206
  101. package/src/scss/mixins.scss +0 -0
  102. package/src/scss/variables.scss +0 -1
  103. package/src/types/ChartProps.ts +0 -7
@@ -2,8 +2,10 @@ import { type Color } from '@cdc/core/types/Color'
2
2
 
3
3
  export type ForestPlotConfigSettings = {
4
4
  colors: {
5
- line: Color // color of line of effect
6
- shape: Color // color for effect estimate shape
5
+ // color of line of no effect
6
+ line: Color
7
+ // color for effect estimate shape
8
+ shape: Color
7
9
  }
8
10
  // description - appears below the study column.
9
11
  description: {
@@ -11,8 +13,9 @@ export type ForestPlotConfigSettings = {
11
13
  text: string
12
14
  location: number
13
15
  }
14
- // effect estimates
15
- estimateField: string // column chose for the effect estimate
16
+ // column chose for the effect estimate
17
+ estimateField: string
18
+ // column chose for the esimate radius
16
19
  estimateRadius: string
17
20
  hideDateCategoryCol: boolean
18
21
  leftWidthOffset: number
@@ -33,15 +36,8 @@ export type ForestPlotConfigSettings = {
33
36
  radius: {
34
37
  min: number
35
38
  max: number
36
- /** @deprecated - moved to estimateField due to duplication */
37
39
  scalingColumn: string
38
40
  }
39
- /** @deprecated - moved to pooledResult */
40
- regression: {
41
- lower: number
42
- upper: number
43
- estimateField: number
44
- }
45
41
  result: {
46
42
  show: boolean
47
43
  text: string
@@ -51,9 +47,6 @@ export type ForestPlotConfigSettings = {
51
47
  shape: string
52
48
  startAt: number
53
49
  title: string // centered title above the chart
54
-
55
- /** @deprecated - moved to lineOfNoEffect*/
56
- showZeroLine: boolean
57
50
  // labels under chart
58
51
  leftLabel: string
59
52
  rightLabel: string
@@ -1,17 +0,0 @@
1
- x,y1,y2,y3,y4
2
- 1000,8,37,72,82
3
- 2000,2,30,75,83
4
- 3000,15,42,51,95
5
- 4,10,38,61,96
6
- 5,1,38,66,86
7
- 60,6,37,70,85
8
- 10,19,47,59,91
9
- 24,18,32,68,89
10
- 3,7,38,74,89
11
- 26,10,39,56,91
12
- 42,16,38,55,76
13
- 32,20,46,52,94
14
- 11,9,41,57,86
15
- 22,10,47,56,80
16
- 73,1,36,71,94
17
- 23,13,30,66,78
@@ -1,5 +0,0 @@
1
- import { createContext } from 'react'
2
-
3
- const ConfigContext = createContext({})
4
-
5
- export default ConfigContext
@@ -1,91 +0,0 @@
1
- import React, { useContext } from 'react'
2
- import ConfigContext from '../ConfigContext'
3
- import { useBarChart } from '../hooks/useBarChart'
4
- import { BarStack } from '@visx/shape'
5
- import { Group } from '@visx/group'
6
- import { Text } from '@visx/text'
7
- import { type BarChartProps } from '../types/ChartProps'
8
-
9
- const BarChartStackedVertical = (props: BarChartProps) => {
10
- const { xScale, yScale, xMax, yMax } = props
11
- const { transformedData, colorScale, seriesHighlight, config, formatNumber, formatDate, parseDate, setSharedFilter } = useContext(ConfigContext)
12
- const { isHorizontal, barBorderWidth, applyRadius, hoveredBar, getAdditionalColumn, onMouseLeaveBar, onMouseOverBar } = useBarChart()
13
- const { orientation } = config
14
- const data = config.brush.active && config.brush.data?.length ? config.brush.data : transformedData
15
-
16
- return (
17
- config.visualizationSubType === 'stacked' &&
18
- !isHorizontal && (
19
- <BarStack data={data} keys={config.runtime.barSeriesKeys || config.runtime.seriesKeys} x={d => d[config.runtime.xAxis.dataKey]} xScale={xScale} yScale={yScale} color={colorScale}>
20
- {barStacks =>
21
- barStacks.reverse().map(barStack =>
22
- barStack.bars.map(bar => {
23
- let transparentBar = config.legend.behavior === 'highlight' && seriesHighlight.length > 0 && seriesHighlight.indexOf(bar.key) === -1
24
- let displayBar = config.legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(bar.key) !== -1
25
- let barThickness = xMax / barStack.bars.length
26
- let barThicknessAdjusted = barThickness * (config.barThickness || 0.8)
27
- let offset = (barThickness * (1 - (config.barThickness || 0.8))) / 2
28
- // tooltips
29
- const xAxisValue = config.runtime.xAxis.type === 'date' ? formatDate(parseDate(data[bar.index][config.runtime.xAxis.dataKey])) : data[bar.index][config.runtime.xAxis.dataKey]
30
- const yAxisValue = formatNumber(bar.bar ? bar.bar.data[bar.key] : 0, 'left')
31
- if (!yAxisValue) return
32
- const style = applyRadius(barStack.index)
33
- const xAxisTooltip = config.runtime.xAxis.label ? `${config.runtime.xAxis.label}: ${xAxisValue}` : xAxisValue
34
- const additionalColTooltip = getAdditionalColumn(hoveredBar)
35
- const tooltipBody = `${config.runtime.seriesLabels[bar.key]}: ${yAxisValue}`
36
- const tooltip = `<ul>
37
- <li class="tooltip-heading"">${xAxisTooltip}</li>
38
- <li class="tooltip-body ">${tooltipBody}</li>
39
- <li class="tooltip-body ">${additionalColTooltip}</li>
40
- </li></ul>`
41
-
42
- return (
43
- <Group key={`${barStack.index}--${bar.index}--${orientation}`}>
44
- <style>
45
- {`
46
- #barStack${barStack.index}-${bar.index} rect,
47
- #barStack${barStack.index}-${bar.index} foreignObject div{
48
- animation-delay: ${barStack.index * 0.5}s;
49
- transform-origin: ${barThicknessAdjusted / 2}px ${bar.y + bar.height}px
50
- }
51
- `}
52
- </style>
53
- <Group key={`bar-stack-${barStack.index}-${bar.index}`} id={`barStack${barStack.index}-${bar.index}`} className='stack vertical'>
54
- <Text display={config.labels && displayBar ? 'block' : 'none'} opacity={transparentBar ? 0.5 : 1} x={barThickness * bar.index + offset} y={bar.y - 5} fill={'#000'} textAnchor='middle'>
55
- {yAxisValue}
56
- </Text>
57
- <foreignObject
58
- onMouseOver={() => onMouseOverBar(xAxisValue, bar.key)}
59
- onMouseLeave={onMouseLeaveBar}
60
- key={`bar-stack-${barStack.index}-${bar.index}`}
61
- x={barThickness * bar.index + offset}
62
- y={bar.y}
63
- width={barThicknessAdjusted}
64
- height={bar.height}
65
- display={displayBar ? 'block' : 'none'}
66
- data-tooltip-html={tooltip}
67
- data-tooltip-id={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
68
- onClick={e => {
69
- e.preventDefault()
70
- if (setSharedFilter) {
71
- bar[config.xAxis.dataKey] = xAxisValue
72
- setSharedFilter(config.uid, bar)
73
- }
74
- }}
75
- >
76
- <div
77
- style={{ transition: 'all 0.2s linear', opacity: transparentBar ? 0.2 : 1, width: barThicknessAdjusted, height: bar.height, background: colorScale(config.runtime.seriesLabels[bar.key]), border: `${config.barHasBorder === 'true' ? barBorderWidth : 0}px solid #333`, ...style }}
78
- ></div>
79
- </foreignObject>
80
- </Group>
81
- </Group>
82
- )
83
- })
84
- )
85
- }
86
- </BarStack>
87
- )
88
- )
89
- }
90
-
91
- export default BarChartStackedVertical
@@ -1,30 +0,0 @@
1
- import React, { useContext } from 'react'
2
-
3
- // visx
4
- import { Group } from '@visx/group'
5
- import { Bar } from '@visx/shape'
6
-
7
- // cdc
8
- import BarChartType from './BarChartType'
9
- import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
10
- import ConfigContext from '../ConfigContext'
11
-
12
- const BarChart = ({ xScale, yScale, seriesScale, xMax, yMax, handleTooltipMouseOver, handleTooltipMouseOff, handleTooltipClick }) => {
13
- const { transformedData: data, config } = useContext(ConfigContext)
14
-
15
- return (
16
- <ErrorBoundary component='BarChart'>
17
- <Group left={parseFloat(config.runtime.yAxis.size)}>
18
- <BarChartType.StackedVertical xScale={xScale} yScale={yScale} xMax={xMax} yMax={yMax} />
19
- <BarChartType.StackedHorizontal xScale={xScale} yScale={yScale} xMax={xMax} yMax={yMax} />
20
- <BarChartType.Vertical xScale={xScale} yScale={yScale} xMax={xMax} yMax={yMax} seriesScale={seriesScale} />
21
- <BarChartType.Horizontal xScale={xScale} yScale={yScale} xMax={xMax} yMax={yMax} seriesScale={seriesScale} />
22
-
23
- {/* tooltips */}
24
- <Bar key={'bars'} display={config.tooltips.singleSeries ? 'none' : 'block'} width={Number(xMax)} height={Number(yMax)} fill={'transparent'} fillOpacity={0.05} onMouseMove={e => handleTooltipMouseOver(e, data)} onMouseOut={handleTooltipMouseOff} onClick={e => handleTooltipClick(e, data)} />
25
- </Group>
26
- </ErrorBoundary>
27
- )
28
- }
29
-
30
- export default BarChart
File without changes
File without changes