@cdc/chart 4.22.10 → 4.22.11

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 (72) hide show
  1. package/README.md +5 -5
  2. package/dist/cdcchart.js +4 -4
  3. package/examples/age-adjusted-rates.json +1486 -1218
  4. package/examples/case-rate-example-config.json +1 -1
  5. package/examples/covid-confidence-example-config.json +33 -33
  6. package/examples/covid-example-config.json +34 -34
  7. package/examples/covid-example-data-confidence.json +30 -30
  8. package/examples/covid-example-data.json +20 -20
  9. package/examples/cutoff-example-config.json +36 -36
  10. package/examples/cutoff-example-data.json +36 -36
  11. package/examples/date-exclusions-config.json +1 -1
  12. package/examples/dynamic-legends.json +124 -124
  13. package/examples/gallery/bar-chart-horizontal/horizontal-bar-chart-with-numbers-on-bar.json +191 -197
  14. package/examples/gallery/bar-chart-horizontal/horizontal-bar-chart.json +230 -240
  15. package/examples/gallery/bar-chart-horizontal/horizontal-stacked.json +239 -247
  16. package/examples/gallery/bar-chart-vertical/combo-line-chart.json +136 -136
  17. package/examples/gallery/bar-chart-vertical/vertical-bar-chart-categorical.json +79 -79
  18. package/examples/gallery/bar-chart-vertical/vertical-bar-chart-stacked.json +80 -80
  19. package/examples/gallery/bar-chart-vertical/vertical-bar-chart-with-confidence.json +67 -67
  20. package/examples/gallery/bar-chart-vertical/vertical-bar-chart.json +110 -110
  21. package/examples/gallery/lollipop/lollipop-style-horizontal.json +215 -219
  22. package/examples/gallery/paired-bar/paired-bar-chart.json +195 -195
  23. package/examples/horizontal-chart.json +35 -35
  24. package/examples/horizontal-stacked-bar-chart.json +34 -34
  25. package/examples/line-chart.json +75 -75
  26. package/examples/paired-bar-data.json +16 -14
  27. package/examples/paired-bar-example.json +48 -48
  28. package/examples/paired-bar-formatted.json +36 -36
  29. package/examples/planet-chart-horizontal-example-config.json +33 -33
  30. package/examples/planet-combo-example-config.json +34 -31
  31. package/examples/planet-example-config.json +35 -33
  32. package/examples/planet-example-data.json +56 -56
  33. package/examples/planet-pie-example-config.json +28 -28
  34. package/examples/private/filters.json +170 -0
  35. package/examples/private/line-test-data.json +21 -21
  36. package/examples/private/line-test-two.json +209 -215
  37. package/examples/private/line-test.json +101 -101
  38. package/examples/private/new.json +48800 -0
  39. package/examples/private/shawn.json +1105 -1295
  40. package/examples/private/test.json +10123 -10123
  41. package/examples/private/yaxis-test.json +4 -3
  42. package/examples/private/yaxis.json +26 -26
  43. package/examples/stacked-vertical-bar-example.json +1 -1
  44. package/examples/temp-example-config.json +61 -54
  45. package/examples/temp-example-data.json +1 -1
  46. package/package.json +2 -2
  47. package/src/CdcChart.tsx +339 -380
  48. package/src/components/BarChart.tsx +425 -469
  49. package/src/components/DataTable.tsx +164 -195
  50. package/src/components/EditorPanel.js +1009 -710
  51. package/src/components/Legend.js +279 -329
  52. package/src/components/LineChart.tsx +90 -79
  53. package/src/components/LinearChart.tsx +376 -434
  54. package/src/components/PairedBarChart.tsx +197 -213
  55. package/src/components/PieChart.tsx +95 -151
  56. package/src/components/SparkLine.js +179 -201
  57. package/src/components/useIntersectionObserver.tsx +17 -20
  58. package/src/context.tsx +3 -3
  59. package/src/data/initial-state.js +37 -16
  60. package/src/hooks/useActiveElement.js +13 -13
  61. package/src/hooks/useChartClasses.js +34 -28
  62. package/src/hooks/useColorPalette.ts +56 -63
  63. package/src/hooks/useLegendClasses.js +18 -10
  64. package/src/hooks/useReduceData.ts +62 -78
  65. package/src/hooks/useRightAxis.js +25 -0
  66. package/src/hooks/useTopAxis.js +6 -0
  67. package/src/index.html +45 -45
  68. package/src/index.tsx +13 -16
  69. package/src/scss/DataTable.scss +5 -4
  70. package/src/scss/editor-panel.scss +71 -69
  71. package/src/scss/main.scss +157 -114
  72. package/src/scss/variables.scss +1 -1
@@ -1,623 +1,579 @@
1
- import React, { useContext, useState, useEffect } from 'react';
1
+ import React, { useContext, useState, useEffect } from 'react'
2
+ import { Group } from '@visx/group'
3
+ import { BarGroup, BarStack } from '@visx/shape'
4
+ import { Text } from '@visx/text'
5
+ import chroma from 'chroma-js'
6
+ import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
7
+ import Context from '../context'
8
+ import ReactTooltip from 'react-tooltip'
9
+ import { BarStackHorizontal } from '@visx/shape'
2
10
 
