@cdc/chart 4.26.5 → 4.26.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 (91) hide show
  1. package/CONFIG.md +12 -8
  2. package/dist/{cdcchart-DQ00cQCm.es.js → cdcchart-BWVIUcAF.es.js} +5 -55
  3. package/dist/cdcchart.js +34093 -32767
  4. package/examples/feature/heatmap/average-age-categorical.json +1 -1
  5. package/examples/feature/heatmap/calendar-heatmap.json +1 -1
  6. package/examples/feature/heatmap/sparse-aggregation.json +1 -1
  7. package/examples/private/bad-y-axis.json +543 -0
  8. package/examples/private/bar-chart-negative-value.json +455 -0
  9. package/package.json +3 -3
  10. package/src/CdcChart.tsx +5 -4
  11. package/src/CdcChartComponent.tsx +32 -9
  12. package/src/_stories/Chart.SeriesColorAssignments.stories.tsx +183 -0
  13. package/src/_stories/Chart.YAxisAutoMaxStrategy.stories.tsx +52 -0
  14. package/src/_stories/Chart.YAxisFilterDomain.stories.tsx +90 -0
  15. package/src/_stories/ChartAnnotation.smoke.stories.tsx +10 -0
  16. package/src/_stories/_mock/annotation_event-line_mock.json +1064 -0
  17. package/src/_stories/_mock/heatmap-average-age-categorical.json +1 -1
  18. package/src/_stories/_mock/heatmap.json +1 -1
  19. package/src/components/Annotations/components/AnnotationDraggable.styles.css +22 -1
  20. package/src/components/Annotations/components/AnnotationDraggable.tsx +219 -119
  21. package/src/components/Annotations/tests/AnnotationDraggable.test.tsx +198 -0
  22. package/src/components/Axis/LeftAxis.tsx +3 -0
  23. package/src/components/Axis/LeftAxisGridlines.tsx +8 -1
  24. package/src/components/Axis/RightAxis.tsx +3 -0
  25. package/src/components/Axis/tests/AxisTickValues.test.tsx +86 -0
  26. package/src/components/EditorPanel/EditorPanel.tsx +367 -136
  27. package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +101 -52
  28. package/src/components/EditorPanel/components/Panels/Panel.SmallMultiples.test.tsx +98 -0
  29. package/src/components/EditorPanel/components/Panels/Panel.SmallMultiples.tsx +10 -0
  30. package/src/components/EditorPanel/components/Panels/Panel.Visual.test.tsx +484 -0
  31. package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +3 -0
  32. package/src/components/EditorPanel/components/Panels/SeriesColorAssignments.tsx +262 -0
  33. package/src/components/EditorPanel/components/Panels/panelVisual.styles.css +32 -0
  34. package/src/components/EditorPanel/components/panels.scss +10 -0
  35. package/src/components/EditorPanel/editor-panel.scss +47 -0
  36. package/src/components/EditorPanel/helpers/getVisualizationTypeConfigUpdate.ts +6 -2
  37. package/src/components/EditorPanel/helpers/tests/getVisualizationTypeConfigUpdate.test.ts +20 -2
  38. package/src/components/EditorPanel/useEditorPermissions.test.tsx +256 -11
  39. package/src/components/EditorPanel/useEditorPermissions.ts +41 -5
  40. package/src/components/HeatMap/components/HeatMap.tsx +22 -17
  41. package/src/components/HeatMap/components/HeatMapGradientLegend.tsx +29 -15
  42. package/src/components/HeatMap/heatmap.css +15 -1
  43. package/src/components/HeatMap/tests/HeatMap.test.tsx +39 -7
  44. package/src/components/Legend/Legend.Component.tsx +2 -2
  45. package/src/components/Legend/helpers/createFormatLabels.test.ts +88 -0
  46. package/src/components/Legend/helpers/createFormatLabels.tsx +6 -1
  47. package/src/components/LineChart/helpers.test.ts +230 -1
  48. package/src/components/LineChart/helpers.ts +26 -13
  49. package/src/components/LineChart/index.tsx +21 -4
  50. package/src/components/LinearChart/tests/LinearChart.test.tsx +30 -0
  51. package/src/components/LinearChart.tsx +50 -15
  52. package/src/components/ScatterPlot/ScatterPlot.jsx +3 -3
  53. package/src/components/SmallMultiples/SmallMultipleTile.tsx +3 -0
  54. package/src/components/SmallMultiples/SmallMultiples.tsx +38 -9
  55. package/src/components/SmallMultiples/tests/SmallMultiples.test.tsx +170 -0
  56. package/src/data/initial-state.js +1 -0
  57. package/src/helpers/calculateLeftYAxisWidth.ts +9 -3
  58. package/src/helpers/colorAssignmentHelpers.ts +102 -0
  59. package/src/helpers/dataHelpers.ts +11 -1
  60. package/src/helpers/getAxisMaxOverride.ts +16 -0
  61. package/src/helpers/getCleanTopTickMax.ts +64 -0
  62. package/src/helpers/getColorScale.ts +18 -9
  63. package/src/helpers/getHasBoundarySuppression.ts +26 -0
  64. package/src/helpers/getMinMax.ts +24 -22
  65. package/src/helpers/getYAxisDomainData.ts +38 -0
  66. package/src/helpers/getYAxisFinalizationEligibility.ts +40 -0
  67. package/src/helpers/hasSpacedInlineLabel.ts +10 -0
  68. package/src/helpers/seriesColumnSettings.ts +5 -4
  69. package/src/helpers/smallMultiplesHelpers.ts +5 -0
  70. package/src/helpers/tests/calculateLeftYAxisWidth.test.ts +38 -0
  71. package/src/helpers/tests/dataHelpers.test.ts +135 -0
  72. package/src/helpers/tests/getAxisMaxOverride.test.ts +36 -0
  73. package/src/helpers/tests/getCleanTopTickMax.test.ts +165 -0
  74. package/src/helpers/tests/getColorScale.test.ts +197 -0
  75. package/src/helpers/tests/getMinMax.test.ts +211 -0
  76. package/src/helpers/tests/getYAxisDomainData.test.ts +119 -0
  77. package/src/helpers/tests/getYAxisFinalizationEligibility.test.ts +185 -0
  78. package/src/helpers/tests/{getYAxisAutoPaddingMode.test.ts → hasSpacedInlineLabel.test.ts} +17 -32
  79. package/src/helpers/tests/seriesColumnSettings.test.ts +16 -2
  80. package/src/helpers/tests/smallMultiplesHelpers.test.ts +99 -0
  81. package/src/hooks/tests/useRightAxis.test.tsx +127 -0
  82. package/src/hooks/tests/useScales.test.tsx +307 -29
  83. package/src/hooks/useRightAxis.ts +30 -13
  84. package/src/hooks/useScales.ts +45 -28
  85. package/src/hooks/useTooltip.tsx +3 -1
  86. package/src/test/CdcChart.dataTable.test.tsx +122 -0
  87. package/src/types/ChartConfig.ts +6 -1
  88. package/src/types/ChartContext.ts +3 -0
  89. package/src/helpers/getYAxisAutoPadding.ts +0 -55
  90. package/src/helpers/getYAxisAutoPaddingMode.ts +0 -17
  91. package/src/helpers/tests/getYAxisAutoPadding.test.ts +0 -37
