@mui/x-charts 8.17.0 → 8.19.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 (134) hide show
  1. package/BarChart/BarLabel/BarLabel.d.ts +7 -1
  2. package/BarChart/BarLabel/BarLabel.js +41 -4
  3. package/BarChart/BarLabel/BarLabelItem.d.ts +6 -0
  4. package/BarChart/BarLabel/BarLabelItem.js +4 -2
  5. package/BarChart/BarLabel/BarLabelPlot.js +2 -3
  6. package/BarChart/BarPlot.js +5 -0
  7. package/BarChart/seriesConfig/bar/seriesProcessor.js +15 -9
  8. package/BarChart/types.d.ts +1 -0
  9. package/BarChart/useBarPlotData.js +3 -2
  10. package/CHANGELOG.md +213 -0
  11. package/ChartsSurface/ChartsSurface.js +5 -2
  12. package/LineChart/seriesConfig/seriesProcessor.js +15 -10
  13. package/PieChart/PieArcPlot.js +5 -3
  14. package/esm/BarChart/BarLabel/BarLabel.d.ts +7 -1
  15. package/esm/BarChart/BarLabel/BarLabel.js +41 -4
  16. package/esm/BarChart/BarLabel/BarLabelItem.d.ts +6 -0
  17. package/esm/BarChart/BarLabel/BarLabelItem.js +4 -2
  18. package/esm/BarChart/BarLabel/BarLabelPlot.js +2 -2
  19. package/esm/BarChart/BarPlot.js +5 -0
  20. package/esm/BarChart/seriesConfig/bar/seriesProcessor.js +15 -9
  21. package/esm/BarChart/types.d.ts +1 -0
  22. package/esm/BarChart/useBarPlotData.js +3 -2
  23. package/esm/ChartsSurface/ChartsSurface.js +5 -2
  24. package/esm/LineChart/seriesConfig/seriesProcessor.js +15 -10
  25. package/esm/PieChart/PieArcPlot.js +5 -3
  26. package/esm/hooks/animation/useAnimateBarLabel.d.ts +1 -1
  27. package/esm/hooks/animation/useAnimateBarLabel.js +61 -12
  28. package/esm/hooks/useAxis.d.ts +116 -16
  29. package/esm/hooks/useAxis.js +122 -18
  30. package/esm/hooks/useBarSeries.js +3 -5
  31. package/esm/hooks/useLineSeries.js +3 -5
  32. package/esm/hooks/usePieSeries.js +3 -5
  33. package/esm/hooks/useRadarSeries.js +3 -5
  34. package/esm/hooks/useScale.d.ts +25 -6
  35. package/esm/hooks/useScale.js +29 -8
  36. package/esm/hooks/useScatterSeries.js +3 -5
  37. package/esm/index.d.ts +2 -1
  38. package/esm/index.js +2 -1
  39. package/esm/internals/domUtils.js +30 -14
  40. package/esm/internals/getScale.d.ts +2 -1
  41. package/esm/internals/index.d.ts +1 -1
  42. package/esm/internals/index.js +1 -1
  43. package/esm/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.js +2 -2
  44. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.js +5 -6
  45. package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.js +2 -2
  46. package/esm/internals/plugins/corePlugins/useChartId/useChartId.selectors.js +2 -2
  47. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +4 -1
  48. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +3 -1
  49. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +1 -1
  50. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.js +4 -4
  51. package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.d.ts +1 -1
  52. package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.js +15 -15
  53. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +1 -1
  54. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +5 -5
  55. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +3 -0
  56. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +11 -11
  57. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +5 -6
  58. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +7 -8
  59. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +2 -2
  60. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.selectors.js +2 -2
  61. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +11 -12
  62. package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.js +8 -8
  63. package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.js +4 -4
  64. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +11 -11
  65. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.js +6 -6
  66. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +7 -8
  67. package/esm/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.js +2 -2
  68. package/esm/internals/plugins/utils/selectors.d.ts +1 -14
  69. package/esm/internals/plugins/utils/selectors.js +1 -5
  70. package/esm/internals/seriesSelectorOfType.d.ts +20 -0
  71. package/esm/internals/seriesSelectorOfType.js +38 -0
  72. package/esm/models/seriesType/bar.d.ts +7 -0
  73. package/esm/models/seriesType/config.d.ts +2 -2
  74. package/esm/utils/index.d.ts +4 -0
  75. package/esm/utils/index.js +5 -0
  76. package/esm/utils/niceDomain.d.ts +20 -0
  77. package/esm/utils/niceDomain.js +24 -0
  78. package/hooks/animation/useAnimateBarLabel.d.ts +1 -1
  79. package/hooks/animation/useAnimateBarLabel.js +61 -12
  80. package/hooks/useAxis.d.ts +116 -16
  81. package/hooks/useAxis.js +122 -18
  82. package/hooks/useBarSeries.js +3 -6
  83. package/hooks/useLineSeries.js +3 -6
  84. package/hooks/usePieSeries.js +3 -6
  85. package/hooks/useRadarSeries.js +3 -6
  86. package/hooks/useScale.d.ts +25 -6
  87. package/hooks/useScale.js +29 -8
  88. package/hooks/useScatterSeries.js +3 -6
  89. package/index.d.ts +2 -1
  90. package/index.js +13 -1
  91. package/internals/domUtils.js +30 -14
  92. package/internals/getScale.d.ts +2 -1
  93. package/internals/index.d.ts +1 -1
  94. package/internals/index.js +4 -4
  95. package/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.js +2 -2
  96. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.js +4 -5
  97. package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.js +2 -2
  98. package/internals/plugins/corePlugins/useChartId/useChartId.selectors.js +2 -2
  99. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +4 -1
  100. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +3 -1
  101. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +1 -1
  102. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.js +4 -4
  103. package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.d.ts +1 -1
  104. package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.js +15 -15
  105. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +1 -1
  106. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +5 -5
  107. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +3 -0
  108. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +11 -11
  109. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +4 -5
  110. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +6 -7
  111. package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +2 -2
  112. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.selectors.js +2 -2
  113. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +10 -11
  114. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.js +8 -8
  115. package/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.js +4 -4
  116. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +11 -11
  117. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.js +6 -6
  118. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +6 -7
  119. package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.js +2 -2
  120. package/internals/plugins/utils/selectors.d.ts +1 -14
  121. package/internals/plugins/utils/selectors.js +1 -8
  122. package/internals/seriesSelectorOfType.d.ts +20 -0
  123. package/internals/seriesSelectorOfType.js +46 -0
  124. package/models/seriesType/bar.d.ts +7 -0
  125. package/models/seriesType/config.d.ts +2 -2
  126. package/package.json +5 -5
  127. package/utils/index.d.ts +4 -0
  128. package/utils/index.js +16 -0
  129. package/utils/niceDomain.d.ts +20 -0
  130. package/utils/niceDomain.js +29 -0
  131. package/esm/internals/createSeriesSelectorOfType.d.ts +0 -4
  132. package/esm/internals/createSeriesSelectorOfType.js +0 -45
  133. package/internals/createSeriesSelectorOfType.d.ts +0 -4
  134. package/internals/createSeriesSelectorOfType.js +0 -53
