@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
@@ -5,6 +5,7 @@ import ConfigContext from '../../ConfigContext'
5
5
  import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
6
6
  import { colorPalettesChart } from '@cdc/core/data/colorPalettes'
7
7
  import { handleTooltip, createPlots } from './helpers/index'
8
+ import { APP_FONT_COLOR } from '@cdc/core/helpers/constants'
8
9
  import _ from 'lodash'
9
10
 
10
11
  const CoveBoxPlot = ({ xScale, yScale, seriesScale }) => {
@@ -15,7 +16,7 @@ const CoveBoxPlot = ({ xScale, yScale, seriesScale }) => {
15
16
  const boxWidth = xScale.bandwidth()
16
17
 
17
18
  const bodyStyles = getComputedStyle(document.body)
18
- const defaultColor = bodyStyles.getPropertyValue('--cool-gray-90').trim()
19
+ const defaultColor = APP_FONT_COLOR
19
20
  const constrainedWidth = Math.min(40, boxWidth)
20
21
  const color_0 = _.get(colorPalettesChart, [config.palette, 0], '#000')
21
22
  const plots = createPlots(data, config)
@@ -0,0 +1,73 @@
1
+ import React, { FC, useContext, useEffect, useRef, useState } from 'react'
2
+ import { Brush } from '@visx/brush'
3
+ import { Group } from '@visx/group'
4
+ import { scaleBand, scaleLinear } from '@visx/scale'
5
+ import ConfigContext from '../../ConfigContext'
6
+ import { Text } from '@visx/text'
7
+ import { APP_FONT_SIZE } from '@cdc/core/helpers/constants'
8
+ import { getTextWidth } from '@cdc/core/helpers/getTextWidth'
9
+ import { isDateScale } from '@cdc/core/helpers/cove/date'
10
+ export interface ZoomBrushProps {
11
+ xMax: number
12
+ yMax: number
13
+ brushPosition: { start: { x: number }; end: { x: number } }
14
+ onBrushChange: (bounds: any) => void
15
+ brushKey: number
16
+ }
17
+
18
+ const ZoomBrush: FC<ZoomBrushProps> = ({ xMax, yMax, brushPosition, onBrushChange, brushKey }) => {
19
+ const { tableData, config, parseDate, dashboardConfig } = useContext(ConfigContext)
20
+ const brushRef = useRef(null)
21
+ const dataKey = config.xAxis.dataKey
22
+ const borderRadius = 15
23
+ const mappedDates: string[] = tableData.map(row => row[dataKey])
24
+ const brushheight = 25
25
+ const DASHBOARD_MARGIN = 50
26
+ const BRUSH_HEIGHT_MULTIPLIER = 1.5
27
+
28
+ const xScale = scaleBand<string>({
29
+ domain: mappedDates,
30
+ range: [0, xMax],
31
+ paddingInner: 0.1,
32
+ paddingOuter: 0.1
33
+ })
34
+ const yScale = scaleLinear({ domain: [0, yMax], range: [0, yMax] })
35
+
36
+ const calculateGroupTop = (): number => {
37
+ if (dashboardConfig?.type === 'dashboard') {
38
+ return Number(yMax) + config.xAxis.axisBBox + brushheight * BRUSH_HEIGHT_MULTIPLIER + DASHBOARD_MARGIN
39
+ } else {
40
+ return Number(yMax) + config.xAxis.axisBBox + brushheight * BRUSH_HEIGHT_MULTIPLIER
41
+ }
42
+ }
43
+
44
+ const style = {
45
+ fill: '#474747',
46
+ stroke: 'blue',
47
+ strokeOpacity: 0,
48
+ rx: borderRadius
49
+ }
50
+
51
+ return (
52
+ <Group left={config.yAxis.size} top={calculateGroupTop()}>
53
+ <rect fill='#949494' width={xMax} height={25} rx={borderRadius} pointerEvents='none' />
54
+ <Brush
55
+ innerRef={brushRef}
56
+ key={brushKey}
57
+ xScale={xScale}
58
+ yScale={yScale}
59
+ width={xMax}
60
+ height={25}
61
+ brushDirection='horizontal'
62
+ handleSize={8}
63
+ resizeTriggerAreas={['left', 'right']}
64
+ initialBrushPosition={brushPosition}
65
+ selectedBoxStyle={style}
66
+ onChange={onBrushChange}
67
+ disableDraggingOverlay={true}
68
+ />
69
+ </Group>
70
+ )
71
+ }
72
+
73
+ export default ZoomBrush
@@ -0,0 +1,39 @@
1
+ import { useState, useEffect, useContext } from 'react'
2
+ import ConfigContext, { ChartDispatchContext } from '../../ConfigContext'
3
+ import ZoomBrush from './BrushChart'
4
+ const BrushController = ({ yMax, xMax }) => {
5
+ const { tableData, config, parseDate, dashboardConfig } = useContext(ConfigContext)
6
+ const dataKey = config.xAxis.dataKey
7
+ const [brushKey, setBrushKey] = useState(0)
8
+ const dispatch = useContext(ChartDispatchContext)
9
+ const sharedFilters = dashboardConfig?.dashboard?.sharedFilters ?? []
10
+ const isDashboardFilters = sharedFilters?.length > 0
11
+ const [brushPosition, setBrushPosition] = useState({
12
+ start: { x: 0 },
13
+ end: { x: xMax }
14
+ })
15
+
16
+ const handleBrushChange = (bounds: any) => {
17
+ const selected = bounds.xValues || []
18
+ const filteredData = tableData.filter(row => selected.includes(row[dataKey]))
19
+ dispatch({ type: 'SET_BRUSH_DATA', payload: filteredData })
20
+ }
21
+
22
+ // whenever your other filters change:
23
+ useEffect(() => {
24
+ setBrushPosition({ start: { x: 0 }, end: { x: xMax } })
25
+ dispatch({ type: 'SET_BRUSH_DATA', payload: [] })
26
+ setBrushKey(k => k + 1)
27
+ }, [config.filters, config.exclusions, config.brush?.active, isDashboardFilters])
28
+
29
+ return (
30
+ <ZoomBrush
31
+ xMax={xMax}
32
+ yMax={yMax}
33
+ brushPosition={brushPosition}
34
+ onBrushChange={handleBrushChange}
35
+ brushKey={brushKey}
36
+ />
37
+ )
38
+ }
39
+ export default BrushController
@@ -6,6 +6,7 @@ import { Text } from '@visx/text'
6
6
  import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
7
7
  import useIntersectionObserver from '../hooks/useIntersectionObserver'
8
8
  import { getContrastColor } from '@cdc/core/helpers/cove/accessibility'
9
+ import { APP_FONT_COLOR } from '@cdc/core/helpers/constants'
9
10
  import { getTextWidth } from '@cdc/core/helpers/getTextWidth'
10
11
 
11
12
  export default function DeviationBar({ height, xScale }) {
@@ -14,7 +15,6 @@ export default function DeviationBar({ height, xScale }) {
14
15
  config,
15
16
  formatNumber,
16
17
  twoColorPalette,
17
- updateConfig,
18
18
  parseDate,
19
19
  formatDate,
20
20
  currentViewport
@@ -178,7 +178,7 @@ export default function DeviationBar({ height, xScale }) {
178
178
  // colors
179
179
  const [leftColor, rightColor] = twoColorPalette[twoColor.palette]
180
180
  const barColor = { left: leftColor, right: rightColor }
181
- const fill = getContrastColor('#000', barColor[barPosition])
181
+ const fill = getContrastColor(APP_FONT_COLOR, barColor[barPosition])
182
182
 
183
183
  let textProps = getTextProps(config.isLollipopChart, textFits, lollipopShapeSize, fill)
184
184
  // tooltips