3
- import { Group } from '@visx/group';
4
- import { BarGroup, BarStack } from '@visx/shape';
5
- import { Text } from '@visx/text';
6
- import chroma from 'chroma-js';
7
-
8
- import ErrorBoundary from '@cdc/core/components/ErrorBoundary';
9
-
10
- import Context from '../context';
11
- import ReactTooltip from 'react-tooltip';
12
- import { BarStackHorizontal } from '@visx/shape';
11
+ export default function BarChart({ xScale, yScale, seriesScale, xMax, yMax, getXAxisData, getYAxisData, animatedChart, visible }) {
12
+ const { transformedData: data, colorScale, seriesHighlight, config, formatNumber, updateConfig, setParentConfig, colorPalettes, formatDate, parseDate } = useContext<any>(Context)
13
+ const { orientation, visualizationSubType } = config
14
+ const isHorizontal = orientation === 'horizontal'
13
15
 
16
+ const lollipopBarWidth = config.lollipopSize === 'large' ? 7 : config.lollipopSize === 'medium' ? 6 : 5
17
+ const lollipopShapeSize = config.lollipopSize === 'large' ? 14 : config.lollipopSize === 'medium' ? 12 : 10
14
18
 
19
+ const isLabelBelowBar = config.yAxis.labelPlacement === 'Below Bar'
20
+ const isLabelOnYAxis = config.yAxis.labelPlacement === 'On Date/Category Axis'
21
+ const isLabelOnBar = config.yAxis.labelPlacement === 'On Bar'
22
+ const isLabelMissing = !config.yAxis.labelPlacement
23
+ const displayNumbersOnBar = config.yAxis.displayNumbersOnBar
24
+ const section = config.orientation === 'horizontal' ? 'yAxis' : 'xAxis'
15
25
 
16
- export default function BarChart({ xScale, yScale, seriesScale, xMax, yMax, getXAxisData, getYAxisData, animatedChart, visible }) {
17
- const { transformedData: data, colorScale, seriesHighlight, config, formatNumber, updateConfig, setParentConfig, colorPalettes, formatDate, parseDate } = useContext<any>(Context);
18
- const { orientation, visualizationSubType } = config;
19
- const isHorizontal = orientation === 'horizontal';
26
+ const isRounded = config.barStyle === 'rounded'
27
+ const isStacked = config.visualizationSubType === 'stacked'
28
+ const tipRounding = config.tipRounding
29
+ const radius = config.roundingStyle === 'standard' ? '8px' : config.roundingStyle === 'shallow' ? '5px' : config.roundingStyle === 'finger' ? '15px' : '0px'
30
+ const stackCount = config.runtime.seriesKeys.length
31
+ const barBorderWidth = 1
20
32
 
21
- const lollipopBarWidth = config.lollipopSize === 'large' ? 7 : config.lollipopSize === 'medium' ? 6 : 5;
22
- const lollipopShapeSize = config.lollipopSize === 'large' ? 14 : config.lollipopSize === 'medium' ? 12 : 10;
33
+ const applyRadius = (index: number) => {
34
+ if (index === undefined || index === null || !isRounded) return
35
+ let style = {}
23
36
 
24
- const isLabelBelowBar = config.yAxis.labelPlacement === "Below Bar";
25
- const isLabelOnYAxis = config.yAxis.labelPlacement === "On Date/Category Axis";
26
- const isLabelOnBar = config.yAxis.labelPlacement === "On Bar";
27
- const isLabelMissing = !config.yAxis.labelPlacement;
28
- const displayNumbersOnBar = config.yAxis.displayNumbersOnBar;
29
- const section = config.orientation ==='horizontal' ? 'yAxis' :'xAxis';
37
+ if ((isStacked && index + 1 === stackCount) || !isStacked) {
38
+ style = isHorizontal ? { borderRadius: `0 ${radius} ${radius} 0` } : { borderRadius: `${radius} ${radius} 0 0` }
39
+ }
40
+ if (tipRounding === 'full' && isStacked && index === 0 && stackCount > 1) {
41
+ style = isHorizontal ? { borderRadius: `${radius} 0 0 ${radius}` } : { borderRadius: `0 0 ${radius} ${radius}` }
42
+ }
43
+ if (tipRounding === 'full' && ((isStacked && index === 0 && stackCount === 1) || !isStacked)) {
44
+ style = { borderRadius: radius }
45
+ }
30
46
 
31
- const isRounded = config.barStyle==='rounded';
32
- const isStacked = config.visualizationSubType === 'stacked'
33
- const tipRounding = config.tipRounding ;
34
- const radius = config.roundingStyle ==='standard' ? '8px' : config.roundingStyle ==='shallow' ? '5px': config.roundingStyle ==='finger' ? '15px':'0px';
35
- const stackCount = config.runtime.seriesKeys.length;
36
- const barBorderWidth = 1;
37
-
38
- const applyRadius = (index:number)=>{
39
- if(index === undefined || index === null || !isRounded) return;
40
- let style = {};
41
-
42
- if((isStacked && index+1 === stackCount) || !isStacked){
43
- style = isHorizontal ? {borderRadius:`0 ${radius} ${radius} 0`} : {borderRadius:`${radius} ${radius} 0 0`};
44
- };
45
- if(tipRounding === 'full' && isStacked && index === 0 && stackCount > 1){
46
- style = isHorizontal ? {borderRadius:`${radius} 0 0 ${radius}`} : {borderRadius:`0 0 ${radius} ${radius}`};
47
- };
48
- if(tipRounding === 'full' && ((isStacked && index === 0 && stackCount === 1) || !isStacked)){
49
- style = {borderRadius:radius};
50
- };
51
-
52
- return style;
53
- }
47
+ return style
48
+ }
54
49
 
55
50
  // Using State
56
- const [horizBarHeight, setHorizBarHeight] = useState(null);
57
- const [textWidth, setTextWidth] = useState(null);
51
+ const [horizBarHeight, setHorizBarHeight] = useState(null)
52
+ const [textWidth, setTextWidth] = useState(null)
58
53
 
59
54
  useEffect(() => {
60
- if(orientation === "horizontal" && !config.yAxis.labelPlacement) {
55
+ if (orientation === 'horizontal' && !config.yAxis.labelPlacement) {
61
56
  updateConfig({
62
57
  ...config,
63
58
  yAxis: {
64
59
  ...config,
65
- labelPlacement: "Below Bar"
60
+ labelPlacement: 'Below Bar'
66
61
  }
67
62
  })
68
63
  }
69
- }, [config, updateConfig]);
64
+ }, [config, updateConfig])
70
65
 
71
66
  useEffect(() => {
72
- if(config.isLollipopChart === false && config.barHeight < 25) {
67
+ if (config.isLollipopChart === false && config.barHeight < 25) {
73
68
  updateConfig({ ...config, barHeight: 25 })
74
69
  }
75
- }, [config.isLollipopChart]);
70
+ }, [config.isLollipopChart])
76
71
 
