@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.
Files changed (164) hide show
  1. package/dist/cjs/graphs/Chart/ChartContext.js.map +2 -2
  2. package/dist/cjs/graphs/Chart/config/useChart.js +1 -1
  3. package/dist/cjs/graphs/Chart/config/useChart.js.map +2 -2
  4. package/dist/cjs/graphs/Chart/config/useGetters.js +4 -4
  5. package/dist/cjs/graphs/Chart/config/useGetters.js.map +2 -2
  6. package/dist/cjs/graphs/Chart/config/useInternalMargins.js +2 -2
  7. package/dist/cjs/graphs/Chart/config/useInternalMargins.js.map +2 -2
  8. package/dist/cjs/graphs/Chart/config/useKeyboardNavigation.js +4 -4
  9. package/dist/cjs/graphs/Chart/config/useKeyboardNavigation.js.map +2 -2
  10. package/dist/cjs/graphs/Chart/config/useScales.js +53 -37
  11. package/dist/cjs/graphs/Chart/config/useScales.js.map +2 -2
  12. package/dist/cjs/graphs/Chart/helpers/index.js +2 -2
  13. package/dist/cjs/graphs/Chart/helpers/index.js.map +2 -2
  14. package/dist/cjs/graphs/Chart/helpers/useUniqueData.js +5 -5
  15. package/dist/cjs/graphs/Chart/helpers/useUniqueData.js.map +2 -2
  16. package/dist/cjs/graphs/Chart/helpers/useVirtualizedSeries.js +4 -4
  17. package/dist/cjs/graphs/Chart/helpers/useVirtualizedSeries.js.map +2 -2
  18. package/dist/cjs/graphs/Chart/parts/Axis/Axis.js +47 -0
  19. package/dist/cjs/graphs/Chart/parts/Axis/Axis.js.map +7 -0
  20. package/dist/cjs/graphs/Chart/parts/Axis/AxisBottom.js +88 -71
  21. package/dist/cjs/graphs/Chart/parts/Axis/AxisBottom.js.map +2 -2
  22. package/dist/cjs/graphs/Chart/parts/Axis/AxisLeft.js +88 -58
  23. package/dist/cjs/graphs/Chart/parts/Axis/AxisLeft.js.map +3 -3
  24. package/dist/cjs/graphs/Chart/parts/Axis/AxisRight.js +91 -56
  25. package/dist/cjs/graphs/Chart/parts/Axis/AxisRight.js.map +3 -3
  26. package/dist/cjs/graphs/Chart/parts/{Labels/BottomLabel.js → Axis/GridLine.js} +7 -26
  27. package/dist/cjs/graphs/Chart/parts/Axis/GridLine.js.map +7 -0
  28. package/dist/cjs/graphs/Chart/parts/{Labels/LeftLabel.js → Axis/Tick.js} +12 -25
  29. package/dist/cjs/graphs/Chart/parts/Axis/Tick.js.map +7 -0
  30. package/dist/cjs/graphs/Chart/parts/ChartContainer.js +2 -2
  31. package/dist/cjs/graphs/Chart/parts/ChartContainer.js.map +2 -2
  32. package/dist/cjs/graphs/Chart/parts/Labels/Label.js +3 -18
  33. package/dist/cjs/graphs/Chart/parts/Labels/Label.js.map +3 -3
  34. package/dist/cjs/graphs/Chart/parts/Labels/index.js +102 -0
  35. package/dist/cjs/graphs/Chart/parts/Labels/index.js.map +7 -0
  36. package/dist/cjs/graphs/Chart/parts/Scrapper/Scrapper.js +5 -5
  37. package/dist/cjs/graphs/Chart/parts/Scrapper/Scrapper.js.map +2 -2
  38. package/dist/cjs/graphs/Chart/parts/Scrapper/ScrapperLine.js +1 -1
  39. package/dist/cjs/graphs/Chart/parts/Scrapper/ScrapperLine.js.map +2 -2
  40. package/dist/cjs/graphs/Chart/parts/Scrapper/VerticalScrapperLine.js +3 -3
  41. package/dist/cjs/graphs/Chart/parts/Scrapper/VerticalScrapperLine.js.map +2 -2
  42. package/dist/cjs/graphs/Chart/parts/Scroller/Controllers.js +1 -1
  43. package/dist/cjs/graphs/Chart/parts/Scroller/Controllers.js.map +2 -2
  44. package/dist/cjs/graphs/Chart/parts/Scroller/ScrollableContainerX.js +5 -5
  45. package/dist/cjs/graphs/Chart/parts/Scroller/ScrollableContainerX.js.map +2 -2
  46. package/dist/cjs/graphs/Chart/parts/TrendHighlight.js +1 -1
  47. package/dist/cjs/graphs/Chart/parts/TrendHighlight.js.map +1 -1
  48. package/dist/cjs/graphs/Chart/react-desc-prop-types.js.map +2 -2
  49. package/dist/cjs/graphs/Chart/scales/index.js +186 -0
  50. package/dist/cjs/graphs/Chart/scales/index.js.map +7 -0
  51. package/dist/cjs/graphs/Chart/series/Area.js +5 -5
  52. package/dist/cjs/graphs/Chart/series/Area.js.map +2 -2
  53. package/dist/cjs/graphs/Chart/series/Bars.js +7 -4
  54. package/dist/cjs/graphs/Chart/series/Bars.js.map +2 -2
  55. package/dist/cjs/graphs/Chart/series/HorizontalBars.js +4 -4
  56. package/dist/cjs/graphs/Chart/series/HorizontalBars.js.map +2 -2
  57. package/dist/cjs/graphs/Chart/series/HorizontalStackedBars.js +3 -3
  58. package/dist/cjs/graphs/Chart/series/HorizontalStackedBars.js.map +2 -2
  59. package/dist/cjs/graphs/Chart/series/Line.js +2 -2
  60. package/dist/cjs/graphs/Chart/series/Line.js.map +2 -2
  61. package/dist/cjs/graphs/Chart/series/Points.js +2 -2
  62. package/dist/cjs/graphs/Chart/series/Points.js.map +2 -2
  63. package/dist/cjs/graphs/Chart/series/Rect.js +1 -1
  64. package/dist/cjs/graphs/Chart/series/Rect.js.map +2 -2
  65. package/dist/cjs/graphs/Chart/series/StackedBar.js +3 -3
  66. package/dist/cjs/graphs/Chart/series/StackedBar.js.map +2 -2
  67. package/dist/cjs/graphs/Chart/styles.js +4 -26
  68. package/dist/cjs/graphs/Chart/styles.js.map +2 -2
  69. package/dist/esm/graphs/Chart/ChartContext.js.map +2 -2
  70. package/dist/esm/graphs/Chart/config/useChart.js +1 -1
  71. package/dist/esm/graphs/Chart/config/useChart.js.map +2 -2
  72. package/dist/esm/graphs/Chart/config/useGetters.js +4 -4
  73. package/dist/esm/graphs/Chart/config/useGetters.js.map +2 -2
  74. package/dist/esm/graphs/Chart/config/useInternalMargins.js +2 -2
  75. package/dist/esm/graphs/Chart/config/useInternalMargins.js.map +2 -2
  76. package/dist/esm/graphs/Chart/config/useKeyboardNavigation.js +4 -4
  77. package/dist/esm/graphs/Chart/config/useKeyboardNavigation.js.map +2 -2
  78. package/dist/esm/graphs/Chart/config/useScales.js +53 -37
  79. package/dist/esm/graphs/Chart/config/useScales.js.map +2 -2
  80. package/dist/esm/graphs/Chart/helpers/index.js +2 -2
  81. package/dist/esm/graphs/Chart/helpers/index.js.map +2 -2
  82. package/dist/esm/graphs/Chart/helpers/useUniqueData.js +5 -5
  83. package/dist/esm/graphs/Chart/helpers/useUniqueData.js.map +2 -2
  84. package/dist/esm/graphs/Chart/helpers/useVirtualizedSeries.js +4 -4
  85. package/dist/esm/graphs/Chart/helpers/useVirtualizedSeries.js.map +2 -2
  86. package/dist/esm/graphs/Chart/parts/Axis/Axis.js +21 -0
  87. package/dist/esm/graphs/Chart/parts/Axis/Axis.js.map +7 -0
  88. package/dist/esm/graphs/Chart/parts/Axis/AxisBottom.js +90 -73
  89. package/dist/esm/graphs/Chart/parts/Axis/AxisBottom.js.map +2 -2
  90. package/dist/esm/graphs/Chart/parts/Axis/AxisLeft.js +89 -59
  91. package/dist/esm/graphs/Chart/parts/Axis/AxisLeft.js.map +3 -3
  92. package/dist/esm/graphs/Chart/parts/Axis/AxisRight.js +92 -57
  93. package/dist/esm/graphs/Chart/parts/Axis/AxisRight.js.map +3 -3
  94. package/dist/esm/graphs/Chart/parts/Axis/GridLine.js +8 -0
  95. package/dist/esm/graphs/Chart/parts/Axis/GridLine.js.map +7 -0
  96. package/dist/esm/graphs/Chart/parts/Axis/Tick.js +13 -0
  97. package/dist/esm/graphs/Chart/parts/Axis/Tick.js.map +7 -0
  98. package/dist/esm/graphs/Chart/parts/ChartContainer.js +2 -2
  99. package/dist/esm/graphs/Chart/parts/ChartContainer.js.map +2 -2
  100. package/dist/esm/graphs/Chart/parts/Labels/Label.js +4 -19
  101. package/dist/esm/graphs/Chart/parts/Labels/Label.js.map +3 -3
  102. package/dist/esm/graphs/Chart/parts/Labels/index.js +76 -0
  103. package/dist/esm/graphs/Chart/parts/Labels/index.js.map +7 -0
  104. package/dist/esm/graphs/Chart/parts/Scrapper/Scrapper.js +5 -5
  105. package/dist/esm/graphs/Chart/parts/Scrapper/Scrapper.js.map +2 -2
  106. package/dist/esm/graphs/Chart/parts/Scrapper/ScrapperLine.js +1 -1
  107. package/dist/esm/graphs/Chart/parts/Scrapper/ScrapperLine.js.map +2 -2
  108. package/dist/esm/graphs/Chart/parts/Scrapper/VerticalScrapperLine.js +3 -3
  109. package/dist/esm/graphs/Chart/parts/Scrapper/VerticalScrapperLine.js.map +2 -2
  110. package/dist/esm/graphs/Chart/parts/Scroller/Controllers.js +1 -1
  111. package/dist/esm/graphs/Chart/parts/Scroller/Controllers.js.map +2 -2
  112. package/dist/esm/graphs/Chart/parts/Scroller/ScrollableContainerX.js +5 -5
  113. package/dist/esm/graphs/Chart/parts/Scroller/ScrollableContainerX.js.map +2 -2
  114. package/dist/esm/graphs/Chart/parts/TrendHighlight.js +1 -1
  115. package/dist/esm/graphs/Chart/parts/TrendHighlight.js.map +1 -1
  116. package/dist/esm/graphs/Chart/react-desc-prop-types.js.map +2 -2
  117. package/dist/esm/graphs/Chart/scales/index.js +160 -0
  118. package/dist/esm/graphs/Chart/scales/index.js.map +7 -0
  119. package/dist/esm/graphs/Chart/series/Area.js +5 -5
  120. package/dist/esm/graphs/Chart/series/Area.js.map +2 -2
  121. package/dist/esm/graphs/Chart/series/Bars.js +7 -4
  122. package/dist/esm/graphs/Chart/series/Bars.js.map +2 -2
  123. package/dist/esm/graphs/Chart/series/HorizontalBars.js +4 -4
  124. package/dist/esm/graphs/Chart/series/HorizontalBars.js.map +2 -2
  125. package/dist/esm/graphs/Chart/series/HorizontalStackedBars.js +3 -3
  126. package/dist/esm/graphs/Chart/series/HorizontalStackedBars.js.map +2 -2
  127. package/dist/esm/graphs/Chart/series/Line.js +2 -2
  128. package/dist/esm/graphs/Chart/series/Line.js.map +2 -2
  129. package/dist/esm/graphs/Chart/series/Points.js +2 -2
  130. package/dist/esm/graphs/Chart/series/Points.js.map +2 -2
  131. package/dist/esm/graphs/Chart/series/Rect.js +1 -1
  132. package/dist/esm/graphs/Chart/series/Rect.js.map +2 -2
  133. package/dist/esm/graphs/Chart/series/StackedBar.js +3 -3
  134. package/dist/esm/graphs/Chart/series/StackedBar.js.map +2 -2
  135. package/dist/esm/graphs/Chart/styles.js +4 -26
  136. package/dist/esm/graphs/Chart/styles.js.map +2 -2
  137. package/dist/types/graphs/Chart/ChartContext.d.ts +12 -4
  138. package/dist/types/graphs/Chart/config/useChart.d.ts +6 -6
  139. package/dist/types/graphs/Chart/config/useGetters.d.ts +2 -2
  140. package/dist/types/graphs/Chart/config/useScales.d.ts +6 -5
  141. package/dist/types/graphs/Chart/parts/Axis/Axis.d.ts +26 -0
  142. package/dist/types/graphs/Chart/parts/Axis/AxisLeft.d.ts +2 -1
  143. package/dist/types/graphs/Chart/parts/Axis/AxisRight.d.ts +2 -1
  144. package/dist/types/graphs/Chart/parts/Axis/GridLine.d.ts +9 -0
  145. package/dist/types/graphs/Chart/parts/Axis/Tick.d.ts +15 -0
  146. package/dist/types/graphs/Chart/parts/Labels/Label.d.ts +10 -1
  147. package/dist/types/graphs/Chart/parts/Labels/index.d.ts +1 -0
  148. package/dist/types/graphs/Chart/react-desc-prop-types.d.ts +3 -2
  149. package/dist/types/graphs/Chart/scales/index.d.ts +53 -0
  150. package/dist/types/graphs/Chart/styles.d.ts +1 -2
  151. package/package.json +4 -4
  152. package/dist/cjs/graphs/Chart/parts/Labels/BottomLabel.js.map +0 -7
  153. package/dist/cjs/graphs/Chart/parts/Labels/LeftLabel.js.map +0 -7
  154. package/dist/cjs/graphs/Chart/parts/Labels/RightLabel.js +0 -56
  155. package/dist/cjs/graphs/Chart/parts/Labels/RightLabel.js.map +0 -7
  156. package/dist/esm/graphs/Chart/parts/Labels/BottomLabel.js +0 -27
  157. package/dist/esm/graphs/Chart/parts/Labels/BottomLabel.js.map +0 -7
  158. package/dist/esm/graphs/Chart/parts/Labels/LeftLabel.js +0 -26
  159. package/dist/esm/graphs/Chart/parts/Labels/LeftLabel.js.map +0 -7
  160. package/dist/esm/graphs/Chart/parts/Labels/RightLabel.js +0 -30
  161. package/dist/esm/graphs/Chart/parts/Labels/RightLabel.js.map +0 -7
  162. package/dist/types/graphs/Chart/parts/Labels/BottomLabel.d.ts +0 -1
  163. package/dist/types/graphs/Chart/parts/Labels/LeftLabel.d.ts +0 -1
  164. 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, jsxs } from "react/jsx-runtime";