@@ -0,0 +1,20 @@
1
+ import { ChartSeriesDefaultized, ChartsSeriesConfig } from "../models/seriesType/config.js";
2
+ import { SeriesId } from "../models/seriesType/common.js";
3
+ import type { ProcessedSeries } from "./plugins/corePlugins/useChartSeries/index.js";
4
+ export declare const selectorAllSeriesOfType: (args_0: import("./plugins/corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("./plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("./plugins/corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("./plugins/corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof ChartsSeriesConfig> & import("./plugins/corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("./index.js").UseChartInteractionListenerState & Partial<{}> & {
5
+ cacheKey: import("./index.js").ChartStateCacheKey;
6
+ }, seriesType: keyof ChartsSeriesConfig) => import("./index.js").SeriesProcessorResult<"line"> | import("./index.js").SeriesProcessorResult<"bar"> | {
7
+ series: Record<SeriesId, import("../index.js").DefaultizedScatterSeriesType>;
8
+ seriesOrder: SeriesId[];
9
+ } | {
10
+ series: Record<SeriesId, import("../index.js").DefaultizedPieSeriesType>;
11
+ seriesOrder: SeriesId[];
12
+ } | {
13
+ series: Record<SeriesId, import("../index.js").DefaultizedRadarSeriesType>;
14
+ seriesOrder: SeriesId[];
15
+ } | undefined;
16
+ export declare const selectorSeriesOfType: (args_0: import("./plugins/corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("./plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("./plugins/corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("./plugins/corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof ChartsSeriesConfig> & import("./plugins/corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("./index.js").UseChartInteractionListenerState & Partial<{}> & {
17
+ cacheKey: import("./index.js").ChartStateCacheKey;
18
+ }, seriesType: keyof ChartsSeriesConfig, ids?: SeriesId | SeriesId[] | undefined) => import("../index.js").DefaultizedLineSeriesType | import("../index.js").DefaultizedBarSeriesType | import("../index.js").DefaultizedRadarSeriesType | import("../index.js").DefaultizedScatterSeriesType | import("../index.js").DefaultizedPieSeriesType | (import("../index.js").DefaultizedLineSeriesType | import("../index.js").DefaultizedBarSeriesType | import("../index.js").DefaultizedRadarSeriesType | import("../index.js").DefaultizedScatterSeriesType | import("../index.js").DefaultizedPieSeriesType | undefined)[] | undefined;
19
+ export declare const useAllSeriesOfType: <T extends keyof ChartsSeriesConfig>(seriesType: T) => ProcessedSeries[T];
20
+ export declare const useSeriesOfType: <T extends keyof ChartsSeriesConfig>(seriesType: T, seriesId?: SeriesId | SeriesId[]) => ChartSeriesDefaultized<T> | ChartSeriesDefaultized<T>[] | undefined;
@@ -0,0 +1,38 @@
1
+ import { warnOnce } from '@mui/x-internals/warning';
2
+ import { createSelector, createSelectorMemoized } from '@mui/x-internals/store';
3
+ import { selectorChartSeriesProcessed } from "./plugins/corePlugins/useChartSeries/useChartSeries.selectors.js";
4
+ import { useStore } from "./store/useStore.js";
5
+ import { useSelector } from "./store/useSelector.js";
6
+ export const selectorAllSeriesOfType = createSelector(selectorChartSeriesProcessed, (processedSeries, seriesType) => processedSeries[seriesType]);
7
+ export const selectorSeriesOfType = createSelectorMemoized(selectorChartSeriesProcessed, (processedSeries, seriesType, ids) => {
8
+ if (!ids || Array.isArray(ids) && ids.length === 0) {
9
+ return processedSeries[seriesType]?.seriesOrder?.map(seriesId => processedSeries[seriesType]?.series[seriesId]) ?? [];
10
+ }
11
+ if (!Array.isArray(ids)) {
12
+ return processedSeries[seriesType]?.series?.[ids];
13
+ }
14
+ const result = [];
15
+ const failedIds = [];
16
+ for (const id of ids) {
17
+ const series = processedSeries[seriesType]?.series?.[id];
18
+ if (series) {
19
+ result.push(series);
20
+ } else {
21
+ failedIds.push(id);
22
+ }
23
+ }
24
+ if (process.env.NODE_ENV !== 'production' && failedIds.length > 0) {
25
+ const formattedIds = failedIds.map(v => JSON.stringify(v)).join(', ');
26
+ const fnName = `use${seriesType.charAt(0).toUpperCase()}${seriesType.slice(1)}Series`;
27
+ warnOnce([`MUI X Charts: The following ids provided to "${fnName}" could not be found: ${formattedIds}.`, `Make sure that they exist and their series are using the "${seriesType}" series type.`]);
28
+ }
29
+ return result;
30
+ });
31
+ export const useAllSeriesOfType = seriesType => {
32
+ const store = useStore();
33
+ return useSelector(store, selectorAllSeriesOfType, seriesType);
34
+ };
35
+ export const useSeriesOfType = (seriesType, seriesId) => {
36
+ const store = useStore();
37
+ return useSelector(store, selectorSeriesOfType, seriesType, seriesId);
38
+ };
@@ -44,6 +44,13 @@ export interface BarSeriesType extends CommonSeriesType<number | null>, Cartesia
44
44
  * @returns {string} The formatted label.
45
45
  */
46
46
  barLabel?: 'value' | ((item: BarItem, context: BarLabelContext) => string | null | undefined);
47
+ /**
48
+ * The placement of the bar label. It accepts the following values:
49
+ * - 'center': the label is centered on the bar
50
+ * - 'outside': the label is placed after the end of the bar, from the point of the view of the origin. For a vertical positive bar, the label is above its top edge; for a horizontal negative bar, the label is placed to the left of its leftmost limit.
51
+ * @default 'center'
52
+ */
53
+ barLabelPlacement?: 'center' | 'outside';
47
54
  }
48
55
  /**
49
56
  * An object that allows to identify a single bar.
@@ -83,6 +83,6 @@ export type ChartSeriesDefaultized<T extends ChartSeriesType> = ChartsSeriesConf
83
83
  export type ChartItemIdentifier<T extends ChartSeriesType> = ChartsSeriesConfig[T]['itemIdentifier'];
84
84
  export type ChartItemIdentifierWithData<T extends ChartSeriesType> = ChartsSeriesConfig[T]['itemIdentifierWithData'];
85
85
  export type DatasetElementType<T> = {
86
- [key: string]: Readonly<T>;
86
+ [key: string]: T;
87
87
  };
88
- export type DatasetType<T = number | string | Date | null | undefined> = DatasetElementType<T>[];
88
+ export type DatasetType<T = unknown> = DatasetElementType<T>[];
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Exported utility functions for the x-charts library.
3
+ */
4
+ export * from "./niceDomain.js";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Exported utility functions for the x-charts library.
3
+ */
4
+
5
+ export * from "./niceDomain.js";
@@ -0,0 +1,20 @@
1
+ import { NumberValue } from '@mui/x-charts-vendor/d3-scale';
2
+ import { ContinuousScaleName } from "../models/index.js";
3
+ /**
4
+ * Returns a nice domain for the given scale type and domain.
5
+ * Does not modify the original domain.
6
+ *
7
+ * Providing a count improves the nice domain calculation by trying to align tick values to round
8
+ * numbers or dates.
9
+ *
10
+ * For example, if you have a domain of [29, 72] and there are 5 ticks, the nice domain will be
11
+ * [20, 80] so that the ticks can be at [20, 35, 50, 65, 80].
12
+ * However, if there are 11 ticks, the nice domain will be [25, 75] so that the ticks can be at
13
+ * [25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75].
14
+ *
15
+ * @param scaleType The type of the scale (e.g., 'linear', 'log', 'time', etc.).
16
+ * @param domain The domain to be made nicer.
17
+ * @param count An optional number of ticks to improve the nice domain calculation. Defaults to 5.
18
+ */
19
+ export declare function niceDomain<Domain extends NumberValue>(scaleType: Exclude<ContinuousScaleName, 'time' | 'utc'>, domain: Iterable<Domain>, count?: number): Domain[];
20
+ export declare function niceDomain<Domain extends NumberValue>(scaleType: 'time' | 'utc', domain: Iterable<Domain>, count?: number): Date[];
@@ -0,0 +1,24 @@
1
+ import { getScale } from "../internals/getScale.js";
2
+
3
+ /**
4
+ * Returns a nice domain for the given scale type and domain.
5
+ * Does not modify the original domain.
6
+ *
7
+ * Providing a count improves the nice domain calculation by trying to align tick values to round
8
+ * numbers or dates.
9
+ *
10
+ * For example, if you have a domain of [29, 72] and there are 5 ticks, the nice domain will be
11
+ * [20, 80] so that the ticks can be at [20, 35, 50, 65, 80].
12
+ * However, if there are 11 ticks, the nice domain will be [25, 75] so that the ticks can be at
13
+ * [25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75].
14
+ *
15
+ * @param scaleType The type of the scale (e.g., 'linear', 'log', 'time', etc.).
16
+ * @param domain The domain to be made nicer.
17
+ * @param count An optional number of ticks to improve the nice domain calculation. Defaults to 5.
18
+ */
19
+
20
+ export function niceDomain(scaleType, domain, count = 5) {
21
+ const scale = getScale(scaleType, domain, [0, 1]);
22
+ scale.nice(count);
23
+ return scale.domain();
24
+ }
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import type { BarLabelProps } from "../../BarChart/index.js";
3
- type UseAnimateBarLabelParams = Pick<BarLabelProps, 'xOrigin' | 'yOrigin' | 'x' | 'y' | 'width' | 'height' | 'layout' | 'skipAnimation'> & {
3
+ type UseAnimateBarLabelParams = Pick<BarLabelProps, 'xOrigin' | 'yOrigin' | 'x' | 'y' | 'width' | 'height' | 'layout' | 'skipAnimation' | 'placement'> & {
4
4
  ref?: React.Ref<SVGTextElement>;
5
5
  };
6
6
  type UseAnimateBarLabelReturn = {
@@ -11,14 +11,12 @@ function barLabelPropsInterpolator(from, to) {
11
11
  const interpolateY = (0, _d3Interpolate.interpolateNumber)(from.y, to.y);
12
12
  const interpolateWidth = (0, _d3Interpolate.interpolateNumber)(from.width, to.width);
13
13
  const interpolateHeight = (0, _d3Interpolate.interpolateNumber)(from.height, to.height);
14
- return t => {
15
- return {
16
- x: interpolateX(t),
17
- y: interpolateY(t),
18
- width: interpolateWidth(t),
19
- height: interpolateHeight(t)
20
- };
21
- };
14
+ return t => ({
15
+ x: interpolateX(t),
16
+ y: interpolateY(t),
17
+ width: interpolateWidth(t),
18
+ height: interpolateHeight(t)
19
+ });
22
20
  }
23
21
 
24
22
  /**
@@ -31,15 +29,21 @@ function barLabelPropsInterpolator(from, to) {
31
29
  * pass the ref returned by this hook to the `path` element and the `ref` provided as argument will also be called.
32
30
  */
33
31
  function useAnimateBarLabel(props) {
32
+ const {
33
+ initialX,
34
+ currentX,
35
+ initialY,
36
+ currentY
37
+ } = props.placement === 'outside' ? getOutsidePlacement(props) : getCenterPlacement(props);
34
38
  const initialProps = {
35
- x: props.layout === 'vertical' ? props.x + props.width / 2 : props.xOrigin,
36
- y: props.layout === 'vertical' ? props.yOrigin : props.y + props.height / 2,
39
+ x: initialX,
40
+ y: initialY,
37
41
  width: props.width,
38
42
  height: props.height
39
43
  };
40
44
  const currentProps = {
41
- x: props.x + props.width / 2,
42
- y: props.y + props.height / 2,
45
+ x: currentX,
46
+ y: currentY,
43
47
  width: props.width,
44
48
  height: props.height
45
49
  };
@@ -56,4 +60,49 @@ function useAnimateBarLabel(props) {
56
60
  skip: props.skipAnimation,
57
61
  ref: props.ref
58
62
  });
63
+ }
64
+ const LABEL_OFFSET = 4;
65
+ function getCenterPlacement(props) {
66
+ return {
67
+ initialX: props.layout === 'vertical' ? props.x + props.width / 2 : props.xOrigin,
68
+ initialY: props.layout === 'vertical' ? props.yOrigin : props.y + props.height / 2,
69
+ currentX: props.x + props.width / 2,
70
+ currentY: props.y + props.height / 2
71
+ };
72
+ }
73
+ function getOutsidePlacement(props) {
74
+ let initialY = 0;
75
+ let currentY = 0;
76
+ let initialX = 0;
77
+ let currentX = 0;
78
+ if (props.layout === 'vertical') {
79
+ const shouldPlaceAbove = props.y < props.yOrigin;
80
+ if (shouldPlaceAbove) {
81
+ initialY = props.yOrigin - LABEL_OFFSET;
82
+ currentY = props.y - LABEL_OFFSET;
83
+ } else {
84
+ initialY = props.yOrigin + LABEL_OFFSET;
85
+ currentY = props.y + props.height + LABEL_OFFSET;
86
+ }
87
+ return {
88
+ initialX: props.x + props.width / 2,
89
+ currentX: props.x + props.width / 2,
90
+ initialY,
91
+ currentY
92
+ };
93
+ }
94
+ const shouldPlaceToTheLeft = props.x < props.xOrigin;
95
+ if (shouldPlaceToTheLeft) {
96
+ initialX = props.xOrigin;
97
+ currentX = props.x - LABEL_OFFSET;
98
+ } else {
99
+ initialX = props.xOrigin;
100
+ currentX = props.x + props.width + LABEL_OFFSET;
101
+ }
102
+ return {
103
+ initialX,
104
+ currentX,
105
+ initialY: props.y + props.height / 2,
106
+ currentY: props.y + props.height / 2
107
+ };
59
108
  }
@@ -2,12 +2,17 @@ import { AxisId, ChartsRadiusAxisProps, ChartsRotationAxisProps, PolarAxisDefaul
2
2
  /**
3
3
  * Get all the x-axes.
4
4
  *
5
- * - `xAxis` is an object with the shape `{ [axisId]: axis }`.
6
- * - `xAxisIds` is an array of axis IDs.
5
+ * Returns all X axes configured in the chart along with their IDs.
6
+ * This is useful when you need to iterate over multiple axes or access all axis configurations at once.
7
7
  *
8
- * If access to a specific X axis is needed, use the `useXAxis` hook instead.
8
+ * @returns An object containing:
9
+ * - `xAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
10
+ * - `xAxisIds`: An array of all X axis IDs in the chart
9
11
  *
10
- * @returns `{ xAxis, xAxisIds }` - The x-axes and their IDs.
12
+ * @example
13
+ * const { xAxis, xAxisIds } = useXAxes();
14
+ *
15
+ * @see `useXAxis` for accessing a single X axis
11
16
  */
12
17
  export declare function useXAxes(): {
13
18
  xAxis: import("../internals/index.js").ComputedAxisConfig<ChartsXAxisProps>;
@@ -16,36 +21,131 @@ export declare function useXAxes(): {
16
21
  /**
17
22
  * Get all the y-axes.
18
23
  *
19
- * - `yAxis` is an object with the shape `{ [axisId]: axis }`.
20
- * - `yAxisIds` is an array of axis IDs.
24
+ * Returns all Y axes configured in the chart along with their IDs.
25
+ * This is useful when you need to iterate over multiple axes or access all axis configurations at once.
26
+ *
27
+ * @returns An object containing:
28
+ * - `yAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
29
+ * - `yAxisIds`: An array of all Y axis IDs in the chart
21
30
  *
22
- * If access to a specific Y axis is needed, use the `useYAxis` hook instead.
31
+ * @example
32
+ * const { yAxis, yAxisIds } = useYAxes();
23
33
  *
24
- * @returns `{ yAxis, yAxisIds }` - The y-axes and their IDs.
34
+ * @see `useYAxis` for accessing a single Y axis
25
35
  */
26
36
  export declare function useYAxes(): {
27
37
  yAxis: import("../internals/index.js").ComputedAxisConfig<ChartsYAxisProps>;
28
38
  yAxisIds: AxisId[];
29
39
  };
30
40
  /**
31
- * Get the X axis.
32
- * @param {AxisId | undefined} axisId - If provided returns the x axis with axisId, else returns the values for the default x axis.
33
- * @returns The X axis.
41
+ * Get a specific X axis or the default X axis.
42
+ *
43
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
44
+ * - A string or number matching the axis ID defined in the chart's `xAxis` prop
45
+ * - Undefined to get the default (first) X axis
46
+ * @returns The configuration for a single X axis.
47
+ *
48
+ * @example
49
+ * // Get the default X axis
50
+ * const xAxis = useXAxis();
51
+ *
52
+ * @example
53
+ * // Get a specific X axis by string ID
54
+ * const xAxis = useXAxis('revenue');
34
55
  */
35
56
  export declare function useXAxis<T extends keyof AxisScaleConfig>(axisId?: AxisId): ComputedAxis<T, any, ChartsXAxisProps>;
36
57
  /**
37
- * Get the Y axis.
38
- * @param {AxisId | undefined} axisId - If provided returns the y axis with axisId, else returns the values for the default y axis.
39
- * @returns The Y axis.
58
+ * Get a specific Y axis or the default Y axis.
59
+ *
60
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
61
+ * - A string or number matching the axis ID defined in the chart's `yAxis` prop
62
+ * - Undefined to get the default (first) Y axis
63
+ * @returns The configuration for a single Y axis.
64
+ *
65
+ * @example
66
+ * // Get the default Y axis
67
+ * const yAxis = useYAxis();
68
+ *
69
+ * @example
70
+ * // Get a specific Y axis by string ID
71
+ * const yAxis = useYAxis('temperature');
40
72
  */
41
73
  export declare function useYAxis<T extends keyof AxisScaleConfig>(axisId?: AxisId): ComputedAxis<T, any, ChartsYAxisProps>;
74
+ /**
75
+ * Get all the rotation axes for polar charts.
76
+ *
77
+ * Returns all rotation axes configured in polar charts along with their IDs.
78
+ * Rotation axes are used in charts like `RadarChart` to define angular positioning.
79
+ *
80
+ * @returns An object containing:
81
+ * - `rotationAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
82
+ * - `rotationAxisIds`: An array of all rotation axis IDs in the chart
83
+ *
84
+ * @example
85
+ * const { rotationAxis, rotationAxisIds } = useRotationAxes();
86
+ *
87
+ * @see `useRotationAxis` for accessing a single rotation axis
88
+ */
42
89
  export declare function useRotationAxes(): {
43
90
  rotationAxis: import("../internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js").DefaultizedAxisConfig<ChartsRotationAxisProps>;
44
91
  rotationAxisIds: string[];
45
92
  };
93
+ /**
94
+ * Get all the radius axes for polar charts.
95
+ *
96
+ * Returns all radial axes configured in polar charts along with their IDs.
97
+ * Radius axes are used in charts like `RadarChart` to define radial positioning and scaling.
98
+ *
99
+ * @returns An object containing:
100
+ * - `radiusAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
101
+ * - `radiusAxisIds`: An array of all radius axis IDs in the chart
102
+ *
103
+ * @example
104
+ * const { radiusAxis, radiusAxisIds } = useRadiusAxes();
105
+ *
106
+ * @see `useRadiusAxis` for accessing a single radius axis
107
+ */
46
108
  export declare function useRadiusAxes(): {
47
109
  radiusAxis: import("../internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js").DefaultizedAxisConfig<ChartsRadiusAxisProps>;
48
110
  radiusAxisIds: string[];
49
111
  };
50
- export declare function useRotationAxis(identifier?: number | string): PolarAxisDefaultized<ScaleName, any, ChartsRotationAxisProps> | undefined;
51
- export declare function useRadiusAxis(identifier?: number | string): PolarAxisDefaultized<ScaleName, any, ChartsRadiusAxisProps> | undefined;
112
+ /**
113
+ * Get a specific rotation axis or the default rotation axis for polar charts.
114
+ *
115
+ * Returns the configuration and scale for a rotation axis in polar charts.
116
+ * The rotation axis controls the angular positioning of data points around the circle.
117
+ *
118
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
119
+ * - A string or number matching the axis ID defined in the chart's rotation axis configuration
120
+ * - Undefined to get the default (first) rotation axis
121
+ * @returns The rotation axis configuration, or undefined if not found
122
+ *
123
+ * @example
124
+ * // Get the default rotation axis
125
+ * const rotationAxis = useRotationAxis();
126
+ *
127
+ * @example
128
+ * // Get a specific rotation axis by string ID
129
+ * const rotationAxis = useRotationAxis('categories');
130
+ */
131
+ export declare function useRotationAxis(axisId?: AxisId): PolarAxisDefaultized<ScaleName, any, ChartsRotationAxisProps> | undefined;
132
+ /**
133
+ * Get a specific radius axis or the default radius axis for polar charts.
134
+ *
135
+ * Returns the configuration and scale for a radial axis in polar charts.
136
+ * The radius axis controls the radial distance of data points from the center of the circle.
137
+ *
138
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
139
+ * - A string or number matching the axis ID defined in the chart's radius axis configuration
140
+ * - Undefined to get the default (first) radius axis
141
+ * @returns The radius axis configuration, or undefined if not found
142
+ *
143
+ * @example
144
+ * // Get the default radius axis
145
+ * const radiusAxis = useRadiusAxis();
146
+ *
147
+ * @example
148
+ * // Get a specific radius axis by string ID
149
+ * const radiusAxis = useRadiusAxis('magnitude');
150
+ */
151
+ export declare function useRadiusAxis(axisId?: AxisId): PolarAxisDefaultized<ScaleName, any, ChartsRadiusAxisProps> | undefined;
package/hooks/useAxis.js CHANGED
@@ -19,12 +19,17 @@ var _useStore = require("../internals/store/useStore");
19
19
  /**
20
20
  * Get all the x-axes.
21
21
  *
22
- * - `xAxis` is an object with the shape `{ [axisId]: axis }`.
23
- * - `xAxisIds` is an array of axis IDs.
22
+ * Returns all X axes configured in the chart along with their IDs.
23
+ * This is useful when you need to iterate over multiple axes or access all axis configurations at once.
24
24
  *
25
- * If access to a specific X axis is needed, use the `useXAxis` hook instead.
25
+ * @returns An object containing:
26
+ * - `xAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
27
+ * - `xAxisIds`: An array of all X axis IDs in the chart
26
28
  *
27
- * @returns `{ xAxis, xAxisIds }` - The x-axes and their IDs.
29
+ * @example
30
+ * const { xAxis, xAxisIds } = useXAxes();
31
+ *
32
+ * @see `useXAxis` for accessing a single X axis
28
33
  */
29
34
  function useXAxes() {
30
35
  const store = (0, _useStore.useStore)();
@@ -41,12 +46,17 @@ function useXAxes() {
41
46
  /**
42
47
  * Get all the y-axes.
43
48
  *
44
- * - `yAxis` is an object with the shape `{ [axisId]: axis }`.
45
- * - `yAxisIds` is an array of axis IDs.
49
+ * Returns all Y axes configured in the chart along with their IDs.
50
+ * This is useful when you need to iterate over multiple axes or access all axis configurations at once.
51
+ *
52
+ * @returns An object containing:
53
+ * - `yAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
54
+ * - `yAxisIds`: An array of all Y axis IDs in the chart
46
55
  *
47
- * If access to a specific Y axis is needed, use the `useYAxis` hook instead.
56
+ * @example
57
+ * const { yAxis, yAxisIds } = useYAxes();
48
58
  *
49
- * @returns `{ yAxis, yAxisIds }` - The y-axes and their IDs.
59
+ * @see `useYAxis` for accessing a single Y axis
50
60
  */
51
61
  function useYAxes() {
52
62
  const store = (0, _useStore.useStore)();
@@ -61,9 +71,20 @@ function useYAxes() {
61
71
  }
62
72
 
63
73
  /**
64
- * Get the X axis.
65
- * @param {AxisId | undefined} axisId - If provided returns the x axis with axisId, else returns the values for the default x axis.
66
- * @returns The X axis.
74
+ * Get a specific X axis or the default X axis.
75
+ *
76
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
77
+ * - A string or number matching the axis ID defined in the chart's `xAxis` prop
78
+ * - Undefined to get the default (first) X axis
79
+ * @returns The configuration for a single X axis.
80
+ *
81
+ * @example
82
+ * // Get the default X axis
83
+ * const xAxis = useXAxis();
84
+ *
85
+ * @example
86
+ * // Get a specific X axis by string ID
87
+ * const xAxis = useXAxis('revenue');
67
88
  */
68
89
  function useXAxis(axisId) {
69
90
  const store = (0, _useStore.useStore)();
@@ -76,9 +97,20 @@ function useXAxis(axisId) {
76
97
  }
77
98
 
78
99
  /**
79
- * Get the Y axis.
80
- * @param {AxisId | undefined} axisId - If provided returns the y axis with axisId, else returns the values for the default y axis.
81
- * @returns The Y axis.
100
+ * Get a specific Y axis or the default Y axis.
101
+ *
102
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
103
+ * - A string or number matching the axis ID defined in the chart's `yAxis` prop
104
+ * - Undefined to get the default (first) Y axis
105
+ * @returns The configuration for a single Y axis.
106
+ *
107
+ * @example
108
+ * // Get the default Y axis
109
+ * const yAxis = useYAxis();
110
+ *
111
+ * @example
112
+ * // Get a specific Y axis by string ID
113
+ * const yAxis = useYAxis('temperature');
82
114
  */
83
115
  function useYAxis(axisId) {
84
116
  const store = (0, _useStore.useStore)();
@@ -89,6 +121,22 @@ function useYAxis(axisId) {
89
121
  const id = axisId ?? yAxisIds[0];
90
122
  return yAxis[id];
91
123
  }
124
+
125
+ /**
126
+ * Get all the rotation axes for polar charts.
127
+ *
128
+ * Returns all rotation axes configured in polar charts along with their IDs.
129
+ * Rotation axes are used in charts like `RadarChart` to define angular positioning.
130
+ *
131
+ * @returns An object containing:
132
+ * - `rotationAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
133
+ * - `rotationAxisIds`: An array of all rotation axis IDs in the chart
134
+ *
135
+ * @example
136
+ * const { rotationAxis, rotationAxisIds } = useRotationAxes();
137
+ *
138
+ * @see `useRotationAxis` for accessing a single rotation axis
139
+ */
92
140
  function useRotationAxes() {
93
141
  const store = (0, _useStore.useStore)();
94
142
  const {
@@ -100,6 +148,22 @@ function useRotationAxes() {
100
148
  rotationAxisIds
101
149
  };
102
150
  }
151
+
152
+ /**
153
+ * Get all the radius axes for polar charts.
154
+ *
155
+ * Returns all radial axes configured in polar charts along with their IDs.
156
+ * Radius axes are used in charts like `RadarChart` to define radial positioning and scaling.
157
+ *
158
+ * @returns An object containing:
159
+ * - `radiusAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
160
+ * - `radiusAxisIds`: An array of all radius axis IDs in the chart
161
+ *
162
+ * @example
163
+ * const { radiusAxis, radiusAxisIds } = useRadiusAxes();
164
+ *
165
+ * @see `useRadiusAxis` for accessing a single radius axis
166
+ */
103
167
  function useRadiusAxes() {
104
168
  const store = (0, _useStore.useStore)();
105
169
  const {
@@ -111,21 +175,61 @@ function useRadiusAxes() {
111
175
  radiusAxisIds
112
176
  };
113
177
  }
114
- function useRotationAxis(identifier) {
178
+
179
+ /**
180
+ * Get a specific rotation axis or the default rotation axis for polar charts.
181
+ *
182
+ * Returns the configuration and scale for a rotation axis in polar charts.
183
+ * The rotation axis controls the angular positioning of data points around the circle.
184
+ *
185
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
186
+ * - A string or number matching the axis ID defined in the chart's rotation axis configuration
187
+ * - Undefined to get the default (first) rotation axis
188
+ * @returns The rotation axis configuration, or undefined if not found
189
+ *
190
+ * @example
191
+ * // Get the default rotation axis
192
+ * const rotationAxis = useRotationAxis();
193
+ *
194
+ * @example
195
+ * // Get a specific rotation axis by string ID
196
+ * const rotationAxis = useRotationAxis('categories');
197
+ */
198
+ function useRotationAxis(axisId) {
115
199
  const store = (0, _useStore.useStore)();
116
200
  const {
117
201
  axis: rotationAxis,
118
202
  axisIds: rotationAxisIds
119
203
  } = (0, _useSelector.useSelector)(store, _useChartPolarAxis.selectorChartRotationAxis);
120
- const id = typeof identifier === 'string' ? identifier : rotationAxisIds[identifier ?? 0];
204
+ const id = axisId ?? rotationAxisIds[0];
121
205
  return rotationAxis[id];
122
206
  }
123
- function useRadiusAxis(identifier) {
207
+
208
+ /**
209
+ * Get a specific radius axis or the default radius axis for polar charts.
210
+ *
211
+ * Returns the configuration and scale for a radial axis in polar charts.
212
+ * The radius axis controls the radial distance of data points from the center of the circle.
213
+ *
214
+ * @param {AxisId} [axisId] - The axis identifier. Can be:
215
+ * - A string or number matching the axis ID defined in the chart's radius axis configuration
216
+ * - Undefined to get the default (first) radius axis
217
+ * @returns The radius axis configuration, or undefined if not found
218
+ *
219
+ * @example
220
+ * // Get the default radius axis
221
+ * const radiusAxis = useRadiusAxis();
222
+ *
223
+ * @example
224
+ * // Get a specific radius axis by string ID
225
+ * const radiusAxis = useRadiusAxis('magnitude');
226
+ */
227
+ function useRadiusAxis(axisId) {
124
228
  const store = (0, _useStore.useStore)();
125
229
  const {
126
230
  axis: radiusAxis,
127
231
  axisIds: radiusAxisIds
128
232
  } = (0, _useSelector.useSelector)(store, _useChartPolarAxis.selectorChartRadiusAxis);
129
- const id = typeof identifier === 'string' ? identifier : radiusAxisIds[identifier ?? 0];
233
+ const id = axisId ?? radiusAxisIds[0];
130
234
  return radiusAxis[id];
131
235
  }
@@ -6,10 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.useBarSeries = useBarSeries;
8
8
  exports.useBarSeriesContext = useBarSeriesContext;
9
- var _createSeriesSelectorOfType = require("../internals/createSeriesSelectorOfType");
10
- const useSelectorSeries = (0, _createSeriesSelectorOfType.createSeriesSelectorsOfType)('bar');
11
- const useSelectorSeriesContext = (0, _createSeriesSelectorOfType.createAllSeriesSelectorOfType)('bar');
12
-
9
+ var _seriesSelectorOfType = require("../internals/seriesSelectorOfType");
13
10
  /**
14
11
  * Get access to the internal state of bar series.
15
12
  *
@@ -33,7 +30,7 @@ const useSelectorSeriesContext = (0, _createSeriesSelectorOfType.createAllSeries
33
30
  */
34
31
 
35
32
  function useBarSeries(seriesIds) {
36
- return useSelectorSeries(seriesIds);
33
+ return (0, _seriesSelectorOfType.useSeriesOfType)('bar', seriesIds);
37
34
  }
38
35
 
39
36
  /**
@@ -45,5 +42,5 @@ function useBarSeries(seriesIds) {
45
42
  * @returns the bar series
46
43
  */
47
44
  function useBarSeriesContext() {
48
- return useSelectorSeriesContext();
45
+ return (0, _seriesSelectorOfType.useAllSeriesOfType)('bar');
49
46
  }