77
72
  useEffect(() => {
78
- if(config.visualizationSubType === 'horizontal') {
73
+ if (config.visualizationSubType === 'horizontal') {
79
74
  updateConfig({
80
75
  ...config,
81
76
  orientation: 'horizontal'
82
77
  })
83
78
  }
84
- }, []);
85
-
86
- useEffect(()=>{
87
- if(config.barStyle==='lollipop' && !config.isLollipopChart ){
88
- updateConfig({ ...config, isLollipopChart:true })
79
+ }, [])
80
+
81
+ useEffect(() => {
82
+ if (config.barStyle === 'lollipop' && !config.isLollipopChart) {
83
+ updateConfig({ ...config, isLollipopChart: true })
89
84
  }
90
- if( isRounded || config.barStyle==='flat' ){
91
- updateConfig({ ...config, isLollipopChart:false })
85
+ if (isRounded || config.barStyle === 'flat') {
86
+ updateConfig({ ...config, isLollipopChart: false })
92
87
  }
93
- },[config.barStyle])
88
+ }, [config.barStyle])
94
89
 
95
90
  // config.runtime.seriesKeys.sort().reverse();
96
91
 
97
92
  return (
98
- <ErrorBoundary component="BarChart">
93
+ <ErrorBoundary component='BarChart'>
99
94
  <Group left={config.runtime.yAxis.size}>
100
-
101
95
  {/* Stacked Vertical */}
102
- { config.visualizationSubType === 'stacked' && !isHorizontal && (
103
- <BarStack
104
- data={data}
105
- keys={(config.runtime.barSeriesKeys || config.runtime.seriesKeys)}
106
- x={(d: any) => d[config.runtime.xAxis.dataKey]}
107
- xScale={xScale}
108
- yScale={yScale}
109
- color={colorScale}
110
- >
111
- {barStacks => barStacks.reverse().map(barStack => barStack.bars.map(bar => {
112
- const xAxisValue = config.runtime.xAxis.type==='date' ? formatDate(parseDate( data[bar.index][config.runtime.xAxis.dataKey])) : data[bar.index][config.runtime.xAxis.dataKey]
113
- let yAxisTooltip = config.runtime.yAxis.label ? `${config.runtime.yAxis.label}: ${formatNumber(bar.bar ? bar.bar.data[bar.key] : 0)}` : formatNumber(bar.bar ? bar.bar.data[bar.key] : 0)
114
- let xAxisTooltip = config.runtime.xAxis.label ? `${config.runtime.xAxis.label}: ${xAxisValue}` : xAxisValue;
115
-
116
- const tooltip = `<div>
117
- ${yAxisTooltip}<br />
118
- ${xAxisTooltip}<br />
119
- ${config.seriesLabel ? `${config.seriesLabel}: ${bar.key}` : ''}`
120
-
121
- let transparentBar = config.legend.behavior === 'highlight' && seriesHighlight.length > 0 && seriesHighlight.indexOf(bar.key) === -1;
122
- let displayBar = config.legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(bar.key) !== -1;
123
- let barThickness = xMax / barStack.bars.length;
124
- let barThicknessAdjusted = barThickness * (config.barThickness || 0.8);
125
- let offset = barThickness * (1 - (config.barThickness || 0.8)) / 2;
126
- const style = applyRadius(barStack.index)
127
-
128
- return (
129
- <>
130
- <style>
131
- {`
96
+ {config.visualizationSubType === 'stacked' && !isHorizontal && (
97
+ <BarStack data={data} keys={config.runtime.barSeriesKeys || config.runtime.seriesKeys} x={(d: any) => d[config.runtime.xAxis.dataKey]} xScale={xScale} yScale={yScale} color={colorScale}>
98
+ {barStacks =>
99
+ barStacks.reverse().map(barStack =>
100
+ barStack.bars.map(bar => {
101
+ const xAxisValue = config.runtime.xAxis.type === 'date' ? formatDate(parseDate(data[bar.index][config.runtime.xAxis.dataKey])) : data[bar.index][config.runtime.xAxis.dataKey]
102
+ const yAxisValue = formatNumber(bar.bar ? bar.bar.data[bar.key] : 0)
103
+ let yAxisTooltip =config.runtime.yAxis.isLegendValue ? `${bar.key}: ${yAxisValue}` : config.runtime.yAxis.label ? `${config.runtime.yAxis.label}: ${yAxisValue}` : yAxisValue;
104
+ let xAxisTooltip = config.runtime.xAxis.label ? `${config.runtime.xAxis.label}: ${xAxisValue}` : xAxisValue
105
+
106
+ const tooltip = `<div>
107
+ ${yAxisTooltip}<br />
108
+ ${xAxisTooltip}<br />
109
+ ${config.seriesLabel ? `${config.seriesLabel}: ${bar.key}` : ''}`
110
+
111
+ let transparentBar = config.legend.behavior === 'highlight' && seriesHighlight.length > 0 && seriesHighlight.indexOf(bar.key) === -1
112
+ let displayBar = config.legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(bar.key) !== -1
113
+ let barThickness = xMax / barStack.bars.length
114
+ let barThicknessAdjusted = barThickness * (config.barThickness || 0.8)
115
+ let offset = (barThickness * (1 - (config.barThickness || 0.8))) / 2
116
+ const style = applyRadius(barStack.index)
117
+
118
+ return (
119
+ <>
120
+ <style>
121
+ {`
132
122
  #barStack${barStack.index}-${bar.index} rect,
133
123
  #barStack${barStack.index}-${bar.index} foreignObject{
134
124
  animation-delay: ${barStack.index}.2s;
135
- transform-origin: ${barThicknessAdjusted/2}px ${bar.y + bar.height}px
125
+ transform-origin: ${barThicknessAdjusted / 2}px ${bar.y + bar.height}px
136
126
  }
137
127
  `}
138
- </style>
139
- <Group key={`bar-stack-${barStack.index}-${bar.index}`} id={`barStack${barStack.index}-${bar.index}`} className='stack vertical'>
140
- <Text
141
- display={config.labels && displayBar ? 'block' : 'none'}
142
- opacity={transparentBar ? 0.5 : 1}
143
- x={barThickness * (bar.index + 0.5) + offset}
144
- y={bar.y - 5}
145
- fill={bar.color}
146
- textAnchor="middle">
147
- {formatNumber(bar.bar ? bar.bar.data[bar.key] : 0)}
148
- </Text>
149
- <foreignObject
150
- key={`bar-stack-${barStack.index}-${bar.index}`}
151
- x={barThickness * bar.index + offset}
152
- y={bar.y}
153
- width={barThicknessAdjusted}
154
- height={bar.height}
155
- style={{background:bar.color,border:`${config.barHasBorder==='true' ? barBorderWidth: 0 }px solid #333`,...style}}
156
- opacity={transparentBar ? 0.5 : 1}
157
- display={displayBar ? 'block' : 'none'}
158
- data-tip={tooltip}
159
- data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
160
- > </foreignObject>
161
- </Group>
162
- </>
163
- )}
164
- ))}
128
+ </style>
129
+ <Group key={`bar-stack-${barStack.index}-${bar.index}`} id={`barStack${barStack.index}-${bar.index}`} className='stack vertical'>
130
+ <Text display={config.labels && displayBar ? 'block' : 'none'} opacity={transparentBar ? 0.5 : 1} x={barThickness * (bar.index + 0.5) + offset} y={bar.y - 5} fill={bar.color} textAnchor='middle'>
131
+ {formatNumber(bar.bar ? bar.bar.data[bar.key] : 0)}
132
+ </Text>
133
+ <foreignObject
134
+ key={`bar-stack-${barStack.index}-${bar.index}`}
135
+ x={barThickness * bar.index + offset}
136
+ y={bar.y}
137
+ width={barThicknessAdjusted}
138
+ height={bar.height}
139
+ style={{ background: bar.color, border: `${config.barHasBorder === 'true' ? barBorderWidth : 0}px solid #333`, ...style }}
140
+ opacity={transparentBar ? 0.5 : 1}
141
+ display={displayBar ? 'block' : 'none'}
142
+ data-tip={tooltip}
143
+ data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
144
+ >
145
+ {' '}
146
+ </foreignObject>
147
+ </Group>
148
+ </>
149
+ )
150
+ })
151
+ )
152
+ }
165
153
  </BarStack>
166
154
  )}
167
155
 
168
156
  {/* Stacked Horizontal */}