3
- import React2, { useContext, useEffect, useRef } from "react";
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 { useUniqueData } from "../../helpers/useUniqueData";
8
- import { getFormatGenerator } from "../../helpers";
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 axisRef = useRef(null);
21
- const gridRef = useRef(null);
22
- const { tickValues, tickFormat, overwriteTicks, color, tickRotation, tickCount } = xAxis.tick || {};
23
- const ticksScales = ["linear", "time", "log"];
24
- const uniqueData = useUniqueData();
25
- useEffect(() => {
26
- const grid = axisBottom(xScale).tickSize(-innerHeight).tickFormat("").tickSizeOuter(0);
27
- const axis = axisBottom(xScale).tickSizeOuter(0);
28
- if (ticksScales.includes(xAxis.type)) {
29
- const ticksNum = (() => {
30
- if (tickCount)
31
- return tickCount;
32
- if (containerRatio > 1) {
33
- return innerWidth / 80 * containerRatio;
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
- return innerWidth / 80;
36
- })();
37
- const ticks = xScale.ticks?.(ticksNum);
38
- if (containerRatio > 1 && uniqueData.length < 10 && !isHorizontal) {
39
- const ticksName = uniqueData.map((u) => u.xValue);
40
- axis.tickValues(ticksName);
41
- grid.tickValues(ticksName);
42
- } else if (tickValues && ticks) {
43
- const finalTicks = overwriteTicks ? tickValues : [...ticks, ...tickValues];
44
- axis.tickValues(finalTicks);
45
- } else {
46
- axis.tickValues(ticks);
47
- grid.tickValues(ticks);
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
- innerHeight,
69
- overwriteTicks,
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
- uniqueData.length,
81
- uniqueData,
82
- internalMargin.left,
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, useEffect, useRef } from 'react';\nimport type { ScaleLinear, ScaleTime } from 'd3';\nimport { select, axisBottom } from 'd3';\nimport { StyledAxis, StyledGrid } from '../../styles';\nimport { ChartContext } from '../../ChartContext';\nimport type { DSChartT } from '../../react-desc-prop-types';\nimport { useUniqueData } from '../../helpers/useUniqueData';\nimport { getFormatGenerator } from '../../helpers';\n\nexport const AxisBottom = React.memo(() => {\n const {\n props: { xAxis },\n innerHeight,\n xScale,\n innerWidth,\n containerRatio,\n internalMargin,\n isHorizontal,\n setAxisBottomRef,\n } = useContext(ChartContext);\n\n const axisRef = useRef<SVGSVGElement>(null);\n const gridRef = useRef<SVGSVGElement>(null);\n const { tickValues, tickFormat, overwriteTicks, color, tickRotation, tickCount } =\n xAxis.tick || ({} as DSChartT.AxisTickT);\n\n const ticksScales = ['linear', 'time', 'log'];\n // const ticks = xScale.ticks?.(tickCount ?? width / 100);\n\n const uniqueData = useUniqueData();\n useEffect(() => {\n const grid = axisBottom(xScale as ScaleLinear<number, number>)\n .tickSize(-innerHeight)\n .tickFormat('')\n .tickSizeOuter(0);\n\n const axis = axisBottom(xScale as ScaleLinear<number, number>).tickSizeOuter(0);\n\n if (ticksScales.includes(xAxis.type)) {\n const ticksNum = (() => {\n if (tickCount) return tickCount;\n if (containerRatio > 1) {\n return (innerWidth / 80) * containerRatio;\n }\n return innerWidth / 80;\n })();\n const ticks = (xScale as ScaleLinear<number, number> | ScaleTime<number, number, never>).ticks?.(ticksNum);\n\n // we show the only the ticks values on the screen when zoomed enough\n // @todo we need to improve this logic\n if (containerRatio > 1 && uniqueData.length < 10 && !isHorizontal) {\n const ticksName = uniqueData.map((u) => u.xValue);\n axis.tickValues(ticksName);\n grid.tickValues(ticksName);\n } else if (tickValues && ticks) {\n const finalTicks = overwriteTicks ? tickValues : [...ticks, ...tickValues];\n axis.tickValues(finalTicks);\n } else {\n axis.tickValues(ticks);\n grid.tickValues(ticks);\n }\n }\n\n if (tickFormat) {\n if (typeof tickFormat === 'string') {\n const formatGenerator = getFormatGenerator(xAxis.type ?? 'linear');\n axis.tickFormat((d) => formatGenerator(tickFormat)(d));\n }\n if (typeof tickFormat === 'function') {\n axis.tickFormat(tickFormat);\n }\n }\n\n if (axisRef?.current && gridRef?.current) {\n if (xAxis?.showGrid) select(gridRef.current).call(grid);\n const axisNode = select(axisRef.current);\n axisNode.call(axis);\n\n // // need to remove the first tick when live under the domain line\n // const firstTick = axisNode.select('.tick').node() as SVGGElement; // select all the text elements\n // if (firstTick?.getBoundingClientRect().left < internalMargin.left + 10 && !xScale.bandwidth) {\n // firstTick.remove();\n // }\n if (tickRotation)\n axisNode\n .selectAll('text')\n .style('text-anchor', tickRotation > 0 ? 'start' : 'end')\n .attr('dx', 8 * Math.sin(Math.PI * (tickRotation / 180)))\n .attr('dy', '.71em')\n .attr('y', 11.5 - 2.5 * (tickRotation / 15) * (tickRotation > 0 ? 1 : -1))\n .attr('transform', `rotate(${tickRotation})`);\n }\n }, [\n innerHeight,\n overwriteTicks,\n xAxis?.showGrid,\n tickFormat,\n tickValues,\n xScale,\n tickRotation,\n xAxis.type,\n ticksScales,\n tickCount,\n containerRatio,\n innerWidth,\n uniqueData.length,\n uniqueData,\n internalMargin.left,\n isHorizontal,\n ]);\n if (xAxis.hideAxis) return null;\n return (\n <g transform={`translate(0,${innerHeight})`}>\n <g ref={setAxisBottomRef}>\n <StyledAxis axisColor={xAxis.color} tickColor={color} ref={axisRef}></StyledAxis>\n </g>\n <StyledGrid ref={gridRef}></StyledGrid>\n </g>\n );\n});\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACkHnB,SAEI,KAFJ;AAhHJ,OAAOA,UAAS,YAAY,WAAW,cAAc;AAErD,SAAS,QAAQ,kBAAkB;AACnC,SAAS,YAAY,kBAAkB;AACvC,SAAS,oBAAoB;AAE7B,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AAE5B,MAAM,aAAaA,OAAM,KAAK,MAAM;AACzC,QAAM;AAAA,IACJ,OAAO,EAAE,MAAM;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,YAAY;AAE3B,QAAM,UAAU,OAAsB,IAAI;AAC1C,QAAM,UAAU,OAAsB,IAAI;AAC1C,QAAM,EAAE,YAAY,YAAY,gBAAgB,OAAO,cAAc,UAAU,IAC7E,MAAM,QAAS,CAAC;AAElB,QAAM,cAAc,CAAC,UAAU,QAAQ,KAAK;AAG5C,QAAM,aAAa,cAAc;AACjC,YAAU,MAAM;AACd,UAAM,OAAO,WAAW,MAAqC,EAC1D,SAAS,CAAC,WAAW,EACrB,WAAW,EAAE,EACb,cAAc,CAAC;AAElB,UAAM,OAAO,WAAW,MAAqC,EAAE,cAAc,CAAC;AAE9E,QAAI,YAAY,SAAS,MAAM,IAAI,GAAG;AACpC,YAAM,YAAY,MAAM;AACtB,YAAI;AAAW,iBAAO;AACtB,YAAI,iBA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AAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA,eAAe;AAAA,IACf;AAAA,EACF,CAAC;AACD,MAAI,MAAM;AAAU,WAAO;AAC3B,SACE,qBAAC,OAAE,WAAW,eAAe,gBAC3B;AAAA,wBAAC,OAAE,KAAK,kBACN,8BAAC,cAAW,WAAW,MAAM,OAAO,WAAW,OAAO,KAAK,SAAS,GACtE;AAAA,IACA,oBAAC,cAAW,KAAK,SAAS;AAAA,KAC5B;AAEJ,CAAC;",
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": "AAAA,YAAY,WAAW;ACqDV;AAnDb,OAAOA,UAAS,YAAY,SAAS,mBAAmB;AAExD,SAAS,oBAAoB;AAE7B,SAAS,YAA0D;AACnE,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAEtB,MAA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AE,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,WAAW,OAAO,iBAAiB,SAAS;AAAA,UAC5C,YAAY;AAAA,UACZ,YAAY;AAAA,UACZ;AAAA,UACA,WAAW;AAAA,UACV,GAAG;AAAA;AAAA,MACN;AAAA,IAEJ;AAAA,IACA,CAAC,OAAO,MAAM,OAAO,QAAQ,aAAa,WAAW,KAAK;AAAA,EAC5D;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;AAAA,MACjB,IAAI;AAAA,MACJ,IAAI;AAAA,IACN;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,OAAO;AAAA,QACP,UAAU;AAAA,QACV,WAAW,aAAa;AAAA,QACxB;AAAA,QACA;AAAA,QACA,OAAO;AAAA;AAAA,IACT;AAAA,EAEJ,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN;AAAA,EACF,CAAC;AACH,CAAC;",
6
6
  "names": ["React"]
7
7
  }
@@ -1,71 +1,101 @@
1
1
  import * as React from "react";
2
- import { jsx, jsxs } from "react/jsx-runtime";
3
- import { useContext, useEffect, useRef } from "react";
4
- import { select, axisLeft } from "d3";
5
- import { StyledAxis, StyledGrid } from "../../styles";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import React2, { useCallback, useContext, useMemo } from "react";
6
4
  import { ChartContext } from "../../ChartContext";
7
- import { getFormatGenerator } from "../../helpers";
8
- const AxisLeft = () => {
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 ref = useRef(null);
19
- const gridRef = useRef(null);
20
- const { tickValues, color: tickColor, tickFormat, overwriteTicks, tickRotation, tickCount } = yAxis.tick || {};
21
- const ticks = yScale.ticks?.(tickCount ?? height / 80);
22
- const { type, showGrid, color: axisColor } = yAxis;
23
- useEffect(() => {
24
- const axis = axisLeft(yScale).tickSizeOuter(0);
25
- const grid = axisLeft(yScale).tickFormat((_) => "").tickSize(showGrid ? -innerWidth : 0).tickSizeOuter(0);
26
- if (tickValues && ticks) {
27
- const finalTicks = overwriteTicks ? tickValues : [...ticks, ...tickValues];
28
- axis.tickValues(finalTicks);
29
- } else {
30
- axis.tickValues(ticks);
31
- grid.tickValues(ticks);
32
- }
33
- if (tickFormat) {
34
- if (typeof tickFormat === "string") {
35
- const formatGenerator = getFormatGenerator(type ?? "linear");
36
- axis.tickFormat((d) => formatGenerator(tickFormat)(d));
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
- if (typeof tickFormat === "function") {
39
- axis.tickFormat(tickFormat);
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, { useContext, useEffect, useRef } from 'react';\nimport { select, axisLeft } from 'd3';\nimport { StyledAxis, StyledGrid } from '../../styles';\nimport { ChartContext } from '../../ChartContext';\nimport { getFormatGenerator } from '../../helpers';\n\nexport const AxisLeft = () => {\n const {\n props: { yAxis },\n innerHeight,\n innerWidth,\n yScale,\n chartId,\n height,\n setAxisLeftRef,\n } = useContext(ChartContext);\n\n const ref = useRef<SVGSVGElement>(null);\n const gridRef = useRef<SVGSVGElement>(null);\n const { tickValues, color: tickColor, tickFormat, overwriteTicks, tickRotation, tickCount } = yAxis.tick || {};\n\n const ticks = yScale.ticks?.(tickCount ?? height / 80);\n\n const { type, showGrid, color: axisColor } = yAxis;\n\n useEffect(() => {\n const axis = axisLeft(yScale).tickSizeOuter(0);\n\n const grid = axisLeft(yScale)\n .tickFormat((_) => '')\n .tickSize(showGrid ? -innerWidth : 0)\n .tickSizeOuter(0);\n\n if (tickValues && ticks) {\n const finalTicks = overwriteTicks ? tickValues : [...ticks, ...tickValues];\n axis.tickValues(finalTicks);\n } else {\n axis.tickValues(ticks);\n grid.tickValues(ticks);\n }\n\n if (tickFormat) {\n if (typeof tickFormat === 'string') {\n const formatGenerator = getFormatGenerator(type ?? 'linear');\n\n axis.tickFormat((d) => formatGenerator(tickFormat)(d));\n }\n if (typeof tickFormat === 'function') {\n axis.tickFormat(tickFormat);\n }\n }\n if (ref?.current && gridRef?.current) {\n select(gridRef.current).call(grid);\n const axisNode = select(ref.current);\n axisNode.call(axis);\n if (tickRotation)\n axisNode\n .selectAll('text')\n .style('text-anchor', 'end')\n .attr('dx', '-.8em')\n .attr('dy', '.15em')\n .attr('transform', `rotate(-${tickRotation})`);\n }\n }, [\n innerHeight,\n innerWidth,\n overwriteTicks,\n showGrid,\n tickFormat,\n tickRotation,\n tickValues,\n ticks,\n type,\n yAxis,\n yScale,\n ]);\n\n if (yAxis.hideAxis) return null;\n\n return (\n <g>\n <g mask={`url(#mask-${chartId})`}>\n <StyledGrid ref={gridRef}></StyledGrid>\n </g>\n <g ref={setAxisLeftRef}>\n <StyledAxis axisColor={axisColor} ref={ref} tickColor={tickColor} className=\"axis-left\"></StyledAxis>\n </g>\n </g>\n );\n};\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACkFnB,SAEI,KAFJ;AAhFJ,SAAgB,YAAY,WAAW,cAAc;AACrD,SAAS,QAAQ,gBAAgB;AACjC,SAAS,YAAY,kBAAkB;AACvC,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AAE5B,MAAM,WAAW,MAAM;AAC5B,QAAM;AAAA,IACJ,OAAO,EAAE,MAAM;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,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;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,MAAM;AAAU,WAAO;AAE3B,SACE,qBAAC,OACC;AAAA,wBAAC,OAAE,MAAM,aAAa,YACpB,8BAAC,cAAW,KAAK,SAAS,GAC5B;AAAA,IACA,oBAAC,OAAE,KAAK,gBACN,8BAAC,cAAW,WAAsB,KAAU,WAAsB,WAAU,aAAY,GAC1F;AAAA,KACF;AAEJ;",
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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AAO,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, jsxs } from "react/jsx-runtime";
3
- import { useContext, useEffect, useRef } from "react";
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 { getFormatGenerator } from "../../helpers";
8
- const AxisRight = () => {
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
- chartId,
15
- height,
14
+ innerWidth,
16
15
  setAxisRightRef
17
16
  } = useContext(ChartContext);
18
- const ref = useRef(null);
19
- const gridRef = useRef(null);
20
- const { tickValues, color: tickColor, tickFormat, overwriteTicks, tickRotation, tickCount } = y2Axis.tick || {};
21
- const ticks = y2Scale.ticks?.(tickCount ?? height / 80);
22
- const { type, showGrid, color: axisColor } = y2Axis;
23
- useEffect(() => {
24
- const axis = axisRight(y2Scale).tickSizeOuter(0);
25
- const grid = axisRight(y2Scale).tickFormat((_) => "").tickSize(showGrid ? -innerWidth : 0).tickSizeOuter(0);
26
- if (tickValues && ticks) {
27
- const finalTicks = overwriteTicks ? tickValues : [...ticks, ...tickValues];
28
- axis.tickValues(finalTicks);
29
- } else {
30
- axis.tickValues(ticks);
31
- grid.tickValues(ticks);
32
- }
33
- if (tickFormat) {
34
- if (typeof tickFormat === "string") {
35
- const formatGenerator = getFormatGenerator(type ?? "linear");
36
- axis.tickFormat((d) => formatGenerator(tickFormat)(d));
37
- }
38
- if (typeof tickFormat === "function") {
39
- axis.tickFormat(tickFormat);
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
- if (ref?.current && gridRef?.current) {
43
- select(gridRef.current).call(grid);
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
  };