@elliemae/ds-dataviz 3.13.0-next.4 → 3.13.0
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/ChartContext.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useChart.js +55 -10
- package/dist/cjs/graphs/Chart/config/useChart.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useInternalMargins.js +48 -19
- package/dist/cjs/graphs/Chart/config/useInternalMargins.js.map +3 -3
- package/dist/cjs/graphs/Chart/config/useKeyboardNavigation.js +89 -7
- package/dist/cjs/graphs/Chart/config/useKeyboardNavigation.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useScales.js +25 -12
- package/dist/cjs/graphs/Chart/config/useScales.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useValidateProps.js +37 -0
- package/dist/cjs/graphs/Chart/config/useValidateProps.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/Axis/AxisBottom.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/ChartContainer.js +28 -10
- package/dist/cjs/graphs/Chart/parts/ChartContainer.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Labels/LeftLabel.js +5 -5
- package/dist/cjs/graphs/Chart/parts/Labels/LeftLabel.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Legend/BottomLegend.js +43 -43
- package/dist/cjs/graphs/Chart/parts/Legend/BottomLegend.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Legend/LeftLegend.js +12 -8
- package/dist/cjs/graphs/Chart/parts/Legend/LeftLegend.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Legend/LegendItem.js +4 -10
- package/dist/cjs/graphs/Chart/parts/Legend/LegendItem.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Legend/RightLegend.js +5 -9
- package/dist/cjs/graphs/Chart/parts/Legend/RightLegend.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Legend/TopLegend.js +21 -18
- package/dist/cjs/graphs/Chart/parts/Legend/TopLegend.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Scroller/Controllers.js +42 -19
- package/dist/cjs/graphs/Chart/parts/Scroller/Controllers.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Scroller/ScrollableContainerX.js +28 -18
- package/dist/cjs/graphs/Chart/parts/Scroller/ScrollableContainerX.js.map +2 -2
- package/dist/cjs/graphs/Chart/react-desc-prop-types.js +14 -1
- package/dist/cjs/graphs/Chart/react-desc-prop-types.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/Bars.js +2 -2
- package/dist/cjs/graphs/Chart/series/Bars.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/Point.js +1 -2
- package/dist/cjs/graphs/Chart/series/Point.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/Rect.js +2 -2
- package/dist/cjs/graphs/Chart/series/Rect.js.map +1 -1
- package/dist/cjs/graphs/Chart/series/StackedBar.js +1 -1
- package/dist/cjs/graphs/Chart/series/StackedBar.js.map +1 -1
- package/dist/cjs/graphs/constants.js +7 -0
- package/dist/cjs/graphs/constants.js.map +2 -2
- package/dist/esm/graphs/Chart/ChartContext.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useChart.js +55 -10
- package/dist/esm/graphs/Chart/config/useChart.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useInternalMargins.js +49 -20
- package/dist/esm/graphs/Chart/config/useInternalMargins.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useKeyboardNavigation.js +90 -8
- package/dist/esm/graphs/Chart/config/useKeyboardNavigation.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useScales.js +25 -12
- package/dist/esm/graphs/Chart/config/useScales.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useValidateProps.js +11 -0
- package/dist/esm/graphs/Chart/config/useValidateProps.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/Axis/AxisBottom.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/ChartContainer.js +28 -10
- package/dist/esm/graphs/Chart/parts/ChartContainer.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Labels/LeftLabel.js +5 -5
- package/dist/esm/graphs/Chart/parts/Labels/LeftLabel.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Legend/BottomLegend.js +44 -44
- package/dist/esm/graphs/Chart/parts/Legend/BottomLegend.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Legend/LeftLegend.js +13 -9
- package/dist/esm/graphs/Chart/parts/Legend/LeftLegend.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Legend/LegendItem.js +4 -10
- package/dist/esm/graphs/Chart/parts/Legend/LegendItem.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Legend/RightLegend.js +6 -10
- package/dist/esm/graphs/Chart/parts/Legend/RightLegend.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Legend/TopLegend.js +23 -20
- package/dist/esm/graphs/Chart/parts/Legend/TopLegend.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Scroller/Controllers.js +44 -21
- package/dist/esm/graphs/Chart/parts/Scroller/Controllers.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Scroller/ScrollableContainerX.js +29 -19
- package/dist/esm/graphs/Chart/parts/Scroller/ScrollableContainerX.js.map +2 -2
- package/dist/esm/graphs/Chart/react-desc-prop-types.js +14 -1
- package/dist/esm/graphs/Chart/react-desc-prop-types.js.map +2 -2
- package/dist/esm/graphs/Chart/series/Bars.js +2 -2
- package/dist/esm/graphs/Chart/series/Bars.js.map +2 -2
- package/dist/esm/graphs/Chart/series/Point.js +1 -2
- package/dist/esm/graphs/Chart/series/Point.js.map +2 -2
- package/dist/esm/graphs/Chart/series/Rect.js +2 -2
- package/dist/esm/graphs/Chart/series/Rect.js.map +1 -1
- package/dist/esm/graphs/Chart/series/StackedBar.js +1 -1
- package/dist/esm/graphs/Chart/series/StackedBar.js.map +1 -1
- package/dist/esm/graphs/constants.js +7 -0
- package/dist/esm/graphs/constants.js.map +2 -2
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/graphs/Chart/ChartContext.tsx", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import type React from 'react';\nimport { createContext, createRef } from 'react';\nimport type { ScaleLinear, ScaleBand, ScaleOrdinal } from 'd3';\nimport { scaleLinear, scaleBand, scaleOrdinal } from 'd3';\nimport type { DSChartT } from './react-desc-prop-types';\nimport { defaultProps } from './react-desc-prop-types';\ninterface ContextT {\n props: DSChartT.Props;\n currentData: DSChartT.InternalData;\n xScale: ScaleLinear<number, number, never> | ScaleBand<string>;\n yScale: ScaleLinear<number, number, never> | ScaleBand<string>;\n y2Scale: ScaleLinear<number, number, never>;\n innerHeight: number;\n innerWidth: number;\n activePoint: DSChartT.InternalDatum | null;\n containerRef: React.RefObject<HTMLDivElement>;\n groups: string[];\n subGroupScale?: ScaleBand<string> | null;\n colorScale: ScaleOrdinal<string, unknown, string>;\n axisLeftRef: SVGGElement | null;\n scrapperPosY: string;\n scrapperPosX: string;\n xScrollbarPosition: number;\n isGrabbed: boolean;\n startPosition: number;\n isScrollbarVisible: boolean;\n lastPosition: React.MutableRefObject<number>;\n containerRatio: number;\n internalMargin: {\n bottom: number;\n top: number;\n right: number;\n left: number;\n };\n leftLegendWidth: number;\n leftLegend: SVGGElement;\n rightLegend: SVGGElement;\n axisBottomHeight: number;\n bottomLabelHeight: number;\n rightLabelWidth: number;\n axisRightWidth: number;\n isHorizontal: boolean;\n leftLabel: SVGGElement;\n chartId: string;\n hiddenSeries: string[];\n stackedData: DSChartT.StackedSeriesByGroupT;\n setActivePoint: React.Dispatch<React.SetStateAction<DSChartT.InternalDatum | null>>;\n setLeftAxisRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getBandwidth: () => number;\n setScrapperPosY: React.Dispatch<React.SetStateAction<string>>;\n setScrapperPosX: React.Dispatch<React.SetStateAction<string>>;\n setXScrollbarPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsGrabbed: React.Dispatch<React.SetStateAction<boolean>>;\n setStartPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsScrollbarVisible: React.Dispatch<React.SetStateAction<boolean>>;\n setAxisLeftRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setTopLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisBottomRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisRightRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getXValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n getYValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n setHiddenSeries: React.Dispatch<React.SetStateAction<string[]>>;\n getXScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n getYScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n}\nconst defaultContext: ContextT = {\n props: defaultProps,\n xScale: scaleBand(),\n yScale: scaleLinear(),\n innerHeight: 0,\n innerWidth: 0,\n activePoint: null,\n setActivePoint: () => {},\n scrapperPosY: '',\n setScrapperPosY: () => {},\n containerRef: createRef<HTMLDivElement>(),\n groups: [],\n colorScale: scaleOrdinal(),\n setLeftAxisRef: () => {},\n};\nexport const ChartContext = createContext(defaultContext);\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAAyC;AAEzC,gBAAqD;AAErD,mCAA6B;
|
|
4
|
+
"sourcesContent": ["import type React from 'react';\nimport { createContext, createRef } from 'react';\nimport type { ScaleLinear, ScaleBand, ScaleOrdinal } from 'd3';\nimport { scaleLinear, scaleBand, scaleOrdinal } from 'd3';\nimport type { DSChartT } from './react-desc-prop-types';\nimport { defaultProps } from './react-desc-prop-types';\ninterface ContextT {\n props: DSChartT.Props;\n originalSeries: DSChartT.SeriesT;\n currentData: DSChartT.InternalData;\n xScale: ScaleLinear<number, number, never> | ScaleBand<string>;\n yScale: ScaleLinear<number, number, never> | ScaleBand<string>;\n y2Scale: ScaleLinear<number, number, never>;\n innerHeight: number;\n innerWidth: number;\n activePoint: DSChartT.InternalDatum | null;\n containerRef: React.RefObject<HTMLDivElement>;\n groups: string[];\n subGroupScale?: ScaleBand<string> | null;\n colorScale: ScaleOrdinal<string, unknown, string>;\n axisLeftRef: SVGGElement | null;\n scrapperPosY: string;\n scrapperPosX: string;\n xScrollbarPosition: number;\n isGrabbed: boolean;\n startPosition: number;\n isScrollbarVisible: boolean;\n lastPosition: React.MutableRefObject<number>;\n containerRatio: number;\n internalMargin: {\n bottom: number;\n top: number;\n right: number;\n left: number;\n };\n toolbarHeight: number;\n leftLegendHeight: number;\n rightLegendHeight: number;\n leftLabelHeight: number;\n leftLegendWidth: number;\n leftLegend: SVGGElement;\n bottomLegend: SVGGElement;\n rightLegend: SVGGElement;\n axisBottomHeight: number;\n bottomLabelHeight: number;\n rightLabelWidth: number;\n axisRightWidth: number;\n isHorizontal: boolean;\n leftLabel: SVGGElement;\n chartId: string;\n hiddenSeries: string[];\n stackedData: DSChartT.StackedSeriesByGroupT;\n width: number;\n height: number;\n setActivePoint: React.Dispatch<React.SetStateAction<DSChartT.InternalDatum | null>>;\n setLeftAxisRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getBandwidth: () => number;\n setScrapperPosY: React.Dispatch<React.SetStateAction<string>>;\n setScrapperPosX: React.Dispatch<React.SetStateAction<string>>;\n setXScrollbarPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsGrabbed: React.Dispatch<React.SetStateAction<boolean>>;\n setStartPosition: React.Dispatch<React.SetStateAction<number>>;\n setIsScrollbarVisible: React.Dispatch<React.SetStateAction<boolean>>;\n setAxisLeftRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setTopLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLegend: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisBottomRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setLeftLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setAxisRightRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setRightLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n setBottomLabel: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n getXValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n getYValue: (datum: DSChartT.InternalDatum) => string | number | Date;\n setHiddenSeries: React.Dispatch<React.SetStateAction<string[]>>;\n getXScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n getYScaleValue: (datum: DSChartT.InternalDatum) => number | undefined;\n setContainerRatio: React.Dispatch<React.SetStateAction<number>>;\n setToolbarRef: React.Dispatch<React.SetStateAction<SVGGElement | null>>;\n}\nconst defaultContext: ContextT = {\n props: defaultProps,\n xScale: scaleBand(),\n yScale: scaleLinear(),\n innerHeight: 0,\n innerWidth: 0,\n activePoint: null,\n setActivePoint: () => {},\n scrapperPosY: '',\n setScrapperPosY: () => {},\n containerRef: createRef<HTMLDivElement>(),\n groups: [],\n colorScale: scaleOrdinal(),\n setLeftAxisRef: () => {},\n};\nexport const ChartContext = createContext(defaultContext);\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAAyC;AAEzC,gBAAqD;AAErD,mCAA6B;AA4E7B,MAAM,iBAA2B;AAAA,EAC/B,OAAO;AAAA,EACP,YAAQ,qBAAU;AAAA,EAClB,YAAQ,uBAAY;AAAA,EACpB,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,gBAAgB,MAAM;AAAA,EAAC;AAAA,EACvB,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAAA,EACxB,kBAAc,wBAA0B;AAAA,EACxC,QAAQ,CAAC;AAAA,EACT,gBAAY,wBAAa;AAAA,EACzB,gBAAgB,MAAM;AAAA,EAAC;AACzB;AACO,MAAM,mBAAe,4BAAc,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -31,20 +31,22 @@ var React = __toESM(require("react"));
|
|
|
31
31
|
var import_react = require("react");
|
|
32
32
|
var import_uid = require("uid");
|
|
33
33
|
var import_lodash = require("lodash");
|
|
34
|
+
var import_react_desc_prop_types = require("../react-desc-prop-types");
|
|
34
35
|
var import_useScales = require("./useScales");
|
|
35
36
|
var import_helpers = require("../helpers");
|
|
36
37
|
var import_useInternalMargins = require("./useInternalMargins");
|
|
37
38
|
var import_useGetters = require("./useGetters");
|
|
38
39
|
var import_resize_observer_polyfill = __toESM(require("resize-observer-polyfill"));
|
|
40
|
+
var import_useValidateProps = require("./useValidateProps");
|
|
39
41
|
const useResizeObserver = (ref) => {
|
|
40
|
-
const [dimensions, setDimensions] = (0, import_react.useState)(
|
|
42
|
+
const [dimensions, setDimensions] = (0, import_react.useState)(0);
|
|
41
43
|
(0, import_react.useEffect)(() => {
|
|
42
44
|
if (ref) {
|
|
43
45
|
const observeTarget = ref;
|
|
44
46
|
const resizeObserver = new import_resize_observer_polyfill.default(
|
|
45
47
|
(0, import_lodash.debounce)((entries) => {
|
|
46
48
|
entries.forEach((entry) => {
|
|
47
|
-
setDimensions(entry.contentRect);
|
|
49
|
+
setDimensions(Math.ceil(entry.contentRect.width));
|
|
48
50
|
});
|
|
49
51
|
}, 200)
|
|
50
52
|
);
|
|
@@ -57,14 +59,24 @@ const useResizeObserver = (ref) => {
|
|
|
57
59
|
return dimensions;
|
|
58
60
|
};
|
|
59
61
|
const useChart = (props) => {
|
|
62
|
+
(0, import_useValidateProps.useValidateProps)(props, import_react_desc_prop_types.propTypes);
|
|
60
63
|
const { series, yAxis, xAxis, width: userWidth, height: userHeight, groups: groupsStacked } = props;
|
|
64
|
+
const originalSeries = (0, import_react.useMemo)(() => {
|
|
65
|
+
if (series.length === 0) {
|
|
66
|
+
return import_react_desc_prop_types.defaultProps.series;
|
|
67
|
+
}
|
|
68
|
+
return series;
|
|
69
|
+
}, [series]);
|
|
61
70
|
const [containerRef, setContainerRef] = (0, import_react.useState)(null);
|
|
62
71
|
const svgRef = (0, import_react.useRef)(null);
|
|
63
|
-
const
|
|
64
|
-
const width = (0, import_react.useMemo)(() => userWidth ??
|
|
72
|
+
const dimensionWidth = useResizeObserver(containerRef);
|
|
73
|
+
const width = (0, import_react.useMemo)(() => userWidth ?? dimensionWidth ?? 0, [dimensionWidth, userWidth]);
|
|
65
74
|
const height = (0, import_react.useMemo)(() => userHeight ?? 500, [userHeight]);
|
|
66
75
|
const [isGrabbed, setIsGrabbed] = (0, import_react.useState)(false);
|
|
67
76
|
const [startPosition, setStartPosition] = (0, import_react.useState)(0);
|
|
77
|
+
const [isZooming, setIsZooming] = (0, import_react.useState)(false);
|
|
78
|
+
const [zoomStartingPosition, setZoomStartingPosition] = (0, import_react.useState)(0);
|
|
79
|
+
const [movingPosition, setMovingPosition] = (0, import_react.useState)(0);
|
|
68
80
|
const [activePoint, setActivePoint] = (0, import_react.useState)(null);
|
|
69
81
|
const [activeSerie, setActiveSerie] = (0, import_react.useState)("");
|
|
70
82
|
const [scrapperPosY, setScrapperPosY] = (0, import_react.useState)("");
|
|
@@ -93,7 +105,14 @@ const useChart = (props) => {
|
|
|
93
105
|
bottomLabelHeight,
|
|
94
106
|
internalMargin,
|
|
95
107
|
leftLegendWidth,
|
|
96
|
-
rightLabelWidth
|
|
108
|
+
rightLabelWidth,
|
|
109
|
+
leftLabelHeight,
|
|
110
|
+
rightLegendHeight,
|
|
111
|
+
bottomLegendWidth,
|
|
112
|
+
leftLabelWidth,
|
|
113
|
+
axisLeftWidth,
|
|
114
|
+
topLegendHeight,
|
|
115
|
+
leftLegendHeight
|
|
97
116
|
} = (0, import_useInternalMargins.useInternalMargins)({
|
|
98
117
|
axisLeftRef,
|
|
99
118
|
axisBottomRef,
|
|
@@ -117,7 +136,7 @@ const useChart = (props) => {
|
|
|
117
136
|
);
|
|
118
137
|
const [hiddenSeries, setHiddenSeries] = (0, import_react.useState)([]);
|
|
119
138
|
const currentData = (0, import_react.useMemo)(
|
|
120
|
-
() =>
|
|
139
|
+
() => originalSeries.filter((serie) => !hiddenSeries.includes(serie.name)).map((d, i) => ({
|
|
121
140
|
...d,
|
|
122
141
|
key: `${d.name}-${i}`,
|
|
123
142
|
data: d.data.map((value, index) => ({
|
|
@@ -128,12 +147,13 @@ const useChart = (props) => {
|
|
|
128
147
|
scale: d.scale
|
|
129
148
|
})).filter((datum) => datum.value !== null && datum.value !== void 0)
|
|
130
149
|
})),
|
|
131
|
-
[hiddenSeries,
|
|
150
|
+
[hiddenSeries, originalSeries]
|
|
132
151
|
);
|
|
133
152
|
const stackedData = (0, import_react.useMemo)(() => (0, import_helpers.stackData)(groupsStacked, currentData), [groupsStacked, currentData]);
|
|
134
153
|
const groups = (0, import_react.useMemo)(() => currentData.map((serie) => serie.name), [currentData]);
|
|
135
154
|
const { xScale, yScale, y2Scale, subGroupScale, colorScale, getBandwidth } = (0, import_useScales.useScales)({
|
|
136
155
|
props,
|
|
156
|
+
originalSeries,
|
|
137
157
|
innerHeight,
|
|
138
158
|
innerWidth,
|
|
139
159
|
groups,
|
|
@@ -154,6 +174,13 @@ const useChart = (props) => {
|
|
|
154
174
|
return (0, import_react.useMemo)(
|
|
155
175
|
() => ({
|
|
156
176
|
props,
|
|
177
|
+
originalSeries,
|
|
178
|
+
isZooming,
|
|
179
|
+
setIsZooming,
|
|
180
|
+
zoomStartingPosition,
|
|
181
|
+
setZoomStartingPosition,
|
|
182
|
+
setMovingPosition,
|
|
183
|
+
movingPosition,
|
|
157
184
|
innerHeight,
|
|
158
185
|
innerWidth,
|
|
159
186
|
groups,
|
|
@@ -218,10 +245,22 @@ const useChart = (props) => {
|
|
|
218
245
|
width,
|
|
219
246
|
setContainerRatio,
|
|
220
247
|
toolbarHeight,
|
|
221
|
-
setToolbarRef
|
|
248
|
+
setToolbarRef,
|
|
249
|
+
leftLabelHeight,
|
|
250
|
+
rightLegendHeight,
|
|
251
|
+
bottomLegendWidth,
|
|
252
|
+
bottomLegend,
|
|
253
|
+
leftLabelWidth,
|
|
254
|
+
axisLeftWidth,
|
|
255
|
+
topLegendHeight,
|
|
256
|
+
leftLegendHeight
|
|
222
257
|
}),
|
|
223
258
|
[
|
|
224
259
|
props,
|
|
260
|
+
originalSeries,
|
|
261
|
+
isZooming,
|
|
262
|
+
zoomStartingPosition,
|
|
263
|
+
movingPosition,
|
|
225
264
|
innerHeight,
|
|
226
265
|
innerWidth,
|
|
227
266
|
groups,
|
|
@@ -262,9 +301,15 @@ const useChart = (props) => {
|
|
|
262
301
|
hiddenSeries,
|
|
263
302
|
height,
|
|
264
303
|
width,
|
|
265
|
-
setContainerRatio,
|
|
266
304
|
toolbarHeight,
|
|
267
|
-
|
|
305
|
+
leftLabelHeight,
|
|
306
|
+
rightLegendHeight,
|
|
307
|
+
bottomLegendWidth,
|
|
308
|
+
bottomLegend,
|
|
309
|
+
leftLabelWidth,
|
|
310
|
+
axisLeftWidth,
|
|
311
|
+
topLegendHeight,
|
|
312
|
+
leftLegendHeight
|
|
268
313
|
]
|
|
269
314
|
);
|
|
270
315
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/graphs/Chart/config/useChart.tsx", "../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable max-nested-callbacks */\n/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useState, useEffect, useRef } from 'react';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAqD;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable max-nested-callbacks */\n/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useState, useEffect, useRef } from 'react';\nimport { useMemoMergePropsWithDefault } from '@elliemae/ds-utilities';\nimport { uid } from 'uid';\nimport { debounce } from 'lodash';\nimport type { ScaleBand } from 'd3';\nimport type { DSChartT } from '../react-desc-prop-types';\nimport { defaultProps, propTypes } from '../react-desc-prop-types';\nimport { useScales } from './useScales';\nimport { stackData } from '../helpers';\nimport { useInternalMargins } from './useInternalMargins';\nimport { useGetters } from './useGetters';\nimport ResizeObserver from 'resize-observer-polyfill';\nimport { useValidateProps } from './useValidateProps';\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst useResizeObserver = (ref: HTMLElement | null | undefined) => {\n const [dimensions, setDimensions] = useState<number>(0);\n\n useEffect(() => {\n if (ref) {\n const observeTarget = ref;\n const resizeObserver = new ResizeObserver(\n debounce((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setDimensions(Math.ceil(entry.contentRect.width));\n });\n }, 200),\n );\n resizeObserver.observe(observeTarget);\n\n return () => {\n resizeObserver.unobserve(observeTarget);\n };\n }\n }, [ref]);\n return dimensions;\n};\n\nexport const useChart = (props: DSChartT.Props) => {\n useValidateProps(props, propTypes);\n\n // const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);\n const { series, yAxis, xAxis, width: userWidth, height: userHeight, groups: groupsStacked } = props;\n\n const originalSeries = useMemo(() => {\n if (series.length === 0) {\n return defaultProps.series;\n }\n return series;\n }, [series]);\n const [containerRef, setContainerRef] = useState<HTMLDivElement | null>(null);\n const svgRef = useRef(null);\n\n const dimensionWidth = useResizeObserver(containerRef);\n const width = useMemo(() => userWidth ?? dimensionWidth ?? 0, [dimensionWidth, userWidth]);\n\n const height = useMemo(() => userHeight ?? 500, [userHeight]);\n\n const [isGrabbed, setIsGrabbed] = useState(false);\n const [startPosition, setStartPosition] = useState(0);\n\n // zoom\n\n const [isZooming, setIsZooming] = useState(false);\n const [zoomStartingPosition, setZoomStartingPosition] = useState(0);\n const [movingPosition, setMovingPosition] = useState(0);\n\n //\n\n const [activePoint, setActivePoint] = useState(null);\n const [activeSerie, setActiveSerie] = useState('');\n const [scrapperPosY, setScrapperPosY] = useState('');\n const [scrapperPosX, setScrapperPosX] = useState('');\n const [xScrollbarPosition, setXScrollbarPosition] = useState(0);\n const [isScrollbarVisible, setIsScrollbarVisible] = useState(false);\n const [containerRatio, setContainerRatio] = useState(\n props?.xAxis.advanced?.pointSpacing?.value ?? props?.yAxis.advanced?.pointSpacing?.value ?? 1,\n );\n\n const lastPosition = useRef(0);\n\n const [axisLeftRef, setAxisLeftRef] = useState<SVGGElement | null>(null);\n const [axisBottomRef, setAxisBottomRef] = useState<SVGGElement | null>(null);\n const [axisRightRef, setAxisRightRef] = useState<SVGGElement | null>(null);\n\n const [leftLegend, setLeftLegend] = useState<SVGGElement | null>(null);\n const [rightLegend, setRightLegend] = useState<SVGGElement | null>(null);\n const [topLegend, setTopLegend] = useState<SVGGElement | null>(null);\n const [bottomLegend, setBottomLegend] = useState<SVGGElement | null>(null);\n\n const [rightLabel, setRightLabel] = useState<SVGGElement | null>(null);\n const [leftLabel, setLeftLabel] = useState<SVGGElement | null>(null);\n const [bottomLabel, setBottomLabel] = useState<SVGGElement | null>(null);\n\n const [toolbarRef, setToolbarRef] = useState<SVGGElement | null>(null);\n\n const {\n toolbarHeight,\n axisBottomHeight,\n axisRightWidth,\n bottomLabelHeight,\n internalMargin,\n leftLegendWidth,\n rightLabelWidth,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n } = useInternalMargins({\n axisLeftRef,\n axisBottomRef,\n axisRightRef,\n leftLabel,\n leftLegend,\n rightLegend,\n topLegend,\n bottomLegend,\n rightLabel,\n bottomLabel,\n toolbarRef,\n });\n\n const innerWidth = useMemo(\n () => width - internalMargin.left - internalMargin.right,\n [internalMargin.left, internalMargin.right, width],\n );\n const innerHeight = useMemo(\n () => height - internalMargin.top - internalMargin.bottom,\n [internalMargin.top, internalMargin.bottom, height],\n );\n\n const [hiddenSeries, setHiddenSeries] = useState<string[]>([]);\n\n const currentData = useMemo(\n () =>\n originalSeries\n .filter((serie) => !hiddenSeries.includes(serie.name))\n .map((d, i) => ({\n ...d,\n key: `${d.name}-${i}`,\n data: d.data\n .map((value, index) => ({\n key: `${d.name}-${i}-${index}`,\n value,\n position: index,\n serie: d.name,\n scale: d.scale,\n }))\n .filter((datum) => datum.value !== null && datum.value !== undefined), // basically converting from DSChartT.SeriesT to DSChartT.InternalData...\n })) as DSChartT.InternalData,\n [hiddenSeries, originalSeries],\n );\n\n const stackedData = useMemo(() => stackData(groupsStacked, currentData), [groupsStacked, currentData]);\n\n // @TODO we need to create a logic to get this from both axis\n // const containerRatio = props?.xAxis.advanced?.pointSpacing?.value ?? props?.yAxis.advanced?.pointSpacing?.value ?? 1;\n\n const groups = useMemo(() => currentData.map((serie) => serie.name), [currentData]);\n\n const { xScale, yScale, y2Scale, subGroupScale, colorScale, getBandwidth } = useScales({\n props,\n originalSeries,\n innerHeight,\n innerWidth,\n groups,\n stackedData,\n currentData,\n containerRatio,\n });\n\n const isHorizontal = useMemo(() => !!(yScale as ScaleBand<string>).bandwidth, [yScale]);\n\n const { getXValue, getYValue, getXScaleValue, getYScaleValue } = useGetters({\n xAxis,\n yAxis,\n isHorizontal,\n xScale,\n yScale,\n y2Scale,\n });\n const chartId = useMemo(() => uid(6), []);\n\n return useMemo(\n () => ({\n props,\n originalSeries,\n isZooming,\n setIsZooming,\n zoomStartingPosition,\n setZoomStartingPosition,\n setMovingPosition,\n movingPosition,\n innerHeight,\n innerWidth,\n groups,\n currentData,\n colorScale,\n stackedData,\n subGroupScale,\n svgRef,\n xScale,\n yScale,\n y2Scale,\n containerRef,\n getBandwidth,\n scrapperPosY,\n setScrapperPosY,\n scrapperPosX,\n setScrapperPosX,\n activePoint,\n setActivePoint,\n activeSerie,\n setActiveSerie,\n xScrollbarPosition,\n setXScrollbarPosition,\n isGrabbed,\n setIsGrabbed,\n setContainerRef,\n startPosition,\n setStartPosition,\n isScrollbarVisible,\n setIsScrollbarVisible,\n lastPosition,\n containerRatio,\n internalMargin,\n axisLeftRef,\n leftLegendWidth,\n leftLegend,\n setAxisLeftRef,\n setLeftLegend,\n setRightLegend,\n rightLegend,\n setTopLegend,\n setBottomLegend,\n setAxisBottomRef,\n axisBottomHeight,\n setAxisRightRef,\n setRightLabel,\n setBottomLabel,\n getXScaleValue,\n getYScaleValue,\n bottomLabelHeight,\n rightLabelWidth,\n axisRightWidth,\n getXValue,\n getYValue,\n isHorizontal,\n setLeftLabel,\n leftLabel,\n chartId,\n hiddenSeries,\n setHiddenSeries,\n height,\n width,\n setContainerRatio,\n toolbarHeight,\n setToolbarRef,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n bottomLegend,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n }),\n [\n props,\n originalSeries,\n isZooming,\n zoomStartingPosition,\n movingPosition,\n innerHeight,\n innerWidth,\n groups,\n currentData,\n colorScale,\n stackedData,\n subGroupScale,\n xScale,\n yScale,\n y2Scale,\n containerRef,\n getBandwidth,\n scrapperPosY,\n scrapperPosX,\n activePoint,\n activeSerie,\n xScrollbarPosition,\n isGrabbed,\n startPosition,\n isScrollbarVisible,\n containerRatio,\n internalMargin,\n axisLeftRef,\n leftLegendWidth,\n leftLegend,\n rightLegend,\n axisBottomHeight,\n getXScaleValue,\n getYScaleValue,\n bottomLabelHeight,\n rightLabelWidth,\n axisRightWidth,\n getXValue,\n getYValue,\n isHorizontal,\n leftLabel,\n chartId,\n hiddenSeries,\n height,\n width,\n toolbarHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n bottomLegend,\n leftLabelWidth,\n axisLeftWidth,\n topLegendHeight,\n leftLegendHeight,\n ],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAqD;AAErD,iBAAoB;AACpB,oBAAyB;AAGzB,mCAAwC;AACxC,uBAA0B;AAC1B,qBAA0B;AAC1B,gCAAmC;AACnC,wBAA2B;AAC3B,sCAA2B;AAC3B,8BAAiC;AAGjC,MAAM,oBAAoB,CAAC,QAAwC;AACjE,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAiB,CAAC;AAEtD,8BAAU,MAAM;AACd,QAAI,KAAK;AACP,YAAM,gBAAgB;AACtB,YAAM,iBAAiB,IAAI,gCAAAA;AAAA,YACzB,wBAAS,CAAC,YAA8C;AACtD,kBAAQ,QAAQ,CAAC,UAAU;AACzB,0BAAc,KAAK,KAAK,MAAM,YAAY,KAAK,CAAC;AAAA,UAClD,CAAC;AAAA,QACH,GAAG,GAAG;AAAA,MACR;AACA,qBAAe,QAAQ,aAAa;AAEpC,aAAO,MAAM;AACX,uBAAe,UAAU,aAAa;AAAA,MACxC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AACR,SAAO;AACT;AAEO,MAAM,WAAW,CAAC,UAA0B;AACjD,gDAAiB,OAAO,sCAAS;AAGjC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,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["ResizeObserver"]
|
|
7
7
|
}
|
|
@@ -29,8 +29,27 @@ __export(useInternalMargins_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(useInternalMargins_exports);
|
|
30
30
|
var React = __toESM(require("react"));
|
|
31
31
|
var import_react = require("react");
|
|
32
|
-
|
|
33
|
-
const
|
|
32
|
+
var import_resize_observer_polyfill = __toESM(require("resize-observer-polyfill"));
|
|
33
|
+
const useResizeObserver = (ref, { offsetHeight = 0, offsetWidth = 0 } = { offsetHeight: 0, offsetWidth: 0 }) => {
|
|
34
|
+
const [width, setWidth] = (0, import_react.useState)(0);
|
|
35
|
+
const [height, setHeight] = (0, import_react.useState)(0);
|
|
36
|
+
(0, import_react.useEffect)(() => {
|
|
37
|
+
if (ref) {
|
|
38
|
+
const observeTarget = ref;
|
|
39
|
+
const resizeObserver = new import_resize_observer_polyfill.default((entries) => {
|
|
40
|
+
entries.forEach((entry) => {
|
|
41
|
+
setWidth(Math.ceil(entry.contentRect.width + offsetWidth));
|
|
42
|
+
setHeight(Math.ceil(entry.contentRect.height + offsetHeight));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
resizeObserver.observe(observeTarget);
|
|
46
|
+
return () => {
|
|
47
|
+
resizeObserver.unobserve(observeTarget);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}, [offsetHeight, offsetWidth, ref]);
|
|
51
|
+
return { width, height };
|
|
52
|
+
};
|
|
34
53
|
const useInternalMargins = ({
|
|
35
54
|
axisLeftRef,
|
|
36
55
|
axisBottomRef,
|
|
@@ -44,23 +63,25 @@ const useInternalMargins = ({
|
|
|
44
63
|
bottomLabel,
|
|
45
64
|
toolbarRef
|
|
46
65
|
}) => {
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
const { height: toolbarHeight } = useResizeObserver(toolbarRef, { offsetHeight: 10 });
|
|
67
|
+
const { width: axisRightWidth } = useResizeObserver(axisRightRef);
|
|
68
|
+
const { height: axisBottomHeight } = useResizeObserver(axisBottomRef, { offsetHeight: 20 });
|
|
69
|
+
const { width: axisLeftWidth } = useResizeObserver(axisLeftRef, { offsetWidth: 10 });
|
|
70
|
+
const { height: bottomLabelHeight } = useResizeObserver(bottomLabel, { offsetHeight: 10 });
|
|
71
|
+
const { width: rightLabelWidth } = useResizeObserver(rightLabel);
|
|
72
|
+
const { width: leftLabelWidth, height: leftLabelHeight } = useResizeObserver(leftLabel);
|
|
73
|
+
const { height: topLegendHeight } = useResizeObserver(topLegend, { offsetHeight: 20 });
|
|
74
|
+
const { height: bottomLegendHeight, width: bottomLegendWidth } = useResizeObserver(bottomLegend, {
|
|
75
|
+
offsetHeight: 10
|
|
76
|
+
});
|
|
77
|
+
const { width: rightLegendWidth, height: rightLegendHeight } = useResizeObserver(rightLegend);
|
|
78
|
+
const { width: leftLegendWidth, height: leftLegendHeight } = useResizeObserver(leftLegend, { offsetWidth: 20 });
|
|
58
79
|
const internalMargin = (0, import_react.useMemo)(
|
|
59
80
|
() => ({
|
|
60
|
-
bottom:
|
|
61
|
-
top:
|
|
62
|
-
right:
|
|
63
|
-
left:
|
|
81
|
+
bottom: axisBottomHeight + bottomLegendHeight + bottomLabelHeight || 10,
|
|
82
|
+
top: Math.max(topLegendHeight, toolbarHeight) || 10,
|
|
83
|
+
right: rightLabelWidth + axisRightWidth + rightLegendWidth || 10,
|
|
84
|
+
left: axisLeftWidth + leftLabelWidth + leftLegendWidth || 10
|
|
64
85
|
}),
|
|
65
86
|
[
|
|
66
87
|
axisBottomHeight,
|
|
@@ -79,6 +100,7 @@ const useInternalMargins = ({
|
|
|
79
100
|
return (0, import_react.useMemo)(
|
|
80
101
|
() => ({
|
|
81
102
|
internalMargin,
|
|
103
|
+
leftLegendHeight,
|
|
82
104
|
leftLegendWidth,
|
|
83
105
|
axisBottomHeight,
|
|
84
106
|
bottomLegendHeight,
|
|
@@ -89,11 +111,15 @@ const useInternalMargins = ({
|
|
|
89
111
|
rightLegendWidth,
|
|
90
112
|
axisLeftWidth,
|
|
91
113
|
leftLabelWidth,
|
|
92
|
-
toolbarHeight
|
|
114
|
+
toolbarHeight,
|
|
115
|
+
leftLabelHeight,
|
|
116
|
+
rightLegendHeight,
|
|
117
|
+
bottomLegendWidth
|
|
93
118
|
}),
|
|
94
119
|
[
|
|
95
120
|
axisBottomHeight,
|
|
96
121
|
toolbarHeight,
|
|
122
|
+
leftLegendHeight,
|
|
97
123
|
axisLeftWidth,
|
|
98
124
|
axisRightWidth,
|
|
99
125
|
bottomLabelHeight,
|
|
@@ -103,7 +129,10 @@ const useInternalMargins = ({
|
|
|
103
129
|
leftLegendWidth,
|
|
104
130
|
rightLabelWidth,
|
|
105
131
|
rightLegendWidth,
|
|
106
|
-
topLegendHeight
|
|
132
|
+
topLegendHeight,
|
|
133
|
+
leftLabelHeight,
|
|
134
|
+
rightLegendHeight,
|
|
135
|
+
bottomLegendWidth
|
|
107
136
|
]
|
|
108
137
|
);
|
|
109
138
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/graphs/Chart/config/useInternalMargins.tsx", "../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo } from 'react';\n\ninterface UseInternalMarginsT {\n axisLeftRef: SVGGElement | null;\n axisBottomRef: SVGGElement | null;\n axisRightRef: SVGGElement | null;\n leftLegend: SVGGElement | null;\n leftLabel: SVGGElement | null;\n rightLegend: SVGGElement | null;\n topLegend: SVGGElement | null;\n bottomLegend: SVGGElement | null;\n rightLabel: SVGGElement | null;\n bottomLabel: SVGGElement | null;\n toolbarRef: SVGGElement | null;\n}\n\nconst
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-statements */\n/* eslint-disable indent */\nimport { useMemo, useEffect, useState } from 'react';\nimport ResizeObserver from 'resize-observer-polyfill';\n\ninterface UseInternalMarginsT {\n axisLeftRef: SVGGElement | null;\n axisBottomRef: SVGGElement | null;\n axisRightRef: SVGGElement | null;\n leftLegend: SVGGElement | null;\n leftLabel: SVGGElement | null;\n rightLegend: SVGGElement | null;\n topLegend: SVGGElement | null;\n bottomLegend: SVGGElement | null;\n rightLabel: SVGGElement | null;\n bottomLabel: SVGGElement | null;\n toolbarRef: SVGGElement | null;\n}\n\ntype ResizeObserverConstructorEntries = Parameters<ConstructorParameters<typeof ResizeObserver>[0]>[0];\n\nconst useResizeObserver = (\n ref: SVGGElement | null,\n { offsetHeight = 0, offsetWidth = 0 } = { offsetHeight: 0, offsetWidth: 0 },\n) => {\n const [width, setWidth] = useState<number>(0);\n const [height, setHeight] = useState<number>(0);\n\n useEffect(() => {\n if (ref) {\n const observeTarget = ref;\n const resizeObserver = new ResizeObserver((entries: ResizeObserverConstructorEntries) => {\n entries.forEach((entry) => {\n setWidth(Math.ceil(entry.contentRect.width + offsetWidth));\n setHeight(Math.ceil(entry.contentRect.height + offsetHeight));\n });\n });\n\n resizeObserver.observe(observeTarget);\n\n return () => {\n resizeObserver.unobserve(observeTarget);\n };\n }\n }, [offsetHeight, offsetWidth, ref]);\n return { width, height };\n};\n\nexport const useInternalMargins = ({\n axisLeftRef,\n axisBottomRef,\n axisRightRef,\n leftLabel,\n leftLegend,\n rightLegend,\n topLegend,\n bottomLegend,\n rightLabel,\n bottomLabel,\n toolbarRef,\n}: UseInternalMarginsT) => {\n // Toolbar\n const { height: toolbarHeight } = useResizeObserver(toolbarRef, { offsetHeight: 10 });\n\n // Axis\n const { width: axisRightWidth } = useResizeObserver(axisRightRef);\n const { height: axisBottomHeight } = useResizeObserver(axisBottomRef, { offsetHeight: 20 });\n const { width: axisLeftWidth } = useResizeObserver(axisLeftRef, { offsetWidth: 10 });\n\n // Labels\n const { height: bottomLabelHeight } = useResizeObserver(bottomLabel, { offsetHeight: 10 });\n const { width: rightLabelWidth } = useResizeObserver(rightLabel);\n const { width: leftLabelWidth, height: leftLabelHeight } = useResizeObserver(leftLabel);\n\n // Legends\n const { height: topLegendHeight } = useResizeObserver(topLegend, { offsetHeight: 20 });\n const { height: bottomLegendHeight, width: bottomLegendWidth } = useResizeObserver(bottomLegend, {\n offsetHeight: 10,\n });\n const { width: rightLegendWidth, height: rightLegendHeight } = useResizeObserver(rightLegend);\n const { width: leftLegendWidth, height: leftLegendHeight } = useResizeObserver(leftLegend, { offsetWidth: 20 });\n\n const internalMargin = useMemo(\n () => ({\n bottom: axisBottomHeight + bottomLegendHeight + bottomLabelHeight || 10,\n top: Math.max(topLegendHeight, toolbarHeight) || 10,\n right: rightLabelWidth + axisRightWidth + rightLegendWidth || 10,\n left: axisLeftWidth + leftLabelWidth + leftLegendWidth || 10,\n }),\n\n [\n axisBottomHeight,\n bottomLegendHeight,\n bottomLabelHeight,\n topLegendHeight,\n toolbarHeight,\n rightLabelWidth,\n axisRightWidth,\n rightLegendWidth,\n axisLeftWidth,\n leftLabelWidth,\n leftLegendWidth,\n ],\n );\n\n return useMemo(\n () => ({\n internalMargin,\n leftLegendHeight,\n leftLegendWidth,\n axisBottomHeight,\n bottomLegendHeight,\n bottomLabelHeight,\n topLegendHeight,\n rightLabelWidth,\n axisRightWidth,\n rightLegendWidth,\n axisLeftWidth,\n leftLabelWidth,\n toolbarHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n }),\n [\n axisBottomHeight,\n toolbarHeight,\n leftLegendHeight,\n axisLeftWidth,\n axisRightWidth,\n bottomLabelHeight,\n bottomLegendHeight,\n internalMargin,\n leftLabelWidth,\n leftLegendWidth,\n rightLabelWidth,\n rightLegendWidth,\n topLegendHeight,\n leftLabelHeight,\n rightLegendHeight,\n bottomLegendWidth,\n ],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,mBAA6C;AAC7C,sCAA2B;AAkB3B,MAAM,oBAAoB,CACxB,KACA,EAAE,eAAe,GAAG,cAAc,EAAE,IAAI,EAAE,cAAc,GAAG,aAAa,EAAE,MACvE;AACH,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAiB,CAAC;AAC5C,QAAM,CAAC,QAAQ,SAAS,QAAI,uBAAiB,CAAC;AAE9C,8BAAU,MAAM;AACd,QAAI,KAAK;AACP,YAAM,gBAAgB;AACtB,YAAM,iBAAiB,IAAI,gCAAAA,QAAe,CAAC,YAA8C;AACvF,gBAAQ,QAAQ,CAAC,UAAU;AACzB,mBAAS,KAAK,KAAK,MAAM,YAAY,QAAQ,WAAW,CAAC;AACzD,oBAAU,KAAK,KAAK,MAAM,YAAY,SAAS,YAAY,CAAC;AAAA,QAC9D,CAAC;AAAA,MACH,CAAC;AAED,qBAAe,QAAQ,aAAa;AAEpC,aAAO,MAAM;AACX,uBAAe,UAAU,aAAa;AAAA,MACxC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,cAAc,aAAa,GAAG,CAAC;AACnC,SAAO,EAAE,OAAO,OAAO;AACzB;AAEO,MAAM,qBAAqB,CAAC;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA2B;AAEzB,QAAM,EAAE,QAAQ,cAAc,IA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A;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["ResizeObserver"]
|
|
7
7
|
}
|
|
@@ -43,7 +43,9 @@ const useKeyboardNavigation = () => {
|
|
|
43
43
|
activePoint,
|
|
44
44
|
setActivePoint,
|
|
45
45
|
containerRef,
|
|
46
|
+
xScale,
|
|
46
47
|
yScale,
|
|
48
|
+
lastPosition,
|
|
47
49
|
setXScrollbarPosition,
|
|
48
50
|
containerRatio,
|
|
49
51
|
xScrollbarPosition,
|
|
@@ -53,11 +55,18 @@ const useKeyboardNavigation = () => {
|
|
|
53
55
|
getXScaleValue,
|
|
54
56
|
getYScaleValue,
|
|
55
57
|
groups,
|
|
58
|
+
isZooming,
|
|
59
|
+
setIsZooming,
|
|
60
|
+
zoomStartingPosition,
|
|
61
|
+
setZoomStartingPosition,
|
|
62
|
+
setMovingPosition,
|
|
63
|
+
setContainerRatio,
|
|
56
64
|
currentData: data,
|
|
57
65
|
props: { xAxis, yAxis, xScroll, yScroll }
|
|
58
66
|
} = (0, import_react.useContext)(import_ChartContext.ChartContext);
|
|
59
67
|
const xScrollable = xAxis.advanced?.pointSpacing?.value > 1 || xScroll;
|
|
60
68
|
const yScrollable = yAxis.advanced?.pointSpacing?.value > 1 || yScroll;
|
|
69
|
+
const preservedActivePointOnShift = (0, import_react.useRef)();
|
|
61
70
|
const currentSerie = (0, import_react.useMemo)(
|
|
62
71
|
() => data.find((d) => d.name === activePoint?.serie) ?? data[0],
|
|
63
72
|
[activePoint?.serie, data]
|
|
@@ -77,11 +86,9 @@ const useKeyboardNavigation = () => {
|
|
|
77
86
|
);
|
|
78
87
|
const handleOnBlur = (0, import_react.useCallback)(() => {
|
|
79
88
|
setTimeout(() => {
|
|
80
|
-
|
|
81
|
-
setActivePoint(null);
|
|
82
|
-
}
|
|
89
|
+
setActivePoint(null);
|
|
83
90
|
});
|
|
84
|
-
}, [
|
|
91
|
+
}, [setActivePoint]);
|
|
85
92
|
const navigateSerie = (0, import_react.useCallback)(
|
|
86
93
|
(step) => {
|
|
87
94
|
const newValue = findInCircularList(
|
|
@@ -158,6 +165,8 @@ const useKeyboardNavigation = () => {
|
|
|
158
165
|
);
|
|
159
166
|
const onInputKeyDown = (0, import_react.useCallback)(
|
|
160
167
|
(e) => {
|
|
168
|
+
if (!activePoint)
|
|
169
|
+
return;
|
|
161
170
|
if (e.code !== "Tab") {
|
|
162
171
|
e.preventDefault();
|
|
163
172
|
}
|
|
@@ -173,12 +182,85 @@ const useKeyboardNavigation = () => {
|
|
|
173
182
|
else
|
|
174
183
|
changeSerie(e.code === "ArrowDown" ? -1 : 1);
|
|
175
184
|
}
|
|
185
|
+
const { code } = e;
|
|
186
|
+
const isShiftKey = ["ShiftLeft", "ShiftRight"].includes(code);
|
|
187
|
+
if (isShiftKey && !isZooming) {
|
|
188
|
+
setIsZooming(true);
|
|
189
|
+
setZoomStartingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);
|
|
190
|
+
}
|
|
176
191
|
},
|
|
177
|
-
[
|
|
192
|
+
[
|
|
193
|
+
activePoint,
|
|
194
|
+
changeSerie,
|
|
195
|
+
containerRatio,
|
|
196
|
+
getXScaleValue,
|
|
197
|
+
isZooming,
|
|
198
|
+
navigateSerie,
|
|
199
|
+
setIsZooming,
|
|
200
|
+
setZoomStartingPosition,
|
|
201
|
+
xScrollbarPosition,
|
|
202
|
+
yScale.bandwidth
|
|
203
|
+
]
|
|
204
|
+
);
|
|
205
|
+
const handleOnKeyUp = (0, import_react.useCallback)(
|
|
206
|
+
(e) => {
|
|
207
|
+
if (!isZooming && !xScale.bandwidth)
|
|
208
|
+
return false;
|
|
209
|
+
const { shiftKey, code } = e;
|
|
210
|
+
const isShiftKey = ["ShiftLeft", "ShiftRight"].includes(code);
|
|
211
|
+
if (shiftKey && ["ArrowRight", "ArrowLeft"].includes(code)) {
|
|
212
|
+
setMovingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);
|
|
213
|
+
}
|
|
214
|
+
if (isShiftKey) {
|
|
215
|
+
setIsZooming(false);
|
|
216
|
+
setZoomStartingPosition(0);
|
|
217
|
+
setMovingPosition(0);
|
|
218
|
+
const endingPosition = getXScaleValue(activePoint) - xScrollbarPosition * containerRatio;
|
|
219
|
+
const isRightDirection = zoomStartingPosition < endingPosition;
|
|
220
|
+
const offsetActivePoint = findInCircularList(
|
|
221
|
+
currentSerie?.data.map((d) => d.value.toString()),
|
|
222
|
+
currentActiveItemIndex,
|
|
223
|
+
isRightDirection ? 1 : -1
|
|
224
|
+
);
|
|
225
|
+
const correctEndingPosition = getXScaleValue(currentSerie?.data[offsetActivePoint]) - xScrollbarPosition * containerRatio;
|
|
226
|
+
const diff = Math.abs(zoomStartingPosition - correctEndingPosition);
|
|
227
|
+
if (diff <= 0)
|
|
228
|
+
return;
|
|
229
|
+
const newRatio = innerWidth / (innerWidth * containerRatio / diff) < 40 ? innerWidth / 40 : innerWidth * containerRatio / diff;
|
|
230
|
+
const newPosition = lastPosition?.current + (!isRightDirection ? correctEndingPosition : zoomStartingPosition) / containerRatio;
|
|
231
|
+
if (newPosition > innerWidth - innerWidth / newRatio)
|
|
232
|
+
setXScrollbarPosition(innerWidth - innerWidth / newRatio);
|
|
233
|
+
else
|
|
234
|
+
setXScrollbarPosition(newPosition);
|
|
235
|
+
setActivePoint(null);
|
|
236
|
+
setTimeout(() => setActivePoint(activePoint));
|
|
237
|
+
setContainerRatio(newRatio);
|
|
238
|
+
lastPosition.current = newPosition;
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
[
|
|
242
|
+
activePoint,
|
|
243
|
+
containerRatio,
|
|
244
|
+
currentActiveItemIndex,
|
|
245
|
+
currentSerie?.data,
|
|
246
|
+
getXScaleValue,
|
|
247
|
+
innerWidth,
|
|
248
|
+
isZooming,
|
|
249
|
+
lastPosition,
|
|
250
|
+
setActivePoint,
|
|
251
|
+
setContainerRatio,
|
|
252
|
+
setIsZooming,
|
|
253
|
+
setMovingPosition,
|
|
254
|
+
setXScrollbarPosition,
|
|
255
|
+
setZoomStartingPosition,
|
|
256
|
+
xScale.bandwidth,
|
|
257
|
+
xScrollbarPosition,
|
|
258
|
+
zoomStartingPosition
|
|
259
|
+
]
|
|
178
260
|
);
|
|
179
261
|
return (0, import_react.useMemo)(
|
|
180
|
-
() => ({ onInputKeyDown, handleOnBlur, handleOnFocus }),
|
|
181
|
-
[handleOnBlur, handleOnFocus, onInputKeyDown]
|
|
262
|
+
() => ({ handleOnKeyUp, onInputKeyDown, handleOnBlur, handleOnFocus }),
|
|
263
|
+
[handleOnBlur, handleOnFocus, handleOnKeyUp, onInputKeyDown]
|
|
182
264
|
);
|
|
183
265
|
};
|
|
184
266
|
//# sourceMappingURL=useKeyboardNavigation.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/graphs/Chart/config/useKeyboardNavigation.tsx", "../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport { useCallback, useContext, useMemo } from 'react';\nimport { ChartContext } from '../ChartContext';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable max-depth */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport { useCallback, useContext, useMemo, useRef } from 'react';\nimport { ChartContext } from '../ChartContext';\nimport { DSChartT } from '../react-desc-prop-types';\nexport const findInCircularList = (\n list: string[],\n from: number,\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 xScale,\n yScale,\n lastPosition,\n setXScrollbarPosition,\n containerRatio,\n xScrollbarPosition,\n innerWidth,\n innerHeight,\n getYValue,\n getXScaleValue,\n getYScaleValue,\n groups,\n isZooming,\n setIsZooming,\n zoomStartingPosition,\n setZoomStartingPosition,\n setMovingPosition,\n setContainerRatio,\n currentData: data,\n props: { xAxis, yAxis, xScroll, yScroll },\n } = useContext(ChartContext);\n\n const xScrollable = xAxis.advanced?.pointSpacing?.value > 1 || xScroll;\n const yScrollable = yAxis.advanced?.pointSpacing?.value > 1 || yScroll;\n\n const preservedActivePointOnShift = useRef<DSChartT.InternalDatum | null>();\n const currentSerie = useMemo(\n () => data.find((d) => d.name === activePoint?.serie) ?? data[0],\n [activePoint?.serie, data],\n );\n\n const currentActiveItemIndex = useMemo(\n () => currentSerie?.data.findIndex((opt) => opt.key === activePoint?.key),\n [activePoint, currentSerie],\n );\n\n const handleOnFocus: React.FocusEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (containerRef === e.target) {\n setActivePoint(currentSerie?.data[0]);\n setXScrollbarPosition(0);\n }\n },\n [containerRef, currentSerie?.data, setActivePoint, setXScrollbarPosition],\n );\n\n const handleOnBlur: React.FocusEventHandler<HTMLInputElement> = useCallback(() => {\n setTimeout(() => {\n // if (!containerRef.contains(document.activeElement) || containerRef === document.activeElement) {\n setActivePoint(null);\n // }\n });\n }, [setActivePoint]);\n\n const navigateSerie = useCallback(\n (step: number) => {\n const newValue = findInCircularList(\n currentSerie?.data.map((d) => d.value.toString()),\n currentActiveItemIndex,\n step,\n );\n setActivePoint(currentSerie?.data[newValue]);\n\n if (xScrollable) {\n const xValue = getXScaleValue(currentSerie?.data[newValue]);\n if (xValue === undefined) return;\n const barWidth = innerWidth / containerRatio;\n const total = innerWidth * containerRatio;\n if (total <= xValue) {\n // to go from the first to last\n setXScrollbarPosition((total - innerWidth) / containerRatio);\n } else if (xValue > xScrollbarPosition * containerRatio + innerWidth)\n // if is not visible we move the scroll to the next best position\n setXScrollbarPosition((prev) => {\n const nextPosition = prev + (xValue / containerRatio - prev);\n if (nextPosition + barWidth > innerWidth) return innerWidth - barWidth;\n return nextPosition;\n });\n // move backwards - 2 because focus ring in bars\n else if (xValue < xScrollbarPosition * containerRatio) setXScrollbarPosition(xValue / containerRatio);\n }\n if (yScrollable) {\n const yValue = getYScaleValue(currentSerie?.data[newValue]);\n if (yValue === undefined) return;\n const barWidth = innerHeight / containerRatio;\n const total = innerHeight * containerRatio;\n if (total <= yValue) {\n // to go from the first to last\n setXScrollbarPosition((total - innerHeight) / containerRatio);\n } else if (yValue > xScrollbarPosition * containerRatio + innerHeight)\n // if is not visible we move the scroll to the next best position\n setXScrollbarPosition((prev) => {\n const nextPosition = prev + (yValue / containerRatio - prev);\n if (nextPosition + barWidth > innerHeight) return innerHeight - barWidth;\n return nextPosition;\n });\n // move backwards - 2 because focus ring in bars\n else if (yValue < xScrollbarPosition * containerRatio) setXScrollbarPosition(yValue / containerRatio);\n }\n },\n [\n currentSerie?.data,\n currentActiveItemIndex,\n setActivePoint,\n xScrollable,\n yScrollable,\n getXScaleValue,\n innerWidth,\n containerRatio,\n xScrollbarPosition,\n setXScrollbarPosition,\n getYScaleValue,\n innerHeight,\n ],\n );\n\n const changeSerie = useCallback(\n (step: number) => {\n const nextSerie = data.find((d) => {\n const nextSerieIndex = findInCircularList(\n groups,\n groups.findIndex((item) => item === currentSerie.name),\n step,\n );\n\n return d.name === groups[nextSerieIndex];\n });\n setActivePoint(nextSerie?.data[currentActiveItemIndex] || nextSerie?.data?.[0] || null);\n },\n [data, setActivePoint, currentActiveItemIndex, groups, currentSerie.name],\n );\n\n const onInputKeyDown: React.KeyboardEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (!activePoint) return;\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 const { code } = e;\n const isShiftKey = ['ShiftLeft', 'ShiftRight'].includes(code);\n\n if (isShiftKey && !isZooming) {\n setIsZooming(true);\n setZoomStartingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);\n }\n },\n [\n activePoint,\n changeSerie,\n containerRatio,\n getXScaleValue,\n isZooming,\n navigateSerie,\n setIsZooming,\n setZoomStartingPosition,\n xScrollbarPosition,\n yScale.bandwidth,\n ],\n );\n\n const handleOnKeyUp: React.KeyboardEventHandler<HTMLDivElement> = useCallback(\n (e) => {\n if (!isZooming && !xScale.bandwidth) return false;\n const { shiftKey, code } = e;\n const isShiftKey = ['ShiftLeft', 'ShiftRight'].includes(code);\n\n if (shiftKey && ['ArrowRight', 'ArrowLeft'].includes(code)) {\n setMovingPosition(getXScaleValue(activePoint) - xScrollbarPosition * containerRatio);\n }\n if (isShiftKey) {\n setIsZooming(false);\n setZoomStartingPosition(0);\n setMovingPosition(0);\n const endingPosition = getXScaleValue(activePoint) - xScrollbarPosition * containerRatio;\n // isRightDirection is used to know if we are zooming right or left direction\n const isRightDirection = zoomStartingPosition < endingPosition;\n const offsetActivePoint = findInCircularList(\n currentSerie?.data.map((d) => d.value.toString()),\n currentActiveItemIndex,\n isRightDirection ? 1 : -1,\n );\n // we do this so the activePoint does not fall into the blur gradient\n const correctEndingPosition =\n getXScaleValue(currentSerie?.data[offsetActivePoint]) - xScrollbarPosition * containerRatio;\n const diff = Math.abs(zoomStartingPosition - correctEndingPosition);\n if (diff <= 0) return;\n const newRatio =\n innerWidth / ((innerWidth * containerRatio) / diff) < 40\n ? innerWidth / 40\n : (innerWidth * containerRatio) / diff;\n const newPosition =\n lastPosition?.current + (!isRightDirection ? correctEndingPosition : zoomStartingPosition) / containerRatio;\n\n // if is bigger thant innerwidth possible we force the end\n if (newPosition > innerWidth - innerWidth / newRatio) setXScrollbarPosition(innerWidth - innerWidth / newRatio);\n else setXScrollbarPosition(newPosition);\n setActivePoint(null);\n setTimeout(() => setActivePoint(activePoint));\n setContainerRatio(newRatio);\n lastPosition.current = newPosition;\n }\n },\n [\n activePoint,\n containerRatio,\n currentActiveItemIndex,\n currentSerie?.data,\n getXScaleValue,\n innerWidth,\n isZooming,\n lastPosition,\n setActivePoint,\n setContainerRatio,\n setIsZooming,\n setMovingPosition,\n setXScrollbarPosition,\n setZoomStartingPosition,\n xScale.bandwidth,\n xScrollbarPosition,\n zoomStartingPosition,\n ],\n );\n return useMemo(\n () => ({ handleOnKeyUp, onInputKeyDown, handleOnBlur, handleOnFocus }),\n [handleOnBlur, handleOnFocus, handleOnKeyUp, onInputKeyDown],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADIvB,mBAAyD;AACzD,0BAA6B;AAEtB,MAAM,qBAAqB,CAChC,MACA,MACA,OAAO,MAEI;AACX,WACM,KAAK,OAAO,OAAO,KAAK,UAAU,KAAK,QAC3C,MAAM,QAAQ,OAAO,IACrB,KAAK,IAAI,OAAO,KAAK,U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