@elliemae/ds-dataviz 3.14.4 → 3.14.6
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 +1 -1
- package/dist/cjs/graphs/Chart/config/useChart.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useGetters.js +4 -4
- package/dist/cjs/graphs/Chart/config/useGetters.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useInternalMargins.js +2 -2
- package/dist/cjs/graphs/Chart/config/useInternalMargins.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useKeyboardNavigation.js +4 -4
- package/dist/cjs/graphs/Chart/config/useKeyboardNavigation.js.map +2 -2
- package/dist/cjs/graphs/Chart/config/useScales.js +53 -37
- package/dist/cjs/graphs/Chart/config/useScales.js.map +2 -2
- package/dist/cjs/graphs/Chart/helpers/index.js +2 -2
- package/dist/cjs/graphs/Chart/helpers/index.js.map +2 -2
- package/dist/cjs/graphs/Chart/helpers/useUniqueData.js +5 -5
- package/dist/cjs/graphs/Chart/helpers/useUniqueData.js.map +2 -2
- package/dist/cjs/graphs/Chart/helpers/useVirtualizedSeries.js +4 -4
- package/dist/cjs/graphs/Chart/helpers/useVirtualizedSeries.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Axis/Axis.js +47 -0
- package/dist/cjs/graphs/Chart/parts/Axis/Axis.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/Axis/AxisBottom.js +88 -71
- package/dist/cjs/graphs/Chart/parts/Axis/AxisBottom.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Axis/AxisLeft.js +88 -58
- package/dist/cjs/graphs/Chart/parts/Axis/AxisLeft.js.map +3 -3
- package/dist/cjs/graphs/Chart/parts/Axis/AxisRight.js +91 -56
- package/dist/cjs/graphs/Chart/parts/Axis/AxisRight.js.map +3 -3
- package/dist/cjs/graphs/Chart/parts/{Labels/BottomLabel.js → Axis/GridLine.js} +7 -26
- package/dist/cjs/graphs/Chart/parts/Axis/GridLine.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/{Labels/LeftLabel.js → Axis/Tick.js} +12 -25
- package/dist/cjs/graphs/Chart/parts/Axis/Tick.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/ChartContainer.js +2 -2
- package/dist/cjs/graphs/Chart/parts/ChartContainer.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Labels/Label.js +3 -18
- package/dist/cjs/graphs/Chart/parts/Labels/Label.js.map +3 -3
- package/dist/cjs/graphs/Chart/parts/Labels/index.js +102 -0
- package/dist/cjs/graphs/Chart/parts/Labels/index.js.map +7 -0
- package/dist/cjs/graphs/Chart/parts/Scrapper/Scrapper.js +5 -5
- package/dist/cjs/graphs/Chart/parts/Scrapper/Scrapper.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Scrapper/ScrapperLine.js +1 -1
- package/dist/cjs/graphs/Chart/parts/Scrapper/ScrapperLine.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Scrapper/VerticalScrapperLine.js +3 -3
- package/dist/cjs/graphs/Chart/parts/Scrapper/VerticalScrapperLine.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Scroller/Controllers.js +1 -1
- package/dist/cjs/graphs/Chart/parts/Scroller/Controllers.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/Scroller/ScrollableContainerX.js +5 -5
- package/dist/cjs/graphs/Chart/parts/Scroller/ScrollableContainerX.js.map +2 -2
- package/dist/cjs/graphs/Chart/parts/TrendHighlight.js +1 -1
- package/dist/cjs/graphs/Chart/parts/TrendHighlight.js.map +1 -1
- package/dist/cjs/graphs/Chart/react-desc-prop-types.js.map +2 -2
- package/dist/cjs/graphs/Chart/scales/index.js +186 -0
- package/dist/cjs/graphs/Chart/scales/index.js.map +7 -0
- package/dist/cjs/graphs/Chart/series/Area.js +5 -5
- package/dist/cjs/graphs/Chart/series/Area.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/Bars.js +7 -4
- package/dist/cjs/graphs/Chart/series/Bars.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/HorizontalBars.js +4 -4
- package/dist/cjs/graphs/Chart/series/HorizontalBars.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/HorizontalStackedBars.js +3 -3
- package/dist/cjs/graphs/Chart/series/HorizontalStackedBars.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/Line.js +2 -2
- package/dist/cjs/graphs/Chart/series/Line.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/Points.js +2 -2
- package/dist/cjs/graphs/Chart/series/Points.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/Rect.js +1 -1
- package/dist/cjs/graphs/Chart/series/Rect.js.map +2 -2
- package/dist/cjs/graphs/Chart/series/StackedBar.js +3 -3
- package/dist/cjs/graphs/Chart/series/StackedBar.js.map +2 -2
- package/dist/cjs/graphs/Chart/styles.js +4 -26
- package/dist/cjs/graphs/Chart/styles.js.map +2 -2
- package/dist/esm/graphs/Chart/ChartContext.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useChart.js +1 -1
- package/dist/esm/graphs/Chart/config/useChart.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useGetters.js +4 -4
- package/dist/esm/graphs/Chart/config/useGetters.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useInternalMargins.js +2 -2
- package/dist/esm/graphs/Chart/config/useInternalMargins.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useKeyboardNavigation.js +4 -4
- package/dist/esm/graphs/Chart/config/useKeyboardNavigation.js.map +2 -2
- package/dist/esm/graphs/Chart/config/useScales.js +53 -37
- package/dist/esm/graphs/Chart/config/useScales.js.map +2 -2
- package/dist/esm/graphs/Chart/helpers/index.js +2 -2
- package/dist/esm/graphs/Chart/helpers/index.js.map +2 -2
- package/dist/esm/graphs/Chart/helpers/useUniqueData.js +5 -5
- package/dist/esm/graphs/Chart/helpers/useUniqueData.js.map +2 -2
- package/dist/esm/graphs/Chart/helpers/useVirtualizedSeries.js +4 -4
- package/dist/esm/graphs/Chart/helpers/useVirtualizedSeries.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Axis/Axis.js +21 -0
- package/dist/esm/graphs/Chart/parts/Axis/Axis.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/Axis/AxisBottom.js +90 -73
- package/dist/esm/graphs/Chart/parts/Axis/AxisBottom.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Axis/AxisLeft.js +89 -59
- package/dist/esm/graphs/Chart/parts/Axis/AxisLeft.js.map +3 -3
- package/dist/esm/graphs/Chart/parts/Axis/AxisRight.js +92 -57
- package/dist/esm/graphs/Chart/parts/Axis/AxisRight.js.map +3 -3
- package/dist/esm/graphs/Chart/parts/Axis/GridLine.js +8 -0
- package/dist/esm/graphs/Chart/parts/Axis/GridLine.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/Axis/Tick.js +13 -0
- package/dist/esm/graphs/Chart/parts/Axis/Tick.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/ChartContainer.js +2 -2
- package/dist/esm/graphs/Chart/parts/ChartContainer.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Labels/Label.js +4 -19
- package/dist/esm/graphs/Chart/parts/Labels/Label.js.map +3 -3
- package/dist/esm/graphs/Chart/parts/Labels/index.js +76 -0
- package/dist/esm/graphs/Chart/parts/Labels/index.js.map +7 -0
- package/dist/esm/graphs/Chart/parts/Scrapper/Scrapper.js +5 -5
- package/dist/esm/graphs/Chart/parts/Scrapper/Scrapper.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Scrapper/ScrapperLine.js +1 -1
- package/dist/esm/graphs/Chart/parts/Scrapper/ScrapperLine.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Scrapper/VerticalScrapperLine.js +3 -3
- package/dist/esm/graphs/Chart/parts/Scrapper/VerticalScrapperLine.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Scroller/Controllers.js +1 -1
- package/dist/esm/graphs/Chart/parts/Scroller/Controllers.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/Scroller/ScrollableContainerX.js +5 -5
- package/dist/esm/graphs/Chart/parts/Scroller/ScrollableContainerX.js.map +2 -2
- package/dist/esm/graphs/Chart/parts/TrendHighlight.js +1 -1
- package/dist/esm/graphs/Chart/parts/TrendHighlight.js.map +1 -1
- package/dist/esm/graphs/Chart/react-desc-prop-types.js.map +2 -2
- package/dist/esm/graphs/Chart/scales/index.js +160 -0
- package/dist/esm/graphs/Chart/scales/index.js.map +7 -0
- package/dist/esm/graphs/Chart/series/Area.js +5 -5
- package/dist/esm/graphs/Chart/series/Area.js.map +2 -2
- package/dist/esm/graphs/Chart/series/Bars.js +7 -4
- package/dist/esm/graphs/Chart/series/Bars.js.map +2 -2
- package/dist/esm/graphs/Chart/series/HorizontalBars.js +4 -4
- package/dist/esm/graphs/Chart/series/HorizontalBars.js.map +2 -2
- package/dist/esm/graphs/Chart/series/HorizontalStackedBars.js +3 -3
- package/dist/esm/graphs/Chart/series/HorizontalStackedBars.js.map +2 -2
- package/dist/esm/graphs/Chart/series/Line.js +2 -2
- package/dist/esm/graphs/Chart/series/Line.js.map +2 -2
- package/dist/esm/graphs/Chart/series/Points.js +2 -2
- package/dist/esm/graphs/Chart/series/Points.js.map +2 -2
- package/dist/esm/graphs/Chart/series/Rect.js +1 -1
- package/dist/esm/graphs/Chart/series/Rect.js.map +2 -2
- package/dist/esm/graphs/Chart/series/StackedBar.js +3 -3
- package/dist/esm/graphs/Chart/series/StackedBar.js.map +2 -2
- package/dist/esm/graphs/Chart/styles.js +4 -26
- package/dist/esm/graphs/Chart/styles.js.map +2 -2
- package/dist/types/graphs/Chart/ChartContext.d.ts +12 -4
- package/dist/types/graphs/Chart/config/useChart.d.ts +6 -6
- package/dist/types/graphs/Chart/config/useGetters.d.ts +2 -2
- package/dist/types/graphs/Chart/config/useScales.d.ts +6 -5
- package/dist/types/graphs/Chart/parts/Axis/Axis.d.ts +26 -0
- package/dist/types/graphs/Chart/parts/Axis/AxisLeft.d.ts +2 -1
- package/dist/types/graphs/Chart/parts/Axis/AxisRight.d.ts +2 -1
- package/dist/types/graphs/Chart/parts/Axis/GridLine.d.ts +9 -0
- package/dist/types/graphs/Chart/parts/Axis/Tick.d.ts +15 -0
- package/dist/types/graphs/Chart/parts/Labels/Label.d.ts +10 -1
- package/dist/types/graphs/Chart/parts/Labels/index.d.ts +1 -0
- package/dist/types/graphs/Chart/react-desc-prop-types.d.ts +3 -2
- package/dist/types/graphs/Chart/scales/index.d.ts +53 -0
- package/dist/types/graphs/Chart/styles.d.ts +1 -2
- package/package.json +4 -4
- package/dist/cjs/graphs/Chart/parts/Labels/BottomLabel.js.map +0 -7
- package/dist/cjs/graphs/Chart/parts/Labels/LeftLabel.js.map +0 -7
- package/dist/cjs/graphs/Chart/parts/Labels/RightLabel.js +0 -56
- package/dist/cjs/graphs/Chart/parts/Labels/RightLabel.js.map +0 -7
- package/dist/esm/graphs/Chart/parts/Labels/BottomLabel.js +0 -27
- package/dist/esm/graphs/Chart/parts/Labels/BottomLabel.js.map +0 -7
- package/dist/esm/graphs/Chart/parts/Labels/LeftLabel.js +0 -26
- package/dist/esm/graphs/Chart/parts/Labels/LeftLabel.js.map +0 -7
- package/dist/esm/graphs/Chart/parts/Labels/RightLabel.js +0 -30
- package/dist/esm/graphs/Chart/parts/Labels/RightLabel.js.map +0 -7
- package/dist/types/graphs/Chart/parts/Labels/BottomLabel.d.ts +0 -1
- package/dist/types/graphs/Chart/parts/Labels/LeftLabel.d.ts +0 -1
- package/dist/types/graphs/Chart/parts/Labels/RightLabel.d.ts +0 -1
|
@@ -1,93 +1,110 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { jsx
|
|
3
|
-
import React2, { useContext,
|
|
4
|
-
import { select, axisBottom } from "d3";
|
|
5
|
-
import { StyledAxis, StyledGrid } from "../../styles";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import React2, { useContext, useMemo, useCallback } from "react";
|
|
6
4
|
import { ChartContext } from "../../ChartContext";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { Axis } from "./Axis";
|
|
6
|
+
import { Tick } from "./Tick";
|
|
7
|
+
import { GridLine } from "./GridLine";
|
|
8
|
+
import { COLOR_PALLET } from "../../helpers/colorPallet";
|
|
9
9
|
const AxisBottom = React2.memo(() => {
|
|
10
10
|
const {
|
|
11
11
|
props: { xAxis },
|
|
12
12
|
innerHeight,
|
|
13
13
|
xScale,
|
|
14
|
+
yScale,
|
|
14
15
|
innerWidth,
|
|
15
16
|
containerRatio,
|
|
16
|
-
internalMargin,
|
|
17
|
-
isHorizontal,
|
|
18
17
|
setAxisBottomRef
|
|
19
18
|
} = useContext(ChartContext);
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
const { tickRotation } = xAxis.tick || {};
|
|
20
|
+
const { showGrid } = xAxis;
|
|
21
|
+
const textProps = useMemo(() => {
|
|
22
|
+
const commomProps = { fill: COLOR_PALLET[xAxis?.tick?.color] || xAxis?.tick?.color };
|
|
23
|
+
if (!tickRotation)
|
|
24
|
+
return { ...commomProps, y: 17 };
|
|
25
|
+
return {
|
|
26
|
+
...commomProps,
|
|
27
|
+
dx: 8 * Math.sin(Math.PI * (tickRotation / 180)),
|
|
28
|
+
dy: ".71em",
|
|
29
|
+
y: Math.ceil(11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1)),
|
|
30
|
+
transform: `rotate(${tickRotation})`
|
|
31
|
+
};
|
|
32
|
+
}, [tickRotation, xAxis?.tick?.color]);
|
|
33
|
+
const style = useMemo(() => {
|
|
34
|
+
if (!tickRotation)
|
|
35
|
+
return { textAnchor: "middle" };
|
|
36
|
+
return { textAnchor: tickRotation > 0 ? "start" : "end" };
|
|
37
|
+
}, [tickRotation]);
|
|
38
|
+
const GridRenderer = useCallback(
|
|
39
|
+
(props) => {
|
|
40
|
+
if (!showGrid)
|
|
41
|
+
return null;
|
|
42
|
+
const { position, ...rest } = props;
|
|
43
|
+
const gridLineCoords = {
|
|
44
|
+
x1: position,
|
|
45
|
+
x2: position,
|
|
46
|
+
y1: 0,
|
|
47
|
+
y2: innerHeight
|
|
48
|
+
};
|
|
49
|
+
return /* @__PURE__ */ jsx(GridLine, { ...gridLineCoords, ...rest });
|
|
50
|
+
},
|
|
51
|
+
[innerHeight, showGrid]
|
|
52
|
+
);
|
|
53
|
+
const TickRenderer = useCallback(
|
|
54
|
+
(props) => {
|
|
55
|
+
const { position, tickValue, ...rest } = props;
|
|
56
|
+
const tickLineCoords = {
|
|
57
|
+
y2: 5,
|
|
58
|
+
stroke: COLOR_PALLET[xAxis?.tick?.color] || xAxis?.tick?.color
|
|
59
|
+
};
|
|
60
|
+
return /* @__PURE__ */ jsx(
|
|
61
|
+
Tick,
|
|
62
|
+
{
|
|
63
|
+
...tickLineCoords,
|
|
64
|
+
tickValue: xScale.getTickFormatted(tickValue),
|
|
65
|
+
xTranslate: position,
|
|
66
|
+
yTranslate: innerHeight,
|
|
67
|
+
textProps,
|
|
68
|
+
textStyle: style,
|
|
69
|
+
...rest
|
|
34
70
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
[xAxis?.tick?.color, xScale, innerHeight, textProps, style]
|
|
74
|
+
);
|
|
75
|
+
const axisColor = useMemo(() => COLOR_PALLET[xAxis.color] || xAxis.color, [xAxis.color]);
|
|
76
|
+
return useMemo(() => {
|
|
77
|
+
if (xAxis.hideAxis)
|
|
78
|
+
return null;
|
|
79
|
+
const lineCoords = {
|
|
80
|
+
x1: 0,
|
|
81
|
+
x2: innerWidth * containerRatio,
|
|
82
|
+
y1: innerHeight,
|
|
83
|
+
y2: innerHeight
|
|
84
|
+
};
|
|
85
|
+
return /* @__PURE__ */ jsx(
|
|
86
|
+
Axis,
|
|
87
|
+
{
|
|
88
|
+
lineCoords,
|
|
89
|
+
scale: xScale,
|
|
90
|
+
innerRef: setAxisBottomRef,
|
|
91
|
+
dimension: innerWidth * containerRatio,
|
|
92
|
+
TickRenderer,
|
|
93
|
+
GridRenderer,
|
|
94
|
+
color: axisColor
|
|
48
95
|
}
|
|
49
|
-
|
|
50
|
-
if (tickFormat) {
|
|
51
|
-
if (typeof tickFormat === "string") {
|
|
52
|
-
const formatGenerator = getFormatGenerator(xAxis.type ?? "linear");
|
|
53
|
-
axis.tickFormat((d) => formatGenerator(tickFormat)(d));
|
|
54
|
-
}
|
|
55
|
-
if (typeof tickFormat === "function") {
|
|
56
|
-
axis.tickFormat(tickFormat);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (axisRef?.current && gridRef?.current) {
|
|
60
|
-
if (xAxis?.showGrid)
|
|
61
|
-
select(gridRef.current).call(grid);
|
|
62
|
-
const axisNode = select(axisRef.current);
|
|
63
|
-
axisNode.call(axis);
|
|
64
|
-
if (tickRotation)
|
|
65
|
-
axisNode.selectAll("text").style("text-anchor", tickRotation > 0 ? "start" : "end").attr("dx", 8 * Math.sin(Math.PI * (tickRotation / 180))).attr("dy", ".71em").attr("y", 11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1)).attr("transform", `rotate(${tickRotation})`);
|
|
66
|
-
}
|
|
96
|
+
);
|
|
67
97
|
}, [
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
xAxis?.showGrid,
|
|
71
|
-
tickFormat,
|
|
72
|
-
tickValues,
|
|
73
|
-
xScale,
|
|
74
|
-
tickRotation,
|
|
75
|
-
xAxis.type,
|
|
76
|
-
ticksScales,
|
|
77
|
-
tickCount,
|
|
98
|
+
GridRenderer,
|
|
99
|
+
TickRenderer,
|
|
78
100
|
containerRatio,
|
|
101
|
+
axisColor,
|
|
102
|
+
innerHeight,
|
|
79
103
|
innerWidth,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
isHorizontal
|
|
104
|
+
setAxisBottomRef,
|
|
105
|
+
xAxis.hideAxis,
|
|
106
|
+
xScale
|
|
84
107
|
]);
|
|
85
|
-
if (xAxis.hideAxis)
|
|
86
|
-
return null;
|
|
87
|
-
return /* @__PURE__ */ jsxs("g", { transform: `translate(0,${innerHeight})`, children: [
|
|
88
|
-
/* @__PURE__ */ jsx("g", { ref: setAxisBottomRef, children: /* @__PURE__ */ jsx(StyledAxis, { axisColor: xAxis.color, tickColor: color, ref: axisRef }) }),
|
|
89
|
-
/* @__PURE__ */ jsx(StyledGrid, { ref: gridRef })
|
|
90
|
-
] });
|
|
91
108
|
});
|
|
92
109
|
export {
|
|
93
110
|
AxisBottom
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../../src/graphs/Chart/parts/Axis/AxisBottom.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { useContext,
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { useContext, useMemo, useCallback } from 'react';\nimport type { CSSProperties } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { Axis, type GridRenderPropsT, type TickRenderPropsT } from './Axis';\nimport { Tick } from './Tick';\nimport { GridLine } from './GridLine';\nimport { COLOR_PALLET } from '../../helpers/colorPallet';\n\nexport const AxisBottom = React.memo(() => {\n const {\n props: { xAxis },\n innerHeight,\n xScale,\n yScale,\n innerWidth,\n containerRatio,\n setAxisBottomRef,\n } = useContext(ChartContext);\n\n const { tickRotation } = xAxis.tick || ({} as DSChartT.AxisTickT);\n const { showGrid } = xAxis;\n\n const textProps = useMemo(() => {\n const commomProps = { fill: COLOR_PALLET[xAxis?.tick?.color as keyof typeof COLOR_PALLET] || xAxis?.tick?.color };\n if (!tickRotation) return { ...commomProps, y: 17 };\n return {\n ...commomProps,\n dx: 8 * Math.sin(Math.PI * (tickRotation / 180)),\n dy: '.71em',\n y: Math.ceil(11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1)),\n transform: `rotate(${tickRotation})`,\n };\n }, [tickRotation, xAxis?.tick?.color]);\n\n const style: CSSProperties = useMemo(() => {\n if (!tickRotation) return { textAnchor: 'middle' };\n return { textAnchor: tickRotation > 0 ? 'start' : 'end' };\n }, [tickRotation]);\n\n const GridRenderer = useCallback(\n (props: GridRenderPropsT) => {\n if (!showGrid) return null;\n\n const { position, ...rest } = props;\n const gridLineCoords = {\n x1: position,\n x2: position,\n y1: 0,\n y2: innerHeight,\n };\n return <GridLine {...gridLineCoords} {...rest} />;\n },\n [innerHeight, showGrid],\n );\n\n const TickRenderer = useCallback(\n (props: TickRenderPropsT) => {\n const { position, tickValue, ...rest } = props;\n const tickLineCoords = {\n y2: 5,\n stroke: COLOR_PALLET[xAxis?.tick?.color as keyof typeof COLOR_PALLET] || xAxis?.tick?.color,\n };\n return (\n <Tick\n {...tickLineCoords}\n tickValue={xScale.getTickFormatted(tickValue)}\n xTranslate={position}\n yTranslate={innerHeight}\n textProps={textProps}\n textStyle={style}\n {...rest}\n />\n );\n },\n [xAxis?.tick?.color, xScale, innerHeight, textProps, style],\n );\n\n const axisColor = useMemo(() => COLOR_PALLET[xAxis.color as keyof typeof COLOR_PALLET] || xAxis.color, [xAxis.color]);\n\n return useMemo(() => {\n if (xAxis.hideAxis) return null;\n const lineCoords = {\n x1: 0,\n x2: innerWidth * containerRatio,\n y1: innerHeight,\n y2: innerHeight,\n };\n\n return (\n <Axis\n lineCoords={lineCoords}\n scale={xScale}\n innerRef={setAxisBottomRef}\n dimension={innerWidth * containerRatio}\n TickRenderer={TickRenderer}\n GridRenderer={GridRenderer}\n color={axisColor}\n />\n );\n }, [\n GridRenderer,\n TickRenderer,\n containerRatio,\n axisColor,\n innerHeight,\n innerWidth,\n setAxisBottomRef,\n xAxis.hideAxis,\n xScale,\n ]);\n});\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -1,71 +1,101 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { jsx
|
|
3
|
-
import {
|
|
4
|
-
import { select, axisLeft } from "d3";
|
|
5
|
-
import { StyledAxis, StyledGrid } from "../../styles";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import React2, { useCallback, useContext, useMemo } from "react";
|
|
6
4
|
import { ChartContext } from "../../ChartContext";
|
|
7
|
-
import {
|
|
8
|
-
|
|
5
|
+
import { Axis } from "./Axis";
|
|
6
|
+
import { Tick } from "./Tick";
|
|
7
|
+
import { GridLine } from "./GridLine";
|
|
8
|
+
import { COLOR_PALLET } from "../../helpers/colorPallet";
|
|
9
|
+
const AxisLeft = React2.memo(() => {
|
|
9
10
|
const {
|
|
10
11
|
props: { yAxis },
|
|
11
12
|
innerHeight,
|
|
12
|
-
innerWidth,
|
|
13
|
-
yScale,
|
|
14
|
-
chartId,
|
|
15
13
|
height,
|
|
14
|
+
yScale,
|
|
15
|
+
innerWidth,
|
|
16
16
|
setAxisLeftRef
|
|
17
17
|
} = useContext(ChartContext);
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
const { tickRotation } = yAxis.tick || {};
|
|
19
|
+
const { showGrid } = yAxis;
|
|
20
|
+
const textProps = useMemo(() => {
|
|
21
|
+
const commomProps = { fill: COLOR_PALLET[yAxis?.tick?.color] || yAxis?.tick?.color };
|
|
22
|
+
if (!tickRotation)
|
|
23
|
+
return { ...commomProps, x: -10, dy: "0.32em" };
|
|
24
|
+
return {
|
|
25
|
+
...commomProps,
|
|
26
|
+
dy: ".30em",
|
|
27
|
+
dx: "-.10em",
|
|
28
|
+
x: Math.trunc(-(11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1))),
|
|
29
|
+
transform: `rotate(${tickRotation})`
|
|
30
|
+
};
|
|
31
|
+
}, [tickRotation, yAxis?.tick?.color]);
|
|
32
|
+
const style = useMemo(
|
|
33
|
+
() => ({
|
|
34
|
+
textAnchor: "end"
|
|
35
|
+
}),
|
|
36
|
+
[]
|
|
37
|
+
);
|
|
38
|
+
const GridRenderer = useCallback(
|
|
39
|
+
(props) => {
|
|
40
|
+
if (!showGrid)
|
|
41
|
+
return null;
|
|
42
|
+
const { position, ...rest } = props;
|
|
43
|
+
const gridLineCoords = {
|
|
44
|
+
x1: 0,
|
|
45
|
+
x2: innerWidth,
|
|
46
|
+
y1: position,
|
|
47
|
+
y2: position
|
|
48
|
+
};
|
|
49
|
+
return /* @__PURE__ */ jsx(GridLine, { ...gridLineCoords, ...rest });
|
|
50
|
+
},
|
|
51
|
+
[showGrid, innerWidth]
|
|
52
|
+
);
|
|
53
|
+
const TickRenderer = useCallback(
|
|
54
|
+
(props) => {
|
|
55
|
+
const { position, tickValue, ...rest } = props;
|
|
56
|
+
const tickLineCoords = {
|
|
57
|
+
x2: -5,
|
|
58
|
+
stroke: COLOR_PALLET[yAxis?.tick?.color] || yAxis?.tick?.color
|
|
59
|
+
};
|
|
60
|
+
return /* @__PURE__ */ jsx(
|
|
61
|
+
Tick,
|
|
62
|
+
{
|
|
63
|
+
...tickLineCoords,
|
|
64
|
+
xTranslate: 0,
|
|
65
|
+
yTranslate: position,
|
|
66
|
+
textProps,
|
|
67
|
+
textStyle: style,
|
|
68
|
+
tickValue: yScale.getTickFormatted(tickValue),
|
|
69
|
+
...rest
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
[style, textProps, yAxis?.tick?.color, yScale]
|
|
74
|
+
);
|
|
75
|
+
const axisColor = useMemo(() => COLOR_PALLET[yAxis.color] || yAxis.color, [yAxis.color]);
|
|
76
|
+
return useMemo(() => {
|
|
77
|
+
if (yAxis.hideAxis)
|
|
78
|
+
return null;
|
|
79
|
+
const lineCoords = {
|
|
80
|
+
x1: 0,
|
|
81
|
+
x2: 0,
|
|
82
|
+
y1: 0,
|
|
83
|
+
y2: innerHeight
|
|
84
|
+
};
|
|
85
|
+
return /* @__PURE__ */ jsx(
|
|
86
|
+
Axis,
|
|
87
|
+
{
|
|
88
|
+
lineCoords,
|
|
89
|
+
scale: yScale,
|
|
90
|
+
innerRef: setAxisLeftRef,
|
|
91
|
+
dimension: height,
|
|
92
|
+
GridRenderer,
|
|
93
|
+
TickRenderer,
|
|
94
|
+
color: axisColor
|
|
37
95
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
if (ref?.current && gridRef?.current) {
|
|
43
|
-
select(gridRef.current).call(grid);
|
|
44
|
-
const axisNode = select(ref.current);
|
|
45
|
-
axisNode.call(axis);
|
|
46
|
-
if (tickRotation)
|
|
47
|
-
axisNode.selectAll("text").style("text-anchor", "end").attr("dx", "-.8em").attr("dy", ".15em").attr("transform", `rotate(-${tickRotation})`);
|
|
48
|
-
}
|
|
49
|
-
}, [
|
|
50
|
-
innerHeight,
|
|
51
|
-
innerWidth,
|
|
52
|
-
overwriteTicks,
|
|
53
|
-
showGrid,
|
|
54
|
-
tickFormat,
|
|
55
|
-
tickRotation,
|
|
56
|
-
tickValues,
|
|
57
|
-
ticks,
|
|
58
|
-
type,
|
|
59
|
-
yAxis,
|
|
60
|
-
yScale
|
|
61
|
-
]);
|
|
62
|
-
if (yAxis.hideAxis)
|
|
63
|
-
return null;
|
|
64
|
-
return /* @__PURE__ */ jsxs("g", { children: [
|
|
65
|
-
/* @__PURE__ */ jsx("g", { mask: `url(#mask-${chartId})`, children: /* @__PURE__ */ jsx(StyledGrid, { ref: gridRef }) }),
|
|
66
|
-
/* @__PURE__ */ jsx("g", { ref: setAxisLeftRef, children: /* @__PURE__ */ jsx(StyledAxis, { axisColor, ref, tickColor, className: "axis-left" }) })
|
|
67
|
-
] });
|
|
68
|
-
};
|
|
96
|
+
);
|
|
97
|
+
}, [GridRenderer, TickRenderer, axisColor, height, innerHeight, setAxisLeftRef, yAxis.hideAxis, yScale]);
|
|
98
|
+
});
|
|
69
99
|
export {
|
|
70
100
|
AxisLeft
|
|
71
101
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../scripts/build/transpile/react-shim.js", "../../../../../../src/graphs/Chart/parts/Axis/AxisLeft.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, {
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport React, { type CSSProperties, useCallback, useContext, useMemo } from 'react';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { Axis, type TickRenderPropsT, type GridRenderPropsT } from './Axis';\nimport { Tick } from './Tick';\nimport { GridLine } from './GridLine';\nimport { COLOR_PALLET } from '../../helpers/colorPallet';\n\nexport const AxisLeft = React.memo(() => {\n const {\n props: { yAxis },\n innerHeight,\n height,\n yScale,\n innerWidth,\n setAxisLeftRef,\n } = useContext(ChartContext);\n\n const { tickRotation } = yAxis.tick || ({} as DSChartT.AxisTickT);\n const { showGrid } = yAxis;\n\n const textProps = useMemo(() => {\n const commomProps = { fill: COLOR_PALLET[yAxis?.tick?.color as keyof typeof COLOR_PALLET] || yAxis?.tick?.color };\n if (!tickRotation) return { ...commomProps, x: -10, dy: '0.32em' };\n return {\n ...commomProps,\n dy: '.30em',\n dx: '-.10em',\n x: Math.trunc(-(11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1))),\n transform: `rotate(${tickRotation})`,\n };\n }, [tickRotation, yAxis?.tick?.color]);\n\n const style: CSSProperties = useMemo(\n () => ({\n textAnchor: 'end',\n }),\n [],\n );\n\n const GridRenderer = useCallback(\n (props: GridRenderPropsT) => {\n if (!showGrid) return null;\n const { position, ...rest } = props;\n const gridLineCoords = {\n x1: 0,\n x2: innerWidth,\n y1: position,\n y2: position,\n };\n return <GridLine {...gridLineCoords} {...rest} />;\n },\n [showGrid, innerWidth],\n );\n\n const TickRenderer = useCallback(\n (props: TickRenderPropsT) => {\n const { position, tickValue, ...rest } = props;\n const tickLineCoords = {\n x2: -5,\n stroke: COLOR_PALLET[yAxis?.tick?.color as keyof typeof COLOR_PALLET] || yAxis?.tick?.color,\n };\n return (\n <Tick\n {...tickLineCoords}\n xTranslate={0}\n yTranslate={position}\n textProps={textProps}\n textStyle={style}\n tickValue={yScale.getTickFormatted(tickValue)}\n {...rest}\n />\n );\n },\n [style, textProps, yAxis?.tick?.color, yScale],\n );\n\n const axisColor = useMemo(() => COLOR_PALLET[yAxis.color as keyof typeof COLOR_PALLET] || yAxis.color, [yAxis.color]);\n\n return useMemo(() => {\n if (yAxis.hideAxis) return null;\n const lineCoords = {\n x1: 0,\n x2: 0,\n y1: 0,\n y2: innerHeight,\n };\n\n return (\n <Axis\n lineCoords={lineCoords}\n scale={yScale}\n innerRef={setAxisLeftRef}\n dimension={height}\n GridRenderer={GridRenderer}\n TickRenderer={TickRenderer}\n color={axisColor}\n />\n );\n }, [GridRenderer, TickRenderer, axisColor, height, innerHeight, setAxisLeftRef, yAxis.hideAxis, yScale]);\n});\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACoDV;AAlDb,OAAOA,UAA6B,aAAa,YAAY,eAAe;AAC5E,SAAS,oBAAoB;AAE7B,SAAS,YAA0D;AACnE,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAEtB,MAAM,WAAWA,OAAM,KAAK,MAAM;AACvC,QAAM;AAAA,IACJ,OAAO,EAAE,MAAM;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,YAAY;AAE3B,QAAM,EAAE,aAAa,IAAI,MAAM,QAAS,CAAC;AACzC,QAAM,EAAE,SAAS,IAAI;AAErB,QAAM,YAAY,QAAQ,MAAM;AAC9B,UAAM,cAAc,EAAE,MAAM,aAAa,OAAO,MAAM,UAAuC,OAAO,MAAM,MAAM;AAChH,QAAI,CAAC;AAAc,aAAO,EAAE,GAAG,aAAa,GAAG,KAAK,IAAI,SAAS;AACjE,WAAO;AAAA,MACL,GAAG;AAAA,MACH,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,GAAG,KAAK,MAAM,EAAE,OAAO,OAAO,eAAe,OAAO,eAAe,IAAI,IAAI,IAAI;AAAA,MAC/E,WAAW,UAAU;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,cAAc,OAAO,MAAM,KAAK,CAAC;AAErC,QAAM,QAAuB;AAAA,IAC3B,OAAO;AAAA,MACL,YAAY;AAAA,IACd;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,eAAe;AAAA,IACnB,CAAC,UAA4B;AAC3B,UAAI,CAAC;AAAU,eAAO;AACtB,YAAM,EAAE,aAAa,KAAK,IAAI;AAC9B,YAAM,iBAAiB;AAAA,QACrB,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AACA,aAAO,oBAAC,YAAU,GAAG,gBAAiB,GAAG,MAAM;AAAA,IACjD;AAAA,IACA,CAAC,UAAU,UAAU;AAAA,EACvB;AAEA,QAAM,eAAe;AAAA,IACnB,CAAC,UAA4B;AAC3B,YAAM,EAAE,UAAU,cAAc,KAAK,IAAI;AACzC,YAAM,iBAAiB;AAAA,QACrB,IAAI;AAAA,QACJ,QAAQ,aAAa,OAAO,MAAM,UAAuC,OAAO,MAAM;AAAA,MACxF;AACA,aACE;AAAA,QAAC;AAAA;AAAA,UACE,GAAG;AAAA,UACJ,YAAY;AAAA,UACZ,YAAY;AAAA,UACZ;AAAA,UACA,WAAW;AAAA,UACX,WAAW,OAAO,iBAAiB,SAAS;AAAA,UAC3C,GAAG;AAAA;AAAA,MACN;AAAA,IAEJ;AAAA,IACA,CAAC,OAAO,WAAW,OAAO,MAAM,OAAO,MAAM;AAAA,EAC/C;AAEA,QAAM,YAAY,QAAQ,MAAM,aAAa,MAAM,UAAuC,MAAM,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpH,SAAO,QAAQ,MAAM;AACnB,QAAI,MAAM;AAAU,aAAO;AAC3B,UAAM,aAAa;AAAA,MACjB,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IACN;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,OAAO;AAAA,QACP,UAAU;AAAA,QACV,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA,OAAO;AAAA;AAAA,IACT;AAAA,EAEJ,GAAG,CAAC,cAAc,cAAc,WAAW,QAAQ,aAAa,gBAAgB,MAAM,UAAU,MAAM,CAAC;AACzG,CAAC;",
|
|
6
|
+
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -1,69 +1,104 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { jsx
|
|
3
|
-
import {
|
|
4
|
-
import { select, axisRight } from "d3";
|
|
5
|
-
import { StyledAxis, StyledGrid } from "../../styles";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import React2, { useCallback, useContext, useMemo } from "react";
|
|
6
4
|
import { ChartContext } from "../../ChartContext";
|
|
7
|
-
import {
|
|
8
|
-
|
|
5
|
+
import { Axis } from "./Axis";
|
|
6
|
+
import { Tick } from "./Tick";
|
|
7
|
+
import { GridLine } from "./GridLine";
|
|
8
|
+
import { COLOR_PALLET } from "../../helpers/colorPallet";
|
|
9
|
+
const AxisRight = React2.memo(() => {
|
|
9
10
|
const {
|
|
10
11
|
props: { y2Axis },
|
|
11
12
|
innerHeight,
|
|
12
|
-
innerWidth,
|
|
13
13
|
y2Scale,
|
|
14
|
-
|
|
15
|
-
height,
|
|
14
|
+
innerWidth,
|
|
16
15
|
setAxisRightRef
|
|
17
16
|
} = useContext(ChartContext);
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
const { tickRotation } = y2Axis?.tick || {};
|
|
18
|
+
const { showGrid } = y2Axis;
|
|
19
|
+
const textProps = useMemo(() => {
|
|
20
|
+
const commomProps = { fill: COLOR_PALLET[y2Axis?.tick?.color] || y2Axis?.tick?.color };
|
|
21
|
+
if (!tickRotation)
|
|
22
|
+
return { ...commomProps, x: 10, dy: "0.32em" };
|
|
23
|
+
return {
|
|
24
|
+
...commomProps,
|
|
25
|
+
dx: 8 * Math.sin(Math.PI * (tickRotation / 180)),
|
|
26
|
+
dy: ".71em",
|
|
27
|
+
y: 11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1),
|
|
28
|
+
transform: `rotate(${tickRotation})`
|
|
29
|
+
};
|
|
30
|
+
}, [tickRotation, y2Axis?.tick?.color]);
|
|
31
|
+
const style = useMemo(() => {
|
|
32
|
+
if (!tickRotation)
|
|
33
|
+
return {
|
|
34
|
+
textAnchor: "start"
|
|
35
|
+
};
|
|
36
|
+
return { textAnchor: tickRotation > 0 ? "start" : "end" };
|
|
37
|
+
}, [tickRotation]);
|
|
38
|
+
const GridRenderer = useCallback(
|
|
39
|
+
(props) => {
|
|
40
|
+
if (!showGrid)
|
|
41
|
+
return null;
|
|
42
|
+
const { position, ...rest } = props;
|
|
43
|
+
const gridLineCoords = {
|
|
44
|
+
x1: 0,
|
|
45
|
+
x2: innerWidth,
|
|
46
|
+
y1: position,
|
|
47
|
+
y2: position
|
|
48
|
+
};
|
|
49
|
+
return /* @__PURE__ */ jsx(GridLine, { ...gridLineCoords, ...rest });
|
|
50
|
+
},
|
|
51
|
+
[innerWidth, showGrid]
|
|
52
|
+
);
|
|
53
|
+
const TickRenderer = useCallback(
|
|
54
|
+
(props) => {
|
|
55
|
+
const { position, tickValue, ...rest } = props;
|
|
56
|
+
const tickLineCoords = {
|
|
57
|
+
x2: 5,
|
|
58
|
+
stroke: COLOR_PALLET[y2Axis?.tick?.color] || y2Axis?.tick?.color
|
|
59
|
+
};
|
|
60
|
+
return /* @__PURE__ */ jsx(
|
|
61
|
+
Tick,
|
|
62
|
+
{
|
|
63
|
+
...tickLineCoords,
|
|
64
|
+
yTranslate: position,
|
|
65
|
+
xTranslate: innerWidth,
|
|
66
|
+
textProps,
|
|
67
|
+
textStyle: style,
|
|
68
|
+
tickValue: y2Scale.getTickFormatted(tickValue),
|
|
69
|
+
...rest
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
[innerWidth, style, textProps, y2Axis?.tick?.color, y2Scale]
|
|
74
|
+
);
|
|
75
|
+
const axisColor = useMemo(
|
|
76
|
+
() => COLOR_PALLET[y2Axis.color] || y2Axis.color,
|
|
77
|
+
[y2Axis.color]
|
|
78
|
+
);
|
|
79
|
+
return useMemo(() => {
|
|
80
|
+
if (y2Axis?.hideAxis)
|
|
81
|
+
return null;
|
|
82
|
+
const lineCoords = {
|
|
83
|
+
x1: innerWidth,
|
|
84
|
+
x2: innerWidth,
|
|
85
|
+
y1: 0,
|
|
86
|
+
y2: innerHeight
|
|
87
|
+
};
|
|
88
|
+
return /* @__PURE__ */ jsx(
|
|
89
|
+
Axis,
|
|
90
|
+
{
|
|
91
|
+
lineCoords,
|
|
92
|
+
scale: y2Scale,
|
|
93
|
+
innerRef: setAxisRightRef,
|
|
94
|
+
dimension: innerHeight,
|
|
95
|
+
GridRenderer,
|
|
96
|
+
TickRenderer,
|
|
97
|
+
color: axisColor
|
|
40
98
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const axisNode = select(ref.current);
|
|
45
|
-
axisNode.call(axis);
|
|
46
|
-
}
|
|
47
|
-
}, [
|
|
48
|
-
innerHeight,
|
|
49
|
-
innerWidth,
|
|
50
|
-
overwriteTicks,
|
|
51
|
-
showGrid,
|
|
52
|
-
tickFormat,
|
|
53
|
-
tickRotation,
|
|
54
|
-
tickValues,
|
|
55
|
-
ticks,
|
|
56
|
-
type,
|
|
57
|
-
y2Axis,
|
|
58
|
-
y2Scale
|
|
59
|
-
]);
|
|
60
|
-
if (y2Axis.hideAxis)
|
|
61
|
-
return null;
|
|
62
|
-
return /* @__PURE__ */ jsxs("g", { transform: `translate(${innerWidth},0)`, children: [
|
|
63
|
-
/* @__PURE__ */ jsx("g", { mask: `url(#mask-${chartId})`, children: /* @__PURE__ */ jsx(StyledGrid, { ref: gridRef }) }),
|
|
64
|
-
/* @__PURE__ */ jsx("g", { ref: setAxisRightRef, children: /* @__PURE__ */ jsx(StyledAxis, { axisColor, ref, tickColor, className: "axis-right" }) })
|
|
65
|
-
] });
|
|
66
|
-
};
|
|
99
|
+
);
|
|
100
|
+
}, [GridRenderer, TickRenderer, axisColor, innerHeight, innerWidth, setAxisRightRef, y2Axis?.hideAxis, y2Scale]);
|
|
101
|
+
});
|
|
67
102
|
export {
|
|
68
103
|
AxisRight
|
|
69
104
|
};
|