169
- { config.visualizationSubType === 'stacked' && isHorizontal && (
157
+ {config.visualizationSubType === 'stacked' && isHorizontal && (
170
158
  <>
171
- <BarStackHorizontal
172
- data={data}
173
- keys={(config.runtime.barSeriesKeys || config.runtime.seriesKeys)}
174
- height={yMax }
175
- y={(d: any) => d[config.runtime.yAxis.dataKey]}
176
- xScale={xScale}
177
- yScale={yScale}
178
- color={colorScale}
179
- offset="none"
180
- >
181
- {(barStacks) =>
182
- barStacks.map((barStack) =>
159
+ <BarStackHorizontal data={data} keys={config.runtime.barSeriesKeys || config.runtime.seriesKeys} height={yMax} y={(d: any) => d[config.runtime.yAxis.dataKey]} xScale={xScale} yScale={yScale} color={colorScale} offset='none'>
160
+ {barStacks =>
161
+ barStacks.map(barStack =>
183
162
  barStack.bars.map((bar, index) => {
184
- const xAxisValue = config.runtime.yAxis.type==='date' ? formatDate(parseDate(data[bar.index][config.runtime.originalXAxis.dataKey])) : data[bar.index][config.runtime.originalXAxis.dataKey]
185
- let yAxisTooltip = config.yAxis.label ? `${config.yAxis.label}: ${formatNumber(data[bar.index][bar.key])}` : `${bar.key}: ${formatNumber(data[bar.index][bar.key])}`
163
+ const yAxisValue = formatNumber(data[bar.index][bar.key]);
164
+ const xAxisValue = config.runtime.yAxis.type === 'date' ? formatDate(parseDate(data[bar.index][config.runtime.originalXAxis.dataKey])) : data[bar.index][config.runtime.originalXAxis.dataKey]
165
+ let yAxisTooltip = config.yAxis.isLegendValue ? `${bar.key}: ${yAxisValue}` : config.yAxis.label ? `${config.yAxis.label}: ${yAxisValue}` :`${yAxisValue}`
186
166
  let xAxisTooltip = config.xAxis.label ? `${config.xAxis.label}: ${xAxisValue}` : xAxisValue
187
167
  // let yAxisTooltip = config.yAxis.label ? `${config.yAxis.label}: ${data[bar.index][bar.key]}` : `${bar.key}: ${data[bar.index][bar.key]}`
188
168
  // let xAxisTooltip = config.xAxis.label ? `${config.xAxis.label}: ${data[bar.index][config.runtime.originalXAxis.dataKey]}` :`${data[bar.index].name}`
189
-
169
+
190
170
  const tooltip = `<div>
191
171
  ${yAxisTooltip}<br />
192
172
  ${xAxisTooltip}<br />
193
173
  ${config.seriesLabel ? `${config.seriesLabel}: ${bar.key}` : ''}`
194
- let transparentBar = config.legend.behavior === 'highlight' && seriesHighlight.length > 0 && seriesHighlight.indexOf(bar.key) === -1;
195
- let displayBar = config.legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(bar.key) !== -1;
196
- const barsPerGroup = config.series.length;
197
- let barHeight = config.barHeight ? config.barHeight : 25;
198
- let barPadding = barHeight;
174
+ let transparentBar = config.legend.behavior === 'highlight' && seriesHighlight.length > 0 && seriesHighlight.indexOf(bar.key) === -1
175
+ let displayBar = config.legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(bar.key) !== -1
176
+ const barsPerGroup = config.series.length
177
+ let barHeight = config.barHeight ? config.barHeight : 25
178
+ let barPadding = barHeight
199
179
 
200
180
  config.barHeight = Number(config.barHeight)
201
- const style = applyRadius(barStack.index);
181
+ const style = applyRadius(barStack.index)
202
182
 
203
- if (orientation=== "horizontal") {
204
-
205
- if(isLabelBelowBar || isLabelMissing || isLabelOnYAxis) {
206
- if(barHeight < 40) {
207
- config.barPadding = 40;
183
+ if (orientation === 'horizontal') {
184
+ if (isLabelBelowBar || isLabelMissing || isLabelOnYAxis) {
185
+ if (barHeight < 40) {
186
+ config.barPadding = 40
208
187
  } else {
209
- config.barPadding = Number(barPadding);
188
+ config.barPadding = Number(barPadding)
210
189
  }
211
190
  } else {
212
- config.barPadding = Number(barPadding) / 2;
191
+ config.barPadding = Number(barPadding) / 2
213
192
  }
214
193
  }
215
194
 
216
- config.height = (Number(barHeight) ) * data.length + (Number(config.barPadding) * data.length);
195
+ config.height = Number(barHeight) * data.length + Number(config.barPadding) * data.length
217
196
 
218
- let labelColor = "#000000";
197
+ let labelColor = '#000000'
219
198
 
220
- let textPosition = (bar.y - config.barPadding/2 - Number(config.barHeight/2) + Number(config.barHeight) ) + 5;
199
+ let textPosition = bar.y - config.barPadding / 2 - Number(config.barHeight / 2) + Number(config.barHeight) + 5
221
200
 
222
201
  if (chroma.contrast(labelColor, bar.color) < 4.9) {
223
- labelColor = '#FFFFFF';
202
+ labelColor = '#FFFFFF'
224
203
  }
225
204
 
226
205
  return (
227
206
  <Group key={index}>
228
- <foreignObject
207
+ <foreignObject
229
208
  key={`barstack-horizontal-${barStack.index}-${bar.index}-${index}`}
230
209
  className={`animated-chart group ${animatedChart ? 'animated' : ''}`}
231
210
  x={bar.x}
232
- y={ bar.y - config.barPadding/2 - config.barHeight/2 }
211
+ y={bar.y - config.barPadding / 2 - config.barHeight / 2}
233
212
  width={bar.width}
234
213
  height={config.barHeight}
235
- style={{background:bar.color,border:`${config.barHasBorder==='true' ? barBorderWidth: 0 }px solid #333`,...style}}
214
+ style={{ background: bar.color, border: `${config.barHasBorder === 'true' ? barBorderWidth : 0}px solid #333`, ...style }}
236
215
  opacity={transparentBar ? 0.5 : 1}
237
216
  display={displayBar ? 'block' : 'none'}
238
217
  data-tip={tooltip}
239
218
  data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
240
219
  ></foreignObject>
241
220
 
242
- {(orientation === 'horizontal' && visualizationSubType === 'stacked') && isLabelBelowBar && barStack.index === 0 && !config.yAxis.hideLabel &&
221
+ {orientation === 'horizontal' && visualizationSubType === 'stacked' && isLabelBelowBar && barStack.index === 0 && !config.yAxis.hideLabel && (
243
222
  <Text
244
- x={ `${bar.x + (config.isLollipopChart ? 15 : 5)}` } // padding
223
+ x={`${bar.x + (config.isLollipopChart ? 15 : 5)}`} // padding
245
224
  y={textPosition}
246
- fill={ '#000000' }
247
- textAnchor="start"
248
- verticalAnchor="start"
225
+ fill={'#000000'}
226
+ textAnchor='start'
227
+ verticalAnchor='start'
249
228
  >
250
- {isHorizontal ? xAxisValue : formatNumber(xAxisValue)}
229
+ {isHorizontal ? xAxisValue : formatNumber(xAxisValue)}
251
230
  </Text>
252
- }
231
+ )}
253
232
 
254
- { displayNumbersOnBar && textWidth + 50 < bar.width &&
233
+ {displayNumbersOnBar && textWidth + 50 < bar.width && (
255
234
  <Text
256
235
  display={displayBar ? 'block' : 'none'}
257
- x={ bar.x + barStack.bars[bar.index].width / 2 } // padding
258
- y={ textPosition - 5 - config.barHeight/2 }
259
- fill={ labelColor }
260
- textAnchor="middle"
261
- verticalAnchor="middle"
262
- innerRef={
263
- (e) => {
264
- if(e) {
265
- // use font sizes and padding to set the bar height
266
- let elem = e.getBBox()
267
- setTextWidth(elem.width)
268
- }
236
+ x={bar.x + barStack.bars[bar.index].width / 2} // padding
237
+ y={textPosition - 5 - config.barHeight / 2}
238
+ fill={labelColor}
239
+ textAnchor='middle'
240
+ verticalAnchor='middle'
241
+ innerRef={e => {
242
+ if (e) {
243
+ // use font sizes and padding to set the bar height
244
+ let elem = e.getBBox()
245
+ setTextWidth(elem.width)
269
246
  }
270
- }
247
+ }}
271
248
  >
272
249
  {formatNumber(data[bar.index][bar.key])}
273
250
  </Text>
274
- }
251
+ )}
275
252
  </Group>
276
253
  )
277
- }
278
- ))
254
+ })
255
+ )
279
256
  }
280
257
  </BarStackHorizontal>
281
258
  </>
282
259
  )}
283
260
 
284
261
  {/* Bar Groups: Not Stacked */}
285
- { config.visualizationSubType !== 'stacked' && (
262
+ {config.visualizationSubType !== 'stacked' && (
286
263
  <Group>
287
264
  <BarGroup
288
265
  data={data}
289
- keys={(config.runtime.barSeriesKeys || config.runtime.seriesKeys)}
266
+ keys={config.runtime.barSeriesKeys || config.runtime.seriesKeys}
290
267
  height={yMax}
291
268
  x0={(d: any) => d[config.runtime.originalXAxis.dataKey]}
292
269
  x0Scale={config.runtime.horizontal ? yScale : xScale}
293
270
  x1Scale={seriesScale}
294
271
  yScale={config.runtime.horizontal ? xScale : yScale}
295
- color={() => {return '';}}
272
+ color={() => {
273
+ return ''
274
+ }}
296
275
  >
297
- {(barGroups) => {
298
- let barType = 'vertical';
299
- if (orientation=== "horizontal") {
300
- const barsPerGroup = config.series.length;
301
- let barHeight = config.barHeight ? config.barHeight : 25;
302
- let barPadding = barHeight;
303
- barType = 'horizontal';
304
-
305
- if(isLabelBelowBar || isLabelMissing || isLabelOnYAxis) {
306
- if(barHeight < 40) {
307
- config.barPadding = 40;
276
+ {barGroups => {
277
+ let barType = 'vertical'
278
+ if (orientation === 'horizontal') {
279
+ const barsPerGroup = config.series.length
280
+ let barHeight = config.barHeight ? config.barHeight : 25
281
+ let barPadding = barHeight
282
+ barType = 'horizontal'
283
+
284
+ if (isLabelBelowBar || isLabelMissing || isLabelOnYAxis) {
285
+ if (barHeight < 40) {
286
+ config.barPadding = 40
308
287
  } else {
309
- config.barPadding = barPadding;
288
+ config.barPadding = barPadding
310
289
  }
311
290
  } else {
312
- config.barPadding = barPadding / 2;
291
+ config.barPadding = barPadding / 2
313
292
  }
314
293
 
315
- if(config.isLollipopChart && config.yAxis.labelPlacement === 'Below Bar') {
316
- config.barPadding = config.barPadding + 7;
294
+ if (config.isLollipopChart && config.yAxis.labelPlacement === 'Below Bar') {
295
+ config.barPadding = config.barPadding + 7
317
296
  }
318
- config.barHeight = config.isLollipopChart ? lollipopBarWidth : barHeight;
319
- config.height = (barsPerGroup * barHeight) * barGroups.length + (config.barPadding * barGroups.length);
297
+ config.barHeight = config.isLollipopChart ? lollipopBarWidth : barHeight
298
+ config.height = barsPerGroup * barHeight * barGroups.length + config.barPadding * barGroups.length
320
299
  }
321
300
 
322
301
  return barGroups.map((barGroup, index) => (
323
- <Group
324
- className={`bar-group-${barGroup.index}-${barGroup.x0}--${index} ${barType}`}
325
- key={`bar-group-${barGroup.index}-${barGroup.x0}--${index}`}
326
- top={config.runtime.horizontal ? yMax / barGroups.length * barGroup.index : 0}
327
- left={config.runtime.horizontal ? 0 : xMax / barGroups.length * barGroup.index}>
328
- {barGroup.bars.map((bar,index) => {
329
-
330
- let transparentBar = config.legend.behavior === 'highlight' && seriesHighlight.length > 0 && seriesHighlight.indexOf(bar.key) === -1;
331
- let displayBar = config.legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(bar.key) !== -1;
332
- let barHeight = orientation === "horizontal" ? config.barHeight : Math.abs(yScale(bar.value) - yScale(0));
333
- let barY = bar.value >= 0 ? bar.y : yScale(0);
334
- let barGroupWidth = (config.runtime.horizontal ? yMax : xMax) / barGroups.length * (config.barThickness || 0.8);
335
- let offset = (config.runtime.horizontal ? yMax : xMax) / barGroups.length * (1 - (config.barThickness || 0.8)) / 2;
336
-
337
- // ! Unsure if this should go back.
338
- if(config.isLollipopChart) {
339
- offset = ( (config.runtime.horizontal ? yMax : xMax) / barGroups.length / 2) - lollipopBarWidth / 2
340
- }
341
-
342
- const set = new Set()
343
- data.forEach(d=>set.add(d[config.legend.colorCode]));
344
- const uniqValues = Array.from(set);
302
+ <Group
303
+ className={`bar-group-${barGroup.index}-${barGroup.x0}--${index} ${barType}`}
304
+ key={`bar-group-${barGroup.index}-${barGroup.x0}--${index}`}
305
+ top={config.runtime.horizontal ? (yMax / barGroups.length) * barGroup.index : 0}
306
+ left={config.runtime.horizontal ? 0 : (xMax / barGroups.length) * barGroup.index}
307
+ >
308
+ {barGroup.bars.map((bar, index) => {
309
+ let transparentBar = config.legend.behavior === 'highlight' && seriesHighlight.length > 0 && seriesHighlight.indexOf(bar.key) === -1
310
+ let displayBar = config.legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(bar.key) !== -1
311
+ let barHeight = orientation === 'horizontal' ? config.barHeight : Math.abs(yScale(bar.value) - yScale(0))
312
+ let barY = bar.value >= 0 ? bar.y : yScale(0)
313
+ let barGroupWidth = ((config.runtime.horizontal ? yMax : xMax) / barGroups.length) * (config.barThickness || 0.8)
314
+ let offset = (((config.runtime.horizontal ? yMax : xMax) / barGroups.length) * (1 - (config.barThickness || 0.8))) / 2
315
+
316
+ // ! Unsure if this should go back.
317
+ if (config.isLollipopChart) {
318
+ offset = (config.runtime.horizontal ? yMax : xMax) / barGroups.length / 2 - lollipopBarWidth / 2
319
+ }
345
320
 
346
- let palette = colorPalettes[config.palette].slice(0,uniqValues.length);
321
+ const set = new Set()
322
+ data.forEach(d => set.add(d[config.legend.colorCode]))
323
+ const uniqValues = Array.from(set)
347
324
 
348
- let barWidth = config.isLollipopChart ? lollipopBarWidth : barGroupWidth / barGroup.bars.length;
349
- let barColor = config.runtime.seriesLabels && config.runtime.seriesLabels[bar.key] ? colorScale(config.runtime.seriesLabels[bar.key]) : colorScale(bar.key);
350
- while( palette.length < barGroups.length ){
351
- palette =palette.concat(palette)
352
- }
353
- if( config.legend.colorCode && config.series.length===1) barColor = palette[barGroup.index];
354
-
355
- let yAxisValue = formatNumber(bar.value);
356
- let xAxisValue = config.runtime[section].type==='date' ? formatDate(parseDate(data[barGroup.index][config.runtime.originalXAxis.dataKey])) : data[barGroup.index][config.runtime.originalXAxis.dataKey]
357
-
358
- if(config.runtime.horizontal){
359
- let tempValue = yAxisValue;
360
- yAxisValue = xAxisValue;
361
- xAxisValue = tempValue;
362
- barWidth = config.barHeight
363
- }
325
+ let palette = colorPalettes[config.palette].slice(0, uniqValues.length)
364
326
 
365
- let yAxisTooltip = config.runtime.yAxis.label ? `${config.runtime.yAxis.label}: ${yAxisValue}` : yAxisValue
366
- let xAxisTooltip = config.runtime.xAxis.label ? `${config.runtime.xAxis.label}: ${xAxisValue}` : xAxisValue
367
- let horizBarLabelPadding = null;
368
- let labelColor = "#000000";
327
+ let barWidth = config.isLollipopChart ? lollipopBarWidth : barGroupWidth / barGroup.bars.length
328
+ let barColor = config.runtime.seriesLabels && config.runtime.seriesLabels[bar.key] ? colorScale(config.runtime.seriesLabels[bar.key]) : colorScale(bar.key)
329
+ while (palette.length < barGroups.length) {
330
+ palette = palette.concat(palette)
331
+ }
332
+ if (config.legend.colorCode && config.series.length === 1) barColor = palette[barGroup.index]
369
333
 
370
- // Set label color
371
- if (chroma.contrast(labelColor, barColor) < 4.9) {
372
- labelColor = '#FFFFFF';
373
- }
334
+ let yAxisValue = formatNumber(bar.value)
335
+ let xAxisValue = config.runtime[section].type === 'date' ? formatDate(parseDate(data[barGroup.index][config.runtime.originalXAxis.dataKey])) : data[barGroup.index][config.runtime.originalXAxis.dataKey]
374
336
 
375
- // font size and text spacing used for centering text on bar
376
- if(config.fontSize === "small") {
377
- horizBarLabelPadding = 16;
378
- } else if(config.fontSize === "medium") {
379
- horizBarLabelPadding = 18;
380
- } else{
381
- horizBarLabelPadding = 20;
382
- }
383
- const onBarTextSpacing = 25;
384
- const tooltip = `<div>
337
+ if (config.runtime.horizontal) {
338
+ let tempValue = yAxisValue
339
+ yAxisValue = xAxisValue
340
+ xAxisValue = tempValue
341
+ barWidth = config.barHeight
342
+ }
343
+
344
+ let yAxisTooltip = config.runtime.yAxis.isLegendValue ? `${bar.key} : ${yAxisValue}`: config.runtime.yAxis.label ? `${config.runtime.yAxis.label}: ${yAxisValue}` :yAxisValue;
345
+ let xAxisTooltip =config.runtime.xAxis.isLegendValue ? ` ${bar.key} :${xAxisValue}` : config.runtime.xAxis.label ? `${config.runtime.xAxis.label}: ${xAxisValue}` : xAxisValue
346
+ let horizBarLabelPadding = null
347
+ let labelColor = '#000000'
348
+
349
+ // Set label color
350
+ if (chroma.contrast(labelColor, barColor) < 4.9) {
351
+ labelColor = '#FFFFFF'
352
+ }
353
+
354
+ // font size and text spacing used for centering text on bar
355
+ if (config.fontSize === 'small') {
356
+ horizBarLabelPadding = 16
357
+ } else if (config.fontSize === 'medium') {
358
+ horizBarLabelPadding = 18
359
+ } else {
360
+ horizBarLabelPadding = 20
361
+ }
362
+ const onBarTextSpacing = 25
363
+ const tooltip = `<div>
385
364
  ${yAxisTooltip}<br />
386
365
  ${xAxisTooltip}<br />
387
366
  ${config.seriesLabel ? `${config.seriesLabel}: ${bar.key}` : ''}`
388
- const style = applyRadius(index)
367
+ const style = applyRadius(index)
389
368
 
390
- return (
369
+ return (
391
370
  <>
392
371
  {/* This feels gross but inline transition was not working well*/}
393
372
  <style>
394
- {`
373
+ {`
395
374
  .linear #barGroup${barGroup.index},
396
375
  .Combo #barGroup${barGroup.index} {
397
376
  transform-origin: 0 ${barY + barHeight}px;
398
377
  }
399
378
  `}
400
- </style>
401
- <Group key={`bar-sub-group-${barGroup.index}-${barGroup.x0}-${barY}--${index}`}>
402
- <Text
403
- display={config.labels && displayBar ? 'block' : 'none'}
404
- opacity={transparentBar ? 0.5 : 1}
405
- x={barWidth * (barGroup.bars.length - bar.index - 0.5) + offset}
406
- y={barY - 5}
407
- fill={barColor}
408
- textAnchor="middle">
409
- {formatNumber(bar.value)}
410
- </Text>
411
- <foreignObject
412
- id={`barGroup${barGroup.index}`}
413
- key={`bar-group-bar-${barGroup.index}-${bar.index}-${bar.value}-${bar.key}`}
414
- x={ config.runtime.horizontal ? 0 : barWidth * (barGroup.bars.length - bar.index - 1) + offset }
415
- y={config.runtime.horizontal ? barWidth * (barGroup.bars.length - bar.index - 1) + (config.isLollipopChart && isLabelOnYAxis ? offset : 0) : barY }
416
- width={config.runtime.horizontal ? bar.y : barWidth}
417
- height={config.runtime.horizontal ? barWidth : barHeight}
418
- style={{
419
- background:config.isLollipopChart && config.lollipopColorStyle === 'regular' ? barColor :
420
- config.isLollipopChart && config.lollipopColorStyle === 'two-tone' ? chroma(barColor).brighten(1) : barColor ,
421
- border:`${config.isLollipopChart ? 0 :config.barHasBorder==='true' ? barBorderWidth: 0 }px solid #333`,
422
- ...style
423
- }}
424
- opacity={transparentBar ? 0.5 : 1}
425
- display={displayBar ? 'block' : 'none'}
426
- data-tip={tooltip}
427
- data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
428
- ></foreignObject>
429
- {config.isLollipopChart && config.lollipopShape === 'circle' &&
430
- <circle
431
- cx={orientation === 'horizontal' ? bar.y : barWidth * (barGroup.bars.length - bar.index - 1) + (isLabelBelowBar && orientation === 'horizontal' ? 0 : offset) + lollipopShapeSize/3.5}
432
- cy={orientation === 'horizontal' ? lollipopShapeSize/3.5 + (isLabelBelowBar && orientation === 'horizontal' ? 0: offset) : bar.y}
433
- r={lollipopShapeSize/2}
434
- fill={barColor}
435
- key={`circle--${bar.index}`}
436
- data-tip={tooltip}
437
- data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
438
- style={{ filter: 'unset', opacity: 1 }}
439
- />
440
- }
441
- {config.isLollipopChart && config.lollipopShape === 'square' &&
442
- <rect
443
- x={
444
- (orientation === 'horizontal' && bar.y > 10) ? bar.y - lollipopShapeSize / 2 : (orientation === 'horizontal' && bar.y < 10) ? 0 :
445
- (orientation !== 'horizontal') ? offset - lollipopBarWidth / 2 : barWidth * (barGroup.bars.length - bar.index - 1) + offset - 5.25
446
- }
447
- y={
448
- orientation === 'horizontal' ? 0 - lollipopBarWidth / 2 + (isLabelBelowBar ? 0 : offset) : config.height - bar.y > 10 ? bar.y - lollipopShapeSize / 2 : 0 }
449
- width={lollipopShapeSize}
450
- height={lollipopShapeSize}
451
- fill={barColor}
452
- key={`circle--${bar.index}`}
453
- data-tip={tooltip}
454
- data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
455
- style={{ 'opacity': 1, filter: 'unset' }}
456
- >
457
- <animate attributeName="height" values={`0, ${lollipopShapeSize}`} dur="2.5s"/>
458
- </rect>
459
- }
460
- {orientation === "horizontal" && textWidth + 100 < bar.y ?
461
- config.yAxis.labelPlacement === "On Bar" &&
462
- <Group>
463
- <Text
464
- innerRef={
465
- (e) => {
466
- if(e) {
467
- // use font sizes and padding to set the bar height
468
- let elem = e.getBBox()
469
- setTextWidth(elem.width)
470
- config.barHeight = ( (elem.height * 2) + (horizBarLabelPadding * 2) + onBarTextSpacing / 2 )
471
- config.barPadding = ( horizBarHeight / 2 )
472
- }
473
- }
474
- }
475
- x={ bar.y - horizBarLabelPadding }
476
- y={ barHeight * (barGroup.bars.length - bar.index - 1) + ( horizBarLabelPadding * 2 ) }
477
- fill={ labelColor }
478
- textAnchor="end"
479
- >
480
- { yAxisValue }
481
- </Text>
482
- <Text
483
- x={ bar.y - horizBarLabelPadding }
484
- y={ barWidth * (barGroup.bars.length - bar.index - 1) + ( horizBarLabelPadding * 2 ) + onBarTextSpacing }
485
- fill={ labelColor }
486
- textAnchor="end"
379
+ </style>
380
+ <Group key={`bar-sub-group-${barGroup.index}-${barGroup.x0}-${barY}--${index}`}>
381
+ <Text display={config.labels && displayBar ? 'block' : 'none'} opacity={transparentBar ? 0.5 : 1} x={barWidth * (barGroup.bars.length - bar.index - 0.5) + offset} y={barY - 5} fill={barColor} textAnchor='middle'>
382
+ {formatNumber(bar.value)}
383
+ </Text>
384
+ <foreignObject
385
+ id={`barGroup${barGroup.index}`}
386
+ key={`bar-group-bar-${barGroup.index}-${bar.index}-${bar.value}-${bar.key}`}
387
+ x={config.runtime.horizontal ? 0 : barWidth * (barGroup.bars.length - bar.index - 1) + offset}
388
+ y={config.runtime.horizontal ? barWidth * (barGroup.bars.length - bar.index - 1) + (config.isLollipopChart && isLabelOnYAxis ? offset : 0) : barY}
389
+ width={config.runtime.horizontal ? bar.y : barWidth}
390
+ height={config.runtime.horizontal ? barWidth : barHeight}
391
+ style={{
392
+ background: config.isLollipopChart && config.lollipopColorStyle === 'regular' ? barColor : config.isLollipopChart && config.lollipopColorStyle === 'two-tone' ? chroma(barColor).brighten(1) : barColor,
393
+ border: `${config.isLollipopChart ? 0 : config.barHasBorder === 'true' ? barBorderWidth : 0}px solid #333`,
394
+ ...style
395
+ }}
396
+ opacity={transparentBar ? 0.5 : 1}
397
+ display={displayBar ? 'block' : 'none'}
398
+ data-tip={tooltip}
399
+ data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
400
+ ></foreignObject>
401
+ {config.isLollipopChart && config.lollipopShape === 'circle' && (
402
+ <circle
403
+ cx={orientation === 'horizontal' ? bar.y : barWidth * (barGroup.bars.length - bar.index - 1) + (isLabelBelowBar && orientation === 'horizontal' ? 0 : offset) + lollipopShapeSize / 3.5}
404
+ cy={orientation === 'horizontal' ? lollipopShapeSize / 3.5 + (isLabelBelowBar && orientation === 'horizontal' ? 0 : offset) : bar.y}
405
+ r={lollipopShapeSize / 2}
406
+ fill={barColor}
407
+ key={`circle--${bar.index}`}
408
+ data-tip={tooltip}
409
+ data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
410
+ style={{ filter: 'unset', opacity: 1 }}
411
+ />
412
+ )}
413
+ {config.isLollipopChart && config.lollipopShape === 'square' && (
414
+ <rect
415
+ x={orientation === 'horizontal' && bar.y > 10 ? bar.y - lollipopShapeSize / 2 : orientation === 'horizontal' && bar.y < 10 ? 0 : orientation !== 'horizontal' ? offset - lollipopBarWidth / 2 : barWidth * (barGroup.bars.length - bar.index - 1) + offset - 5.25}
416
+ y={orientation === 'horizontal' ? 0 - lollipopBarWidth / 2 + (isLabelBelowBar ? 0 : offset) : config.height - bar.y > 10 ? bar.y - lollipopShapeSize / 2 : 0}
417
+ width={lollipopShapeSize}
418
+ height={lollipopShapeSize}
419
+ fill={barColor}
420
+ key={`circle--${bar.index}`}
421
+ data-tip={tooltip}
422
+ data-for={`cdc-open-viz-tooltip-${config.runtime.uniqueId}`}
423
+ style={{ opacity: 1, filter: 'unset' }}
487
424
  >
488
- { xAxisValue }
489
- </Text>
490
- </Group>
491
- :
492
- (isLabelOnBar) &&
493
- <Group>
494
- {/* hide y label if we're only showing data on bar */}
495
- <Text
496
- x={ bar.y + horizBarLabelPadding }
497
- y={ barWidth * (barGroup.bars.length - bar.index - 1) + ( horizBarLabelPadding * 2 ) }
498
- fill={ "#000" }
499
- textAnchor="start"
500
- verticalAnchor="end"
501
- >{yAxisValue}</Text>
502
- <Text
503
- x={ bar.y + horizBarLabelPadding }
504
- y={ barWidth * (barGroup.bars.length - bar.index - 1) + ( horizBarLabelPadding * 2 ) + onBarTextSpacing }
505
- fill={ "#000" }
506
- textAnchor="start"
507
- verticalAnchor="start"
508
- >
509
- { xAxisValue }
510
- </Text>
511
- </Group>
512
- }
513
-
514
- { orientation === "horizontal" && isLabelBelowBar && !config.yAxis.hideLabel &&
515
- <>
516
- <Text
517
- x={ config.yAxis.hideAxis ? 0 : 5 } // padding
518
- y={ config.isLollipopChart ? lollipopShapeSize * config.series.length + 2 : barWidth * config.series.length + 7 }
519
- verticalAnchor={"start"}
520
- textAnchor={"start"}
521
- >{config.runtime.yAxis.type==='date' ? formatDate(parseDate(data[barGroup.index][config.runtime.originalXAxis.dataKey])) :isHorizontal?data[barGroup.index][config.runtime.originalXAxis.dataKey]: formatNumber(data[barGroup.index][config.runtime.originalXAxis.dataKey])}
522
- </Text>
523
-
524
- { (displayNumbersOnBar) ?
525
- (textWidth + 100 < bar.y && !config.isLollipopChart) ?
526
- (
527
- <Text
528
- display={displayBar ? 'block' : 'none'}
529
- x={ bar.y - 5 } // padding
530
- y={ config.isLollipopChart ? offset : (config.barHeight / 2 ) + config.barHeight * (barGroup.bars.length - bar.index - 1) }
531
- fill={ labelColor }
532
- textAnchor="end"
533
- verticalAnchor="middle"
534
- >
535
- { xAxisValue }
536
- </Text>
537
- )
538
- : (
425
+ <animate attributeName='height' values={`0, ${lollipopShapeSize}`} dur='2.5s' />
426
+ </rect>
427
+ )}
428
+ {orientation === 'horizontal' && textWidth + 100 < bar.y
429
+ ? config.yAxis.labelPlacement === 'On Bar' && (
430
+ <Group>
431
+ <Text
432
+ innerRef={e => {
433
+ if (e) {
434
+ // use font sizes and padding to set the bar height
435
+ let elem = e.getBBox()
436
+ setTextWidth(elem.width)
437
+ config.barHeight = elem.height * 2 + horizBarLabelPadding * 2 + onBarTextSpacing / 2
438
+ config.barPadding = horizBarHeight / 2
439
+ }
440
+ }}
441
+ x={bar.y - horizBarLabelPadding}
442
+ y={barHeight * (barGroup.bars.length - bar.index - 1) + horizBarLabelPadding * 2}
443
+ fill={labelColor}
444
+ textAnchor='end'
445
+ >
446
+ {yAxisValue}
447
+ </Text>
448
+ <Text x={bar.y - horizBarLabelPadding} y={barWidth * (barGroup.bars.length - bar.index - 1) + horizBarLabelPadding * 2 + onBarTextSpacing} fill={labelColor} textAnchor='end'>
449
+ {xAxisValue}
450
+ </Text>
451
+ </Group>
452
+ )
453
+ : isLabelOnBar && (
454
+ <Group>
455
+ {/* hide y label if we're only showing data on bar */}
456
+ <Text x={bar.y + horizBarLabelPadding} y={barWidth * (barGroup.bars.length - bar.index - 1) + horizBarLabelPadding * 2} fill={'#000'} textAnchor='start' verticalAnchor='end'>
457
+ {yAxisValue}
458
+ </Text>
459
+ <Text x={bar.y + horizBarLabelPadding} y={barWidth * (barGroup.bars.length - bar.index - 1) + horizBarLabelPadding * 2 + onBarTextSpacing} fill={'#000'} textAnchor='start' verticalAnchor='start'>
460
+ {xAxisValue}
461
+ </Text>
462
+ </Group>
463
+ )}
464
+
465
+ {orientation === 'horizontal' && isLabelBelowBar && !config.yAxis.hideLabel && (
466
+ <>
539
467
  <Text
540
- display={displayBar ? 'block' : 'none'}
541
- x={ `${bar.y + (config.isLollipopChart ? 15 : 5) + (config.isLollipopChart && barGroup.bars.length === bar.index ? offset : 0 ) }`} // padding
542
- y={ config.isLollipopChart ? 0 : (config.barHeight / 2 ) + config.barHeight * (barGroup.bars.length - bar.index - 1)}
543
- fill={ '#000000'}
544
- textAnchor="start"
545
- verticalAnchor="middle"
546
- fontWeight={'normal'}
468
+ x={config.yAxis.hideAxis ? 0 : 5} // padding
469
+ y={config.isLollipopChart ? lollipopShapeSize * config.series.length + 2 : barWidth * config.series.length + 7}
470
+ verticalAnchor={'start'}
471
+ textAnchor={'start'}
547
472
  >
548
- { xAxisValue }
473
+ {config.runtime.yAxis.type === 'date'
474
+ ? formatDate(parseDate(data[barGroup.index][config.runtime.originalXAxis.dataKey]))
475
+ : isHorizontal
476
+ ? data[barGroup.index][config.runtime.originalXAxis.dataKey]
477
+ : formatNumber(data[barGroup.index][config.runtime.originalXAxis.dataKey])}
549
478
  </Text>
550
- )
551
- : ""
552
- }
553
- </>
554
- }
555
479
 
556
- { (isLabelOnYAxis && orientation === "horizontal") &&
557
- <>
558
- { (displayNumbersOnBar) ?
559
- (textWidth + 100 < bar.y && !config.isLollipopChart) ?
560
- (
561
- <Text
562
- display={displayBar ? 'block' : 'none'}
563
- x={ bar.y - 5 } // padding
564
- y={
565
- config.isLollipopChart ? (config.barHeight * (barGroup.bars.length - bar.index - 1) ) + offset :
566
- (config.barHeight * (barGroup.bars.length - bar.index - 1) ) + (config.barHeight / 2 )
567
- }
568
- fill={ labelColor }
569
- textAnchor="end"
570
- verticalAnchor="middle"
571
- >
572
- { formatNumber(xAxisValue )}
573
- </Text>
574
- )
575
- : (
576
- <Text
577
- display={displayBar ? 'block' : 'none'}
578
- x={ `${bar.y + (config.isLollipopChart ? 15 : 5)}` } // padding
579
- y={
580
- config.isLollipopChart ? (config.barHeight * (barGroup.bars.length - bar.index - 1) ) + offset :
581
- (config.barHeight * (barGroup.bars.length - bar.index - 1) ) + (config.barHeight / 2 )
582
- }
583
- fill={ '#000000' }
584
- textAnchor="start"
585
- verticalAnchor="middle"
586
- >
587
- {formatNumber( xAxisValue) }
588
- </Text>
589
- )
590
- : ""
591
- }
592
- </>
593
- }
594
- </Group>
595
- </>
596
- )}
597
- )}
598
- </Group>
599
- ))}}
480
+ {displayNumbersOnBar ? (
481
+ textWidth + 100 < bar.y && !config.isLollipopChart ? (
482
+ <Text
483
+ display={displayBar ? 'block' : 'none'}
484
+ x={bar.y - 5} // padding
485
+ y={config.isLollipopChart ? offset : config.barHeight / 2 + config.barHeight * (barGroup.bars.length - bar.index - 1)}
486
+ fill={labelColor}
487
+ textAnchor='end'
488
+ verticalAnchor='middle'
489
+ >
490
+ {xAxisValue}
491
+ </Text>
492
+ ) : (
493
+ <Text
494
+ display={displayBar ? 'block' : 'none'}
495
+ x={`${bar.y + (config.isLollipopChart ? 15 : 5) + (config.isLollipopChart && barGroup.bars.length === bar.index ? offset : 0)}`} // padding
496
+ y={config.isLollipopChart ? 0 : config.barHeight / 2 + config.barHeight * (barGroup.bars.length - bar.index - 1)}
497
+ fill={'#000000'}
498
+ textAnchor='start'
499
+ verticalAnchor='middle'
500
+ fontWeight={'normal'}
501
+ >
502
+ {xAxisValue}
503
+ </Text>
504
+ )
505
+ ) : (
506
+ ''
507
+ )}
508
+ </>
509
+ )}
510
+
511
+ {isLabelOnYAxis && orientation === 'horizontal' && (
512
+ <>
513
+ {displayNumbersOnBar ? (
514
+ textWidth + 100 < bar.y && !config.isLollipopChart ? (
515
+ <Text
516
+ display={displayBar ? 'block' : 'none'}
517
+ x={bar.y - 5} // padding
518
+ y={config.isLollipopChart ? config.barHeight * (barGroup.bars.length - bar.index - 1) + offset : config.barHeight * (barGroup.bars.length - bar.index - 1) + config.barHeight / 2}
519
+ fill={labelColor}
520
+ textAnchor='end'
521
+ verticalAnchor='middle'
522
+ >
523
+ {formatNumber(xAxisValue)}
524
+ </Text>
525
+ ) : (
526
+ <Text
527
+ display={displayBar ? 'block' : 'none'}
528
+ x={`${bar.y + (config.isLollipopChart ? 15 : 5)}`} // padding
529
+ y={config.isLollipopChart ? config.barHeight * (barGroup.bars.length - bar.index - 1) + offset : config.barHeight * (barGroup.bars.length - bar.index - 1) + config.barHeight / 2}
530
+ fill={'#000000'}
531
+ textAnchor='start'
532
+ verticalAnchor='middle'
533
+ >
534
+ {formatNumber(xAxisValue)}
535
+ </Text>
536
+ )
537
+ ) : (
538
+ ''
539
+ )}
540
+ </>
541
+ )}
542
+ </Group>
543
+ </>
544
+ )
545
+ })}
546
+ </Group>
547
+ ))
548
+ }}
600
549
  </BarGroup>
601
550
 
602
- {Object.keys(config.confidenceKeys).length > 0 ? data.map((d) => {
603
- let xPos = xScale(getXAxisData(d));
604
- let upperPos = yScale(getYAxisData(d, config.confidenceKeys.lower));
605
- let lowerPos = yScale(getYAxisData(d, config.confidenceKeys.upper));
606
- let tickWidth = 5;
607
-
608
- return (
609
- <path key={`confidence-interval-${d[config.runtime.originalXAxis.dataKey]}`} stroke="#333" strokeWidth="2px" d={`
551
+ {Object.keys(config.confidenceKeys).length > 0
552
+ ? data.map(d => {
553
+ let xPos = xScale(getXAxisData(d))
554
+ let upperPos = yScale(getYAxisData(d, config.confidenceKeys.lower))
555
+ let lowerPos = yScale(getYAxisData(d, config.confidenceKeys.upper))
556
+ let tickWidth = 5
557
+
558
+ return (
559
+ <path
560
+ key={`confidence-interval-${d[config.runtime.originalXAxis.dataKey]}`}
561
+ stroke='#333'
562
+ strokeWidth='2px'
563
+ d={`
610
564
  M${xPos - tickWidth} ${upperPos}
611
565
  L${xPos + tickWidth} ${upperPos}
612
566
  M${xPos} ${upperPos}
613
567
  L${xPos} ${lowerPos}
614
568
  M${xPos - tickWidth} ${lowerPos}
615
- L${xPos + tickWidth} ${lowerPos}`}/>
616
- );
617
- }) : ''}
569
+ L${xPos + tickWidth} ${lowerPos}`}
570
+ />
571
+ )
572
+ })
573
+ : ''}
618
574
  </Group>
619
575
  )}
620
576
  </Group>
621
577
  </ErrorBoundary>
622
- );
578
+ )
623
579
  }