@cdc/chart 4.25.6 → 4.25.7

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 (36) hide show
  1. package/dist/cdcchart.js +52667 -32246
  2. package/package.json +3 -2
  3. package/src/CdcChartComponent.tsx +13 -9
  4. package/src/_stories/Chart.BoxPlot.stories.tsx +35 -0
  5. package/src/_stories/Chart.stories.tsx +0 -7
  6. package/src/_stories/Chart.tooltip.stories.tsx +35 -275
  7. package/src/_stories/_mock/bar-chart-suppressed.json +2 -80
  8. package/src/_stories/_mock/boxplot_multiseries.json +252 -166
  9. package/src/components/AreaChart/components/AreaChart.Stacked.jsx +1 -1
  10. package/src/components/AreaChart/components/AreaChart.jsx +4 -8
  11. package/src/components/BarChart/components/BarChart.Horizontal.tsx +34 -2
  12. package/src/components/BarChart/components/BarChart.Vertical.tsx +15 -0
  13. package/src/components/BoxPlot/BoxPlot.Horizontal.tsx +131 -0
  14. package/src/components/BoxPlot/{BoxPlot.tsx → BoxPlot.Vertical.tsx} +4 -4
  15. package/src/components/BoxPlot/helpers/index.ts +32 -12
  16. package/src/components/BrushChart.tsx +1 -1
  17. package/src/components/EditorPanel/EditorPanel.tsx +19 -14
  18. package/src/components/EditorPanel/components/Panels/Panel.General.tsx +2 -2
  19. package/src/components/Forecasting/{Forecasting.jsx → Forecasting.tsx} +32 -12
  20. package/src/components/Legend/LegendGroup/LegendGroup.tsx +1 -0
  21. package/src/components/Legend/helpers/index.ts +2 -2
  22. package/src/components/LineChart/helpers.ts +7 -7
  23. package/src/components/LinearChart.tsx +127 -72
  24. package/src/data/initial-state.js +1 -5
  25. package/src/helpers/countNumOfTicks.ts +4 -19
  26. package/src/helpers/filterAndShiftLinearDateTicks.ts +58 -0
  27. package/src/helpers/getBridgedData.ts +13 -0
  28. package/src/helpers/tests/getBridgedData.test.ts +64 -0
  29. package/src/hooks/useScales.ts +42 -42
  30. package/src/hooks/useTooltip.tsx +3 -2
  31. package/src/scss/main.scss +2 -4
  32. package/src/store/chart.actions.ts +2 -2
  33. package/src/store/chart.reducer.ts +4 -12
  34. package/src/types/ChartConfig.ts +1 -6
  35. package/src/components/BoxPlot/index.tsx +0 -3
  36. /package/src/components/Brush/{BrushController..tsx → BrushController.tsx} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdc/chart",
3
- "version": "4.25.6",
3
+ "version": "4.25.7",
4
4
  "description": "React component for visualizing tabular data in various types of charts",
5
5
  "moduleName": "CdcChart",
6
6
  "main": "dist/cdcchart",
@@ -26,6 +26,7 @@
26
26
  },
27
27
  "license": "Apache-2.0",
28
28
  "dependencies": {
29
+ "@cdc/core": "^4.25.7",
29
30
  "@hello-pangea/dnd": "^16.2.0",
30
31
  "@react-spring/web": "^9.7.5",
31
32
  "@visx/axis": "3.12.0",
@@ -53,7 +54,7 @@
53
54
  "react": "^18.2.0",
54
55
  "react-dom": "^18.2.0"
55
56
  },
56
- "gitHead": "6097de1ff814001880d9ac64bd66becdc092d63c",
57
+ "gitHead": "9062881d50c824ee6cdd71868bafd016a5e5694d",
57
58
  "devDependencies": {
58
59
  "@types/d3-array": "^3.2.1",
59
60
  "@types/d3-format": "^3.0.4",
@@ -65,6 +65,7 @@ import isNumber from '@cdc/core/helpers/isNumber'
65
65
  import coveUpdateWorker from '@cdc/core/helpers/coveUpdateWorker'
66
66
  import EditorContext from '../../editor/src/ConfigContext'
67
67
  import { EDITOR_WIDTH } from '@cdc/core/helpers/constants'
68
+ import { extractCoveData, updateVegaData } from '@cdc/core/helpers/vegaConfig'
68
69
  // Local helpers
69
70
  import { isConvertLineToBarGraph } from './helpers/isConvertLineToBarGraph'
70
71
  import { getBoxPlotConfig } from './helpers/getBoxPlotConfig'
@@ -124,8 +125,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
124
125
  coveLoadedEventRan,
125
126
  imageId,
126
127
  seriesHighlight,
127
- colorScale,
128
- brushConfig
128
+ colorScale
129
129
  } = state
