@cdc/chart 4.25.3-6 → 4.25.5-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 (84) hide show
  1. package/dist/cdcchart-1a1724a1.es.js +4886 -0
  2. package/dist/cdcchart.js +50347 -75521
  3. package/index.html +1 -0
  4. package/package.json +22 -27
  5. package/src/CdcChart.tsx +1 -22
  6. package/src/CdcChartComponent.tsx +35 -21
  7. package/src/_stories/Chart.CI.stories.tsx +43 -0
  8. package/src/_stories/Chart.DynamicSeries.stories.tsx +68 -49
  9. package/src/_stories/Chart.Legend.Gradient.stories.tsx +6 -0
  10. package/src/_stories/Chart.stories.tsx +7 -16
  11. package/src/_stories/_mock/bar_chart_ci_labels.json +620 -0
  12. package/src/_stories/_mock/barchart_labels.mock.json +612 -0
  13. package/src/_stories/_mock/dynamic_series_bar_config.json +1 -1
  14. package/src/_stories/_mock/dynamic_series_suppression_mock.json +610 -0
  15. package/{examples/private/line-issue.json → src/_stories/_mock/legend_groupBy_mock.json} +46 -69
  16. package/src/components/Annotations/components/AnnotationDropdown.tsx +2 -2
  17. package/src/components/AreaChart/components/AreaChart.jsx +33 -5
  18. package/src/components/Axis/Categorical.Axis.tsx +2 -2
  19. package/src/components/BarChart/components/BarChart.Horizontal.tsx +51 -41
  20. package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +19 -9
  21. package/src/components/BarChart/components/BarChart.StackedVertical.tsx +20 -9
  22. package/src/components/BarChart/components/BarChart.Vertical.tsx +48 -31
  23. package/src/components/BarChart/components/{BarChart.jsx → BarChart.tsx} +23 -5
  24. package/src/components/BarChart/components/context.tsx +20 -2
  25. package/src/components/BarChart/helpers/getBarHeights.ts +47 -0
  26. package/src/components/BarChart/helpers/index.ts +5 -2
  27. package/src/components/BarChart/helpers/tests/getBarHeights.test.ts +83 -0
  28. package/src/{hooks → components/BarChart/helpers}/useBarChart.ts +11 -47
  29. package/src/components/BoxPlot/BoxPlot.tsx +2 -1
  30. package/src/components/DeviationBar.jsx +2 -1
  31. package/src/components/EditorPanel/EditorPanel.tsx +60 -24
  32. package/src/components/EditorPanel/components/Panels/Panel.General.tsx +34 -34
  33. package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +51 -25
  34. package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +10 -3
  35. package/src/components/EditorPanel/helpers/updateFieldRankByValue.ts +4 -3
  36. package/src/components/EditorPanel/useEditorPermissions.ts +1 -4
  37. package/src/components/ForestPlot/ForestPlot.tsx +2 -2
  38. package/src/components/Legend/Legend.Component.tsx +69 -58
  39. package/src/components/Legend/Legend.Suppression.tsx +12 -22
  40. package/src/components/Legend/Legend.tsx +3 -1
  41. package/src/components/Legend/LegendGroup/LegendGroup.styles.css +40 -0
  42. package/src/components/Legend/LegendGroup/LegendGroup.tsx +103 -0
  43. package/src/components/Legend/LegendGroup/index.tsx +3 -0
  44. package/src/components/Legend/helpers/createFormatLabels.tsx +28 -0
  45. package/src/components/LineChart/LineChartProps.ts +3 -1
  46. package/src/components/LineChart/components/LineChart.Circle.tsx +77 -119
  47. package/src/components/LineChart/helpers.ts +133 -56
  48. package/src/components/LineChart/index.tsx +125 -60
  49. package/src/components/LinearChart.tsx +74 -115
  50. package/src/components/PairedBarChart.jsx +3 -2
  51. package/src/components/PieChart/PieChart.tsx +71 -91
  52. package/src/components/ScatterPlot/ScatterPlot.jsx +5 -0
  53. package/src/components/Sparkline/components/SparkLine.tsx +80 -18
  54. package/src/components/ZoomBrush.tsx +4 -4
  55. package/src/data/initial-state.js +4 -2
  56. package/src/helpers/countNumOfTicks.ts +1 -1
  57. package/src/helpers/dataHelpers.ts +31 -0
  58. package/src/helpers/sizeHelpers.ts +23 -0
  59. package/src/hooks/useMinMax.ts +21 -28
  60. package/src/hooks/useRightAxis.ts +4 -2
  61. package/src/hooks/useScales.ts +12 -14
  62. package/src/hooks/useTooltip.tsx +204 -203
  63. package/src/index.jsx +2 -2
  64. package/src/scss/main.scss +13 -6
  65. package/src/store/chart.actions.ts +1 -1
  66. package/src/types/ChartConfig.ts +7 -1
  67. package/LICENSE +0 -201
  68. package/examples/private/DEV-8850-2.json +0 -493
  69. package/examples/private/DEV-9822.json +0 -574
  70. package/examples/private/DEV-9840.json +0 -553
  71. package/examples/private/DEV-9850-3.json +0 -461
  72. package/examples/private/chart.json +0 -1084
  73. package/examples/private/ci_formatted.json +0 -202
  74. package/examples/private/ci_issue.json +0 -3016
  75. package/examples/private/completed.json +0 -634
  76. package/examples/private/dem-data-long.csv +0 -20
  77. package/examples/private/dem-data-long.json +0 -36
  78. package/examples/private/demographic_data.csv +0 -157
  79. package/examples/private/demographic_data.json +0 -2654
  80. package/examples/private/demographic_dynamic.json +0 -443
  81. package/examples/private/demographic_standard.json +0 -560
  82. package/examples/private/ehdi.json +0 -29939
  83. package/examples/private/not-loading.json +0 -360
  84. package/examples/private/test.json +0 -493
