@cdc/chart 4.23.7 → 4.23.8
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 +27964 -26942
- package/examples/feature/__data__/area-chart-date-apple.json +5122 -0
- package/examples/feature/__data__/city-temperature.json +2198 -0
- package/examples/feature/area/area-chart-category.json +45 -45
- package/examples/feature/area/area-chart-date-apple.json +10376 -0
- package/examples/feature/area/area-chart-date-city-temperature.json +4528 -0
- package/examples/feature/area/area-chart-date.json +111 -3
- package/examples/feature/forest-plot/broken.json +700 -0
- package/examples/feature/forest-plot/data.csv +24 -0
- package/examples/feature/forest-plot/forest-plot.json +717 -0
- package/examples/feature/pie/planet-pie-example-config.json +1 -1
- package/examples/private/confidence_interval_test.json +248 -0
- package/examples/private/tooltip-issue.json +45275 -0
- package/index.html +13 -11
- package/package.json +4 -3
- package/src/CdcChart.jsx +24 -14
- package/src/components/AreaChart.jsx +84 -59
- package/src/components/BarChart.Horizontal.jsx +251 -0
- package/src/components/BarChart.StackedHorizontal.jsx +118 -0
- package/src/components/BarChart.StackedVertical.jsx +93 -0
- package/src/components/BarChart.Vertical.jsx +204 -0
- package/src/components/BarChart.jsx +14 -674
- package/src/components/BarChartType.jsx +15 -0
- package/src/components/BrushHandle.jsx +17 -0
- package/src/components/DataTable.jsx +63 -21
- package/src/components/EditorPanel.jsx +351 -303
- package/src/components/ForestPlot.jsx +191 -0
- package/src/components/ForestPlotSettings.jsx +508 -0
- package/src/components/LineChart.jsx +2 -2
- package/src/components/LinearChart.jsx +115 -310
- package/src/data/initial-state.js +43 -0
- package/src/hooks/useBarChart.js +186 -0
- package/src/hooks/useEditorPermissions.js +218 -0
- package/src/hooks/useMinMax.js +15 -3
- package/src/hooks/useScales.js +45 -2
- package/src/hooks/useTooltip.jsx +407 -0
- package/src/scss/main.scss +7 -0
package/index.html
CHANGED
|
@@ -34,15 +34,19 @@
|
|
|
34
34
|
-->
|
|
35
35
|
|
|
36
36
|
<!-- GENERIC CHART TYPES -->
|
|
37
|
-
|
|
38
|
-
<!-- <div class="react-container" data-config="/
|
|
37
|
+
<div class="react-container" data-config="/examples/private/tooltip-issue.json"></div>
|
|
38
|
+
<!-- <div class="react-container" data-config="https://cdc.gov/poxvirus/mpox/modules/data-viz/mpx-trends_1.json"></div> -->
|
|
39
|
+
<!-- <div class="react-container" data-config="/examples/private/mpox-bar-test-aug-31.json"></div> -->
|
|
40
|
+
<!-- <div class="react-container" data-config="/examples/feature/area/area-chart-date-city-temperature.json"></div> -->
|
|
41
|
+
<!-- <div class="react-container" data-config="/examples/feature/area/area-chart-date-apple.json"></div> -->
|
|
42
|
+
<!-- <div class="react-container" data-config="/examples/feature/forest-plot/broken.json"></div> -->
|
|
43
|
+
<!-- <div class="react-container" data-config="/examples/feature/forest-plot/forest-plot.json"></div> -->
|
|
39
44
|
<!-- <div class="react-container" data-config="/examples/feature/pie/planet-pie-example-config.json"></div> -->
|
|
40
45
|
<!-- <div class="react-container" data-config="/examples/feature/line/line-chart.json"></div> -->
|
|
41
|
-
<div class="react-container" data-config="/examples/feature/forecasting/index.json"></div>
|
|
42
46
|
<!-- <div class="react-container" data-config="/examples/feature/forecasting/forecasting.json"></div> -->
|
|
43
47
|
<!-- <div class="react-container" data-config="/examples/feature/forecasting/combo-forecasting.json"></div> -->
|
|
44
48
|
<!-- <div class="react-container" data-config="/examples/feature/forecasting/effective_reproduction.json"></div> -->
|
|
45
|
-
|
|
49
|
+
<div class="react-container" data-config="/examples/feature/area/area-chart-date.json"></div>
|
|
46
50
|
<!-- <div class="react-container" data-config="/examples/feature/area/area-chart-category.json"></div> -->
|
|
47
51
|
<!-- <div class="react-container" data-config="/examples/feature/scatterplot/scatterplot.json"></div> -->
|
|
48
52
|
<!-- <div class="react-container" data-config="/examples/feature/deviation/planet-deviation-config.json"></div> -->
|
|
@@ -54,10 +58,9 @@
|
|
|
54
58
|
<!-- BAR -->
|
|
55
59
|
<!-- <div class="react-container" data-config="/examples/feature/bar/planet-example-config.json"></div> -->
|
|
56
60
|
<!-- <div class="react-container" data-config="/examples/feature/bar/planet-chart-horizontal-example-config.json"></div> -->
|
|
57
|
-
<!-- <div class="react-container" data-config="/examples/feature/bar/new.json"></div> -->
|
|
58
61
|
<!-- <div class="react-container" data-config="/examples/feature/bar/example-bar-chart.json"></div> -->
|
|
59
62
|
<!-- <div class="react-container" data-config="/examples/feature/bar/horizontal-chart-max-increase.json"></div> -->
|
|
60
|
-
|
|
63
|
+
<div class="react-container" data-config="/examples/feature/bar/horizontal-chart.json"></div>
|
|
61
64
|
<!-- <div class="react-container" data-config="/examples/feature/bar/horizontal-stacked-bar-chart.json"></div> -->
|
|
62
65
|
<!-- <div class="react-container" data-config="/examples/feature/bar/planet-chart-horizontal-example-config.json"></div> -->
|
|
63
66
|
|
|
@@ -65,12 +68,12 @@
|
|
|
65
68
|
<!-- <div class="react-container" data-config="/examples/feature/sparkline/example-sparkline.json"></div> -->
|
|
66
69
|
|
|
67
70
|
<!-- TESTS DATE EXCLUSIONS -->
|
|
68
|
-
<div class="react-container" data-config="/examples/feature/tests-date-exclusions/date-exclusions-config.json"></div>
|
|
71
|
+
<!-- <div class="react-container" data-config="/examples/feature/tests-date-exclusions/date-exclusions-config.json"></div> -->
|
|
69
72
|
<!-- <div class="react-container" data-config="/examples/feature/tests-case-rate/case-rate-example-config.json"></div> -->
|
|
70
73
|
|
|
71
74
|
<!-- TESTS BIG SMALL-->
|
|
72
75
|
<!-- <div class="react-container" data-config="/examples/feature/tests-big-small/big-small-test-line.json"></div> -->
|
|
73
|
-
<!-- <div class="react-container" data-config="/examples/feature/tests-big-small/big-small-test-bar.json"></div>
|
|
76
|
+
<!-- <div class="react-container" data-config="/examples/feature/tests-big-small/big-small-test-bar.json"></div> -->
|
|
74
77
|
<!-- <div class="react-container" data-config="/examples/feature/tests-big-small/big-small-test-negative.json"></div> -->
|
|
75
78
|
<!-- <div class="react-container" data-config="/examples/feature/tests-big-small/line-chart-max-increase.json"></div> -->
|
|
76
79
|
|
|
@@ -105,12 +108,11 @@
|
|
|
105
108
|
|
|
106
109
|
<!-- VERTICAL BAR CHARTS -->
|
|
107
110
|
<!-- <div class="react-container" data-config="/examples/gallery/bar-chart-vertical/combo-line-chart.json"></div> -->
|
|
108
|
-
<!-- <div class="react-container" data-config="/examples/
|
|
109
|
-
<div class="react-container" data-config="/examples/gallery/bar-chart-vertical/vertical-bar-chart-categorical.json"></div>
|
|
111
|
+
<!-- <div class="react-container" data-config="/examples/gallery/bar-chart-vertical/vertical-bar-chart-categorical.json"></div> -->
|
|
110
112
|
<!-- <div class="react-container" data-config="/examples/gallery/bar-chart-vertical/vertical-bar-chart-stacked.json"></div> -->
|
|
111
113
|
<!-- <div class="react-container" data-config="/examples/gallery/bar-chart-vertical/vertical-bar-chart-confidence.json"></div> -->
|
|
112
114
|
<!-- <div class="react-container" data-config="/examples/gallery/bar-chart-vertical/vertical-bar-chart-confidence.json"></div> -->
|
|
113
|
-
|
|
115
|
+
<div class="react-container" data-config="/examples/gallery/bar-chart-vertical/vertical-bar-chart.json"></div>
|
|
114
116
|
|
|
115
117
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
116
118
|
</body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdc/chart",
|
|
3
|
-
"version": "4.23.
|
|
3
|
+
"version": "4.23.8",
|
|
4
4
|
"description": "React component for visualizing tabular data in various types of charts",
|
|
5
5
|
"moduleName": "CdcChart",
|
|
6
6
|
"main": "dist/cdcchart",
|
|
@@ -29,13 +29,14 @@
|
|
|
29
29
|
"@visx/axis": "^3.0.0",
|
|
30
30
|
"@visx/curve": "^3.0.0",
|
|
31
31
|
"@visx/event": "^3.0.1",
|
|
32
|
+
"@visx/glyph": "^3.3.0",
|
|
32
33
|
"@visx/gradient": "^3.0.0",
|
|
33
34
|
"@visx/group": "^3.0.0",
|
|
34
35
|
"@visx/legend": "^3.0.0",
|
|
35
36
|
"@visx/marker": "^3.0.0",
|
|
36
37
|
"@visx/mock-data": "^3.0.0",
|
|
37
38
|
"@visx/scale": "^3.0.0",
|
|
38
|
-
"@visx/shape": "^3.
|
|
39
|
+
"@visx/shape": "^3.3.0",
|
|
39
40
|
"@visx/stats": "^3.0.0",
|
|
40
41
|
"@visx/text": "^3.0.0",
|
|
41
42
|
"@visx/tooltip": "^3.0.0",
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
"react": "^18.2.0",
|
|
58
59
|
"react-dom": "^18.2.0"
|
|
59
60
|
},
|
|
60
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "ba0a072a40c430baf121ad5ece0165f52a414b86",
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"resize-observer-polyfill": "^1.5.1"
|
|
63
64
|
}
|
package/src/CdcChart.jsx
CHANGED
|
@@ -21,10 +21,6 @@ import LinearChart from './components/LinearChart'
|
|
|
21
21
|
|
|
22
22
|
import { colorPalettesChart as colorPalettes, twoColorPalette } from '@cdc/core/data/colorPalettes'
|
|
23
23
|
|
|
24
|
-
import { publish, subscribe, unsubscribe } from '@cdc/core/helpers/events'
|
|
25
|
-
|
|
26
|
-
import useDataVizClasses from '@cdc/core/helpers/useDataVizClasses'
|
|
27
|
-
|
|
28
24
|
import SparkLine from './components/SparkLine'
|
|
29
25
|
import Legend from './components/Legend'
|
|
30
26
|
import defaults from './data/initial-state'
|
|
@@ -34,6 +30,8 @@ import Filters from '@cdc/core/components/Filters'
|
|
|
34
30
|
import MediaControls from '@cdc/core/components/MediaControls'
|
|
35
31
|
|
|
36
32
|
// Helpers
|
|
33
|
+
import { publish, subscribe, unsubscribe } from '@cdc/core/helpers/events'
|
|
34
|
+
import useDataVizClasses from '@cdc/core/helpers/useDataVizClasses'
|
|
37
35
|
import numberFromString from '@cdc/core/helpers/numberFromString'
|
|
38
36
|
import getViewport from '@cdc/core/helpers/getViewport'
|
|
39
37
|
import { DataTransform } from '@cdc/core/helpers/DataTransform'
|
|
@@ -96,7 +94,7 @@ export default function CdcChart({ configUrl, config: configObj, isEditor = fals
|
|
|
96
94
|
let legendMemo = useRef(new Map()) // map collection
|
|
97
95
|
let innerContainerRef = useRef()
|
|
98
96
|
|
|
99
|
-
if (isDebug) console.log('Chart config', config)
|
|
97
|
+
if (isDebug) console.log('Chart config, isEditor', config, isEditor)
|
|
100
98
|
|
|
101
99
|
const DataTable = config?.table?.showVertical ? DataTable_vert : DataTable_horiz
|
|
102
100
|
|
|
@@ -563,17 +561,20 @@ export default function CdcChart({ configUrl, config: configObj, isEditor = fals
|
|
|
563
561
|
newConfig.runtime.areaSeriesKeys = []
|
|
564
562
|
|
|
565
563
|
newConfig.series.forEach(series => {
|
|
566
|
-
|
|
567
|
-
newConfig.runtime.areaSeriesKeys.push(series)
|
|
568
|
-
}
|
|
564
|
+
newConfig.runtime.areaSeriesKeys.push({ ...series, type: 'Area Chart' })
|
|
569
565
|
})
|
|
570
566
|
}
|
|
571
567
|
|
|
572
|
-
if ((newConfig.visualizationType === 'Bar' && newConfig.orientation === 'horizontal') || ['Deviation Bar', 'Paired Bar'].includes(newConfig.visualizationType)) {
|
|
568
|
+
if ((newConfig.visualizationType === 'Bar' && newConfig.orientation === 'horizontal') || ['Deviation Bar', 'Paired Bar', 'Forest Plot'].includes(newConfig.visualizationType)) {
|
|
573
569
|
newConfig.runtime.xAxis = newConfig.yAxis
|
|
574
570
|
newConfig.runtime.yAxis = newConfig.xAxis
|
|
575
571
|
newConfig.runtime.horizontal = true
|
|
576
572
|
newConfig.orientation = 'horizontal'
|
|
573
|
+
} else if (['Box Plot', 'Scatter Plot', 'Area Chart'].includes(newConfig.visualizationType)) {
|
|
574
|
+
newConfig.runtime.xAxis = newConfig.xAxis
|
|
575
|
+
newConfig.runtime.yAxis = newConfig.yAxis
|
|
576
|
+
newConfig.runtime.horizontal = false
|
|
577
|
+
newConfig.orientation = 'vertical'
|
|
577
578
|
} else {
|
|
578
579
|
newConfig.runtime.xAxis = newConfig.xAxis
|
|
579
580
|
newConfig.runtime.yAxis = newConfig.yAxis
|
|
@@ -873,12 +874,15 @@ export default function CdcChart({ configUrl, config: configObj, isEditor = fals
|
|
|
873
874
|
}
|
|
874
875
|
|
|
875
876
|
// Format numeric data based on settings in config OR from passed in settings for Additional Columns
|
|
877
|
+
// - use only for old horizontal data - newer formatNumber is in helper/formatNumber
|
|
876
878
|
const formatNumber = (num, axis, shouldAbbreviate = false, addColPrefix, addColSuffix, addColRoundTo) => {
|
|
877
879
|
// if num is NaN return num
|
|
878
880
|
if (isNaN(num) || !num) return num
|
|
879
881
|
// Check if the input number is negative
|
|
880
882
|
const isNegative = num < 0
|
|
881
883
|
|
|
884
|
+
if (axis === undefined || !axis) axis = 'left'
|
|
885
|
+
|
|
882
886
|
// If the input number is negative, take the absolute value
|
|
883
887
|
if (isNegative) {
|
|
884
888
|
num = Math.abs(num)
|
|
@@ -893,8 +897,10 @@ export default function CdcChart({ configUrl, config: configObj, isEditor = fals
|
|
|
893
897
|
if (String(num).indexOf(',') !== -1) num = num.replaceAll(',', '')
|
|
894
898
|
|
|
895
899
|
let original = num
|
|
896
|
-
let stringFormattingOptions
|
|
897
|
-
|
|
900
|
+
let stringFormattingOptions = {
|
|
901
|
+
useGrouping: commas ? true : false // for old chart data table to work right cant just leave this to undefined
|
|
902
|
+
}
|
|
903
|
+
if (axis === 'left' || axis === undefined) {
|
|
898
904
|
let roundToPlace
|
|
899
905
|
if (addColRoundTo !== undefined) {
|
|
900
906
|
// if its an Additional Column
|
|
@@ -968,7 +974,7 @@ export default function CdcChart({ configUrl, config: configObj, isEditor = fals
|
|
|
968
974
|
result = addColPrefix + result
|
|
969
975
|
} else {
|
|
970
976
|
if (prefix && axis === 'left') {
|
|
971
|
-
result
|
|
977
|
+
result += prefix
|
|
972
978
|
}
|
|
973
979
|
}
|
|
974
980
|
|
|
@@ -980,6 +986,7 @@ export default function CdcChart({ configUrl, config: configObj, isEditor = fals
|
|
|
980
986
|
result += bottomPrefix
|
|
981
987
|
}
|
|
982
988
|
|
|
989
|
+
// combine prefix and num
|
|
983
990
|
result += num
|
|
984
991
|
|
|
985
992
|
if (addColSuffix && axis === 'left') {
|
|
@@ -1015,11 +1022,13 @@ export default function CdcChart({ configUrl, config: configObj, isEditor = fals
|
|
|
1015
1022
|
'Box Plot': <LinearChart />,
|
|
1016
1023
|
'Area Chart': <LinearChart />,
|
|
1017
1024
|
'Scatter Plot': <LinearChart />,
|
|
1018
|
-
'Deviation Bar': <LinearChart
|
|
1025
|
+
'Deviation Bar': <LinearChart />,
|
|
1026
|
+
'Forest Plot': <LinearChart />
|
|
1019
1027
|
}
|
|
1020
1028
|
|
|
1021
1029
|
const missingRequiredSections = () => {
|
|
1022
1030
|
if (config.visualizationType === 'Forecasting') return false // skip required checks for now.
|
|
1031
|
+
if (config.visualizationType === 'Forest Plot') return false // skip required checks for now.
|
|
1023
1032
|
if (config.visualizationType === 'Pie') {
|
|
1024
1033
|
if (undefined === config?.yAxis.dataKey) {
|
|
1025
1034
|
return true
|
|
@@ -1202,7 +1211,7 @@ export default function CdcChart({ configUrl, config: configObj, isEditor = fals
|
|
|
1202
1211
|
{isDashboard && config.table && config.table.show && config.table.showDataTableLink ? tableLink : link && link}
|
|
1203
1212
|
|
|
1204
1213
|
{/* Description */}
|
|
1205
|
-
{description && config.visualizationType !== 'Spark Line' && <div className='subtext'>{parse(description)}</div>}
|
|
1214
|
+
{description && config.visualizationType !== 'Spark Line' && <div className={'column ' + config.isResponsiveTicks ? 'subtext--responsive-ticks' : 'subtext'}>{parse(description)}</div>}
|
|
1206
1215
|
|
|
1207
1216
|
{/* buttons */}
|
|
1208
1217
|
<MediaControls.Section classes={['download-buttons']}>
|
|
@@ -1297,6 +1306,7 @@ export default function CdcChart({ configUrl, config: configObj, isEditor = fals
|
|
|
1297
1306
|
isNumber,
|
|
1298
1307
|
getTextWidth,
|
|
1299
1308
|
twoColorPalette,
|
|
1309
|
+
isEditor,
|
|
1300
1310
|
isDebug,
|
|
1301
1311
|
setSharedFilter,
|
|
1302
1312
|
setSharedFilterValue,
|
|
@@ -8,52 +8,96 @@ import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
|
|
|
8
8
|
import * as allCurves from '@visx/curve'
|
|
9
9
|
import { AreaClosed, LinePath, Bar } from '@visx/shape'
|
|
10
10
|
import { Group } from '@visx/group'
|
|
11
|
+
import { bisector } from 'd3-array'
|
|
11
12
|
|
|
12
|
-
const AreaChart = ({ xScale, yScale, yMax, xMax, chartRef, handleTooltipMouseOver, handleTooltipMouseOff, tooltipData }) => {
|
|
13
|
+
const AreaChart = ({ xScale, yScale, yMax, xMax, getXAxisData, getYAxisData, chartRef, handleTooltipMouseOver, handleTooltipMouseOff, tooltipData, isDebug, isBrush, brushData, children }) => {
|
|
13
14
|
// enable various console logs in the file
|
|
14
|
-
const DEBUG =
|
|
15
|
+
const DEBUG = isDebug
|
|
15
16
|
|
|
16
17
|
// import data from context
|
|
17
|
-
|
|
18
|
+
let { transformedData: data, config, handleLineType, parseDate, formatDate, formatNumber, seriesHighlight, colorScale, rawData } = useContext(ConfigContext)
|
|
19
|
+
|
|
20
|
+
// use brush data if it is passed in AND if this is NOT a brush chart
|
|
21
|
+
data = !isBrush && undefined !== brushData && brushData.length ? brushData : data
|
|
22
|
+
|
|
23
|
+
if (isBrush && isDebug) console.log('###AREAchart BRUSH data, xScale, yScale, yMax, xMax', data, xScale, yScale, yMax, xMax)
|
|
18
24
|
|
|
19
25
|
// Draw transparent bars over the chart to get tooltip data
|
|
20
26
|
// Turn DEBUG on for additional context.
|
|
21
27
|
if (!data) return
|
|
22
28
|
|
|
29
|
+
// Tooltip helper for getting data to the closest date/category hovered.
|
|
30
|
+
const getXValueFromCoordinate = x => {
|
|
31
|
+
if (config.xAxis.type === 'categorical' || config.visualizationType === 'Combo') {
|
|
32
|
+
let eachBand = xScale.step()
|
|
33
|
+
let numerator = x
|
|
34
|
+
const index = Math.floor(Number(numerator) / eachBand)
|
|
35
|
+
return xScale.domain()[index - 1] // fixes off by 1 error
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (config.xAxis.type === 'date' && config.visualizationType !== 'Combo') {
|
|
39
|
+
const bisectDate = bisector(d => parseDate(d[config.xAxis.dataKey])).left
|
|
40
|
+
const x0 = xScale.invert(x)
|
|
41
|
+
const index = bisectDate(config.data, x0, 1)
|
|
42
|
+
const val = parseDate(config.data[index - 1][config.xAxis.dataKey])
|
|
43
|
+
return val
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const getXAxisDates = brushDataSet => {
|
|
48
|
+
if (undefined === brushDataSet || !brushDataSet) return
|
|
49
|
+
let XAxisBrushDates = []
|
|
50
|
+
brushDataSet.forEach(function convertDateTimeNumber(key, value, brushDataSet) {
|
|
51
|
+
let tmp = getXValueFromCoordinate(xScale(value))
|
|
52
|
+
let date = formatDate(tmp)
|
|
53
|
+
XAxisBrushDates.push(date)
|
|
54
|
+
})
|
|
55
|
+
return XAxisBrushDates
|
|
56
|
+
}
|
|
57
|
+
|
|
23
58
|
const handleX = d => {
|
|
24
59
|
return config.xAxis.type === 'date' ? xScale(parseDate(d[config.xAxis.dataKey], false)) : xScale(d[config.xAxis.dataKey])
|
|
25
60
|
}
|
|
26
61
|
|
|
27
62
|
const handleY = (d, index, s = undefined) => {
|
|
28
|
-
return yScale(d[s.dataKey])
|
|
63
|
+
return isBrush ? yScale(d[s.dataKey]) / 4 : yScale(d[s.dataKey])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// prevents duplicate brush handles being rendered
|
|
67
|
+
const getFirstBrushHandleOnly = (children, index) => {
|
|
68
|
+
if (index === 0) {
|
|
69
|
+
return children
|
|
70
|
+
}
|
|
71
|
+
// else dont return the other brush handles
|
|
29
72
|
}
|
|
30
73
|
|
|
31
74
|
return (
|
|
32
75
|
data && (
|
|
33
|
-
<
|
|
34
|
-
<
|
|
35
|
-
{(config.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
76
|
+
<svg>
|
|
77
|
+
<ErrorBoundary component='AreaChart'>
|
|
78
|
+
<Group className='area-chart' key='area-wrapper' left={Number(config.yAxis.size)} top={isBrush ? yMax * 1.3 : 0}>
|
|
79
|
+
{(config.runtime.areaSeriesKeys || config.series).map((s, index) => {
|
|
80
|
+
let seriesData = data.map(d => {
|
|
81
|
+
return {
|
|
82
|
+
[config.xAxis.dataKey]: d[config.xAxis.dataKey],
|
|
83
|
+
[s.dataKey]: d[s.dataKey]
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
let curveType = allCurves[s.lineType]
|
|
88
|
+
let transparentArea = config.legend.behavior === 'highlight' && seriesHighlight.length > 0 && seriesHighlight.indexOf(s.dataKey) === -1
|
|
89
|
+
let displayArea = config.legend.behavior === 'highlight' || seriesHighlight.length === 0 || seriesHighlight.indexOf(s.dataKey) !== -1
|
|
90
|
+
|
|
91
|
+
if (config.xAxis.type === 'date') {
|
|
92
|
+
data.map(d => xScale(parseDate(d[config.xAxis.dataKey])))
|
|
93
|
+
} else {
|
|
94
|
+
data.map(d => xScale(d[config.xAxis.dataKey]))
|
|
40
95
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (config.xAxis.type === 'date') {
|
|
48
|
-
data.map(d => xScale(parseDate(d[config.xAxis.dataKey])))
|
|
49
|
-
} else {
|
|
50
|
-
data.map(d => xScale(d[config.xAxis.dataKey]))
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<React.Fragment key={index}>
|
|
55
|
-
{/* prettier-ignore */}
|
|
56
|
-
<LinePath
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<React.Fragment key={index}>
|
|
99
|
+
{/* prettier-ignore */}
|
|
100
|
+
<LinePath
|
|
57
101
|
data={seriesData}
|
|
58
102
|
x={d => handleX(d)}
|
|
59
103
|
y={d => handleY(d, index, s)}
|
|
@@ -65,10 +109,10 @@ const AreaChart = ({ xScale, yScale, yMax, xMax, chartRef, handleTooltipMouseOve
|
|
|
65
109
|
strokeDasharray={s.type ? handleLineType(s.type) : 0}
|
|
66
110
|
/>
|
|
67
111
|
|
|
68
|
-
|
|
69
|
-
|
|
112
|
+
{/* prettier-ignore */}
|
|
113
|
+
<AreaClosed
|
|
70
114
|
key={'area-chart'}
|
|
71
|
-
fill={
|
|
115
|
+
fill={displayArea ? colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[s.dataKey] : s.dataKey) : '#000' : 'transparent'}
|
|
72
116
|
fillOpacity={transparentArea ? 0.25 : 0.5}
|
|
73
117
|
data={seriesData}
|
|
74
118
|
x={d => handleX(d)}
|
|
@@ -77,36 +121,17 @@ const AreaChart = ({ xScale, yScale, yMax, xMax, chartRef, handleTooltipMouseOve
|
|
|
77
121
|
curve={curveType}
|
|
78
122
|
strokeDasharray={s.type ? handleLineType(s.type) : 0}
|
|
79
123
|
/>
|
|
124
|
+
{getFirstBrushHandleOnly(children, index)}
|
|
125
|
+
</React.Fragment>
|
|
126
|
+
)
|
|
127
|
+
})}
|
|
80
128
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
opacity={1}
|
|
88
|
-
fillOpacity={1}
|
|
89
|
-
fill={displayArea ? (colorScale ? colorScale(config.runtime.seriesLabels ? config.runtime.seriesLabels[s.dataKey] : s.dataKey) : '#000') : 'transparent'}
|
|
90
|
-
style={{ filter: 'unset', opacity: 1 }}
|
|
91
|
-
/>
|
|
92
|
-
)} */}
|
|
93
|
-
</React.Fragment>
|
|
94
|
-
)
|
|
95
|
-
})}
|
|
96
|
-
|
|
97
|
-
{/* Transparent bar for tooltips */}
|
|
98
|
-
{/* prettier-ignore */}
|
|
99
|
-
<Bar
|
|
100
|
-
width={ Number(xMax)}
|
|
101
|
-
height={ Number(yMax)}
|
|
102
|
-
fill={DEBUG ? 'red' : 'transparent'}
|
|
103
|
-
fillOpacity={0.05}
|
|
104
|
-
style={DEBUG ? { stroke: 'black', strokeWidth: 2 } : {}}
|
|
105
|
-
onMouseMove={e => handleTooltipMouseOver(e, rawData)}
|
|
106
|
-
onMouseLeave={ handleTooltipMouseOff }
|
|
107
|
-
/>
|
|
108
|
-
</Group>
|
|
109
|
-
</ErrorBoundary>
|
|
129
|
+
{/* Transparent bar for tooltips - disable if AreaChart is a brush */}
|
|
130
|
+
{/* prettier-ignore */}
|
|
131
|
+
{!isBrush && <Bar width={Number(xMax)} height={Number(yMax)} fill={DEBUG ? 'red' : 'transparent'} fillOpacity={0.05} style={DEBUG ? { stroke: 'black', strokeWidth: 2 } : {}} onMouseMove={e => handleTooltipMouseOver(e, rawData)} onMouseLeave={handleTooltipMouseOff} />}
|
|
132
|
+
</Group>
|
|
133
|
+
</ErrorBoundary>
|
|
134
|
+
</svg>
|
|
110
135
|
)
|
|
111
136
|
)
|
|
112
137
|
}
|