@cdc/chart 4.24.9 → 4.24.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.
- package/LICENSE +201 -0
- package/dist/cdcchart.js +45911 -41739
- package/examples/feature/boxplot/boxplot-data.json +88 -22
- package/examples/feature/boxplot/boxplot.json +540 -16
- package/examples/feature/boxplot/testing.csv +7 -7
- package/examples/feature/sankey/sankey-example-data.json +0 -1
- package/examples/private/test.json +20092 -0
- package/index.html +4 -4
- package/package.json +2 -2
- package/src/CdcChart.tsx +209 -188
- package/src/_stories/Chart.CustomColors.stories.tsx +19 -0
- package/src/_stories/Chart.DynamicSeries.stories.tsx +27 -0
- package/src/_stories/Chart.Legend.Gradient.stories.tsx +74 -0
- package/src/_stories/Chart.stories.tsx +30 -3
- package/src/_stories/ChartAxisLabels.stories.tsx +20 -0
- package/src/_stories/ChartAxisTitles.stories.tsx +53 -0
- package/src/_stories/ChartEditor.stories.tsx +27 -0
- package/src/_stories/ChartLine.Suppression.stories.tsx +25 -0
- package/src/_stories/ChartPrefixSuffix.stories.tsx +159 -0
- package/src/_stories/_mock/boxplot_multiseries.json +647 -0
- package/src/_stories/_mock/dynamic_series_bar_config.json +723 -0
- package/src/_stories/_mock/dynamic_series_config.json +979 -0
- package/src/_stories/_mock/horizontal_bar.json +257 -0
- package/src/_stories/_mock/large_x_axis_labels.json +261 -0
- package/src/_stories/_mock/paired-bar.json +262 -0
- package/src/_stories/_mock/pie_with_data.json +255 -0
- package/{examples/feature/scatterplot/scatterplot.json → src/_stories/_mock/scatterplot_mock.json} +62 -92
- package/src/_stories/_mock/simplified_line.json +1510 -0
- package/src/_stories/_mock/suppression_mock.json +1549 -0
- package/src/components/Annotations/components/AnnotationDraggable.tsx +0 -3
- package/src/components/Annotations/components/AnnotationDropdown.tsx +1 -1
- package/src/components/Axis/Categorical.Axis.tsx +22 -4
- package/src/components/BarChart/components/BarChart.Horizontal.tsx +95 -16
- package/src/components/BarChart/components/BarChart.StackedHorizontal.tsx +41 -17
- package/src/components/BarChart/components/BarChart.StackedVertical.tsx +43 -9
- package/src/components/BarChart/components/BarChart.Vertical.tsx +123 -47
- package/src/components/BarChart/helpers/index.ts +23 -5
- package/src/components/BoxPlot/BoxPlot.tsx +189 -0
- package/src/components/BrushChart.tsx +3 -2
- package/src/components/DeviationBar.jsx +58 -8
- package/src/components/EditorPanel/EditorPanel.tsx +127 -102
- package/src/components/EditorPanel/components/Panels/Panel.Annotate.tsx +11 -28
- package/src/components/EditorPanel/components/Panels/Panel.BoxPlot.tsx +51 -6
- package/src/components/EditorPanel/components/Panels/Panel.General.tsx +21 -4
- package/src/components/EditorPanel/components/Panels/Panel.Regions.tsx +40 -9
- package/src/components/EditorPanel/components/Panels/Panel.Sankey.tsx +3 -3
- package/src/components/EditorPanel/components/Panels/Panel.Series.tsx +121 -56
- package/src/components/EditorPanel/components/Panels/Panel.Visual.tsx +296 -35
- package/src/components/EditorPanel/components/panels.scss +4 -6
- package/src/components/EditorPanel/editor-panel.scss +0 -8
- package/src/components/EditorPanel/helpers/tests/updateFieldRankByValue.test.ts +38 -0
- package/src/components/EditorPanel/helpers/updateFieldRankByValue.ts +42 -0
- package/src/components/EditorPanel/useEditorPermissions.ts +16 -1
- package/src/components/ForestPlot/ForestPlot.tsx +2 -3
- package/src/components/ForestPlot/ForestPlotProps.ts +2 -0
- package/src/components/Legend/Legend.Component.tsx +23 -24
- package/src/components/Legend/Legend.Suppression.tsx +25 -20
- package/src/components/Legend/Legend.tsx +16 -18
- package/src/components/Legend/helpers/index.ts +16 -19
- package/src/components/LegendWrapper.tsx +3 -1
- package/src/components/LineChart/components/LineChart.Circle.tsx +10 -0
- package/src/components/LineChart/helpers.ts +48 -43
- package/src/components/LineChart/index.tsx +88 -82
- package/src/components/LinearChart.tsx +747 -562
- package/src/components/PairedBarChart.jsx +50 -10
- package/src/components/PieChart/PieChart.tsx +1 -6
- package/src/components/Regions/components/Regions.tsx +33 -19
- package/src/components/Sankey/index.tsx +50 -32
- package/src/components/Sankey/sankey.scss +6 -5
- package/src/components/Sankey/useSankeyAlert.tsx +60 -0
- package/src/components/ScatterPlot/ScatterPlot.jsx +20 -4
- package/src/components/ZoomBrush.tsx +25 -6
- package/src/coreStyles_chart.scss +3 -0
- package/src/data/initial-state.js +8 -10
- package/src/helpers/configHelpers.ts +28 -0
- package/src/helpers/handleRankByValue.ts +15 -0
- package/src/helpers/sizeHelpers.ts +25 -0
- package/src/helpers/tests/handleRankByValue.test.ts +37 -0
- package/src/helpers/tests/sizeHelpers.test.ts +80 -0
- package/src/hooks/useColorPalette.js +10 -2
- package/src/hooks/useLegendClasses.ts +13 -22
- package/src/hooks/useMinMax.ts +27 -13
- package/src/hooks/useReduceData.ts +43 -10
- package/src/hooks/useScales.ts +87 -38
- package/src/hooks/useTooltip.tsx +62 -53
- package/src/index.jsx +1 -0
- package/src/scss/DataTable.scss +5 -4
- package/src/scss/main.scss +57 -70
- package/src/types/ChartConfig.ts +43 -34
- package/src/types/ChartContext.ts +22 -15
- package/src/types/ForestPlot.ts +8 -0
- package/src/_stories/Chart.Legend.Gradient.tsx +0 -19
- package/src/_stories/ChartBrush.stories.tsx +0 -19
- package/src/components/BoxPlot/BoxPlot.jsx +0 -111
- package/src/components/LinearChart.jsx +0 -817
|
@@ -32,11 +32,8 @@ const Annotations = ({ xScale, yScale, xScaleAnnotation, xMax, svgRef, onDragSta
|
|
|
32
32
|
// prettier-ignore
|
|
33
33
|
const {
|
|
34
34
|
config,
|
|
35
|
-
currentViewport,
|
|
36
35
|
dimensions,
|
|
37
|
-
isDraggingAnnotation,
|
|
38
36
|
isEditor,
|
|
39
|
-
isLegendBottom,
|
|
40
37
|
updateConfig
|
|
41
38
|
} = useContext(ConfigContext)
|
|
42
39
|
|
|
@@ -30,7 +30,7 @@ const AnnotationDropdown = () => {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const handleSectionClasses = () => {
|
|
33
|
-
const classes = [`data-table-container`, viewport, `d-block`, `d-lg-none`]
|
|
33
|
+
const classes = [`data-table-container`, viewport, `d-block`, `d-lg-none`, `w-100`]
|
|
34
34
|
|
|
35
35
|
if (config.general.showAnnotationDropdown) {
|
|
36
36
|
classes.push('d-lg-block')
|
|
@@ -7,9 +7,10 @@ import ConfigContext from '../../ConfigContext'
|
|
|
7
7
|
import chroma from 'chroma-js'
|
|
8
8
|
import createBarElement from '@cdc/core/components/createBarElement'
|
|
9
9
|
import { useBarChart } from '../../hooks/useBarChart'
|
|
10
|
+
import { getTextWidth } from '@cdc/core/helpers/getTextWidth'
|
|
10
11
|
|
|
11
12
|
const CategoricalYAxis = ({ yMax, leftSize, max, xMax }) => {
|
|
12
|
-
const { config
|
|
13
|
+
const { config } = useContext(ConfigContext)
|
|
13
14
|
const { fontSize } = useBarChart()
|
|
14
15
|
|
|
15
16
|
const { orientation } = config
|
|
@@ -82,7 +83,14 @@ const CategoricalYAxis = ({ yMax, leftSize, max, xMax }) => {
|
|
|
82
83
|
const keys = Object.keys(transformedData[0])
|
|
83
84
|
return (
|
|
84
85
|
<Group left={leftSize - xScale.bandwidth()} top={0}>
|
|
85
|
-
<BarStack
|
|
86
|
+
<BarStack
|
|
87
|
+
data={transformedData}
|
|
88
|
+
keys={keys}
|
|
89
|
+
x={() => xScale(xScaleValue)}
|
|
90
|
+
xScale={xScale}
|
|
91
|
+
yScale={yScale}
|
|
92
|
+
color={colorScale}
|
|
93
|
+
>
|
|
86
94
|
{barStacks =>
|
|
87
95
|
barStacks.map(barStack =>
|
|
88
96
|
barStack.bars.map(bar => {
|
|
@@ -96,7 +104,11 @@ const CategoricalYAxis = ({ yMax, leftSize, max, xMax }) => {
|
|
|
96
104
|
</li></ul>`
|
|
97
105
|
return (
|
|
98
106
|
<Group key={`${barStack.index}--${bar.index}--${orientation}`}>
|
|
99
|
-
<Group
|
|
107
|
+
<Group
|
|
108
|
+
key={`bar-stack-${barStack.index}-${bar.index}`}
|
|
109
|
+
id={`barStack${barStack.index}-${bar.index}`}
|
|
110
|
+
className='stack vertical'
|
|
111
|
+
>
|
|
100
112
|
{createBarElement({
|
|
101
113
|
type: 'axisBar',
|
|
102
114
|
config: config,
|
|
@@ -126,7 +138,13 @@ const CategoricalYAxis = ({ yMax, leftSize, max, xMax }) => {
|
|
|
126
138
|
{bar.key}
|
|
127
139
|
</Text>
|
|
128
140
|
{/* gridLines */}
|
|
129
|
-
{config.runtime.yAxis.gridLines &&
|
|
141
|
+
{config.runtime.yAxis.gridLines && (
|
|
142
|
+
<Line
|
|
143
|
+
from={{ x: bar.x + xScale.bandwidth(), y: bar.y }}
|
|
144
|
+
to={{ x: xMax + xScale.bandwidth(), y: bar.y }}
|
|
145
|
+
stroke='#d6d6d6'
|
|
146
|
+
/>
|
|
147
|
+
)}
|
|
130
148
|
{/* White background spacing between stackes */}
|
|
131
149
|
{!isLastIndex && <rect x={bar.x} y={bar.y} width={bar.width} height={1} fill={'#fff'}></rect>}
|
|
132
150
|
{/* Right side Axis line */}
|
|
@@ -14,6 +14,7 @@ import { BarGroup } from '@visx/shape'
|
|
|
14
14
|
import { getContrastColor } from '@cdc/core/helpers/cove/accessibility'
|
|
15
15
|
import createBarElement from '@cdc/core/components/createBarElement'
|
|
16
16
|
import { getBarConfig, testZeroValue } from '../helpers'
|
|
17
|
+
import { getTextWidth } from '@cdc/core/helpers/getTextWidth'
|
|
17
18
|
|
|
18
19
|
// Third party libraries
|
|
19
20
|
import chroma from 'chroma-js'
|
|
@@ -24,9 +25,38 @@ import { ChartContext } from '../../../types/ChartContext'
|
|
|
24
25
|
|
|
25
26
|
export const BarChartHorizontal = () => {
|
|
26
27
|
const { xScale, yScale, yMax, seriesScale } = useContext<BarChartContextValues>(BarChartContext)
|
|
27
|
-
const {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const {
|
|
29
|
+
transformedData: data,
|
|
30
|
+
tableData,
|
|
31
|
+
colorScale,
|
|
32
|
+
seriesHighlight,
|
|
33
|
+
config,
|
|
34
|
+
formatNumber,
|
|
35
|
+
formatDate,
|
|
36
|
+
parseDate,
|
|
37
|
+
setSharedFilter,
|
|
38
|
+
isNumber,
|
|
39
|
+
getYAxisData,
|
|
40
|
+
getXAxisData
|
|
41
|
+
} = useContext<ChartContext>(ConfigContext)
|
|
42
|
+
const {
|
|
43
|
+
isHorizontal,
|
|
44
|
+
barBorderWidth,
|
|
45
|
+
updateBars,
|
|
46
|
+
assignColorsToValues,
|
|
47
|
+
section,
|
|
48
|
+
fontSize,
|
|
49
|
+
isLabelBelowBar,
|
|
50
|
+
displayNumbersOnBar,
|
|
51
|
+
lollipopBarWidth,
|
|
52
|
+
lollipopShapeSize,
|
|
53
|
+
getHighlightedBarColorByValue,
|
|
54
|
+
getHighlightedBarByValue,
|
|
55
|
+
getAdditionalColumn,
|
|
56
|
+
hoveredBar,
|
|
57
|
+
onMouseLeaveBar,
|
|
58
|
+
onMouseOverBar
|
|
59
|
+
} = useBarChart()
|
|
30
60
|
|
|
31
61
|
const { HighLightedBarUtils } = useHighlightedBars(config)
|
|
32
62
|
|
|
@@ -49,13 +79,29 @@ export const BarChartHorizontal = () => {
|
|
|
49
79
|
>
|
|
50
80
|
{barGroups => {
|
|
51
81
|
return updateBars(barGroups).map((barGroup, index) => (
|
|
52
|
-
<Group
|
|
82
|
+
<Group
|
|
83
|
+
className={`bar-group-${barGroup.index}-${barGroup.x0}--${index} ${config.orientation}`}
|
|
84
|
+
key={`bar-group-${barGroup.index}-${barGroup.x0}--${index}`}
|
|
85
|
+
id={`bar-group-${barGroup.index}-${barGroup.x0}--${index}`}
|
|
86
|
+
top={barGroup.y}
|
|
87
|
+
>
|
|
53
88
|
{barGroup.bars.map((bar, index) => {
|
|
54
89
|
const scaleVal = config.yAxis.type === 'logarithmic' ? 0.1 : 0
|
|
55
|
-
let highlightedBarValues = config.highlightedBarValues
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
90
|
+
let highlightedBarValues = config.highlightedBarValues
|
|
91
|
+
.map(item => item.value)
|
|
92
|
+
.filter(item => item !== ('' || undefined))
|
|
93
|
+
highlightedBarValues =
|
|
94
|
+
config.xAxis.type === 'date'
|
|
95
|
+
? HighLightedBarUtils.formatDates(highlightedBarValues)
|
|
96
|
+
: highlightedBarValues
|
|
97
|
+
let transparentBar =
|
|
98
|
+
config.legend.behavior === 'highlight' &&
|
|
99
|
+
seriesHighlight.length > 0 &&
|
|
100
|
+
seriesHighlight.indexOf(bar.key) === -1
|
|
101
|
+
let displayBar =
|
|
102
|
+
config.legend.behavior === 'highlight' ||
|
|
103
|
+
seriesHighlight.length === 0 ||
|
|
104
|
+
seriesHighlight.indexOf(bar.key) !== -1
|
|
59
105
|
let barHeight = config.barHeight
|
|
60
106
|
let numbericBarHeight = parseInt(!config.isLollipopChart ? barHeight : lollipopBarWidth)
|
|
61
107
|
if (isNaN(numbericBarHeight)) {
|
|
@@ -65,10 +111,17 @@ export const BarChartHorizontal = () => {
|
|
|
65
111
|
const defaultBarWidth = Math.abs(xScale(bar.value) - xScale(scaleVal))
|
|
66
112
|
const isPositiveBar = bar.value >= 0 && isNumber(bar.value)
|
|
67
113
|
|
|
68
|
-
const {
|
|
114
|
+
const {
|
|
115
|
+
barWidthHorizontal: barWidth,
|
|
116
|
+
isSuppressed,
|
|
117
|
+
getAbsentDataLabel
|
|
118
|
+
} = getBarConfig({ bar, defaultBarWidth, config, isNumber, isVertical: false })
|
|
69
119
|
const barX = bar.value < 0 ? Math.abs(xScale(bar.value)) : xScale(scaleVal)
|
|
70
120
|
const yAxisValue = formatNumber(bar.value, 'left')
|
|
71
|
-
const xAxisValue =
|
|
121
|
+
const xAxisValue =
|
|
122
|
+
config.runtime[section].type === 'date'
|
|
123
|
+
? formatDate(parseDate(data[barGroup.index][config.runtime.originalXAxis.dataKey]))
|
|
124
|
+
: data[barGroup.index][config.runtime.originalXAxis.dataKey]
|
|
72
125
|
|
|
73
126
|
const barPosition = !isPositiveBar ? 'below' : 'above'
|
|
74
127
|
const absentDataLabel = getAbsentDataLabel(yAxisValue)
|
|
@@ -96,7 +149,9 @@ export const BarChartHorizontal = () => {
|
|
|
96
149
|
// create new Index for bars with negative values
|
|
97
150
|
const newIndex = bar.value < 0 ? -1 : index
|
|
98
151
|
|
|
99
|
-
let yAxisTooltip = config.runtime.yAxis.label
|
|
152
|
+
let yAxisTooltip = config.runtime.yAxis.label
|
|
153
|
+
? `${config.runtime.yAxis.label}: ${xAxisValue}`
|
|
154
|
+
: xAxisValue
|
|
100
155
|
const additionalColTooltip = getAdditionalColumn(hoveredBar)
|
|
101
156
|
const tooltipBody = `${config.runtime.seriesLabels[bar.key]}: ${yAxisValue}`
|
|
102
157
|
const tooltip = `<ul>
|
|
@@ -108,15 +163,28 @@ export const BarChartHorizontal = () => {
|
|
|
108
163
|
// configure colors
|
|
109
164
|
let labelColor = '#000000'
|
|
110
165
|
labelColor = HighLightedBarUtils.checkFontColor(yAxisValue, highlightedBarValues, labelColor) // Set if background is transparent'
|
|
111
|
-
let barColor =
|
|
166
|
+
let barColor =
|
|
167
|
+
config.runtime.seriesLabels && config.runtime.seriesLabels[bar.key]
|
|
168
|
+
? colorScale(config.runtime.seriesLabels[bar.key])
|
|
169
|
+
: colorScale(bar.key)
|
|
112
170
|
barColor = assignColorsToValues(barGroups.length, barGroup.index, barColor) // Color code by category
|
|
113
171
|
const isRegularLollipopColor = config.isLollipopChart && config.lollipopColorStyle === 'regular'
|
|
114
172
|
const isTwoToneLollipopColor = config.isLollipopChart && config.lollipopColorStyle === 'two-tone'
|
|
115
173
|
const isHighlightedBar = highlightedBarValues?.includes(xAxisValue)
|
|
116
174
|
const highlightedBarColor = getHighlightedBarColorByValue(xAxisValue)
|
|
117
175
|
const highlightedBar = getHighlightedBarByValue(xAxisValue)
|
|
118
|
-
const borderColor = isHighlightedBar
|
|
119
|
-
|
|
176
|
+
const borderColor = isHighlightedBar
|
|
177
|
+
? highlightedBarColor
|
|
178
|
+
: config.barHasBorder === 'true'
|
|
179
|
+
? '#000'
|
|
180
|
+
: 'transparent'
|
|
181
|
+
const borderWidth = isHighlightedBar
|
|
182
|
+
? highlightedBar.borderWidth
|
|
183
|
+
: config.isLollipopChart
|
|
184
|
+
? 0
|
|
185
|
+
: config.barHasBorder === 'true'
|
|
186
|
+
? barBorderWidth
|
|
187
|
+
: 0
|
|
120
188
|
const displaylollipopShape = testZeroValue(bar.value) ? 'none' : 'block'
|
|
121
189
|
|
|
122
190
|
// update label color
|
|
@@ -176,7 +244,12 @@ export const BarChartHorizontal = () => {
|
|
|
176
244
|
|
|
177
245
|
const hasAsterisk = String(pd.symbol).includes('Asterisk')
|
|
178
246
|
const verticalAnchor = hasAsterisk ? 'middle' : 'end'
|
|
179
|
-
const iconSize =
|
|
247
|
+
const iconSize =
|
|
248
|
+
pd.symbol === 'Asterisk'
|
|
249
|
+
? barHeight * 1.2
|
|
250
|
+
: pd.symbol === 'Double Asterisk'
|
|
251
|
+
? barHeight
|
|
252
|
+
: barHeight / 1.5
|
|
180
253
|
const fillColor = pd.displayGray ? '#8b8b8a' : '#000'
|
|
181
254
|
return (
|
|
182
255
|
<Text // prettier-ignore
|
|
@@ -240,7 +313,13 @@ export const BarChartHorizontal = () => {
|
|
|
240
313
|
</Text>
|
|
241
314
|
)}
|
|
242
315
|
{isLabelBelowBar && !config.yAxis.hideLabel && (
|
|
243
|
-
<Text
|
|
316
|
+
<Text
|
|
317
|
+
x={config.yAxis.hideAxis ? 0 : 5}
|
|
318
|
+
y={barGroup.height}
|
|
319
|
+
dy={4}
|
|
320
|
+
verticalAnchor={'start'}
|
|
321
|
+
textAnchor={'start'}
|
|
322
|
+
>
|
|
244
323
|
{config.runtime.yAxis.type === 'date'
|
|
245
324
|
? formatDate(parseDate(data[barGroup.index][config.runtime.originalXAxis.dataKey]))
|
|
246
325
|
: isHorizontal
|
|
@@ -5,6 +5,7 @@ import { BarStackHorizontal } from '@visx/shape'
|
|
|
5
5
|
import { Group } from '@visx/group'
|
|
6
6
|
import { Text } from '@visx/text'
|
|
7
7
|
import { getContrastColor } from '@cdc/core/helpers/cove/accessibility'
|
|
8
|
+
import { getTextWidth } from '@cdc/core/helpers/getTextWidth'
|
|
8
9
|
|
|
9
10
|
// types
|
|
10
11
|
import BarChartContext, { type BarChartContextValues } from './context'
|
|
@@ -22,7 +23,6 @@ const BarChartStackedHorizontal = () => {
|
|
|
22
23
|
config,
|
|
23
24
|
formatDate,
|
|
24
25
|
formatNumber,
|
|
25
|
-
getTextWidth,
|
|
26
26
|
parseDate,
|
|
27
27
|
seriesHighlight,
|
|
28
28
|
setSharedFilter,
|
|
@@ -37,18 +37,38 @@ const BarChartStackedHorizontal = () => {
|
|
|
37
37
|
config.visualizationSubType === 'stacked' &&
|
|
38
38
|
isHorizontal && (
|
|
39
39
|
<>
|
|
40
|
-
<BarStackHorizontal
|
|
40
|
+
<BarStackHorizontal
|
|
41
|
+
data={data}
|
|
42
|
+
keys={barStackedSeriesKeys}
|
|
43
|
+
height={yMax}
|
|
44
|
+
y={d => d[config.runtime.yAxis.dataKey]}
|
|
45
|
+
xScale={xScale}
|
|
46
|
+
yScale={yScale}
|
|
47
|
+
color={colorScale}
|
|
48
|
+
offset='none'
|
|
49
|
+
>
|
|
41
50
|
{barStacks =>
|
|
42
51
|
barStacks.map(barStack =>
|
|
43
52
|
updateBars(barStack.bars).map((bar, index) => {
|
|
44
|
-
const transparentBar =
|
|
45
|
-
|
|
53
|
+
const transparentBar =
|
|
54
|
+
config.legend.behavior === 'highlight' &&
|
|
55
|
+
seriesHighlight.length > 0 &&
|
|
56
|
+
seriesHighlight.indexOf(bar.key) === -1
|
|
57
|
+
const displayBar =
|
|
58
|
+
config.legend.behavior === 'highlight' ||
|
|
59
|
+
seriesHighlight.length === 0 ||
|
|
60
|
+
seriesHighlight.indexOf(bar.key) !== -1
|
|
46
61
|
config.barHeight = Number(config.barHeight)
|
|
47
62
|
const labelColor = getContrastColor('#000', colorScale(config.runtime.seriesLabels[bar.key]))
|
|
48
63
|
// tooltips
|
|
49
64
|
const xAxisValue = formatNumber(data[bar.index][bar.key], 'left')
|
|
50
|
-
const yAxisValue =
|
|
51
|
-
|
|
65
|
+
const yAxisValue =
|
|
66
|
+
config.runtime.yAxis.type === 'date'
|
|
67
|
+
? formatDate(parseDate(data[bar.index][config.runtime.originalXAxis.dataKey]))
|
|
68
|
+
: data[bar.index][config.runtime.originalXAxis.dataKey]
|
|
69
|
+
const yAxisTooltip = config.runtime.yAxis.label
|
|
70
|
+
? `${config.runtime.yAxis.label}: ${yAxisValue}`
|
|
71
|
+
: yAxisValue
|
|
52
72
|
const textWidth = getTextWidth(xAxisValue, `normal ${fontSize[config.fontSize]}px sans-serif`)
|
|
53
73
|
const additionalColTooltip = getAdditionalColumn(hoveredBar)
|
|
54
74
|
const tooltipBody = `${config.runtime.seriesLabels[bar.key]}: ${xAxisValue}`
|
|
@@ -93,17 +113,21 @@ const BarChartStackedHorizontal = () => {
|
|
|
93
113
|
}
|
|
94
114
|
})}
|
|
95
115
|
|
|
96
|
-
{orientation === 'horizontal' &&
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
116
|
+
{orientation === 'horizontal' &&
|
|
117
|
+
visualizationSubType === 'stacked' &&
|
|
118
|
+
isLabelBelowBar &&
|
|
119
|
+
barStack.index === 0 &&
|
|
120
|
+
!config.yAxis.hideLabel && (
|
|
121
|
+
<Text
|
|
122
|
+
x={`${bar.x + (config.isLollipopChart ? 15 : 5)}`} // padding
|
|
123
|
+
y={bar.y + bar.height * 1.2}
|
|
124
|
+
fill={'#000000'}
|
|
125
|
+
textAnchor='start'
|
|
126
|
+
verticalAnchor='start'
|
|
127
|
+
>
|
|
128
|
+
{yAxisValue}
|
|
129
|
+
</Text>
|
|
130
|
+
)}
|
|
107
131
|
|
|
108
132
|
{displayNumbersOnBar && textWidth < bar.width && (
|
|
109
133
|
<Text
|
|
@@ -13,32 +13,62 @@ import createBarElement from '@cdc/core/components/createBarElement'
|
|
|
13
13
|
const BarChartStackedVertical = () => {
|
|
14
14
|
const [barWidth, setBarWidth] = useState(0)
|
|
15
15
|
const { xScale, yScale, seriesScale, xMax, yMax } = useContext(BarChartContext)
|
|
16
|
-
const { transformedData, colorScale, seriesHighlight, config, formatNumber, formatDate, parseDate, setSharedFilter } =
|
|
17
|
-
|
|
16
|
+
const { transformedData, colorScale, seriesHighlight, config, formatNumber, formatDate, parseDate, setSharedFilter } =
|
|
17
|
+
useContext(ConfigContext)
|
|
18
|
+
const {
|
|
19
|
+
isHorizontal,
|
|
20
|
+
barBorderWidth,
|
|
21
|
+
applyRadius,
|
|
22
|
+
hoveredBar,
|
|
23
|
+
getAdditionalColumn,
|
|
24
|
+
onMouseLeaveBar,
|
|
25
|
+
onMouseOverBar,
|
|
26
|
+
barStackedSeriesKeys
|
|
27
|
+
} = useBarChart()
|
|
18
28
|
const { orientation } = config
|
|
19
29
|
|
|
20
30
|
const data = config.brush?.active && config.brush.data?.length ? config.brush.data : transformedData
|
|
21
31
|
const isDateAxisType = config.runtime.xAxis.type === 'date-time' || config.runtime.xAxis.type === 'date'
|
|
32
|
+
const isDateTimeScaleAxisType = config.runtime.xAxis.type === 'date-time'
|
|
22
33
|
|
|
23
34
|
return (
|
|
24
35
|
config.visualizationSubType === 'stacked' &&
|
|
25
36
|
!isHorizontal && (
|
|
26
37
|
<>
|
|
27
|
-
<BarStack
|
|
38
|
+
<BarStack
|
|
39
|
+
data={data}
|
|
40
|
+
keys={barStackedSeriesKeys}
|
|
41
|
+
x={d => d[config.runtime.xAxis.dataKey]}
|
|
42
|
+
xScale={xScale}
|
|
43
|
+
yScale={yScale}
|
|
44
|
+
color={colorScale}
|
|
45
|
+
>
|
|
28
46
|
{barStacks =>
|
|
29
47
|
barStacks.reverse().map(barStack =>
|
|
30
48
|
barStack.bars.map(bar => {
|
|
31
|
-
let transparentBar =
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
let transparentBar =
|
|
50
|
+
config.legend.behavior === 'highlight' &&
|
|
51
|
+
seriesHighlight.length > 0 &&
|
|
52
|
+
seriesHighlight.indexOf(bar.key) === -1
|
|
53
|
+
let displayBar =
|
|
54
|
+
config.legend.behavior === 'highlight' ||
|
|
55
|
+
seriesHighlight.length === 0 ||
|
|
56
|
+
seriesHighlight.indexOf(bar.key) !== -1
|
|
57
|
+
let barThickness = isDateAxisType
|
|
58
|
+
? seriesScale.range()[1] - seriesScale.range()[0]
|
|
59
|
+
: xMax / barStack.bars.length
|
|
34
60
|
if (config.runtime.xAxis.type !== 'date') barThickness = config.barThickness * barThickness
|
|
35
61
|
// tooltips
|
|
36
62
|
const rawXValue = bar.bar.data[config.runtime.xAxis.dataKey]
|
|
37
63
|
const xAxisValue = isDateAxisType ? formatDate(parseDate(rawXValue)) : rawXValue
|
|
38
64
|
const yAxisValue = formatNumber(bar.bar ? bar.bar.data[bar.key] : 0, 'left')
|
|
39
65
|
if (!yAxisValue) return
|
|
40
|
-
const barX =
|
|
41
|
-
|
|
66
|
+
const barX =
|
|
67
|
+
xScale(isDateAxisType ? parseDate(rawXValue) : rawXValue) -
|
|
68
|
+
(isDateTimeScaleAxisType ? barThickness / 2 : 0)
|
|
69
|
+
const xAxisTooltip = config.runtime.xAxis.label
|
|
70
|
+
? `${config.runtime.xAxis.label}: ${xAxisValue}`
|
|
71
|
+
: xAxisValue
|
|
42
72
|
const additionalColTooltip = getAdditionalColumn(hoveredBar)
|
|
43
73
|
const tooltipBody = `${config.runtime.seriesLabels[bar.key]}: ${yAxisValue}`
|
|
44
74
|
const tooltip = `<ul>
|
|
@@ -51,7 +81,11 @@ const BarChartStackedVertical = () => {
|
|
|
51
81
|
|
|
52
82
|
return (
|
|
53
83
|
<Group key={`${barStack.index}--${bar.index}--${orientation}`}>
|
|
54
|
-
<Group
|
|
84
|
+
<Group
|
|
85
|
+
key={`bar-stack-${barStack.index}-${bar.index}`}
|
|
86
|
+
id={`barStack${barStack.index}-${bar.index}`}
|
|
87
|
+
className='stack vertical'
|
|
88
|
+
>
|
|
55
89
|
{createBarElement({
|
|
56
90
|
config: config,
|
|
57
91
|
seriesHighlight,
|