@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
@@ -1,99 +1,32 @@
1
1
  {
2
- "errors": [],
3
- "currentViewport": "lg",
4
- "id": 1,
5
- "category": "Charts",
6
- "label": "Bar",
7
- "type": "chart",
8
- "subType": "Bar",
9
- "orientation": "vertical",
10
- "barThickness": "0.37",
11
- "visualizationSubType": "regular",
12
- "xAxis": {
13
- "sortDates": false,
14
- "anchors": [],
15
- "type": "categorical",
16
- "showTargetLabel": true,
17
- "targetLabel": "Target",
18
- "hideAxis": false,
19
- "hideLabel": false,
20
- "hideTicks": false,
21
- "size": 75,
22
- "tickRotation": 0,
23
- "min": "",
24
- "max": "",
25
- "labelColor": "#333",
26
- "tickLabelColor": "#333",
27
- "tickColor": "#333",
28
- "numTicks": "",
29
- "labelOffset": 0,
30
- "axisPadding": 200,
31
- "target": 0,
32
- "maxTickRotation": 45,
33
- "padding": 5,
34
- "showYearsOnce": false,
35
- "sortByRecentDate": false,
36
- "dataKey": "date",
37
- "tickWidthMax": 86
38
- },
39
- "icon": {
40
- "key": null,
41
- "ref": null,
42
- "props": {},
43
- "_owner": null,
44
- "_store": {}
45
- },
46
- "content": "Use bars to show comparisons between data categories.",
47
- "visualizationType": "Bar",
48
- "datasets": {},
49
- "activeVizButtonID": 1,
50
- "dataFileName": "http://localhost:8080/example/data-vertical.json",
51
- "dataFileSourceType": "url",
52
- "formattedData": [
53
- {
54
- "date": "01/01/2020",
55
- "value": 90
56
- },
57
- {
58
- "date": "02/01/2020",
59
- "value": 120
60
- },
61
- {
62
- "date": "03/01/2020",
63
- "value": 150
64
- }
65
- ],
66
- "dataUrl": "http://localhost:8080/examples/data-vertical.json",
67
- "dataDescription": {
68
- "horizontal": false,
69
- "series": false
70
- },
71
2
  "annotations": [],
3
+ "type": "chart",
72
4
  "debugSvg": false,
73
5
  "chartMessage": {
74
6
  "noData": "No Data Available"
75
7
  },
76
- "title": "Chart Title",
77
- "showTitle": true,
8
+ "title": "",
9
+ "showTitle": false,
78
10
  "showDownloadMediaButton": false,
79
11
  "theme": "theme-blue",
80
12
  "animate": false,
13
+ "fontSize": "medium",
81
14
  "lineDatapointStyle": "hover",
82
15
  "lineDatapointColor": "Same as Line",
83
- "barHasBorder": "true",
16
+ "barHasBorder": "false",
84
17
  "isLollipopChart": false,
85
18
  "lollipopShape": "circle",
86
19
  "lollipopColorStyle": "two-tone",
87
- "barStyle": "",
20
+ "visualizationSubType": "regular",
21
+ "barStyle": "flat",
88
22
  "roundingStyle": "standard",
89
23
  "tipRounding": "top",
90
- "isResponsiveTicks": false,
24
+ "isResponsiveTicks": true,
91
25
  "general": {
92
26
  "annotationDropdownText": "Annotations",
93
- "showDownloadButton": false,
94
- "showMissingDataLabel": true,
27
+ "showMissingDataLabel": false,
95
28
  "showSuppressedSymbol": true,
96
- "showZeroValueData": true,
29
+ "showZeroValueData": false,
97
30
  "hideNullValue": true
98
31
  },
99
32
  "padding": {
@@ -106,29 +39,32 @@
106
39
  "displayNumbersOnBar": false,
107
40
  "hideLabel": false,
108
41
  "hideTicks": false,
109
- "size": 50,
42
+ "size": "75",
110
43
  "gridLines": false,
111
44
  "enablePadding": false,
112
- "min": "",
113
- "max": "",
45
+ "min": "0.1",
46
+ "max": "3",
114
47
  "labelColor": "#333",
115
48
  "tickLabelColor": "#333",
116
49
  "tickColor": "#333",
117
- "rightHideAxis": false,
50
+ "rightHideAxis": true,
118
51
  "rightAxisSize": 0,
119
52
  "rightLabel": "",
120
53
  "rightLabelOffsetSize": 0,
121
54
  "rightAxisLabelColor": "#333",
122
55
  "rightAxisTickLabelColor": "#333",
123
56
  "rightAxisTickColor": "#333",
124
- "numTicks": "",
57
+ "numTicks": "6",
125
58
  "axisPadding": 0,
126
59
  "scalePadding": 10,
127
60
  "tickRotation": 0,
128
61
  "anchors": [],
129
62
  "shoMissingDataLabel": true,
130
63
  "showMissingDataLine": true,
131
- "categories": []
64
+ "categories": [],
65
+ "label": "Reported cases per 100,000 Population",
66
+ "type": "linear",
67
+ "dataKey": "Hispanic"
132
68
  },
133
69
  "boxplot": {
134
70
  "plots": [],
@@ -157,12 +93,43 @@
157
93
  "hasLine": false
158
94
  },
159
95
  "isLegendValue": false,
96
+ "barThickness": 0.35,
160
97
  "barHeight": 25,
161
98
  "barSpace": 15,
162
99
  "heights": {
163
100
  "vertical": 300,
164
101
  "horizontal": 750
165
102
  },
103
+ "xAxis": {
104
+ "sortDates": false,
105
+ "anchors": [],
106
+ "type": "categorical",
107
+ "showTargetLabel": true,
108
+ "targetLabel": "Target",
109
+ "hideAxis": false,
110
+ "hideLabel": false,
111
+ "hideTicks": false,
112
+ "size": 75,
113
+ "tickRotation": 0,
114
+ "min": "",
115
+ "max": "",
116
+ "labelColor": "#333",
117
+ "tickLabelColor": "#333",
118
+ "tickColor": "#333",
119
+ "numTicks": "",
120
+ "labelOffset": 0,
121
+ "axisPadding": 200,
122
+ "target": 0,
123
+ "maxTickRotation": 0,
124
+ "padding": 5,
125
+ "showYearsOnce": false,
126
+ "sortByRecentDate": false,
127
+ "dataKey": "Year",
128
+ "label": "Year",
129
+ "manual": true,
130
+ "axisBBox": 63.41333770751953,
131
+ "tickWidthMax": 39
132
+ },
166
133
  "table": {
167
134
  "label": "Data Table",
168
135
  "expanded": true,
@@ -174,12 +141,13 @@
174
141
  "showDownloadLinkBelow": true,
175
142
  "indexLabel": "",
176
143
  "download": true,
177
- "showVertical": true,
144
+ "showVertical": false,
178
145
  "dateDisplayFormat": "",
179
146
  "showMissingDataLabel": true,
180
147
  "showSuppressedSymbol": true,
181
148
  "show": true
182
149
  },
150
+ "orientation": "vertical",
183
151
  "color": "pinkpurple",
184
152
  "columns": {},
185
153
  "legend": {
@@ -202,18 +170,22 @@
202
170
  "hideSuppressedLabels": false,
203
171
  "hideSuppressionLink": false,
204
172
  "seriesHighlight": [],
205
- "style": "circles",
173
+ "style": "boxes",
206
174
  "subStyle": "linear blocks",
175
+ "groupBy": "",
207
176
  "shape": "circle",
208
177
  "tickRotation": "",
178
+ "order": "dataColumn",
209
179
  "hideBorder": {
210
180
  "side": false,
211
181
  "topBottom": true
212
182
  },
213
- "position": "right"
183
+ "position": "right",
184
+ "orderedValues": [],
185
+ "unified": true
214
186
  },
215
187
  "brush": {
216
- "height": 45,
188
+ "height": 25,
217
189
  "active": false
218
190
  },
219
191
  "exclusions": {
@@ -226,7 +198,7 @@
226
198
  "palette": "monochrome-1",
227
199
  "isPaletteReversed": false
228
200
  },
229
- "labels": true,
201
+ "labels": false,
230
202
  "dataFormat": {
231
203
  "commas": false,
232
204
  "prefix": "",
@@ -234,9 +206,10 @@
234
206
  "abbreviated": false,
235
207
  "bottomSuffix": "",
236
208
  "bottomPrefix": "",
237
- "bottomAbbreviated": false
209
+ "bottomAbbreviated": false,
210
+ "roundTo": "1",
211
+ "showPiePercent": true
238
212
  },
239
- "filters": [],
240
213
  "confidenceKeys": {},
241
214
  "visual": {
242
215
  "border": true,
@@ -252,8 +225,32 @@
252
225
  "highlightedBarValues": [],
253
226
  "series": [
254
227
  {
255
- "dataKey": "value",
256
- "type": "Bar",
228
+ "dataKey": "American Indian/Alaska Native",
229
+ "type": "Line",
230
+ "axis": "Left",
231
+ "tooltip": true
232
+ },
233
+ {
234
+ "dataKey": "Asian/Pacific Islander",
235
+ "type": "Line",
236
+ "axis": "Left",
237
+ "tooltip": true
238
+ },
239
+ {
240
+ "dataKey": "Black, non-Hispanic",
241
+ "type": "Line",
242
+ "axis": "Left",
243
+ "tooltip": true
244
+ },
245
+ {
246
+ "dataKey": "White, non-Hispanic",
247
+ "type": "Line",
248
+ "axis": "Left",
249
+ "tooltip": true
250
+ },
251
+ {
252
+ "dataKey": "Hispanic",
253
+ "type": "Line",
257
254
  "axis": "Left",
258
255
  "tooltip": true
259
256
  }
@@ -352,9 +349,69 @@
352
349
  },
353
350
  "data": []
354
351
  },
355
- "version": "4.25.1",
352
+ "errors": [],
353
+ "currentViewport": "lg",
354
+ "id": 4,
355
+ "category": "Charts",
356
+ "label": "Line",
357
+ "subType": "Line",
358
+ "icon": {
359
+ "key": null,
360
+ "ref": null,
361
+ "props": {},
362
+ "_owner": null
363
+ },
364
+ "content": "Present one or more data trends over time.",
365
+ "visualizationType": "Pie",
366
+ "datasets": {},
367
+ "activeVizButtonID": 4,
368
+ "data": [
369
+ {
370
+ "Year": "2007",
371
+ "American Indian/Alaska Native": "1.4",
372
+ "Asian/Pacific Islander": "0.9",
373
+ "Black, non-Hispanic": "2.3",
374
+ "White, non-Hispanic": "1",
375
+ "Hispanic": "50"
376
+ },
377
+ {
378
+ "Year": "2008",
379
+ "American Indian/Alaska Native": "1.8",
380
+ "Asian/Pacific Islander": "0.8",
381
+ "Black, non-Hispanic": "2.2",
382
+ "White, non-Hispanic": "0.9",
383
+ "Hispanic": "40"
384
+ }
385
+ ],
386
+ "dataFileName": "chart_data 2-6.csv",
387
+ "dataFileSourceType": "file",
388
+ "dataDescription": {
389
+ "horizontal": false,
390
+ "series": false
391
+ },
392
+ "version": "4.25.6",
393
+ "dynamicMarginTop": 0,
394
+ "formattedData": [
395
+ {
396
+ "Year": "2007",
397
+ "American Indian/Alaska Native": "1.4",
398
+ "Asian/Pacific Islander": "0.9",
399
+ "Black, non-Hispanic": "2.3",
400
+ "White, non-Hispanic": "1",
401
+ "Hispanic": "50"
402
+ },
403
+ {
404
+ "Year": "2008",
405
+ "American Indian/Alaska Native": "1.8",
406
+ "Asian/Pacific Islander": "0.8",
407
+ "Black, non-Hispanic": "2.2",
408
+ "White, non-Hispanic": "0.9",
409
+ "Hispanic": "40"
410
+ }
411
+ ],
412
+ "filters": [],
356
413
  "migrations": {
357
414
  "addColorMigration": true
358
415
  },
359
- "dynamicMarginTop": 0
360
- }
416
+ "allowLineToBarGraph": "__​undefined__"
417
+ }
@@ -3,13 +3,13 @@ import ConfigContext from '../../../ConfigContext'
3
3
  import './AnnotationDropdown.styles.css'