@@ -5,8 +5,8 @@
5
5
  "chartMessage": {
6
6
  "noData": "No Data Available"
7
7
  },
8
- "title": "",
9
- "showTitle": false,
8
+ "title": "Legend Group in Bar Chart",
9
+ "showTitle": true,
10
10
  "showDownloadMediaButton": false,
11
11
  "theme": "theme-blue",
12
12
  "animate": false,
@@ -127,8 +127,8 @@
127
127
  "dataKey": "Year",
128
128
  "label": "Year",
129
129
  "manual": true,
130
- "axisBBox": 52.939998626708984,
131
- "tickWidthMax": 41
130
+ "axisBBox": 62.779998779296875,
131
+ "tickWidthMax": 39
132
132
  },
133
133
  "table": {
134
134
  "label": "Data Table",
@@ -172,12 +172,16 @@
172
172
  "seriesHighlight": [],
173
173
  "style": "boxes",
174
174
  "subStyle": "linear blocks",
175
+ "groupBy": "group",
176
+ "shape": "circle",
175
177
  "tickRotation": "",
176
178
  "hideBorder": {
177
179
  "side": false,
178
- "topBottom": true
180
+ "topBottom": false
179
181
  },
180
- "position": "top"
182
+ "position": "bottom",
183
+ "subGroup": "group",
184
+ "labelAlignment": "left"
181
185
  },
182
186
  "brush": {
183
187
  "height": 25,
@@ -210,7 +214,9 @@
210
214
  "accent": true,
211
215
  "background": true,
212
216
  "verticalHoverLine": false,
213
- "horizontalHoverLine": false
217
+ "horizontalHoverLine": false,
218
+ "lineDatapointSymbol": "none",
219
+ "maximumShapeAmount": 7
214
220
  },
215
221
  "useLogScale": false,
216
222
  "filterBehavior": "Filter Change",
@@ -354,7 +360,7 @@
354
360
  "_owner": null
