@mui/x-charts 9.0.4 → 9.1.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.
Files changed (157) hide show
  1. package/BarChart/BarChart.d.mts +1 -2
  2. package/BarChart/BarChart.d.ts +1 -2
  3. package/BarChart/BarChart.js +2 -913
  4. package/BarChart/BarChart.mjs +2 -913
  5. package/BarChart/seriesConfig/bar/seriesProcessor.js +2 -0
  6. package/BarChart/seriesConfig/bar/seriesProcessor.mjs +2 -0
  7. package/CHANGELOG.md +133 -0
  8. package/ChartsAxisHighlightValue/ChartsAxisHighlightValue.d.mts +55 -0
  9. package/ChartsAxisHighlightValue/ChartsAxisHighlightValue.d.ts +55 -0
  10. package/ChartsAxisHighlightValue/ChartsAxisHighlightValue.js +94 -0
  11. package/ChartsAxisHighlightValue/ChartsAxisHighlightValue.mjs +88 -0
  12. package/ChartsAxisHighlightValue/ChartsAxisHighlightValueItem.d.mts +13 -0
  13. package/ChartsAxisHighlightValue/ChartsAxisHighlightValueItem.d.ts +13 -0
  14. package/ChartsAxisHighlightValue/ChartsAxisHighlightValueItem.js +86 -0
  15. package/ChartsAxisHighlightValue/ChartsAxisHighlightValueItem.mjs +80 -0
  16. package/ChartsAxisHighlightValue/chartsAxisHighlightValueClasses.d.mts +18 -0
  17. package/ChartsAxisHighlightValue/chartsAxisHighlightValueClasses.d.ts +18 -0
  18. package/ChartsAxisHighlightValue/chartsAxisHighlightValueClasses.js +26 -0
  19. package/ChartsAxisHighlightValue/chartsAxisHighlightValueClasses.mjs +16 -0
  20. package/ChartsAxisHighlightValue/index.d.mts +1 -0
  21. package/ChartsAxisHighlightValue/index.d.ts +1 -0
  22. package/ChartsAxisHighlightValue/index.js +16 -0
  23. package/ChartsAxisHighlightValue/index.mjs +1 -0
  24. package/ChartsAxisHighlightValue/useAxisHighlightValue.d.mts +14 -0
  25. package/ChartsAxisHighlightValue/useAxisHighlightValue.d.ts +14 -0
  26. package/ChartsAxisHighlightValue/useAxisHighlightValue.js +130 -0
  27. package/ChartsAxisHighlightValue/useAxisHighlightValue.mjs +124 -0
  28. package/ChartsContainer/ChartsContainer.js +4 -1431
  29. package/ChartsContainer/ChartsContainer.mjs +4 -1431
  30. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.d.mts +15 -0
  31. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.d.ts +15 -0
  32. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.js +56 -0
  33. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.mjs +50 -0
  34. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.types.d.mts +6 -0
  35. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.types.d.ts +6 -0
  36. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.types.js +5 -0
  37. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlight.types.mjs +1 -0
  38. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlightPath.d.mts +11 -0
  39. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlightPath.d.ts +11 -0
  40. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlightPath.js +70 -0
  41. package/ChartsRadialAxisHighlight/ChartsRadialAxisHighlightPath.mjs +64 -0
  42. package/ChartsRadialAxisHighlight/ChartsRadiusAxisHighlight.d.mts +9 -0
  43. package/ChartsRadialAxisHighlight/ChartsRadiusAxisHighlight.d.ts +9 -0
  44. package/ChartsRadialAxisHighlight/ChartsRadiusAxisHighlight.js +87 -0
  45. package/ChartsRadialAxisHighlight/ChartsRadiusAxisHighlight.mjs +81 -0
  46. package/ChartsRadialAxisHighlight/ChartsRotationAxisHighlight.d.mts +9 -0
  47. package/ChartsRadialAxisHighlight/ChartsRotationAxisHighlight.d.ts +9 -0
  48. package/ChartsRadialAxisHighlight/ChartsRotationAxisHighlight.js +98 -0
  49. package/ChartsRadialAxisHighlight/ChartsRotationAxisHighlight.mjs +92 -0
  50. package/ChartsRadialAxisHighlight/chartsRadialAxisHighlightClasses.d.mts +7 -0
  51. package/ChartsRadialAxisHighlight/chartsRadialAxisHighlightClasses.d.ts +7 -0
  52. package/ChartsRadialAxisHighlight/chartsRadialAxisHighlightClasses.js +14 -0
  53. package/ChartsRadialAxisHighlight/chartsRadialAxisHighlightClasses.mjs +6 -0
  54. package/ChartsRadialAxisHighlight/index.d.mts +5 -0
  55. package/ChartsRadialAxisHighlight/index.d.ts +5 -0
  56. package/ChartsRadialAxisHighlight/index.js +47 -0
  57. package/ChartsRadialAxisHighlight/index.mjs +4 -0
  58. package/ChartsRadiusAxis/index.d.mts +3 -2
  59. package/ChartsRadiusAxis/index.d.ts +3 -2
  60. package/ChartsRadiusAxis/index.mjs +3 -1
  61. package/ChartsRotationAxis/index.d.mts +3 -2
  62. package/ChartsRotationAxis/index.d.ts +3 -2
  63. package/ChartsRotationAxis/index.mjs +3 -1
  64. package/ChartsXAxis/useAxisTicksProps.d.mts +162 -81
  65. package/ChartsXAxis/useAxisTicksProps.d.ts +162 -81
  66. package/ChartsYAxis/useAxisTicksProps.d.mts +162 -81
  67. package/ChartsYAxis/useAxisTicksProps.d.ts +162 -81
  68. package/LICENSE +2 -0
  69. package/LineChart/LineChart.js +2 -913
  70. package/LineChart/LineChart.mjs +2 -913
  71. package/LineChart/seriesConfig/curveEvaluation.d.mts +19 -1
  72. package/LineChart/seriesConfig/curveEvaluation.d.ts +19 -1
  73. package/LineChart/seriesConfig/curveEvaluation.js +132 -0
  74. package/LineChart/seriesConfig/curveEvaluation.mjs +131 -0
  75. package/LineChart/seriesConfig/getSeriesWithDefaultValues.js +2 -1
  76. package/LineChart/seriesConfig/getSeriesWithDefaultValues.mjs +2 -1
  77. package/LineChart/seriesConfig/seriesProcessor.js +4 -0
  78. package/LineChart/seriesConfig/seriesProcessor.mjs +4 -0
  79. package/LineChart/useAreaPlotData.js +4 -0
  80. package/LineChart/useAreaPlotData.mjs +4 -0
  81. package/LineChart/useLinePlotData.js +2 -0
  82. package/LineChart/useLinePlotData.mjs +2 -0
  83. package/LineChart/useMarkPlotData.js +2 -0
  84. package/LineChart/useMarkPlotData.mjs +2 -0
  85. package/ScatterChart/FocusedScatterMark.js +10 -24
  86. package/ScatterChart/FocusedScatterMark.mjs +10 -24
  87. package/ScatterChart/HighlightedScatterMark.d.mts +11 -0
  88. package/ScatterChart/HighlightedScatterMark.d.ts +11 -0
  89. package/ScatterChart/HighlightedScatterMark.js +68 -0
  90. package/ScatterChart/HighlightedScatterMark.mjs +62 -0
  91. package/ScatterChart/ScatterChart.d.mts +1 -2
  92. package/ScatterChart/ScatterChart.d.ts +1 -2
  93. package/ScatterChart/ScatterChart.js +2 -913
  94. package/ScatterChart/ScatterChart.mjs +2 -913
  95. package/ScatterChart/index.d.mts +1 -0
  96. package/ScatterChart/index.d.ts +1 -0
  97. package/ScatterChart/index.js +12 -0
  98. package/ScatterChart/index.mjs +1 -0
  99. package/ScatterChart/scatterClasses.d.mts +3 -1
  100. package/ScatterChart/scatterClasses.d.ts +3 -1
  101. package/ScatterChart/scatterClasses.js +3 -2
  102. package/ScatterChart/scatterClasses.mjs +3 -2
  103. package/ScatterChart/useScatterChartProps.js +3 -1
  104. package/ScatterChart/useScatterChartProps.mjs +3 -1
  105. package/ScatterChart/useScatterItemPosition.d.mts +16 -0
  106. package/ScatterChart/useScatterItemPosition.d.ts +16 -0
  107. package/ScatterChart/useScatterItemPosition.js +47 -0
  108. package/ScatterChart/useScatterItemPosition.mjs +41 -0
  109. package/SparkLineChart/SparkLineChart.js +2 -913
  110. package/SparkLineChart/SparkLineChart.mjs +2 -913
  111. package/hooks/useAxis.d.mts +3 -3
  112. package/hooks/useAxis.d.ts +3 -3
  113. package/hooks/useAxisSystem.d.mts +1 -1
  114. package/hooks/useAxisSystem.d.ts +1 -1
  115. package/hooks/useAxisSystem.js +1 -1
  116. package/hooks/useAxisSystem.mjs +1 -1
  117. package/index.d.mts +2 -0
  118. package/index.d.ts +2 -0
  119. package/index.js +25 -1
  120. package/index.mjs +3 -1
  121. package/internals/index.d.mts +5 -0
  122. package/internals/index.d.ts +5 -0
  123. package/internals/index.js +48 -0
  124. package/internals/index.mjs +5 -0
  125. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +4 -2
  126. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.mjs +4 -2
  127. package/internals/plugins/corePlugins/useChartSeriesConfig/types/polarExtremumGetter.types.d.mts +2 -2
  128. package/internals/plugins/corePlugins/useChartSeriesConfig/types/polarExtremumGetter.types.d.ts +2 -2
  129. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.mts +3 -2
  130. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +3 -2
  131. package/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.d.mts +4 -7
  132. package/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.d.ts +4 -7
  133. package/internals/plugins/featurePlugins/useChartPolarAxis/defaultizeAxis.d.mts +3 -2
  134. package/internals/plugins/featurePlugins/useChartPolarAxis/defaultizeAxis.d.ts +3 -2
  135. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisExtremum.d.mts +2 -2
  136. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisExtremum.d.ts +2 -2
  137. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.d.mts +2 -2
  138. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.d.ts +2 -2
  139. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +20 -4
  140. package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.mjs +20 -4
  141. package/internals/plugins/featurePlugins/useChartPolarAxis/index.d.mts +2 -1
  142. package/internals/plugins/featurePlugins/useChartPolarAxis/index.d.ts +2 -1
  143. package/internals/plugins/featurePlugins/useChartPolarAxis/index.js +12 -0
  144. package/internals/plugins/featurePlugins/useChartPolarAxis/index.mjs +2 -1
  145. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.mts +4 -4
  146. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +4 -4
  147. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.types.d.mts +3 -3
  148. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.types.d.ts +3 -3
  149. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.mts +1 -1
  150. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +1 -1
  151. package/models/axis.d.mts +28 -28
  152. package/models/axis.d.ts +28 -28
  153. package/models/axis.js +5 -1
  154. package/models/axis.mjs +5 -1
  155. package/models/seriesType/line.d.mts +6 -6
  156. package/models/seriesType/line.d.ts +6 -6
  157. package/package.json +31 -3