4
4
  import Icon from '@cdc/core/components/ui/Icon'
5
5
  import Annotation from '..'
6
- import { appFontSize } from '@cdc/core/helpers/cove/fontSettings'
6
+ import { APP_FONT_SIZE } from '@cdc/core/helpers/constants'
7
7
 
8
8
  const AnnotationDropdown = () => {
9
9
  const { currentViewport: viewport, config } = useContext(ConfigContext)
10
10
  const [expanded, setExpanded] = useState(false)
11
11
 
12
- const titleFontSize = ['sm', 'xs', 'xxs'].includes(viewport) ? '13px' : `${appFontSize}px`
12
+ const titleFontSize = ['sm', 'xs', 'xxs'].includes(viewport) ? '13px' : `${APP_FONT_SIZE}px`
13
13
 
14
14
  const {
15
15
  config: { annotations }
@@ -14,13 +14,28 @@ import { bisector } from 'd3-array'
14
14
  const AreaChart = props => {
15
15
  const { xScale, yScale, yMax, xMax, handleTooltipMouseOver, handleTooltipMouseOff, isDebug, children } = props
16
16
  // import data from context
17
- let { transformedData, config, handleLineType, parseDate, formatDate, formatNumber, seriesHighlight, colorScale, rawData, brushConfig } = useContext(ConfigContext)
17
+ let {
18
+ transformedData,
19
+ config,
20
+ handleLineType,
21
+ parseDate,
22
+ formatDate,
23
+ formatNumber,
24
+ seriesHighlight,
25
+ colorScale,
26
+ rawData,
27
+ brushConfig
28
+ } = useContext(ConfigContext)
18
29
  const data = config.brush?.active && brushConfig.data?.length ? brushConfig.data : transformedData
19
30
 
20
31
  if (!data) return
21
32
 
22
33
  const handleX = d => {
23
- return (isDateScale(config.xAxis) ? xScale(parseDate(d[config.xAxis.dataKey], false)) : xScale(d[config.xAxis.dataKey])) + (xScale.bandwidth ? xScale.bandwidth() / 2 : 0)
34
+ return (
35
+ (isDateScale(config.xAxis)
36
+ ? xScale(parseDate(d[config.xAxis.dataKey], false))
37
+ : xScale(d[config.xAxis.dataKey])) + (xScale.bandwidth ? xScale.bandwidth() / 2 : 0)
38
+ )
24
39
  }
25
40
 
26
41
  const handleY = (d, index, s = undefined) => {
@@ -41,8 +56,14 @@ const AreaChart = props => {
41
56
  })
42
57
 
43
58
  let curveType = allCurves[s.lineType]
44
- let transparentArea = config.legend.behavior === 'highlight' && seriesHighlight.length > 0 && seriesHighlight.indexOf(s.dataKey) === -1
45
- let displayArea = config.legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(s.dataKey) !== -1
59
+ let transparentArea =
60
+ config.legend.behavior === 'highlight' &&
61
+ seriesHighlight.length > 0 &&
62
+ seriesHighlight.indexOf(s.dataKey) === -1
63
+ let displayArea =
64
+ config.legend.behavior === 'highlight' ||
65
+ seriesHighlight.length === 0 ||
66
+ seriesHighlight.indexOf(s.dataKey) !== -1
46
67
 
47
68
  return (
48
69
  <React.Fragment key={index}>
@@ -74,7 +95,14 @@ const AreaChart = props => {
74
95
  </React.Fragment>
75
96
  )
76
97
  })}
77
- <Bar width={Number(xMax)} height={Number(yMax)} fill={'transparent'} fillOpacity={0.05} onMouseMove={e => handleTooltipMouseOver(e, rawData)} onMouseLeave={handleTooltipMouseOff} />
98
+ <Bar
99
+ width={Number(xMax)}
100
+ height={Number(yMax)}
101
+ fill={'transparent'}
102
+ fillOpacity={0.05}
103
+ onMouseMove={e => handleTooltipMouseOver(e, rawData)}
104
+ onMouseLeave={handleTooltipMouseOff}
105
+ />
78
106
  </Group>
79
107
  </ErrorBoundary>
80
108
  </svg>
@@ -7,7 +7,7 @@ import ConfigContext from '../../ConfigContext'
7
7
  import chroma from 'chroma-js'
8
8
  import createBarElement from '@cdc/core/components/createBarElement'
9
9
  import { getTextWidth } from '@cdc/core/helpers/getTextWidth'
10
- import { appFontSize } from '@cdc/core/helpers/cove/fontSettings'
10
+ import { APP_FONT_SIZE } from '@cdc/core/helpers/constants'
11
11
 
12
12
  const CategoricalYAxis = ({ yMax, leftSize, max, xMax }) => {
13
13
  const { config } = useContext(ConfigContext)
@@ -94,7 +94,7 @@ const CategoricalYAxis = ({ yMax, leftSize, max, xMax }) => {
94
94
  barStacks.map(barStack =>
95
95
  barStack.bars.map(bar => {
96
96
  const isLastIndex = config.yAxis.categories.length - 1 === barStack.index
97
- const textSize = appFontSize / 1.3
97
+ const textSize = APP_FONT_SIZE / 1.3
98
98
  const textColor = chroma(bar.color).luminance() < 0.4 ? '#fff' : '#000'
99
99
  const textWidth = getTextWidth(bar.key, `${textSize}px`)
100
100
  const displayText = Number(textWidth) < bar.width && bar.height > textSize
@@ -2,7 +2,6 @@ import React, { useContext } from 'react'
2
2
 
3
3
  // Local context and hooks
4
4
  import ConfigContext from '../../../ConfigContext'
5
- import { useBarChart } from '../../../hooks/useBarChart'
6
5
  import { useHighlightedBars } from '../../../hooks/useHighlightedBars'
7
6
 
8
7
  // VisX library imports
@@ -12,9 +11,11 @@ import { BarGroup } from '@visx/shape'
12
11
 
13
12
  // CDC core components and helpers
14
13
  import { getColorContrast, getContrastColor } from '@cdc/core/helpers/cove/accessibility'
14
+ import { APP_FONT_COLOR } from '@cdc/core/helpers/constants'
15
15
  import createBarElement from '@cdc/core/components/createBarElement'
16
16
  import { getBarConfig, testZeroValue } from '../helpers'
17
17
  import { getTextWidth } from '@cdc/core/helpers/getTextWidth'
18
+ import isNumber from '@cdc/core/helpers/isNumber'
18
19
 
19
20
  // Third party libraries
20
21
  import chroma from 'chroma-js'
@@ -24,29 +25,16 @@ import BarChartContext, { BarChartContextValues } from './context'
24
25
  import { ChartContext } from '../../../types/ChartContext'
25
26
  import _ from 'lodash'
26
27
  import { getBarData } from '../helpers/getBarData'
28
+ import { getHorizontalBarHeights } from '../helpers/getBarHeights'
27
29
 
28
30
  export const BarChartHorizontal = () => {
29
- const { xScale, yScale, yMax, seriesScale } = useContext<BarChartContextValues>(BarChartContext)
30
- const {
31
- transformedData: data,
32
- tableData,
33
- colorScale,
34
- seriesHighlight,
35
- config,
36
- formatNumber,
37
- formatDate,
38
- parseDate,
39
- setSharedFilter,
40
- isNumber
41
- } = useContext<ChartContext>(ConfigContext)
31
+ const { xScale, yScale, yMax, seriesScale, barChart } = useContext<BarChartContextValues>(BarChartContext)
42
32
  const {
43
33
  isHorizontal,
44
34
  barBorderWidth,
45
- updateBars,
46
35
  assignColorsToValues,
47
36
  section,
48
37
  isLabelBelowBar,
49
- displayNumbersOnBar,
50
38
  lollipopBarWidth,
51
39
  lollipopShapeSize,
52
40
  getHighlightedBarColorByValue,
@@ -55,7 +43,19 @@ export const BarChartHorizontal = () => {
55
43
  hoveredBar,
56
44
  onMouseLeaveBar,
57
45
  onMouseOverBar
58
- } = useBarChart()
46
+ } = barChart
47
+
48
+ const {
49
+ transformedData: data,
50
+ tableData,
51
+ colorScale,
52
+ seriesHighlight,
53
+ config,
54
+ formatNumber,
55
+ formatDate,
56
+ parseDate,
57
+ setSharedFilter
58
+ } = useContext<ChartContext>(ConfigContext)
59
59
 
60
60
  const { HighLightedBarUtils } = useHighlightedBars(config)
61
61
 
@@ -63,10 +63,6 @@ export const BarChartHorizontal = () => {
63
63
 
64
64
  const _data = getBarData(config, data, hasConfidenceInterval)
65
65
 
66
- const root = document.documentElement
67
-
68
- const coolGray90 = getComputedStyle(root).getPropertyValue('--cool-gray-90')
69
-
70
66
  return (
71
67
  config.visualizationSubType !== 'stacked' &&
72
68
  config.visualizationType === 'Bar' &&
@@ -85,7 +81,7 @@ export const BarChartHorizontal = () => {
85
81
  }}
86
82
  >
87
83
  {barGroups => {
88
- return updateBars(barGroups).map((barGroup, index) => (
84
+ return getHorizontalBarHeights(config, barGroups).map((barGroup, index) => (
89
85
  <Group
90
86
  className={`bar-group-${barGroup.index}-${barGroup.x0}--${index} ${config.orientation}`}
91
87
  key={`bar-group-${barGroup.index}-${barGroup.x0}--${index}`}
@@ -120,19 +116,19 @@ export const BarChartHorizontal = () => {
120
116
  const defaultBarWidth = Math.abs(xScale(bar.value) - xScale(scaleVal))
121
117
  const isPositiveBar = bar.value >= 0 && isNumber(bar.value)
122
118
 
123
- const {
124
- barWidthHorizontal: barWidth,
125
- isSuppressed,
126
- getAbsentDataLabel
127
- } = getBarConfig({ bar, defaultBarWidth, config, isNumber, isVertical: false })
128
119
  const barX = bar.value < 0 ? Math.abs(xScale(bar.value)) : xScale(scaleVal)
129
120
  const yAxisValue = formatNumber(bar.value, 'left')
130
121
  const xAxisValue =
131
122
  config.runtime[section].type === 'date' ? formatDate(parseDate(dataValue)) : dataValue
123
+ const {
124
+ barWidthHorizontal: barWidth,
125
+ isSuppressed,
126
+ absentDataLabel
127
+ } = getBarConfig({ bar, defaultBarWidth, config, isVertical: false, yAxisValue, barWidth: 0 })
132
128
 
133
129
  const barPosition = !isPositiveBar ? 'below' : 'above'
134
- const absentDataLabel = getAbsentDataLabel(yAxisValue)
135
- const barDefaultLabel = !config.yAxis.displayNumbersOnBar ? '' : yAxisValue
130
+
131
+ const barDefaultLabel = !config.yAxis.displayNumbersOnBar || absentDataLabel ? '' : yAxisValue
136
132
 
137
133
  // check if bar text/value string fits into each bars.
138
134
  const textWidth = getTextWidth(barDefaultLabel)
@@ -192,15 +188,20 @@ export const BarChartHorizontal = () => {
192
188
  ? highlightedBar.borderWidth
193
189
  : config.isLollipopChart
194
190
  ? 0
195
- : config.barHasBorder === 'true'
191
+ : config.barHasBorder === 'true' && !absentDataLabel && !isSuppressed
196
192
  ? barBorderWidth
197
193
  : 0
198
194
  const displaylollipopShape = testZeroValue(bar.value) ? 'none' : 'block'
195
+ const hideGroup =
196
+ (!isNumber(bar.value) && !config.general.showMissingDataLabel) ||
197
+ (String(bar.value) === '0' && !config.general.showZeroValueData)
198
+ ? 'none'
199
+ : 'block' // hide bar group if no value or zero value
199
200
 
200
201
  // update label color
201
202
  if (barColor && labelColor && textFits) {
202
- labelColor = getContrastColor('#000', barColor)
203
- let constrast = getColorContrast('#000', barColor)
203
+ labelColor = getContrastColor(APP_FONT_COLOR, barColor)
204
+ let constrast = getColorContrast(APP_FONT_COLOR, barColor)
204
205
  const contrastLevel = 7
205
206
  if (constrast < contrastLevel) {
206
207
  labelColor = '#fff'
@@ -227,10 +228,9 @@ export const BarChartHorizontal = () => {
227
228
  const d = datum[config.confidenceKeys[position]]
228
229
  return xScale(d)
229
230
  })
230
- // End Confidence Interval Variables
231
231
 
232
232
  return (
233
- <Group key={`${barGroup.index}--${index}`}>
233
+ <Group display={hideGroup} key={`${barGroup.index}--${index}`}>
234
234
  <Group key={`bar-sub-group-${barGroup.index}-${barGroup.x0}-${barY}--${index}`}>
235
235
  {createBarElement({
236
236
  config: config,
@@ -244,7 +244,7 @@ export const BarChartHorizontal = () => {
244
244
  height: numbericBarHeight,
245
245
  x: barX,
246
246
  y: barHeight * bar.index,
247
- onMouseOver: () => onMouseOverBar(xAxisValue, bar.key),
247
+ onMouseOver: e => onMouseOverBar(xAxisValue, bar.key, e, data),
248
248
  onMouseLeave: onMouseLeaveBar,
249
249
  tooltipHtml: tooltip,
250
250
  tooltipId: `cdc-open-viz-tooltip-${config.runtime.uniqueId}`,
@@ -261,6 +261,7 @@ export const BarChartHorizontal = () => {
261
261
  display: displayBar ? 'block' : 'none'
262
262
  }
263
263
  })}
264
+
264
265
  {config.preliminaryData?.map((pd, index) => {
265
266
  // check if user selected column
266
267
  const selectedSuppressionColumn = !pd.column || pd.column === bar.key
@@ -387,10 +388,10 @@ export const BarChartHorizontal = () => {
387
388
  <animate attributeName='height' values={`0, ${lollipopShapeSize}`} dur='2.5s' />
388
389
  </rect>
389
390
  )}
390
- {hasConfidenceInterval && (
391
+ {hasConfidenceInterval && displayBar && (
391
392
  <path
392
393
  key={`confidence-interval-h-${yPos}-${datum[config.runtime.originalXAxis.dataKey]}`}
393
- stroke={coolGray90}
394
+ stroke={APP_FONT_COLOR}
394
395
  strokeWidth='px'
395
396
  d={`
396
397
  M${lowerPos} ${yPos - tickWidth}