355
361
  },
356
362
  "content": "Present one or more data trends over time.",
357
- "visualizationType": "Line",
363
+ "visualizationType": "Bar",
358
364
  "datasets": {},
359
365
  "activeVizButtonID": 4,
360
366
  "data": [
@@ -362,136 +368,107 @@
362
368
  "Year": "2007",
363
369
  "American Indian/Alaska Native": "1.4",
364
370
  "Asian/Pacific Islander": "0.9",
365
- "Black, non-Hispanic": "2.3",
366
- "White, non-Hispanic": "1",
367
- "Hispanic": "1"
371
+ "group": "Main Group"
368
372
  },
369
373
  {
370
374
  "Year": "2008",
371
375
  "American Indian/Alaska Native": "1.8",
372
376
  "Asian/Pacific Islander": "0.8",
373
- "Black, non-Hispanic": "2.2",
374
- "White, non-Hispanic": "0.9",
375
- "Hispanic": "0.8"
377
+ "group": "Main Group"
376
378
  },
377
379
  {
378
380
  "Year": "2009",
379
381
  "American Indian/Alaska Native": "1",
380
382
  "Asian/Pacific Islander": "0.7",
381
- "Black, non-Hispanic": "1.7",
382
- "White, non-Hispanic": "0.8",
383
- "Hispanic": "0.7"
383
+ "group": "Main Group"
384
384
  },
385
385
  {
386
386
  "Year": "2010",
387
387
  "American Indian/Alaska Native": "1.1",
388
388
  "Asian/Pacific Islander": "0.6",
389
- "Black, non-Hispanic": "1.7",
390
- "White, non-Hispanic": "0.8",
391
- "Hispanic": "0.6"
389
+ "group": "Main Group"
392
390
  },
393
391
  {
394
392
  "Year": "2011",
395
- "American Indian/Alaska Native": "0.5",
396
- "Asian/Pacific Islander": "0.4",
397
393
  "Black, non-Hispanic": "1.4",
398
394
  "White, non-Hispanic": "0.8",
399
- "Hispanic": "0.4"
395
+ "group": "Second Group"
400
396
  },
401
397
  {
402
398
  "Year": "2012",
403
- "American Indian/Alaska Native": "0.7",
404
- "Asian/Pacific Islander": "0.4",
405
399
  "Black, non-Hispanic": "1.1",
406
400
  "White, non-Hispanic": "0.8",
407
- "Hispanic": "0.4"
401
+ "group": "Second Group"
408
402
  },
409
403
  {
410
404
  "Year": "2013",
411
- "American Indian/Alaska Native": "0.7",
412
- "Asian/Pacific Islander": "0.3",
413
- "Black, non-Hispanic": "0.9",
414
405
  "White, non-Hispanic": "0.9",
415
- "Hispanic": "0.4"
406
+ "group": "Second Group"
416
407
  },
417
408
  {
418
409
  "Year": "2014",
419
- "American Indian/Alaska Native": "0.8",
420
- "Asian/Pacific Islander": "0.3",
421
- "Black, non-Hispanic": "0.8",
422
410
  "White, non-Hispanic": "0.9",
423
- "Hispanic": "0.3"
411
+ "group": "Second Group"
424
412
  },
425
413
  {
426
414
  "Year": "2015",
427
415
  "American Indian/Alaska Native": "0.7",
428
- "Asian/Pacific Islander": "0.4",
429
- "Black, non-Hispanic": "1",
430
- "White, non-Hispanic": "1.1",
431
- "Hispanic": "0.3"
416
+ "Hispanic": "0.3",
417
+ "group": "Third Group"
432
418
  },
433
419
  {
434
420
  "Year": "2016",
435
421
  "American Indian/Alaska Native": "0.5",
436
- "Asian/Pacific Islander": "0.3",
437
- "Black, non-Hispanic": "0.9",
438
- "White, non-Hispanic": "1",
439
- "Hispanic": "0.3"
422
+ "Hispanic": "0.3",
423
+ "group": "Third Group"
440
424
  },
