@evergis/charts 3.1.6 → 3.1.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 +2 -2
- package/README.md +10 -0
- package/dist/charts/BarChart/draw.d.ts +2 -2
- package/dist/charts/BarChart/drawGrid/index.d.ts +2 -2
- package/dist/charts/BarChart/drawGrid/types.d.ts +8 -8
- package/dist/charts/BarChart/drawLines/index.d.ts +13 -13
- package/dist/charts/BarChart/drawLines/types.d.ts +9 -9
- package/dist/charts/BarChart/drawTooltip/getLabel.d.ts +2 -2
- package/dist/charts/BarChart/drawTooltip/getLabelY.d.ts +2 -2
- package/dist/charts/BarChart/drawTooltip/index.d.ts +2 -2
- package/dist/charts/BarChart/drawTooltip/types.d.ts +12 -13
- package/dist/charts/BarChart/getBars/index.d.ts +3 -3
- package/dist/charts/BarChart/getBars/types.d.ts +6 -6
- package/dist/charts/BarChart/getDomain.d.ts +5 -5
- package/dist/charts/BarChart/hooks/useSelection.d.ts +2 -2
- package/dist/charts/BarChart/index.d.ts +3 -3
- package/dist/charts/BarChart/marshaling.d.ts +2 -2
- package/dist/charts/BarChart/resizeBarWidth/index.d.ts +2 -2
- package/dist/charts/BarChart/resizeBarWidth/types.d.ts +5 -5
- package/dist/charts/BarChart/styled.d.ts +37 -37
- package/dist/charts/BarChart/types.d.ts +148 -148
- package/dist/charts/BubbleChart/bubbleChartDefaultProps.d.ts +14 -14
- package/dist/charts/BubbleChart/draw.d.ts +2 -2
- package/dist/charts/BubbleChart/drawGrid/index.d.ts +2 -2
- package/dist/charts/BubbleChart/drawGrid/types.d.ts +8 -8
- package/dist/charts/BubbleChart/drawTooltip/index.d.ts +2 -2
- package/dist/charts/BubbleChart/drawTooltip/styled.d.ts +1 -1
- package/dist/charts/BubbleChart/drawTooltip/types.d.ts +4 -4
- package/dist/charts/BubbleChart/index.d.ts +3 -3
- package/dist/charts/BubbleChart/styled.d.ts +17 -17
- package/dist/charts/BubbleChart/types.d.ts +55 -55
- package/dist/charts/BubbleChart/unmount.d.ts +1 -1
- package/dist/charts/CalendarChart/draw.d.ts +2 -2
- package/dist/charts/CalendarChart/index.d.ts +3 -3
- package/dist/charts/CalendarChart/styled.d.ts +18 -18
- package/dist/charts/CalendarChart/types.d.ts +22 -22
- package/dist/charts/HorizontalBarChart/Bar/index.d.ts +3 -3
- package/dist/charts/HorizontalBarChart/Bar/styled.d.ts +1 -1
- package/dist/charts/HorizontalBarChart/Bar/types.d.ts +11 -11
- package/dist/charts/HorizontalBarChart/Tooltip/index.d.ts +3 -3
- package/dist/charts/HorizontalBarChart/Tooltip/types.d.ts +5 -5
- package/dist/charts/HorizontalBarChart/XScale/hooks/useScale.d.ts +2 -2
- package/dist/charts/HorizontalBarChart/XScale/index.d.ts +3 -3
- package/dist/charts/HorizontalBarChart/XScale/styled.d.ts +3 -3
- package/dist/charts/HorizontalBarChart/hooks/useMarshaling.d.ts +5 -5
- package/dist/charts/HorizontalBarChart/hooks/useStackWrapper.d.ts +12 -12
- package/dist/charts/HorizontalBarChart/hooks/useTooltip/index.d.ts +3 -3
- package/dist/charts/HorizontalBarChart/hooks/useTooltip/types.d.ts +6 -3
- package/dist/charts/HorizontalBarChart/index.d.ts +3 -3
- package/dist/charts/HorizontalBarChart/styled.d.ts +30 -30
- package/dist/charts/HorizontalBarChart/types.d.ts +41 -41
- package/dist/charts/LineChart/draw.d.ts +2 -2
- package/dist/charts/LineChart/drawGrid/index.d.ts +2 -2
- package/dist/charts/LineChart/drawGrid/types.d.ts +9 -9
- package/dist/charts/LineChart/drawLabel/index.d.ts +3 -3
- package/dist/charts/LineChart/drawLabel/styled.d.ts +2 -2
- package/dist/charts/LineChart/drawLabel/types.d.ts +7 -7
- package/dist/charts/LineChart/drawTooltip/index.d.ts +2 -2
- package/dist/charts/LineChart/drawTooltip/types.d.ts +9 -9
- package/dist/charts/LineChart/index.d.ts +3 -3
- package/dist/charts/LineChart/styled.d.ts +27 -27
- package/dist/charts/LineChart/types.d.ts +78 -78
- package/dist/charts/PieChart/draw.d.ts +2 -2
- package/dist/charts/PieChart/drawRadialLabels/helpers.d.ts +3 -3
- package/dist/charts/PieChart/drawRadialLabels/index.d.ts +2 -2
- package/dist/charts/PieChart/drawRadialLabels/types.d.ts +11 -11
- package/dist/charts/PieChart/drawTooltips/index.d.ts +2 -2
- package/dist/charts/PieChart/drawTooltips/types.d.ts +8 -8
- package/dist/charts/PieChart/index.d.ts +3 -3
- package/dist/charts/PieChart/styled.d.ts +18 -18
- package/dist/charts/PieChart/types.d.ts +54 -54
- package/dist/charts/RadarChart/draw.d.ts +2 -2
- package/dist/charts/RadarChart/drawRadialLabels/index.d.ts +2 -2
- package/dist/charts/RadarChart/drawRadialLabels/styled.d.ts +2 -2
- package/dist/charts/RadarChart/drawRadialLabels/types.d.ts +25 -25
- package/dist/charts/RadarChart/helpers.d.ts +2 -2
- package/dist/charts/RadarChart/index.d.ts +3 -3
- package/dist/charts/RadarChart/styled.d.ts +13 -13
- package/dist/charts/RadarChart/types.d.ts +42 -42
- package/dist/charts.esm.js +3327 -3297
- package/dist/charts.esm.js.map +1 -1
- package/dist/common/components/SwipeScroll/animate.d.ts +6 -6
- package/dist/common/components/SwipeScroll/hooks/useSwipe.d.ts +2 -2
- package/dist/common/components/SwipeScroll/index.d.ts +3 -3
- package/dist/common/components/SwipeScroll/styled.d.ts +1 -1
- package/dist/common/components/SwipeScroll/types.d.ts +8 -8
- package/dist/common/components/Wrapper.d.ts +1 -1
- package/dist/common/components/labels/index.d.ts +7 -7
- package/dist/common/components/labels/types.d.ts +6 -6
- package/dist/common/components/tooltips/index.d.ts +14 -14
- package/dist/common/types/interpolator.d.ts +1 -1
- package/dist/common/types/margin.d.ts +6 -6
- package/dist/helpers/appendSvg.d.ts +2 -2
- package/dist/helpers/common.d.ts +2 -2
- package/dist/helpers/computeDimensions.d.ts +2 -2
- package/dist/helpers/getLegend/index.d.ts +19 -19
- package/dist/helpers/getLegend/types.d.ts +15 -15
- package/dist/helpers/getTextWidth.d.ts +1 -1
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/math.d.ts +2 -2
- package/dist/helpers/stackedData.d.ts +2 -2
- package/dist/helpers/textAlignCenter.d.ts +2 -2
- package/dist/helpers/throttle.d.ts +1 -1
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/useNode.d.ts +2 -2
- package/dist/hooks/useResize.d.ts +1 -1
- package/dist/index.d.ts +26 -26
- package/dist/index.js +3553 -5
- package/dist/index.js.map +1 -0
- package/package.json +29 -40
- package/dist/charts.cjs.development.js +0 -3513
- package/dist/charts.cjs.development.js.map +0 -1
- package/dist/charts.cjs.production.min.js +0 -2
- package/dist/charts.cjs.production.min.js.map +0 -1
- package/dist/jest.config.d.ts +0 -14
- package/dist/stories/Bar/Examples.stories.d.ts +0 -23
- package/dist/stories/Bar/HorizontalBar.stories.d.ts +0 -25
- package/dist/stories/Bar/Statistics.stories.d.ts +0 -7
- package/dist/stories/Bar/VerticalBar.stories.d.ts +0 -41
- package/dist/stories/Bubble/Bubble.stories.d.ts +0 -23
- package/dist/stories/Bubble/Examples.stories.d.ts +0 -4
- package/dist/stories/Bubble/examples/VEB/InvestBubble.d.ts +0 -5
- package/dist/stories/Bubble/examples/VEB/hooks/useCustomize.d.ts +0 -3
- package/dist/stories/Bubble/examples/VEB/hooks/useRenderTooltip/index.d.ts +0 -4
- package/dist/stories/Bubble/examples/VEB/hooks/useRenderTooltip/styled.d.ts +0 -8
- package/dist/stories/Bubble/examples/VEB/styled.d.ts +0 -1
- package/dist/stories/Calendar/Calendar.stories.d.ts +0 -23
- package/dist/stories/Calendar/ColorScheme.stories.d.ts +0 -7
- package/dist/stories/Calendar/Examples.stories.d.ts +0 -11
- package/dist/stories/Calendar/Legend.stories.d.ts +0 -30
- package/dist/stories/Common/SwipeScroll/SwipeScroll.stories.d.ts +0 -13
- package/dist/stories/Common/SwipeScroll/hooks/useSwipe.d.ts +0 -1
- package/dist/stories/Line/Examples.stories.d.ts +0 -7
- package/dist/stories/Line/Line.stories.d.ts +0 -48
- package/dist/stories/Line/examples/Beeline.d.ts +0 -5
- package/dist/stories/Line/examples/GeoVeb.d.ts +0 -5
- package/dist/stories/Line/examples/GeoVebInterval/data.d.ts +0 -9
- package/dist/stories/Line/examples/GeoVebInterval/index.d.ts +0 -5
- package/dist/stories/Line/examples/GeoVebInterval/styled.d.ts +0 -4
- package/dist/stories/Line/examples/Msp.d.ts +0 -5
- package/dist/stories/Pie/ColorScheme.stories.d.ts +0 -7
- package/dist/stories/Pie/Examples.stories.d.ts +0 -7
- package/dist/stories/Pie/Pie.stories.d.ts +0 -47
- package/dist/stories/Radar/Chart.stories.d.ts +0 -38
- package/dist/stories/Radar/Github.stories.d.ts +0 -7
- package/dist/stories/Radar/Gradient.stories.d.ts +0 -7
- package/dist/stories/Radar/Veb.stories.d.ts +0 -7
- package/dist/stories/Sankey/Examples.stories.d.ts +0 -4
- package/dist/stories/Sankey/examples/RelatedIndustries/data.d.ts +0 -2
- package/dist/stories/Sankey/examples/RelatedIndustries/index.d.ts +0 -5
- package/dist/stories/__internal__/colors.d.ts +0 -40
- package/dist/stories/__internal__/components/BeelineLineChart/hooks/useCustomize.d.ts +0 -11
- package/dist/stories/__internal__/components/BeelineLineChart/hooks/useLineRenderTooltip/index.d.ts +0 -5
- package/dist/stories/__internal__/components/BeelineLineChart/hooks/useLineRenderTooltip/styled.d.ts +0 -5
- package/dist/stories/__internal__/components/BeelineLineChart/index.d.ts +0 -3
- package/dist/stories/__internal__/components/BeelineLineChart/styled.d.ts +0 -3
- package/dist/stories/__internal__/components/BeelineRangeLineChart/Range/index.d.ts +0 -7
- package/dist/stories/__internal__/components/BeelineRangeLineChart/Range/styled.d.ts +0 -3
- package/dist/stories/__internal__/components/BeelineRangeLineChart/hooks/useChange.d.ts +0 -8
- package/dist/stories/__internal__/components/BeelineRangeLineChart/index.d.ts +0 -2
- package/dist/stories/__internal__/components/BeelineRangeLineChart/styled.d.ts +0 -4
- package/dist/stories/__internal__/components/BeelineTrafficHorizontalBarChart/data.d.ts +0 -5
- package/dist/stories/__internal__/components/BeelineTrafficHorizontalBarChart/hooks/useRenderDataTable.d.ts +0 -2
- package/dist/stories/__internal__/components/BeelineTrafficHorizontalBarChart/index.d.ts +0 -2
- package/dist/stories/__internal__/components/BeelineTrafficHorizontalBarChart/styled.d.ts +0 -3
- package/dist/stories/__internal__/components/Divider.d.ts +0 -6
- package/dist/stories/__internal__/components/GeoVebBarCharts.d.ts +0 -2
- package/dist/stories/__internal__/components/GeoVebHorizontalBarCharts/data.d.ts +0 -47
- package/dist/stories/__internal__/components/GeoVebHorizontalBarCharts/hooks/useRenderTooltip.d.ts +0 -3
- package/dist/stories/__internal__/components/GeoVebHorizontalBarCharts/hooks/useSimpleRenderTooltip.d.ts +0 -3
- package/dist/stories/__internal__/components/GeoVebHorizontalBarCharts/index.d.ts +0 -4
- package/dist/stories/__internal__/components/GeoVebHorizontalBarCharts/styled.d.ts +0 -4
- package/dist/stories/__internal__/components/GeoYearsBarChart/index.d.ts +0 -2
- package/dist/stories/__internal__/components/GeoYearsBarChart/styled.d.ts +0 -4
- package/dist/stories/__internal__/components/MixedTableChart/Chart/index.d.ts +0 -3
- package/dist/stories/__internal__/components/MixedTableChart/Chart/styled.d.ts +0 -2
- package/dist/stories/__internal__/components/MixedTableChart/index.d.ts +0 -3
- package/dist/stories/__internal__/components/MixedTableChart/styled.d.ts +0 -5
- package/dist/stories/__internal__/components/MixedTableChart/types.d.ts +0 -21
- package/dist/stories/__internal__/components/MspDashboardChart/hooks/useAnimation.d.ts +0 -5
- package/dist/stories/__internal__/components/MspDashboardChart/index.d.ts +0 -3
- package/dist/stories/__internal__/components/MspDashboardChart/styled.d.ts +0 -5
- package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useAnimationAreas.d.ts +0 -6
- package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useAnimationBars.d.ts +0 -5
- package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useCustomize.d.ts +0 -4
- package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useData.d.ts +0 -8
- package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useMarshalledMap.d.ts +0 -1
- package/dist/stories/__internal__/components/MspPromSupplyBarChart/hooks/useRenderTooltip.d.ts +0 -2
- package/dist/stories/__internal__/components/MspPromSupplyBarChart/index.d.ts +0 -9
- package/dist/stories/__internal__/components/MspPromSupplyBarChart/styled.d.ts +0 -22
- package/dist/stories/__internal__/components/SankeyTriChart/Groups/getCSSProperties.d.ts +0 -4
- package/dist/stories/__internal__/components/SankeyTriChart/Groups/helpers.d.ts +0 -1
- package/dist/stories/__internal__/components/SankeyTriChart/Groups/index.d.ts +0 -5
- package/dist/stories/__internal__/components/SankeyTriChart/Groups/styled.d.ts +0 -1
- package/dist/stories/__internal__/components/SankeyTriChart/ItemContent/getCSSProperties.d.ts +0 -3
- package/dist/stories/__internal__/components/SankeyTriChart/ItemContent/index.d.ts +0 -5
- package/dist/stories/__internal__/components/SankeyTriChart/ItemContent/styled.d.ts +0 -8
- package/dist/stories/__internal__/components/SankeyTriChart/draw.d.ts +0 -2
- package/dist/stories/__internal__/components/SankeyTriChart/helpers.d.ts +0 -9
- package/dist/stories/__internal__/components/SankeyTriChart/index.d.ts +0 -10
- package/dist/stories/__internal__/components/SankeyTriChart/marshaling.d.ts +0 -6
- package/dist/stories/__internal__/components/SankeyTriChart/styled.d.ts +0 -1
- package/dist/stories/__internal__/components/SankeyTriChart/types.d.ts +0 -40
- package/dist/stories/__internal__/components/SberBarMixChart/colors.d.ts +0 -3
- package/dist/stories/__internal__/components/SberBarMixChart/data.d.ts +0 -8
- package/dist/stories/__internal__/components/SberBarMixChart/hooks/styled.d.ts +0 -3
- package/dist/stories/__internal__/components/SberBarMixChart/hooks/useRenderTooltip.d.ts +0 -2
- package/dist/stories/__internal__/components/SberBarMixChart/index.d.ts +0 -2
- package/dist/stories/__internal__/components/SberBarMixChart/styled.d.ts +0 -1
- package/dist/stories/__internal__/components/StatisticsBarCharts/NumbersStatistics.d.ts +0 -2
- package/dist/stories/__internal__/components/StatisticsBarCharts/StringsStatistics.d.ts +0 -2
- package/dist/stories/__internal__/components/StatisticsBarCharts/index.d.ts +0 -2
- package/dist/stories/__internal__/components/StatisticsBarCharts/styled.d.ts +0 -1
- package/dist/stories/__internal__/components/VebEstimationBarChart/data.d.ts +0 -38
- package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useCustomize.d.ts +0 -5
- package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useDrawBars.d.ts +0 -4
- package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useRenderLabel/index.d.ts +0 -9
- package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useRenderLabel/styled.d.ts +0 -1
- package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useRenderTooltip/index.d.ts +0 -8
- package/dist/stories/__internal__/components/VebEstimationBarChart/hooks/useRenderTooltip/styled.d.ts +0 -13
- package/dist/stories/__internal__/components/VebEstimationBarChart/index.d.ts +0 -3
- package/dist/stories/__internal__/components/VebEstimationBarChart/styled.d.ts +0 -2
- package/dist/stories/__internal__/components/VebFilterBarChart/index.d.ts +0 -2
- package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/hooks/useRenderSum/index.d.ts +0 -3
- package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/hooks/useRenderSum/styled.d.ts +0 -1
- package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/hooks/useRenderTooltip/index.d.ts +0 -1
- package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/hooks/useRenderTooltip/styled.d.ts +0 -5
- package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/index.d.ts +0 -3
- package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/styled.d.ts +0 -5
- package/dist/stories/__internal__/components/VebGroupHorizontalBarChart/types.d.ts +0 -11
- package/dist/stories/__internal__/curves.d.ts +0 -8
- package/dist/stories/__internal__/data/msp.d.ts +0 -14
- package/dist/stories/__internal__/data/mspDashboard.d.ts +0 -1
- package/dist/stories/__internal__/data/mspPromSupply.d.ts +0 -11
- package/dist/stories/__internal__/data/population.d.ts +0 -4
- package/dist/stories/__internal__/data/veb.d.ts +0 -31
- package/dist/stories/__internal__/helpers/Path.d.ts +0 -10
- package/dist/stories/__internal__/helpers/Vector.d.ts +0 -9
- package/dist/stories/__internal__/helpers/animation.d.ts +0 -15
- package/dist/stories/__internal__/helpers/hexToRGB.d.ts +0 -1
- package/dist/stories/__internal__/helpers/random.d.ts +0 -1
- package/dist/stories/__internal__/helpers/randomData.d.ts +0 -14
- package/dist/stories/__internal__/helpers/randomHorizontalBarData.d.ts +0 -5
- package/dist/stories/__internal__/helpers/randomIntervalData.d.ts +0 -11
- package/dist/stories/__internal__/helpers/randomLineData.d.ts +0 -8
- package/dist/stories/__internal__/helpers/randomText.d.ts +0 -1
- package/dist/stories/__internal__/helpers/roundedRect.d.ts +0 -10
- package/dist/stories/__internal__/helpers/shuffleArray.d.ts +0 -1
- package/dist/stories/__internal__/hooks/useBarData.d.ts +0 -10
- package/dist/stories/__internal__/hooks/useLegend.d.ts +0 -1
- package/dist/stories/__internal__/hooks/useMinMaxValue.d.ts +0 -4
- package/dist/stories/__internal__/interpolates.d.ts +0 -23
- package/dist/storybook-static/1.05dfd83c.iframe.bundle.d.ts +0 -0
- package/dist/storybook-static/189.8c077122866758d3cf20.manager.bundle.d.ts +0 -0
- package/dist/storybook-static/190.58050c9beb344d4cefd9.manager.bundle.d.ts +0 -2
- package/dist/storybook-static/191.b202c06c72968435b80b.manager.bundle.d.ts +0 -0
- package/dist/storybook-static/192.83987c5b15f8a80893c5.manager.bundle.d.ts +0 -0
- package/dist/storybook-static/193.8a12aa992b466e778018.manager.bundle.d.ts +0 -2
- package/dist/storybook-static/2.0231c7b6.iframe.bundle.d.ts +0 -0
- package/dist/storybook-static/6.6185fd0d.iframe.bundle.d.ts +0 -0
- package/dist/storybook-static/7.0ede09e9.iframe.bundle.d.ts +0 -0
- package/dist/storybook-static/8.6f0230ef.iframe.bundle.d.ts +0 -2
- package/dist/storybook-static/main.6b7543c14993fcfcab71.manager.bundle.d.ts +0 -2
- package/dist/storybook-static/main.724b5942.iframe.bundle.d.ts +0 -9
- package/dist/storybook-static/runtime~main.92273705.iframe.bundle.d.ts +0 -1
- package/dist/storybook-static/runtime~main.c89e55a461c11ef29193.manager.bundle.d.ts +0 -1
|
@@ -1,3513 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
|
-
var styled = require('styled-components');
|
|
8
|
-
var styled__default = _interopDefault(styled);
|
|
9
|
-
var React = require('react');
|
|
10
|
-
var React__default = _interopDefault(React);
|
|
11
|
-
var d3 = require('d3');
|
|
12
|
-
var ReactDOMServer = _interopDefault(require('react-dom/server'));
|
|
13
|
-
var lodash = require('lodash');
|
|
14
|
-
var reactDom = require('react-dom');
|
|
15
|
-
|
|
16
|
-
function _extends() {
|
|
17
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
18
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
19
|
-
var t = arguments[e];
|
|
20
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
21
|
-
}
|
|
22
|
-
return n;
|
|
23
|
-
}, _extends.apply(null, arguments);
|
|
24
|
-
}
|
|
25
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
26
|
-
if (null == r) return {};
|
|
27
|
-
var t = {};
|
|
28
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
29
|
-
if (-1 !== e.indexOf(n)) continue;
|
|
30
|
-
t[n] = r[n];
|
|
31
|
-
}
|
|
32
|
-
return t;
|
|
33
|
-
}
|
|
34
|
-
function _taggedTemplateLiteralLoose(e, t) {
|
|
35
|
-
return t || (t = e.slice(0)), e.raw = t, e;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var _templateObject;
|
|
39
|
-
const Wrapper = /*#__PURE__*/styled__default.div(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n width: 100%;\n box-sizing: border-box;\n"])));
|
|
40
|
-
|
|
41
|
-
function useNode() {
|
|
42
|
-
const [node, onSetNode] = React.useState(null);
|
|
43
|
-
const ref = React.useCallback(onSetNode, [onSetNode]);
|
|
44
|
-
return [ref, node];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function throttle(fn, wait) {
|
|
48
|
-
let isCalled = false;
|
|
49
|
-
return function () {
|
|
50
|
-
if (!isCalled) {
|
|
51
|
-
fn(...arguments);
|
|
52
|
-
isCalled = true;
|
|
53
|
-
setTimeout(function () {
|
|
54
|
-
isCalled = false;
|
|
55
|
-
}, wait);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const THROTTLE_DELAY = 44;
|
|
61
|
-
const useResize = (width, callback, delay) => {
|
|
62
|
-
const throttledCallback = React.useMemo(() => {
|
|
63
|
-
return callback ? throttle(callback, delay || THROTTLE_DELAY) : undefined;
|
|
64
|
-
}, [callback, delay]);
|
|
65
|
-
React.useEffect(() => {
|
|
66
|
-
throttledCallback && typeof width !== "number" && window.addEventListener("resize", throttledCallback);
|
|
67
|
-
return () => throttledCallback && window.removeEventListener("resize", throttledCallback);
|
|
68
|
-
}, [width, throttledCallback]);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const appendSvg = (node, width, height) => {
|
|
72
|
-
d3.select(node).select('svg').remove();
|
|
73
|
-
const svg = d3.select(node).append('svg').attr('width', width).attr('height', height);
|
|
74
|
-
return svg;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
var _templateObject$1;
|
|
78
|
-
const SwipeScrollContainer = /*#__PURE__*/styled__default.div(_templateObject$1 || (_templateObject$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n overflow: hidden;\n user-select: none;\n"])));
|
|
79
|
-
|
|
80
|
-
function animate(_ref) {
|
|
81
|
-
let {
|
|
82
|
-
duration,
|
|
83
|
-
timing,
|
|
84
|
-
draw
|
|
85
|
-
} = _ref;
|
|
86
|
-
const start = performance.now();
|
|
87
|
-
let requestId;
|
|
88
|
-
requestAnimationFrame(function requestAnimate(time) {
|
|
89
|
-
let timeFraction = (time - start) / duration;
|
|
90
|
-
if (timeFraction < 1) {
|
|
91
|
-
requestId = requestAnimationFrame(requestAnimate);
|
|
92
|
-
}
|
|
93
|
-
if (timeFraction > 1) cancelAnimationFrame(requestId);
|
|
94
|
-
const progress = timing(timeFraction);
|
|
95
|
-
draw(progress, requestId);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
const easeOutQuad = time => time * (2 - time);
|
|
99
|
-
|
|
100
|
-
const range = (num, min, max) => Math.min(Math.max(num, min), max);
|
|
101
|
-
const defaultRefs = {
|
|
102
|
-
animation: 0,
|
|
103
|
-
speed: 0,
|
|
104
|
-
timestamp: 0,
|
|
105
|
-
startX: 0,
|
|
106
|
-
currentX: 0
|
|
107
|
-
};
|
|
108
|
-
const useSwipe = (node, _ref) => {
|
|
109
|
-
let {
|
|
110
|
-
width,
|
|
111
|
-
duration,
|
|
112
|
-
animationFunc,
|
|
113
|
-
onSwipe
|
|
114
|
-
} = _ref;
|
|
115
|
-
const container = d3.select(node);
|
|
116
|
-
const body = d3.select('body');
|
|
117
|
-
const documentSelect = d3.select(document);
|
|
118
|
-
const refs = React.useRef(defaultRefs);
|
|
119
|
-
React.useEffect(() => {
|
|
120
|
-
if (width && refs.current.animation) {
|
|
121
|
-
cancelAnimationFrame(refs.current.animation);
|
|
122
|
-
refs.current = defaultRefs;
|
|
123
|
-
}
|
|
124
|
-
}, [width]);
|
|
125
|
-
const onMove = React.useCallback(event => {
|
|
126
|
-
const {
|
|
127
|
-
width: nodeWidth
|
|
128
|
-
} = node ? node.getBoundingClientRect() : {
|
|
129
|
-
width: 0
|
|
130
|
-
};
|
|
131
|
-
const [x] = d3.pointer(event.type.includes('touch') ? event.touches[0] : event);
|
|
132
|
-
const newX = x - refs.current.startX;
|
|
133
|
-
const maxX = width - nodeWidth;
|
|
134
|
-
const translateX = range(newX, -maxX, 0);
|
|
135
|
-
container.style('transform', "translateX(" + translateX + "px)");
|
|
136
|
-
if (refs.current.currentX) {
|
|
137
|
-
const hundred = 100;
|
|
138
|
-
const now = Date.now();
|
|
139
|
-
const dt = now - refs.current.timestamp;
|
|
140
|
-
const dx = translateX - refs.current.currentX;
|
|
141
|
-
const speedX = Math.round(dx / dt * hundred);
|
|
142
|
-
refs.current.speed = speedX;
|
|
143
|
-
refs.current.timestamp = now;
|
|
144
|
-
}
|
|
145
|
-
refs.current.currentX = translateX;
|
|
146
|
-
onSwipe && onSwipe(translateX, container);
|
|
147
|
-
}, [onSwipe, width, node, container]);
|
|
148
|
-
const onEnd = React.useCallback(() => {
|
|
149
|
-
const {
|
|
150
|
-
width: nodeWidth
|
|
151
|
-
} = node ? node.getBoundingClientRect() : {
|
|
152
|
-
width: 0
|
|
153
|
-
};
|
|
154
|
-
documentSelect.on('mousemove.swipe touchmove.swipe mouseup.swipe touchend.swipe', null);
|
|
155
|
-
body.style('cursor', null);
|
|
156
|
-
if (width > nodeWidth) {
|
|
157
|
-
container.style('cursor', 'grab');
|
|
158
|
-
} else {
|
|
159
|
-
container.style('cursor', null);
|
|
160
|
-
}
|
|
161
|
-
const dt = Date.now() - refs.current.timestamp;
|
|
162
|
-
const dtEnd = 44;
|
|
163
|
-
if (dt < dtEnd) {
|
|
164
|
-
animate({
|
|
165
|
-
duration: duration,
|
|
166
|
-
timing: animationFunc || easeOutQuad,
|
|
167
|
-
draw: (progress, requestId) => {
|
|
168
|
-
refs.current.animation = requestId;
|
|
169
|
-
const px = Math.round(refs.current.speed * 2 * progress);
|
|
170
|
-
const currX = refs.current.currentX + px;
|
|
171
|
-
const maxX = width - nodeWidth;
|
|
172
|
-
const translateX = range(currX, -maxX, 0);
|
|
173
|
-
const transX = Math.max(Math.min(currX, maxX), 0);
|
|
174
|
-
if (refs.current.currentX !== transX) {
|
|
175
|
-
container.style('transform', "translateX(" + translateX + "px)");
|
|
176
|
-
onSwipe && onSwipe(translateX, container);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}, [body, animationFunc, onSwipe, container, duration, node, width, documentSelect]);
|
|
182
|
-
const onStart = React.useCallback(event => {
|
|
183
|
-
const isTouch = event.type.includes('touch');
|
|
184
|
-
const [x] = d3.pointer(isTouch ? event.touches[0] : event, node);
|
|
185
|
-
const {
|
|
186
|
-
left
|
|
187
|
-
} = node && node.parentElement ? node.parentElement.getBoundingClientRect() : {
|
|
188
|
-
left: 0
|
|
189
|
-
};
|
|
190
|
-
body.style('cursor', 'grabbing');
|
|
191
|
-
container.style('cursor', 'grabbing');
|
|
192
|
-
if (refs.current.animation) {
|
|
193
|
-
cancelAnimationFrame(refs.current.animation);
|
|
194
|
-
refs.current = defaultRefs;
|
|
195
|
-
}
|
|
196
|
-
refs.current.startX = Math.max(x + left, 0);
|
|
197
|
-
documentSelect.on('mousemove.swipe touchmove.swipe', onMove);
|
|
198
|
-
documentSelect.on('mouseup.swipe touchend.swipe', onEnd);
|
|
199
|
-
}, [container, body, node, onEnd, onMove, documentSelect]);
|
|
200
|
-
React.useEffect(() => {
|
|
201
|
-
if (node) {
|
|
202
|
-
const {
|
|
203
|
-
width: nodeWidth
|
|
204
|
-
} = node.getBoundingClientRect();
|
|
205
|
-
if (width > nodeWidth) {
|
|
206
|
-
container.style('cursor', 'grab');
|
|
207
|
-
container.on('mousedown.swipe touchstart.swipe', onStart);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}, [container, onStart, node, width]);
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
const _excluded = ["children", "width", "onSwipe"];
|
|
214
|
-
const SwipeScroll = _ref => {
|
|
215
|
-
let {
|
|
216
|
-
children,
|
|
217
|
-
width,
|
|
218
|
-
onSwipe
|
|
219
|
-
} = _ref,
|
|
220
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
221
|
-
const [ref, draggingNode] = useNode();
|
|
222
|
-
useSwipe(draggingNode, _extends({
|
|
223
|
-
width,
|
|
224
|
-
onSwipe
|
|
225
|
-
}, props));
|
|
226
|
-
return React__default.createElement(SwipeScrollContainer, Object.assign({}, props), React__default.createElement("div", {
|
|
227
|
-
ref: ref
|
|
228
|
-
}, children));
|
|
229
|
-
};
|
|
230
|
-
SwipeScroll.defaultProps = {
|
|
231
|
-
duration: 1400
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
const degByIndex = (index, count) => {
|
|
235
|
-
const degs = 360;
|
|
236
|
-
const deg = degs / count * index;
|
|
237
|
-
return deg;
|
|
238
|
-
};
|
|
239
|
-
const getTextAnchor = (index, length) => {
|
|
240
|
-
const deg = degByIndex(index, length);
|
|
241
|
-
const halfAngle = 180;
|
|
242
|
-
if ([0, halfAngle].includes(deg)) {
|
|
243
|
-
return 'middle';
|
|
244
|
-
}
|
|
245
|
-
if (deg < halfAngle) {
|
|
246
|
-
return 'start';
|
|
247
|
-
}
|
|
248
|
-
return 'end';
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
var _templateObject$2;
|
|
252
|
-
const getTranslate = _ref => {
|
|
253
|
-
let {
|
|
254
|
-
anchor,
|
|
255
|
-
index,
|
|
256
|
-
translateX,
|
|
257
|
-
translateY
|
|
258
|
-
} = _ref;
|
|
259
|
-
if (index === 0 && anchor === 'middle') {
|
|
260
|
-
return "translate(calc(-50% + " + translateX + "px), calc(-100% + " + translateY + "px))";
|
|
261
|
-
} else if (anchor === 'middle') {
|
|
262
|
-
return "translate(calc(-50% + " + translateX + "px), calc(" + translateY + "px))";
|
|
263
|
-
} else if (anchor === 'start') {
|
|
264
|
-
return "translate(calc(" + translateX + "px), calc(-50% + " + translateY + "px))";
|
|
265
|
-
} else if (anchor === 'end') {
|
|
266
|
-
return "translate(calc(-100% + " + translateX + "px), calc(-50% + " + translateY + "px))";
|
|
267
|
-
}
|
|
268
|
-
return "translate(" + translateX + "px, " + translateY + "px)";
|
|
269
|
-
};
|
|
270
|
-
const LabelContainer = /*#__PURE__*/styled__default.div.attrs(props => ({
|
|
271
|
-
style: {
|
|
272
|
-
transform: getTranslate(props)
|
|
273
|
-
}
|
|
274
|
-
}))(_templateObject$2 || (_templateObject$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n"])));
|
|
275
|
-
|
|
276
|
-
const labelClassName = 'd3-chart-label';
|
|
277
|
-
const drawRadialLabels = _ref => {
|
|
278
|
-
let {
|
|
279
|
-
node,
|
|
280
|
-
dataLength,
|
|
281
|
-
radiusScale,
|
|
282
|
-
maxValue,
|
|
283
|
-
angleSlice,
|
|
284
|
-
radius,
|
|
285
|
-
xOffset,
|
|
286
|
-
yOffset,
|
|
287
|
-
translateX,
|
|
288
|
-
translateY,
|
|
289
|
-
renderLabel,
|
|
290
|
-
selectLabel
|
|
291
|
-
} = _ref;
|
|
292
|
-
const d3container = d3.select(node);
|
|
293
|
-
d3container.selectAll("." + labelClassName).remove();
|
|
294
|
-
const pxToValue = value => maxValue / radius * value;
|
|
295
|
-
const axisX = i => radiusScale(maxValue + pxToValue(xOffset || 0)) * Math.cos(angleSlice * i - Math.PI / 2);
|
|
296
|
-
const axisY = i => radiusScale((maxValue + pxToValue(yOffset || 0)) * Math.sin(angleSlice * i - Math.PI / 2));
|
|
297
|
-
const labels = Array.from({
|
|
298
|
-
length: dataLength
|
|
299
|
-
}, (_, index) => ({
|
|
300
|
-
x: Math.ceil(axisX(index)),
|
|
301
|
-
y: Math.ceil(axisY(index))
|
|
302
|
-
}));
|
|
303
|
-
labels.forEach((_ref2, index) => {
|
|
304
|
-
let {
|
|
305
|
-
x,
|
|
306
|
-
y
|
|
307
|
-
} = _ref2;
|
|
308
|
-
const anchor = getTextAnchor(index, dataLength);
|
|
309
|
-
const html = ReactDOMServer.renderToString(React__default.createElement(LabelContainer, {
|
|
310
|
-
anchor: anchor,
|
|
311
|
-
translateX: translateX || 0,
|
|
312
|
-
translateY: translateY || 0,
|
|
313
|
-
index: index,
|
|
314
|
-
style: {
|
|
315
|
-
left: x,
|
|
316
|
-
top: y
|
|
317
|
-
}
|
|
318
|
-
}, typeof renderLabel === 'function' ? renderLabel(anchor, index) : renderLabel));
|
|
319
|
-
const label = d3container.append('div').attr('class', labelClassName).html(html);
|
|
320
|
-
selectLabel(label, anchor, index);
|
|
321
|
-
});
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
var _templateObject$3, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
325
|
-
const getTranslate$1 = _ref => {
|
|
326
|
-
let {
|
|
327
|
-
anchor,
|
|
328
|
-
index,
|
|
329
|
-
translateX,
|
|
330
|
-
translateY
|
|
331
|
-
} = _ref;
|
|
332
|
-
if (index === 0 && anchor === "middle") {
|
|
333
|
-
return "translate(calc(-50% + " + translateX + "px), calc(-100% + " + translateY + "px))";
|
|
334
|
-
} else if (anchor === "middle") {
|
|
335
|
-
return "translate(calc(-50% + " + translateX + "px), calc(" + translateY + "px))";
|
|
336
|
-
} else if (anchor === "start") {
|
|
337
|
-
return "translate(calc(" + translateX + "px), calc(-50% + " + translateY + "px))";
|
|
338
|
-
} else if (anchor === "end") {
|
|
339
|
-
return "translate(calc(-100% + " + translateX + "px), calc(-50% + " + translateY + "px))";
|
|
340
|
-
}
|
|
341
|
-
return "translate(" + translateX + "px, " + translateY + "px)";
|
|
342
|
-
};
|
|
343
|
-
const Label = /*#__PURE__*/styled__default.div(_templateObject$3 || (_templateObject$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n font-size: 12px;\n"])));
|
|
344
|
-
const Name = /*#__PURE__*/styled__default.div(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n text-align: center;\n max-width: 120px;\n"])));
|
|
345
|
-
const middleBadgeStyles = /*#__PURE__*/styled.css(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n top: 50%;\n right: 0;\n transform: translate(calc(100% + 6px), -50%);\n"])));
|
|
346
|
-
const DefaultBadge = /*#__PURE__*/styled__default.div(_templateObject4 || (_templateObject4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n padding: 2px 4px;\n border-radius: 4px;\n color: rgb(255, 255, 255);\n background-color: rgb(144, 197, 61);\n margin-left: 8px;\n"])));
|
|
347
|
-
const MiddleBadge = /*#__PURE__*/styled__default(DefaultBadge)(_templateObject5 || (_templateObject5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n ", "\n"])), middleBadgeStyles);
|
|
348
|
-
const BadgePrefix = /*#__PURE__*/styled__default.div(_templateObject6 || (_templateObject6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-left: 4px;\n font-size: 10px;\n color: rgba(255, 255, 255, 0.54);\n"])));
|
|
349
|
-
|
|
350
|
-
var _templateObject$4;
|
|
351
|
-
const radarChartclassNames = {
|
|
352
|
-
radar: 'radar',
|
|
353
|
-
radarAxis: 'radarAxis',
|
|
354
|
-
radarAxisTextGlobal: 'radarAxisTextGlobal',
|
|
355
|
-
radarAxisText: 'radarAxisText',
|
|
356
|
-
radarPolygon: 'radarPolygon',
|
|
357
|
-
radarLabel: 'radarLabel',
|
|
358
|
-
radarLabelName: 'radarLabelName',
|
|
359
|
-
radarLabelBadge: 'radarLabelBadge',
|
|
360
|
-
radarLabelBadgePrefix: 'radarLabelBadgePrefix',
|
|
361
|
-
radarCircle: 'radarCircle'
|
|
362
|
-
};
|
|
363
|
-
const SvgWrapper = /*#__PURE__*/styled__default(Wrapper)(_templateObject$4 || (_templateObject$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n path,\n line,\n circle {\n fill: none;\n stroke-width: 1px;\n stroke: rgba(149, 149, 149, 0.18);\n }\n }\n .", " {\n font-size: 12px;\n fill-opacity: 0.56;\n }\n .", " {\n fill-opacity: 0.06;\n stroke-width: 2px;\n fill: rgb(144, 197, 61);\n stroke: rgb(144, 197, 61);\n }\n .", " {\n fill: rgb(144, 197, 61);\n }\n"])), radarChartclassNames.radarAxis, radarChartclassNames.radarAxisText, radarChartclassNames.radarPolygon, radarChartclassNames.radarCircle);
|
|
364
|
-
|
|
365
|
-
const draw = (node, props) => {
|
|
366
|
-
const {
|
|
367
|
-
data,
|
|
368
|
-
curve,
|
|
369
|
-
polar,
|
|
370
|
-
formatValue,
|
|
371
|
-
badgePrefix,
|
|
372
|
-
labelOffset,
|
|
373
|
-
circleRadius,
|
|
374
|
-
svgElements,
|
|
375
|
-
renderLabel: _renderLabel,
|
|
376
|
-
customize,
|
|
377
|
-
formatAxisValue,
|
|
378
|
-
radarStyles,
|
|
379
|
-
labelIndex,
|
|
380
|
-
selectLabel: _selectLabel
|
|
381
|
-
} = props;
|
|
382
|
-
if (node !== null && data.length) {
|
|
383
|
-
const defaultBleedLength = 10;
|
|
384
|
-
const bleedLength = typeof props.bleedLength === 'number' ? props.bleedLength : defaultBleedLength;
|
|
385
|
-
const {
|
|
386
|
-
width: nodeWidth
|
|
387
|
-
} = node.getBoundingClientRect();
|
|
388
|
-
const width = props.width || nodeWidth;
|
|
389
|
-
const defaultHeight = 400;
|
|
390
|
-
const height = props.height || defaultHeight;
|
|
391
|
-
const minValue = props.minValue || Math.min(0, d3.min(data, i => d3.min(i.map(_ref => {
|
|
392
|
-
let {
|
|
393
|
-
value
|
|
394
|
-
} = _ref;
|
|
395
|
-
return value;
|
|
396
|
-
}))));
|
|
397
|
-
const maxValue = (props.maxValue || Math.max(0, d3.max(data, i => d3.max(i.map(_ref2 => {
|
|
398
|
-
let {
|
|
399
|
-
value
|
|
400
|
-
} = _ref2;
|
|
401
|
-
return value;
|
|
402
|
-
}))))) - minValue;
|
|
403
|
-
const paddingX = props.paddingX || 0;
|
|
404
|
-
const paddingY = props.paddingY || 0;
|
|
405
|
-
const radius = Math.min((width - paddingX * 2 - bleedLength * 2) / 2, (height - paddingY * 2 - bleedLength * 2) / 2);
|
|
406
|
-
const defaultLevels = 4;
|
|
407
|
-
const ticks = d3.scaleLinear().domain([0, maxValue || 1]).range([]).ticks(props.levels || defaultLevels);
|
|
408
|
-
const lastTick = ticks[ticks.length - 1];
|
|
409
|
-
const newLastTick = lastTick + (ticks[1] - ticks[0]);
|
|
410
|
-
if (lastTick < maxValue) {
|
|
411
|
-
ticks.push(newLastTick);
|
|
412
|
-
}
|
|
413
|
-
const levels = props.levels || ticks.length - 1;
|
|
414
|
-
const newMaxValue = ticks[ticks.length - 1];
|
|
415
|
-
const angleSlice = Math.PI * 2 / data[0].length;
|
|
416
|
-
const radiusScale = d3.scaleLinear().range([0, radius]).domain([0, newMaxValue]);
|
|
417
|
-
const radarLine = d3.lineRadial().curve(d3.curveLinearClosed)
|
|
418
|
-
// @ts-ignore
|
|
419
|
-
.radius(_ref3 => {
|
|
420
|
-
let {
|
|
421
|
-
value
|
|
422
|
-
} = _ref3;
|
|
423
|
-
return radiusScale(value);
|
|
424
|
-
}).angle((_, i) => i * angleSlice);
|
|
425
|
-
const radarValue = d3.lineRadial().curve(curve || d3.curveLinearClosed)
|
|
426
|
-
// @ts-ignore
|
|
427
|
-
.radius(_ref4 => {
|
|
428
|
-
let {
|
|
429
|
-
value
|
|
430
|
-
} = _ref4;
|
|
431
|
-
return radiusScale(value);
|
|
432
|
-
}).angle((_, i) => i * angleSlice);
|
|
433
|
-
const svg = appendSvg(node, width, height);
|
|
434
|
-
const globalCenter = svg.append('g');
|
|
435
|
-
const levelsGrid = d3.range(1, levels + 1).reverse();
|
|
436
|
-
const axisGridY = value => -value * radius / levels;
|
|
437
|
-
const getAxisValue = value => newMaxValue * value / levels;
|
|
438
|
-
const gridGlobal = globalCenter.append('g').attr('class', radarChartclassNames.radarAxis).selectAll().data([data[0]]).enter();
|
|
439
|
-
const radarGlobal = globalCenter.append('g').attr('class', radarChartclassNames.radar);
|
|
440
|
-
const axis = gridGlobal.selectAll().data(data[0].map(_ref5 => {
|
|
441
|
-
let {
|
|
442
|
-
name
|
|
443
|
-
} = _ref5;
|
|
444
|
-
return name;
|
|
445
|
-
})).enter();
|
|
446
|
-
let maxGridHeight = 0;
|
|
447
|
-
if (polar) {
|
|
448
|
-
levelsGrid.forEach(value => {
|
|
449
|
-
const path = gridGlobal.append('circle').attr('cx', 0).attr('cy', 0).attr('r', () => radius / levels * value);
|
|
450
|
-
const circleNode = path.node();
|
|
451
|
-
const circleHeight = circleNode.getBoundingClientRect().height;
|
|
452
|
-
maxGridHeight = Math.max(maxGridHeight, circleHeight);
|
|
453
|
-
});
|
|
454
|
-
} else {
|
|
455
|
-
levelsGrid.map(getAxisValue).forEach(value => {
|
|
456
|
-
const path = gridGlobal.append('path').attr('d', () =>
|
|
457
|
-
// @ts-ignore
|
|
458
|
-
radarLine(Array.from({
|
|
459
|
-
length: data[0].length
|
|
460
|
-
}, () => ({
|
|
461
|
-
value
|
|
462
|
-
}))));
|
|
463
|
-
const pathNode = path.node();
|
|
464
|
-
const pathHeight = pathNode.getBoundingClientRect().height;
|
|
465
|
-
maxGridHeight = Math.max(maxGridHeight, pathHeight);
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
const radiusByMaxValue = radiusScale(newMaxValue) + bleedLength;
|
|
469
|
-
axis.append('line').attr('x1', 0).attr('y1', 0).attr('x2', (_, i) => Math.round(radiusByMaxValue * Math.cos(angleSlice * i - Math.PI / 2))).attr('y2', (_, i) => Math.round(radiusByMaxValue * Math.sin(angleSlice * i - Math.PI / 2)));
|
|
470
|
-
radarGlobal.selectAll('path').data(data).join('path').attr('class', radarChartclassNames.radarPolygon).attr('style', (_, index) => (radarStyles == null ? void 0 : radarStyles[index]) || '').attr('d', d => radarValue(
|
|
471
|
-
// @ts-ignore
|
|
472
|
-
d.map(dataItem => _extends({}, dataItem, {
|
|
473
|
-
value: dataItem.value - minValue
|
|
474
|
-
}))));
|
|
475
|
-
const format = d3.format(',');
|
|
476
|
-
const axisTextGlobal = globalCenter.append('g').attr('class', radarChartclassNames.radarAxisTextGlobal);
|
|
477
|
-
axisTextGlobal.selectAll('text').data(levelsGrid).enter().append('text').attr('class', radarChartclassNames.radarAxisText).attr('x', '4').attr('y', axisGridY).attr('dy', 0).attr('dominant-baseline', 'central').text((value, index) => {
|
|
478
|
-
const axisValue = getAxisValue(value) + minValue;
|
|
479
|
-
return formatAxisValue ? formatAxisValue(axisValue, index) : format(axisValue);
|
|
480
|
-
});
|
|
481
|
-
circleRadius && data.forEach(item => {
|
|
482
|
-
const circleGlobal = globalCenter.append('g').attr('class', radarChartclassNames.radarCircle);
|
|
483
|
-
item.forEach((_ref6, i) => {
|
|
484
|
-
let {
|
|
485
|
-
value
|
|
486
|
-
} = _ref6;
|
|
487
|
-
circleGlobal.append('circle').attr('cx', Math.round(radiusScale(value) * Math.cos(angleSlice * i - Math.PI / 2))).attr('cy', Math.round(radiusScale(value * Math.sin(angleSlice * i - Math.PI / 2)))).attr('r', circleRadius);
|
|
488
|
-
});
|
|
489
|
-
});
|
|
490
|
-
const defaultLabelOffset = 8;
|
|
491
|
-
const heightInner = height - bleedLength - paddingY;
|
|
492
|
-
const translateX = width / 2;
|
|
493
|
-
const translateY = heightInner / 2 + (heightInner - maxGridHeight) / 2;
|
|
494
|
-
const offset = bleedLength + (labelOffset || defaultLabelOffset);
|
|
495
|
-
globalCenter.attr('transform', "translate(" + translateX + "," + translateY + ")");
|
|
496
|
-
drawRadialLabels({
|
|
497
|
-
node,
|
|
498
|
-
maxValue: newMaxValue,
|
|
499
|
-
translateX,
|
|
500
|
-
translateY,
|
|
501
|
-
dataLength: data[labelIndex || 0].length,
|
|
502
|
-
angleSlice,
|
|
503
|
-
radius,
|
|
504
|
-
radiusScale,
|
|
505
|
-
xOffset: offset,
|
|
506
|
-
yOffset: offset,
|
|
507
|
-
renderLabel: (anchor, index) => {
|
|
508
|
-
const items = data.map(item => item[index]);
|
|
509
|
-
const Badge = anchor === 'middle' ? MiddleBadge : DefaultBadge;
|
|
510
|
-
const item = data[labelIndex || 0][index];
|
|
511
|
-
const {
|
|
512
|
-
name,
|
|
513
|
-
value
|
|
514
|
-
} = item;
|
|
515
|
-
return _renderLabel ? _renderLabel({
|
|
516
|
-
item,
|
|
517
|
-
items,
|
|
518
|
-
anchor,
|
|
519
|
-
index
|
|
520
|
-
}) : React__default.createElement(Label, {
|
|
521
|
-
className: radarChartclassNames.radarLabel
|
|
522
|
-
}, React__default.createElement(Name, {
|
|
523
|
-
className: radarChartclassNames.radarLabelName
|
|
524
|
-
}, name), React__default.createElement(Badge, {
|
|
525
|
-
className: radarChartclassNames.radarLabelBadge
|
|
526
|
-
}, formatValue ? formatValue(value, index) : format(value), badgePrefix && React__default.createElement(BadgePrefix, {
|
|
527
|
-
className: radarChartclassNames.radarLabelBadgePrefix
|
|
528
|
-
}, badgePrefix)));
|
|
529
|
-
},
|
|
530
|
-
selectLabel: (label, anchor, index) => {
|
|
531
|
-
if (_selectLabel) {
|
|
532
|
-
const items = data.map(item => item[index]);
|
|
533
|
-
const item = data[labelIndex || 0][index];
|
|
534
|
-
_selectLabel(label, {
|
|
535
|
-
index,
|
|
536
|
-
item,
|
|
537
|
-
items,
|
|
538
|
-
anchor
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
if (svgElements) {
|
|
544
|
-
const html = ReactDOMServer.renderToString(svgElements);
|
|
545
|
-
svg.append('g').html(html);
|
|
546
|
-
}
|
|
547
|
-
customize && customize(svg);
|
|
548
|
-
}
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
const RadarChart = props => {
|
|
552
|
-
const {
|
|
553
|
-
className,
|
|
554
|
-
style
|
|
555
|
-
} = props;
|
|
556
|
-
const [ref, node] = useNode();
|
|
557
|
-
React.useEffect(() => {
|
|
558
|
-
node && draw(node, props);
|
|
559
|
-
}, [node, props]);
|
|
560
|
-
const onDraw = () => draw(node, props);
|
|
561
|
-
useResize(props.width, onDraw);
|
|
562
|
-
return React__default.createElement("div", {
|
|
563
|
-
className: className,
|
|
564
|
-
style: style
|
|
565
|
-
}, React__default.createElement(SvgWrapper, {
|
|
566
|
-
ref: ref
|
|
567
|
-
}));
|
|
568
|
-
};
|
|
569
|
-
RadarChart.defaultProps = {
|
|
570
|
-
height: 400,
|
|
571
|
-
data: [],
|
|
572
|
-
curve: d3.curveLinearClosed
|
|
573
|
-
};
|
|
574
|
-
|
|
575
|
-
function radiansToDegrees(radians) {
|
|
576
|
-
const flatAngle = 180;
|
|
577
|
-
return radians * flatAngle / Math.PI;
|
|
578
|
-
}
|
|
579
|
-
function degreesToRadians(degrees) {
|
|
580
|
-
const flatAngle = 180;
|
|
581
|
-
return degrees * (Math.PI / flatAngle);
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
var _templateObject$5;
|
|
585
|
-
const pieChartclassNames = {
|
|
586
|
-
pieGlobal: 'pieGlobal',
|
|
587
|
-
pieSlice: 'pieSlice',
|
|
588
|
-
pieSliceLabel: 'pieSliceLabel',
|
|
589
|
-
pieSliceLabelValue: 'pieSliceLabelValue',
|
|
590
|
-
pieSliceLabelName: 'pieSliceLabelName',
|
|
591
|
-
pieRadialLabel: 'pieRadialLabel',
|
|
592
|
-
pieRadialLink: 'pieRadialLink',
|
|
593
|
-
pieTooltipContainer: 'pieTooltipContainer',
|
|
594
|
-
pieTooltipFlex: 'pieTooltipFlex',
|
|
595
|
-
pieTooltip: 'pieTooltip',
|
|
596
|
-
pieTooltipItem: 'pieTooltipItem',
|
|
597
|
-
pieTooltipName: 'pieTooltipName',
|
|
598
|
-
pieTooltipValue: 'pieTooltipValue',
|
|
599
|
-
pieTooltipColorBox: 'pieTooltipColorBox',
|
|
600
|
-
pieFullChartTooltipCircle: 'pieFullChartTooltipCircle'
|
|
601
|
-
};
|
|
602
|
-
const SvgWrapper$1 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$5 || (_templateObject$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n fill: #4a4a4a;\n }\n .", " {\n position: absolute;\n max-width: 128px;\n }\n .", " {\n stroke: #000;\n }\n .", " {\n fill: transparent;\n cursor: pointer;\n }\n"])), pieChartclassNames.pieSliceLabel, pieChartclassNames.pieRadialLabel, pieChartclassNames.pieRadialLink, pieChartclassNames.pieFullChartTooltipCircle);
|
|
603
|
-
|
|
604
|
-
const getMidFactor = d => d.startAngle + (d.endAngle - d.startAngle) / 2 < Math.PI ? 1 : -1;
|
|
605
|
-
const getAlign = d => {
|
|
606
|
-
const midangle = d.startAngle + (d.endAngle - d.startAngle) / 2;
|
|
607
|
-
return midangle < Math.PI ? 'start' : 'end';
|
|
608
|
-
};
|
|
609
|
-
|
|
610
|
-
const drawRadialLabels$1 = _ref => {
|
|
611
|
-
let {
|
|
612
|
-
arc,
|
|
613
|
-
enableRadialLabels,
|
|
614
|
-
global,
|
|
615
|
-
node,
|
|
616
|
-
radius,
|
|
617
|
-
dataReady,
|
|
618
|
-
radialLabelsLinkHorizontalLength,
|
|
619
|
-
formatRadialLabel,
|
|
620
|
-
radialLabelsTextXOffset,
|
|
621
|
-
translateX,
|
|
622
|
-
translateY,
|
|
623
|
-
radialLabelYOffset,
|
|
624
|
-
radialAngleXOffset
|
|
625
|
-
} = _ref;
|
|
626
|
-
const d3container = d3.select(node);
|
|
627
|
-
d3container.selectAll("." + pieChartclassNames.pieRadialLabel).remove();
|
|
628
|
-
if (enableRadialLabels) {
|
|
629
|
-
const defaultRadialLabelsLinkHorizontalLength = 4;
|
|
630
|
-
const outerArc = d3.arc().innerRadius(radius).outerRadius(radius);
|
|
631
|
-
global.selectAll('allPolylines').data(dataReady).enter().append('polyline').attr('class', pieChartclassNames.pieRadialLink).style('fill', 'none').attr('points', d => {
|
|
632
|
-
const midFactor = getMidFactor(d);
|
|
633
|
-
const posA = arc.centroid(d);
|
|
634
|
-
const posB = outerArc.centroid(d);
|
|
635
|
-
const posC = outerArc.centroid(d);
|
|
636
|
-
const posCPi = [(radius + (radialLabelsLinkHorizontalLength || defaultRadialLabelsLinkHorizontalLength)) * midFactor, posC[1]];
|
|
637
|
-
return [[posA[0], posA[1]], [posB[0] + (radialAngleXOffset || 0) * midFactor, posB[1] - (radialLabelYOffset || 0) * d.index], [posCPi[0], posCPi[1] - (radialLabelYOffset || 0) * d.index]];
|
|
638
|
-
});
|
|
639
|
-
const getPosition = d => {
|
|
640
|
-
const pos = outerArc.centroid(d);
|
|
641
|
-
return [(radius + (radialLabelsLinkHorizontalLength || defaultRadialLabelsLinkHorizontalLength)) * getMidFactor(d), pos[1]];
|
|
642
|
-
};
|
|
643
|
-
const defaultRadialLabelsTextXOffset = 4;
|
|
644
|
-
d3container.selectAll('allLabels').data(dataReady).enter().append('div')
|
|
645
|
-
// @ts-ignore
|
|
646
|
-
.html(d => {
|
|
647
|
-
const html = ReactDOMServer.renderToString(
|
|
648
|
-
// @ts-ignore
|
|
649
|
-
formatRadialLabel ? formatRadialLabel(d) : d.data.name);
|
|
650
|
-
return html;
|
|
651
|
-
}).attr('class', pieChartclassNames.pieRadialLabel)
|
|
652
|
-
// @ts-ignore
|
|
653
|
-
.style('transform', d => getTranslate$1({
|
|
654
|
-
anchor: getAlign(d),
|
|
655
|
-
index: d.index,
|
|
656
|
-
translateX,
|
|
657
|
-
translateY: translateY - (radialLabelYOffset || 0) * d.index
|
|
658
|
-
}))
|
|
659
|
-
// @ts-ignore
|
|
660
|
-
.style('left',
|
|
661
|
-
// @ts-ignore
|
|
662
|
-
d => getPosition(d)[0] - (getAlign(d) === 'start' ? -(radialLabelsTextXOffset || defaultRadialLabelsTextXOffset) : radialLabelsTextXOffset || defaultRadialLabelsTextXOffset) + "px")
|
|
663
|
-
// @ts-ignore
|
|
664
|
-
.style('top', d => getPosition(d)[1] + "px")
|
|
665
|
-
// @ts-ignore
|
|
666
|
-
.style('text-align', getAlign);
|
|
667
|
-
}
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
var _templateObject$6, _templateObject2$1, _templateObject3$1, _templateObject4$1, _templateObject5$1, _templateObject6$1, _templateObject7, _templateObject8, _templateObject9, _templateObject0, _templateObject1, _templateObject10, _templateObject11, _templateObject12;
|
|
671
|
-
const TooltipFlex = /*#__PURE__*/styled__default.div(_templateObject$6 || (_templateObject$6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 0;\n height: 0;\n display: flex;\n align-items: flex-end;\n justify-content: center;\n pointer-events: none;\n white-space: nowrap;\n"])));
|
|
672
|
-
const LabelFlex = /*#__PURE__*/styled__default(TooltipFlex)(_templateObject2$1 || (_templateObject2$1 = /*#__PURE__*/_taggedTemplateLiteralLoose([""])));
|
|
673
|
-
const LabelFlexCenter = /*#__PURE__*/styled__default(LabelFlex)(_templateObject3$1 || (_templateObject3$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n align-items: center;\n"])));
|
|
674
|
-
const TooltipContainer = /*#__PURE__*/styled__default.div(_templateObject4$1 || (_templateObject4$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n font-size: 11px;\n color: #fff;\n margin-bottom: 8px;\n padding: 4px 6px;\n background-color: rgba(48, 69, 79, 1);\n border-radius: 4px;\n box-shadow: 0 0.1875rem 0.5rem rgba(48, 69, 79, 0.06);\n\n :before {\n content: '';\n position: absolute;\n bottom: 0;\n left: 50%;\n transform: translate(-50%, 100%);\n width: 0;\n height: 0;\n border-style: solid;\n border-width: 4px 3px 0 3px;\n border-color: rgba(48, 69, 79, 1) transparent transparent transparent;\n }\n"])));
|
|
675
|
-
const TooltipGroupName = /*#__PURE__*/styled__default.div(_templateObject5$1 || (_templateObject5$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: 14px;\n margin-bottom: 6px;\n"])));
|
|
676
|
-
const TooltipItem = /*#__PURE__*/styled__default.div(_templateObject6$1 || (_templateObject6$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n margin-bottom: 0.25rem;\n\n &:last-of-type {\n margin-bottom: 0;\n }\n"])));
|
|
677
|
-
const ColFlex = /*#__PURE__*/styled__default.div(_templateObject7 || (_templateObject7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n margin-right: 4px;\n"])));
|
|
678
|
-
const ColorBox = /*#__PURE__*/styled__default.div(_templateObject8 || (_templateObject8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-right: 4px;\n width: 10px;\n height: 10px;\n border-radius: 2px;\n"])));
|
|
679
|
-
const ColorLine = /*#__PURE__*/styled__default(ColorBox)(_templateObject9 || (_templateObject9 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n height: 2px;\n border-radius: 0;\n"])));
|
|
680
|
-
const Name$1 = /*#__PURE__*/styled__default.div(_templateObject0 || (_templateObject0 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-right: 4px;\n"])));
|
|
681
|
-
const Value = /*#__PURE__*/styled__default.div(_templateObject1 || (_templateObject1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n text-align: right;\n flex-shrink: 0;\n flex-grow: 1;\n"])));
|
|
682
|
-
const Label$1 = /*#__PURE__*/styled__default.div(_templateObject10 || (_templateObject10 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n font-size: 11px;\n color: #fff;\n font-weight: bold;\n letter-spacing: 0.52px;\n"])));
|
|
683
|
-
const LabelTop = /*#__PURE__*/styled__default(Label$1)(_templateObject11 || (_templateObject11 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n top: 6px;\n"])));
|
|
684
|
-
const LabelBottom = /*#__PURE__*/styled__default(Label$1)(_templateObject12 || (_templateObject12 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n bottom: 6px;\n"])));
|
|
685
|
-
|
|
686
|
-
const drawTooltip = _ref => {
|
|
687
|
-
let {
|
|
688
|
-
fullChartTooltip,
|
|
689
|
-
global,
|
|
690
|
-
tooltipRoot,
|
|
691
|
-
data,
|
|
692
|
-
tooltipClassName,
|
|
693
|
-
tooltipBind,
|
|
694
|
-
renderTooltip,
|
|
695
|
-
arc,
|
|
696
|
-
allSlices,
|
|
697
|
-
tooltipStyle,
|
|
698
|
-
width,
|
|
699
|
-
height,
|
|
700
|
-
radius
|
|
701
|
-
} = _ref;
|
|
702
|
-
const container = tooltipRoot || document.querySelector('body');
|
|
703
|
-
const format = d3.format(',');
|
|
704
|
-
const pieTooltipContainer = d3.select(container).select("." + pieChartclassNames.pieTooltipContainer);
|
|
705
|
-
const isEmpty = pieTooltipContainer.empty();
|
|
706
|
-
const tooltipContainer = isEmpty ? d3.select(container).append('div').attr('class', pieChartclassNames.pieTooltipContainer + " " + (tooltipClassName || '')).style('position', 'absolute').style('opacity', '0').style('z-index', '103') : pieTooltipContainer;
|
|
707
|
-
if (tooltipStyle) {
|
|
708
|
-
Object.entries(tooltipStyle).forEach(_ref2 => {
|
|
709
|
-
let [prop, val] = _ref2;
|
|
710
|
-
return tooltipContainer.style(prop, val);
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
tooltipContainer.html('');
|
|
714
|
-
let isVisible = false;
|
|
715
|
-
const setVisible = visible => {
|
|
716
|
-
isVisible = Boolean(visible);
|
|
717
|
-
const opacity = isVisible ? '1' : '0';
|
|
718
|
-
tooltipContainer.style('opacity', opacity);
|
|
719
|
-
};
|
|
720
|
-
const setPosition = (event, pieChartDatum) => {
|
|
721
|
-
let [x, y] = d3.pointer(event, document);
|
|
722
|
-
if (!tooltipBind && fullChartTooltip) {
|
|
723
|
-
const [itemX, itemY] = d3.pointer(event, event.target);
|
|
724
|
-
x = x - itemX;
|
|
725
|
-
y = y - itemY;
|
|
726
|
-
} else if (!tooltipBind) {
|
|
727
|
-
const globalNode = global.node();
|
|
728
|
-
const {
|
|
729
|
-
x: itemX,
|
|
730
|
-
y: itemY,
|
|
731
|
-
width: itemWidth,
|
|
732
|
-
height: itemHeight
|
|
733
|
-
} = globalNode ? globalNode.getBoundingClientRect() : {
|
|
734
|
-
x: 0,
|
|
735
|
-
y: 0,
|
|
736
|
-
width: 0,
|
|
737
|
-
height: 0
|
|
738
|
-
};
|
|
739
|
-
const [arcX, arcY] = arc.centroid(pieChartDatum);
|
|
740
|
-
x = itemX + itemWidth / 2 + arcX;
|
|
741
|
-
y = itemY + itemHeight / 2 + arcY;
|
|
742
|
-
}
|
|
743
|
-
tooltipContainer.style('left', x + 'px').style('top', y + 'px');
|
|
744
|
-
};
|
|
745
|
-
const setTooltip = (event, pieChartDatum) => {
|
|
746
|
-
setVisible(true);
|
|
747
|
-
setPosition(event, pieChartDatum);
|
|
748
|
-
const pieChartData = pieChartDatum ? [pieChartDatum.data] : data;
|
|
749
|
-
tooltipContainer.html(() => {
|
|
750
|
-
const html = ReactDOMServer.renderToString(React__default.createElement(TooltipFlex, {
|
|
751
|
-
className: pieChartclassNames.pieTooltipFlex
|
|
752
|
-
}, React__default.createElement(TooltipContainer, {
|
|
753
|
-
className: pieChartclassNames.pieTooltip
|
|
754
|
-
}, renderTooltip ? renderTooltip(pieChartData) : React__default.createElement(React__default.Fragment, null, pieChartData.map((_ref3, index) => {
|
|
755
|
-
let {
|
|
756
|
-
color,
|
|
757
|
-
name,
|
|
758
|
-
value
|
|
759
|
-
} = _ref3;
|
|
760
|
-
return React__default.createElement(TooltipItem, {
|
|
761
|
-
key: name + "-" + index,
|
|
762
|
-
className: pieChartclassNames.pieTooltipItem
|
|
763
|
-
}, color && React__default.createElement(ColorBox, {
|
|
764
|
-
className: pieChartclassNames.pieTooltipColorBox,
|
|
765
|
-
style: {
|
|
766
|
-
backgroundColor: color
|
|
767
|
-
}
|
|
768
|
-
}), name && React__default.createElement(Name$1, {
|
|
769
|
-
className: pieChartclassNames.pieTooltipName
|
|
770
|
-
}, name), React__default.createElement(Value, {
|
|
771
|
-
className: pieChartclassNames.pieTooltipValue
|
|
772
|
-
}, format(value)));
|
|
773
|
-
})))));
|
|
774
|
-
return html;
|
|
775
|
-
});
|
|
776
|
-
};
|
|
777
|
-
if (fullChartTooltip) {
|
|
778
|
-
global.on('mouseover.fulltooltip', event => setTooltip(event));
|
|
779
|
-
global.on('mouseout.fulltooltip', () => {
|
|
780
|
-
tooltipContainer.html('');
|
|
781
|
-
setVisible();
|
|
782
|
-
});
|
|
783
|
-
if (width && height) {
|
|
784
|
-
global.append('circle').attr('class', pieChartclassNames.pieFullChartTooltipCircle).attr('r', radius).attr('cx', 0).attr('cy', 0);
|
|
785
|
-
}
|
|
786
|
-
if (!tooltipBind) {
|
|
787
|
-
global.on('touchmove.tooltipBind mousemove.tooltipBind', event => setPosition(event));
|
|
788
|
-
}
|
|
789
|
-
} else {
|
|
790
|
-
allSlices.on('mouseover.slice', setTooltip);
|
|
791
|
-
if (!tooltipBind) {
|
|
792
|
-
allSlices.on('touchmove.slice mousemove.slice', setPosition);
|
|
793
|
-
}
|
|
794
|
-
allSlices.on('mouseout.slice', () => {
|
|
795
|
-
tooltipContainer.html('');
|
|
796
|
-
setVisible();
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
};
|
|
800
|
-
|
|
801
|
-
const draw$1 = (node, props) => {
|
|
802
|
-
const {
|
|
803
|
-
data,
|
|
804
|
-
padAngle,
|
|
805
|
-
onClick,
|
|
806
|
-
outerRadius,
|
|
807
|
-
startAngle,
|
|
808
|
-
endAngle,
|
|
809
|
-
cornerRadius,
|
|
810
|
-
margin,
|
|
811
|
-
enableSlicesLabels,
|
|
812
|
-
formatSliceLabel,
|
|
813
|
-
slicesLabelsSkipAngle,
|
|
814
|
-
enableSlicesLabelsName,
|
|
815
|
-
formatSliceLabelName,
|
|
816
|
-
borderWidth,
|
|
817
|
-
borderColor,
|
|
818
|
-
enableRadialLabels,
|
|
819
|
-
backgroundColor,
|
|
820
|
-
radialLabelsLinkHorizontalLength,
|
|
821
|
-
radialLabelsTextXOffset,
|
|
822
|
-
formatRadialLabel,
|
|
823
|
-
radialLabelYOffset,
|
|
824
|
-
svgElements,
|
|
825
|
-
formatSliceTitle,
|
|
826
|
-
radialAngleXOffset,
|
|
827
|
-
withTooltip,
|
|
828
|
-
fullChartTooltip,
|
|
829
|
-
tooltipClassName,
|
|
830
|
-
tooltipBind,
|
|
831
|
-
renderTooltip,
|
|
832
|
-
tooltipStyle
|
|
833
|
-
} = props;
|
|
834
|
-
if (node !== null && data.length) {
|
|
835
|
-
const marginTop = margin ? margin.top : 0;
|
|
836
|
-
const marginRight = margin ? margin.right : 0;
|
|
837
|
-
const marginBottom = margin ? margin.bottom : 0;
|
|
838
|
-
const marginLeft = margin ? margin.left : 0;
|
|
839
|
-
const {
|
|
840
|
-
width: nodeWidth
|
|
841
|
-
} = node.getBoundingClientRect();
|
|
842
|
-
const width = props.width || nodeWidth;
|
|
843
|
-
const defaultHeight = 240;
|
|
844
|
-
const height = props.height || defaultHeight;
|
|
845
|
-
const radius = (Math.min(width, height) - (borderWidth || 0) * 2 - (width > height ? marginTop + marginBottom : marginRight + marginLeft)) / 2;
|
|
846
|
-
const svg = appendSvg(node, width, height);
|
|
847
|
-
const global = svg.append('g').attr('class', pieChartclassNames.pieGlobal).attr('transform', "translate(" + ((width - (marginLeft + marginRight)) / 2 + marginLeft) + "," + ((height - (marginBottom + marginTop)) / 2 + marginTop) + ")");
|
|
848
|
-
const maxPadAngle = 45;
|
|
849
|
-
const dividerPadAngle = 100;
|
|
850
|
-
const fullAngle = 360;
|
|
851
|
-
const pie = d3.pie().startAngle(-degreesToRadians(startAngle || 0)).endAngle(degreesToRadians(endAngle || fullAngle)).padAngle(padAngle ? Math.max(Math.min(padAngle / dividerPadAngle, maxPadAngle), 0) : 0).sort(null)
|
|
852
|
-
// @ts-ignore
|
|
853
|
-
.value(_ref => {
|
|
854
|
-
let {
|
|
855
|
-
value
|
|
856
|
-
} = _ref;
|
|
857
|
-
return value;
|
|
858
|
-
});
|
|
859
|
-
// @ts-ignore
|
|
860
|
-
const dataReady = pie(data);
|
|
861
|
-
const maxOuterRadius = 0.95;
|
|
862
|
-
const arc = d3.arc().cornerRadius(cornerRadius || 0).innerRadius(radius).outerRadius(radius * Math.min(Math.max(outerRadius || 0, 0), maxOuterRadius));
|
|
863
|
-
if (typeof backgroundColor === 'string') {
|
|
864
|
-
global.append('path').attr('fill', backgroundColor).attr('d', () =>
|
|
865
|
-
// @ts-ignore
|
|
866
|
-
arc({
|
|
867
|
-
startAngle: degreesToRadians(0),
|
|
868
|
-
endAngle: degreesToRadians(fullAngle)
|
|
869
|
-
}));
|
|
870
|
-
}
|
|
871
|
-
const format = d3.format(',');
|
|
872
|
-
const allSlices = global.selectAll('allSlices').data(dataReady).enter().append('path')
|
|
873
|
-
// @ts-ignore
|
|
874
|
-
.attr('d', arc);
|
|
875
|
-
allSlices.attr('class', pieChartclassNames.pieSlice).attr('fill', _ref2 => {
|
|
876
|
-
let {
|
|
877
|
-
index
|
|
878
|
-
} = _ref2;
|
|
879
|
-
return data[index].color || '';
|
|
880
|
-
}).attr('stroke', borderColor || '').attr('stroke-width', borderWidth || 0).attr('style', onClick ? 'cursor: pointer' : '').on('click',
|
|
881
|
-
// @ts-ignore
|
|
882
|
-
(_, d) => onClick && onClick(data[d.index])).append('svg:title').text(d => formatSliceTitle ?
|
|
883
|
-
// @ts-ignore
|
|
884
|
-
formatSliceTitle(d) : fullChartTooltip || withTooltip ? '' : (data[d.index].name || '') + " (" + format(data[d.index].value) + ")");
|
|
885
|
-
if (enableSlicesLabels) {
|
|
886
|
-
const text = global.selectAll('allSlices').data(dataReady).enter().append('text').attr('class', pieChartclassNames.pieSliceLabel).attr('text-anchor', 'middle').attr('dominant-baseline', 'central').attr('transform',
|
|
887
|
-
// @ts-ignore
|
|
888
|
-
d => 'translate(' + arc.centroid(d) + ')');
|
|
889
|
-
text.append('tspan').attr('class', pieChartclassNames.pieSliceLabelValue)
|
|
890
|
-
// @ts-ignore
|
|
891
|
-
.text(d => {
|
|
892
|
-
const deg = radiansToDegrees(d.endAngle - d.startAngle);
|
|
893
|
-
if (!slicesLabelsSkipAngle || deg > slicesLabelsSkipAngle) {
|
|
894
|
-
return formatSliceLabel ? formatSliceLabel(d) : d.value;
|
|
895
|
-
}
|
|
896
|
-
});
|
|
897
|
-
if (enableSlicesLabelsName) {
|
|
898
|
-
text.append('tspan').attr('class', pieChartclassNames.pieSliceLabelName)
|
|
899
|
-
// @ts-ignore
|
|
900
|
-
.text(d => formatSliceLabelName ? formatSliceLabelName(d) : d.data.name).attr('x', '0').attr('dy', '1.2em');
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
drawRadialLabels$1({
|
|
904
|
-
arc,
|
|
905
|
-
enableRadialLabels,
|
|
906
|
-
global,
|
|
907
|
-
radius,
|
|
908
|
-
node,
|
|
909
|
-
dataReady,
|
|
910
|
-
translateX: (width - (marginLeft - marginRight)) / 2,
|
|
911
|
-
translateY: (height + (marginTop - marginBottom)) / 2,
|
|
912
|
-
radialLabelsLinkHorizontalLength,
|
|
913
|
-
radialLabelsTextXOffset,
|
|
914
|
-
formatRadialLabel,
|
|
915
|
-
radialLabelYOffset,
|
|
916
|
-
radialAngleXOffset
|
|
917
|
-
});
|
|
918
|
-
if (withTooltip || fullChartTooltip) {
|
|
919
|
-
drawTooltip({
|
|
920
|
-
fullChartTooltip,
|
|
921
|
-
global,
|
|
922
|
-
data,
|
|
923
|
-
tooltipClassName,
|
|
924
|
-
tooltipBind,
|
|
925
|
-
renderTooltip,
|
|
926
|
-
allSlices,
|
|
927
|
-
arc,
|
|
928
|
-
tooltipStyle,
|
|
929
|
-
width,
|
|
930
|
-
height,
|
|
931
|
-
radius
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
if (svgElements) {
|
|
935
|
-
const html = ReactDOMServer.renderToString(svgElements);
|
|
936
|
-
svg.append('g').html(html);
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
|
|
941
|
-
const PieChart = props => {
|
|
942
|
-
const {
|
|
943
|
-
className,
|
|
944
|
-
style,
|
|
945
|
-
children
|
|
946
|
-
} = props;
|
|
947
|
-
const [ref, node] = useNode();
|
|
948
|
-
React.useEffect(() => {
|
|
949
|
-
node && draw$1(node, props);
|
|
950
|
-
}, [node, props]);
|
|
951
|
-
const onDraw = () => draw$1(node, props);
|
|
952
|
-
useResize(props.width, onDraw);
|
|
953
|
-
return React__default.createElement("div", {
|
|
954
|
-
className: className,
|
|
955
|
-
style: style
|
|
956
|
-
}, React__default.createElement(SvgWrapper$1, {
|
|
957
|
-
ref: ref
|
|
958
|
-
}, children));
|
|
959
|
-
};
|
|
960
|
-
PieChart.defaultProps = {
|
|
961
|
-
data: [],
|
|
962
|
-
startAngle: 0,
|
|
963
|
-
endAngle: 360,
|
|
964
|
-
slicesLabelsSkipAngle: 0,
|
|
965
|
-
radialLabelYOffset: 16,
|
|
966
|
-
radialAngleXOffset: 8
|
|
967
|
-
};
|
|
968
|
-
|
|
969
|
-
const defaultN = 256;
|
|
970
|
-
const legendClassNames = {
|
|
971
|
-
legendContainer: 'd3-legend-container',
|
|
972
|
-
legendTitle: 'd3-legend-title',
|
|
973
|
-
legendTick: 'd3-legend-tick',
|
|
974
|
-
legendTickLine: 'd3-legend-tick-line',
|
|
975
|
-
legendTickText: 'd3-legend-tick-text'
|
|
976
|
-
};
|
|
977
|
-
function ramp(color, n) {
|
|
978
|
-
if (n === void 0) {
|
|
979
|
-
n = defaultN;
|
|
980
|
-
}
|
|
981
|
-
const canvas = document.createElement('canvas');
|
|
982
|
-
canvas.width = n;
|
|
983
|
-
canvas.height = 1;
|
|
984
|
-
const context = canvas.getContext('2d');
|
|
985
|
-
for (let i = 0; i < n; ++i) {
|
|
986
|
-
context.fillStyle = color(i / (n - 1));
|
|
987
|
-
context.fillRect(i, 0, 1, 1);
|
|
988
|
-
}
|
|
989
|
-
return canvas;
|
|
990
|
-
}
|
|
991
|
-
const legendDefaultParams = {
|
|
992
|
-
tickSize: 6,
|
|
993
|
-
height: 44,
|
|
994
|
-
width: 320,
|
|
995
|
-
marginTop: 18,
|
|
996
|
-
marginBottom: 16,
|
|
997
|
-
ticksDivier: 64,
|
|
998
|
-
titleMarginBottom: 6
|
|
999
|
-
};
|
|
1000
|
-
const getLegend = _ref => {
|
|
1001
|
-
let {
|
|
1002
|
-
color,
|
|
1003
|
-
title,
|
|
1004
|
-
tickSize = legendDefaultParams.tickSize,
|
|
1005
|
-
width = legendDefaultParams.width,
|
|
1006
|
-
height = legendDefaultParams.height + tickSize,
|
|
1007
|
-
marginTop = legendDefaultParams.marginTop,
|
|
1008
|
-
marginRight = 0,
|
|
1009
|
-
marginBottom = legendDefaultParams.marginBottom + tickSize,
|
|
1010
|
-
marginLeft = 0,
|
|
1011
|
-
ticks = legendDefaultParams.width / legendDefaultParams.ticksDivier,
|
|
1012
|
-
tickFormat,
|
|
1013
|
-
tickValues,
|
|
1014
|
-
titleMarginBottom
|
|
1015
|
-
} = _ref;
|
|
1016
|
-
const svg = d3.create('svg').attr('width', width).attr('height', height)
|
|
1017
|
-
// @ts-ignore
|
|
1018
|
-
.attr('viewBox', [0, 0, width, height]).style('overflow', 'visible').style('display', 'block');
|
|
1019
|
-
let tickAdjust = g => {
|
|
1020
|
-
const tick = g.selectAll('.tick');
|
|
1021
|
-
tick.selectAll('.tick line').attr('y1', marginTop + marginBottom - height).attr('class', legendClassNames.legendTickLine);
|
|
1022
|
-
tick.selectAll('.tick text').attr('class', legendClassNames.legendTickText);
|
|
1023
|
-
tick.attr('class', legendClassNames.legendTick);
|
|
1024
|
-
return tick;
|
|
1025
|
-
};
|
|
1026
|
-
let x;
|
|
1027
|
-
// Continuous
|
|
1028
|
-
if (color.interpolate) {
|
|
1029
|
-
const n = Math.min(color.domain().length, color.range().length);
|
|
1030
|
-
x = color.copy().rangeRound(d3.quantize(d3.interpolate(marginLeft, width - marginRight), n));
|
|
1031
|
-
svg.append('image').attr('x', marginLeft).attr('y', marginTop).attr('class', legendClassNames.legendContainer).attr('width', width - marginLeft - marginRight).attr('height', height - marginTop - marginBottom).attr('preserveAspectRatio', 'none').attr('xlink:href', ramp(color.copy().domain(d3.quantize(d3.interpolate(0, 1), n))).toDataURL());
|
|
1032
|
-
}
|
|
1033
|
-
// Sequential
|
|
1034
|
-
else if (color.interpolator) {
|
|
1035
|
-
x = Object.assign(color.copy().interpolator(d3.interpolateRound(marginLeft, width - marginRight)), {
|
|
1036
|
-
range() {
|
|
1037
|
-
return [marginLeft, width - marginRight];
|
|
1038
|
-
}
|
|
1039
|
-
});
|
|
1040
|
-
svg.append('image').attr('x', marginLeft).attr('y', marginTop).attr('width', width - marginLeft - marginRight).attr('height', height - marginTop - marginBottom).attr('preserveAspectRatio', 'none').attr('xlink:href', ramp(color.interpolator()).toDataURL());
|
|
1041
|
-
// scaleSequentialQuantile doesn’t implement ticks or tickFormat.
|
|
1042
|
-
if (!x.ticks) {
|
|
1043
|
-
if (tickValues === undefined) {
|
|
1044
|
-
const n = Math.round(ticks + 1);
|
|
1045
|
-
tickValues = d3.range(n).map(i => d3.quantile(color.domain(), i / (n - 1)));
|
|
1046
|
-
}
|
|
1047
|
-
if (typeof tickFormat !== 'function') {
|
|
1048
|
-
tickFormat = d3.format(tickFormat === undefined ? ',f' : tickFormat);
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
svg.append('g').attr('transform', "translate(0," + (height - marginBottom) + ")")
|
|
1053
|
-
// @ts-ignore
|
|
1054
|
-
.call(d3.axisBottom(x).ticks(ticks, typeof tickFormat === 'string' ? tickFormat : undefined)
|
|
1055
|
-
// @ts-ignore
|
|
1056
|
-
.tickFormat(typeof tickFormat === 'function' ? tickFormat : undefined).tickSize(tickSize)
|
|
1057
|
-
// @ts-ignore
|
|
1058
|
-
.tickValues(tickValues)).call(tickAdjust).call(g => g.select('.domain').remove()).call(g => g.append('text').attr('x', marginLeft).attr('class', legendClassNames.legendTitle).attr('y', marginTop + marginBottom - height - (titleMarginBottom || legendDefaultParams.titleMarginBottom)).attr('fill', 'currentColor').attr('text-anchor', 'start').attr('font-weight', 'bold').text(title));
|
|
1059
|
-
return svg;
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
var _templateObject$7;
|
|
1063
|
-
const calendarChartClassNames = /*#__PURE__*/_extends({
|
|
1064
|
-
calendarChart: "calendarChart",
|
|
1065
|
-
calendarYear: "calendarYear",
|
|
1066
|
-
calendarAxis: "calendarAxis",
|
|
1067
|
-
calendarBody: "calendarBody",
|
|
1068
|
-
calendarHeader: "calendarHeader",
|
|
1069
|
-
calendarYearTitle: "calendarYearTitle",
|
|
1070
|
-
calendarWeekDay: "calendarWeekDay",
|
|
1071
|
-
calendarMonth: "calendarMonth",
|
|
1072
|
-
calendarDays: "calendarDays",
|
|
1073
|
-
calendarDay: "calendarDay"
|
|
1074
|
-
}, legendClassNames);
|
|
1075
|
-
const headerHeight = "20px";
|
|
1076
|
-
const SvgWrapper$2 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$7 || (_templateObject$7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n display: flex;\n margin-bottom: 16px;\n }\n\n .", " {\n display: inline-flex;\n align-items: flex-end;\n height: ", ";\n margin-bottom: 4px;\n font-weight: bold;\n }\n\n .", " {\n height: ", ";\n margin-bottom: 4px;\n position: relative;\n display: flex;\n }\n\n .", " {\n font-size: 14px;\n bottom: 0;\n position: absolute;\n }\n\n .", " {\n display: flex;\n flex-direction: column;\n margin-right: 10px;\n }\n\n .", " {\n font-size: 12px;\n display: inline-flex;\n align-items: center;\n justify-content: flex-end;\n }\n\n .", " {\n position: relative;\n }\n\n .", " {\n position: absolute;\n }\n"])), calendarChartClassNames.calendarYear, calendarChartClassNames.calendarYearTitle, headerHeight, calendarChartClassNames.calendarHeader, headerHeight, calendarChartClassNames.calendarMonth, calendarChartClassNames.calendarAxis, calendarChartClassNames.calendarWeekDay, calendarChartClassNames.calendarDays, calendarChartClassNames.calendarDay);
|
|
1077
|
-
|
|
1078
|
-
const draw$2 = (node, props) => {
|
|
1079
|
-
const {
|
|
1080
|
-
data,
|
|
1081
|
-
startSunday,
|
|
1082
|
-
weekdays,
|
|
1083
|
-
interpolator,
|
|
1084
|
-
monthSpacing,
|
|
1085
|
-
onEachDay,
|
|
1086
|
-
colorRange,
|
|
1087
|
-
legendProps
|
|
1088
|
-
} = props;
|
|
1089
|
-
if (node !== null && data.length) {
|
|
1090
|
-
const years = d3.group(data, d => d.date.getUTCFullYear());
|
|
1091
|
-
const cellOffset = typeof props.cellOffset === 'number' ? props.cellOffset : 0;
|
|
1092
|
-
const weekDays = 7;
|
|
1093
|
-
const defaultCellSize = 18;
|
|
1094
|
-
const cellSize = props.cellSize || defaultCellSize;
|
|
1095
|
-
const countDay = i => startSunday ? i : (i + (weekDays - 1)) % weekDays;
|
|
1096
|
-
const days = weekdays || ['вс', 'пн', 'вт', 'ср', 'чт', 'пт', 'сб'];
|
|
1097
|
-
const sundayIndex = 6;
|
|
1098
|
-
const formatDay = i => startSunday ? days[i] : i === sundayIndex ? days[0] : days[i + 1];
|
|
1099
|
-
const formatDate = d3.utcFormat('%x');
|
|
1100
|
-
const timeWeek = startSunday ? d3.utcSunday : d3.utcMonday;
|
|
1101
|
-
const getTimeWeekCount = (from, to) => timeWeek.count(d3.utcYear(from), to);
|
|
1102
|
-
const getMonthSpacing = date => date.getUTCMonth() * (monthSpacing || 0);
|
|
1103
|
-
const formatMonth = d3.utcFormat('%b');
|
|
1104
|
-
const max = d3.max(data.map(_ref => {
|
|
1105
|
-
let {
|
|
1106
|
-
value
|
|
1107
|
-
} = _ref;
|
|
1108
|
-
return value;
|
|
1109
|
-
}));
|
|
1110
|
-
const min = d3.min(data.map(_ref2 => {
|
|
1111
|
-
let {
|
|
1112
|
-
value
|
|
1113
|
-
} = _ref2;
|
|
1114
|
-
return value;
|
|
1115
|
-
}));
|
|
1116
|
-
const color = colorRange ? d3.scaleLinear().domain([min, max])
|
|
1117
|
-
// @ts-ignore
|
|
1118
|
-
.range(colorRange) : d3.scaleSequential(interpolator || d3.interpolateGreens).domain([min, +max]);
|
|
1119
|
-
let chartWidth = 0;
|
|
1120
|
-
years.forEach((values, year) => {
|
|
1121
|
-
const min = new Date(year, 1);
|
|
1122
|
-
const max = d3.max(values.map(d => d.date));
|
|
1123
|
-
const months = max.getUTCMonth() - min.getUTCMonth();
|
|
1124
|
-
const weekCount = getTimeWeekCount(min, max) + 1;
|
|
1125
|
-
const width = weekCount * (cellSize + cellOffset) + (monthSpacing || 0) * months;
|
|
1126
|
-
chartWidth = Math.max(chartWidth, width);
|
|
1127
|
-
});
|
|
1128
|
-
d3.select(node).select("." + calendarChartClassNames.calendarChart).remove();
|
|
1129
|
-
const container = d3.select(node).append('div').attr('class', calendarChartClassNames.calendarChart);
|
|
1130
|
-
const year = container.selectAll('div')
|
|
1131
|
-
// @ts-ignore
|
|
1132
|
-
.data(years).join('div').attr('class', calendarChartClassNames.calendarYear);
|
|
1133
|
-
const calendarWeekdays = year.append('div').attr('class', calendarChartClassNames.calendarAxis);
|
|
1134
|
-
calendarWeekdays.append('div').attr('class', calendarChartClassNames.calendarYearTitle)
|
|
1135
|
-
// @ts-ignore
|
|
1136
|
-
.text(_ref3 => {
|
|
1137
|
-
let [key] = _ref3;
|
|
1138
|
-
return key;
|
|
1139
|
-
});
|
|
1140
|
-
calendarWeekdays.selectAll('span').data(d3.range(weekDays)).join('div').attr('class', calendarChartClassNames.calendarWeekDay).style('height', cellSize + 'px').style('margin-bottom', cellOffset + 'px').text(formatDay);
|
|
1141
|
-
const body = year.append('div').attr('class', calendarChartClassNames.calendarBody);
|
|
1142
|
-
const header = body.append('div').attr('class', calendarChartClassNames.calendarHeader);
|
|
1143
|
-
header.selectAll('div')
|
|
1144
|
-
// @ts-ignore
|
|
1145
|
-
.data(_ref4 => {
|
|
1146
|
-
let [_, values] = _ref4;
|
|
1147
|
-
const fullYearlastMonth = 12;
|
|
1148
|
-
const fullYearlastDate = 31;
|
|
1149
|
-
return d3.utcMonths(d3.utcMonth(new Date(values[0].date.getUTCFullYear(), 1, 1)), d3.utcMonth(new Date(values[0].date.getUTCFullYear(), fullYearlastMonth, fullYearlastDate)));
|
|
1150
|
-
}).join('div').attr('class', calendarChartClassNames.calendarMonth).style('left', d => getTimeWeekCount(d, timeWeek.ceil(d)) * (cellSize + cellOffset) + getMonthSpacing(d) + 'px')
|
|
1151
|
-
// @ts-ignore
|
|
1152
|
-
.text(formatMonth);
|
|
1153
|
-
// @ts-ignore
|
|
1154
|
-
body.append('div').attr('class', calendarChartClassNames.calendarDays).style('height', (cellSize + cellOffset) * weekDays + 'px').style('width', chartWidth + 'px').selectAll('div')
|
|
1155
|
-
// @ts-ignore
|
|
1156
|
-
.data(_ref5 => {
|
|
1157
|
-
let [, values] = _ref5;
|
|
1158
|
-
return values;
|
|
1159
|
-
}).join('div')
|
|
1160
|
-
// @ts-ignore
|
|
1161
|
-
.each((data, index, elements) => {
|
|
1162
|
-
if (onEachDay) {
|
|
1163
|
-
const element = elements[index];
|
|
1164
|
-
const currColor = color(data.value);
|
|
1165
|
-
onEachDay(data, element, currColor);
|
|
1166
|
-
}
|
|
1167
|
-
}).attr('class', calendarChartClassNames.calendarDay).style('width', cellSize + 'px').style('height', cellSize + 'px')
|
|
1168
|
-
// @ts-ignore
|
|
1169
|
-
.style('left', d => getTimeWeekCount(d.date, d.date) * (cellSize + cellOffset) + getMonthSpacing(d.date) + 'px').style('top',
|
|
1170
|
-
// @ts-ignore
|
|
1171
|
-
d => countDay(d.date.getUTCDay()) * (cellSize + cellOffset) + 'px')
|
|
1172
|
-
// @ts-ignore
|
|
1173
|
-
.style('background-color', d => color(d.value))
|
|
1174
|
-
// @ts-ignore
|
|
1175
|
-
.attr('title', d => formatDate(d.date) + " - " + d.value);
|
|
1176
|
-
if (typeof legendProps === 'object') {
|
|
1177
|
-
const legend = getLegend(_extends({
|
|
1178
|
-
color: color
|
|
1179
|
-
}, legendProps));
|
|
1180
|
-
const containerNode = container.node();
|
|
1181
|
-
const legendSvg = legend.node();
|
|
1182
|
-
containerNode.appendChild(legendSvg);
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
};
|
|
1186
|
-
|
|
1187
|
-
const CalendarChart = props => {
|
|
1188
|
-
const {
|
|
1189
|
-
className,
|
|
1190
|
-
style,
|
|
1191
|
-
children,
|
|
1192
|
-
data,
|
|
1193
|
-
startSunday,
|
|
1194
|
-
weekdays,
|
|
1195
|
-
cellOffset,
|
|
1196
|
-
cellSize,
|
|
1197
|
-
interpolator,
|
|
1198
|
-
monthSpacing,
|
|
1199
|
-
colorRange,
|
|
1200
|
-
legendProps
|
|
1201
|
-
} = props;
|
|
1202
|
-
const [ref, node] = useNode();
|
|
1203
|
-
React.useEffect(() => {
|
|
1204
|
-
node && draw$2(node, props);
|
|
1205
|
-
// eslint-disable-next-line
|
|
1206
|
-
}, [node, data, startSunday, weekdays, cellOffset, cellSize, interpolator, monthSpacing, colorRange, legendProps]);
|
|
1207
|
-
return React__default.createElement(SvgWrapper$2, {
|
|
1208
|
-
ref: ref,
|
|
1209
|
-
className: className,
|
|
1210
|
-
style: style
|
|
1211
|
-
}, children);
|
|
1212
|
-
};
|
|
1213
|
-
CalendarChart.defaultProps = {
|
|
1214
|
-
data: []
|
|
1215
|
-
};
|
|
1216
|
-
|
|
1217
|
-
function computeDimensions(selection) {
|
|
1218
|
-
let dimensions;
|
|
1219
|
-
const node = selection.node();
|
|
1220
|
-
if (node instanceof SVGGraphicsElement) {
|
|
1221
|
-
// check if node is svg element
|
|
1222
|
-
dimensions = node.getBBox();
|
|
1223
|
-
} else {
|
|
1224
|
-
// else is html element
|
|
1225
|
-
dimensions = node.getBoundingClientRect();
|
|
1226
|
-
}
|
|
1227
|
-
return dimensions;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
function none() {
|
|
1231
|
-
return;
|
|
1232
|
-
}
|
|
1233
|
-
function isVoid(value) {
|
|
1234
|
-
return value === undefined || value === null || Number.isNaN(value);
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
const stackedData = data => {
|
|
1238
|
-
const stacks = {};
|
|
1239
|
-
return data.map((item, index) => {
|
|
1240
|
-
stacks[index] = {};
|
|
1241
|
-
if (index > 0) {
|
|
1242
|
-
return _extends({}, item, {
|
|
1243
|
-
values: item.values.map((value, valuesIndex) => {
|
|
1244
|
-
const prevValue = stacks[index - 1][valuesIndex];
|
|
1245
|
-
stacks[index][valuesIndex] = Number((typeof prevValue !== 'number' ? 0 : Math.abs(prevValue)) + (typeof value !== 'number' ? 0 : Math.abs(value)));
|
|
1246
|
-
return stacks[index][valuesIndex];
|
|
1247
|
-
})
|
|
1248
|
-
});
|
|
1249
|
-
} else {
|
|
1250
|
-
item.values.forEach((value, valuesIndex) => {
|
|
1251
|
-
stacks[index][valuesIndex] = Number(value);
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
return item;
|
|
1255
|
-
});
|
|
1256
|
-
};
|
|
1257
|
-
|
|
1258
|
-
var _templateObject$8, _templateObject2$2;
|
|
1259
|
-
const lineChartClassNames = {
|
|
1260
|
-
lineChartYScaleGlobal: "lineChartYScaleGlobal",
|
|
1261
|
-
lineChartYScaleRight: "lineChartYScaleRight",
|
|
1262
|
-
lineChartXScaleGlobal: "lineChartXScaleGlobal",
|
|
1263
|
-
lineChartLinesGlobal: "lineChartLinesGlobal",
|
|
1264
|
-
lineChartLine: "lineChartLine",
|
|
1265
|
-
lineChartAreasGlobal: "lineChartAreasGlobal",
|
|
1266
|
-
lineChartArea: "lineChartArea",
|
|
1267
|
-
lineChartDotsGlobalContainer: "lineChartDotsGlobalContainer",
|
|
1268
|
-
lineChartDotsGlobal: "lineChartDotsGlobal",
|
|
1269
|
-
lineChartDot: "lineChartDot",
|
|
1270
|
-
lineChartGridGlobal: "lineChartGridGlobal",
|
|
1271
|
-
lineChartGridLineX: "lineChartGridLineX",
|
|
1272
|
-
lineChartGridLineY: "lineChartGridLineY",
|
|
1273
|
-
lineChartLabelContainer: "lineChartLabelContainer",
|
|
1274
|
-
lineChartLabelFlex: "lineChartLabelFlex",
|
|
1275
|
-
lineChartLabel: "lineChartLabel",
|
|
1276
|
-
lineChartMouseGlobal: "lineChartMouseGlobal",
|
|
1277
|
-
lineChartMouseLine: "lineChartMouseLine",
|
|
1278
|
-
lineChartMouseRect: "lineChartMouseRect",
|
|
1279
|
-
lineChartMouseCircle: "lineChartMouseCircle",
|
|
1280
|
-
lineChartMouseLabelContainer: "lineChartMouseLabelContainer",
|
|
1281
|
-
lineChartMouseLabel: "lineChartMouseLabel"
|
|
1282
|
-
};
|
|
1283
|
-
const SvgWrapper$3 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$8 || (_templateObject$8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", ",\n .", ",\n .", " {\n shape-rendering: crispEdges;\n }\n\n .", " {\n fill: none;\n stroke: steelblue;\n stroke-width: 1.5px;\n stroke-linejoin: round;\n stroke-linecap: round;\n }\n\n .", " {\n fill-opacity: 0.24;\n }\n\n .", ",\n .", ",\n .", " {\n stroke: rgba(149, 149, 149, 0.24);\n }\n\n .", ",\n .", " {\n transition: opacity linear 200ms;\n pointer-events: none;\n stroke-width: 1px;\n }\n\n .", " {\n stroke: #fff;\n stroke-width: 2px;\n }\n\n .", " {\n shape-rendering: crispEdges;\n }\n\n .", " {\n fill: none;\n pointer-events: all;\n }\n"])), lineChartClassNames.lineChartYScaleGlobal, lineChartClassNames.lineChartXScaleGlobal, lineChartClassNames.lineChartGridGlobal, lineChartClassNames.lineChartLinesGlobal, lineChartClassNames.lineChartArea, lineChartClassNames.lineChartGridLineX, lineChartClassNames.lineChartGridLineY, lineChartClassNames.lineChartMouseLine, lineChartClassNames.lineChartMouseLine, lineChartClassNames.lineChartMouseCircle, lineChartClassNames.lineChartDot, lineChartClassNames.lineChartMouseLine, lineChartClassNames.lineChartMouseRect);
|
|
1284
|
-
const TooltipStyles = /*#__PURE__*/styled.createGlobalStyle(_templateObject2$2 || (_templateObject2$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n transition: opacity linear 200ms;\n z-index: 100;\n\n .", " {\n justify-content: flex-start;\n align-items: center;\n pointer-events: none;\n }\n\n .", " {\n margin: 0 0 0 10px;\n }\n }\n"])), lineChartClassNames.lineChartMouseLabel, lineChartClassNames.lineChartLabelFlex, lineChartClassNames.lineChartLabel);
|
|
1285
|
-
|
|
1286
|
-
const drawGrid = _ref => {
|
|
1287
|
-
let {
|
|
1288
|
-
svg,
|
|
1289
|
-
yScale,
|
|
1290
|
-
xScale,
|
|
1291
|
-
yTicksCount,
|
|
1292
|
-
lastIndex,
|
|
1293
|
-
drawGridX,
|
|
1294
|
-
drawGridY
|
|
1295
|
-
} = _ref;
|
|
1296
|
-
if (!drawGridY && !drawGridX) return;
|
|
1297
|
-
const global = svg.append('g').attr('class', lineChartClassNames.lineChartGridGlobal);
|
|
1298
|
-
const yTicks = yScale.ticks(yTicksCount);
|
|
1299
|
-
if (drawGridX) {
|
|
1300
|
-
global.append('g').selectAll('line').data(yTicks).join('line').attr('class', lineChartClassNames.lineChartGridLineX).attr('x1', () => xScale(0)).attr('x2', () => xScale(lastIndex)).attr('y1', d => Math.round(yScale(d))).attr('y2', d => Math.round(yScale(d)));
|
|
1301
|
-
}
|
|
1302
|
-
if (drawGridY) {
|
|
1303
|
-
global.append('g').selectAll('line').data(Array.from({
|
|
1304
|
-
length: lastIndex + 1
|
|
1305
|
-
}, (_, index) => index)).join('line').attr('class', lineChartClassNames.lineChartGridLineY).attr('x1', (_, index) => Math.round(xScale(index))).attr('x2', (_, index) => Math.round(xScale(index))).attr('y1', () => Math.round(yScale(yTicks[0]))).attr('y2', () => Math.round(yScale(yTicks[yTicks.length - 1])));
|
|
1306
|
-
}
|
|
1307
|
-
};
|
|
1308
|
-
|
|
1309
|
-
var _templateObject$9, _templateObject2$3;
|
|
1310
|
-
const LabelContainer$1 = /*#__PURE__*/styled__default.div(_templateObject$9 || (_templateObject$9 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 0;\n height: 0;\n display: flex;\n align-items: flex-end;\n justify-content: center;\n font-size: 12px;\n white-space: nowrap;\n"])));
|
|
1311
|
-
const Label$2 = /*#__PURE__*/styled__default.div(_templateObject2$3 || (_templateObject2$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-bottom: 4px;\n"])));
|
|
1312
|
-
|
|
1313
|
-
const labelClassName$1 = 'd3-chart-label';
|
|
1314
|
-
const drawLabel = _ref => {
|
|
1315
|
-
let {
|
|
1316
|
-
node,
|
|
1317
|
-
data,
|
|
1318
|
-
yScale,
|
|
1319
|
-
xScale,
|
|
1320
|
-
formatLabel,
|
|
1321
|
-
eachLabel
|
|
1322
|
-
} = _ref;
|
|
1323
|
-
const labelsDiv = d3.select(node).append('div').attr('class', labelClassName$1);
|
|
1324
|
-
const format = d3.format(',');
|
|
1325
|
-
// @ts-ignore
|
|
1326
|
-
data.forEach(_ref2 => {
|
|
1327
|
-
let {
|
|
1328
|
-
values
|
|
1329
|
-
} = _ref2;
|
|
1330
|
-
labelsDiv.append('div').selectAll('div').data(values).join('div').attr('class', lineChartClassNames.lineChartLabelContainer).style('position', 'absolute').style('left', (_, index) => xScale(index) + 'px').style('top', d => yScale(d) + 'px').html((d, index, elements) => {
|
|
1331
|
-
const html = ReactDOMServer.renderToString(React__default.createElement(LabelContainer$1, {
|
|
1332
|
-
className: lineChartClassNames.lineChartLabelFlex
|
|
1333
|
-
}, React__default.createElement(Label$2, {
|
|
1334
|
-
className: lineChartClassNames.lineChartLabel
|
|
1335
|
-
}, formatLabel ? formatLabel(d, index, elements) : format(d))));
|
|
1336
|
-
return html;
|
|
1337
|
-
})
|
|
1338
|
-
// @ts-ignore
|
|
1339
|
-
.each(eachLabel ? eachLabel : none);
|
|
1340
|
-
});
|
|
1341
|
-
};
|
|
1342
|
-
|
|
1343
|
-
const _excluded$1 = ["values"];
|
|
1344
|
-
const drawTooltip$1 = _ref => {
|
|
1345
|
-
let {
|
|
1346
|
-
svg,
|
|
1347
|
-
node,
|
|
1348
|
-
data: argData,
|
|
1349
|
-
xScale,
|
|
1350
|
-
yScale,
|
|
1351
|
-
dynamicCircleRadius,
|
|
1352
|
-
formatDynamicTooltip,
|
|
1353
|
-
renderTooltip,
|
|
1354
|
-
stackedTooltipIndex,
|
|
1355
|
-
stackedTooltip,
|
|
1356
|
-
tooltipLineTop,
|
|
1357
|
-
tooltipRoot,
|
|
1358
|
-
tooltipClassName,
|
|
1359
|
-
dotSnapping,
|
|
1360
|
-
lastIndex
|
|
1361
|
-
} = _ref;
|
|
1362
|
-
const container = tooltipRoot || document.querySelector('body');
|
|
1363
|
-
const format = d3.format(',');
|
|
1364
|
-
const chartData = argData.filter(_ref2 => {
|
|
1365
|
-
let {
|
|
1366
|
-
tooltipOff
|
|
1367
|
-
} = _ref2;
|
|
1368
|
-
return !tooltipOff;
|
|
1369
|
-
});
|
|
1370
|
-
const data = typeof stackedTooltipIndex === 'number' ? [chartData[stackedTooltipIndex]] : stackedTooltip ? [chartData[0]] : chartData;
|
|
1371
|
-
const [x1, x2] = xScale.range();
|
|
1372
|
-
const [y1, y2] = yScale.range();
|
|
1373
|
-
const mouseGlobal = svg.append('g').attr('class', lineChartClassNames.lineChartMouseGlobal);
|
|
1374
|
-
const mouseRect = mouseGlobal.append('rect').attr('width', x2 - x1).attr('height', Math.abs(y1 - y2)).attr('class', lineChartClassNames.lineChartMouseRect).attr('transform', "translate(" + x1 + ", " + y2 + ")");
|
|
1375
|
-
const mouseLine = mouseGlobal.append('path').attr('class', lineChartClassNames.lineChartMouseLine).style('opacity', '0');
|
|
1376
|
-
const lines = svg.selectAll("." + lineChartClassNames.lineChartLine).nodes();
|
|
1377
|
-
const circles = mouseGlobal.selectAll('circle').data(chartData.filter(_ref3 => {
|
|
1378
|
-
let {
|
|
1379
|
-
dynamicDotOff
|
|
1380
|
-
} = _ref3;
|
|
1381
|
-
return !dynamicDotOff;
|
|
1382
|
-
})).join('circle').attr('class', lineChartClassNames.lineChartMouseCircle).attr('r', dynamicCircleRadius).attr('fill', _ref4 => {
|
|
1383
|
-
let {
|
|
1384
|
-
stroke
|
|
1385
|
-
} = _ref4;
|
|
1386
|
-
return stroke || 'none';
|
|
1387
|
-
}).attr('stroke', _ref5 => {
|
|
1388
|
-
let {
|
|
1389
|
-
stroke
|
|
1390
|
-
} = _ref5;
|
|
1391
|
-
return stroke || 'none';
|
|
1392
|
-
}).style('opacity', '0');
|
|
1393
|
-
let labelContainer = d3.select("." + lineChartClassNames.lineChartMouseLabelContainer);
|
|
1394
|
-
if (labelContainer.size() === 0) {
|
|
1395
|
-
labelContainer = d3.select(container).append('div').attr('class', lineChartClassNames.lineChartMouseLabelContainer);
|
|
1396
|
-
}
|
|
1397
|
-
let labels = null;
|
|
1398
|
-
let isVisible = false;
|
|
1399
|
-
const setVisible = visible => {
|
|
1400
|
-
isVisible = Boolean(visible);
|
|
1401
|
-
const opacity = isVisible ? '1' : '0';
|
|
1402
|
-
mouseLine.style('opacity', opacity);
|
|
1403
|
-
circles.style('opacity', opacity);
|
|
1404
|
-
labels && labels.style('opacity', opacity);
|
|
1405
|
-
};
|
|
1406
|
-
const mouseMove = event => {
|
|
1407
|
-
const [docX, docY] = d3.pointer(event, document);
|
|
1408
|
-
const [rectrX] = d3.pointer(event, mouseRect);
|
|
1409
|
-
const [nodeX, nodeY] = d3.pointer(event, node);
|
|
1410
|
-
const x = rectrX - (rectrX - nodeX);
|
|
1411
|
-
const left = nodeX + (docX - nodeX);
|
|
1412
|
-
const currIndex = Math.abs(xScale.invert(x));
|
|
1413
|
-
const positions = {};
|
|
1414
|
-
const getValue = values => {
|
|
1415
|
-
// The returning result is fixed for the task: https://jr.everpoint.ru/browse/PUB-5648
|
|
1416
|
-
// Before the task it was like this (and I don't know why):
|
|
1417
|
-
/* return !isVoid(values[Math.floor(currIndex + 1)])
|
|
1418
|
-
? values[Math.floor(currIndex)]
|
|
1419
|
-
: null;*/
|
|
1420
|
-
return values[Math.floor(currIndex)];
|
|
1421
|
-
};
|
|
1422
|
-
lines.forEach((line, index) => {
|
|
1423
|
-
let pos = {
|
|
1424
|
-
x: 0,
|
|
1425
|
-
y: 0
|
|
1426
|
-
};
|
|
1427
|
-
if (!line.hasAttribute('d') || argData[index].tooltipOff) {
|
|
1428
|
-
positions[index] = pos;
|
|
1429
|
-
return;
|
|
1430
|
-
}
|
|
1431
|
-
if (!dotSnapping) {
|
|
1432
|
-
let beginning = 0;
|
|
1433
|
-
let end = line.getTotalLength();
|
|
1434
|
-
let target = null;
|
|
1435
|
-
while (true) {
|
|
1436
|
-
target = Math.floor((beginning + end) / 2);
|
|
1437
|
-
pos = line.getPointAtLength(target);
|
|
1438
|
-
if ((target === end || target === beginning) && pos.x !== x) {
|
|
1439
|
-
break;
|
|
1440
|
-
}
|
|
1441
|
-
if (pos.x > x) {
|
|
1442
|
-
end = target;
|
|
1443
|
-
} else if (pos.x < x) {
|
|
1444
|
-
beginning = target;
|
|
1445
|
-
} else {
|
|
1446
|
-
break;
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
positions[index] = pos;
|
|
1450
|
-
} else {
|
|
1451
|
-
const [x1, x2] = xScale.range();
|
|
1452
|
-
const chartWidth = x2 - x1;
|
|
1453
|
-
const step = chartWidth / lastIndex;
|
|
1454
|
-
positions[index] = {
|
|
1455
|
-
x: x1 + Math.round(currIndex) * step,
|
|
1456
|
-
y: typeof argData[index].values[Math.round(currIndex)] === "number" ? yScale(argData[index].values[Math.round(currIndex)]) : 0
|
|
1457
|
-
};
|
|
1458
|
-
}
|
|
1459
|
-
});
|
|
1460
|
-
circles.attr('transform', (lineChartData, index) => {
|
|
1461
|
-
const value = getValue(lineChartData.values);
|
|
1462
|
-
return positions[index] && value ? 'translate(' + (!dotSnapping ? x : positions[index].x) + ',' + positions[index].y + ')' : 'translate(-9999, -9999)';
|
|
1463
|
-
}).attr('style', _ref6 => {
|
|
1464
|
-
let {
|
|
1465
|
-
dynamicDotStyle
|
|
1466
|
-
} = _ref6;
|
|
1467
|
-
return dynamicDotStyle || '';
|
|
1468
|
-
});
|
|
1469
|
-
const datas = chartData.map((_ref7, i) => {
|
|
1470
|
-
let {
|
|
1471
|
-
values
|
|
1472
|
-
} = _ref7,
|
|
1473
|
-
rest = _objectWithoutPropertiesLoose(_ref7, _excluded$1);
|
|
1474
|
-
return _extends({}, rest, {
|
|
1475
|
-
value: getValue(values),
|
|
1476
|
-
invertValue: positions[i] ? yScale.invert(positions[i].y) : 0
|
|
1477
|
-
});
|
|
1478
|
-
});
|
|
1479
|
-
const noHasData = datas.every(_ref8 => {
|
|
1480
|
-
let {
|
|
1481
|
-
value
|
|
1482
|
-
} = _ref8;
|
|
1483
|
-
return isVoid(value);
|
|
1484
|
-
});
|
|
1485
|
-
if (noHasData && isVisible) {
|
|
1486
|
-
setVisible();
|
|
1487
|
-
} else if (!isVisible && !noHasData) {
|
|
1488
|
-
setVisible(true);
|
|
1489
|
-
}
|
|
1490
|
-
const topIndex = Object.keys(positions).reduce((acc, key, index) => {
|
|
1491
|
-
var _datas$Number, _datas$Number2;
|
|
1492
|
-
const prevValue = (_datas$Number = datas[Number(acc)]) == null ? void 0 : _datas$Number.value;
|
|
1493
|
-
const value = (_datas$Number2 = datas[Number(key)]) == null ? void 0 : _datas$Number2.value;
|
|
1494
|
-
const dynamicDotOff = argData == null ? void 0 : argData[index].dynamicDotOff;
|
|
1495
|
-
return index === 0 || isVoid(value) || dynamicDotOff ? acc : isVoid(prevValue) || positions[acc].y > positions[key].y ? key : acc;
|
|
1496
|
-
}, '0');
|
|
1497
|
-
const labelTexts = labels && labels.style('left', (_, i) => {
|
|
1498
|
-
var _positions$i$x, _positions$i;
|
|
1499
|
-
return !dotSnapping ? left + "px" : ((_positions$i$x = (_positions$i = positions[i]) == null ? void 0 : _positions$i.x) != null ? _positions$i$x : 0) + "px";
|
|
1500
|
-
}).style('top', (_, i) => {
|
|
1501
|
-
var _positions$index$y, _positions$index;
|
|
1502
|
-
const index = typeof stackedTooltipIndex === 'number' ? stackedTooltipIndex : stackedTooltip ? topIndex : i;
|
|
1503
|
-
return ((_positions$index$y = (_positions$index = positions[index]) == null ? void 0 : _positions$index.y) != null ? _positions$index$y : 0) + (docY - nodeY) + "px";
|
|
1504
|
-
}).select("." + lineChartClassNames.lineChartLabel);
|
|
1505
|
-
if (renderTooltip && labels) {
|
|
1506
|
-
labels.html((_, index) => {
|
|
1507
|
-
return ReactDOMServer.renderToString(React__default.createElement(LabelContainer$1, {
|
|
1508
|
-
className: lineChartClassNames.lineChartLabelFlex
|
|
1509
|
-
}, renderTooltip(datas, {
|
|
1510
|
-
indexX: Math.round(currIndex),
|
|
1511
|
-
indexY: index,
|
|
1512
|
-
svg,
|
|
1513
|
-
event
|
|
1514
|
-
})));
|
|
1515
|
-
});
|
|
1516
|
-
} else {
|
|
1517
|
-
labelTexts && labelTexts.text((_, i) => {
|
|
1518
|
-
const value = datas[i].value;
|
|
1519
|
-
const invertValue = datas[i].invertValue;
|
|
1520
|
-
return formatDynamicTooltip ? formatDynamicTooltip(invertValue, value) : format(invertValue);
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1523
|
-
mouseLine.attr('d', () => {
|
|
1524
|
-
var _positions$topIndex;
|
|
1525
|
-
let d = 'M' + x + ',' + y1;
|
|
1526
|
-
d += ' ' + x + ',' + (tooltipLineTop ? y2 : ((_positions$topIndex = positions[topIndex]) == null ? void 0 : _positions$topIndex.y) || 0);
|
|
1527
|
-
return d;
|
|
1528
|
-
});
|
|
1529
|
-
};
|
|
1530
|
-
mouseRect.on('mouseover.tooltip', event => {
|
|
1531
|
-
labels = labelContainer.selectAll('div').data(data).join('div').attr('class', lineChartClassNames.lineChartMouseLabel + " " + (tooltipClassName || '')).style('opacity', '0').style('position', 'absolute').html(() => {
|
|
1532
|
-
const html = ReactDOMServer.renderToString(React__default.createElement(LabelContainer$1, {
|
|
1533
|
-
className: lineChartClassNames.lineChartLabelFlex
|
|
1534
|
-
}, React__default.createElement(Label$2, {
|
|
1535
|
-
className: lineChartClassNames.lineChartLabel
|
|
1536
|
-
})));
|
|
1537
|
-
return html;
|
|
1538
|
-
});
|
|
1539
|
-
mouseMove(event);
|
|
1540
|
-
});
|
|
1541
|
-
mouseRect.on('mouseout.tooltip', () => {
|
|
1542
|
-
d3.select("." + lineChartClassNames.lineChartMouseLabelContainer).selectAll('*').remove();
|
|
1543
|
-
setVisible();
|
|
1544
|
-
});
|
|
1545
|
-
mouseRect.on('touchmove.tooltip mousemove.tooltip', mouseMove);
|
|
1546
|
-
};
|
|
1547
|
-
|
|
1548
|
-
const draw$3 = (node, props) => {
|
|
1549
|
-
const {
|
|
1550
|
-
data: chartData,
|
|
1551
|
-
labels,
|
|
1552
|
-
margin,
|
|
1553
|
-
customYAxisSelection,
|
|
1554
|
-
customXAxisSelection,
|
|
1555
|
-
customYAxis,
|
|
1556
|
-
customXAxis,
|
|
1557
|
-
curve,
|
|
1558
|
-
yAxisPadding,
|
|
1559
|
-
xAxisPadding,
|
|
1560
|
-
drawGridY,
|
|
1561
|
-
drawGridX,
|
|
1562
|
-
withLabels,
|
|
1563
|
-
formatLabel,
|
|
1564
|
-
eachLabel,
|
|
1565
|
-
stacked,
|
|
1566
|
-
dynamicTooltipEnable,
|
|
1567
|
-
dynamicCircleRadius,
|
|
1568
|
-
formatDynamicTooltip,
|
|
1569
|
-
renderTooltip,
|
|
1570
|
-
stackedTooltip,
|
|
1571
|
-
stackedTooltipIndex,
|
|
1572
|
-
tooltipLineTop,
|
|
1573
|
-
customize,
|
|
1574
|
-
customYScale,
|
|
1575
|
-
customLine,
|
|
1576
|
-
tooltipClassName,
|
|
1577
|
-
xScaleItemWidth,
|
|
1578
|
-
areaCurve,
|
|
1579
|
-
dotSnapping,
|
|
1580
|
-
rightAxis
|
|
1581
|
-
} = props;
|
|
1582
|
-
if (node !== null && chartData.length) {
|
|
1583
|
-
const data = stacked ? stackedData(chartData) : chartData;
|
|
1584
|
-
const marginTop = margin ? margin.top : 0;
|
|
1585
|
-
const marginRight = margin ? margin.right : 0;
|
|
1586
|
-
const marginBottom = margin ? margin.bottom : 0;
|
|
1587
|
-
const marginLeft = margin ? margin.left : 0;
|
|
1588
|
-
const {
|
|
1589
|
-
width: nodeWidth
|
|
1590
|
-
} = node.getBoundingClientRect();
|
|
1591
|
-
const width = props.width || nodeWidth;
|
|
1592
|
-
const height = props.height || 0;
|
|
1593
|
-
const min = typeof props.min === 'number' ? props.min : d3.min(data, _ref => {
|
|
1594
|
-
let {
|
|
1595
|
-
values
|
|
1596
|
-
} = _ref;
|
|
1597
|
-
return d3.min(values);
|
|
1598
|
-
});
|
|
1599
|
-
const max = typeof props.max === 'number' ? props.max : d3.max(data, _ref2 => {
|
|
1600
|
-
let {
|
|
1601
|
-
values
|
|
1602
|
-
} = _ref2;
|
|
1603
|
-
return d3.max(values);
|
|
1604
|
-
});
|
|
1605
|
-
const svg = appendSvg(node, width, height || 0);
|
|
1606
|
-
const yRange = [height - marginTop - marginBottom - (xAxisPadding || 0), marginTop];
|
|
1607
|
-
const yScale = d3.scaleLinear().domain([min || 0, max || 0]).range(yRange).nice();
|
|
1608
|
-
customYScale && customYScale(yScale);
|
|
1609
|
-
const yTicksCountDefault = 8;
|
|
1610
|
-
const yAxisLeft = d3.axisLeft(yScale).ticks(yTicksCountDefault);
|
|
1611
|
-
customYAxis && customYAxis(yAxisLeft);
|
|
1612
|
-
const yTicksCount = yAxisLeft.tickArguments()[0];
|
|
1613
|
-
const yAxis = svg.append('g').attr('class', lineChartClassNames.lineChartYScaleGlobal).call(yAxisLeft).call(customYAxisSelection ? customYAxisSelection : none);
|
|
1614
|
-
const {
|
|
1615
|
-
width: yAxisWidth
|
|
1616
|
-
} = computeDimensions(yAxis);
|
|
1617
|
-
yAxis.attr('transform', "translate(" + (marginLeft + yAxisWidth) + ", 0)");
|
|
1618
|
-
let yAxisRightWidth = 0;
|
|
1619
|
-
if (rightAxis) {
|
|
1620
|
-
const rightAxisMin = d3.min(rightAxis);
|
|
1621
|
-
const rightAxisMax = d3.max(rightAxis);
|
|
1622
|
-
const yRightScale = d3.scaleLinear().domain([rightAxisMin || 0, rightAxisMax || 0]).range(yRange).nice();
|
|
1623
|
-
const yAxisRightTicks = d3.axisRight(yRightScale).ticks(yTicksCountDefault);
|
|
1624
|
-
const yAxisRight = svg.append('g').attr('class', lineChartClassNames.lineChartYScaleGlobal + " " + lineChartClassNames.lineChartYScaleRight).call(yAxisRightTicks).call(customYAxisSelection ? customYAxisSelection : none);
|
|
1625
|
-
({
|
|
1626
|
-
width: yAxisRightWidth
|
|
1627
|
-
} = computeDimensions(yAxisRight));
|
|
1628
|
-
yAxisRight.attr('transform', "translate(" + (width - yAxisRightWidth) + ", 0)");
|
|
1629
|
-
}
|
|
1630
|
-
/** xScale **/
|
|
1631
|
-
const lastIndex = labels && labels.length ? labels.length - 1 : data.reduce((acc, _ref3) => {
|
|
1632
|
-
let {
|
|
1633
|
-
values
|
|
1634
|
-
} = _ref3;
|
|
1635
|
-
return Math.max(acc, values.length);
|
|
1636
|
-
}, 0) - 1;
|
|
1637
|
-
const xScale = d3.scaleLinear().domain([0, lastIndex]).range([marginLeft + yAxisWidth + (yAxisPadding || 0), width - yAxisRightWidth - marginRight]);
|
|
1638
|
-
const xAxisBottom = d3.axisBottom(xScale).tickFormat(value =>
|
|
1639
|
-
// @ts-ignore
|
|
1640
|
-
labels && labels.length > 0 ? labels[value] : 0).ticks(lastIndex);
|
|
1641
|
-
if (typeof xScaleItemWidth === 'number') {
|
|
1642
|
-
const [x1, x2] = xScale.range();
|
|
1643
|
-
const chartWidth = x2 - x1;
|
|
1644
|
-
xAxisBottom.ticks(Math.round(chartWidth / xScaleItemWidth)).tickSizeOuter(0);
|
|
1645
|
-
}
|
|
1646
|
-
customXAxis && customXAxis(xAxisBottom);
|
|
1647
|
-
drawGrid({
|
|
1648
|
-
svg,
|
|
1649
|
-
yScale,
|
|
1650
|
-
xScale,
|
|
1651
|
-
yTicksCount,
|
|
1652
|
-
lastIndex,
|
|
1653
|
-
drawGridY,
|
|
1654
|
-
drawGridX
|
|
1655
|
-
});
|
|
1656
|
-
if (Array.isArray(labels) && labels.length > 0) {
|
|
1657
|
-
const xAxis = svg.append('g').call(customXAxisSelection ? customXAxisSelection : none).attr('class', lineChartClassNames.lineChartXScaleGlobal).call(xAxisBottom);
|
|
1658
|
-
const {
|
|
1659
|
-
height: xAxisHeight
|
|
1660
|
-
} = computeDimensions(xAxis);
|
|
1661
|
-
xAxis.attr('transform', "translate(0, " + (height - Math.ceil(xAxisHeight) - marginBottom) + ")");
|
|
1662
|
-
}
|
|
1663
|
-
const line = d3.line().defined(d => d !== null).x((_, index) => xScale(index)).y(d => yScale(d)).curve(curve || d3.curveLinear);
|
|
1664
|
-
customLine && customLine(line);
|
|
1665
|
-
const withAreas = data.some(_ref4 => {
|
|
1666
|
-
let {
|
|
1667
|
-
fill
|
|
1668
|
-
} = _ref4;
|
|
1669
|
-
return fill;
|
|
1670
|
-
});
|
|
1671
|
-
if (withAreas) {
|
|
1672
|
-
let dataIndex = -2;
|
|
1673
|
-
const getArea = d => {
|
|
1674
|
-
const {
|
|
1675
|
-
minAreaValues
|
|
1676
|
-
} = d;
|
|
1677
|
-
const minTick = yScale.ticks()[0];
|
|
1678
|
-
return d3.area().defined(d => d !== null).x((_, index) => xScale(index)).y0((value, index) => {
|
|
1679
|
-
if (index === 0) {
|
|
1680
|
-
dataIndex = dataIndex + 1;
|
|
1681
|
-
}
|
|
1682
|
-
let minValue = minTick;
|
|
1683
|
-
if (minAreaValues && typeof minAreaValues[index] === 'number') {
|
|
1684
|
-
minValue = minAreaValues[index] || minValue;
|
|
1685
|
-
} else if (minAreaValues) {
|
|
1686
|
-
minValue = yScale(minValue - value);
|
|
1687
|
-
}
|
|
1688
|
-
const currData = data[dataIndex];
|
|
1689
|
-
return stacked ? dataIndex > -1 ? yScale(typeof currData.values[index] !== 'number' ? 0 : currData.values[index]) : yScale(minValue) : yScale(minValue);
|
|
1690
|
-
}).y1(d => yScale(d)).curve(areaCurve || curve || d3.curveLinear);
|
|
1691
|
-
};
|
|
1692
|
-
svg.append('g').attr('class', lineChartClassNames.lineChartAreasGlobal).selectAll('path').data(data.filter(_ref5 => {
|
|
1693
|
-
let {
|
|
1694
|
-
fill
|
|
1695
|
-
} = _ref5;
|
|
1696
|
-
return Boolean(fill);
|
|
1697
|
-
})).join('path').attr('class', lineChartClassNames.lineChartArea).attr('d', d => {
|
|
1698
|
-
const area = getArea(d);
|
|
1699
|
-
return area(d.values);
|
|
1700
|
-
}).attr('fill', _ref6 => {
|
|
1701
|
-
let {
|
|
1702
|
-
fill
|
|
1703
|
-
} = _ref6;
|
|
1704
|
-
return fill || 'none';
|
|
1705
|
-
}).attr('style', _ref7 => {
|
|
1706
|
-
let {
|
|
1707
|
-
areaStyle
|
|
1708
|
-
} = _ref7;
|
|
1709
|
-
return areaStyle || '';
|
|
1710
|
-
});
|
|
1711
|
-
}
|
|
1712
|
-
svg.append('g').attr('class', lineChartClassNames.lineChartLinesGlobal).selectAll('path').data(data).join('path').attr('class', lineChartClassNames.lineChartLine).attr('d', d => line(d.values)).attr('stroke', _ref8 => {
|
|
1713
|
-
let {
|
|
1714
|
-
stroke
|
|
1715
|
-
} = _ref8;
|
|
1716
|
-
return stroke || 'steelblue';
|
|
1717
|
-
}).attr('style', _ref9 => {
|
|
1718
|
-
let {
|
|
1719
|
-
style
|
|
1720
|
-
} = _ref9;
|
|
1721
|
-
return style || '';
|
|
1722
|
-
});
|
|
1723
|
-
const dots = data.filter(_ref0 => {
|
|
1724
|
-
let {
|
|
1725
|
-
dot
|
|
1726
|
-
} = _ref0;
|
|
1727
|
-
return dot;
|
|
1728
|
-
});
|
|
1729
|
-
if (dots.length > 0) {
|
|
1730
|
-
const dotsGlobal = svg.append('g').attr('class', lineChartClassNames.lineChartDotsGlobalContainer);
|
|
1731
|
-
dots.forEach(item => {
|
|
1732
|
-
const {
|
|
1733
|
-
values,
|
|
1734
|
-
dot
|
|
1735
|
-
} = item;
|
|
1736
|
-
const {
|
|
1737
|
-
radius,
|
|
1738
|
-
style,
|
|
1739
|
-
filter
|
|
1740
|
-
} = dot;
|
|
1741
|
-
const dotsGroup = dotsGlobal.append('g').attr('class', lineChartClassNames.lineChartDotsGlobal);
|
|
1742
|
-
dotsGroup.selectAll('circle').data(values).join('circle').attr('cx', (_, index) => xScale(index)).attr('class', lineChartClassNames.lineChartDot).attr('cy', d => yScale(d)).attr('r', radius || 0).attr('style', style || '');
|
|
1743
|
-
if (filter) {
|
|
1744
|
-
dotsGroup.selectAll('circle').select((_, i, g) => filter(item, i, g) ? g[i] : null).remove();
|
|
1745
|
-
}
|
|
1746
|
-
});
|
|
1747
|
-
}
|
|
1748
|
-
d3.select(node).select("." + labelClassName$1).remove();
|
|
1749
|
-
withLabels && drawLabel({
|
|
1750
|
-
node,
|
|
1751
|
-
eachLabel,
|
|
1752
|
-
data,
|
|
1753
|
-
yScale,
|
|
1754
|
-
xScale,
|
|
1755
|
-
formatLabel
|
|
1756
|
-
});
|
|
1757
|
-
if (dynamicTooltipEnable) {
|
|
1758
|
-
drawTooltip$1({
|
|
1759
|
-
tooltipLineTop,
|
|
1760
|
-
stackedTooltip,
|
|
1761
|
-
renderTooltip,
|
|
1762
|
-
stackedTooltipIndex,
|
|
1763
|
-
formatDynamicTooltip,
|
|
1764
|
-
node,
|
|
1765
|
-
svg,
|
|
1766
|
-
data,
|
|
1767
|
-
xScale,
|
|
1768
|
-
yScale,
|
|
1769
|
-
dynamicCircleRadius,
|
|
1770
|
-
tooltipClassName,
|
|
1771
|
-
dotSnapping,
|
|
1772
|
-
lastIndex
|
|
1773
|
-
});
|
|
1774
|
-
}
|
|
1775
|
-
customize && customize({
|
|
1776
|
-
svg,
|
|
1777
|
-
yScale,
|
|
1778
|
-
xScale
|
|
1779
|
-
});
|
|
1780
|
-
}
|
|
1781
|
-
};
|
|
1782
|
-
|
|
1783
|
-
const LineChart = props => {
|
|
1784
|
-
const {
|
|
1785
|
-
className,
|
|
1786
|
-
style,
|
|
1787
|
-
children
|
|
1788
|
-
} = props;
|
|
1789
|
-
const [ref, node] = useNode();
|
|
1790
|
-
React.useEffect(() => {
|
|
1791
|
-
node && draw$3(node, props);
|
|
1792
|
-
}, [node, props]);
|
|
1793
|
-
const onDraw = () => draw$3(node, props);
|
|
1794
|
-
useResize(props.width, onDraw);
|
|
1795
|
-
return React__default.createElement("div", {
|
|
1796
|
-
className: className,
|
|
1797
|
-
style: style
|
|
1798
|
-
}, React__default.createElement(TooltipStyles, null), React__default.createElement(SvgWrapper$3, {
|
|
1799
|
-
ref: ref
|
|
1800
|
-
}, children));
|
|
1801
|
-
};
|
|
1802
|
-
LineChart.defaultProps = {
|
|
1803
|
-
data: [],
|
|
1804
|
-
labels: [],
|
|
1805
|
-
height: 240,
|
|
1806
|
-
yAxisPadding: 10,
|
|
1807
|
-
xAxisPadding: 20,
|
|
1808
|
-
margin: {
|
|
1809
|
-
top: 10,
|
|
1810
|
-
right: 10,
|
|
1811
|
-
bottom: 10,
|
|
1812
|
-
left: 0
|
|
1813
|
-
},
|
|
1814
|
-
dynamicCircleRadius: 4,
|
|
1815
|
-
stackedTooltip: false
|
|
1816
|
-
};
|
|
1817
|
-
|
|
1818
|
-
const barChartLinesClassNames = {
|
|
1819
|
-
barChartLinesGlobal: 'barChartLinesGlobal',
|
|
1820
|
-
barChartLine: 'barChartLine',
|
|
1821
|
-
barChartAreasGlobal: 'barChartAreasGlobal',
|
|
1822
|
-
barChartArea: 'barChartArea'
|
|
1823
|
-
};
|
|
1824
|
-
const drawLines = _ref => {
|
|
1825
|
-
let {
|
|
1826
|
-
svg,
|
|
1827
|
-
lineData,
|
|
1828
|
-
min,
|
|
1829
|
-
yScale,
|
|
1830
|
-
xScale,
|
|
1831
|
-
curve,
|
|
1832
|
-
stackedLine
|
|
1833
|
-
} = _ref;
|
|
1834
|
-
let linesSelection = null;
|
|
1835
|
-
let areasSelection = null;
|
|
1836
|
-
let area = null;
|
|
1837
|
-
const line = d3.line().defined(d => d !== null).x((_, index) => xScale(index) + bandwidth / 2)
|
|
1838
|
-
// @ts-ignore
|
|
1839
|
-
.y(d => yScale(d)).curve(curve || d3.curveLinear);
|
|
1840
|
-
const bandwidth = xScale.bandwidth();
|
|
1841
|
-
const linesData = lineData.filter(_ref2 => {
|
|
1842
|
-
let {
|
|
1843
|
-
lineType
|
|
1844
|
-
} = _ref2;
|
|
1845
|
-
return lineType === 'line';
|
|
1846
|
-
});
|
|
1847
|
-
const areasData = lineData.filter(_ref3 => {
|
|
1848
|
-
let {
|
|
1849
|
-
lineType
|
|
1850
|
-
} = _ref3;
|
|
1851
|
-
return lineType === 'area';
|
|
1852
|
-
});
|
|
1853
|
-
if (linesData.length > 0) {
|
|
1854
|
-
linesSelection = svg.append('g').attr('class', barChartLinesClassNames.barChartLinesGlobal).selectAll('path').data(linesData).join('path').attr('class', barChartLinesClassNames.barChartLine).attr('d', d => line(d.values)).attr('stroke', _ref4 => {
|
|
1855
|
-
let {
|
|
1856
|
-
stroke
|
|
1857
|
-
} = _ref4;
|
|
1858
|
-
return stroke || '';
|
|
1859
|
-
}).attr('fill', _ref5 => {
|
|
1860
|
-
let {
|
|
1861
|
-
fill
|
|
1862
|
-
} = _ref5;
|
|
1863
|
-
return fill || 'none';
|
|
1864
|
-
});
|
|
1865
|
-
}
|
|
1866
|
-
if (areasData.length > 0) {
|
|
1867
|
-
let dataIndex = -2;
|
|
1868
|
-
area = d3.area().x((_, index) => xScale(index) + bandwidth / 2).y0((_, index) => {
|
|
1869
|
-
if (index === 0) {
|
|
1870
|
-
dataIndex = dataIndex + 1;
|
|
1871
|
-
}
|
|
1872
|
-
return stackedLine ? dataIndex > -1 ? yScale(typeof lineData[dataIndex].values[index] !== 'number' ? 0 : lineData[dataIndex].values[index]) : yScale(min) : yScale(min);
|
|
1873
|
-
})
|
|
1874
|
-
// @ts-ignore
|
|
1875
|
-
.y1(d => yScale(d)).curve(curve || d3.curveLinear);
|
|
1876
|
-
areasSelection = svg.append('g').attr('class', barChartLinesClassNames.barChartAreasGlobal).selectAll('path').data(areasData).join('path').attr('class', barChartLinesClassNames.barChartArea).attr('d', d => area && area(d.values)).attr('fill', _ref6 => {
|
|
1877
|
-
let {
|
|
1878
|
-
fill
|
|
1879
|
-
} = _ref6;
|
|
1880
|
-
return fill || 'none';
|
|
1881
|
-
});
|
|
1882
|
-
}
|
|
1883
|
-
return {
|
|
1884
|
-
areasSelection,
|
|
1885
|
-
linesSelection,
|
|
1886
|
-
area
|
|
1887
|
-
};
|
|
1888
|
-
};
|
|
1889
|
-
|
|
1890
|
-
var _templateObject$a, _templateObject2$4;
|
|
1891
|
-
const tooltipClassnames = {
|
|
1892
|
-
barChartMouseRect: 'barChartMouseRect',
|
|
1893
|
-
barChartMouseContainer: 'barChartMouseContainer',
|
|
1894
|
-
barChartTooltipFlex: 'barChartTooltipFlex',
|
|
1895
|
-
barChartMouseTooltip: 'barChartMouseTooltip',
|
|
1896
|
-
barChartTooltip: 'barChartTooltip',
|
|
1897
|
-
barChartTooltipItem: 'barChartTooltipItem',
|
|
1898
|
-
barChartTooltipColFlex: 'barChartTooltipColFlex',
|
|
1899
|
-
barChartTooltipGroupName: 'barChartTooltipGroupName',
|
|
1900
|
-
barChartColorBox: 'barChartColorBox',
|
|
1901
|
-
barChartColorLine: 'barChartColorLine',
|
|
1902
|
-
barChartTooltipName: 'barChartTooltipName',
|
|
1903
|
-
barChartTooltipValue: 'barChartTooltipValue'
|
|
1904
|
-
};
|
|
1905
|
-
const labelClassnames = {
|
|
1906
|
-
barChartLabelContainer: 'barChartLabelContainer',
|
|
1907
|
-
barChartLabelFlex: 'barChartLabelFlex',
|
|
1908
|
-
barChartLabel: 'barChartLabel'
|
|
1909
|
-
};
|
|
1910
|
-
const barChartClassNames = /*#__PURE__*/_extends({
|
|
1911
|
-
barChartBarGlobal: 'barChartBarGlobal',
|
|
1912
|
-
barChartYScaleGlobal: 'barChartYScaleGlobal',
|
|
1913
|
-
barChartYAxis: 'barChartYAxis',
|
|
1914
|
-
barChartXAxis: 'barChartXAxis',
|
|
1915
|
-
barChartYAxisZeroTick: 'barChartYAxisZeroTick',
|
|
1916
|
-
barChartGridGlobal: 'barChartGridGlobal',
|
|
1917
|
-
barChartGridLineX: 'barChartGridLineX',
|
|
1918
|
-
barChartGridLineXZero: 'barChartGridLineXZero',
|
|
1919
|
-
barChartGridLineYZero: 'barChartGridLineYZero',
|
|
1920
|
-
barChartGridLineY: 'barChartGridLineY',
|
|
1921
|
-
barChartSelection: 'barChartSelection'
|
|
1922
|
-
}, tooltipClassnames, labelClassnames, barChartLinesClassNames);
|
|
1923
|
-
const SvgWrapper$4 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$a || (_templateObject$a = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: ", ";\n user-select: ", ";\n width: ", ";\n\n line {\n stroke-width: 1px;\n shape-rendering: crispEdges;\n }\n\n .", ",\n .", " {\n stroke: rgba(48, 69, 79, 0.06);\n }\n\n .", " {\n }\n\n .", " {\n fill: none;\n pointer-events: all;\n }\n\n .", " {\n stroke-width: 1.5px;\n stroke-linejoin: round;\n stroke-linecap: round;\n }\n\n .", " {\n shape-rendering: auto;\n }\n\n .", " {\n fill-opacity: 0.24;\n }\n\n .", " {\n position: absolute;\n top: 0;\n width: 0;\n background: rgba(0, 170, 255, 0.06);\n box-shadow: 1px 0 0 #00AAFF, -1px 0 0 #00AAFF;\n pointer-events: none;\n }\n"])), _ref => {
|
|
1924
|
-
let {
|
|
1925
|
-
selectable
|
|
1926
|
-
} = _ref;
|
|
1927
|
-
return selectable && "inline-block";
|
|
1928
|
-
}, _ref2 => {
|
|
1929
|
-
let {
|
|
1930
|
-
selectable
|
|
1931
|
-
} = _ref2;
|
|
1932
|
-
return selectable && "none";
|
|
1933
|
-
}, _ref3 => {
|
|
1934
|
-
let {
|
|
1935
|
-
selectable
|
|
1936
|
-
} = _ref3;
|
|
1937
|
-
return selectable && "auto";
|
|
1938
|
-
}, barChartClassNames.barChartGridLineX, barChartClassNames.barChartGridLineY, barChartClassNames.barChartMouseRect, barChartClassNames.barChartMouseRect, barChartClassNames.barChartLinesGlobal, barChartClassNames.barChartLine, barChartClassNames.barChartArea, barChartClassNames.barChartSelection);
|
|
1939
|
-
const TooltipStyles$1 = /*#__PURE__*/styled.createGlobalStyle(_templateObject2$4 || (_templateObject2$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n z-index: 100;\n transition: all linear 144ms;\n\n .", " {\n margin-bottom: 4px;\n :last-of-type {\n margin-bottom: 0;\n }\n }\n }\n"])), barChartClassNames.barChartMouseTooltip, barChartClassNames.barChartTooltipItem);
|
|
1940
|
-
|
|
1941
|
-
const useSelection = (node, props) => {
|
|
1942
|
-
const drawing = React.useRef(false);
|
|
1943
|
-
const startX = React.useRef(0);
|
|
1944
|
-
const selection = React.useRef();
|
|
1945
|
-
const clearSelection = React.useCallback(() => {
|
|
1946
|
-
if (node && selection.current) {
|
|
1947
|
-
drawing.current = false;
|
|
1948
|
-
node.removeChild(selection.current);
|
|
1949
|
-
selection.current = undefined;
|
|
1950
|
-
}
|
|
1951
|
-
}, [node]);
|
|
1952
|
-
const onStartDrawing = React.useCallback(e => {
|
|
1953
|
-
const isTouch = Boolean(e.touches);
|
|
1954
|
-
e.stopPropagation();
|
|
1955
|
-
if (node && e.which !== 3) {
|
|
1956
|
-
var _props$margin$bottom, _props$margin, _e$touches$;
|
|
1957
|
-
clearSelection();
|
|
1958
|
-
selection.current = document.createElement("div");
|
|
1959
|
-
selection.current.setAttribute("class", barChartClassNames.barChartSelection);
|
|
1960
|
-
selection.current.setAttribute("style", "height: calc(100% - " + ((_props$margin$bottom = (_props$margin = props.margin) == null ? void 0 : _props$margin.bottom) != null ? _props$margin$bottom : 0) + "px)");
|
|
1961
|
-
node.appendChild(selection.current);
|
|
1962
|
-
drawing.current = true;
|
|
1963
|
-
startX.current = isTouch ? ((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.pageX) - node.firstChild.getBoundingClientRect().left : e.offsetX;
|
|
1964
|
-
selection.current.style.display = "block";
|
|
1965
|
-
selection.current.style.width = "0px";
|
|
1966
|
-
selection.current.style.left = startX.current + "px";
|
|
1967
|
-
}
|
|
1968
|
-
}, [node]);
|
|
1969
|
-
const onDraw = React.useCallback(e => {
|
|
1970
|
-
const isTouch = Boolean(e.touches);
|
|
1971
|
-
e.stopPropagation();
|
|
1972
|
-
if (node && drawing.current && selection.current) {
|
|
1973
|
-
var _e$touches$2;
|
|
1974
|
-
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
1975
|
-
const offsetX = isTouch ? ((_e$touches$2 = e.touches[0]) == null ? void 0 : _e$touches$2.pageX) - node.firstChild.getBoundingClientRect().left : e.offsetX;
|
|
1976
|
-
const newWidth = offsetX - startX.current;
|
|
1977
|
-
if (offsetX >= 0) {
|
|
1978
|
-
if (newWidth > 0) {
|
|
1979
|
-
selection.current.style.marginLeft = "0px";
|
|
1980
|
-
selection.current.style.width = offsetX <= nodeWidth ? newWidth + "px" : nodeWidth - startX.current + "px";
|
|
1981
|
-
} else {
|
|
1982
|
-
selection.current.style.right = nodeWidth - startX.current + "px";
|
|
1983
|
-
selection.current.style.width = Math.abs(newWidth) + "px";
|
|
1984
|
-
selection.current.style.marginLeft = newWidth + "px";
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
if (isTouch) {
|
|
1988
|
-
if (node.offsetLeft > e.touches[0].pageX) {
|
|
1989
|
-
selection.current.style.right = nodeWidth - startX.current + "px";
|
|
1990
|
-
selection.current.style.width = startX.current + "px";
|
|
1991
|
-
selection.current.style.marginLeft = "-" + startX.current + "px";
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
}
|
|
1995
|
-
}, [node]);
|
|
1996
|
-
const onMouseLeave = React.useCallback(e => {
|
|
1997
|
-
if (drawing.current && node && selection.current) {
|
|
1998
|
-
if (node.offsetLeft > e.pageX) {
|
|
1999
|
-
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
2000
|
-
selection.current.style.right = nodeWidth - startX.current + "px";
|
|
2001
|
-
selection.current.style.width = startX.current + "px";
|
|
2002
|
-
selection.current.style.marginLeft = "-" + startX.current + "px";
|
|
2003
|
-
}
|
|
2004
|
-
if (node.offsetLeft + node.offsetWidth < e.pageX) {
|
|
2005
|
-
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
2006
|
-
selection.current.style.left = startX.current + "px";
|
|
2007
|
-
selection.current.style.width = nodeWidth - startX.current + "px";
|
|
2008
|
-
selection.current.style.marginLeft = "0px";
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
}, [node]);
|
|
2012
|
-
const onStopDrawing = React.useCallback(() => {
|
|
2013
|
-
if (node && selection.current) {
|
|
2014
|
-
const nodeWidth = node.firstChild.getBoundingClientRect().width;
|
|
2015
|
-
const selectionMinX = selection.current.offsetLeft >= 0 ? selection.current.offsetLeft <= nodeWidth ? selection.current.offsetLeft : nodeWidth : 0;
|
|
2016
|
-
const selectionWidth = selection.current.getBoundingClientRect().right - selection.current.getBoundingClientRect().left;
|
|
2017
|
-
const selectionMaxX = selection.current.offsetLeft + selectionWidth <= nodeWidth ? selection.current.offsetLeft + selectionWidth >= 0 ? selection.current.offsetLeft + selectionWidth : 0 : nodeWidth;
|
|
2018
|
-
const min = Math.round(selectionMinX);
|
|
2019
|
-
const max = Math.round(selectionMaxX);
|
|
2020
|
-
if (max - min > 0 && props.onSelect) {
|
|
2021
|
-
props.onSelect([min, max]);
|
|
2022
|
-
}
|
|
2023
|
-
}
|
|
2024
|
-
clearSelection();
|
|
2025
|
-
}, [node, clearSelection]);
|
|
2026
|
-
React.useEffect(() => {
|
|
2027
|
-
if (node) {
|
|
2028
|
-
node.childNodes.forEach(child => {
|
|
2029
|
-
child.style.userSelect = "none";
|
|
2030
|
-
});
|
|
2031
|
-
node.addEventListener("mousedown", onStartDrawing);
|
|
2032
|
-
node.addEventListener("touchstart", onStartDrawing);
|
|
2033
|
-
node.addEventListener("mousemove", onDraw);
|
|
2034
|
-
node.addEventListener("touchmove", onDraw);
|
|
2035
|
-
node.addEventListener("mouseleave", onMouseLeave);
|
|
2036
|
-
node.addEventListener("mouseup", onStopDrawing);
|
|
2037
|
-
node.addEventListener("touchend", onStopDrawing);
|
|
2038
|
-
document.addEventListener("mouseup", onStopDrawing);
|
|
2039
|
-
}
|
|
2040
|
-
return () => {
|
|
2041
|
-
node == null || node.removeEventListener("mousedown", onStartDrawing);
|
|
2042
|
-
node == null || node.removeEventListener("touchstart", onStartDrawing);
|
|
2043
|
-
node == null || node.removeEventListener("mousemove", onDraw);
|
|
2044
|
-
node == null || node.removeEventListener("touchmove", onDraw);
|
|
2045
|
-
node == null || node.removeEventListener("mouseleave", onMouseLeave);
|
|
2046
|
-
node == null || node.removeEventListener("mouseup", onStopDrawing);
|
|
2047
|
-
node == null || node.removeEventListener("touchend", onStopDrawing);
|
|
2048
|
-
document.removeEventListener("mouseup", onStopDrawing);
|
|
2049
|
-
};
|
|
2050
|
-
}, [node]);
|
|
2051
|
-
};
|
|
2052
|
-
|
|
2053
|
-
const drawGrid$1 = _ref => {
|
|
2054
|
-
let {
|
|
2055
|
-
svg,
|
|
2056
|
-
yScale,
|
|
2057
|
-
xScale,
|
|
2058
|
-
yTicksCount,
|
|
2059
|
-
drawGridX,
|
|
2060
|
-
drawGridY
|
|
2061
|
-
} = _ref;
|
|
2062
|
-
if (!drawGridY && !drawGridX) return;
|
|
2063
|
-
const global = svg.append('g').attr('class', barChartClassNames.barChartGridGlobal);
|
|
2064
|
-
const yTicks = yScale.ticks(yTicksCount);
|
|
2065
|
-
const range = xScale.range();
|
|
2066
|
-
const domain = xScale.domain();
|
|
2067
|
-
if (drawGridX) {
|
|
2068
|
-
global.append('g').selectAll('line').data(yTicks).join('line').attr('class', d => d === 0 ? barChartClassNames.barChartGridLineX + " " + barChartClassNames.barChartGridLineXZero : barChartClassNames.barChartGridLineX).attr('x1', () => range[0]).attr('x2', () => range[1]).attr('y1', d => Math.round(yScale(d))).attr('y2', d => Math.round(yScale(d)));
|
|
2069
|
-
}
|
|
2070
|
-
if (drawGridY) {
|
|
2071
|
-
const getX = index => domain[index] !== void 0 ? index === 0 ? range[0] : Math.round(xScale.step() * index + range[0] - xScale.step() / 2 * xScale.padding()) : range[1];
|
|
2072
|
-
global.append('g').selectAll('line').data(Array.from({
|
|
2073
|
-
length: domain.length + 1
|
|
2074
|
-
}, (_, index) => index)).join('line').attr('class', d => d === 0 ? barChartClassNames.barChartGridLineY + " " + barChartClassNames.barChartGridLineYZero : barChartClassNames.barChartGridLineY).attr('x1', getX).attr('x2', getX).attr('y1', () => Math.round(yScale(yTicks[0]))).attr('y2', () => Math.round(yScale(yTicks[yTicks.length - 1])));
|
|
2075
|
-
}
|
|
2076
|
-
};
|
|
2077
|
-
|
|
2078
|
-
const _excluded$2 = ["groupName"];
|
|
2079
|
-
const getDomain = _ref => {
|
|
2080
|
-
let {
|
|
2081
|
-
data,
|
|
2082
|
-
minDomainValue,
|
|
2083
|
-
maxDomainValue
|
|
2084
|
-
} = _ref;
|
|
2085
|
-
let MIN = Number.POSITIVE_INFINITY;
|
|
2086
|
-
let MAX = Number.NEGATIVE_INFINITY;
|
|
2087
|
-
data.forEach(_ref2 => {
|
|
2088
|
-
let groups = _objectWithoutPropertiesLoose(_ref2, _excluded$2);
|
|
2089
|
-
let groupMax = 0;
|
|
2090
|
-
let groupMin = 0;
|
|
2091
|
-
Object.keys(groups).forEach(key => {
|
|
2092
|
-
const group = groups[key];
|
|
2093
|
-
let stackMax = 0;
|
|
2094
|
-
let stackMin = 0;
|
|
2095
|
-
Object.keys(group).forEach(groupKey => {
|
|
2096
|
-
const value = group[groupKey];
|
|
2097
|
-
if (value > 0) {
|
|
2098
|
-
stackMax += value;
|
|
2099
|
-
} else {
|
|
2100
|
-
stackMin += value;
|
|
2101
|
-
}
|
|
2102
|
-
});
|
|
2103
|
-
groupMax = Math.min(groupMax, stackMin);
|
|
2104
|
-
groupMin = Math.max(groupMin, stackMax);
|
|
2105
|
-
});
|
|
2106
|
-
MIN = Math.min(MIN, groupMax);
|
|
2107
|
-
MAX = Math.max(MAX, groupMin);
|
|
2108
|
-
});
|
|
2109
|
-
if (MIN === 0 && MAX === 0) {
|
|
2110
|
-
return {
|
|
2111
|
-
min: typeof minDomainValue === 'number' ? minDomainValue : 0,
|
|
2112
|
-
max: typeof maxDomainValue === 'number' ? maxDomainValue : 1
|
|
2113
|
-
};
|
|
2114
|
-
}
|
|
2115
|
-
return {
|
|
2116
|
-
min: typeof minDomainValue === 'number' ? minDomainValue : MIN,
|
|
2117
|
-
max: typeof maxDomainValue === 'number' ? maxDomainValue : MAX
|
|
2118
|
-
};
|
|
2119
|
-
};
|
|
2120
|
-
|
|
2121
|
-
const _excluded$3 = ["groupName"];
|
|
2122
|
-
const marshaling = _ref => {
|
|
2123
|
-
let {
|
|
2124
|
-
data,
|
|
2125
|
-
yScale,
|
|
2126
|
-
xScale,
|
|
2127
|
-
barWidth,
|
|
2128
|
-
barPadding,
|
|
2129
|
-
colors,
|
|
2130
|
-
marginTop
|
|
2131
|
-
} = _ref;
|
|
2132
|
-
return data.map((_ref2, groupIndex) => {
|
|
2133
|
-
let {
|
|
2134
|
-
groupName
|
|
2135
|
-
} = _ref2,
|
|
2136
|
-
groups = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
|
|
2137
|
-
const marshalledGroup = [];
|
|
2138
|
-
const hundred = 100;
|
|
2139
|
-
const bandwidth = xScale.bandwidth();
|
|
2140
|
-
const groupsKeys = Object.keys(groups);
|
|
2141
|
-
groupsKeys.forEach((key, stackIndex) => {
|
|
2142
|
-
const group = groups[key];
|
|
2143
|
-
const groupKeys = Object.keys(group);
|
|
2144
|
-
const barGroupWidth = (barWidth + barPadding) * groupsKeys.length - (groupKeys.length > 1 ? barPadding : 0);
|
|
2145
|
-
let stackMax = 0;
|
|
2146
|
-
let stackMin = 0;
|
|
2147
|
-
groupKeys.forEach(groupKey => {
|
|
2148
|
-
const value = group[groupKey];
|
|
2149
|
-
const color = colors[groupKey];
|
|
2150
|
-
const x = (barWidth + barPadding) * stackIndex + bandwidth / 2 - barGroupWidth / 2;
|
|
2151
|
-
const isPositiveValue = value > 0;
|
|
2152
|
-
const height = isPositiveValue ? Math.abs((yScale(stackMax - value) - yScale(stackMax) + Number.EPSILON) * hundred / hundred) : Math.abs((yScale(stackMin - value) - yScale(stackMin) + Number.EPSILON) * hundred / hundred);
|
|
2153
|
-
if (isPositiveValue) {
|
|
2154
|
-
stackMax += value;
|
|
2155
|
-
}
|
|
2156
|
-
const y = isPositiveValue ? (yScale(stackMax) + Number.EPSILON) * hundred / hundred : yScale(stackMin) - yScale(0) + yScale(0);
|
|
2157
|
-
marshalledGroup.push({
|
|
2158
|
-
x,
|
|
2159
|
-
y: y + (marginTop || 0),
|
|
2160
|
-
height,
|
|
2161
|
-
color,
|
|
2162
|
-
value,
|
|
2163
|
-
groupName: groupName,
|
|
2164
|
-
name: groupKey,
|
|
2165
|
-
stackIndex,
|
|
2166
|
-
groupIndex
|
|
2167
|
-
});
|
|
2168
|
-
if (!isPositiveValue) {
|
|
2169
|
-
stackMin += value;
|
|
2170
|
-
}
|
|
2171
|
-
});
|
|
2172
|
-
});
|
|
2173
|
-
return marshalledGroup;
|
|
2174
|
-
});
|
|
2175
|
-
};
|
|
2176
|
-
|
|
2177
|
-
const getLabelY = (labelPosition, y2, item) => {
|
|
2178
|
-
switch (labelPosition) {
|
|
2179
|
-
case 'center':
|
|
2180
|
-
return item.y + item.height / 2 - y2;
|
|
2181
|
-
case 'bottom':
|
|
2182
|
-
return item.y + item.height - y2;
|
|
2183
|
-
default:
|
|
2184
|
-
return item.y;
|
|
2185
|
-
}
|
|
2186
|
-
};
|
|
2187
|
-
|
|
2188
|
-
const getLabel = labelPosition => {
|
|
2189
|
-
switch (labelPosition) {
|
|
2190
|
-
case 'top':
|
|
2191
|
-
return LabelTop;
|
|
2192
|
-
case 'bottom':
|
|
2193
|
-
return LabelBottom;
|
|
2194
|
-
default:
|
|
2195
|
-
return Label$1;
|
|
2196
|
-
}
|
|
2197
|
-
};
|
|
2198
|
-
|
|
2199
|
-
const _excluded$4 = ["values"];
|
|
2200
|
-
const drawTooltip$2 = _ref => {
|
|
2201
|
-
let {
|
|
2202
|
-
svg,
|
|
2203
|
-
node,
|
|
2204
|
-
data,
|
|
2205
|
-
marshalledData,
|
|
2206
|
-
xScale,
|
|
2207
|
-
yScale,
|
|
2208
|
-
renderTooltip,
|
|
2209
|
-
labelPosition,
|
|
2210
|
-
marginTop,
|
|
2211
|
-
renderLabel,
|
|
2212
|
-
barWidth,
|
|
2213
|
-
barPadding,
|
|
2214
|
-
dynamicTooltipEnable,
|
|
2215
|
-
hideTooltipGroupName,
|
|
2216
|
-
tooltipY,
|
|
2217
|
-
tooltipBind,
|
|
2218
|
-
lineData,
|
|
2219
|
-
formatTooltipValue,
|
|
2220
|
-
formatTooltipName,
|
|
2221
|
-
tooltipYDomain,
|
|
2222
|
-
setTooltipPosition,
|
|
2223
|
-
onLabelItem,
|
|
2224
|
-
isBarTooltip,
|
|
2225
|
-
bars,
|
|
2226
|
-
tooltipRoot,
|
|
2227
|
-
tooltipClassName,
|
|
2228
|
-
onBarClick,
|
|
2229
|
-
onBarHover
|
|
2230
|
-
} = _ref;
|
|
2231
|
-
d3.select(node).select("." + barChartClassNames.barChartMouseContainer).remove();
|
|
2232
|
-
const xScaleBandDomain = xScale.domain();
|
|
2233
|
-
const [x1, x2] = xScale.range();
|
|
2234
|
-
const [y1, y2] = yScale.range();
|
|
2235
|
-
const bandwidth = xScale.bandwidth();
|
|
2236
|
-
const format = d3.format(',');
|
|
2237
|
-
const getX = index => xScaleBandDomain[index] !== void 0 ? index === 0 ? x1 : Math.round(xScale.step() * index + x1 - xScale.step() / 2 * xScale.padding()) : x2;
|
|
2238
|
-
const groups = xScaleBandDomain.map(value => getX(Number(value) + 1));
|
|
2239
|
-
const topYDomain = tooltipYDomain ? tooltipYDomain({
|
|
2240
|
-
data: marshalledData,
|
|
2241
|
-
lineData,
|
|
2242
|
-
yScale
|
|
2243
|
-
}) : marshalledData.reduce((acc, curr, index) => {
|
|
2244
|
-
const lineMin = d3.min(lineData, _ref2 => {
|
|
2245
|
-
let {
|
|
2246
|
-
values
|
|
2247
|
-
} = _ref2;
|
|
2248
|
-
return typeof values[index] === 'number' ? yScale((values[index] || 0) - y2) : Number.POSITIVE_INFINITY;
|
|
2249
|
-
}) || Number.POSITIVE_INFINITY;
|
|
2250
|
-
acc.push(curr.reduce((acc, _ref3) => {
|
|
2251
|
-
let {
|
|
2252
|
-
y
|
|
2253
|
-
} = _ref3;
|
|
2254
|
-
return Math.min(acc, y, lineMin);
|
|
2255
|
-
}, Number.POSITIVE_INFINITY));
|
|
2256
|
-
return acc;
|
|
2257
|
-
}, []);
|
|
2258
|
-
const mouseGlobal = svg.append('g').attr('class', 'lineChartMouseGlobal');
|
|
2259
|
-
const mouseRect = mouseGlobal.append('rect').attr('width', x2 - x1).attr('height', Math.abs(y1 - y2)).attr('class', barChartClassNames.barChartMouseRect).attr('transform', "translate(" + x1 + ", " + y2 + ")");
|
|
2260
|
-
if (dynamicTooltipEnable) {
|
|
2261
|
-
const tooltipContainer = tooltipRoot || document.querySelector('body');
|
|
2262
|
-
let tooltip = d3.select("." + barChartClassNames.barChartMouseTooltip);
|
|
2263
|
-
if (tooltip.size() === 0) {
|
|
2264
|
-
tooltip = d3.select(tooltipContainer).append('div').attr('class', barChartClassNames.barChartMouseTooltip).style('opacity', '0').style('position', 'absolute').html(() => {
|
|
2265
|
-
const html = ReactDOMServer.renderToString(React__default.createElement(TooltipFlex, {
|
|
2266
|
-
className: barChartClassNames.barChartTooltipFlex
|
|
2267
|
-
}));
|
|
2268
|
-
return html;
|
|
2269
|
-
});
|
|
2270
|
-
}
|
|
2271
|
-
const barChartTootipFlex = tooltip.select("." + barChartClassNames.barChartTooltipFlex);
|
|
2272
|
-
let isVisible = false;
|
|
2273
|
-
let flagCurrIndex = null;
|
|
2274
|
-
const setVisible = visible => {
|
|
2275
|
-
isVisible = Boolean(visible);
|
|
2276
|
-
const opacity = isVisible ? '1' : '0';
|
|
2277
|
-
tooltip.style('opacity', opacity);
|
|
2278
|
-
if (!isVisible) {
|
|
2279
|
-
tooltip.attr('class', barChartClassNames.barChartMouseTooltip);
|
|
2280
|
-
flagCurrIndex = null;
|
|
2281
|
-
tooltip.style('transition', 'none');
|
|
2282
|
-
tooltip.style('top', null);
|
|
2283
|
-
tooltip.style('left', null);
|
|
2284
|
-
} else {
|
|
2285
|
-
tooltip.attr('class', barChartClassNames.barChartMouseTooltip + " " + (tooltipClassName || ''));
|
|
2286
|
-
tooltip.style('transition', null);
|
|
2287
|
-
}
|
|
2288
|
-
};
|
|
2289
|
-
mouseRect.on('mouseout.tooltip', () => setVisible());
|
|
2290
|
-
mouseRect.on('touchmove.tooltip mousemove.tooltip', event => {
|
|
2291
|
-
const [docX, docY] = d3.pointer(event, document);
|
|
2292
|
-
const [rectrX] = d3.pointer(event, mouseRect);
|
|
2293
|
-
const [nodeX, nodeY] = d3.pointer(event, node);
|
|
2294
|
-
const x = rectrX - (rectrX - nodeX);
|
|
2295
|
-
const offsetX = docX - nodeX;
|
|
2296
|
-
const offsetY = docY - nodeY;
|
|
2297
|
-
const currIndex = groups.findIndex(value => x <= value);
|
|
2298
|
-
if (isBarTooltip) {
|
|
2299
|
-
const containts = document.elementsFromPoint(event.clientX, event.clientY);
|
|
2300
|
-
const currBars = d3.select(bars.nodes()[currIndex]).selectAll('rect').nodes();
|
|
2301
|
-
const isContains = containts.some(item => currBars.includes(item));
|
|
2302
|
-
if (!isContains) {
|
|
2303
|
-
if (isVisible) {
|
|
2304
|
-
setVisible(false);
|
|
2305
|
-
}
|
|
2306
|
-
mouseRect.style('cursor', 'default');
|
|
2307
|
-
return;
|
|
2308
|
-
} else {
|
|
2309
|
-
mouseRect.style('cursor', 'pointer');
|
|
2310
|
-
}
|
|
2311
|
-
}
|
|
2312
|
-
const top = (typeof tooltipY === 'number' ? tooltipY : topYDomain[currIndex] - y2) + offsetY;
|
|
2313
|
-
const left = (tooltipBind ? (xScale(currIndex) || 0) + bandwidth / 2 : x) + offsetX;
|
|
2314
|
-
if (tooltipBind && flagCurrIndex === currIndex) {
|
|
2315
|
-
return;
|
|
2316
|
-
}
|
|
2317
|
-
let currData = marshalledData[currIndex];
|
|
2318
|
-
if (Array.isArray(currData) && currData.length === 0) {
|
|
2319
|
-
return;
|
|
2320
|
-
}
|
|
2321
|
-
if (lineData) {
|
|
2322
|
-
const currLineData = lineData.map(_ref4 => {
|
|
2323
|
-
let {
|
|
2324
|
-
values
|
|
2325
|
-
} = _ref4,
|
|
2326
|
-
rest = _objectWithoutPropertiesLoose(_ref4, _excluded$4);
|
|
2327
|
-
return _extends({}, rest, {
|
|
2328
|
-
value: values[currIndex],
|
|
2329
|
-
groupName: data[currIndex] && data[currIndex].groupName
|
|
2330
|
-
});
|
|
2331
|
-
});
|
|
2332
|
-
if (Array.isArray(currLineData) && Array.isArray(currData)) {
|
|
2333
|
-
currData = currData.concat(currLineData);
|
|
2334
|
-
}
|
|
2335
|
-
}
|
|
2336
|
-
const svgWidth = svg.node().getBoundingClientRect().width;
|
|
2337
|
-
if (typeof setTooltipPosition === 'function') {
|
|
2338
|
-
setTooltipPosition({
|
|
2339
|
-
left,
|
|
2340
|
-
top,
|
|
2341
|
-
tooltip,
|
|
2342
|
-
svgWidth
|
|
2343
|
-
});
|
|
2344
|
-
} else if (!setTooltipPosition) {
|
|
2345
|
-
tooltip.style('left', left + "px").style('top', top + "px");
|
|
2346
|
-
}
|
|
2347
|
-
if (renderTooltip) {
|
|
2348
|
-
barChartTootipFlex.html(() => {
|
|
2349
|
-
const html = ReactDOMServer.renderToString(React__default.createElement(React__default.Fragment, null, renderTooltip(currData, setTooltipPosition ? {
|
|
2350
|
-
left,
|
|
2351
|
-
top,
|
|
2352
|
-
tooltip,
|
|
2353
|
-
svgWidth
|
|
2354
|
-
} : undefined, barWidth)));
|
|
2355
|
-
return html;
|
|
2356
|
-
});
|
|
2357
|
-
} else {
|
|
2358
|
-
if (!isVisible) {
|
|
2359
|
-
setVisible(true);
|
|
2360
|
-
}
|
|
2361
|
-
barChartTootipFlex.html(() => {
|
|
2362
|
-
const html = ReactDOMServer.renderToString(React__default.createElement(TooltipContainer, {
|
|
2363
|
-
className: barChartClassNames.barChartTooltip
|
|
2364
|
-
}, currData && currData[0] && !hideTooltipGroupName && React__default.createElement(TooltipGroupName, {
|
|
2365
|
-
className: barChartClassNames.barChartTooltipGroupName
|
|
2366
|
-
}, currData[0].groupName), currData && currData.map(_ref5 => {
|
|
2367
|
-
let {
|
|
2368
|
-
name,
|
|
2369
|
-
value,
|
|
2370
|
-
stroke,
|
|
2371
|
-
fill,
|
|
2372
|
-
color,
|
|
2373
|
-
lineType
|
|
2374
|
-
} = _ref5;
|
|
2375
|
-
return React__default.createElement(TooltipItem, {
|
|
2376
|
-
key: name,
|
|
2377
|
-
className: barChartClassNames.barChartTooltipItem
|
|
2378
|
-
}, React__default.createElement(ColFlex, {
|
|
2379
|
-
className: barChartClassNames.barChartTooltipColFlex
|
|
2380
|
-
}, lineType ? React__default.createElement(ColorLine, {
|
|
2381
|
-
className: barChartClassNames.barChartColorLine,
|
|
2382
|
-
style: {
|
|
2383
|
-
backgroundColor: stroke || fill
|
|
2384
|
-
}
|
|
2385
|
-
}) : React__default.createElement(ColorBox, {
|
|
2386
|
-
className: barChartClassNames.barChartColorBox,
|
|
2387
|
-
style: {
|
|
2388
|
-
backgroundColor: color
|
|
2389
|
-
}
|
|
2390
|
-
}), React__default.createElement(Name$1, {
|
|
2391
|
-
className: barChartClassNames.barChartTooltipName
|
|
2392
|
-
}, formatTooltipName ? formatTooltipName(name) : name)), React__default.createElement(Value, {
|
|
2393
|
-
className: barChartClassNames.barChartTooltipValue
|
|
2394
|
-
}, formatTooltipValue ? formatTooltipValue(value, name) : format(value)));
|
|
2395
|
-
})));
|
|
2396
|
-
return html;
|
|
2397
|
-
});
|
|
2398
|
-
}
|
|
2399
|
-
flagCurrIndex = currIndex;
|
|
2400
|
-
if (!isVisible) {
|
|
2401
|
-
setVisible(true);
|
|
2402
|
-
}
|
|
2403
|
-
});
|
|
2404
|
-
}
|
|
2405
|
-
const container = d3.select(node).append('div').attr('class', barChartClassNames.barChartMouseContainer);
|
|
2406
|
-
const labelContainer = container.append('div').attr('class', barChartClassNames.barChartLabelContainer).style('position', 'absolute').style('top', y2 + "px");
|
|
2407
|
-
const isMouseWithin = (e, callback) => {
|
|
2408
|
-
const [rectrX, rectrY] = d3.pointer(e, mouseRect);
|
|
2409
|
-
const [nodeX, nodeY] = d3.pointer(e, node);
|
|
2410
|
-
const x = rectrX - (rectrX - nodeX);
|
|
2411
|
-
const y = rectrY - nodeY;
|
|
2412
|
-
const currIndex = groups.findIndex(value => x <= value);
|
|
2413
|
-
const dataItem = marshalledData[currIndex][0];
|
|
2414
|
-
if (dataItem.height >= y1 - y) {
|
|
2415
|
-
callback(dataItem);
|
|
2416
|
-
}
|
|
2417
|
-
};
|
|
2418
|
-
mouseGlobal.on("click", e => isMouseWithin(e, dataItem => onBarClick && onBarClick(dataItem))).on("mousemove", e => isMouseWithin(e, dataItem => onBarHover && onBarHover(dataItem))).on("mouseleave", () => onBarHover && onBarHover(undefined));
|
|
2419
|
-
if (labelPosition) {
|
|
2420
|
-
const concatedData = lineData ? marshalledData.map((stack, index) => stack.concat(lineData.map(_ref6 => {
|
|
2421
|
-
let {
|
|
2422
|
-
values,
|
|
2423
|
-
name,
|
|
2424
|
-
stroke
|
|
2425
|
-
} = _ref6;
|
|
2426
|
-
const {
|
|
2427
|
-
stacksCount
|
|
2428
|
-
} = stack.reduce((acc, _ref7) => {
|
|
2429
|
-
let {
|
|
2430
|
-
stackIndex
|
|
2431
|
-
} = _ref7;
|
|
2432
|
-
const {
|
|
2433
|
-
indexFlag,
|
|
2434
|
-
stacksCount
|
|
2435
|
-
} = acc;
|
|
2436
|
-
if (stackIndex !== indexFlag) {
|
|
2437
|
-
return {
|
|
2438
|
-
indexFlag: stackIndex,
|
|
2439
|
-
stacksCount: stacksCount + 1
|
|
2440
|
-
};
|
|
2441
|
-
}
|
|
2442
|
-
return acc;
|
|
2443
|
-
}, {
|
|
2444
|
-
indexFlag: -1,
|
|
2445
|
-
stacksCount: 0
|
|
2446
|
-
});
|
|
2447
|
-
const barsWidth = (barWidth * stacksCount + (barPadding || 0) * (stacksCount - 1)) / 2;
|
|
2448
|
-
return {
|
|
2449
|
-
x: stack[0].x - barWidth / 2 + barsWidth,
|
|
2450
|
-
y: yScale(values[index]) + marginTop,
|
|
2451
|
-
height: 0,
|
|
2452
|
-
color: stroke,
|
|
2453
|
-
value: values[index],
|
|
2454
|
-
groupName: stack[0].groupName,
|
|
2455
|
-
name,
|
|
2456
|
-
stackIndex: 0,
|
|
2457
|
-
groupIndex: index
|
|
2458
|
-
};
|
|
2459
|
-
}))) : marshalledData;
|
|
2460
|
-
const groups = labelContainer.selectAll('div').data(concatedData).enter().append('div').style('position', 'absolute').style('transform', (_, index) => "translate(" + Math.round(xScale(index)) + "px," + -(marginTop || 0) + "px)");
|
|
2461
|
-
const LabelFlexStyled = labelPosition === 'center' ? LabelFlexCenter : LabelFlex;
|
|
2462
|
-
const LabelStyle = getLabel(labelPosition);
|
|
2463
|
-
groups.selectAll('span').data(item => onLabelItem ? onLabelItem(item) : item).join('div').style('left', item => Math.round(item.x + barWidth / 2) + "px").style('top', item => getLabelY(labelPosition, y2, item) + "px").style('position', 'absolute').html(item => ReactDOMServer.renderToString(React__default.createElement(LabelFlexStyled, {
|
|
2464
|
-
className: barChartClassNames.barChartLabelFlex
|
|
2465
|
-
}, renderLabel ? renderLabel(_extends({}, item, {
|
|
2466
|
-
barWidth
|
|
2467
|
-
})) : React__default.createElement(LabelStyle, {
|
|
2468
|
-
className: barChartClassNames.barChartLabel
|
|
2469
|
-
}, format(item.value)))));
|
|
2470
|
-
}
|
|
2471
|
-
};
|
|
2472
|
-
|
|
2473
|
-
const _excluded$5 = ["groupName"];
|
|
2474
|
-
const resizeBarWidth = _ref => {
|
|
2475
|
-
let {
|
|
2476
|
-
data,
|
|
2477
|
-
range,
|
|
2478
|
-
barWidth,
|
|
2479
|
-
barPadding,
|
|
2480
|
-
sectionPadding
|
|
2481
|
-
} = _ref;
|
|
2482
|
-
const groupPadding = typeof sectionPadding === 'number' ? sectionPadding : 0;
|
|
2483
|
-
const chartWidth = range[1] - range[0];
|
|
2484
|
-
const barsWidth = data.reduce((acc, _ref2) => {
|
|
2485
|
-
let curr = _objectWithoutPropertiesLoose(_ref2, _excluded$5);
|
|
2486
|
-
return acc + Object.keys(curr).reduce((acc, _key, index) => index > 0 ? acc + (barWidth || 0) + (barPadding || 0) : acc + barWidth, 0) + groupPadding;
|
|
2487
|
-
}, groupPadding);
|
|
2488
|
-
if (chartWidth < barsWidth) {
|
|
2489
|
-
return Math.floor(barWidth * (chartWidth / barsWidth));
|
|
2490
|
-
}
|
|
2491
|
-
return barWidth;
|
|
2492
|
-
};
|
|
2493
|
-
|
|
2494
|
-
const MIN_BAR_HEIGHT = 2;
|
|
2495
|
-
const getBars = _ref => {
|
|
2496
|
-
let {
|
|
2497
|
-
groups,
|
|
2498
|
-
barWidth
|
|
2499
|
-
} = _ref;
|
|
2500
|
-
return groups.selectAll('rect').data(item => item).join('rect').attr('x', item => item.x).attr('y', item => item.y).attr('width', barWidth).attr('height', item => item.value === null ? 0 : Math.max(item.height, MIN_BAR_HEIGHT)).style('fill', item => item.color);
|
|
2501
|
-
};
|
|
2502
|
-
|
|
2503
|
-
const MIN_BAR_HEIGHT$1 = 2;
|
|
2504
|
-
const draw$4 = (node, props) => {
|
|
2505
|
-
const {
|
|
2506
|
-
data,
|
|
2507
|
-
lineData = [],
|
|
2508
|
-
markers = [],
|
|
2509
|
-
barWidth: barWidthProp,
|
|
2510
|
-
barPadding,
|
|
2511
|
-
colors,
|
|
2512
|
-
margin,
|
|
2513
|
-
xAxisPadding,
|
|
2514
|
-
yAxisPadding,
|
|
2515
|
-
drawGridY,
|
|
2516
|
-
drawGridX,
|
|
2517
|
-
customYScale,
|
|
2518
|
-
customXScale,
|
|
2519
|
-
customYAxisLeft,
|
|
2520
|
-
customXAxisBottom,
|
|
2521
|
-
customYAxis,
|
|
2522
|
-
customXAxis,
|
|
2523
|
-
customBars,
|
|
2524
|
-
customize,
|
|
2525
|
-
dynamicTooltipEnable,
|
|
2526
|
-
hideTooltipGroupName,
|
|
2527
|
-
renderTooltip,
|
|
2528
|
-
labelPosition,
|
|
2529
|
-
renderLabel,
|
|
2530
|
-
tooltipY,
|
|
2531
|
-
tooltipBind,
|
|
2532
|
-
stackedLine,
|
|
2533
|
-
curve,
|
|
2534
|
-
formatTooltipValue,
|
|
2535
|
-
formatTooltipName,
|
|
2536
|
-
sectionPadding,
|
|
2537
|
-
minValuesLine,
|
|
2538
|
-
tooltipYDomain,
|
|
2539
|
-
marshalledMap,
|
|
2540
|
-
minValue,
|
|
2541
|
-
maxValue,
|
|
2542
|
-
minDomainValue,
|
|
2543
|
-
maxDomainValue,
|
|
2544
|
-
drawBars,
|
|
2545
|
-
setTooltipPosition,
|
|
2546
|
-
onLabelItem,
|
|
2547
|
-
isBarTooltip,
|
|
2548
|
-
xScaleItemWidth,
|
|
2549
|
-
tooltipRoot,
|
|
2550
|
-
tooltipClassName,
|
|
2551
|
-
onBarClick,
|
|
2552
|
-
onBarHover
|
|
2553
|
-
} = props;
|
|
2554
|
-
if (node !== null && data.length) {
|
|
2555
|
-
const marginTop = margin ? margin.top : 0;
|
|
2556
|
-
const marginRight = margin ? margin.right : 0;
|
|
2557
|
-
const marginBottom = margin ? margin.bottom : 0;
|
|
2558
|
-
const marginLeft = margin ? margin.left : 0;
|
|
2559
|
-
const defaultBarWidth = 12;
|
|
2560
|
-
const {
|
|
2561
|
-
width: nodeWidth
|
|
2562
|
-
} = node.getBoundingClientRect();
|
|
2563
|
-
const width = props.width || nodeWidth;
|
|
2564
|
-
const height = props.height || 0;
|
|
2565
|
-
const barDomain = getDomain({
|
|
2566
|
-
data,
|
|
2567
|
-
minDomainValue,
|
|
2568
|
-
maxDomainValue
|
|
2569
|
-
});
|
|
2570
|
-
const min = typeof minValue === 'number' ? minValue : Math.min(d3.min(lineData, _ref => {
|
|
2571
|
-
let {
|
|
2572
|
-
values
|
|
2573
|
-
} = _ref;
|
|
2574
|
-
return d3.min(values);
|
|
2575
|
-
}) || Number.POSITIVE_INFINITY, barDomain.min || 0);
|
|
2576
|
-
const max = typeof maxValue === 'number' ? maxValue : Math.max(d3.max(lineData, _ref2 => {
|
|
2577
|
-
let {
|
|
2578
|
-
values
|
|
2579
|
-
} = _ref2;
|
|
2580
|
-
return d3.max(values);
|
|
2581
|
-
}) || Number.NEGATIVE_INFINITY, barDomain.max);
|
|
2582
|
-
const svg = appendSvg(node, width, height || 0);
|
|
2583
|
-
const yTicksCountDefault = 6;
|
|
2584
|
-
const labels = data.map(item => item.groupName);
|
|
2585
|
-
let barWidth = barWidthProp || defaultBarWidth;
|
|
2586
|
-
const yScale = d3.scaleLinear().domain([min, max]).range([height - marginTop - marginBottom - (xAxisPadding || 0), marginTop]).nice();
|
|
2587
|
-
customYScale && customYScale(yScale);
|
|
2588
|
-
const yTicks = yScale.ticks();
|
|
2589
|
-
const yAxisLeft = d3.axisLeft(yScale).ticks(yTicksCountDefault);
|
|
2590
|
-
customYAxisLeft && customYAxisLeft(yAxisLeft);
|
|
2591
|
-
const yTicksCount = yAxisLeft.tickArguments()[0];
|
|
2592
|
-
const yAxis = svg.append('g').attr('class', barChartClassNames.barChartYAxis).call(yAxisLeft);
|
|
2593
|
-
yAxis.selectAll('.tick').attr('class', value => {
|
|
2594
|
-
return value === 0 ? "tick " + barChartClassNames.barChartYAxisZeroTick : 'tick';
|
|
2595
|
-
});
|
|
2596
|
-
customYAxis && customYAxis(yAxis);
|
|
2597
|
-
const {
|
|
2598
|
-
width: yAxisWidth
|
|
2599
|
-
} = computeDimensions(yAxis);
|
|
2600
|
-
const range = [marginLeft + yAxisWidth + (yAxisPadding || 0), width - marginRight];
|
|
2601
|
-
const xScale = d3.scaleBand().domain(d3.range(data.length)).range(range);
|
|
2602
|
-
barWidth = resizeBarWidth({
|
|
2603
|
-
data,
|
|
2604
|
-
sectionPadding,
|
|
2605
|
-
range,
|
|
2606
|
-
barWidth,
|
|
2607
|
-
barPadding
|
|
2608
|
-
});
|
|
2609
|
-
customXScale && customXScale(xScale);
|
|
2610
|
-
const [x1, x2] = xScale.range();
|
|
2611
|
-
const xAxisBottom = d3.axisBottom(xScale).tickFormat(value => labels[Number(value)]);
|
|
2612
|
-
if (typeof xScaleItemWidth === 'number') {
|
|
2613
|
-
xAxisBottom.tickValues(xScale.domain().filter((_, i, array) => {
|
|
2614
|
-
const chartWidth = x2 - x1;
|
|
2615
|
-
const ticks = Math.round(chartWidth / xScaleItemWidth);
|
|
2616
|
-
const length = array.length;
|
|
2617
|
-
const divider = Math.round(length / ticks);
|
|
2618
|
-
return !(i % divider);
|
|
2619
|
-
})).tickSizeOuter(0);
|
|
2620
|
-
}
|
|
2621
|
-
customXAxisBottom && customXAxisBottom(xAxisBottom, {
|
|
2622
|
-
node,
|
|
2623
|
-
labels
|
|
2624
|
-
});
|
|
2625
|
-
const xAxis = svg.append('g').call(xAxisBottom).attr('class', barChartClassNames.barChartXAxis);
|
|
2626
|
-
customXAxis && customXAxis(xAxis);
|
|
2627
|
-
const marshalled = marshaling({
|
|
2628
|
-
data,
|
|
2629
|
-
yScale,
|
|
2630
|
-
xScale,
|
|
2631
|
-
barWidth,
|
|
2632
|
-
barPadding: typeof barPadding === 'number' ? barPadding : 0,
|
|
2633
|
-
colors,
|
|
2634
|
-
marginTop
|
|
2635
|
-
});
|
|
2636
|
-
const marshalledData = marshalledMap ? marshalledMap(marshalled) : marshalled;
|
|
2637
|
-
yAxis.attr('transform', "translate( " + (marginLeft + yAxisWidth) + ", 0)");
|
|
2638
|
-
drawGrid$1({
|
|
2639
|
-
svg,
|
|
2640
|
-
yScale,
|
|
2641
|
-
xScale,
|
|
2642
|
-
yTicksCount,
|
|
2643
|
-
drawGridY,
|
|
2644
|
-
drawGridX
|
|
2645
|
-
});
|
|
2646
|
-
xAxis.attr('transform', "translate(0, " + (yScale(yTicks[0]) + (xAxisPadding || 0)) + ")");
|
|
2647
|
-
const maskId = "height-limit-mask-" + lodash.uniqueId();
|
|
2648
|
-
svg.append('defs').append('mask').attr('id', maskId).append('rect').attr('width', '100%').attr('height', height - marginBottom + MIN_BAR_HEIGHT$1).attr('fill', 'white');
|
|
2649
|
-
const gSvg = svg.append('g').attr('class', barChartClassNames.barChartBarGlobal).attr('mask', "url(#" + maskId + ")");
|
|
2650
|
-
const groups = gSvg.selectAll('g').data(marshalledData).enter().append('g').attr('transform', (_, i) => "translate(" + Math.round(xScale(i)) + "," + -(marginTop || 0) + ")");
|
|
2651
|
-
const bars = drawBars ? drawBars({
|
|
2652
|
-
groups,
|
|
2653
|
-
yScale,
|
|
2654
|
-
marshalledData,
|
|
2655
|
-
barWidth
|
|
2656
|
-
}) : getBars({
|
|
2657
|
-
groups,
|
|
2658
|
-
barWidth
|
|
2659
|
-
});
|
|
2660
|
-
markers.forEach(marker => {
|
|
2661
|
-
if (!marker) {
|
|
2662
|
-
return;
|
|
2663
|
-
}
|
|
2664
|
-
if (marker.horizontal) {
|
|
2665
|
-
if (marker.line) {
|
|
2666
|
-
svg.append('line').style("stroke", marker.lineColor || marker.color || "inherit").style("stroke-width", 1).style("stroke-dasharray", "5, 3").attr("x1", marginLeft + yAxisWidth).attr("y1", yScale(marker.value) + 1).attr("x2", width).attr("y2", yScale(marker.value) + 1);
|
|
2667
|
-
}
|
|
2668
|
-
svg.append("text").attr("y", yScale(marker.value) + 1).attr("x", marginLeft + yAxisWidth).attr('text-anchor', 'middle').attr("class", ["marker", marker.className].filter(Boolean).join(" ")).style("fill", (marker == null ? void 0 : marker.color) || "inherit").text(marker.label);
|
|
2669
|
-
return;
|
|
2670
|
-
}
|
|
2671
|
-
if (marker.line) {
|
|
2672
|
-
svg.append('line').style("stroke", marker.lineColor || marker.color || "inherit").style("stroke-width", 1).style("stroke-dasharray", "5, 3").attr("x1", width / data.length * marker.value + 1).attr("y1", 0).attr("x2", width / data.length * marker.value + 1).attr("y2", height - marginTop - marginBottom + 8);
|
|
2673
|
-
}
|
|
2674
|
-
svg.append("text").attr("y", height - 2).attr("x", width / data.length * marker.value + 1).attr('text-anchor', marker.align === 'right' ? 'end' : marker.align === 'left' ? 'start' : 'middle').attr("class", ["marker", marker.className].filter(Boolean).join(" ")).style("fill", (marker == null ? void 0 : marker.color) || "inherit").text(marker.label);
|
|
2675
|
-
});
|
|
2676
|
-
let lines = null;
|
|
2677
|
-
if (Array.isArray(lineData) && lineData.length > 0) {
|
|
2678
|
-
lines = drawLines({
|
|
2679
|
-
svg,
|
|
2680
|
-
lineData,
|
|
2681
|
-
xScale,
|
|
2682
|
-
yScale,
|
|
2683
|
-
min: typeof minValuesLine === 'number' ? minValuesLine : min,
|
|
2684
|
-
stackedLine,
|
|
2685
|
-
curve
|
|
2686
|
-
});
|
|
2687
|
-
}
|
|
2688
|
-
customBars && customBars({
|
|
2689
|
-
bars,
|
|
2690
|
-
yScale,
|
|
2691
|
-
lines,
|
|
2692
|
-
marshalledData,
|
|
2693
|
-
lineData
|
|
2694
|
-
});
|
|
2695
|
-
if (dynamicTooltipEnable || labelPosition) {
|
|
2696
|
-
drawTooltip$2({
|
|
2697
|
-
svg,
|
|
2698
|
-
node,
|
|
2699
|
-
xScale,
|
|
2700
|
-
yScale,
|
|
2701
|
-
marshalledData,
|
|
2702
|
-
data,
|
|
2703
|
-
lineData,
|
|
2704
|
-
renderTooltip,
|
|
2705
|
-
labelPosition,
|
|
2706
|
-
marginTop,
|
|
2707
|
-
renderLabel,
|
|
2708
|
-
barWidth,
|
|
2709
|
-
barPadding,
|
|
2710
|
-
dynamicTooltipEnable,
|
|
2711
|
-
hideTooltipGroupName,
|
|
2712
|
-
tooltipY,
|
|
2713
|
-
tooltipBind,
|
|
2714
|
-
formatTooltipValue,
|
|
2715
|
-
formatTooltipName,
|
|
2716
|
-
tooltipYDomain,
|
|
2717
|
-
setTooltipPosition,
|
|
2718
|
-
onLabelItem,
|
|
2719
|
-
isBarTooltip,
|
|
2720
|
-
bars: groups,
|
|
2721
|
-
tooltipRoot,
|
|
2722
|
-
tooltipClassName,
|
|
2723
|
-
onBarClick,
|
|
2724
|
-
onBarHover
|
|
2725
|
-
});
|
|
2726
|
-
}
|
|
2727
|
-
customize && customize({
|
|
2728
|
-
svg,
|
|
2729
|
-
marshalledData,
|
|
2730
|
-
yScale,
|
|
2731
|
-
xScale,
|
|
2732
|
-
lineData
|
|
2733
|
-
});
|
|
2734
|
-
}
|
|
2735
|
-
};
|
|
2736
|
-
|
|
2737
|
-
const BarChart = props => {
|
|
2738
|
-
const {
|
|
2739
|
-
className,
|
|
2740
|
-
style,
|
|
2741
|
-
children,
|
|
2742
|
-
selectable
|
|
2743
|
-
} = props;
|
|
2744
|
-
const [ref, node] = useNode();
|
|
2745
|
-
React.useEffect(() => {
|
|
2746
|
-
node && draw$4(node, props);
|
|
2747
|
-
}, [node, props]);
|
|
2748
|
-
const onDraw = () => draw$4(node, props);
|
|
2749
|
-
useResize(props.width, onDraw);
|
|
2750
|
-
useSelection(selectable ? node : null, props);
|
|
2751
|
-
return React__default.createElement("div", {
|
|
2752
|
-
className: className,
|
|
2753
|
-
style: style
|
|
2754
|
-
}, React__default.createElement(TooltipStyles$1, null), React__default.createElement(SvgWrapper$4, {
|
|
2755
|
-
ref: ref,
|
|
2756
|
-
selectable: selectable
|
|
2757
|
-
}, children));
|
|
2758
|
-
};
|
|
2759
|
-
BarChart.defaultProps = {
|
|
2760
|
-
data: [],
|
|
2761
|
-
colors: {},
|
|
2762
|
-
margin: {
|
|
2763
|
-
top: 10,
|
|
2764
|
-
right: 10,
|
|
2765
|
-
bottom: 10,
|
|
2766
|
-
left: 0
|
|
2767
|
-
},
|
|
2768
|
-
barWidth: 12,
|
|
2769
|
-
barPadding: 0,
|
|
2770
|
-
height: 320,
|
|
2771
|
-
yAxisPadding: 0,
|
|
2772
|
-
xAxisPadding: 0,
|
|
2773
|
-
tooltipBind: true,
|
|
2774
|
-
sectionPadding: 1
|
|
2775
|
-
};
|
|
2776
|
-
|
|
2777
|
-
const _excluded$6 = ["value"];
|
|
2778
|
-
const hundred = 100;
|
|
2779
|
-
const useMarshaling = _ref => {
|
|
2780
|
-
let {
|
|
2781
|
-
data,
|
|
2782
|
-
fullExtent,
|
|
2783
|
-
maxValue,
|
|
2784
|
-
labels
|
|
2785
|
-
} = _ref;
|
|
2786
|
-
return React.useMemo(() => {
|
|
2787
|
-
const fullMax = d3.max(data, item => d3.sum(item, _ref2 => {
|
|
2788
|
-
let {
|
|
2789
|
-
value
|
|
2790
|
-
} = _ref2;
|
|
2791
|
-
return value;
|
|
2792
|
-
}));
|
|
2793
|
-
const scaleLinear = d3.scaleLinear().domain([0, typeof maxValue === 'number' ? maxValue : fullMax]).range([0, hundred]);
|
|
2794
|
-
return {
|
|
2795
|
-
fullMax,
|
|
2796
|
-
data: data.map((item, index) => {
|
|
2797
|
-
if (!fullExtent) {
|
|
2798
|
-
scaleLinear.domain([0, typeof maxValue === 'number' ? maxValue : d3.sum(item, _ref3 => {
|
|
2799
|
-
let {
|
|
2800
|
-
value
|
|
2801
|
-
} = _ref3;
|
|
2802
|
-
return value;
|
|
2803
|
-
})]);
|
|
2804
|
-
}
|
|
2805
|
-
return item.map(_ref4 => {
|
|
2806
|
-
let {
|
|
2807
|
-
value
|
|
2808
|
-
} = _ref4,
|
|
2809
|
-
rest = _objectWithoutPropertiesLoose(_ref4, _excluded$6);
|
|
2810
|
-
return _extends({}, rest, {
|
|
2811
|
-
value,
|
|
2812
|
-
width: scaleLinear(value),
|
|
2813
|
-
groupName: labels ? labels[index] : ''
|
|
2814
|
-
});
|
|
2815
|
-
});
|
|
2816
|
-
})
|
|
2817
|
-
};
|
|
2818
|
-
}, [data, fullExtent, maxValue, labels]);
|
|
2819
|
-
};
|
|
2820
|
-
|
|
2821
|
-
var _templateObject$b, _templateObject2$5, _templateObject3$2, _templateObject4$2, _templateObject5$2, _templateObject6$2, _templateObject7$1, _templateObject8$1;
|
|
2822
|
-
const horizontalBarChartClassNames = {
|
|
2823
|
-
horizontalBarChartButtonTd: "horizontalBarChartButtonTd",
|
|
2824
|
-
horizontalBarChartLabelTd: "horizontalBarChartLabelTd",
|
|
2825
|
-
horizontalBarChartLabelCell: "horizontalBarChartLabelCell",
|
|
2826
|
-
horizontalBarChartBarTd: "horizontalBarChartBarTd",
|
|
2827
|
-
horizontalBarChartBarFlex: "horizontalBarChartBarFlex",
|
|
2828
|
-
horizontalBarChartBar: "horizontalBarChartBar",
|
|
2829
|
-
horizontalBarChartBarFirst: "horizontalBarChartBarFirst",
|
|
2830
|
-
horizontalBarChartBarLast: "horizontalBarChartBarLast",
|
|
2831
|
-
horizontalBarChartBarOnly: "horizontalBarChartBarOnly",
|
|
2832
|
-
horizontalBarChartTooltipFlex: "horizontalBarChartTooltipFlex",
|
|
2833
|
-
horizontalBarChartStackWrapper: "horizontalBarChartStackWrapper",
|
|
2834
|
-
horizontalBarChartTooltipContainer: "horizontalBarChartTooltipContainer",
|
|
2835
|
-
horizontalBarChartStackSumContainer: "horizontalBarChartStackSumContainer",
|
|
2836
|
-
horizontalBarChartStackSum: "horizontalBarChartStackSum",
|
|
2837
|
-
horizontalBarChartXScaleTd: "horizontalBarChartXScaleTd",
|
|
2838
|
-
horizontalBarChartXScaleTicks: "horizontalBarChartXScaleTicks",
|
|
2839
|
-
horizontalBarChartXScaleTick: "horizontalBarChartXScaleTick",
|
|
2840
|
-
horizontalBarChartTooltipItem: "horizontalBarChartTooltipItem",
|
|
2841
|
-
horizontalBarChartTooltipName: "horizontalBarChartTooltipName",
|
|
2842
|
-
horizontalBarChartTooltipValue: "horizontalBarChartTooltipValue"
|
|
2843
|
-
};
|
|
2844
|
-
const Table = /*#__PURE__*/styled__default.table(_templateObject$b || (_templateObject$b = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n"])));
|
|
2845
|
-
const LabelCell = /*#__PURE__*/styled__default.div(_templateObject2$5 || (_templateObject2$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n text-align: right;\n"])));
|
|
2846
|
-
const BarFlex = /*#__PURE__*/styled__default.div(_templateObject3$2 || (_templateObject3$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n display: flex;\n height: 1rem;\n"])));
|
|
2847
|
-
const BarsTd = /*#__PURE__*/styled__default.td(_templateObject4$2 || (_templateObject4$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n position: relative;\n vertical-align: middle;\n"])));
|
|
2848
|
-
const TooltipFlex$1 = /*#__PURE__*/styled__default(TooltipFlex)(_templateObject5$2 || (_templateObject5$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n top: 0;\n left: 50%;\n transform: translate(-50%, -50%);\n will-change: left, top;\n"])));
|
|
2849
|
-
const StackSumContainer = /*#__PURE__*/styled__default.div(_templateObject6$2 || (_templateObject6$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n"])));
|
|
2850
|
-
const StackSum = /*#__PURE__*/styled__default.div(_templateObject7$1 || (_templateObject7$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n white-space: nowrap;\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(0, -50%);\n"])));
|
|
2851
|
-
const StackWrapper = /*#__PURE__*/styled__default.div(_templateObject8$1 || (_templateObject8$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n top: 0;\n display: flex;\n justify-content: flex-start;\n height: 100%;\n"])));
|
|
2852
|
-
|
|
2853
|
-
const Tooltip = _ref => {
|
|
2854
|
-
let {
|
|
2855
|
-
renderTooltip,
|
|
2856
|
-
bars,
|
|
2857
|
-
style,
|
|
2858
|
-
className
|
|
2859
|
-
} = _ref;
|
|
2860
|
-
const format = d3.format(',');
|
|
2861
|
-
return React__default.createElement(TooltipFlex$1, {
|
|
2862
|
-
className: horizontalBarChartClassNames.horizontalBarChartTooltipFlex + " " + (className || ''),
|
|
2863
|
-
style: style
|
|
2864
|
-
}, React__default.createElement(TooltipContainer, {
|
|
2865
|
-
className: horizontalBarChartClassNames.horizontalBarChartTooltipContainer
|
|
2866
|
-
}, renderTooltip ? renderTooltip(bars) : bars.map((_ref2, index) => {
|
|
2867
|
-
let {
|
|
2868
|
-
color,
|
|
2869
|
-
name,
|
|
2870
|
-
value,
|
|
2871
|
-
groupName
|
|
2872
|
-
} = _ref2;
|
|
2873
|
-
return React__default.createElement(TooltipItem, {
|
|
2874
|
-
key: (name || '') + "-" + index + "-" + groupName,
|
|
2875
|
-
className: horizontalBarChartClassNames.horizontalBarChartTooltipItem
|
|
2876
|
-
}, color && React__default.createElement(ColorBox, {
|
|
2877
|
-
style: {
|
|
2878
|
-
backgroundColor: color
|
|
2879
|
-
}
|
|
2880
|
-
}), name && React__default.createElement(Name$1, {
|
|
2881
|
-
className: horizontalBarChartClassNames.horizontalBarChartTooltipName
|
|
2882
|
-
}, name), React__default.createElement(Value, {
|
|
2883
|
-
className: horizontalBarChartClassNames.horizontalBarChartTooltipValue
|
|
2884
|
-
}, format(value)));
|
|
2885
|
-
})));
|
|
2886
|
-
};
|
|
2887
|
-
|
|
2888
|
-
const rootElement = /*#__PURE__*/document.createElement('div');
|
|
2889
|
-
const useTooltip = _ref => {
|
|
2890
|
-
let {
|
|
2891
|
-
renderTooltip,
|
|
2892
|
-
tooltipBind,
|
|
2893
|
-
tooltipStyle,
|
|
2894
|
-
tooltipRoot,
|
|
2895
|
-
tooltipClassName,
|
|
2896
|
-
hideTooltip
|
|
2897
|
-
} = _ref;
|
|
2898
|
-
React.useEffect(() => {
|
|
2899
|
-
const container = tooltipRoot || document.querySelector('body');
|
|
2900
|
-
container && container.appendChild(rootElement);
|
|
2901
|
-
return () => {
|
|
2902
|
-
reactDom.unmountComponentAtNode(rootElement);
|
|
2903
|
-
};
|
|
2904
|
-
}, [tooltipRoot]);
|
|
2905
|
-
const onMouseMove = React.useCallback((event, bars) => {
|
|
2906
|
-
let [x, y] = d3.pointer(event, document);
|
|
2907
|
-
if (!tooltipBind && 'getBoundingClientRect' in event.target) {
|
|
2908
|
-
const {
|
|
2909
|
-
width,
|
|
2910
|
-
height
|
|
2911
|
-
} = event.target.getBoundingClientRect();
|
|
2912
|
-
const [barX, barY] = d3.pointer(event, event.target);
|
|
2913
|
-
x = x - barX + width / 2;
|
|
2914
|
-
y = y - barY + height / 2;
|
|
2915
|
-
}
|
|
2916
|
-
if (rootElement) {
|
|
2917
|
-
rootElement.style.visibility = 'visible';
|
|
2918
|
-
}
|
|
2919
|
-
reactDom.render(React__default.createElement(Tooltip, {
|
|
2920
|
-
style: _extends({
|
|
2921
|
-
left: x,
|
|
2922
|
-
top: y
|
|
2923
|
-
}, tooltipStyle),
|
|
2924
|
-
bars: bars,
|
|
2925
|
-
renderTooltip: renderTooltip,
|
|
2926
|
-
className: tooltipClassName
|
|
2927
|
-
}), rootElement);
|
|
2928
|
-
}, [tooltipClassName, tooltipStyle, renderTooltip, tooltipBind]);
|
|
2929
|
-
const onMouseLeave = React.useCallback(() => {
|
|
2930
|
-
if (rootElement) {
|
|
2931
|
-
rootElement.style.visibility = 'hidden';
|
|
2932
|
-
hideTooltip && hideTooltip();
|
|
2933
|
-
}
|
|
2934
|
-
}, [hideTooltip]);
|
|
2935
|
-
return [onMouseMove, onMouseLeave];
|
|
2936
|
-
};
|
|
2937
|
-
|
|
2938
|
-
const _excluded$7 = ["item", "mouseMove", "mouseLeave", "tooltipBind"];
|
|
2939
|
-
const useStackWrapper = stackedTooltip => {
|
|
2940
|
-
return React.useMemo(() => stackedTooltip ? _ref => {
|
|
2941
|
-
let {
|
|
2942
|
-
item,
|
|
2943
|
-
mouseMove,
|
|
2944
|
-
mouseLeave,
|
|
2945
|
-
tooltipBind
|
|
2946
|
-
} = _ref,
|
|
2947
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded$7);
|
|
2948
|
-
return React__default.createElement(StackWrapper, Object.assign({
|
|
2949
|
-
className: horizontalBarChartClassNames.horizontalBarChartStackWrapper,
|
|
2950
|
-
onMouseOver: event => mouseMove(event, item),
|
|
2951
|
-
onMouseMove: tooltipBind ? event => mouseMove(event, item) : void 0,
|
|
2952
|
-
onMouseOut: mouseLeave
|
|
2953
|
-
}, props));
|
|
2954
|
-
} : _ref2 => {
|
|
2955
|
-
let {
|
|
2956
|
-
children
|
|
2957
|
-
} = _ref2;
|
|
2958
|
-
return React__default.createElement(React.Fragment, null, children);
|
|
2959
|
-
}, [stackedTooltip]);
|
|
2960
|
-
};
|
|
2961
|
-
|
|
2962
|
-
var _templateObject$c;
|
|
2963
|
-
const BarStyled = /*#__PURE__*/styled__default.div(_templateObject$c || (_templateObject$c = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n display: inline-flex;\n height: 100%;\n"])));
|
|
2964
|
-
|
|
2965
|
-
const Bar = _ref => {
|
|
2966
|
-
let {
|
|
2967
|
-
withTooltip,
|
|
2968
|
-
bar,
|
|
2969
|
-
formatNativeTitle,
|
|
2970
|
-
tooltipBind,
|
|
2971
|
-
mouseMove,
|
|
2972
|
-
mouseLeave,
|
|
2973
|
-
pointerEventsNone,
|
|
2974
|
-
isFirstChild,
|
|
2975
|
-
isLastChild,
|
|
2976
|
-
isOnlyChild
|
|
2977
|
-
} = _ref;
|
|
2978
|
-
const {
|
|
2979
|
-
color,
|
|
2980
|
-
width
|
|
2981
|
-
} = bar;
|
|
2982
|
-
const ceiledWidth = Math.abs(width);
|
|
2983
|
-
const onMouseMove = withTooltip ? event => mouseMove(event, [bar]) : void 0;
|
|
2984
|
-
const onMouseLeave = withTooltip ? () => mouseLeave() : void 0;
|
|
2985
|
-
return React__default.createElement(BarStyled, {
|
|
2986
|
-
className: horizontalBarChartClassNames.horizontalBarChartBar + " " + (isFirstChild ? horizontalBarChartClassNames.horizontalBarChartBarFirst : '') + " " + (isLastChild ? horizontalBarChartClassNames.horizontalBarChartBarLast : '') + " " + (isOnlyChild ? horizontalBarChartClassNames.horizontalBarChartBarOnly : ''),
|
|
2987
|
-
style: {
|
|
2988
|
-
width: ceiledWidth + "%",
|
|
2989
|
-
backgroundColor: color,
|
|
2990
|
-
pointerEvents: pointerEventsNone ? 'none' : 'auto'
|
|
2991
|
-
},
|
|
2992
|
-
title: formatNativeTitle ? formatNativeTitle(bar) : '',
|
|
2993
|
-
onMouseOver: onMouseMove,
|
|
2994
|
-
onMouseMove: tooltipBind ? onMouseMove : void 0,
|
|
2995
|
-
onMouseOut: onMouseLeave
|
|
2996
|
-
});
|
|
2997
|
-
};
|
|
2998
|
-
|
|
2999
|
-
const hundred$1 = 100;
|
|
3000
|
-
const useScale = _ref => {
|
|
3001
|
-
let {
|
|
3002
|
-
maxValue,
|
|
3003
|
-
scaleTicks,
|
|
3004
|
-
scaleDomain
|
|
3005
|
-
} = _ref;
|
|
3006
|
-
return React.useMemo(() => {
|
|
3007
|
-
const scaleLinear = d3.scaleLinear().domain([0, maxValue]).range([0, hundred$1]);
|
|
3008
|
-
const ticks = scaleLinear.ticks(scaleTicks);
|
|
3009
|
-
return (scaleDomain || ticks).map(value => ({
|
|
3010
|
-
value,
|
|
3011
|
-
x: scaleLinear(value)
|
|
3012
|
-
}));
|
|
3013
|
-
}, [maxValue, scaleTicks, scaleDomain]);
|
|
3014
|
-
};
|
|
3015
|
-
|
|
3016
|
-
var _templateObject$d, _templateObject2$6, _templateObject3$3;
|
|
3017
|
-
const TickTd = /*#__PURE__*/styled__default.td(_templateObject$d || (_templateObject$d = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n"])));
|
|
3018
|
-
const Ticks = /*#__PURE__*/styled__default.div(_templateObject2$6 || (_templateObject2$6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: relative;\n height: 1rem;\n"])));
|
|
3019
|
-
const Tick = /*#__PURE__*/styled__default.div(_templateObject3$3 || (_templateObject3$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n white-space: nowrap;\n width: 0;\n height: 0;\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n display: flex;\n align-items: center;\n justify-content: center;\n"])));
|
|
3020
|
-
|
|
3021
|
-
const XScale = _ref => {
|
|
3022
|
-
let {
|
|
3023
|
-
maxValue,
|
|
3024
|
-
scaleTicks,
|
|
3025
|
-
renderTicks,
|
|
3026
|
-
scaleDomain
|
|
3027
|
-
} = _ref;
|
|
3028
|
-
const range = useScale({
|
|
3029
|
-
maxValue,
|
|
3030
|
-
scaleTicks,
|
|
3031
|
-
scaleDomain
|
|
3032
|
-
});
|
|
3033
|
-
const format = d3.format(',');
|
|
3034
|
-
return React__default.createElement("tr", null, React__default.createElement("td", null), React__default.createElement(TickTd, {
|
|
3035
|
-
className: horizontalBarChartClassNames.horizontalBarChartXScaleTd
|
|
3036
|
-
}, React__default.createElement(Ticks, {
|
|
3037
|
-
className: horizontalBarChartClassNames.horizontalBarChartXScaleTicks
|
|
3038
|
-
}, range.map((tick, index, ticks) => {
|
|
3039
|
-
const {
|
|
3040
|
-
value,
|
|
3041
|
-
x
|
|
3042
|
-
} = tick;
|
|
3043
|
-
return React__default.createElement(Tick, {
|
|
3044
|
-
key: value,
|
|
3045
|
-
className: horizontalBarChartClassNames.horizontalBarChartXScaleTick,
|
|
3046
|
-
style: {
|
|
3047
|
-
left: x + "%",
|
|
3048
|
-
justifyContent: index === 0 ? 'flex-start' : index === ticks.length - 1 ? 'flex-end' : ''
|
|
3049
|
-
}
|
|
3050
|
-
}, renderTicks ? renderTicks(tick) : format(value));
|
|
3051
|
-
}))));
|
|
3052
|
-
};
|
|
3053
|
-
|
|
3054
|
-
const HorizontalBarChart = _ref => {
|
|
3055
|
-
let {
|
|
3056
|
-
data,
|
|
3057
|
-
className,
|
|
3058
|
-
style,
|
|
3059
|
-
children,
|
|
3060
|
-
labels,
|
|
3061
|
-
fullExtent,
|
|
3062
|
-
maxValue,
|
|
3063
|
-
formatNativeTitle,
|
|
3064
|
-
renderTooltip,
|
|
3065
|
-
withTooltip,
|
|
3066
|
-
withStackSum,
|
|
3067
|
-
tooltipBind,
|
|
3068
|
-
scaleTicks,
|
|
3069
|
-
renderTicks,
|
|
3070
|
-
renderButton,
|
|
3071
|
-
tooltipStyle,
|
|
3072
|
-
tooltipClassName,
|
|
3073
|
-
scaleDomain,
|
|
3074
|
-
renderDataTable,
|
|
3075
|
-
thead,
|
|
3076
|
-
withoutXScale,
|
|
3077
|
-
stackedTooltip,
|
|
3078
|
-
fullChartTooltip,
|
|
3079
|
-
hideTooltip
|
|
3080
|
-
} = _ref;
|
|
3081
|
-
const {
|
|
3082
|
-
fullMax,
|
|
3083
|
-
data: marshalingData
|
|
3084
|
-
} = useMarshaling({
|
|
3085
|
-
data,
|
|
3086
|
-
fullExtent,
|
|
3087
|
-
maxValue,
|
|
3088
|
-
labels
|
|
3089
|
-
});
|
|
3090
|
-
const [mouseMove, mouseLeave] = useTooltip({
|
|
3091
|
-
renderTooltip,
|
|
3092
|
-
tooltipBind,
|
|
3093
|
-
tooltipStyle,
|
|
3094
|
-
tooltipClassName,
|
|
3095
|
-
hideTooltip
|
|
3096
|
-
});
|
|
3097
|
-
const Stack = useStackWrapper(stackedTooltip);
|
|
3098
|
-
return React__default.createElement(Table, {
|
|
3099
|
-
className: className,
|
|
3100
|
-
style: style,
|
|
3101
|
-
onMouseOver: fullChartTooltip ? event => mouseMove(event, marshalingData.flat()) : void 0,
|
|
3102
|
-
onMouseMove: fullChartTooltip ? event => mouseMove(event, marshalingData.flat()) : void 0,
|
|
3103
|
-
onMouseOut: fullChartTooltip ? mouseLeave : void 0
|
|
3104
|
-
}, thead, React__default.createElement("tbody", null, marshalingData.map((item, rowIndex) => {
|
|
3105
|
-
const stackSum = (withStackSum || renderDataTable) && d3.sum(item, _ref2 => {
|
|
3106
|
-
let {
|
|
3107
|
-
value
|
|
3108
|
-
} = _ref2;
|
|
3109
|
-
return value;
|
|
3110
|
-
});
|
|
3111
|
-
const sumWidth = d3.sum(item, _ref3 => {
|
|
3112
|
-
let {
|
|
3113
|
-
width
|
|
3114
|
-
} = _ref3;
|
|
3115
|
-
return width;
|
|
3116
|
-
});
|
|
3117
|
-
return React__default.createElement("tr", {
|
|
3118
|
-
key: "row-" + rowIndex
|
|
3119
|
-
}, typeof renderButton === "function" && React__default.createElement("td", {
|
|
3120
|
-
className: horizontalBarChartClassNames.horizontalBarChartButtonTd
|
|
3121
|
-
}, renderButton(item, rowIndex)), React__default.createElement("td", {
|
|
3122
|
-
className: horizontalBarChartClassNames.horizontalBarChartLabelTd
|
|
3123
|
-
}, labels && labels[rowIndex] && React__default.createElement(LabelCell, {
|
|
3124
|
-
className: horizontalBarChartClassNames.horizontalBarChartLabelCell
|
|
3125
|
-
}, labels[rowIndex])), React__default.createElement(BarsTd, {
|
|
3126
|
-
className: horizontalBarChartClassNames.horizontalBarChartBarTd,
|
|
3127
|
-
style: {
|
|
3128
|
-
pointerEvents: fullChartTooltip ? "none" : "auto"
|
|
3129
|
-
}
|
|
3130
|
-
}, React__default.createElement(BarFlex, {
|
|
3131
|
-
className: horizontalBarChartClassNames.horizontalBarChartBarFlex,
|
|
3132
|
-
style: {
|
|
3133
|
-
pointerEvents: fullChartTooltip ? "none" : "auto"
|
|
3134
|
-
}
|
|
3135
|
-
}, React__default.createElement(Stack, {
|
|
3136
|
-
style: stackedTooltip ? {
|
|
3137
|
-
width: sumWidth + "%"
|
|
3138
|
-
} : void 0,
|
|
3139
|
-
item: item,
|
|
3140
|
-
tooltipBind: tooltipBind,
|
|
3141
|
-
mouseMove: mouseMove,
|
|
3142
|
-
mouseLeave: mouseLeave
|
|
3143
|
-
}), item.map((bar, barIndex, array) => bar.value !== 0 && React__default.createElement(Bar, {
|
|
3144
|
-
key: "bar-" + (bar.name || "") + "-" + barIndex,
|
|
3145
|
-
formatNativeTitle: formatNativeTitle,
|
|
3146
|
-
bar: bar,
|
|
3147
|
-
tooltipBind: tooltipBind,
|
|
3148
|
-
pointerEventsNone: stackedTooltip || fullChartTooltip,
|
|
3149
|
-
withTooltip: withTooltip && !stackedTooltip,
|
|
3150
|
-
mouseMove: mouseMove,
|
|
3151
|
-
mouseLeave: mouseLeave,
|
|
3152
|
-
isOnlyChild: array.length === 1,
|
|
3153
|
-
isFirstChild: barIndex === 0 && array.length > 1,
|
|
3154
|
-
isLastChild: array.length - 1 === barIndex && array.length > 1
|
|
3155
|
-
})), withStackSum && React__default.createElement(StackSumContainer, {
|
|
3156
|
-
className: horizontalBarChartClassNames.horizontalBarChartStackSumContainer
|
|
3157
|
-
}, React__default.createElement(StackSum, {
|
|
3158
|
-
className: horizontalBarChartClassNames.horizontalBarChartStackSum
|
|
3159
|
-
}, stackSum)))), renderDataTable && renderDataTable(item, stackSum, rowIndex));
|
|
3160
|
-
}), !withoutXScale && React__default.createElement(XScale, {
|
|
3161
|
-
maxValue: typeof maxValue === "number" ? maxValue : fullMax,
|
|
3162
|
-
scaleTicks: scaleTicks,
|
|
3163
|
-
renderTicks: renderTicks,
|
|
3164
|
-
scaleDomain: scaleDomain
|
|
3165
|
-
}), children));
|
|
3166
|
-
};
|
|
3167
|
-
HorizontalBarChart.defaultProps = {
|
|
3168
|
-
fullExtent: true,
|
|
3169
|
-
withTooltip: false,
|
|
3170
|
-
withStackSum: false,
|
|
3171
|
-
tooltipBind: false,
|
|
3172
|
-
scaleTicks: 4,
|
|
3173
|
-
withoutXScale: false
|
|
3174
|
-
};
|
|
3175
|
-
|
|
3176
|
-
const bubbleChartDefaultProps = {
|
|
3177
|
-
height: 280,
|
|
3178
|
-
minSize: 6,
|
|
3179
|
-
maxSize: 30,
|
|
3180
|
-
margin: {
|
|
3181
|
-
top: 10,
|
|
3182
|
-
right: 15,
|
|
3183
|
-
bottom: 10,
|
|
3184
|
-
left: 0
|
|
3185
|
-
},
|
|
3186
|
-
yAxisPadding: 10,
|
|
3187
|
-
xAxisPadding: 10,
|
|
3188
|
-
yScaleLabelPadding: 10
|
|
3189
|
-
};
|
|
3190
|
-
|
|
3191
|
-
var _templateObject$e, _templateObject2$7;
|
|
3192
|
-
const bubbleChartClassNames = {
|
|
3193
|
-
bubbleChartYAxis: "bubbleChartYAxis",
|
|
3194
|
-
bubbleChartYAxisZeroTick: "bubbleChartYAxisZeroTick",
|
|
3195
|
-
bubbleChartXAxis: "bubbleChartXAxis",
|
|
3196
|
-
bubbleChartGridGlobal: "bubbleChartGridGlobal",
|
|
3197
|
-
bubbleChartGridLineX: "bubbleChartGridLineX",
|
|
3198
|
-
bubbleChartGridLineY: "bubbleChartGridLineY",
|
|
3199
|
-
bubbleChartCircle: "bubbleChartCircle",
|
|
3200
|
-
bubbleChartYScaleLabel: "bubbleChartYScaleLabel",
|
|
3201
|
-
bubbleChartTooltip: "bubbleChartTooltip",
|
|
3202
|
-
bubbleChartTooltipContainer: "bubbleChartTooltipContainer",
|
|
3203
|
-
bubbleChartTooltipFlex: "bubbleChartTooltipFlex",
|
|
3204
|
-
bubbleChartTip: "bubbleChartTip"
|
|
3205
|
-
};
|
|
3206
|
-
const SvgWrapper$5 = /*#__PURE__*/styled__default(Wrapper)(_templateObject$e || (_templateObject$e = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", ",\n .", ",\n .", " {\n shape-rendering: crispEdges;\n }\n\n .", ",\n .", " {\n stroke: rgba(149, 149, 149, 0.24);\n }\n\n .", " {\n font-size: 10px;\n }\n"])), bubbleChartClassNames.bubbleChartYAxis, bubbleChartClassNames.bubbleChartXAxis, bubbleChartClassNames.bubbleChartGridGlobal, bubbleChartClassNames.bubbleChartGridLineX, bubbleChartClassNames.bubbleChartGridLineY, bubbleChartClassNames.bubbleChartYScaleLabel);
|
|
3207
|
-
const TooltipStyles$2 = /*#__PURE__*/styled.createGlobalStyle(_templateObject2$7 || (_templateObject2$7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .", " {\n position: absolute;\n transition: opacity 150ms cubic-bezier(0.2, 1, 0.6, 1);\n pointer-events: none;\n z-index: 1;\n }\n"])), bubbleChartClassNames.bubbleChartTooltipContainer);
|
|
3208
|
-
|
|
3209
|
-
const drawGrid$2 = _ref => {
|
|
3210
|
-
let {
|
|
3211
|
-
svg,
|
|
3212
|
-
yScale,
|
|
3213
|
-
xScale,
|
|
3214
|
-
yTicksCount,
|
|
3215
|
-
drawGridX,
|
|
3216
|
-
drawGridY
|
|
3217
|
-
} = _ref;
|
|
3218
|
-
if (!drawGridY && !drawGridX) return;
|
|
3219
|
-
const [min, max] = xScale.domain();
|
|
3220
|
-
const global = svg.append('g').attr('class', bubbleChartClassNames.bubbleChartGridGlobal);
|
|
3221
|
-
const yTicks = yScale.ticks(yTicksCount);
|
|
3222
|
-
if (drawGridX) {
|
|
3223
|
-
global.append('g').selectAll('line').data(yTicks).join('line').attr('class', bubbleChartClassNames.bubbleChartGridLineX).attr('x1', () => xScale(min)).attr('x2', () => xScale(max)).attr('y1', d => Math.round(yScale(d))).attr('y2', d => Math.round(yScale(d)));
|
|
3224
|
-
}
|
|
3225
|
-
if (drawGridY) {
|
|
3226
|
-
global.append('g').selectAll('line').data(xScale.ticks(yTicksCount)).join('line').attr('class', bubbleChartClassNames.bubbleChartGridLineY).attr('x1', d => Math.round(xScale(d))).attr('x2', d => Math.round(xScale(d))).attr('y1', () => Math.round(yScale(yTicks[0]))).attr('y2', () => Math.round(yScale(yTicks[yTicks.length - 1])));
|
|
3227
|
-
}
|
|
3228
|
-
};
|
|
3229
|
-
|
|
3230
|
-
var _templateObject$f;
|
|
3231
|
-
const Tooltip$1 = /*#__PURE__*/styled__default.div(_templateObject$f || (_templateObject$f = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 0;\n height: 0;\n display: flex;\n align-items: flex-end;\n justify-content: center;\n font-size: 12px;\n white-space: nowrap;\n"])));
|
|
3232
|
-
|
|
3233
|
-
const drawTooltip$3 = _ref => {
|
|
3234
|
-
let {
|
|
3235
|
-
bubbles,
|
|
3236
|
-
tooltipRoot,
|
|
3237
|
-
tooltipClassName,
|
|
3238
|
-
renderTooltip
|
|
3239
|
-
} = _ref;
|
|
3240
|
-
const root = tooltipRoot || document.querySelector('body');
|
|
3241
|
-
const format = d3.format(',');
|
|
3242
|
-
let container = d3.select(root).select("." + bubbleChartClassNames.bubbleChartTooltip);
|
|
3243
|
-
if (container.node() === null) {
|
|
3244
|
-
container = d3.select(root).append('div').attr('class', bubbleChartClassNames.bubbleChartTooltip);
|
|
3245
|
-
}
|
|
3246
|
-
let tooltip = container.append('div').attr('class', bubbleChartClassNames.bubbleChartTooltipContainer + " " + (tooltipClassName || '')).style('opacity', '0');
|
|
3247
|
-
bubbles.on('mouseover.tooltip', (event, data) => {
|
|
3248
|
-
const {
|
|
3249
|
-
sizeValue
|
|
3250
|
-
} = data;
|
|
3251
|
-
const circle = event.currentTarget;
|
|
3252
|
-
const {
|
|
3253
|
-
x,
|
|
3254
|
-
y,
|
|
3255
|
-
width
|
|
3256
|
-
} = circle.getBoundingClientRect();
|
|
3257
|
-
const left = window.pageXOffset + x + width / 2;
|
|
3258
|
-
const top = window.pageYOffset + y;
|
|
3259
|
-
tooltip.style('left', left + "px").style('top', top + "px").html(() => {
|
|
3260
|
-
const html = ReactDOMServer.renderToString(React__default.createElement(Tooltip$1, {
|
|
3261
|
-
className: bubbleChartClassNames.bubbleChartTooltipFlex
|
|
3262
|
-
}, React__default.createElement(TooltipContainer, {
|
|
3263
|
-
className: bubbleChartClassNames.bubbleChartTip
|
|
3264
|
-
}, format(sizeValue))));
|
|
3265
|
-
return html;
|
|
3266
|
-
});
|
|
3267
|
-
renderTooltip && renderTooltip({
|
|
3268
|
-
tooltip,
|
|
3269
|
-
data,
|
|
3270
|
-
circle
|
|
3271
|
-
});
|
|
3272
|
-
tooltip.style('opacity', '1');
|
|
3273
|
-
});
|
|
3274
|
-
bubbles.on('mouseout.tooltip', () => {
|
|
3275
|
-
tooltip.style('opacity', '0');
|
|
3276
|
-
});
|
|
3277
|
-
};
|
|
3278
|
-
|
|
3279
|
-
const draw$5 = (node, props) => {
|
|
3280
|
-
const {
|
|
3281
|
-
data,
|
|
3282
|
-
margin,
|
|
3283
|
-
xAxisPadding,
|
|
3284
|
-
yAxisPadding,
|
|
3285
|
-
customYScale,
|
|
3286
|
-
customYAxis,
|
|
3287
|
-
customXScale,
|
|
3288
|
-
customXAxis,
|
|
3289
|
-
minSize,
|
|
3290
|
-
maxSize,
|
|
3291
|
-
minYValue,
|
|
3292
|
-
maxYValue,
|
|
3293
|
-
drawGridY,
|
|
3294
|
-
drawGridX,
|
|
3295
|
-
scaleLog,
|
|
3296
|
-
xScaleItemWidth,
|
|
3297
|
-
bubbleStyle,
|
|
3298
|
-
customize,
|
|
3299
|
-
yScaleLabel,
|
|
3300
|
-
yScaleLabelPadding,
|
|
3301
|
-
enableTooltip,
|
|
3302
|
-
tooltipRoot,
|
|
3303
|
-
tooltipClassName,
|
|
3304
|
-
renderTooltip
|
|
3305
|
-
} = props;
|
|
3306
|
-
if (node !== null && data.length) {
|
|
3307
|
-
const marginTop = margin ? margin.top : 0;
|
|
3308
|
-
const marginRight = margin ? margin.right : 0;
|
|
3309
|
-
const marginBottom = margin ? margin.bottom : 0;
|
|
3310
|
-
const marginLeft = margin ? margin.left : 0;
|
|
3311
|
-
const {
|
|
3312
|
-
width: nodeWidth
|
|
3313
|
-
} = node.getBoundingClientRect();
|
|
3314
|
-
const width = props.width || nodeWidth;
|
|
3315
|
-
const height = props.height || 0;
|
|
3316
|
-
const yTicksCountDefault = 6;
|
|
3317
|
-
const minY = typeof minYValue === 'number' ? minYValue : d3.min(data, _ref => {
|
|
3318
|
-
let {
|
|
3319
|
-
yValue
|
|
3320
|
-
} = _ref;
|
|
3321
|
-
return yValue;
|
|
3322
|
-
});
|
|
3323
|
-
const maxY = typeof maxYValue === 'number' ? maxYValue : d3.max(data, _ref2 => {
|
|
3324
|
-
let {
|
|
3325
|
-
yValue
|
|
3326
|
-
} = _ref2;
|
|
3327
|
-
return yValue;
|
|
3328
|
-
});
|
|
3329
|
-
const svg = appendSvg(node, width, height || 0);
|
|
3330
|
-
const sizeScale = scaleLog ? d3.scaleLog().domain([d3.min(data, _ref3 => {
|
|
3331
|
-
let {
|
|
3332
|
-
sizeValue
|
|
3333
|
-
} = _ref3;
|
|
3334
|
-
return sizeValue;
|
|
3335
|
-
}) || 0.1, d3.max(data, _ref4 => {
|
|
3336
|
-
let {
|
|
3337
|
-
sizeValue
|
|
3338
|
-
} = _ref4;
|
|
3339
|
-
return sizeValue;
|
|
3340
|
-
}) || 0.1]).range([minSize || bubbleChartDefaultProps.minSize || 0.1, maxSize || bubbleChartDefaultProps.maxSize || 0.1]) : d3.scaleLinear().domain([d3.min(data, _ref5 => {
|
|
3341
|
-
let {
|
|
3342
|
-
sizeValue
|
|
3343
|
-
} = _ref5;
|
|
3344
|
-
return sizeValue;
|
|
3345
|
-
}), d3.max(data, _ref6 => {
|
|
3346
|
-
let {
|
|
3347
|
-
sizeValue
|
|
3348
|
-
} = _ref6;
|
|
3349
|
-
return sizeValue;
|
|
3350
|
-
})]).range([minSize || bubbleChartDefaultProps.minSize, maxSize || bubbleChartDefaultProps.maxSize]);
|
|
3351
|
-
const yRange1 = height - marginTop - marginBottom - (xAxisPadding || 0);
|
|
3352
|
-
const yScale = scaleLog ? d3.scaleLog().domain([minY || 0.1, maxY || 0.1]).range([yRange1 || 0.1, marginTop || 0.1]).nice() : d3.scaleLinear().domain([minY, maxY]).range([yRange1, marginTop]).nice();
|
|
3353
|
-
customYScale && customYScale(yScale);
|
|
3354
|
-
const yTicks = yScale.ticks();
|
|
3355
|
-
const yAxisLeft = d3.axisLeft(yScale).ticks(yTicksCountDefault);
|
|
3356
|
-
const yTicksCount = yAxisLeft.tickArguments()[0];
|
|
3357
|
-
const yAxis = svg.append('g').attr('class', bubbleChartClassNames.bubbleChartYAxis).call(yAxisLeft);
|
|
3358
|
-
let yScaleLabelHeight = yScaleLabelPadding || 0;
|
|
3359
|
-
if (yScaleLabel) {
|
|
3360
|
-
const label = svg.append('text').text(yScaleLabel).attr('class', bubbleChartClassNames.bubbleChartYScaleLabel);
|
|
3361
|
-
const {
|
|
3362
|
-
width,
|
|
3363
|
-
height
|
|
3364
|
-
} = computeDimensions(label);
|
|
3365
|
-
yScaleLabelHeight = yScaleLabelHeight + height;
|
|
3366
|
-
label.attr('transform', "rotate(-90) translate(-" + (yRange1 + marginBottom + width) / 2 + ", " + height + ")");
|
|
3367
|
-
}
|
|
3368
|
-
yAxis.selectAll('.tick').attr('class', value => {
|
|
3369
|
-
return value === 0 ? "tick " + bubbleChartClassNames.bubbleChartYAxisZeroTick : 'tick';
|
|
3370
|
-
});
|
|
3371
|
-
customYAxis && customYAxis(yAxis);
|
|
3372
|
-
const {
|
|
3373
|
-
width: yAxisWidth
|
|
3374
|
-
} = computeDimensions(yAxis);
|
|
3375
|
-
const xScale = scaleLog ? d3.scaleLog().domain([d3.min(data, _ref7 => {
|
|
3376
|
-
let {
|
|
3377
|
-
xValue
|
|
3378
|
-
} = _ref7;
|
|
3379
|
-
return xValue;
|
|
3380
|
-
}) || 0.1, d3.max(data, _ref8 => {
|
|
3381
|
-
let {
|
|
3382
|
-
xValue
|
|
3383
|
-
} = _ref8;
|
|
3384
|
-
return xValue;
|
|
3385
|
-
}) || 0.1]).range([marginLeft + yAxisWidth + (yAxisPadding || 0) + yScaleLabelHeight || 0.1, width - marginRight || 0.1]) : d3.scaleLinear().domain([d3.min(data, _ref9 => {
|
|
3386
|
-
let {
|
|
3387
|
-
xValue
|
|
3388
|
-
} = _ref9;
|
|
3389
|
-
return xValue;
|
|
3390
|
-
}), d3.max(data, _ref0 => {
|
|
3391
|
-
let {
|
|
3392
|
-
xValue
|
|
3393
|
-
} = _ref0;
|
|
3394
|
-
return xValue;
|
|
3395
|
-
})]).range([marginLeft + yAxisWidth + (yAxisPadding || 0) + yScaleLabelHeight, width - marginRight]);
|
|
3396
|
-
customXScale && customXScale(xScale);
|
|
3397
|
-
const xAxisBottom = d3.axisBottom(xScale);
|
|
3398
|
-
if (typeof xScaleItemWidth === 'number') {
|
|
3399
|
-
const [x1, x2] = xScale.range();
|
|
3400
|
-
const chartWidth = x2 - x1;
|
|
3401
|
-
xAxisBottom.ticks(Math.round(chartWidth / xScaleItemWidth)).tickSizeOuter(0);
|
|
3402
|
-
}
|
|
3403
|
-
const xAxis = svg.append('g').call(xAxisBottom).attr('class', bubbleChartClassNames.bubbleChartXAxis);
|
|
3404
|
-
customXAxis && customXAxis(xAxis);
|
|
3405
|
-
yAxis.attr('transform', "translate(" + (marginLeft + yAxisWidth + yScaleLabelHeight) + ", 0)");
|
|
3406
|
-
drawGrid$2({
|
|
3407
|
-
svg,
|
|
3408
|
-
yScale,
|
|
3409
|
-
xScale,
|
|
3410
|
-
yTicksCount,
|
|
3411
|
-
drawGridY,
|
|
3412
|
-
drawGridX
|
|
3413
|
-
});
|
|
3414
|
-
xAxis.attr('transform', "translate(0, " + (yScale(yTicks[0]) + (xAxisPadding || 0)) + ")");
|
|
3415
|
-
const bubbles = svg.append('g').selectAll('dot').data(data).enter().append('circle').attr('class', bubbleChartClassNames.bubbleChartCircle).attr('cx', _ref1 => {
|
|
3416
|
-
let {
|
|
3417
|
-
xValue
|
|
3418
|
-
} = _ref1;
|
|
3419
|
-
return xScale(xValue);
|
|
3420
|
-
}).attr('cy', _ref10 => {
|
|
3421
|
-
let {
|
|
3422
|
-
yValue
|
|
3423
|
-
} = _ref10;
|
|
3424
|
-
return yScale(yValue);
|
|
3425
|
-
}).attr('r', _ref11 => {
|
|
3426
|
-
let {
|
|
3427
|
-
sizeValue
|
|
3428
|
-
} = _ref11;
|
|
3429
|
-
return sizeScale(sizeValue) / 2;
|
|
3430
|
-
}).attr('fill', _ref12 => {
|
|
3431
|
-
let {
|
|
3432
|
-
color
|
|
3433
|
-
} = _ref12;
|
|
3434
|
-
return color || 'rgba(0, 176, 113, 0.6)';
|
|
3435
|
-
}).attr('stroke', _ref13 => {
|
|
3436
|
-
let {
|
|
3437
|
-
stroke
|
|
3438
|
-
} = _ref13;
|
|
3439
|
-
return stroke || 'transparent';
|
|
3440
|
-
}).attr('style', _ref14 => {
|
|
3441
|
-
let {
|
|
3442
|
-
style
|
|
3443
|
-
} = _ref14;
|
|
3444
|
-
return style || bubbleStyle || '';
|
|
3445
|
-
});
|
|
3446
|
-
if (enableTooltip) {
|
|
3447
|
-
drawTooltip$3({
|
|
3448
|
-
bubbles,
|
|
3449
|
-
tooltipRoot,
|
|
3450
|
-
tooltipClassName,
|
|
3451
|
-
renderTooltip
|
|
3452
|
-
});
|
|
3453
|
-
}
|
|
3454
|
-
customize && customize({
|
|
3455
|
-
svg,
|
|
3456
|
-
bubbles,
|
|
3457
|
-
yScale,
|
|
3458
|
-
xScale,
|
|
3459
|
-
sizeScale
|
|
3460
|
-
});
|
|
3461
|
-
}
|
|
3462
|
-
};
|
|
3463
|
-
|
|
3464
|
-
const unmount = tooltipRoot => {
|
|
3465
|
-
const root = tooltipRoot || document.querySelector('body');
|
|
3466
|
-
d3.select(root).select("." + bubbleChartClassNames.bubbleChartTooltip).remove();
|
|
3467
|
-
};
|
|
3468
|
-
|
|
3469
|
-
const BubbleChart = props => {
|
|
3470
|
-
const {
|
|
3471
|
-
className,
|
|
3472
|
-
style,
|
|
3473
|
-
children,
|
|
3474
|
-
tooltipRoot
|
|
3475
|
-
} = props;
|
|
3476
|
-
const [ref, node] = useNode();
|
|
3477
|
-
React.useEffect(() => {
|
|
3478
|
-
node && draw$5(node, props);
|
|
3479
|
-
}, [node, props]);
|
|
3480
|
-
React.useEffect(() => {
|
|
3481
|
-
return () => unmount(tooltipRoot);
|
|
3482
|
-
}, [tooltipRoot]);
|
|
3483
|
-
const onDraw = () => draw$5(node, props);
|
|
3484
|
-
useResize(props.width, onDraw);
|
|
3485
|
-
return React__default.createElement("div", {
|
|
3486
|
-
className: className,
|
|
3487
|
-
style: style
|
|
3488
|
-
}, React__default.createElement(TooltipStyles$2, null), React__default.createElement(SvgWrapper$5, {
|
|
3489
|
-
ref: ref
|
|
3490
|
-
}, children));
|
|
3491
|
-
};
|
|
3492
|
-
BubbleChart.defaultProps = bubbleChartDefaultProps;
|
|
3493
|
-
|
|
3494
|
-
exports.BarChart = BarChart;
|
|
3495
|
-
exports.BubbleChart = BubbleChart;
|
|
3496
|
-
exports.CalendarChart = CalendarChart;
|
|
3497
|
-
exports.ChartWrapper = Wrapper;
|
|
3498
|
-
exports.HorizontalBarChart = HorizontalBarChart;
|
|
3499
|
-
exports.LineChart = LineChart;
|
|
3500
|
-
exports.PieChart = PieChart;
|
|
3501
|
-
exports.RadarChart = RadarChart;
|
|
3502
|
-
exports.SwipeScroll = SwipeScroll;
|
|
3503
|
-
exports.appendSvg = appendSvg;
|
|
3504
|
-
exports.barChartClassNames = barChartClassNames;
|
|
3505
|
-
exports.bubbleChartClassNames = bubbleChartClassNames;
|
|
3506
|
-
exports.calendarChartClassNames = calendarChartClassNames;
|
|
3507
|
-
exports.horizontalBarChartClassNames = horizontalBarChartClassNames;
|
|
3508
|
-
exports.lineChartClassNames = lineChartClassNames;
|
|
3509
|
-
exports.pieChartclassNames = pieChartclassNames;
|
|
3510
|
-
exports.radarChartclassNames = radarChartclassNames;
|
|
3511
|
-
exports.useNode = useNode;
|
|
3512
|
-
exports.useResize = useResize;
|
|
3513
|
-
//# sourceMappingURL=charts.cjs.development.js.map
|