@@ -0,0 +1,18 @@
1
+ export interface ChartsAxisHighlightValueClasses {
2
+ /** Styles applied to the root element. */
3
+ root: string;
4
+ /** Styles applied to the top axis highlight. */
5
+ top: string;
6
+ /** Styles applied to the bottom axis highlight. */
7
+ bottom: string;
8
+ /** Styles applied to the left axis highlight. */
9
+ left: string;
10
+ /** Styles applied to the right axis highlight. */
11
+ right: string;
12
+ }
13
+ export type ChartsAxisHighlightValueClassKey = keyof ChartsAxisHighlightValueClasses;
14
+ export declare function getChartsAxisHighlightValueUtilityClass(slot: string): string;
15
+ export declare const useUtilityClasses: (ownerState: {
16
+ position: "top" | "right" | "bottom" | "left";
17
+ }) => Record<"root", string>;
18
+ export declare const chartsAxisHighlightValueClasses: ChartsAxisHighlightValueClasses;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.chartsAxisHighlightValueClasses = void 0;
8
+ exports.getChartsAxisHighlightValueUtilityClass = getChartsAxisHighlightValueUtilityClass;
9
+ exports.useUtilityClasses = void 0;
10
+ var _generateUtilityClass = _interopRequireDefault(require("@mui/utils/generateUtilityClass"));
11
+ var _generateUtilityClasses = _interopRequireDefault(require("@mui/utils/generateUtilityClasses"));
12
+ var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
13
+ function getChartsAxisHighlightValueUtilityClass(slot) {
14
+ return (0, _generateUtilityClass.default)('MuiChartsAxisHighlightValue', slot);
15
+ }
16
+ const useUtilityClasses = ownerState => {
17
+ const {
18
+ position
19
+ } = ownerState;
20
+ const slots = {
21
+ root: ['root', position]
22
+ };
23
+ return (0, _composeClasses.default)(slots, getChartsAxisHighlightValueUtilityClass);
24
+ };
25
+ exports.useUtilityClasses = useUtilityClasses;
26
+ const chartsAxisHighlightValueClasses = exports.chartsAxisHighlightValueClasses = (0, _generateUtilityClasses.default)('MuiChartsAxisHighlightValue', ['root', 'top', 'bottom', 'left', 'right']);
@@ -0,0 +1,16 @@
1
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
3
+ import composeClasses from '@mui/utils/composeClasses';
4
+ export function getChartsAxisHighlightValueUtilityClass(slot) {
5
+ return generateUtilityClass('MuiChartsAxisHighlightValue', slot);
6
+ }
7
+ export const useUtilityClasses = ownerState => {
8
+ const {
9
+ position
10
+ } = ownerState;
11
+ const slots = {
12
+ root: ['root', position]
13
+ };
14
+ return composeClasses(slots, getChartsAxisHighlightValueUtilityClass);
15
+ };
16
+ export const chartsAxisHighlightValueClasses = generateUtilityClasses('MuiChartsAxisHighlightValue', ['root', 'top', 'bottom', 'left', 'right']);
@@ -0,0 +1 @@
1
+ export * from "./ChartsAxisHighlightValue.mjs";
@@ -0,0 +1 @@
1
+ export * from "./ChartsAxisHighlightValue.js";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _ChartsAxisHighlightValue = require("./ChartsAxisHighlightValue");
7
+ Object.keys(_ChartsAxisHighlightValue).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _ChartsAxisHighlightValue[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _ChartsAxisHighlightValue[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1 @@
1
+ export * from "./ChartsAxisHighlightValue.mjs";
@@ -0,0 +1,14 @@
1
+ import type { AxisId } from "../models/axis.mjs";
2
+ import type { ChartsAxisHighlightValuePosition } from "./ChartsAxisHighlightValue.mjs";
3
+ import type { ChartsAxisHighlightValueItemProps } from "./ChartsAxisHighlightValueItem.mjs";
4
+ export interface AxisHighlightValueItem extends ChartsAxisHighlightValueItemProps {
5
+ key: string;
6
+ }
7
+ export interface UseAxisHighlightValueParams {
8
+ axisDirection: 'x' | 'y';
9
+ axisId?: AxisId;
10
+ labelPosition?: ChartsAxisHighlightValuePosition;
11
+ value?: number | Date | string | null;
12
+ valueFormatter?: (value: number | Date | string) => string;
13
+ }
14
+ export declare function useAxisHighlightValue(params: UseAxisHighlightValueParams): AxisHighlightValueItem[];
@@ -0,0 +1,14 @@
1
+ import type { AxisId } from "../models/axis.js";
2
+ import type { ChartsAxisHighlightValuePosition } from "./ChartsAxisHighlightValue.js";
3
+ import type { ChartsAxisHighlightValueItemProps } from "./ChartsAxisHighlightValueItem.js";
4
+ export interface AxisHighlightValueItem extends ChartsAxisHighlightValueItemProps {
5
+ key: string;
6
+ }
7
+ export interface UseAxisHighlightValueParams {
8
+ axisDirection: 'x' | 'y';
9
+ axisId?: AxisId;
10
+ labelPosition?: ChartsAxisHighlightValuePosition;
11
+ value?: number | Date | string | null;
12
+ valueFormatter?: (value: number | Date | string) => string;
13
+ }
14
+ export declare function useAxisHighlightValue(params: UseAxisHighlightValueParams): AxisHighlightValueItem[];
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAxisHighlightValue = useAxisHighlightValue;
7
+ var _getValueToPositionMapper = require("../hooks/getValueToPositionMapper");
8
+ var _hooks = require("../hooks");
9
+ var _useStore = require("../internals/store/useStore");
10
+ var _useChartCartesianAxis = require("../internals/plugins/featurePlugins/useChartCartesianAxis");
11
+ function getAxisValueFormatter(axis, valueFormatter) {
12
+ if (valueFormatter) {
13
+ return valueFormatter;
14
+ }
15
+ if (axis.valueFormatter) {
16
+ return v => axis.valueFormatter(v, {
17
+ location: 'tooltip',
18
+ scale: axis.scale
19
+ });
20
+ }
21
+ return v => `${v}`;
22
+ }
23
+ const EMPTY_ARRAY = [];
24
+ function useAxisHighlightValue(params) {
25
+ const {
26
+ axisDirection,
27
+ axisId,
28
+ labelPosition = 'end',
29
+ value,
30
+ valueFormatter
31
+ } = params;
32
+ const {
33
+ top,
34
+ left,
35
+ width,
36
+ height,
37
+ right,
38
+ bottom
39
+ } = (0, _hooks.useDrawingArea)();
40
+ const store = (0, _useStore.useStore)();
41
+ const highlightSelector = axisDirection === 'x' ? _useChartCartesianAxis.selectorChartsHighlightXAxisValue : _useChartCartesianAxis.selectorChartsHighlightYAxisValue;
42
+ const axisSelector = axisDirection === 'x' ? _useChartCartesianAxis.selectorChartXAxis : _useChartCartesianAxis.selectorChartYAxis;
43
+ const axisHighlightValues = store.use(highlightSelector);
44
+ const axes = store.use(axisSelector);
45
+ if (labelPosition === 'none') {
46
+ return EMPTY_ARRAY;
47
+ }
48
+ let items;
49
+ if (value !== undefined && value !== null) {
50
+ const targetAxisId = axisId ?? axes.axisIds[0];
51
+ items = [{
52
+ axisId: targetAxisId,
53
+ value
54
+ }];
55
+ } else {
56
+ items = axisHighlightValues.filter(item => (axisId === undefined || item.axisId === axisId) && item.value !== undefined).map(item => ({
57
+ axisId: item.axisId,
58
+ value: item.value
59
+ }));
60
+ }
61
+ const result = [];
62
+ for (const {
63
+ axisId: itemAxisId,
64
+ value: itemValue
65
+ } of items) {
66
+ const axis = axes.axis[itemAxisId];
67
+ if (!axis) {
68
+ continue;
69
+ }
70
+ const scale = axis.scale;
71
+ const position = (0, _getValueToPositionMapper.getValueToPositionMapper)(scale)(itemValue);
72
+ if (!Number.isFinite(position)) {
73
+ continue;
74
+ }
75
+ const format = getAxisValueFormatter(axis, valueFormatter);
76
+ const formattedValue = format(itemValue);
77
+ if (axisDirection === 'x') {
78
+ if (labelPosition === 'start' || labelPosition === 'both') {
79
+ result.push({
80
+ key: `${itemAxisId}-${String(itemValue)}-start`,
81
+ x: position,
82
+ y: top,
83
+ formattedValue,
84
+ position: 'top',
85
+ minCoord: left,
86
+ maxCoord: left + width,
87
+ space: top
88
+ });
89
+ }
90
+ if (labelPosition === 'end' || labelPosition === 'both') {
91
+ result.push({
92
+ key: `${itemAxisId}-${String(itemValue)}-end`,
93
+ x: position,
94
+ y: top + height,
95
+ formattedValue,
96
+ position: 'bottom',
97
+ minCoord: left,
98
+ maxCoord: left + width,
99
+ space: bottom
100
+ });
101
+ }
102
+ } else {
103
+ if (labelPosition === 'start' || labelPosition === 'both') {
104
+ result.push({
105
+ key: `${itemAxisId}-${String(itemValue)}-start`,
106
+ x: left,
107
+ y: position,
108
+ formattedValue,
109
+ position: 'left',
110
+ minCoord: top,
111
+ maxCoord: top + height,
112
+ space: left
113
+ });
114
+ }
115
+ if (labelPosition === 'end' || labelPosition === 'both') {
116
+ result.push({
117
+ key: `${itemAxisId}-${String(itemValue)}-end`,
118
+ x: left + width,
119
+ y: position,
120
+ formattedValue,
121
+ position: 'right',
122
+ minCoord: top,
123
+ maxCoord: top + height,
124
+ space: right
125
+ });
126
+ }
127
+ }
128
+ }
129
+ return result;
130
+ }
@@ -0,0 +1,124 @@
1
+ import { getValueToPositionMapper } from "../hooks/getValueToPositionMapper.mjs";
2
+ import { useDrawingArea } from "../hooks/index.mjs";
3
+ import { useStore } from "../internals/store/useStore.mjs";
4
+ import { selectorChartsHighlightXAxisValue, selectorChartsHighlightYAxisValue, selectorChartXAxis, selectorChartYAxis } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.mjs";
5
+ function getAxisValueFormatter(axis, valueFormatter) {
6
+ if (valueFormatter) {
7
+ return valueFormatter;
8
+ }
9
+ if (axis.valueFormatter) {
10
+ return v => axis.valueFormatter(v, {
11
+ location: 'tooltip',
12
+ scale: axis.scale
13
+ });
14
+ }
15
+ return v => `${v}`;
16
+ }
17
+ const EMPTY_ARRAY = [];
18
+ export function useAxisHighlightValue(params) {
19
+ const {
20
+ axisDirection,
21
+ axisId,
22
+ labelPosition = 'end',
23
+ value,
24
+ valueFormatter
25
+ } = params;
26
+ const {
27
+ top,
28
+ left,
29
+ width,
30
+ height,
31
+ right,
32
+ bottom
33
+ } = useDrawingArea();
34
+ const store = useStore();
35
+ const highlightSelector = axisDirection === 'x' ? selectorChartsHighlightXAxisValue : selectorChartsHighlightYAxisValue;
36
+ const axisSelector = axisDirection === 'x' ? selectorChartXAxis : selectorChartYAxis;
37
+ const axisHighlightValues = store.use(highlightSelector);
38
+ const axes = store.use(axisSelector);
39
+ if (labelPosition === 'none') {
40
+ return EMPTY_ARRAY;
41
+ }
42
+ let items;
43
+ if (value !== undefined && value !== null) {
44
+ const targetAxisId = axisId ?? axes.axisIds[0];
45
+ items = [{
46
+ axisId: targetAxisId,
47
+ value
48
+ }];
49
+ } else {
50
+ items = axisHighlightValues.filter(item => (axisId === undefined || item.axisId === axisId) && item.value !== undefined).map(item => ({
51
+ axisId: item.axisId,
52
+ value: item.value
53
+ }));
54
+ }
55
+ const result = [];
56
+ for (const {
57
+ axisId: itemAxisId,
58
+ value: itemValue
59
+ } of items) {
60
+ const axis = axes.axis[itemAxisId];
61
+ if (!axis) {
62
+ continue;
63
+ }
64
+ const scale = axis.scale;
65
+ const position = getValueToPositionMapper(scale)(itemValue);
66
+ if (!Number.isFinite(position)) {
67
+ continue;
68
+ }
69
+ const format = getAxisValueFormatter(axis, valueFormatter);
70
+ const formattedValue = format(itemValue);
71
+ if (axisDirection === 'x') {
72
+ if (labelPosition === 'start' || labelPosition === 'both') {
73
+ result.push({
74
+ key: `${itemAxisId}-${String(itemValue)}-start`,
75
+ x: position,
76
+ y: top,
77
+ formattedValue,
78
+ position: 'top',
79
+ minCoord: left,
80
+ maxCoord: left + width,
81
+ space: top
82
+ });
83
+ }
84
+ if (labelPosition === 'end' || labelPosition === 'both') {
85
+ result.push({
86
+ key: `${itemAxisId}-${String(itemValue)}-end`,
87
+ x: position,
88
+ y: top + height,
89
+ formattedValue,
90
+ position: 'bottom',
91
+ minCoord: left,
92
+ maxCoord: left + width,
93
+ space: bottom
94
+ });
95
+ }
96
+ } else {
97
+ if (labelPosition === 'start' || labelPosition === 'both') {
98
+ result.push({
99
+ key: `${itemAxisId}-${String(itemValue)}-start`,
100
+ x: left,
101
+ y: position,
102
+ formattedValue,
103
+ position: 'left',
104
+ minCoord: top,
105
+ maxCoord: top + height,
106
+ space: left
107
+ });
108
+ }
109
+ if (labelPosition === 'end' || labelPosition === 'both') {
110
+ result.push({
111
+ key: `${itemAxisId}-${String(itemValue)}-end`,
112
+ x: left + width,
113
+ y: position,
114
+ formattedValue,
115
+ position: 'right',
116
+ minCoord: top,
117
+ maxCoord: top + height,
118
+ space: right
119
+ });
120
+ }
121
+ }
122
+ }
123
+ return result;
124
+ }