441
425
  {
442
426
  "Year": "2017",
443
427
  "American Indian/Alaska Native": "0.7",
444
- "Asian/Pacific Islander": "0.3",
445
- "Black, non-Hispanic": "1",
446
- "White, non-Hispanic": "1.1",
447
- "Hispanic": "0.3"
428
+ "Hispanic": "0.3",
429
+ "group": "Third Group"
448
430
  },
449
431
  {
450
432
  "Year": "2018",
451
433
  "American Indian/Alaska Native": "0.9",
452
- "Asian/Pacific Islander": "0.3",
453
- "Black, non-Hispanic": "1",
454
- "White, non-Hispanic": "1",
455
- "Hispanic": "0.4"
434
+ "Hispanic": "0.4",
435
+ "group": "Third Group"
456
436
  },
457
437
  {
458
438
  "Year": "2019",
459
439
  "American Indian/Alaska Native": "0.6",
460
- "Asian/Pacific Islander": "0.3",
461
- "Black, non-Hispanic": "0.9",
462
- "White, non-Hispanic": "1",
463
- "Hispanic": "0.4"
440
+ "Hispanic": "0.4",
441
+ "group": "Third Group"
464
442
  },
465
443
  {
466
444
  "Year": "2020",
467
445
  "American Indian/Alaska Native": "0.4",
468
- "Asian/Pacific Islander": "0.2",
469
- "Black, non-Hispanic": "0.7",
470
- "White, non-Hispanic": "0.7",
471
- "Hispanic": "0.3"
446
+ "Hispanic": "0.3",
447
+ "group": "Third Group"
472
448
  },
473
449
  {
474
450
  "Year": "2021",
475
451
  "American Indian/Alaska Native": "0.4",
476
- "Asian/Pacific Islander": "0.2",
477
- "Black, non-Hispanic": "0.9",
478
- "White, non-Hispanic": "0.6",
479
- "Hispanic": "0.4"
452
+ "Hispanic": "0.4",
453
+ "group": "Third Group"
480
454
  },
481
455
  {
482
456
  "Year": "2022",
483
457
  "American Indian/Alaska Native": "0.4",
484
- "Asian/Pacific Islander": "0.3",
485
458
  "Black, non-Hispanic": "1",
486
- "White, non-Hispanic": "0.6",
487
- "Hispanic": "0.4"
459
+ "group": "Fourth Group"
488
460
  }
489
461
  ],
490
462
  "dataFileName": "chart_data 2-6.csv",
491
463
  "dataFileSourceType": "file",
492
464
  "dataDescription": {
493
- "horizontal": true
465
+ "horizontal": false,
466
+ "series": false
494
467
  },
495
- "version": "4.24.10",
496
- "dynamicMarginTop": 0
497
- }
468
+ "version": "4.25.1",
469
+ "dynamicMarginTop": 0,
470
+ "filters": [],
471
+ "migrations": {
472
+ "addColorMigration": true
473
+ }
474
+ }
@@ -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,18 +43,30 @@ 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
 
62
- const hasConfidenceInterval = Object.keys(config.confidenceKeys).length > 0
62
+ const hasConfidenceInterval =
63
+ config.confidenceKeys.upper &&
64
+ config.confidenceKeys.lower &&
65
+ config.confidenceKeys.upper !== '' &&
66
+ config.confidenceKeys.lower !== ''
63
67
 
64
68
  const _data = getBarData(config, data, hasConfidenceInterval)
65
69
 
66
- const root = document.documentElement
67
-
68
- const coolGray90 = getComputedStyle(root).getPropertyValue('--cool-gray-90')
69
-
70
70
  return (
71
71
  config.visualizationSubType !== 'stacked' &&
72
72
  config.visualizationType === 'Bar' &&
@@ -85,7 +85,7 @@ export const BarChartHorizontal = () => {
85
85
  }}
