@elliemae/ds-dataviz 3.6.0-next.3
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/dist/cjs/graphs/Chart/Chart.js +61 -0
- package/dist/cjs/graphs/Chart/Chart.js.map +7 -0
- package/dist/cjs/graphs/Chart/ChartContext.js +67 -0
- package/dist/cjs/graphs/Chart/ChartContext.js.map +7 -0
- package/dist/cjs/graphs/Chart/Pie.js +49 -0
- package/dist/cjs/graphs/Chart/Pie.js.map +7 -0
- package/dist/cjs/graphs/Chart/config/useChart.js +109 -0
- package/dist/cjs/graphs/Chart/config/useChart.js.map +7 -0
- package/dist/cjs/graphs/Chart/config/useKeyboardNavigation.js +119 -0
- package/dist/cjs/graphs/Chart/config/useKeyboardNavigation.js.map +7 -0
- package/dist/cjs/graphs/Chart/config/useScales.js +107 -0
- package/dist/cjs/graphs/Chart/config/useScales.js.map +7 -0
- package/dist/cjs/graphs/Chart/helpers/index.js +83 -0
- package/dist/cjs/graphs/Chart/helpers/index.js.map +7 -0
- package/dist/cjs/graphs/Chart/index.js +26 -0
- package/dist/cjs/graphs/Chart/index.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/ActivePoint.js +83 -0
- package/dist/cjs/graphs/Chart/parts/ActivePoint.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/AxisBottom.js +86 -0
- package/dist/cjs/graphs/Chart/parts/AxisBottom.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/AxisLeft.js +79 -0
- package/dist/cjs/graphs/Chart/parts/AxisLeft.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/AxisRight.js +63 -0
- package/dist/cjs/graphs/Chart/parts/AxisRight.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/ChartContainer.js +78 -0
- package/dist/cjs/graphs/Chart/parts/ChartContainer.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/ColorLegend.js +70 -0
- package/dist/cjs/graphs/Chart/parts/ColorLegend.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/FocusableRegion.js +116 -0
- package/dist/cjs/graphs/Chart/parts/FocusableRegion.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/Scrapper.js +130 -0
- package/dist/cjs/graphs/Chart/parts/Scrapper.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/SeriesFactory.js +82 -0
- package/dist/cjs/graphs/Chart/parts/SeriesFactory.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/VerticalScrapper.js +138 -0
- package/dist/cjs/graphs/Chart/parts/VerticalScrapper.js.map +7 -0
- package/dist/cjs/graphs/Chart/react-desc-prop-types.js +57 -0
- package/dist/cjs/graphs/Chart/react-desc-prop-types.js.map +7 -0
- package/dist/cjs/graphs/Chart/series/Area.js +73 -0
- package/dist/cjs/graphs/Chart/series/Area.js.map +7 -0
- package/dist/cjs/graphs/Chart/series/Bars.js +68 -0
- package/dist/cjs/graphs/Chart/series/Bars.js.map +7 -0
- package/dist/cjs/graphs/Chart/series/Line.js +70 -0
- package/dist/cjs/graphs/Chart/series/Line.js.map +7 -0
- package/dist/cjs/graphs/Chart/series/Pie.js +46 -0
- package/dist/cjs/graphs/Chart/series/Pie.js.map +7 -0
- package/dist/cjs/graphs/Chart/series/Point.js +67 -0
- package/dist/cjs/graphs/Chart/series/Point.js.map +7 -0
- package/dist/cjs/graphs/Chart/series/Points.js +84 -0
- package/dist/cjs/graphs/Chart/series/Points.js.map +7 -0
- package/dist/cjs/graphs/Chart/series/Rect.js +78 -0
- package/dist/cjs/graphs/Chart/series/Rect.js.map +7 -0
- package/dist/cjs/graphs/Chart/series/StackedBar.js +66 -0
- package/dist/cjs/graphs/Chart/series/StackedBar.js.map +7 -0
- package/dist/cjs/graphs/Chart/series/index.js +32 -0
- package/dist/cjs/graphs/Chart/series/index.js.map +7 -0
- package/dist/cjs/graphs/Chart/styles.js +123 -0
- package/dist/cjs/graphs/Chart/styles.js.map +7 -0
- package/dist/cjs/graphs/constants.js +37 -0
- package/dist/cjs/graphs/constants.js.map +7 -0
- package/dist/cjs/graphs/index.js +27 -0
- package/dist/cjs/graphs/index.js.map +7 -0
- package/dist/cjs/index.js +33 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/esm/graphs/Chart/Chart.js +35 -0
- package/dist/esm/graphs/Chart/Chart.js.map +7 -0
- package/dist/esm/graphs/Chart/ChartContext.js +41 -0
- package/dist/esm/graphs/Chart/ChartContext.js.map +7 -0
- package/dist/esm/graphs/Chart/Pie.js +23 -0
- package/dist/esm/graphs/Chart/Pie.js.map +7 -0
- package/dist/esm/graphs/Chart/config/useChart.js +83 -0
- package/dist/esm/graphs/Chart/config/useChart.js.map +7 -0
- package/dist/esm/graphs/Chart/config/useKeyboardNavigation.js +93 -0
- package/dist/esm/graphs/Chart/config/useKeyboardNavigation.js.map +7 -0
- package/dist/esm/graphs/Chart/config/useScales.js +81 -0
- package/dist/esm/graphs/Chart/config/useScales.js.map +7 -0
- package/dist/esm/graphs/Chart/helpers/index.js +57 -0
- package/dist/esm/graphs/Chart/helpers/index.js.map +7 -0
- package/dist/esm/graphs/Chart/index.js +3 -0
- package/dist/esm/graphs/Chart/index.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/ActivePoint.js +57 -0
- package/dist/esm/graphs/Chart/parts/ActivePoint.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/AxisBottom.js +60 -0
- package/dist/esm/graphs/Chart/parts/AxisBottom.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/AxisLeft.js +53 -0
- package/dist/esm/graphs/Chart/parts/AxisLeft.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/AxisRight.js +37 -0
- package/dist/esm/graphs/Chart/parts/AxisRight.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/ChartContainer.js +52 -0
- package/dist/esm/graphs/Chart/parts/ChartContainer.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/ColorLegend.js +44 -0
- package/dist/esm/graphs/Chart/parts/ColorLegend.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/FocusableRegion.js +90 -0
- package/dist/esm/graphs/Chart/parts/FocusableRegion.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/Scrapper.js +104 -0
- package/dist/esm/graphs/Chart/parts/Scrapper.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/SeriesFactory.js +56 -0
- package/dist/esm/graphs/Chart/parts/SeriesFactory.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/VerticalScrapper.js +112 -0
- package/dist/esm/graphs/Chart/parts/VerticalScrapper.js.map +7 -0
- package/dist/esm/graphs/Chart/react-desc-prop-types.js +31 -0
- package/dist/esm/graphs/Chart/react-desc-prop-types.js.map +7 -0
- package/dist/esm/graphs/Chart/series/Area.js +47 -0
- package/dist/esm/graphs/Chart/series/Area.js.map +7 -0
- package/dist/esm/graphs/Chart/series/Bars.js +42 -0
- package/dist/esm/graphs/Chart/series/Bars.js.map +7 -0
- package/dist/esm/graphs/Chart/series/Line.js +44 -0
- package/dist/esm/graphs/Chart/series/Line.js.map +7 -0
- package/dist/esm/graphs/Chart/series/Pie.js +20 -0
- package/dist/esm/graphs/Chart/series/Pie.js.map +7 -0
- package/dist/esm/graphs/Chart/series/Point.js +41 -0
- package/dist/esm/graphs/Chart/series/Point.js.map +7 -0
- package/dist/esm/graphs/Chart/series/Points.js +58 -0
- package/dist/esm/graphs/Chart/series/Points.js.map +7 -0
- package/dist/esm/graphs/Chart/series/Rect.js +52 -0
- package/dist/esm/graphs/Chart/series/Rect.js.map +7 -0
- package/dist/esm/graphs/Chart/series/StackedBar.js +40 -0
- package/dist/esm/graphs/Chart/series/StackedBar.js.map +7 -0
- package/dist/esm/graphs/Chart/series/index.js +9 -0
- package/dist/esm/graphs/Chart/series/index.js.map +7 -0
- package/dist/esm/graphs/Chart/styles.js +97 -0
- package/dist/esm/graphs/Chart/styles.js.map +7 -0
- package/dist/esm/graphs/constants.js +11 -0
- package/dist/esm/graphs/constants.js.map +7 -0
- package/dist/esm/graphs/index.js +4 -0
- package/dist/esm/graphs/index.js.map +7 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +7 -0
- package/package.json +76 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useCallback, useContext, useMemo, useState } from "react";
|
|
3
|
+
import { ChartContext } from "../ChartContext";
|
|
4
|
+
const findInCircularList = (list, from, step = 1) => {
|
|
5
|
+
for (let i = (from + step + list.length) % list.length; i !== from && from > -1; i = (i + step + list.length) % list.length) {
|
|
6
|
+
if (list[i])
|
|
7
|
+
return i;
|
|
8
|
+
}
|
|
9
|
+
return from;
|
|
10
|
+
};
|
|
11
|
+
const useKeyboardNavigation = () => {
|
|
12
|
+
const {
|
|
13
|
+
activePoint,
|
|
14
|
+
setActivePoint,
|
|
15
|
+
containerRef,
|
|
16
|
+
groups,
|
|
17
|
+
yScale,
|
|
18
|
+
props: { data }
|
|
19
|
+
} = useContext(ChartContext);
|
|
20
|
+
const [currentFocusedDataset, setCurrentFocusedDataset] = useState(groups[0]);
|
|
21
|
+
const currentGroup = useMemo(() => data.find((d) => d.name === currentFocusedDataset), [currentFocusedDataset, data]);
|
|
22
|
+
const currentItemIndex = useMemo(
|
|
23
|
+
() => currentGroup.data.findIndex((opt) => opt.key === activePoint),
|
|
24
|
+
[activePoint, currentGroup]
|
|
25
|
+
);
|
|
26
|
+
const handleOnFocus = useCallback(
|
|
27
|
+
(e) => {
|
|
28
|
+
if (containerRef?.current === e.target) {
|
|
29
|
+
setActivePoint(currentGroup.data[0].key);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
[containerRef, currentGroup, setActivePoint]
|
|
33
|
+
);
|
|
34
|
+
const handleOnBlur = useCallback(() => {
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
if (!containerRef?.current?.contains(document.activeElement) || containerRef?.current === document.activeElement) {
|
|
37
|
+
setActivePoint("");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}, [containerRef, setActivePoint]);
|
|
41
|
+
const navigateSerie = useCallback(
|
|
42
|
+
(step) => {
|
|
43
|
+
const newValue = findInCircularList(
|
|
44
|
+
currentGroup.data.map((d) => d.value.toString()),
|
|
45
|
+
currentItemIndex,
|
|
46
|
+
step
|
|
47
|
+
);
|
|
48
|
+
setActivePoint(currentGroup.data[newValue].key);
|
|
49
|
+
},
|
|
50
|
+
[currentGroup.data, currentItemIndex, setActivePoint]
|
|
51
|
+
);
|
|
52
|
+
const changeSerie = useCallback(
|
|
53
|
+
(step) => {
|
|
54
|
+
setCurrentFocusedDataset((prev) => {
|
|
55
|
+
const nextGroup = findInCircularList(
|
|
56
|
+
groups,
|
|
57
|
+
groups.findIndex((item) => item === prev),
|
|
58
|
+
step
|
|
59
|
+
);
|
|
60
|
+
const nextGroupData = data.find((d) => d.name === groups[nextGroup]);
|
|
61
|
+
setActivePoint(nextGroupData.data[currentItemIndex].key);
|
|
62
|
+
return groups[nextGroup];
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
[currentItemIndex, data, setActivePoint, groups]
|
|
66
|
+
);
|
|
67
|
+
const onInputKeyDown = useCallback(
|
|
68
|
+
(e) => {
|
|
69
|
+
if (e.code !== "Tab") {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
}
|
|
72
|
+
if (["ArrowLeft", "ArrowRight"].includes(e.code)) {
|
|
73
|
+
if (yScale.bandwidth)
|
|
74
|
+
changeSerie(e.code === "ArrowLeft" ? -1 : 1);
|
|
75
|
+
else
|
|
76
|
+
navigateSerie(e.code === "ArrowLeft" ? -1 : 1);
|
|
77
|
+
}
|
|
78
|
+
if (["ArrowDown", "ArrowUp"].includes(e.code)) {
|
|
79
|
+
if (yScale.bandwidth)
|
|
80
|
+
navigateSerie(e.code === "ArrowDown" ? -1 : 1);
|
|
81
|
+
else
|
|
82
|
+
changeSerie(e.code === "ArrowDown" ? -1 : 1);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
[changeSerie, navigateSerie, yScale.bandwidth]
|
|
86
|
+
);
|
|
87
|
+
return { onInputKeyDown, handleOnBlur, handleOnFocus };
|
|
88
|
+
};
|
|
89
|
+
export {
|
|
90
|
+
findInCircularList,
|
|
91
|
+
useKeyboardNavigation
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=useKeyboardNavigation.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/config/useKeyboardNavigation.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport { useCallback, useContext, useMemo, useState } from 'react';\nimport { ChartContext } from '../ChartContext';\n\nexport const findInCircularList = (\n list,\n from: number,\n //criteria: (item) => boolean,\n step = 1,\n // eslint-disable-next-line max-params\n): number => {\n for (\n let i = (from + step + list.length) % list.length;\n i !== from && from > -1;\n i = (i + step + list.length) % list.length\n ) {\n if (list[i]) return i;\n }\n return from; // return same item\n};\n\nexport const useKeyboardNavigation = () => {\n const {\n activePoint,\n setActivePoint,\n containerRef,\n groups,\n yScale,\n props: { data },\n } = useContext(ChartContext);\n\n const [currentFocusedDataset, setCurrentFocusedDataset] = useState(groups[0]);\n\n const currentGroup = useMemo(() => data.find((d) => d.name === currentFocusedDataset), [currentFocusedDataset, data]);\n\n const currentItemIndex = useMemo(\n () => currentGroup.data.findIndex((opt) => opt.key === activePoint),\n [activePoint, currentGroup],\n );\n\n const handleOnFocus: React.FocusEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (containerRef?.current === e.target) {\n setActivePoint(currentGroup.data[0].key);\n }\n },\n [containerRef, currentGroup, setActivePoint],\n );\n\n const handleOnBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(() => {\n setTimeout(() => {\n if (\n !containerRef?.current?.contains(document.activeElement) ||\n containerRef?.current === document.activeElement\n ) {\n setActivePoint('');\n }\n });\n }, [containerRef, setActivePoint]);\n\n const navigateSerie = useCallback(\n (step: number) => {\n const newValue = findInCircularList(\n currentGroup.data.map((d) => d.value.toString()),\n currentItemIndex,\n step,\n );\n setActivePoint(currentGroup.data[newValue].key);\n },\n [currentGroup.data, currentItemIndex, setActivePoint],\n );\n\n const changeSerie = useCallback(\n (step: number) => {\n setCurrentFocusedDataset((prev) => {\n const nextGroup = findInCircularList(\n groups,\n groups.findIndex((item) => item === prev),\n step,\n );\n const nextGroupData = data.find((d) => d.name === groups[nextGroup]);\n setActivePoint(nextGroupData.data[currentItemIndex].key);\n return groups[nextGroup];\n });\n },\n [currentItemIndex, data, setActivePoint, groups],\n );\n\n const onInputKeyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback(\n (e) => {\n if (e.code !== 'Tab') {\n e.preventDefault();\n }\n if (['ArrowLeft', 'ArrowRight'].includes(e.code)) {\n if (yScale.bandwidth) changeSerie(e.code === 'ArrowLeft' ? -1 : 1);\n else navigateSerie(e.code === 'ArrowLeft' ? -1 : 1);\n }\n\n if (['ArrowDown', 'ArrowUp'].includes(e.code)) {\n if (yScale.bandwidth) navigateSerie(e.code === 'ArrowDown' ? -1 : 1);\n else changeSerie(e.code === 'ArrowDown' ? -1 : 1);\n }\n },\n [changeSerie, navigateSerie, yScale.bandwidth],\n );\n\n return { onInputKeyDown, handleOnBlur, handleOnFocus };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,aAAa,YAAY,SAAS,gBAAgB;AAC3D,SAAS,oBAAoB;AAEtB,MAAM,qBAAqB,CAChC,MACA,MAEA,OAAO,MAEI;AACX,WACM,KAAK,OAAO,OAAO,KAAK,UAAU,KAAK,QAC3C,MAAM,QAAQ,OAAO,IACrB,KAAK,IAAI,OAAO,KAAK,UAAU,KAAK,QACpC;AACA,QAAI,KAAK;AAAI,aAAO;AAAA,EACtB;AACA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,UAChB;AAAA,UACA,OAAO,UAAU,CAAC,SAAS,SAAS,IAAI;AAAA,UACxC;AAAA,QACF;AACA,cAAM,gBAAgB,KAAK,KAAK,CAAC,MAAM,EAAE,SAAS,OAAO,UAAU;AACnE,uBAAe,cAAc,KAAK,kBAAkB,GAAG;AACvD,eAAO,OAAO;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,IACA,CAAC,kBAAkB,MAAM,gBAAgB,MAAM;AAAA,EACjD;AAEA,QAAM,iBAA+D;AAAA,IACnE,CAAC,MAAM;AACL,UAAI,EAAE,SAAS,OAAO;AACpB,UAAE,eAAe;AAAA,MACnB;AACA,UAAI,CAAC,aAAa,YAAY,EAAE,SAAS,EAAE,IAAI,GAAG;AAChD,YAAI,OAAO;AAAW,sBAAY,EAAE,SAAS,cAAc,KAAK,CAAC;AAAA;AAC5D,wBAAc,EAAE,SAAS,cAAc,KAAK,CAAC;AAAA,MACpD;AAEA,UAAI,CAAC,aAAa,SAAS,EAAE,SAAS,EAAE,IAAI,GAAG;AAC7C,YAAI,OAAO;AAAW,wBAAc,EAAE,SAAS,cAAc,KAAK,CAAC;AAAA;AAC9D,sBAAY,EAAE,SAAS,cAAc,KAAK,CAAC;AAAA,MAClD;AAAA,IACF;AAAA,IACA,CAAC,aAAa,eAAe,OAAO,SAAS;AAAA,EAC/C;AAEA,SAAO,EAAE,gBAAgB,cAAc,cAAc;AACvD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useMemo, useCallback } from "react";
|
|
3
|
+
import { max, min, scaleLinear, scaleBand, scaleTime, scaleOrdinal, scaleLog } from "d3";
|
|
4
|
+
import { getStackedIndex } from "../helpers";
|
|
5
|
+
const useScales = ({ props, innerHeight, innerWidth, stackedData, currentData, groups }) => {
|
|
6
|
+
const { series, xAxis, yAxis, y2Axis, groups: stackedSeries, types } = props;
|
|
7
|
+
const getBandDomain = useCallback((axis) => axis.cols ?? [...series[0].data.keys()], [series]);
|
|
8
|
+
const getLinearDomain = useCallback(
|
|
9
|
+
(axis, axisString, withStackData = true) => {
|
|
10
|
+
const begin = axis?.beginAtZero ? 0 : void 0;
|
|
11
|
+
const data = series.filter((serie) => {
|
|
12
|
+
if (serie.scale === "y2") {
|
|
13
|
+
return serie.scale === axisString;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
}).map(
|
|
17
|
+
(serie) => typeof serie.data[0] === "number" ? serie.data : serie.data.map((coord) => coord[axisString])
|
|
18
|
+
);
|
|
19
|
+
const stack = withStackData && [
|
|
20
|
+
min(stackedData.flat(), (layer) => min(layer, (sequence) => sequence[1])),
|
|
21
|
+
max(stackedData.flat(), (layer) => max(layer, (sequence) => sequence[1]))
|
|
22
|
+
];
|
|
23
|
+
const minRange = min([begin, min(data.flat()), stack[0]]);
|
|
24
|
+
const maxRange = max([max(data.flat()), stack[1]]);
|
|
25
|
+
return [
|
|
26
|
+
minRange - (axisString === "x" ? (maxRange - minRange) * 0.05 : 0),
|
|
27
|
+
maxRange + (axisString === "x" ? (maxRange - minRange) * 0.05 : 0)
|
|
28
|
+
];
|
|
29
|
+
},
|
|
30
|
+
[series, stackedData]
|
|
31
|
+
);
|
|
32
|
+
const getScaleTime = (domain, range) => scaleTime().domain([min(domain) ?? 0, max(domain) ?? 0]).range(range).nice();
|
|
33
|
+
const getScaleBand = (domain, range, padding = 0.2) => scaleBand().domain(domain).range(range).padding(padding);
|
|
34
|
+
const getScaleLinear = (domain, range) => scaleLinear().domain(domain).range(range);
|
|
35
|
+
const getScaleLog = (domain, range) => scaleLog().domain(domain).range(range);
|
|
36
|
+
const xScale = useMemo(() => {
|
|
37
|
+
if (xAxis?.type === "time")
|
|
38
|
+
return getScaleTime(xAxis.cols, [0, innerWidth]);
|
|
39
|
+
if (xAxis?.type === "linear" || yAxis?.type === "band") {
|
|
40
|
+
const withStackData = yAxis?.type === "band";
|
|
41
|
+
return getScaleLinear(getLinearDomain(xAxis, "x", withStackData), [0, innerWidth]);
|
|
42
|
+
}
|
|
43
|
+
return getScaleBand(getBandDomain(xAxis), [0, innerWidth], xAxis.padding);
|
|
44
|
+
}, [getBandDomain, getLinearDomain, innerWidth, xAxis, yAxis?.type]);
|
|
45
|
+
const yScale = useMemo(() => {
|
|
46
|
+
if (yAxis?.type === "band")
|
|
47
|
+
return getScaleBand(getBandDomain(yAxis), [innerHeight, 0], yAxis.padding);
|
|
48
|
+
if (yAxis?.type === "log")
|
|
49
|
+
return getScaleLog(getLinearDomain(yAxis, "y"), [innerHeight, 0]);
|
|
50
|
+
return getScaleLinear(getLinearDomain(yAxis, "y"), [innerHeight, 0]);
|
|
51
|
+
}, [getBandDomain, getLinearDomain, innerHeight, yAxis]);
|
|
52
|
+
const y2Scale = useMemo(() => {
|
|
53
|
+
if (!y2Axis)
|
|
54
|
+
return null;
|
|
55
|
+
if (y2Axis?.type === "band")
|
|
56
|
+
return getScaleBand(getBandDomain(y2Axis), [innerHeight, 0], y2Scale.padding);
|
|
57
|
+
if (y2Axis?.type === "log")
|
|
58
|
+
return getScaleLog(getLinearDomain(y2Axis, "y2"), [innerHeight, 0]);
|
|
59
|
+
return getScaleLinear(getLinearDomain(y2Axis, "y2"), [innerHeight, 0]);
|
|
60
|
+
}, [getBandDomain, getLinearDomain, innerHeight, y2Axis]);
|
|
61
|
+
const colorScale = scaleOrdinal().domain(groups).range(currentData.map((d) => d.color));
|
|
62
|
+
const subgroupsWithBars = currentData.filter(
|
|
63
|
+
(serie) => serie.type === "bar" && !(stackedSeries?.length && getStackedIndex(stackedSeries, serie.name) > -1)
|
|
64
|
+
).map((serie) => serie.name);
|
|
65
|
+
const getBandwidth = useCallback(() => {
|
|
66
|
+
if (xScale.bandwidth)
|
|
67
|
+
return xScale.bandwidth();
|
|
68
|
+
if (yScale.bandwidth)
|
|
69
|
+
return yScale.bandwidth();
|
|
70
|
+
return innerWidth / xScale.ticks().length / 2;
|
|
71
|
+
}, [innerWidth, xScale, yScale]);
|
|
72
|
+
if (stackedSeries?.length) {
|
|
73
|
+
stackedSeries.forEach((_, i) => subgroupsWithBars.push(`stacked-data-${i}`));
|
|
74
|
+
}
|
|
75
|
+
const subGroupScale = getBandwidth() ? scaleBand().domain(subgroupsWithBars).range([0, getBandwidth() ?? 0]).padding(0.05) : null;
|
|
76
|
+
return { xScale, y2Scale, yScale, subGroupScale, colorScale, getBandwidth };
|
|
77
|
+
};
|
|
78
|
+
export {
|
|
79
|
+
useScales
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=useScales.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/config/useScales.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useCallback } from 'react';\nimport { max, min, scaleLinear, scaleBand, scaleTime, scaleOrdinal, scaleLog, Series, ScaleBand } from 'd3';\nimport { DSChartT } from '../react-desc-prop-types';\nimport { getStackedIndex } from '../helpers';\n\ninterface UseScales {\n props: DSChartT.Props;\n innerHeight: number;\n innerWidth: number;\n stackedData: Series<\n {\n [key: string]: number;\n },\n string\n >[][];\n currentData: {\n key: string;\n group: string;\n type: DSChartT.SerieTypeT;\n scale?: string;\n color: string;\n data: {\n key: string;\n value: number | { x: number; y: number };\n position: number;\n }[];\n }[];\n groups: string[];\n}\nexport const useScales = ({ props, innerHeight, innerWidth, stackedData, currentData, groups }: UseScales) => {\n const { series, xAxis, yAxis, y2Axis, groups: stackedSeries, types } = props;\n\n const getBandDomain = useCallback((axis: DSChartT.AxisT) => axis.cols ?? [...series[0].data.keys()], [series]);\n\n const getLinearDomain = useCallback(\n (axis?: DSChartT.AxisT, axisString?: string, withStackData = true) => {\n // const data2 = data ? extent(data) : [];\n const begin = axis?.beginAtZero ? 0 : undefined;\n const data = series\n .filter((serie) => {\n if (serie.scale === 'y2') {\n return serie.scale === axisString;\n }\n return true;\n })\n .map((serie) =>\n typeof serie.data[0] === 'number' ? serie.data : serie.data.map((coord) => coord[axisString]),\n );\n\n const stack = withStackData && [\n min(stackedData.flat(), (layer) => min(layer, (sequence) => sequence[1])),\n max(stackedData.flat(), (layer) => max(layer, (sequence) => sequence[1])),\n ];\n const minRange = min([begin, min(data.flat()), stack[0]]);\n const maxRange = max([max(data.flat()), stack[1]]);\n // we set a pad on the x axis, we can create a prop to set this constant\n return [\n minRange - (axisString === 'x' ? (maxRange - minRange) * 0.05 : 0),\n maxRange + (axisString === 'x' ? (maxRange - minRange) * 0.05 : 0),\n ];\n },\n [series, stackedData],\n );\n\n const getScaleTime = (domain: Date[], range: number[]) =>\n scaleTime()\n .domain([min(domain) ?? 0, max(domain) ?? 0])\n .range(range)\n .nice();\n const getScaleBand = (domain: string[], range: number[], padding = 0.2) =>\n scaleBand().domain(domain).range(range).padding(padding);\n const getScaleLinear = (domain: number[], range: number[]) => scaleLinear().domain(domain).range(range);\n const getScaleLog = (domain: number[], range: number[]) => scaleLog().domain(domain).range(range);\n\n const xScale = useMemo(() => {\n if (xAxis?.type === 'time') return getScaleTime(xAxis.cols as Date[], [0, innerWidth]);\n if (xAxis?.type === 'linear' || yAxis?.type === 'band') {\n const withStackData = yAxis?.type === 'band';\n return getScaleLinear(getLinearDomain(xAxis, 'x', withStackData) as number[], [0, innerWidth]);\n }\n\n return getScaleBand(getBandDomain(xAxis) as string[], [0, innerWidth], xAxis.padding);\n }, [getBandDomain, getLinearDomain, innerWidth, xAxis, yAxis?.type]);\n\n const yScale = useMemo(() => {\n if (yAxis?.type === 'band') return getScaleBand(getBandDomain(yAxis), [innerHeight, 0], yAxis.padding);\n if (yAxis?.type === 'log') return getScaleLog(getLinearDomain(yAxis, 'y'), [innerHeight, 0]);\n return getScaleLinear(getLinearDomain(yAxis, 'y'), [innerHeight, 0]);\n }, [getBandDomain, getLinearDomain, innerHeight, yAxis]);\n\n const y2Scale = useMemo(() => {\n if (!y2Axis) return null;\n if (y2Axis?.type === 'band') return getScaleBand(getBandDomain(y2Axis), [innerHeight, 0], y2Scale.padding);\n if (y2Axis?.type === 'log') return getScaleLog(getLinearDomain(y2Axis, 'y2'), [innerHeight, 0]);\n return getScaleLinear(getLinearDomain(y2Axis, 'y2'), [innerHeight, 0]);\n }, [getBandDomain, getLinearDomain, innerHeight, y2Axis]);\n\n const colorScale = scaleOrdinal()\n .domain(groups)\n .range(currentData.map((d) => d.color));\n // get only groups bars to calculate the subgroup scale\n\n const subgroupsWithBars = currentData\n .filter(\n (serie) => serie.type === 'bar' && !(stackedSeries?.length && getStackedIndex(stackedSeries, serie.name) > -1),\n )\n .map((serie) => serie.name);\n\n const getBandwidth = useCallback(() => {\n if ((xScale as ScaleBand<string>).bandwidth) return (xScale as ScaleBand<string>).bandwidth();\n if ((yScale as ScaleBand<string>).bandwidth) return (yScale as ScaleBand<string>).bandwidth();\n return innerWidth / xScale.ticks().length / 2;\n }, [innerWidth, xScale, yScale]);\n\n if (stackedSeries?.length) {\n stackedSeries.forEach((_, i) => subgroupsWithBars.push(`stacked-data-${i}`));\n }\n\n const subGroupScale = getBandwidth()\n ? scaleBand()\n .domain(subgroupsWithBars)\n .range([0, getBandwidth() ?? 0])\n .padding(0.05)\n : null;\n\n return { xScale, y2Scale, yScale, subGroupScale, colorScale, getBandwidth };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACEvB,SAAS,SAAS,mBAAmB;AACrC,SAAS,KAAK,KAAK,aAAa,WAAW,WAAW,cAAc,gBAAmC;AAEvG,SAAS,uBAAuB;AA0BzB,MAAM,YAAY,CAAC,EAAE,OAAO,aAAa,YAAY,aAAa,aAAa,OAAO,MAAiB;AAC5G,QAAM,EAAE,QAAQ,OAAO,OAAO,QAAQ,QAAQ,eAAe,MAAM,IAAI;AAEvE,QAAM,gBAAgB,YAAY,CAAC,SAAyB,KAAK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AO,eAAe,gBAAgB,QAAQ,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC;AAAA,EACvE,GAAG,CAAC,eAAe,iBAAiB,aAAa,MAAM,CAAC;AAExD,QAAM,aAAa,aAAa,EAC7B,OAAO,MAAM,EACb,MAAM,YAAY,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAGxC,QAAM,oBAAoB,YACvB;AAAA,IACC,CAAC,UAAU,MAAM,SAAS,SAAS,EAAE,eAAe,UAAU,gBAAgB,eAAe,MAAM,IAAI,IAAI;AAAA,EAC7G,EACC,IAAI,CAAC,UAAU,MAAM,IAAI;AAE5B,QAAM,eAAe,YAAY,MAAM;AACrC,QAAK,OAA6B;AAAW,aAAQ,OAA6B,UAAU;AAC5F,QAAK,OAA6B;AAAW,aAAQ,OAA6B,UAAU;AAC5F,WAAO,aAAa,OAAO,MAAM,EAAE,SAAS;AAAA,EAC9C,GAAG,CAAC,YAAY,QAAQ,MAAM,CAAC;AAE/B,MAAI,eAAe,QAAQ;AACzB,kBAAc,QAAQ,CAAC,GAAG,MAAM,kBAAkB,KAAK,gBAAgB,GAAG,CAAC;AAAA,EAC7E;AAEA,QAAM,gBAAgB,aAAa,IAC/B,UAAU,EACP,OAAO,iBAAiB,EACxB,MAAM,CAAC,GAAG,aAAa,KAAK,CAAC,CAAC,EAC9B,QAAQ,IAAI,IACf;AAEJ,SAAO,EAAE,QAAQ,SAAS,QAAQ,eAAe,YAAY,aAAa;AAC5E;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { stack } from "d3";
|
|
3
|
+
const getStackedIndex = (groups, serie) => {
|
|
4
|
+
for (let i = 0; i < groups.length; i += 1) {
|
|
5
|
+
for (let j = 0; j < groups[i].length; j += 1) {
|
|
6
|
+
if (groups[i][j] === serie)
|
|
7
|
+
return i;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return -1;
|
|
11
|
+
};
|
|
12
|
+
const getStackedData = (stackedData, serie) => {
|
|
13
|
+
for (let i = 0; i < stackedData?.length; i += 1) {
|
|
14
|
+
const data = stackedData[i].find((d) => d.key === serie.name);
|
|
15
|
+
if (data)
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
const stackData = (groupsStacked, series) => {
|
|
21
|
+
const aux = [];
|
|
22
|
+
if (!groupsStacked)
|
|
23
|
+
return [];
|
|
24
|
+
groupsStacked?.forEach((g) => {
|
|
25
|
+
const seriesStacked = series.filter((serie) => g.includes(serie.name));
|
|
26
|
+
const keys = seriesStacked.map((serie) => serie.name);
|
|
27
|
+
const stackData2 = [];
|
|
28
|
+
seriesStacked.forEach((serie) => {
|
|
29
|
+
serie.data.forEach((d, i) => {
|
|
30
|
+
if (typeof stackData2[i] === "object") {
|
|
31
|
+
stackData2[i][serie.name] = typeof d === "number" ? d : d.y;
|
|
32
|
+
}
|
|
33
|
+
stackData2[i] = { ...stackData2[i], [serie.name]: typeof d === "number" ? d : d.y };
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
aux.push(stack().keys(keys)(stackData2));
|
|
37
|
+
});
|
|
38
|
+
return aux;
|
|
39
|
+
};
|
|
40
|
+
const getSeriesValuesAt = (data, point) => {
|
|
41
|
+
const seriesValuesAtPoint = {};
|
|
42
|
+
data.forEach((serie) => {
|
|
43
|
+
serie.data.forEach((datum) => {
|
|
44
|
+
if (datum.value === point) {
|
|
45
|
+
seriesValuesAtPoint[serie.name] = seriesValuesAtPoint[serie.name] ? [...seriesValuesAtPoint[serie.name], point] : [point];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return seriesValuesAtPoint;
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
getSeriesValuesAt,
|
|
53
|
+
getStackedData,
|
|
54
|
+
getStackedIndex,
|
|
55
|
+
stackData
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/helpers/index.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { stack } from 'd3';\nimport { values } from 'lodash';\n\nexport const getStackedIndex = (groups: string[][], serie: string) => {\n for (let i = 0; i < groups.length; i += 1) {\n for (let j = 0; j < groups[i].length; j += 1) {\n if (groups[i][j] === serie) return i;\n }\n }\n return -1;\n};\n\nexport const getStackedData = (stackedData, serie) => {\n for (let i = 0; i < stackedData?.length; i += 1) {\n const data = stackedData[i].find((d) => d.key === serie.name);\n if (data) return data;\n }\n return false;\n};\n\nexport const stackData = (groupsStacked, series) => {\n const aux = [];\n if (!groupsStacked) return [];\n groupsStacked?.forEach((g) => {\n const seriesStacked = series.filter((serie) => g.includes(serie.name));\n const keys = seriesStacked.map((serie) => serie.name);\n const stackData: Array<{ [key: string]: number }> = [];\n seriesStacked.forEach((serie) => {\n serie.data.forEach((d, i) => {\n if (typeof stackData[i] === 'object') {\n stackData[i][serie.name] = typeof d === 'number' ? d : d.y;\n }\n stackData[i] = { ...stackData[i], [serie.name]: typeof d === 'number' ? d : d.y };\n });\n });\n\n aux.push(stack().keys(keys)(stackData));\n });\n return aux;\n};\n\nexport const getSeriesValuesAt = (data, point) => {\n const seriesValuesAtPoint = {};\n data.forEach((serie) => {\n serie.data.forEach((datum) => {\n if (datum.value === point) {\n seriesValuesAtPoint[serie.name] = seriesValuesAtPoint[serie.name]\n ? [...seriesValuesAtPoint[serie.name], point]\n : [point];\n }\n });\n });\n return seriesValuesAtPoint;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa;AAGf,MAAM,kBAAkB,CAAC,QAAoB,UAAkB;AACpE,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KA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AAI,MAAM,UAAU,OAAO;AACzB,4BAAoB,MAAM,QAAQ,oBAAoB,MAAM,QACxD,CAAC,GAAG,oBAAoB,MAAM,OAAO,KAAK,IAC1C,CAAC,KAAK;AAAA,MACZ;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;",
|
|
6
|
+
"names": ["stackData"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/graphs/Chart/index.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './Chart';\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext, useMemo, useRef } from "react";
|
|
4
|
+
import { ChartContext } from "../ChartContext";
|
|
5
|
+
import { Line, Points, Bars, StackedBar } from "../series";
|
|
6
|
+
import { getStackedIndex } from "../helpers";
|
|
7
|
+
const ActivePoint = () => {
|
|
8
|
+
const {
|
|
9
|
+
props: { data, groups },
|
|
10
|
+
activePoint,
|
|
11
|
+
activeSerie
|
|
12
|
+
} = useContext(ChartContext);
|
|
13
|
+
const lastActiveSerie = useRef(null);
|
|
14
|
+
const activeItem = useMemo(() => {
|
|
15
|
+
let item = null;
|
|
16
|
+
if (!activePoint && !activeSerie && lastActiveSerie.current) {
|
|
17
|
+
item = lastActiveSerie.current;
|
|
18
|
+
}
|
|
19
|
+
if (activeSerie) {
|
|
20
|
+
item = data.find((serie) => serie.key === activeSerie);
|
|
21
|
+
lastActiveSerie.current = item;
|
|
22
|
+
} else if (activePoint) {
|
|
23
|
+
item = data.find((serie) => serie.data.some((value) => activePoint === value.key));
|
|
24
|
+
lastActiveSerie.current = item;
|
|
25
|
+
} else if (!lastActiveSerie.current) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (item.type === "bar" && groups && getStackedIndex(groups, item.name) > -1) {
|
|
29
|
+
return /* @__PURE__ */ jsx(StackedBar, {
|
|
30
|
+
serie: item
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (item.type === "bar") {
|
|
34
|
+
return /* @__PURE__ */ jsx(Bars, {
|
|
35
|
+
serie: item
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (item.type === "point") {
|
|
39
|
+
return /* @__PURE__ */ jsx(Points, {
|
|
40
|
+
serie: item
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (item.type === "line") {
|
|
44
|
+
return /* @__PURE__ */ jsx(Line, {
|
|
45
|
+
serie: item
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}, [activePoint, activeSerie, data, groups]);
|
|
49
|
+
return /* @__PURE__ */ jsx("g", {
|
|
50
|
+
className: "redraw",
|
|
51
|
+
children: activeItem
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
ActivePoint
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=ActivePoint.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/parts/ActivePoint.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable arrow-body-style */\n/* eslint-disable indent */\nimport React, { useContext, useMemo, useRef } from 'react';\nimport { ChartContext } from '../ChartContext';\nimport { Line, Points, Bars, StackedBar } from '../series';\nimport { getStackedIndex } from '../helpers';\n\nexport const ActivePoint = () => {\n const {\n props: { data, groups },\n activePoint,\n activeSerie,\n } = useContext(ChartContext);\n\n const lastActiveSerie = useRef(null);\n const activeItem = useMemo(() => {\n let item = null;\n if (!activePoint && !activeSerie && lastActiveSerie.current) {\n item = lastActiveSerie.current;\n }\n if (activeSerie) {\n item = data.find((serie) => serie.key === activeSerie);\n lastActiveSerie.current = item;\n } else if (activePoint) {\n item = data.find((serie) => serie.data.some((value) => activePoint === value.key));\n lastActiveSerie.current = item;\n } else if (!lastActiveSerie.current) {\n return;\n }\n\n if (item.type === 'bar' && groups && getStackedIndex(groups, item.name) > -1) {\n return <StackedBar serie={item} />;\n }\n if (item.type === 'bar') {\n return <Bars serie={item} />;\n }\n if (item.type === 'point') {\n return <Points serie={item} />;\n }\n if (item.type === 'line') {\n return <Line serie={item} />;\n }\n }, [activePoint, activeSerie, data, groups]);\n\n return <g className=\"redraw\">{activeItem}</g>;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB;AAGA,SAAgB,YAAY,SAAS,cAAc;AACnD,SAAS,oBAAoB;AAC7B,SAAS,MAAM,QAAQ,MAAM,kBAAkB;AAC/C,SAAS,uBAAuB;AAEzB,MAAM,cAAc,MAAM;AAC/B,QAAM;AAAA,IACJ,OAAO,EAAE,MAAM,OAAO;AAAA,IACtB;AAAA,IACA;AAAA,EACF,IAAI,WAAW,YAAY;AAE3B,QAAM,kBAAkB,OAAO,IAAI;AACnC,QAAM,aAAa,QAAQ,MAAM;AAC/B,QAAI,OAAO;AACX,QAAI,CAAC,eAAe,CAAC,eAAe,gBAAgB,SAAS;AAC3D,aAAO,gBAAgB;AAAA,IACzB;AACA,QAAI,aAAa;AACf,aAAO,KAAK,KAAK,CAAC,UAAU,MAAM,QAAQ,WAAW;AACrD,sBAAgB,UAAU;AAAA,IAC5B,WAAW,aAAa;AACtB,aAAO,KAAK,KAAK,CAAC,UAAU,MAAM,KAAK,KAAK,CAAC,UAAU,gBAAgB,MAAM,GAAG,CAAC;AACjF,sBAAgB,UAAU;AAAA,IAC5B,WAAW,CAAC,gBAAgB,SAAS;AACnC;AAAA,IACF;AAEA,QAAI,KAAK,SAAS,SAAS,UAAU,gBAAgB,QAAQ,KAAK,IAAI,IAAI,IAAI;AAC5E,aAAO,oBAAC;AAAA,QAAW,OAAO;AAAA,OAAM;AAAA,IAClC;AACA,QAAI,KAAK,SAAS,OAAO;AACvB,aAAO,oBAAC;AAAA,QAAK,OAAO;AAAA,OAAM;AAAA,IAC5B;AACA,QAAI,KAAK,SAAS,SAAS;AACzB,aAAO,oBAAC;AAAA,QAAO,OAAO;AAAA,OAAM;AAAA,IAC9B;AACA,QAAI,KAAK,SAAS,QAAQ;AACxB,aAAO,oBAAC;AAAA,QAAK,OAAO;AAAA,OAAM;AAAA,IAC5B;AAAA,EACF,GAAG,CAAC,aAAa,aAAa,MAAM,MAAM,CAAC;AAE3C,SAAO,oBAAC;AAAA,IAAE,WAAU;AAAA,IAAU;AAAA,GAAW;AAC3C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useContext, useEffect, useRef } from "react";
|
|
4
|
+
import { select, axisBottom, timeFormat } from "d3";
|
|
5
|
+
import { StyledAxis, StyledGrid } from "../styles";
|
|
6
|
+
import { ChartContext } from "../ChartContext";
|
|
7
|
+
const AxisBottom = () => {
|
|
8
|
+
const {
|
|
9
|
+
props: { xAxis, xAxisLabelOffset = 50, xAxisLabel },
|
|
10
|
+
innerHeight,
|
|
11
|
+
innerWidth,
|
|
12
|
+
xScale,
|
|
13
|
+
tickOffset = 3
|
|
14
|
+
} = useContext(ChartContext);
|
|
15
|
+
const axisRef = useRef();
|
|
16
|
+
const gridRef = useRef();
|
|
17
|
+
const ticks = xScale.ticks?.();
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const grid = axisBottom(xScale).tickSize(xAxis?.showGrid ? -innerHeight : 0).tickFormat("").tickSizeOuter(0);
|
|
20
|
+
const axis = axisBottom(xScale);
|
|
21
|
+
if (xAxis.tickValues && ticks) {
|
|
22
|
+
console.log(ticks, "ticks");
|
|
23
|
+
const finalTicks = xAxis.overwriteTicks ? xAxis.tickValues : [...ticks, ...xAxis.tickValues];
|
|
24
|
+
axis.tickValues(finalTicks);
|
|
25
|
+
}
|
|
26
|
+
if (xAxis.tickFormat) {
|
|
27
|
+
if (typeof xAxis.tickFormat === "string") {
|
|
28
|
+
const formatGenerator = timeFormat(xAxis.tickFormat);
|
|
29
|
+
axis.tickFormat((d) => formatGenerator(d));
|
|
30
|
+
}
|
|
31
|
+
if (typeof xAxis.tickFormat === "function") {
|
|
32
|
+
axis.tickFormat(xAxis.tickFormat);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
select(gridRef.current).call(grid);
|
|
36
|
+
select(axisRef.current).call(axis);
|
|
37
|
+
}, [innerHeight, ticks, xAxis?.showGrid, xAxis.tickFormat, xAxis.tickValues, xScale]);
|
|
38
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
39
|
+
transform: `translate(0,${innerHeight})`,
|
|
40
|
+
children: [
|
|
41
|
+
/* @__PURE__ */ jsx(StyledAxis, {
|
|
42
|
+
ref: axisRef,
|
|
43
|
+
children: /* @__PURE__ */ jsx("text", {
|
|
44
|
+
className: "axis-label",
|
|
45
|
+
x: innerWidth / 2,
|
|
46
|
+
y: xAxisLabelOffset,
|
|
47
|
+
textAnchor: "middle",
|
|
48
|
+
children: xAxis.label
|
|
49
|
+
})
|
|
50
|
+
}),
|
|
51
|
+
/* @__PURE__ */ jsx(StyledGrid, {
|
|
52
|
+
ref: gridRef
|
|
53
|
+
})
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
AxisBottom
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=AxisBottom.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/parts/AxisBottom.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useEffect, useRef } from 'react';\nimport { select, axisBottom, timeFormat } from 'd3';\nimport { StyledAxis, StyledGrid } from '../styles';\nimport { ChartContext } from '../ChartContext';\n\nexport const AxisBottom = () => {\n const {\n props: { xAxis, xAxisLabelOffset = 50, xAxisLabel },\n innerHeight,\n innerWidth,\n xScale,\n tickOffset = 3,\n } = useContext(ChartContext);\n\n const axisRef = useRef();\n const gridRef = useRef();\n const ticks = xScale.ticks?.();\n useEffect(() => {\n const grid = axisBottom(xScale)\n .tickSize(xAxis?.showGrid ? -innerHeight : 0)\n .tickFormat('')\n .tickSizeOuter(0);\n\n const axis = axisBottom(xScale);\n\n if (xAxis.tickValues && ticks) {\n console.log(ticks, 'ticks');\n const finalTicks = xAxis.overwriteTicks ? xAxis.tickValues : [...ticks, ...xAxis.tickValues];\n axis.tickValues(finalTicks);\n }\n\n if (xAxis.tickFormat) {\n if (typeof xAxis.tickFormat === 'string') {\n const formatGenerator = timeFormat(xAxis.tickFormat);\n axis.tickFormat((d) => formatGenerator(d));\n }\n if (typeof xAxis.tickFormat === 'function') {\n axis.tickFormat(xAxis.tickFormat);\n }\n }\n\n select(gridRef.current).call(grid);\n select(axisRef.current).call(axis);\n }, [innerHeight, ticks, xAxis?.showGrid, xAxis.tickFormat, xAxis.tickValues, xScale]);\n\n return (\n <g transform={`translate(0,${innerHeight})`}>\n <StyledAxis ref={axisRef}>\n <text className=\"axis-label\" x={innerWidth / 2} y={xAxisLabelOffset} textAnchor=\"middle\">\n {xAxis.label}\n </text>\n </StyledAxis>\n <StyledGrid ref={gridRef}></StyledGrid>\n </g>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB;AAAA,SAAgB,YAAY,WAAW,cAAc;AACrD,SAAS,QAAQ,YAAY,kBAAkB;AAC/C,SAAS,YAAY,kBAAk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7E,gBAAM;AAAA,SACT;AAAA,OACF;AAAA,MACA,oBAAC;AAAA,QAAW,KAAK;AAAA,OAAS;AAAA;AAAA,GAC5B;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useContext, useEffect, useRef } from "react";
|
|
4
|
+
import { select, axisLeft } from "d3";
|
|
5
|
+
import { StyledAxis, StyledGrid } from "../styles";
|
|
6
|
+
import { ChartContext } from "../ChartContext";
|
|
7
|
+
const AxisLeft = () => {
|
|
8
|
+
const {
|
|
9
|
+
props: { yAxis, yAxisLabelOffset = 45, yAxisLabel },
|
|
10
|
+
innerHeight,
|
|
11
|
+
innerWidth,
|
|
12
|
+
yScale
|
|
13
|
+
} = useContext(ChartContext);
|
|
14
|
+
const ref = useRef();
|
|
15
|
+
const gridRef = useRef();
|
|
16
|
+
const ticks = yScale.ticks?.();
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const axis = axisLeft(yScale);
|
|
19
|
+
if (yAxis.tickValues && ticks) {
|
|
20
|
+
console.log(ticks, "ticks");
|
|
21
|
+
const finalTicks = yAxis.overwriteTicks ? yAxis.tickValues : [...ticks, ...yAxis.tickValues];
|
|
22
|
+
axis.tickValues(finalTicks);
|
|
23
|
+
}
|
|
24
|
+
if (yAxis.tickFormat) {
|
|
25
|
+
axis.tickFormat(yAxis.tickFormat);
|
|
26
|
+
}
|
|
27
|
+
const grid = axisLeft(yScale).tickFormat("").tickSize(yAxis?.showGrid ? -innerWidth : 0).tickSizeOuter(0);
|
|
28
|
+
select(ref.current).call(axis);
|
|
29
|
+
select(gridRef.current).call(grid);
|
|
30
|
+
}, [innerWidth, ticks, yAxis.overwriteTicks, yAxis?.showGrid, yAxis.tickFormat, yAxis.tickValues, yScale]);
|
|
31
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
32
|
+
children: [
|
|
33
|
+
/* @__PURE__ */ jsx(StyledAxis, {
|
|
34
|
+
ref,
|
|
35
|
+
color: yAxis.color,
|
|
36
|
+
children: /* @__PURE__ */ jsx("text", {
|
|
37
|
+
className: "axis-label",
|
|
38
|
+
textAnchor: "middle",
|
|
39
|
+
transform: `translate(${-yAxisLabelOffset},${innerHeight / 2}) rotate(-90)`,
|
|
40
|
+
children: yAxis?.label
|
|
41
|
+
})
|
|
42
|
+
}),
|
|
43
|
+
" ",
|
|
44
|
+
/* @__PURE__ */ jsx(StyledGrid, {
|
|
45
|
+
ref: gridRef
|
|
46
|
+
})
|
|
47
|
+
]
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
export {
|
|
51
|
+
AxisLeft
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=AxisLeft.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/parts/AxisLeft.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useEffect, useRef } from 'react';\nimport { select, axisLeft } from 'd3';\nimport { StyledAxis, StyledGrid } from '../styles';\nimport { ChartContext } from '../ChartContext';\n\nexport const AxisLeft = () => {\n const {\n props: { yAxis, yAxisLabelOffset = 45, yAxisLabel },\n innerHeight,\n innerWidth,\n yScale,\n } = useContext(ChartContext);\n\n const ref = useRef();\n const gridRef = useRef();\n const ticks = yScale.ticks?.();\n\n useEffect(() => {\n const axis = axisLeft(yScale);\n\n if (yAxis.tickValues && ticks) {\n console.log(ticks, 'ticks');\n const finalTicks = yAxis.overwriteTicks ? yAxis.tickValues : [...ticks, ...yAxis.tickValues];\n axis.tickValues(finalTicks);\n }\n\n if (yAxis.tickFormat) {\n axis.tickFormat(yAxis.tickFormat);\n }\n\n const grid = axisLeft(yScale)\n .tickFormat('')\n .tickSize(yAxis?.showGrid ? -innerWidth : 0)\n .tickSizeOuter(0);\n\n select(ref.current).call(axis);\n select(gridRef.current).call(grid);\n }, [innerWidth, ticks, yAxis.overwriteTicks, yAxis?.showGrid, yAxis.tickFormat, yAxis.tickValues, yScale]);\n return (\n <g>\n <StyledAxis ref={ref} color={yAxis.color}>\n <text\n className=\"axis-label\"\n textAnchor=\"middle\"\n transform={`translate(${-yAxisLabelOffset},${innerHeight / 2}) rotate(-90)`}\n >\n {yAxis?.label}\n </text>\n </StyledAxis>{' '}\n <StyledGrid ref={gridRef}></StyledGrid>\n </g>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB;AAAA,SAAgB,YAAY,WAAW,cAAc;AACrD,SAAS,QAAQ,gBAAgB;AACjC,SAAS,YAAY,kBAAkB;AACvC,SAAS,oBAAoB;AAEtB,MAAM,WAAW,MAAM;AAC5B,QAAM;AAAA,IACJ,OAAO,EAAE,OAAO,mBAAmB,IAAI,WAAW;AAAA,IAClD;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,YAAY;AAE3B,QAAM,MAAM,OAAO;AACnB,QAAM,UAAU,OAAO;AACvB,QAAM,QAAQ,OAAO,QAAQ;AAE7B,YAAU,MAAM;AACd,UAAM,OAAO,SAAS,MAAM;AAE5B,QAAI,MAAM,cAAc,OAAO;AAC7B,cAAQ,IAAI,OAAO,OAAO;AAC1B,YAAM,aAAa,MAAM,iBAAiB,MAAM,aAAa,CAAC,GAAG,OAAO,GAAG,MAAM,UAAU;AAC3F,WAAK,WAAW,UAAU;AAAA,IAC5B;AAEA,QAAI,MAAM,YAAY;AACpB,WAAK,WAAW,MAAM,UAAU;AAAA,IAClC;AAEA,UAAM,OAAO,SAAS,MAAM,EACzB,WAAW,EAAE,EACb,SAAS,OAAO,WAAW,CAAC,aAAa,CAAC,EAC1C,cAAc,CAAC;AAElB,WAAO,IAAI,OAAO,EAAE,KAAK,IAAI;AAC7B,WAAO,QAAQ,OAAO,EAAE,KAAK,IAAI;AAAA,EACnC,GAAG,CAAC,YAAY,OAAO,MAAM,gBAAgB,OAAO,UAAU,MAAM,YAAY,MAAM,YAAY,MAAM,CAAC;AACzG,SACE,qBAAC;AAAA,IACC;AAAA,0BAAC;AAAA,QAAW;AAAA,QAAU,OAAO,MAAM;AAAA,QACjC,8BAAC;AAAA,UACC,WAAU;AAAA,UACV,YAAW;AAAA,UACX,WAAW,aAAa,CAAC,oBAAoB,cAAc;AAAA,UAE1D,iBAAO;AAAA,SACV;AAAA,OACF;AAAA,MAAc;AAAA,MACd,oBAAC;AAAA,QAAW,KAAK;AAAA,OAAS;AAAA;AAAA,GAC5B;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext, useEffect, useRef } from "react";
|
|
4
|
+
import { select, axisRight } from "d3";
|
|
5
|
+
import { StyledAxis } from "../styles";
|
|
6
|
+
import { ChartContext } from "../ChartContext";
|
|
7
|
+
const AxisRight = () => {
|
|
8
|
+
const {
|
|
9
|
+
props: { y2Axis, yAxisLabelOffset = 45, y2AxisLabel },
|
|
10
|
+
innerHeight,
|
|
11
|
+
innerWidth,
|
|
12
|
+
y2Scale
|
|
13
|
+
} = useContext(ChartContext);
|
|
14
|
+
if (!y2Axis)
|
|
15
|
+
return null;
|
|
16
|
+
const ref = useRef();
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const axis = axisRight(y2Scale).tickSizeOuter(0);
|
|
19
|
+
select(ref.current).call(axis);
|
|
20
|
+
}, [innerWidth, y2Scale]);
|
|
21
|
+
return /* @__PURE__ */ jsx("g", {
|
|
22
|
+
transform: `translate(${innerWidth},0)`,
|
|
23
|
+
children: /* @__PURE__ */ jsx(StyledAxis, {
|
|
24
|
+
ref,
|
|
25
|
+
color: y2Axis.color,
|
|
26
|
+
children: /* @__PURE__ */ jsx("text", {
|
|
27
|
+
className: "axis-label",
|
|
28
|
+
textAnchor: "middle",
|
|
29
|
+
transform: `translate(${-yAxisLabelOffset},${innerHeight / 2}) rotate(-90)`
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
AxisRight
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=AxisRight.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/parts/AxisRight.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useEffect, useRef } from 'react';\nimport { select, axisRight } from 'd3';\nimport { StyledAxis } from '../styles';\nimport { ChartContext } from '../ChartContext';\n\nexport const AxisRight = () => {\n const {\n props: { y2Axis, yAxisLabelOffset = 45, y2AxisLabel },\n innerHeight,\n innerWidth,\n y2Scale,\n } = useContext(ChartContext);\n\n if (!y2Axis) return null;\n const ref = useRef();\n useEffect(() => {\n const axis = axisRight(y2Scale).tickSizeOuter(0);\n\n select(ref.current).call(axis);\n }, [innerWidth, y2Scale]);\n return (\n <g transform={`translate(${innerWidth},0)`}>\n <StyledAxis ref={ref} color={y2Axis.color}>\n <text\n className=\"axis-label\"\n textAnchor=\"middle\"\n transform={`translate(${-yAxisLabelOffset},${innerHeight / 2}) rotate(-90)`}\n >\n {/* {y2Axis?.label} */}\n </text>\n </StyledAxis>\n </g>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB;AAAA,SAAgB,YAAY,WAAW,cAAc;AACrD,SAAS,QAAQ,iBAAiB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAEtB,MAAM,YAAY,MAAM;AAC7B,QAAM;AAAA,IACJ,OAAO,EAAE,QAAQ,mBAAmB,IAAI,YAAY;AAAA,IACpD;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,YAAY;AAE3B,MAAI,CAAC;AAAQ,WAAO;AACpB,QAAM,MAAM,OAAO;AACnB,YAAU,MAAM;AACd,UAAM,OAAO,UAAU,OAAO,EAAE,cAAc,CAAC;AAE/C,WAAO,IAAI,OAAO,EAAE,KAAK,IAAI;AAAA,EAC/B,GAAG,CAAC,YAAY,OAAO,CAAC;AACxB,SACE,oBAAC;AAAA,IAAE,WAAW,aAAa;AAAA,IACzB,8BAAC;AAAA,MAAW;AAAA,MAAU,OAAO,OAAO;AAAA,MAClC,8BAAC;AAAA,QACC,WAAU;AAAA,QACV,YAAW;AAAA,QACX,WAAW,aAAa,CAAC,oBAAoB,cAAc;AAAA,OAG7D;AAAA,KACF;AAAA,GACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useContext, useCallback, useMemo } from "react";
|
|
4
|
+
import { StyledSVGWrapper } from "../styles";
|
|
5
|
+
import { ChartContext } from "../ChartContext";
|
|
6
|
+
import { useKeyboardNavigation } from "../config/useKeyboardNavigation";
|
|
7
|
+
const ChartContainer = ({ children }) => {
|
|
8
|
+
const {
|
|
9
|
+
props: { width, height, margin, responsive },
|
|
10
|
+
containerRef,
|
|
11
|
+
activePoint,
|
|
12
|
+
setScrapperPosY,
|
|
13
|
+
setScrapperPosX,
|
|
14
|
+
svgRef
|
|
15
|
+
} = useContext(ChartContext);
|
|
16
|
+
const dimensions = useMemo(
|
|
17
|
+
() => responsive ? {
|
|
18
|
+
viewBox: `0 0 ${width} ${height}`
|
|
19
|
+
} : {
|
|
20
|
+
width,
|
|
21
|
+
height
|
|
22
|
+
},
|
|
23
|
+
[height, responsive, width]
|
|
24
|
+
);
|
|
25
|
+
const { onInputKeyDown, handleOnBlur, handleOnFocus } = useKeyboardNavigation();
|
|
26
|
+
const onMouseLeaveHandler = useCallback(() => {
|
|
27
|
+
setScrapperPosY("");
|
|
28
|
+
setScrapperPosX("");
|
|
29
|
+
}, [setScrapperPosX, setScrapperPosY]);
|
|
30
|
+
return /* @__PURE__ */ jsx(StyledSVGWrapper, {
|
|
31
|
+
ref: containerRef,
|
|
32
|
+
onKeyDown: onInputKeyDown,
|
|
33
|
+
"aria-hidden": "true",
|
|
34
|
+
tabIndex: activePoint ? -1 : 0,
|
|
35
|
+
onBlur: handleOnBlur,
|
|
36
|
+
onFocus: handleOnFocus,
|
|
37
|
+
onMouseLeave: onMouseLeaveHandler,
|
|
38
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
39
|
+
ref: svgRef,
|
|
40
|
+
...dimensions,
|
|
41
|
+
children: /* @__PURE__ */ jsx("g", {
|
|
42
|
+
className: "container",
|
|
43
|
+
transform: `translate(${margin.left},${margin.top})`,
|
|
44
|
+
children
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
ChartContainer
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=ChartContainer.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../src/graphs/Chart/parts/ChartContainer.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useCallback, useMemo } from 'react';\nimport { StyledSVGWrapper } from '../styles';\n\nimport { ChartContext } from '../ChartContext';\nimport { useKeyboardNavigation } from '../config/useKeyboardNavigation';\ninterface ChartContainerT {\n children: JSX.Element | JSX.Element[] | string | string[];\n}\nexport const ChartContainer: React.ComponentType<ChartContainerT> = ({ children }) => {\n const {\n props: { width, height, margin, responsive },\n containerRef,\n activePoint,\n setScrapperPosY,\n setScrapperPosX,\n svgRef,\n } = useContext(ChartContext);\n\n const dimensions = useMemo(\n () =>\n responsive\n ? {\n viewBox: `0 0 ${width} ${height}`,\n }\n : {\n width,\n height,\n },\n [height, responsive, width],\n );\n const { onInputKeyDown, handleOnBlur, handleOnFocus } = useKeyboardNavigation();\n\n const onMouseLeaveHandler = useCallback(() => {\n setScrapperPosY('');\n setScrapperPosX('');\n }, [setScrapperPosX, setScrapperPosY]);\n\n return (\n <StyledSVGWrapper\n ref={containerRef}\n onKeyDown={onInputKeyDown}\n aria-hidden=\"true\"\n tabIndex={activePoint ? -1 : 0}\n onBlur={handleOnBlur}\n onFocus={handleOnFocus}\n // onMouseDown={(e) => e.preventDefault()}\n onMouseLeave={onMouseLeaveHandler}\n >\n <svg ref={svgRef} {...dimensions}>\n <g className=\"container\" transform={`translate(${margin.left},${margin.top})`}>\n {children}\n </g>\n </svg>\n </StyledSVGWrapper>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB;AAAA,SAAgB,YAAY,aAAa,eAAe;AACxD,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAI/B,MAAM,iBAAuD,CAAC,EAAE,SAAS,MAAM;AACpF,QAAM;AAAA,IACJ,OAAO,EAAE,OAAO,QAAQ,QAAQ,WAAW;AAAA,IAC3C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,YAAY;AAE3B,QAAM,aAAa;AAAA,IACjB,MACE,aACI;AAAA,MACE,SAAS,OAAO,SAAS;AAAA,IAC3B,IACA;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAAA,IACN,CAAC,QAAQ,YAAY,KAAK;AAAA,EAC5B;AACA,QAAM,EAAE,gBAAgB,cAAc,cAAc,IAAI,sBAAsB;AAE9E,QAAM,sBAAsB,YAAY,MAAM;AAC5C,oBAAgB,EAAE;AAClB,oBAAgB,EAAE;AAAA,EACpB,GAAG,CAAC,iBAAiB,eAAe,CAAC;AAErC,SACE,oBAAC;AAAA,IACC,KAAK;AAAA,IACL,WAAW;AAAA,IACX,eAAY;AAAA,IACZ,UAAU,cAAc,KAAK;AAAA,IAC7B,QAAQ;AAAA,IACR,SAAS;AAAA,IAET,cAAc;AAAA,IAEd,8BAAC;AAAA,MAAI,KAAK;AAAA,MAAS,GAAG;AAAA,MACpB,8BAAC;AAAA,QAAE,WAAU;AAAA,QAAY,WAAW,aAAa,OAAO,QAAQ,OAAO;AAAA,QACpE;AAAA,OACH;AAAA,KACF;AAAA,GACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|