@mui/x-charts 8.6.0 → 8.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChart/BarChart.d.ts +1 -1
- package/BarChart/BarChart.js +16 -0
- package/BarChart/BarPlot.js +11 -150
- package/BarChart/useBarPlotData.d.ts +8 -0
- package/BarChart/useBarPlotData.js +146 -0
- package/CHANGELOG.md +202 -1
- package/ChartContainer/ChartContainer.d.ts +1 -21
- package/ChartContainer/ChartContainer.js +22 -8
- package/ChartContainer/index.d.ts +8 -1
- package/ChartContainer/useChartContainerProps.js +8 -2
- package/ChartDataProvider/ChartDataProvider.js +6 -0
- package/ChartDataProvider/useChartDataProviderProps.d.ts +1 -1
- package/ChartDataProvider/useChartDataProviderProps.js +6 -1
- package/ChartsAxisHighlight/ChartsXAxisHighlight.d.ts +1 -1
- package/ChartsAxisHighlight/ChartsXAxisHighlight.js +34 -24
- package/ChartsAxisHighlight/ChartsYAxisHighlight.d.ts +1 -1
- package/ChartsAxisHighlight/ChartsYAxisHighlight.js +34 -24
- package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
- package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
- package/ChartsReferenceLine/ChartsXReferenceLine.js +48 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
- package/ChartsReferenceLine/ChartsYReferenceLine.js +48 -1
- package/ChartsReferenceLine/index.d.ts +3 -1
- package/ChartsSurface/ChartsSurface.js +2 -1
- package/ChartsTooltip/ChartsTooltipContainer.js +6 -3
- package/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
- package/ChartsTooltip/utils.js +18 -29
- package/Gauge/GaugeContainer.d.ts +1 -1
- package/LineChart/AreaPlot.js +5 -115
- package/LineChart/LineChart.js +22 -0
- package/LineChart/LineHighlightPlot.js +10 -4
- package/LineChart/LinePlot.js +5 -99
- package/LineChart/MarkPlot.js +17 -3
- package/LineChart/useAreaPlotData.d.ts +12 -0
- package/LineChart/useAreaPlotData.js +126 -0
- package/LineChart/useLinePlotData.d.ts +11 -0
- package/LineChart/useLinePlotData.js +108 -0
- package/PieChart/PieChart.d.ts +1 -1
- package/RadarChart/RadarDataProvider/RadarDataProvider.d.ts +1 -1
- package/ScatterChart/Scatter.js +22 -48
- package/ScatterChart/ScatterChart.d.ts +1 -1
- package/ScatterChart/ScatterPlot.js +2 -2
- package/ScatterChart/seriesConfig/seriesProcessor.js +3 -0
- package/ScatterChart/useScatterPlotData.d.ts +8 -0
- package/ScatterChart/useScatterPlotData.js +33 -0
- package/SparkLineChart/SparkLineChart.d.ts +1 -1
- package/SparkLineChart/SparkLineChart.js +16 -0
- package/context/ChartApi.d.ts +22 -0
- package/context/ChartApi.js +5 -0
- package/context/ChartProvider/ChartContext.js +1 -0
- package/context/index.d.ts +2 -1
- package/context/useChartApiContext.d.ts +1 -1
- package/esm/BarChart/BarChart.d.ts +1 -1
- package/esm/BarChart/BarChart.js +16 -0
- package/esm/BarChart/BarPlot.js +12 -152
- package/esm/BarChart/useBarPlotData.d.ts +8 -0
- package/esm/BarChart/useBarPlotData.js +139 -0
- package/esm/ChartContainer/ChartContainer.d.ts +1 -21
- package/esm/ChartContainer/ChartContainer.js +22 -8
- package/esm/ChartContainer/index.d.ts +8 -1
- package/esm/ChartContainer/index.js +6 -1
- package/esm/ChartContainer/useChartContainerProps.js +8 -2
- package/esm/ChartDataProvider/ChartDataProvider.js +6 -0
- package/esm/ChartDataProvider/useChartDataProviderProps.d.ts +1 -1
- package/esm/ChartDataProvider/useChartDataProviderProps.js +7 -2
- package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.d.ts +1 -1
- package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.js +36 -26
- package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.d.ts +1 -1
- package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.js +36 -26
- package/esm/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +47 -0
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +47 -0
- package/esm/ChartsReferenceLine/index.d.ts +3 -1
- package/esm/ChartsReferenceLine/index.js +2 -1
- package/esm/ChartsSurface/ChartsSurface.js +2 -1
- package/esm/ChartsTooltip/ChartsTooltipContainer.js +6 -3
- package/esm/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
- package/esm/ChartsTooltip/utils.js +18 -29
- package/esm/Gauge/GaugeContainer.d.ts +1 -1
- package/esm/LineChart/AreaPlot.js +5 -115
- package/esm/LineChart/LineChart.js +22 -0
- package/esm/LineChart/LineHighlightPlot.js +11 -5
- package/esm/LineChart/LinePlot.js +5 -99
- package/esm/LineChart/MarkPlot.js +17 -3
- package/esm/LineChart/useAreaPlotData.d.ts +12 -0
- package/esm/LineChart/useAreaPlotData.js +119 -0
- package/esm/LineChart/useLinePlotData.d.ts +11 -0
- package/esm/LineChart/useLinePlotData.js +101 -0
- package/esm/PieChart/PieChart.d.ts +1 -1
- package/esm/RadarChart/RadarDataProvider/RadarDataProvider.d.ts +1 -1
- package/esm/ScatterChart/Scatter.js +23 -49
- package/esm/ScatterChart/ScatterChart.d.ts +1 -1
- package/esm/ScatterChart/ScatterPlot.js +2 -2
- package/esm/ScatterChart/seriesConfig/seriesProcessor.js +3 -0
- package/esm/ScatterChart/useScatterPlotData.d.ts +8 -0
- package/esm/ScatterChart/useScatterPlotData.js +26 -0
- package/esm/SparkLineChart/SparkLineChart.d.ts +1 -1
- package/esm/SparkLineChart/SparkLineChart.js +16 -0
- package/esm/context/ChartApi.d.ts +22 -0
- package/esm/context/ChartApi.js +1 -0
- package/esm/context/ChartProvider/ChartContext.js +2 -0
- package/esm/context/index.d.ts +2 -1
- package/esm/context/useChartApiContext.d.ts +1 -1
- package/esm/hooks/useAxis.d.ts +2 -2
- package/esm/hooks/useInteractionItemProps.d.ts +14 -9
- package/esm/hooks/useInteractionItemProps.js +28 -28
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -2
- package/esm/internals/constants.d.ts +3 -0
- package/esm/internals/constants.js +4 -0
- package/esm/internals/getLabel.d.ts +1 -1
- package/esm/internals/index.d.ts +6 -0
- package/esm/internals/index.js +6 -0
- package/esm/internals/plugins/corePlugins/corePlugins.d.ts +4 -2
- package/esm/internals/plugins/corePlugins/corePlugins.js +3 -1
- package/esm/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
- package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -29
- package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
- package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +0 -6
- package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/index.d.ts +3 -0
- package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/index.js +2 -0
- package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.d.ts +3 -0
- package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.js +27 -0
- package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.d.ts +8 -0
- package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.js +3 -0
- package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.d.ts +21 -0
- package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js +1 -0
- package/esm/internals/plugins/corePlugins/useChartId/useChartId.js +2 -0
- package/esm/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.js +1 -0
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +77 -0
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +1 -0
- package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.d.ts +5 -1
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +4 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.d.ts +1 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.js +5 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisDomainLimit.d.ts +7 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisDomainLimit.js +14 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/index.d.ts +2 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/index.js +2 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +90 -36
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +18 -1
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.d.ts +3 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +76 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +10 -5
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +8 -5
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.ts +47 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +48 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +18 -12
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +16 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/zoom.types.d.ts +6 -1
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +34 -34
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +7 -8
- package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +47 -30
- package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
- package/esm/internals/plugins/utils/useLazySelectorEffect.d.ts +7 -0
- package/esm/internals/plugins/utils/useLazySelectorEffect.js +70 -0
- package/esm/internals/store/useCharts.d.ts +1 -1
- package/esm/locales/elGR.d.ts +19 -0
- package/esm/locales/elGR.js +15 -0
- package/esm/locales/index.d.ts +1 -0
- package/esm/locales/index.js +1 -0
- package/esm/models/axis.d.ts +15 -0
- package/esm/models/axis.js +4 -0
- package/esm/models/index.d.ts +1 -1
- package/esm/models/seriesType/scatter.d.ts +11 -2
- package/esm/themeAugmentation/components.d.ts +3 -0
- package/esm/themeAugmentation/props.d.ts +2 -0
- package/hooks/useAxis.d.ts +2 -2
- package/hooks/useInteractionItemProps.d.ts +14 -9
- package/hooks/useInteractionItemProps.js +29 -28
- package/index.d.ts +2 -1
- package/index.js +37 -11
- package/internals/constants.d.ts +3 -0
- package/internals/constants.js +5 -1
- package/internals/getLabel.d.ts +1 -1
- package/internals/index.d.ts +6 -0
- package/internals/index.js +52 -0
- package/internals/plugins/corePlugins/corePlugins.d.ts +4 -2
- package/internals/plugins/corePlugins/corePlugins.js +3 -1
- package/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
- package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -29
- package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
- package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +0 -6
- package/internals/plugins/corePlugins/useChartExperimentalFeature/index.d.ts +3 -0
- package/internals/plugins/corePlugins/useChartExperimentalFeature/index.js +27 -0
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.d.ts +3 -0
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.js +34 -0
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.d.ts +8 -0
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.js +10 -0
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.d.ts +21 -0
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js +5 -0
- package/internals/plugins/corePlugins/useChartId/useChartId.js +1 -0
- package/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
- package/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
- package/internals/plugins/corePlugins/useChartInteractionListener/index.js +12 -0
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +84 -0
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +5 -0
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.d.ts +5 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +4 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.d.ts +1 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/defaultizeZoom.js +4 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisDomainLimit.d.ts +7 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisDomainLimit.js +21 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/index.d.ts +2 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/index.js +24 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +90 -36
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +18 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.d.ts +3 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +82 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +10 -5
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +9 -6
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.d.ts +47 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +55 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +18 -12
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +18 -3
- package/internals/plugins/featurePlugins/useChartCartesianAxis/zoom.types.d.ts +6 -1
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
- package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +34 -34
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +7 -8
- package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +46 -30
- package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
- package/internals/plugins/utils/useLazySelectorEffect.d.ts +7 -0
- package/internals/plugins/utils/useLazySelectorEffect.js +77 -0
- package/internals/store/useCharts.d.ts +1 -1
- package/locales/elGR.d.ts +19 -0
- package/locales/elGR.js +21 -0
- package/locales/index.d.ts +1 -0
- package/locales/index.js +11 -0
- package/models/axis.d.ts +15 -0
- package/models/axis.js +4 -0
- package/models/index.d.ts +1 -1
- package/models/seriesType/scatter.d.ts +11 -2
- package/package.json +4 -3
- package/themeAugmentation/components.d.ts +3 -0
- package/themeAugmentation/props.d.ts +2 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { area as d3Area } from '@mui/x-charts-vendor/d3-shape';
|
|
3
|
+
import { useChartGradientIdBuilder } from "../hooks/useChartGradientId.js";
|
|
4
|
+
import { isBandScale } from "../internals/isBandScale.js";
|
|
5
|
+
import { getCurveFactory } from "../internals/getCurve.js";
|
|
6
|
+
import { getValueToPositionMapper, useLineSeriesContext, useXAxes, useYAxes } from "../hooks/index.js";
|
|
7
|
+
import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
|
|
8
|
+
export function useAreaPlotData(xAxes, yAxes) {
|
|
9
|
+
const seriesData = useLineSeriesContext();
|
|
10
|
+
const defaultXAxisId = useXAxes().xAxisIds[0];
|
|
11
|
+
const defaultYAxisId = useYAxes().yAxisIds[0];
|
|
12
|
+
const getGradientId = useChartGradientIdBuilder();
|
|
13
|
+
|
|
14
|
+
// This memo prevents odd line chart behavior when hydrating.
|
|
15
|
+
const allData = React.useMemo(() => {
|
|
16
|
+
if (seriesData === undefined) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const {
|
|
20
|
+
series,
|
|
21
|
+
stackingGroups
|
|
22
|
+
} = seriesData;
|
|
23
|
+
const areaPlotData = [];
|
|
24
|
+
for (const stackingGroup of stackingGroups) {
|
|
25
|
+
const groupIds = stackingGroup.ids;
|
|
26
|
+
for (let i = groupIds.length - 1; i >= 0; i -= 1) {
|
|
27
|
+
const seriesId = groupIds[i];
|
|
28
|
+
const {
|
|
29
|
+
xAxisId = defaultXAxisId,
|
|
30
|
+
yAxisId = defaultYAxisId,
|
|
31
|
+
stackedData,
|
|
32
|
+
data,
|
|
33
|
+
connectNulls,
|
|
34
|
+
baseline,
|
|
35
|
+
curve,
|
|
36
|
+
strictStepCurve,
|
|
37
|
+
area
|
|
38
|
+
} = series[seriesId];
|
|
39
|
+
if (!area || !(xAxisId in xAxes) || !(yAxisId in yAxes)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const xScale = xAxes[xAxisId].scale;
|
|
43
|
+
const xPosition = getValueToPositionMapper(xScale);
|
|
44
|
+
const yScale = yAxes[yAxisId].scale;
|
|
45
|
+
const xData = xAxes[xAxisId].data;
|
|
46
|
+
const gradientId = yAxes[yAxisId].colorScale && getGradientId(yAxisId) || xAxes[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
|
|
47
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
48
|
+
if (xData === undefined) {
|
|
49
|
+
throw new Error(`MUI X Charts: ${xAxisId === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisId}"`} should have data property to be able to display a line plot.`);
|
|
50
|
+
}
|
|
51
|
+
if (xData.length < stackedData.length) {
|
|
52
|
+
throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const shouldExpand = curve?.includes('step') && !strictStepCurve && isBandScale(xScale);
|
|
56
|
+
const formattedData = xData?.flatMap((x, index) => {
|
|
57
|
+
const nullData = data[index] == null;
|
|
58
|
+
if (shouldExpand) {
|
|
59
|
+
const rep = [{
|
|
60
|
+
x,
|
|
61
|
+
y: stackedData[index],
|
|
62
|
+
nullData,
|
|
63
|
+
isExtension: false
|
|
64
|
+
}];
|
|
65
|
+
if (!nullData && (index === 0 || data[index - 1] == null)) {
|
|
66
|
+
rep.unshift({
|
|
67
|
+
x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
|
|
68
|
+
y: stackedData[index],
|
|
69
|
+
nullData,
|
|
70
|
+
isExtension: true
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
|
|
74
|
+
rep.push({
|
|
75
|
+
x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
|
|
76
|
+
y: stackedData[index],
|
|
77
|
+
nullData,
|
|
78
|
+
isExtension: true
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return rep;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
x,
|
|
85
|
+
y: stackedData[index],
|
|
86
|
+
nullData
|
|
87
|
+
};
|
|
88
|
+
}) ?? [];
|
|
89
|
+
const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
|
|
90
|
+
const areaPath = d3Area().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y0(d => {
|
|
91
|
+
if (typeof baseline === 'number') {
|
|
92
|
+
return yScale(baseline);
|
|
93
|
+
}
|
|
94
|
+
if (baseline === 'max') {
|
|
95
|
+
return yScale.range()[1];
|
|
96
|
+
}
|
|
97
|
+
if (baseline === 'min') {
|
|
98
|
+
return yScale.range()[0];
|
|
99
|
+
}
|
|
100
|
+
const value = d.y && yScale(d.y[0]);
|
|
101
|
+
if (Number.isNaN(value)) {
|
|
102
|
+
return yScale.range()[0];
|
|
103
|
+
}
|
|
104
|
+
return value;
|
|
105
|
+
}).y1(d => d.y && yScale(d.y[1]));
|
|
106
|
+
const d = areaPath.curve(getCurveFactory(curve))(d3Data) || '';
|
|
107
|
+
areaPlotData.push({
|
|
108
|
+
area: series[seriesId].area,
|
|
109
|
+
color: series[seriesId].color,
|
|
110
|
+
gradientId,
|
|
111
|
+
d,
|
|
112
|
+
seriesId
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return areaPlotData;
|
|
117
|
+
}, [seriesData, defaultXAxisId, defaultYAxisId, xAxes, yAxes, getGradientId]);
|
|
118
|
+
return allData;
|
|
119
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ComputedAxisConfig } from "../internals/plugins/featurePlugins/useChartCartesianAxis/index.js";
|
|
2
|
+
import { ChartsXAxisProps, ChartsYAxisProps } from "../models/index.js";
|
|
3
|
+
import { SeriesId } from "../models/seriesType/common.js";
|
|
4
|
+
interface LinePlotDataPoint {
|
|
5
|
+
d: string;
|
|
6
|
+
seriesId: SeriesId;
|
|
7
|
+
color: string;
|
|
8
|
+
gradientId?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function useLinePlotData(xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): LinePlotDataPoint[];
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { warnOnce } from '@mui/x-internals/warning';
|
|
3
|
+
import { line as d3Line } from '@mui/x-charts-vendor/d3-shape';
|
|
4
|
+
import { useChartGradientIdBuilder } from "../hooks/useChartGradientId.js";
|
|
5
|
+
import { isBandScale } from "../internals/isBandScale.js";
|
|
6
|
+
import { getCurveFactory } from "../internals/getCurve.js";
|
|
7
|
+
import { getValueToPositionMapper, useLineSeriesContext, useXAxes, useYAxes } from "../hooks/index.js";
|
|
8
|
+
import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
|
|
9
|
+
export function useLinePlotData(xAxes, yAxes) {
|
|
10
|
+
const seriesData = useLineSeriesContext();
|
|
11
|
+
const defaultXAxisId = useXAxes().xAxisIds[0];
|
|
12
|
+
const defaultYAxisId = useYAxes().yAxisIds[0];
|
|
13
|
+
const getGradientId = useChartGradientIdBuilder();
|
|
14
|
+
|
|
15
|
+
// This memo prevents odd line chart behavior when hydrating.
|
|
16
|
+
const allData = React.useMemo(() => {
|
|
17
|
+
if (seriesData === undefined) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const {
|
|
21
|
+
series,
|
|
22
|
+
stackingGroups
|
|
23
|
+
} = seriesData;
|
|
24
|
+
const linePlotData = [];
|
|
25
|
+
for (const stackingGroup of stackingGroups) {
|
|
26
|
+
const groupIds = stackingGroup.ids;
|
|
27
|
+
for (const seriesId of groupIds) {
|
|
28
|
+
const {
|
|
29
|
+
xAxisId = defaultXAxisId,
|
|
30
|
+
yAxisId = defaultYAxisId,
|
|
31
|
+
stackedData,
|
|
32
|
+
data,
|
|
33
|
+
connectNulls,
|
|
34
|
+
curve,
|
|
35
|
+
strictStepCurve
|
|
36
|
+
} = series[seriesId];
|
|
37
|
+
if (!(xAxisId in xAxes) || !(yAxisId in yAxes)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const xScale = xAxes[xAxisId].scale;
|
|
41
|
+
const xPosition = getValueToPositionMapper(xScale);
|
|
42
|
+
const yScale = yAxes[yAxisId].scale;
|
|
43
|
+
const xData = xAxes[xAxisId].data;
|
|
44
|
+
const gradientId = yAxes[yAxisId].colorScale && getGradientId(yAxisId) || xAxes[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
|
|
45
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
46
|
+
if (xData === undefined) {
|
|
47
|
+
throw new Error(`MUI X Charts: ${xAxisId === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisId}"`} should have data property to be able to display a line plot.`);
|
|
48
|
+
}
|
|
49
|
+
if (xData.length < stackedData.length) {
|
|
50
|
+
warnOnce(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`, 'error');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const shouldExpand = curve?.includes('step') && !strictStepCurve && isBandScale(xScale);
|
|
54
|
+
const formattedData = xData?.flatMap((x, index) => {
|
|
55
|
+
const nullData = data[index] == null;
|
|
56
|
+
if (shouldExpand) {
|
|
57
|
+
const rep = [{
|
|
58
|
+
x,
|
|
59
|
+
y: stackedData[index],
|
|
60
|
+
nullData,
|
|
61
|
+
isExtension: false
|
|
62
|
+
}];
|
|
63
|
+
if (!nullData && (index === 0 || data[index - 1] == null)) {
|
|
64
|
+
rep.unshift({
|
|
65
|
+
x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
|
|
66
|
+
y: stackedData[index],
|
|
67
|
+
nullData,
|
|
68
|
+
isExtension: true
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
|
|
72
|
+
rep.push({
|
|
73
|
+
x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
|
|
74
|
+
y: stackedData[index],
|
|
75
|
+
nullData,
|
|
76
|
+
isExtension: true
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return rep;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
x,
|
|
83
|
+
y: stackedData[index],
|
|
84
|
+
nullData
|
|
85
|
+
};
|
|
86
|
+
}) ?? [];
|
|
87
|
+
const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
|
|
88
|
+
const linePath = d3Line().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y(d => yScale(d.y[1]));
|
|
89
|
+
const d = linePath.curve(getCurveFactory(curve))(d3Data) || '';
|
|
90
|
+
linePlotData.push({
|
|
91
|
+
color: series[seriesId].color,
|
|
92
|
+
gradientId,
|
|
93
|
+
d,
|
|
94
|
+
seriesId
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return linePlotData;
|
|
99
|
+
}, [seriesData, defaultXAxisId, defaultYAxisId, xAxes, yAxes, getGradientId]);
|
|
100
|
+
return allData;
|
|
101
|
+
}
|
|
@@ -12,7 +12,7 @@ import { ChartsOverlayProps, ChartsOverlaySlotProps, ChartsOverlaySlots } from "
|
|
|
12
12
|
import { PieChartPluginSignatures } from "./PieChart.plugins.js";
|
|
13
13
|
export interface PieChartSlots extends PiePlotSlots, ChartsLegendSlots, ChartsOverlaySlots, ChartsTooltipSlots, ChartsToolbarSlots, Partial<ChartsSlots> {}
|
|
14
14
|
export interface PieChartSlotProps extends PiePlotSlotProps, ChartsLegendSlotProps, ChartsOverlaySlotProps, ChartsTooltipSlotProps, ChartsToolbarSlotProps, Partial<ChartsSlotProps> {}
|
|
15
|
-
export interface PieChartProps extends Omit<ChartContainerProps<'pie', PieChartPluginSignatures>, 'series' | 'slots' | 'slotProps'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, Pick<PiePlotProps, 'skipAnimation'> {
|
|
15
|
+
export interface PieChartProps extends Omit<ChartContainerProps<'pie', PieChartPluginSignatures>, 'series' | 'slots' | 'slotProps' | 'experimentalFeatures'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, Pick<PiePlotProps, 'skipAnimation'> {
|
|
16
16
|
/**
|
|
17
17
|
* The series to display in the pie chart.
|
|
18
18
|
* An array of [[PieSeriesType]] objects.
|
|
@@ -5,7 +5,7 @@ import { RadarSeriesType } from "../../models/seriesType/radar.js";
|
|
|
5
5
|
import { ChartDataProviderProps } from "../../ChartDataProvider/index.js";
|
|
6
6
|
import { RadarConfig } from "./radar.types.js";
|
|
7
7
|
import { ChartAnyPluginSignature } from "../../internals/plugins/models/plugin.js";
|
|
8
|
-
export type RadarDataProviderProps<TSignatures extends readonly ChartAnyPluginSignature[] = RadarChartPluginsSignatures> = Omit<ChartDataProviderProps<'radar', TSignatures>, 'series' | 'rotationAxis' | 'radiusAxis' | 'dataset'> & {
|
|
8
|
+
export type RadarDataProviderProps<TSignatures extends readonly ChartAnyPluginSignature[] = RadarChartPluginsSignatures> = Omit<ChartDataProviderProps<'radar', TSignatures>, 'series' | 'rotationAxis' | 'radiusAxis' | 'dataset' | 'experimentalFeatures'> & {
|
|
9
9
|
/**
|
|
10
10
|
* The series to display in the bar chart.
|
|
11
11
|
* An array of [[RadarSeriesType]] objects.
|
|
@@ -6,15 +6,15 @@ const _excluded = ["ownerState"];
|
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
9
|
-
import {
|
|
10
|
-
import { useInteractionAllItemProps } from "../hooks/useInteractionItemProps.js";
|
|
9
|
+
import { getInteractionItemProps } from "../hooks/useInteractionItemProps.js";
|
|
11
10
|
import { useStore } from "../internals/store/useStore.js";
|
|
12
11
|
import { useSelector } from "../internals/store/useSelector.js";
|
|
13
12
|
import { useItemHighlightedGetter } from "../hooks/useItemHighlightedGetter.js";
|
|
14
13
|
import { selectorChartsVoronoiIsVoronoiEnabled } from "../internals/plugins/featurePlugins/useChartVoronoi/index.js";
|
|
15
|
-
import { useChartContext } from "../context/ChartProvider/index.js";
|
|
16
14
|
import { ScatterMarker } from "./ScatterMarker.js";
|
|
17
15
|
import { useUtilityClasses } from "./scatterClasses.js";
|
|
16
|
+
import { useScatterPlotData } from "./useScatterPlotData.js";
|
|
17
|
+
import { useChartContext } from "../context/ChartProvider/index.js";
|
|
18
18
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
19
|
/**
|
|
20
20
|
* Demos:
|
|
@@ -48,37 +48,7 @@ function Scatter(props) {
|
|
|
48
48
|
isFaded,
|
|
49
49
|
isHighlighted
|
|
50
50
|
} = useItemHighlightedGetter();
|
|
51
|
-
const
|
|
52
|
-
const getXPosition = getValueToPositionMapper(xScale);
|
|
53
|
-
const getYPosition = getValueToPositionMapper(yScale);
|
|
54
|
-
const temp = [];
|
|
55
|
-
for (let i = 0; i < series.data.length; i += 1) {
|
|
56
|
-
const scatterPoint = series.data[i];
|
|
57
|
-
const x = getXPosition(scatterPoint.x);
|
|
58
|
-
const y = getYPosition(scatterPoint.y);
|
|
59
|
-
const isInRange = instance.isPointInside(x, y);
|
|
60
|
-
if (isInRange) {
|
|
61
|
-
const currentItem = {
|
|
62
|
-
seriesId: series.id,
|
|
63
|
-
dataIndex: i
|
|
64
|
-
};
|
|
65
|
-
const isItemHighlighted = isHighlighted(currentItem);
|
|
66
|
-
temp.push({
|
|
67
|
-
x,
|
|
68
|
-
y,
|
|
69
|
-
isHighlighted: isItemHighlighted,
|
|
70
|
-
isFaded: !isItemHighlighted && isFaded(currentItem),
|
|
71
|
-
id: scatterPoint.id,
|
|
72
|
-
seriesId: series.id,
|
|
73
|
-
type: 'scatter',
|
|
74
|
-
dataIndex: i,
|
|
75
|
-
color: colorGetter ? colorGetter(i) : color
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return temp;
|
|
80
|
-
}, [xScale, yScale, series.data, series.id, isHighlighted, isFaded, colorGetter, color, instance]);
|
|
81
|
-
const interactionItemProps = useInteractionAllItemProps(cleanData, skipInteractionHandlers);
|
|
51
|
+
const scatterPlotData = useScatterPlotData(series, xScale, yScale, instance.isPointInside);
|
|
82
52
|
const Marker = slots?.marker ?? ScatterMarker;
|
|
83
53
|
const _useSlotProps = useSlotProps({
|
|
84
54
|
elementType: Marker,
|
|
@@ -94,21 +64,25 @@ function Scatter(props) {
|
|
|
94
64
|
return /*#__PURE__*/_jsx("g", {
|
|
95
65
|
"data-series": series.id,
|
|
96
66
|
className: classes.root,
|
|
97
|
-
children:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
67
|
+
children: scatterPlotData.map((dataPoint, i) => {
|
|
68
|
+
const isItemHighlighted = isHighlighted(dataPoint);
|
|
69
|
+
const isItemFaded = !isItemHighlighted && isFaded(dataPoint);
|
|
70
|
+
return /*#__PURE__*/_jsx(Marker, _extends({
|
|
71
|
+
dataIndex: dataPoint.dataIndex,
|
|
72
|
+
color: colorGetter ? colorGetter(i) : color,
|
|
73
|
+
isHighlighted: isItemHighlighted,
|
|
74
|
+
isFaded: isItemFaded,
|
|
75
|
+
x: dataPoint.x,
|
|
76
|
+
y: dataPoint.y,
|
|
77
|
+
onClick: onItemClick && (event => onItemClick(event, {
|
|
78
|
+
type: 'scatter',
|
|
79
|
+
seriesId: series.id,
|
|
80
|
+
dataIndex: dataPoint.dataIndex
|
|
81
|
+
})),
|
|
82
|
+
"data-highlighted": isItemHighlighted || undefined,
|
|
83
|
+
"data-faded": isItemFaded || undefined
|
|
84
|
+
}, skipInteractionHandlers ? undefined : getInteractionItemProps(instance, dataPoint), markerProps), dataPoint.id ?? dataPoint.dataIndex);
|
|
85
|
+
})
|
|
112
86
|
});
|
|
113
87
|
}
|
|
114
88
|
process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
|
|
@@ -16,7 +16,7 @@ import { UseChartVoronoiSignature } from "../internals/plugins/featurePlugins/us
|
|
|
16
16
|
import { ScatterChartPluginsSignatures } from "./ScatterChart.plugins.js";
|
|
17
17
|
export interface ScatterChartSlots extends ChartsAxisSlots, ScatterPlotSlots, ChartsLegendSlots, ChartsOverlaySlots, ChartsTooltipSlots, ChartsToolbarSlots, Partial<ChartsSlots> {}
|
|
18
18
|
export interface ScatterChartSlotProps extends ChartsAxisSlotProps, ScatterPlotSlotProps, ChartsLegendSlotProps, ChartsOverlaySlotProps, ChartsTooltipSlotProps, ChartsToolbarSlotProps, Partial<ChartsSlotProps> {}
|
|
19
|
-
export interface ScatterChartProps extends Omit<ChartContainerProps<'scatter', ScatterChartPluginsSignatures>, 'series' | 'plugins' | 'onItemClick'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'> {
|
|
19
|
+
export interface ScatterChartProps extends Omit<ChartContainerProps<'scatter', ScatterChartPluginsSignatures>, 'series' | 'plugins' | 'onItemClick' | 'experimentalFeatures' | 'highlightedAxis' | 'onHighlightedAxisChange'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'> {
|
|
20
20
|
/**
|
|
21
21
|
* The series to display in the scatter chart.
|
|
22
22
|
* An array of [[ScatterSeriesType]] objects.
|
|
@@ -5,9 +5,9 @@ import * as React from 'react';
|
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { Scatter } from "./Scatter.js";
|
|
7
7
|
import { useScatterSeriesContext } from "../hooks/useScatterSeries.js";
|
|
8
|
-
import getColor from "./seriesConfig/getColor.js";
|
|
9
8
|
import { useXAxes, useYAxes } from "../hooks/index.js";
|
|
10
9
|
import { useZAxes } from "../hooks/useZAxis.js";
|
|
10
|
+
import { seriesConfig as scatterSeriesConfig } from "./seriesConfig/index.js";
|
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
12
|
/**
|
|
13
13
|
* Demos:
|
|
@@ -58,7 +58,7 @@ function ScatterPlot(props) {
|
|
|
58
58
|
zAxisId,
|
|
59
59
|
color
|
|
60
60
|
} = series[seriesId];
|
|
61
|
-
const colorGetter =
|
|
61
|
+
const colorGetter = scatterSeriesConfig.colorProcessor(series[seriesId], xAxis[xAxisId ?? defaultXAxisId], yAxis[yAxisId ?? defaultYAxisId], zAxis[zAxisId ?? defaultZAxisId]);
|
|
62
62
|
const xScale = xAxis[xAxisId ?? defaultXAxisId].scale;
|
|
63
63
|
const yScale = yAxis[yAxisId ?? defaultYAxisId].scale;
|
|
64
64
|
return /*#__PURE__*/_jsx(ScatterItems, _extends({
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SeriesId } from "../models/seriesType/common.js";
|
|
2
|
+
import { D3Scale } from "../models/axis.js";
|
|
3
|
+
import { DefaultizedScatterSeriesType, ScatterValueType } from "../models/index.js";
|
|
4
|
+
export declare function useScatterPlotData(series: DefaultizedScatterSeriesType, xScale: D3Scale, yScale: D3Scale, isPointInside: (x: number, y: number) => boolean): (ScatterValueType & {
|
|
5
|
+
dataIndex: number;
|
|
6
|
+
seriesId: SeriesId;
|
|
7
|
+
type: "scatter";
|
|
8
|
+
})[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { getValueToPositionMapper } from "../hooks/index.js";
|
|
3
|
+
export function useScatterPlotData(series, xScale, yScale, isPointInside) {
|
|
4
|
+
return React.useMemo(() => {
|
|
5
|
+
const getXPosition = getValueToPositionMapper(xScale);
|
|
6
|
+
const getYPosition = getValueToPositionMapper(yScale);
|
|
7
|
+
const temp = [];
|
|
8
|
+
for (let i = 0; i < series.data.length; i += 1) {
|
|
9
|
+
const scatterPoint = series.data[i];
|
|
10
|
+
const x = getXPosition(scatterPoint.x);
|
|
11
|
+
const y = getYPosition(scatterPoint.y);
|
|
12
|
+
const isInRange = isPointInside(x, y);
|
|
13
|
+
if (isInRange) {
|
|
14
|
+
temp.push({
|
|
15
|
+
x,
|
|
16
|
+
y,
|
|
17
|
+
id: scatterPoint.id,
|
|
18
|
+
seriesId: series.id,
|
|
19
|
+
type: 'scatter',
|
|
20
|
+
dataIndex: i
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return temp;
|
|
25
|
+
}, [xScale, yScale, series.data, series.id, isPointInside]);
|
|
26
|
+
}
|
|
@@ -13,7 +13,7 @@ import { BarPlotSlots, BarPlotSlotProps } from "../BarChart/BarPlot.js";
|
|
|
13
13
|
import { ChartMargin } from "../internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.js";
|
|
14
14
|
export interface SparkLineChartSlots extends AreaPlotSlots, LinePlotSlots, MarkPlotSlots, LineHighlightPlotSlots, Omit<BarPlotSlots, 'barLabel'>, ChartsTooltipSlots {}
|
|
15
15
|
export interface SparkLineChartSlotProps extends AreaPlotSlotProps, LinePlotSlotProps, MarkPlotSlotProps, LineHighlightPlotSlotProps, BarPlotSlotProps, ChartsTooltipSlotProps {}
|
|
16
|
-
export interface SparkLineChartProps extends Omit<ChartContainerProps, 'series' | 'xAxis' | 'yAxis' | 'zAxis' | 'radiusAxis' | 'rotationAxis' | 'margin' | 'plugins' | 'colors' | 'slots' | 'slotProps'> {
|
|
16
|
+
export interface SparkLineChartProps extends Omit<ChartContainerProps, 'series' | 'xAxis' | 'yAxis' | 'zAxis' | 'radiusAxis' | 'rotationAxis' | 'margin' | 'plugins' | 'colors' | 'slots' | 'slotProps' | 'experimentalFeatures'> {
|
|
17
17
|
/**
|
|
18
18
|
* The xAxis configuration.
|
|
19
19
|
* Notice it is a single [[AxisConfig]] object, not an array of configuration.
|
|
@@ -206,6 +206,14 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
206
206
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
207
207
|
*/
|
|
208
208
|
height: PropTypes.number,
|
|
209
|
+
/**
|
|
210
|
+
* The controlled axis highlight.
|
|
211
|
+
* Identified by the axis id, and data index.
|
|
212
|
+
*/
|
|
213
|
+
highlightedAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
214
|
+
axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
215
|
+
dataIndex: PropTypes.number.isRequired
|
|
216
|
+
})),
|
|
209
217
|
/**
|
|
210
218
|
* The highlighted item.
|
|
211
219
|
* Used when the highlight is controlled.
|
|
@@ -249,6 +257,14 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
249
257
|
* @param {HighlightItemData | null} highlightedItem The newly highlighted item.
|
|
250
258
|
*/
|
|
251
259
|
onHighlightChange: PropTypes.func,
|
|
260
|
+
/**
|
|
261
|
+
* The function called when the pointer position corresponds to a new axis data item.
|
|
262
|
+
* This update can either be caused by a pointer movement, or an axis update.
|
|
263
|
+
* In case of multiple axes, the function is called if at least one axis is updated.
|
|
264
|
+
* The argument contains the identifier for all axes with a `data` property.
|
|
265
|
+
* @param {AxisItemIdentifier[]} axisItems The array of axes item identifiers.
|
|
266
|
+
*/
|
|
267
|
+
onHighlightedAxisChange: PropTypes.func,
|
|
252
268
|
/**
|
|
253
269
|
* Callback fired when clicking close to an item.
|
|
254
270
|
* This is only available for scatter plot for now.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PieChartPluginSignatures } from "../PieChart/PieChart.plugins.js";
|
|
2
|
+
import type { BarChartPluginsSignatures } from "../BarChart/BarChart.plugins.js";
|
|
3
|
+
import type { ScatterChartPluginsSignatures } from "../ScatterChart/ScatterChart.plugins.js";
|
|
4
|
+
import type { LineChartPluginsSignatures } from "../LineChart/LineChart.plugins.js";
|
|
5
|
+
import type { AllPluginSignatures, DefaultPluginSignatures } from "../internals/plugins/allPlugins.js";
|
|
6
|
+
import type { ChartAnyPluginSignature } from "../internals/plugins/models/plugin.js";
|
|
7
|
+
import type { ChartPublicAPI } from "../internals/plugins/models/index.js";
|
|
8
|
+
export type PluginsPerSeriesType = {
|
|
9
|
+
line: LineChartPluginsSignatures;
|
|
10
|
+
scatter: ScatterChartPluginsSignatures;
|
|
11
|
+
bar: BarChartPluginsSignatures;
|
|
12
|
+
pie: PieChartPluginSignatures;
|
|
13
|
+
composition: DefaultPluginSignatures;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The API of the chart `apiRef` object.
|
|
17
|
+
* The chart type can be passed as the first generic parameter to narrow down the API to the specific chart type.
|
|
18
|
+
* @example ChartApi<'bar'>
|
|
19
|
+
* If the chart is being created using composition, the `composition` value can be used.
|
|
20
|
+
* @example ChartApi<'composition'>
|
|
21
|
+
*/
|
|
22
|
+
export type ChartApi<TSeries extends keyof PluginsPerSeriesType | undefined = undefined, TSignatures extends readonly ChartAnyPluginSignature[] = (TSeries extends keyof PluginsPerSeriesType ? PluginsPerSeriesType[TSeries] : AllPluginSignatures)> = ChartPublicAPI<TSignatures>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/context/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export type { HighlightScope, FadeOptions, HighlightItemData, HighlightOptions } from "../internals/plugins/featurePlugins/useChartHighlight/index.js";
|
|
2
|
-
export * from "./useChartApiContext.js";
|
|
2
|
+
export * from "./useChartApiContext.js";
|
|
3
|
+
export type { ChartApi } from "./ChartApi.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { ChartApi } from "
|
|
2
|
+
import { ChartApi } from "./ChartApi.js";
|
|
3
3
|
/**
|
|
4
4
|
* The `useChartApiContext` hook provides access to the chart API.
|
|
5
5
|
* This is only available when the chart is rendered within a chart or a `ChartDataProvider` component.
|
package/esm/hooks/useAxis.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { AxisId, ChartsRadiusAxisProps, ChartsRotationAxisProps, PolarAxisDefaul
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function useXAxes(): {
|
|
13
13
|
xAxis: import("../internals/index.js").ComputedAxisConfig<import("../index.js").ChartsXAxisProps>;
|
|
14
|
-
xAxisIds:
|
|
14
|
+
xAxisIds: AxisId[];
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Get all the y-axes.
|
|
@@ -25,7 +25,7 @@ export declare function useXAxes(): {
|
|
|
25
25
|
*/
|
|
26
26
|
export declare function useYAxes(): {
|
|
27
27
|
yAxis: import("../internals/index.js").ComputedAxisConfig<import("../index.js").ChartsYAxisProps>;
|
|
28
|
-
yAxisIds:
|
|
28
|
+
yAxisIds: AxisId[];
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
31
|
* Get the X axis.
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { SeriesItemIdentifier } from "../models/index.js";
|
|
3
|
+
import { UseChartHighlightSignature } from "../internals/plugins/featurePlugins/useChartHighlight/index.js";
|
|
4
|
+
import { UseChartInteractionSignature } from "../internals/plugins/featurePlugins/useChartInteraction/index.js";
|
|
5
|
+
import { ChartItemIdentifier, ChartSeriesType } from "../models/seriesType/config.js";
|
|
6
|
+
import { ChartInstance } from "../internals/plugins/models/index.js";
|
|
3
7
|
export declare const useInteractionItemProps: (data: SeriesItemIdentifier, skip?: boolean) => {
|
|
4
8
|
onPointerEnter?: () => void;
|
|
5
9
|
onPointerLeave?: () => void;
|
|
6
10
|
onPointerDown?: (event: React.PointerEvent) => void;
|
|
7
11
|
};
|
|
8
|
-
export declare const useInteractionAllItemProps: (data: SeriesItemIdentifier[], skip?: boolean) =>
|
|
9
|
-
onPointerEnter?:
|
|
10
|
-
onPointerLeave?:
|
|
11
|
-
onPointerDown?:
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
export declare const useInteractionAllItemProps: (data: SeriesItemIdentifier[], skip?: boolean) => {
|
|
13
|
+
onPointerEnter?: () => void;
|
|
14
|
+
onPointerLeave?: () => void;
|
|
15
|
+
onPointerDown?: (event: React.PointerEvent) => void;
|
|
16
|
+
}[];
|
|
17
|
+
export declare function getInteractionItemProps(instance: ChartInstance<[UseChartInteractionSignature, UseChartHighlightSignature]>, item: ChartItemIdentifier<ChartSeriesType>): {
|
|
18
|
+
onPointerEnter?: () => void;
|
|
19
|
+
onPointerLeave?: () => void;
|
|
20
|
+
onPointerDown?: (event: React.PointerEvent) => void;
|
|
21
|
+
};
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { useChartContext } from "../context/ChartProvider/index.js";
|
|
5
|
-
|
|
5
|
+
function onPointerDown(event) {
|
|
6
6
|
if ('hasPointerCapture' in event.currentTarget && event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
7
7
|
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
8
8
|
}
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
export const useInteractionItemProps = (data, skip) => {
|
|
11
11
|
const {
|
|
12
12
|
instance
|
|
@@ -56,32 +56,32 @@ export const useInteractionAllItemProps = (data, skip) => {
|
|
|
56
56
|
} = useChartContext();
|
|
57
57
|
const results = React.useMemo(() => {
|
|
58
58
|
return data.map(item => {
|
|
59
|
-
|
|
60
|
-
return {};
|
|
61
|
-
}
|
|
62
|
-
const onPointerEnter = () => {
|
|
63
|
-
if (!item) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
instance.setItemInteraction(item);
|
|
67
|
-
instance.setHighlight({
|
|
68
|
-
seriesId: item.seriesId,
|
|
69
|
-
dataIndex: item.dataIndex
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
const onPointerLeave = () => {
|
|
73
|
-
if (!item) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
instance.removeItemInteraction(item);
|
|
77
|
-
instance.clearHighlight();
|
|
78
|
-
};
|
|
79
|
-
return {
|
|
80
|
-
onPointerEnter,
|
|
81
|
-
onPointerLeave,
|
|
82
|
-
onPointerDown
|
|
83
|
-
};
|
|
59
|
+
return skip ? {} : getInteractionItemProps(instance, item);
|
|
84
60
|
});
|
|
85
61
|
}, [data, instance, skip]);
|
|
86
62
|
return results;
|
|
87
|
-
};
|
|
63
|
+
};
|
|
64
|
+
export function getInteractionItemProps(instance, item) {
|
|
65
|
+
function onPointerEnter() {
|
|
66
|
+
if (!item) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
instance.setItemInteraction(item);
|
|
70
|
+
instance.setHighlight({
|
|
71
|
+
seriesId: item.seriesId,
|
|
72
|
+
dataIndex: item.dataIndex
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function onPointerLeave() {
|
|
76
|
+
if (!item) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
instance.removeItemInteraction(item);
|
|
80
|
+
instance.clearHighlight();
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
onPointerEnter,
|
|
84
|
+
onPointerLeave,
|
|
85
|
+
onPointerDown
|
|
86
|
+
};
|
|
87
|
+
}
|
package/esm/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export * from "./SparkLineChart/index.js";
|
|
|
23
23
|
export * from "./Gauge/index.js";
|
|
24
24
|
export * from "./RadarChart/index.js";
|
|
25
25
|
export * from "./ChartsSurface/index.js";
|
|
26
|
-
export
|
|
26
|
+
export { ChartContainer } from "./ChartContainer/index.js";
|
|
27
|
+
export type { ChartContainerProps } from "./ChartContainer/index.js";
|
|
27
28
|
export * from "./ChartDataProvider/index.js";
|
|
28
29
|
export * from "./Toolbar/index.js";
|