86
86
  >
87
87
  {barGroups => {
88
- return updateBars(barGroups).map((barGroup, index) => (
88
+ return getHorizontalBarHeights(config, barGroups).map((barGroup, index) => (
89
89
  <Group
90
90
  className={`bar-group-${barGroup.index}-${barGroup.x0}--${index} ${config.orientation}`}
91
91
  key={`bar-group-${barGroup.index}-${barGroup.x0}--${index}`}
@@ -120,19 +120,19 @@ export const BarChartHorizontal = () => {
120
120
  const defaultBarWidth = Math.abs(xScale(bar.value) - xScale(scaleVal))
121
121
  const isPositiveBar = bar.value >= 0 && isNumber(bar.value)
122
122
 
123
- const {
124
- barWidthHorizontal: barWidth,
125
- isSuppressed,
126
- getAbsentDataLabel
127
- } = getBarConfig({ bar, defaultBarWidth, config, isNumber, isVertical: false })
128
123
  const barX = bar.value < 0 ? Math.abs(xScale(bar.value)) : xScale(scaleVal)
129
124
  const yAxisValue = formatNumber(bar.value, 'left')
130
125
  const xAxisValue =
131
126
  config.runtime[section].type === 'date' ? formatDate(parseDate(dataValue)) : dataValue
127
+ const {
128
+ barWidthHorizontal: barWidth,
129
+ isSuppressed,
130
+ absentDataLabel
131
+ } = getBarConfig({ bar, defaultBarWidth, config, isVertical: false, yAxisValue, barWidth: 0 })
132
132
 
133
133
  const barPosition = !isPositiveBar ? 'below' : 'above'
134
- const absentDataLabel = getAbsentDataLabel(yAxisValue)
135
- const barDefaultLabel = !config.yAxis.displayNumbersOnBar ? '' : yAxisValue
134
+
135
+ const barDefaultLabel = !config.yAxis.displayNumbersOnBar || absentDataLabel ? '' : yAxisValue
136
136
 
137
137
  // check if bar text/value string fits into each bars.
138
138
  const textWidth = getTextWidth(barDefaultLabel)
@@ -159,7 +159,7 @@ export const BarChartHorizontal = () => {
159
159
  let yAxisTooltip = config.runtime.yAxis.label
160
160
  ? `${config.runtime.yAxis.label}: ${xAxisValue}`
161
161
  : xAxisValue
162
- const additionalColTooltip = getAdditionalColumn(hoveredBar)
162
+ const additionalColTooltip = getAdditionalColumn(bar.key, hoveredBar)
163
163
  const tooltipBody = `${config.runtime.seriesLabels[bar.key]}: ${yAxisValue}`
164
164
  const tooltip = `<ul>
165
165
  <li class="tooltip-heading"">${yAxisTooltip}</li>
@@ -192,15 +192,20 @@ export const BarChartHorizontal = () => {
192
192
  ? highlightedBar.borderWidth
193
193
  : config.isLollipopChart
194
194
  ? 0
195
- : config.barHasBorder === 'true'
195
+ : config.barHasBorder === 'true' && !absentDataLabel && !isSuppressed
196
196
  ? barBorderWidth
197
197
  : 0
198
198
  const displaylollipopShape = testZeroValue(bar.value) ? 'none' : 'block'
199
+ const hideGroup =
200
+ (!isNumber(bar.value) && !config.general.showMissingDataLabel) ||
201
+ (String(bar.value) === '0' && !config.general.showZeroValueData)
202
+ ? 'none'
203
+ : 'block' // hide bar group if no value or zero value
199
204
 
200
205
  // update label color
201
206
  if (barColor && labelColor && textFits) {
202
- labelColor = getContrastColor('#000', barColor)
203
- let constrast = getColorContrast('#000', barColor)
207
+ labelColor = getContrastColor(APP_FONT_COLOR, barColor)
208
+ let constrast = getColorContrast(APP_FONT_COLOR, barColor)
204
209
  const contrastLevel = 7
205
210
  if (constrast < contrastLevel) {
206
211
  labelColor = '#fff'
@@ -227,10 +232,11 @@ export const BarChartHorizontal = () => {
227
232
  const d = datum[config.confidenceKeys[position]]
228
233
  return xScale(d)
229
234
  })
230
- // End Confidence Interval Variables
235
+ const labelX = bar.y
236
+ const overlapWithCI = hasConfidenceInterval && labelX >= lowerPos && labelX <= upperPos
231
237
 
232
238
  return (
233
- <Group key={`${barGroup.index}--${index}`}>
239
+ <Group display={hideGroup} key={`${barGroup.index}--${index}`}>
234
240
  <Group key={`bar-sub-group-${barGroup.index}-${barGroup.x0}-${barY}--${index}`}>
235
241
  {createBarElement({
236
242
  config: config,
@@ -244,7 +250,7 @@ export const BarChartHorizontal = () => {
244
250
  height: numbericBarHeight,
245
251
  x: barX,
246
252
  y: barHeight * bar.index,
247
- onMouseOver: () => onMouseOverBar(xAxisValue, bar.key),
253
+ onMouseOver: e => onMouseOverBar(xAxisValue, bar.key, e, data),
248
254
  onMouseLeave: onMouseLeaveBar,
249
255
  tooltipHtml: tooltip,
250
256
  tooltipId: `cdc-open-viz-tooltip-${config.runtime.uniqueId}`,
@@ -305,8 +311,12 @@ export const BarChartHorizontal = () => {
305
311
  display={displayBar ? 'block' : 'none'}
306
312
  x={bar.y}
307
313
  opacity={transparentBar ? 0.5 : 1}
308
- y={config.barHeight / 2 + config.barHeight * bar.index}
309
- fill={labelColor}
314
+ y={
315
+ hasConfidenceInterval && overlapWithCI
316
+ ? config.barHeight * bar.index
317
+ : config.barHeight / 2 + config.barHeight * bar.index
318
+ }
319
+ fill={hasConfidenceInterval && overlapWithCI ? '#000' : labelColor}
310
320
  dx={textPadding}
311
321
  verticalAnchor='middle'
312
322
  textAnchor={textAnchor}
@@ -387,10 +397,10 @@ export const BarChartHorizontal = () => {
387
397
  <animate attributeName='height' values={`0, ${lollipopShapeSize}`} dur='2.5s' />
388
398
  </rect>
389
399
  )}
390
- {hasConfidenceInterval && (
400
+ {hasConfidenceInterval && displayBar && (
391
401
  <path
392
402
  key={`confidence-interval-h-${yPos}-${datum[config.runtime.originalXAxis.dataKey]}`}
393
- stroke={coolGray90}
403
+ stroke={APP_FONT_COLOR}
394
404
  strokeWidth='px'
395
405
  d={`
396
406
  M${lowerPos} ${yPos - tickWidth}
@@ -1,10 +1,10 @@
1
1
  import React, { useContext } from 'react'
2
2
  import ConfigContext from '../../../ConfigContext'
3
- import { useBarChart } from '../../../hooks/useBarChart'
4
3
  import { BarStackHorizontal } from '@visx/shape'
5
4
  import { Group } from '@visx/group'
6
5
  import { Text } from '@visx/text'
7
6
  import { getColorContrast, getContrastColor } from '@cdc/core/helpers/cove/accessibility'
7
+ import { APP_FONT_COLOR } from '@cdc/core/helpers/constants'
8
8
  import { getTextWidth } from '@cdc/core/helpers/getTextWidth'
9
9
 
10
10
  // types
@@ -12,9 +12,10 @@ import BarChartContext, { type BarChartContextValues } from './context'
12
12
  import { type ChartContext } from '../../../types/ChartContext'
13
13
 
14
14
  import createBarElement from '@cdc/core/components/createBarElement'
15
+ import { getHorizontalBarHeights } from '../helpers/getBarHeights'
15
16
 
16
17
  const BarChartStackedHorizontal = () => {
17
- const { yMax, yScale, xScale } = useContext<BarChartContextValues>(BarChartContext)
18
+ const { yMax, yScale, xScale, barChart } = useContext<BarChartContextValues>(BarChartContext)
18
19
 
19
20
  // prettier-ignore
20
21
  const {
@@ -29,8 +30,17 @@ const BarChartStackedHorizontal = () => {
29
30
  transformedData: data
30
31
  } = useContext<ChartContext>(ConfigContext)
31
32
 
32
- // prettier-ignore
33
- const { barBorderWidth, displayNumbersOnBar, getAdditionalColumn, hoveredBar, isHorizontal, isLabelBelowBar, onMouseLeaveBar, onMouseOverBar, updateBars, barStackedSeriesKeys } = useBarChart()
33
+ const {
34
+ barBorderWidth,
35
+ displayNumbersOnBar,
36
+ getAdditionalColumn,
37
+ hoveredBar,
38
+ isHorizontal,
39
+ isLabelBelowBar,
40
+ onMouseLeaveBar,
41
+ onMouseOverBar,
42
+ barStackedSeriesKeys
43
+ } = barChart
34
44
 
35
45
  const { orientation, visualizationSubType } = config
36
46
  return (
@@ -49,7 +59,7 @@ const BarChartStackedHorizontal = () => {
49
59
  >
50
60
  {barStacks =>
51
61
  barStacks.map(barStack =>
52
- updateBars(barStack.bars).map((bar, index) => {
62
+ getHorizontalBarHeights(config, barStack.bars).map((bar, index) => {
53
63
  const transparentBar =
54
64
  config.legend.behavior === 'highlight' &&
55
65
  seriesHighlight.length > 0 &&
@@ -60,8 +70,8 @@ const BarChartStackedHorizontal = () => {
60
70
  seriesHighlight.indexOf(bar.key) !== -1
61
71
  config.barHeight = Number(config.barHeight)
62
72
  let barColor = colorScale(config.runtime.seriesLabels[bar.key])
63
- let labelColor = getContrastColor('#000', barColor)
64
- let constrast = getColorContrast('#000', barColor)
73
+ let labelColor = getContrastColor(APP_FONT_COLOR, barColor)
74
+ let constrast = getColorContrast(APP_FONT_COLOR, barColor)
65
75
  const contrastLevel = 7
66
76
  if (constrast < contrastLevel) {
67
77
  labelColor = '#fff'
@@ -76,7 +86,7 @@ const BarChartStackedHorizontal = () => {
76
86
  ? `${config.runtime.yAxis.label}: ${yAxisValue}`
77
87
  : yAxisValue
78
88
  const textWidth = getTextWidth(xAxisValue)
79
- const additionalColTooltip = getAdditionalColumn(hoveredBar)
89
+ const additionalColTooltip = getAdditionalColumn(bar.key, hoveredBar)
80
90
  const tooltipBody = `${config.runtime.seriesLabels[bar.key]}: ${xAxisValue}`
81
91
  const tooltip = `<ul>
82
92
  <li class="tooltip-heading"">${yAxisTooltip}</li>
@@ -100,7 +110,7 @@ const BarChartStackedHorizontal = () => {
100
110
  height: bar.height,
101
111
  x: bar.x,
102
112
  y: bar.y,
103
- onMouseOver: () => onMouseOverBar(yAxisValue, bar.key),
113
+ onMouseOver: e => onMouseOverBar(yAxisValue, bar.key, e, data),
104
114
  onMouseLeave: onMouseLeaveBar,
105
115
  tooltipHtml: tooltip,
106
116
  tooltipId: `cdc-open-viz-tooltip-${config.runtime.uniqueId}`,