130
130
  const { description, visualizationType } = config
131
131
  const svgRef = useRef(null)
@@ -261,6 +261,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
261
261
  const [plots, categories] = getBoxPlotConfig(newConfig, stateData)
262
262
  newConfig.boxplot['categories'] = categories
263
263
  newConfig.boxplot.plots = plots
264
+ newConfig.yAxis.labelPlacement = 'On Date/Category Axis'
264
265
  }
265
266
  if (newConfig.visualizationType === 'Combo' && newConfig.series) {
266
267
  newConfig.runtime = getComboChartConfig(newConfig)
@@ -286,7 +287,8 @@ const CdcChart: React.FC<CdcChartProps> = ({
286
287
  }
287
288
 
288
289
  if (
289
- (newConfig.visualizationType === 'Bar' && newConfig.orientation === 'horizontal') ||
290
+ ((newConfig.visualizationType === 'Bar' || newConfig.visualizationType === 'Box Plot') &&
291
+ newConfig.orientation === 'horizontal') ||
290
292
  ['Deviation Bar', 'Paired Bar', 'Forest Plot'].includes(newConfig.visualizationType)
291
293
  ) {
292
294
  newConfig.runtime.xAxis = _.cloneDeep(newConfig.yAxis.yAxis || newConfig.yAxis)
@@ -298,7 +300,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
298
300
  // remove after COVE supports categorical axis on horizonatal bars
299
301
  newConfig.yAxis.type = newConfig.yAxis.type === 'categorical' ? 'linear' : newConfig.yAxis.type
300
302
  } else if (
301
- ['Box Plot', 'Scatter Plot', 'Area Chart', 'Line', 'Forecasting'].includes(newConfig.visualizationType) &&
303
+ ['Scatter Plot', 'Area Chart', 'Line', 'Forecasting'].includes(newConfig.visualizationType) &&
302
304
  !convertLineToBarGraph
303
305
  ) {
304
306
  newConfig.runtime.xAxis = newConfig.xAxis
@@ -409,6 +411,10 @@ const CdcChart: React.FC<CdcChartProps> = ({
409
411
  if (newConfig.dataUrl) newConfig.dataUrl = `${newConfig.dataUrl}`
410
412
  let newData = await fetchRemoteData(newConfig.dataUrl)
411
413
 
414
+ if (newConfig.vegaConfig) {
415
+ newData = extractCoveData(updateVegaData(newConfig.vegaConfig, newData))
416
+ }
417
+
412
418
  if (newData && newConfig.dataDescription) {
413
419
  newData = transform.autoStandardize(newData)
414
420
  newData = transform.developerStandardize(newData, newConfig.dataDescription)
@@ -840,7 +846,7 @@ const CdcChart: React.FC<CdcChartProps> = ({
840
846
  if (legend?.hide) classes.push('legend-hidden')
841
847
  if (lineDatapointClass) classes.push(lineDatapointClass)
842
848
  if (!config.barHasBorder) classes.push('chart-bar--no-border')
843
- if (config.brush?.active && dashboardConfig?.type === 'dashboard' && (!isLegendOnBottom || legend.hide))
849
+ if (config.xAxis.brushActive && dashboardConfig?.type === 'dashboard' && (!isLegendOnBottom || legend.hide))
844
850
  classes.push('dashboard-brush')
845
851
  classes.push(...contentClasses)
846
852
  return classes
@@ -851,8 +857,8 @@ const CdcChart: React.FC<CdcChartProps> = ({
851
857
  const isLegendOnBottom = legend?.position === 'bottom' || isLegendWrapViewport(currentViewport)
852
858
 
853
859
  if (config.isResponsiveTicks) classes.push('subtext--responsive-ticks ')
854
- if (config.brush?.active && !isLegendOnBottom) classes.push('subtext--brush-active ')
855
- if (config.brush?.active && config.legend.hide) classes.push('subtext--brush-active ')
860
+ if (config.xAxis.brushActive && !isLegendOnBottom) classes.push('subtext--brush-active ')
861
+ if (config.xAxis.brushActive && config.legend.hide) classes.push('subtext--brush-active ')
856
862
  return classes
857
863
  }
858
864
 
@@ -862,7 +868,6 @@ const CdcChart: React.FC<CdcChartProps> = ({
862
868
  {config.dataKey} (Go to Table)
863
869
  </a>
864
870
  )
865
-
866
871
  body = (
867
872
  <>
868
873
  {isEditor && <EditorPanel datasets={datasets} />}
@@ -1102,7 +1107,6 @@ const CdcChart: React.FC<CdcChartProps> = ({
1102
1107
 
1103
1108
  const contextValues = {
1104
1109
  ...state,
1105
- brushConfig,
1106
1110
  capitalize,
1107
1111
  convertLineToBarGraph,
1108
1112
  clean,
@@ -0,0 +1,35 @@
1
+ import type { Meta, StoryObj } from '@storybook/react'
2
+ import boxPlotConfig from './_mock/boxplot_multiseries.json'
3
+ import Chart from '../CdcChartComponent'
4
+
5
+ const meta: Meta<typeof Chart> = {
6
+ title: 'Components/Templates/Chart/Box Plot',
7
+ component: Chart
8
+ }
9
+
10
+ type Story = StoryObj<typeof Chart>
11
+
12
+ export const BoxPlot_Vertical: Story = {
13
+ args: {
14
+ config: {
15
+ ...boxPlotConfig,
16
+ orientation: 'vertical',
17
+ title: 'Vertical Multiseries Box Plot',
18
+ isEditor: false
19
+ }
20
+ }
21
+ }
22
+
23
+ export const BoxPlot_Horizontal: Story = {
24
+ args: {
25
+ config: {
26
+ ...boxPlotConfig,
27
+ orientation: 'horizontal',
28
+ title: 'Horizontal Multiseries Box Plot',
29
+ yAxis: { ...boxPlotConfig.yAxis, labelPlacement: 'Above Bar' }
30
+ },
31
+ isEditor: false
32
+ }
33
+ }
34
+
35
+ export default meta
@@ -10,7 +10,6 @@ import horizontalBarConfig from './_mock/horizontal_bar.json'
10
10
  import barChartLabels from './_mock/barchart_labels.mock.json'
11
11
  import pieConfig from './_mock/pie_with_data.json'
12
12
  import pieCalculatedArea from './_mock/pie_calculated_area.json'
13
- import boxPlotConfig from './_mock/boxplot_multiseries.json'
14
13
  import areaChartStacked from './_mock/area_chart_stacked.json'
15
14
  import multipleLines from './_mock/short_dates.json'
16
15
  import { editConfigKeys } from '../helpers/configHelpers'
@@ -82,12 +81,6 @@ export const Paired_Bar: Story = {
82
81
  config: pairedBar
83
82
  }
84
83
  }
85
- export const BoxPlot_Multiseries: Story = {
86
- args: {
87
- config: boxPlotConfig,
88
- isEditor: false
89
- }
90
- }
91
84
 
92
85
  export const Area_Chart_stacked: Story = {
93
86
  args: {
@@ -1,7 +1,8 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react'
2
2
 
3
3
  import Chart from '../CdcChartComponent'
4
-
4
+ import barChartStacked from './_mock/barchart_labels.mock.json'
5
+ import barChartSuppressed from './_mock/bar-chart-suppressed.json'
5
6
  const meta: Meta<typeof Chart> = {
6
7
  title: 'Components/Templates/Chart/Tooltip',
7
8
  component: Chart
@@ -9,294 +10,53 @@ const meta: Meta<typeof Chart> = {
9
10
 
10
11
  type Story = StoryObj<typeof Chart>
11
12
 
13
+ export const Increased_Tooltip_Range: Story = {
14
+ args: {
15
+ config: {
16
+ ...barChartSuppressed,
17
+ title: 'Increased Tooltip hovers range for missing and suppressed bars',
18
+ tooltips: {
19
+ ...barChartSuppressed.tooltips,
20
+ singleSeries: true
21
+ }
22
+ }
23
+ }
24
+ }
25
+
12
26
  export const Additional_Tooltip: Story = {
13
27
  args: {
14
28
  config: {
15
- type: 'chart',
16
- debugSvg: false,
17
- chartMessage: {
18
- noData: 'No Data Available'
19
- },
20
- title: 'Example Stacked Bar Chart with Additional tolltip column',
29
+ ...barChartStacked,
30
+ title: 'Stacked Bar Chart with Additional Tooltip Column',
21
31
  showTitle: true,
22
- showDownloadMediaButton: false,
23
- theme: 'theme-orange',
24
- animate: false,
25
- lineDatapointStyle: 'hover',
26
- barHasBorder: 'false',
27
- isLollipopChart: false,
28
- lollipopShape: 'circle',
29
- lollipopColorStyle: 'two-tone',
30
32
  visualizationSubType: 'stacked',
31
- barStyle: '',
32
- roundingStyle: 'standard',
33
- tipRounding: 'top',
34
- isResponsiveTicks: false,
35
- general: {
36
- showDownloadButton: false
37
- },
38
- padding: {
39
- left: 5,
40
- right: 5
41
- },
42
- yAxis: {
43
- hideAxis: false,
44
- displayNumbersOnBar: false,
45
- hideLabel: false,
46
- hideTicks: false,
47
- size: '64',
48
- gridLines: false,
49
- enablePadding: false,
50
- min: '',
51
- max: '',
52
- labelColor: '#333',
53
- tickLabelColor: '#333',
54
- tickColor: '#333',
55
- rightHideAxis: true,
56
- rightAxisSize: 0,
57
- rightLabel: '',
58
- rightLabelOffsetSize: 0,
59
- rightAxisLabelColor: '#333',
60
- rightAxisTickLabelColor: '#333',
61
- rightAxisTickColor: '#333',
62
- numTicks: '',
63
- axisPadding: 0,
64
- tickRotation: 0,
65
- anchors: [],
66
- label: 'Y-Axis Label Example'
67
- },
68
- boxplot: {
69
- plots: [],
70
- borders: 'true',
71
- firstQuartilePercentage: 25,
72
- thirdQuartilePercentage: 75,
73
- boxWidthPercentage: 40,
74
- plotOutlierValues: false,
75
- plotNonOutlierValues: true,
76
- legend: {
77
- showHowToReadText: false,
78
- howToReadText: ''
79
- },
80
- labels: {
81
- q1: 'Lower Quartile',
82
- q2: 'q2',
83
- q3: 'Upper Quartile',
84
- q4: 'q4',
85
- minimum: 'Minimum',
86
- maximum: 'Maximum',
87
- mean: 'Mean',
88
- median: 'Median',
89
- sd: 'Standard Deviation',
90
- iqr: 'Interquartile Range',
91
- total: 'Total',
92
- outliers: 'Outliers',
93
- values: 'Values',
94
- lowerBounds: 'Lower Bounds',
95
- upperBounds: 'Upper Bounds'
33
+ series: [
34
+ ...barChartStacked.series,
35
+ {
36
+ dataKey: 'White, non-Hispanic',
37
+ type: 'Bar',
38
+ axis: 'Left',
39
+ tooltip: true
96
40
  }
97
- },
98
- topAxis: {
99
- hasLine: false
100
- },
101
- isLegendValue: false,
102
- barThickness: 0.35,
103
- barHeight: 25,
104
- barSpace: 15,
105
- heights: {
106
- vertical: 300,
107
- horizontal: 750
108
- },
109
- xAxis: {
110
- sortDates: false,
111
- anchors: [],
112
- type: 'categorical',
113
- showTargetLabel: true,
114
- targetLabel: 'Target',
115
- hideAxis: false,
116
- hideLabel: false,
117
- hideTicks: false,
118
- size: '67',
119
- tickRotation: '25',
120
- min: '',
121
- max: '',
122
- labelColor: '#333',
123
- tickLabelColor: '#333',
124
- tickColor: '#333',
125
- numTicks: '',
126
- labelOffset: 65,
127
- axisPadding: 0,
128
- target: 0,
129
- maxTickRotation: 0,
130
- dataKey: 'Year',
131
- label: 'X-Axis Label Example',
132
- tickWidthMax: 41
133
- },
134
- table: {
135
- label: 'Data Table',
136
- expanded: true,
137
- limitHeight: false,
138
- height: '',
139
- caption: '',
140
- showDownloadUrl: false,
141
- showDataTableLink: true,
142
- indexLabel: '',
143
- download: true,
144
- showVertical: false,
145
- show: true
146
- },
147
- orientation: 'vertical',
148
- color: 'pinkpurple',
41
+ ],
149
42
  columns: {
150
- additionalColumn1: {
151
- label: 'New Column',
152
- dataTable: false,
43
+ 'American Indian/Alaska Native': {
44
+ label: 'Additional Tooltip',
45
+ dataTable: true,
153
46
  tooltips: true,
154
47
  prefix: '',
155
48
  suffix: '',
156
49
  forestPlot: false,
157
50
  startingPoint: '0',
158
51
  forestPlotAlignRight: false,
159
- name: 'Data 1'
52
+ roundToPlace: 0,
53
+ commas: true,
54
+ showInViz: false,
55
+ forestPlotStartingPoint: 0,
56
+ name: 'American Indian/Alaska Native',
57
+ series: 'Hispanic'
160
58
  }
161
- },
162
- legend: {
163
- hide: false,
164
- behavior: 'isolate',
165
- singleRow: false,
166
- colorCode: '',
167
- reverseLabelOrder: false,
168
- description: '',
169
- dynamicLegend: false,
170
- dynamicLegendDefaultText: 'Show All',
171
- dynamicLegendItemLimit: 5,
172
- dynamicLegendItemLimitMessage: 'Dynamic Legend Item Limit Hit.',
173
- dynamicLegendChartMessage: 'Select Options from the Legend',
174
- lineMode: false,
175
- verticalSorted: false,
176
- position: 'right',
177
- label: 'Data Type'
178
- },
179
- brush: {
180
- height: 25,
181
- data: [],
182
- active: false
183
- },
184
- exclusions: {
185
- active: false,
186
- keys: []
187
- },
188
- palette: 'qualitative-bold',
189
- isPaletteReversed: false,
190
- twoColor: {
191
- palette: 'monochrome-1',
192
- isPaletteReversed: false
193
- },
194
- labels: false,
195
- dataFormat: {
196
- commas: false,
197
- prefix: '',
198
- suffix: '%',
199
- abbreviated: false,
200
- bottomSuffix: '',
201
- bottomPrefix: '',
202
- bottomAbbreviated: false
203
- },
204
- confidenceKeys: {},
205
- visual: {
206
- border: true,
207
- accent: true,
208
- background: true,
209
- verticalHoverLine: false,
210
- horizontalHoverLine: false
211
- },
212
- useLogScale: false,
213
- filterBehavior: 'Filter Change',
214
- highlightedBarValues: [],
215
- series: [
216
- {
217
- dataKey: 'Data 2',
218
- type: 'Bar',
219
- tooltip: true
220
- },
221
- {
222
- dataKey: 'Data 3',
223
- type: 'Bar',
224
- tooltip: true
225
- }
226
- ],
227
- tooltips: {
228
- opacity: 90
229
- },
230
- forestPlot: {
231
- startAt: 0,
232
- width: 'auto',
233
- colors: {
234
- line: '',
235
- shape: ''
236
- },
237
- estimateField: '',
238
- estimateRadius: '',
239
- lowerCiField: '',
240
- upperCiField: '',
241
- shape: '',
242
- rowHeight: 20,
243
- showZeroLine: false,
244
- description: {
245
- show: true,
246
- text: 'description',
247
- location: 0
248
- },
249
- result: {
250
- show: true,
251
- text: 'result',
252
- location: 100
253
- },
254
- radius: {
255
- min: 1,
256
- max: 8,
257
- scalingColumn: ''
258
- },
259
- regression: {
260
- lower: 0,
261
- upper: 0,
262
- estimateField: 0
263
- },
264
- leftWidthOffset: 0,
265
- rightWidthOffset: 0
266
- },
267
- area: {
268
- isStacked: false
269
- },
270
- height: '375',
271
- data: [
272
- {
273
- Year: '2015',
274
- 'Data 1': '25',
275
- 'Data 2': '20',
276
- 'Data 3': '55'
277
- },
278
- {
279
- Year: '2016',
280
- 'Data 1': '35',
281
- 'Data 2': '30',
282
- 'Data 3': '35'
283
- },
284
- {
285
- Year: '2017',
286
- 'Data 1': '22',
287
- 'Data 2': '38',
288
- 'Data 3': '40'
289
- },
290
- {
291
- Year: '2018',
292
- 'Data 1': '40',
293
- 'Data 2': '40',
294
- 'Data 3': '20'
295
- }
296
- ],
297
- visualizationType: 'Bar',
298
- validated: 4.23,
299
- dynamicMarginTop: 0
59
+ }
300
60
  }
301
61
  }
302
62
  }
@@ -178,84 +178,7 @@
178
178
  "position": "right",
179
179
  "label": "Data Type"
180
180
  },
181
- "brush": {
182
- "height": 25,
183
- "active": false,
184
- "data": [
185
- {
186
- "Date": "1/15/2016",
187
- "Data 1": "1000",
188
- "Data 2": "110",
189
- "Data 3": "100",
190
- "Data 4": "90",
191
- "Monthly-Goal": "100"
192
- },
193
- {
194
- "Date": "2/15/2016",
195
- "Data 1": "100",
196
- "Data 2": "110",
197
- "Data 3": "100",
198
- "Data 4": "100",
199
- "Monthly-Goal": "100"
200
- },
201
- {
202
- "Date": "3/15/2016",
203
- "Data 1": "80",
204
- "Data 2": "90",
205
- "Data 3": "100",
206
- "Data 4": "120",
207
- "Monthly-Goal": "110"
208
- },
209
- {
210
- "Date": "4/15/2016",
211
- "Data 1": "80",
212
- "Data 2": "90",
213
- "Data 3": "110",
214
- "Data 4": "120",
215
- "Monthly-Goal": "110"
216
- },
217
- {
218
- "Date": "5/15/2016",
219
- "Data 1": "70",
220
- "Data 2": "90",
221
- "Data 3": "110",
222
- "Data 4": "130",
223
- "Monthly-Goal": "120"
224
- },
225
- {
226
- "Date": "6/15/2016",
227
- "Data 1": "100",
228
- "Data 2": "120",
229
- "Data 3": "120",
230
- "Data 4": "130",
231
- "Monthly-Goal": "120"
232
- },
233
- {
234
- "Date": "7/15/2016",
235
- "Data 1": "110",
236
- "Data 2": "140",
237
- "Data 3": "120",
238
- "Data 4": "130",
239
- "Monthly-Goal": "130"
240
- },
241
- {
242
- "Date": "8/15/2016",
243
- "Data 1": "110",
244
- "Data 2": "130",
245
- "Data 3": "120",
246
- "Data 4": "140",
247
- "Monthly-Goal": "130"
248
- },
249
- {
250
- "Date": "9/15/2016",
251
- "Data 1": "120",
252
- "Data 2": "130",
253
- "Data 3": "120",
254
- "Data 4": "150",
255
- "Monthly-Goal": "140"
256
- }
257
- ]
258
- },
181
+
259
182
  "exclusions": {
260
183
  "active": false,
261
184
  "keys": []
@@ -390,7 +313,6 @@
390
313
  },
391
314
  "data": []
392
315
  },
393
- "suppressedData": [],
394
316
  "height": "332",
395
317
  "data": [
396
318
  {
@@ -460,7 +382,7 @@
460
382
  {
461
383
  "Date": "9/15/2016",
462
384
  "Data 1": "120",
463
- "Data 2": "",
385
+ "Data 2": "Aza",
464
386
  "Data 3": "120",
465
387
  "Data 4": "150",
466
388
  "Monthly-Goal": "140"