@@ -28,6 +28,7 @@ interface LeftAxisProps {
28
28
  xMax: number
29
29
  yAxisWidth: number
30
30
  numTicks: number
31
+ tickValues?: number[]
31
32
  tickLabelFontSize: number
32
33
  axisLabelFontSize: number
33
34
  handleLeftTickFormatting: (tick: any, index: number, ticks: any[]) => string
@@ -45,6 +46,7 @@ const LeftAxis: React.FC<LeftAxisProps> = ({
45
46
  xMax,
46
47
  yAxisWidth,
47
48
  numTicks,
49
+ tickValues,
48
50
  tickLabelFontSize,
49
51
  axisLabelFontSize,
50
52
  handleLeftTickFormatting,
@@ -71,6 +73,7 @@ const LeftAxis: React.FC<LeftAxisProps> = ({
71
73
  stroke='#333'
72
74
  tickFormat={handleLeftTickFormatting}
73
75
  numTicks={numTicks}
76
+ {...(tickValues ? { tickValues } : {})}
74
77
  >
75
78
  {props => {
76
79
  const axisCenter =
@@ -10,6 +10,7 @@ interface LeftAxisGridlinesProps {
10
10
  xMax: number
11
11
  yAxisWidth: number
12
12
  numTicks: number
13
+ tickValues?: number[]
13
14
  axisLabelFontSize: number
14
15
  }
15
16
 
@@ -18,6 +19,7 @@ const LeftAxisGridlines: React.FC<LeftAxisGridlinesProps> = ({
18
19
  xMax,
19
20
  yAxisWidth,
20
21
  numTicks,
22
+ tickValues,
21
23
  axisLabelFontSize
22
24
  }) => {
23
25
  const { config } = useContext(ConfigContext)
@@ -27,7 +29,12 @@ const LeftAxisGridlines: React.FC<LeftAxisGridlinesProps> = ({
27
29
  const showSideTitle = config.yAxis.titlePlacement !== 'top'
28
30
 
29
31
  return (
30
- <AxisLeft scale={yScale} left={yAxisWidth - config.yAxis.axisPadding} numTicks={numTicks}>
32
+ <AxisLeft
33
+ scale={yScale}
34
+ left={yAxisWidth - config.yAxis.axisPadding}
35
+ numTicks={numTicks}
36
+ {...(tickValues ? { tickValues } : {})}
37
+ >
31
38
  {props => {
32
39
  const axisCenter =
33
40
  config.orientation === 'horizontal'
@@ -15,6 +15,7 @@ type RightAxisProps = {
15
15
  yMax: number
16
16
  xMax: number
17
17
  yAxisWidth: number
18
+ tickValues?: number[]
18
19
  tickLabelFontSize: number
19
20
  axisLabelFontSize: number
20
21
  }
@@ -29,6 +30,7 @@ export const RightAxis: React.FC<RightAxisProps> = ({
29
30
  yMax,
30
31
  xMax,
31
32
  yAxisWidth,
33
+ tickValues,
32
34
  tickLabelFontSize,
33
35
  axisLabelFontSize
34
36
  }) => {
@@ -45,6 +47,7 @@ export const RightAxis: React.FC<RightAxisProps> = ({
45
47
  label={config.yAxis.rightLabel}
46
48
  tickFormat={tick => formatNumber(tick, 'right')}
47
49
  numTicks={runtime.yAxis.rightNumTicks || undefined}
50
+ {...(tickValues ? { tickValues } : {})}
48
51
  labelOffset={45}
49
52
  >
50
53
  {props => {
@@ -0,0 +1,86 @@
1
+ import React from 'react'
2
+ import { render, screen } from '@testing-library/react'
3
+ import { describe, expect, it, vi } from 'vitest'
4
+ import ConfigContext from '../../../ConfigContext'
5
+ import { createMockChartContext, createMockConfig } from '../../LinearChart/tests/mockConfigContext'
6
+
7
+ vi.mock('@visx/axis', () => ({
8
+ AxisLeft: ({ tickValues }: { tickValues?: number[] }) => (
9
+ <div data-testid='axis-left' data-tick-values={JSON.stringify(tickValues ?? null)} />
10
+ ),
11
+ AxisRight: ({ tickValues }: { tickValues?: number[] }) => (
12
+ <div data-testid='axis-right' data-tick-values={JSON.stringify(tickValues ?? null)} />
13
+ )
14
+ }))
15
+
16
+ import LeftAxis from '../LeftAxis'
17
+ import LeftAxisGridlines from '../LeftAxisGridlines'
18
+ import RightAxis from '../RightAxis'
19
+
20
+ const tickValues = [0, 5, 10, 15]
21
+
22
+ const renderWithContext = (children: React.ReactNode) => {
23
+ const config = createMockConfig({
24
+ runtime: {
25
+ ...createMockConfig().runtime,
26
+ yAxis: {
27
+ ...createMockConfig().runtime.yAxis,
28
+ rightNumTicks: 4
29
+ }
30
+ } as any
31
+ })
32
+
33
+ return render(<ConfigContext.Provider value={createMockChartContext(config)}>{children}</ConfigContext.Provider>)
34
+ }
35
+
36
+ describe('axis tick values', () => {
37
+ it('passes supplied tick values to the left axis', () => {
38
+ renderWithContext(
39
+ <LeftAxis
40
+ yScale={{}}
41
+ xScale={{}}
42
+ yMax={100}
43
+ xMax={300}
44
+ yAxisWidth={50}
45
+ numTicks={4}
46
+ tickValues={tickValues}
47
+ tickLabelFontSize={16}
48
+ axisLabelFontSize={16}
49
+ handleLeftTickFormatting={tick => String(tick)}
50
+ />
51
+ )
52
+
53
+ expect(JSON.parse(screen.getByTestId('axis-left').dataset.tickValues || 'null')).toEqual(tickValues)
54
+ })
55
+
56
+ it('passes supplied tick values to left-axis gridlines', () => {
57
+ renderWithContext(
58
+ <LeftAxisGridlines
59
+ yScale={{}}
60
+ xMax={300}
61
+ yAxisWidth={50}
62
+ numTicks={4}
63
+ tickValues={tickValues}
64
+ axisLabelFontSize={16}
65
+ />
66
+ )
67
+
68
+ expect(JSON.parse(screen.getByTestId('axis-left').dataset.tickValues || 'null')).toEqual(tickValues)
69
+ })
70
+
71
+ it('passes supplied tick values to the right axis', () => {
72
+ renderWithContext(
73
+ <RightAxis
74
+ yScaleRight={{} as any}
75
+ yMax={100}
76
+ xMax={300}
77
+ yAxisWidth={50}
78
+ tickValues={tickValues}
79
+ tickLabelFontSize={16}
80
+ axisLabelFontSize={16}
81
+ />
82
+ )
83
+
84
+ expect(JSON.parse(screen.getByTestId('axis-right').dataset.tickValues || 'null')).toEqual(tickValues)
85
+ })
86
+ })