@mui/x-charts-premium 8.22.1 → 8.24.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/BarChartPremium/BarChartPremium.d.ts +16 -1
- package/BarChartPremium/BarChartPremium.js +44 -1
- package/BarChartPremium/RangeBar/AnimatedRangeBarElement.d.ts +3 -0
- package/BarChartPremium/RangeBar/AnimatedRangeBarElement.js +28 -0
- package/BarChartPremium/RangeBar/RangeBarPlot.d.ts +46 -0
- package/BarChartPremium/RangeBar/RangeBarPlot.js +141 -0
- package/BarChartPremium/RangeBar/seriesConfig/extrema.d.ts +3 -0
- package/BarChartPremium/RangeBar/seriesConfig/extrema.js +85 -0
- package/BarChartPremium/RangeBar/seriesConfig/getColor.d.ts +3 -0
- package/BarChartPremium/RangeBar/seriesConfig/getColor.js +43 -0
- package/BarChartPremium/RangeBar/seriesConfig/getSeriesWithDefaultValues.d.ts +19 -0
- package/BarChartPremium/RangeBar/seriesConfig/getSeriesWithDefaultValues.js +14 -0
- package/BarChartPremium/RangeBar/seriesConfig/index.d.ts +2 -0
- package/BarChartPremium/RangeBar/seriesConfig/index.js +29 -0
- package/BarChartPremium/RangeBar/seriesConfig/legend.d.ts +3 -0
- package/BarChartPremium/RangeBar/seriesConfig/legend.js +29 -0
- package/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.d.ts +3 -0
- package/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.js +54 -0
- package/BarChartPremium/RangeBar/seriesConfig/tooltip.d.ts +4 -0
- package/BarChartPremium/RangeBar/seriesConfig/tooltip.js +44 -0
- package/BarChartPremium/RangeBar/seriesConfig/tooltipPosition.d.ts +3 -0
- package/BarChartPremium/RangeBar/seriesConfig/tooltipPosition.js +59 -0
- package/BarChartPremium/RangeBar/types.d.ts +22 -0
- package/BarChartPremium/RangeBar/types.js +5 -0
- package/BarChartPremium/RangeBar/useRangeBarPlotData.d.ts +12 -0
- package/BarChartPremium/RangeBar/useRangeBarPlotData.js +112 -0
- package/BarChartPremium/RangeBar/useUtilityClasses.d.ts +12 -0
- package/BarChartPremium/RangeBar/useUtilityClasses.js +24 -0
- package/BarChartPremium/index.d.ts +3 -1
- package/BarChartPremium/index.js +25 -1
- package/BarChartPremium/useBarChartPremiumProps.d.ts +5 -1
- package/BarChartPremium/useBarChartPremiumProps.js +19 -1
- package/CHANGELOG.md +211 -0
- package/ChartDataProviderPremium/ChartDataProviderPremium.d.ts +3 -2
- package/ChartDataProviderPremium/ChartDataProviderPremium.js +9 -1
- package/ChartDataProviderPremium/index.d.ts +1 -1
- package/ChartDataProviderPremium/index.js +7 -11
- package/ChartZoomSlider/internals/previews/RangeBarPreviewPlot.d.ts +2 -0
- package/ChartZoomSlider/internals/previews/RangeBarPreviewPlot.js +59 -0
- package/esm/BarChartPremium/BarChartPremium.d.ts +16 -1
- package/esm/BarChartPremium/BarChartPremium.js +45 -2
- package/esm/BarChartPremium/RangeBar/AnimatedRangeBarElement.d.ts +3 -0
- package/esm/BarChartPremium/RangeBar/AnimatedRangeBarElement.js +21 -0
- package/esm/BarChartPremium/RangeBar/RangeBarPlot.d.ts +46 -0
- package/esm/BarChartPremium/RangeBar/RangeBarPlot.js +135 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/extrema.d.ts +3 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/extrema.js +77 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/getColor.d.ts +3 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/getColor.js +37 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/getSeriesWithDefaultValues.d.ts +19 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/getSeriesWithDefaultValues.js +7 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/index.d.ts +2 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/index.js +21 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/legend.d.ts +3 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/legend.js +23 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.d.ts +3 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/seriesProcessor.js +47 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/tooltip.d.ts +4 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/tooltip.js +37 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/tooltipPosition.d.ts +3 -0
- package/esm/BarChartPremium/RangeBar/seriesConfig/tooltipPosition.js +53 -0
- package/esm/BarChartPremium/RangeBar/types.d.ts +22 -0
- package/esm/BarChartPremium/RangeBar/types.js +1 -0
- package/esm/BarChartPremium/RangeBar/useRangeBarPlotData.d.ts +12 -0
- package/esm/BarChartPremium/RangeBar/useRangeBarPlotData.js +105 -0
- package/esm/BarChartPremium/RangeBar/useUtilityClasses.d.ts +12 -0
- package/esm/BarChartPremium/RangeBar/useUtilityClasses.js +15 -0
- package/esm/BarChartPremium/index.d.ts +3 -1
- package/esm/BarChartPremium/index.js +3 -1
- package/esm/BarChartPremium/useBarChartPremiumProps.d.ts +5 -1
- package/esm/BarChartPremium/useBarChartPremiumProps.js +18 -1
- package/esm/ChartDataProviderPremium/ChartDataProviderPremium.d.ts +3 -2
- package/esm/ChartDataProviderPremium/ChartDataProviderPremium.js +8 -1
- package/esm/ChartDataProviderPremium/index.d.ts +1 -1
- package/esm/ChartDataProviderPremium/index.js +1 -1
- package/esm/ChartZoomSlider/internals/previews/RangeBarPreviewPlot.d.ts +2 -0
- package/esm/ChartZoomSlider/internals/previews/RangeBarPreviewPlot.js +53 -0
- package/esm/hooks/animation/index.d.ts +1 -0
- package/esm/hooks/animation/index.js +1 -0
- package/esm/hooks/animation/useAnimateRangeBar.d.ts +18 -0
- package/esm/hooks/animation/useAnimateRangeBar.js +51 -0
- package/esm/hooks/index.d.ts +3 -1
- package/esm/hooks/index.js +4 -1
- package/esm/hooks/useRangeBarSeries.d.ts +34 -0
- package/esm/hooks/useRangeBarSeries.js +40 -0
- package/esm/index.d.ts +4 -1
- package/esm/index.js +5 -4
- package/esm/models/index.d.ts +2 -1
- package/esm/models/index.js +3 -1
- package/esm/models/seriesType/index.d.ts +1 -0
- package/esm/models/seriesType/index.js +1 -0
- package/esm/models/seriesType/rangeBar.d.ts +43 -0
- package/esm/models/seriesType/rangeBar.js +1 -0
- package/esm/moduleAugmentation/rangeBarOnClick.d.ts +8 -0
- package/esm/moduleAugmentation/rangeBarOnClick.js +2 -0
- package/esm/typeOverloads/index.d.ts +1 -0
- package/esm/typeOverloads/index.js +1 -0
- package/esm/typeOverloads/modules.d.ts +22 -0
- package/esm/typeOverloads/modules.js +1 -0
- package/hooks/animation/index.d.ts +1 -0
- package/hooks/animation/index.js +16 -0
- package/hooks/animation/useAnimateRangeBar.d.ts +18 -0
- package/hooks/animation/useAnimateRangeBar.js +57 -0
- package/hooks/index.d.ts +3 -1
- package/hooks/index.js +22 -0
- package/hooks/useRangeBarSeries.d.ts +34 -0
- package/hooks/useRangeBarSeries.js +45 -0
- package/index.d.ts +4 -1
- package/index.js +26 -1
- package/models/index.d.ts +2 -1
- package/models/index.js +11 -0
- package/models/seriesType/index.d.ts +1 -0
- package/models/seriesType/index.js +16 -0
- package/models/seriesType/rangeBar.d.ts +43 -0
- package/models/seriesType/rangeBar.js +5 -0
- package/moduleAugmentation/rangeBarOnClick.d.ts +8 -0
- package/moduleAugmentation/rangeBarOnClick.js +8 -0
- package/package.json +16 -6
- package/typeOverloads/index.d.ts +1 -0
- package/typeOverloads/index.js +6 -0
- package/typeOverloads/modules.d.ts +22 -0
- package/typeOverloads/modules.js +5 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { warnOnce } from '@mui/x-internals/warning';
|
|
3
|
+
const rangeBarValueFormatter = v => v == null ? '' : `[${v[0]}, ${v[1]}]`;
|
|
4
|
+
const seriesProcessor = (params, dataset) => {
|
|
5
|
+
const {
|
|
6
|
+
seriesOrder,
|
|
7
|
+
series
|
|
8
|
+
} = params;
|
|
9
|
+
const completedSeries = {};
|
|
10
|
+
for (const id of seriesOrder) {
|
|
11
|
+
const seriesData = series[id];
|
|
12
|
+
const datasetKeys = seriesData?.datasetKeys;
|
|
13
|
+
if (seriesData.data === undefined && dataset === undefined && process.env.NODE_ENV !== 'production') {
|
|
14
|
+
throw new Error([`MUI X Charts: range bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
15
|
+
}
|
|
16
|
+
const missingKeys = ['start', 'end'].filter(key => typeof datasetKeys?.[key] !== 'string');
|
|
17
|
+
if (datasetKeys && missingKeys.length > 0) {
|
|
18
|
+
throw new Error([`MUI X Charts: range bar series with id='${id}' has incomplete datasetKeys.`, `Properties ${missingKeys.map(key => `"${key}"`).join(', ')} are missing.`].join('\n'));
|
|
19
|
+
}
|
|
20
|
+
completedSeries[id] = _extends({
|
|
21
|
+
layout: 'vertical'
|
|
22
|
+
}, series[id], {
|
|
23
|
+
valueFormatter: series[id].valueFormatter ?? rangeBarValueFormatter,
|
|
24
|
+
data: datasetKeys ? dataset.map(data => {
|
|
25
|
+
const start = data[datasetKeys.start];
|
|
26
|
+
const end = data[datasetKeys.end];
|
|
27
|
+
if (typeof start !== 'number' || typeof end !== 'number') {
|
|
28
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
29
|
+
if (start !== null) {
|
|
30
|
+
warnOnce([`MUI X Charts: Your dataset key "start" is used for plotting an range bar, but contains nonnumerical elements.`, 'Range bars only support numbers.']);
|
|
31
|
+
}
|
|
32
|
+
if (end !== null) {
|
|
33
|
+
warnOnce([`MUI X Charts: Your dataset key "end" is used for plotting an range bar, but contains nonnumerical elements.`, 'Range bars only support numbers.']);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return [start, end];
|
|
39
|
+
}) : series[id].data
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
seriesOrder,
|
|
44
|
+
series: completedSeries
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export default seriesProcessor;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getLabel } from '@mui/x-charts/internals';
|
|
2
|
+
const tooltipGetter = params => {
|
|
3
|
+
const {
|
|
4
|
+
series,
|
|
5
|
+
getColor,
|
|
6
|
+
identifier
|
|
7
|
+
} = params;
|
|
8
|
+
if (!identifier || identifier.dataIndex === undefined) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const label = getLabel(series.label, 'tooltip');
|
|
12
|
+
const value = series.data[identifier.dataIndex];
|
|
13
|
+
if (value == null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const formattedValue = series.valueFormatter(value, {
|
|
17
|
+
dataIndex: identifier.dataIndex
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
identifier,
|
|
21
|
+
color: getColor(identifier.dataIndex),
|
|
22
|
+
label,
|
|
23
|
+
value,
|
|
24
|
+
formattedValue,
|
|
25
|
+
markType: series.labelMarkType
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export const axisTooltipGetter = series => {
|
|
29
|
+
return Object.values(series).map(s => s.layout === 'horizontal' ? {
|
|
30
|
+
direction: 'y',
|
|
31
|
+
axisId: s.yAxisId
|
|
32
|
+
} : {
|
|
33
|
+
direction: 'x',
|
|
34
|
+
axisId: s.xAxisId
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
export default tooltipGetter;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { getRangeBarDimensions } from "../useRangeBarPlotData.js";
|
|
2
|
+
const tooltipItemPositionGetter = params => {
|
|
3
|
+
const {
|
|
4
|
+
series,
|
|
5
|
+
identifier,
|
|
6
|
+
axesConfig,
|
|
7
|
+
placement
|
|
8
|
+
} = params;
|
|
9
|
+
if (!identifier || identifier.dataIndex === undefined) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const itemSeries = series.rangeBar?.series[identifier.seriesId];
|
|
13
|
+
if (series.rangeBar == null || itemSeries == null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (axesConfig.x === undefined || axesConfig.y === undefined) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const dimensions = getRangeBarDimensions(itemSeries.layout, axesConfig.x, axesConfig.y, itemSeries.data, identifier.dataIndex, series.rangeBar.seriesOrder.length, series.rangeBar.seriesOrder.findIndex(id => id === itemSeries.id));
|
|
20
|
+
if (dimensions == null) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const {
|
|
24
|
+
x,
|
|
25
|
+
y,
|
|
26
|
+
width,
|
|
27
|
+
height
|
|
28
|
+
} = dimensions;
|
|
29
|
+
switch (placement) {
|
|
30
|
+
case 'right':
|
|
31
|
+
return {
|
|
32
|
+
x: x + width,
|
|
33
|
+
y: y + height / 2
|
|
34
|
+
};
|
|
35
|
+
case 'bottom':
|
|
36
|
+
return {
|
|
37
|
+
x: x + width / 2,
|
|
38
|
+
y: y + height
|
|
39
|
+
};
|
|
40
|
+
case 'left':
|
|
41
|
+
return {
|
|
42
|
+
x,
|
|
43
|
+
y: y + height / 2
|
|
44
|
+
};
|
|
45
|
+
case 'top':
|
|
46
|
+
default:
|
|
47
|
+
return {
|
|
48
|
+
x: x + width / 2,
|
|
49
|
+
y
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export default tooltipItemPositionGetter;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SeriesId } from '@mui/x-charts/models';
|
|
2
|
+
import type { BarSeriesType } from '@mui/x-charts-pro/models';
|
|
3
|
+
import type { RangeBarValueType } from "../../models/index.js";
|
|
4
|
+
export interface LayoutData {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ProcessedRangeBarSeriesData {
|
|
11
|
+
seriesId: SeriesId;
|
|
12
|
+
data: ProcessedRangeBarData[];
|
|
13
|
+
layout: BarSeriesType['layout'];
|
|
14
|
+
yOrigin: number;
|
|
15
|
+
xOrigin: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ProcessedRangeBarData extends LayoutData {
|
|
18
|
+
seriesId: SeriesId;
|
|
19
|
+
dataIndex: number;
|
|
20
|
+
color: string;
|
|
21
|
+
value: RangeBarValueType | null;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ChartDrawingArea } from '@mui/x-charts/hooks';
|
|
2
|
+
import { type ComputedAxis, type ComputedAxisConfig, type ScaleName } from '@mui/x-charts/internals';
|
|
3
|
+
import { type ChartsXAxisProps, type ChartsYAxisProps } from '@mui/x-charts/models';
|
|
4
|
+
import { type DefaultizedRangeBarSeriesType } from "../../models/seriesType/rangeBar.js";
|
|
5
|
+
import { type ProcessedRangeBarSeriesData } from "./types.js";
|
|
6
|
+
export declare function useRangeBarPlotData(drawingArea: ChartDrawingArea, xAxes: ComputedAxisConfig<ChartsXAxisProps>, yAxes: ComputedAxisConfig<ChartsYAxisProps>): ProcessedRangeBarSeriesData[];
|
|
7
|
+
export declare function getRangeBarDimensions(layout: 'vertical' | 'horizontal', xAxis: ComputedAxis<ScaleName, any, ChartsXAxisProps>, yAxis: ComputedAxis<ScaleName, any, ChartsYAxisProps>, seriesData: DefaultizedRangeBarSeriesType['data'], dataIndex: number, seriesCount: number, seriesIndex: number): {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
height: number;
|
|
11
|
+
width: number;
|
|
12
|
+
} | null;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useXAxes, useYAxes } from '@mui/x-charts/hooks';
|
|
2
|
+
import { checkBarChartScaleErrors, getBandSize, selectorChartSeriesConfig, useStore } from '@mui/x-charts/internals';
|
|
3
|
+
import { useRangeBarSeriesContext } from "../../hooks/useRangeBarSeries.js";
|
|
4
|
+
export function useRangeBarPlotData(drawingArea, xAxes, yAxes) {
|
|
5
|
+
const store = useStore();
|
|
6
|
+
const seriesData = useRangeBarSeriesContext() ?? {
|
|
7
|
+
series: {},
|
|
8
|
+
seriesOrder: []
|
|
9
|
+
};
|
|
10
|
+
const defaultXAxisId = useXAxes().xAxisIds[0];
|
|
11
|
+
const defaultYAxisId = useYAxes().yAxisIds[0];
|
|
12
|
+
const getColor = store.use(selectorChartSeriesConfig).rangeBar.colorProcessor;
|
|
13
|
+
const {
|
|
14
|
+
series,
|
|
15
|
+
seriesOrder
|
|
16
|
+
} = seriesData;
|
|
17
|
+
const xMin = drawingArea.left;
|
|
18
|
+
const xMax = drawingArea.left + drawingArea.width;
|
|
19
|
+
const yMin = drawingArea.top;
|
|
20
|
+
const yMax = drawingArea.top + drawingArea.height;
|
|
21
|
+
const data = seriesOrder.map((seriesId, seriesIndex) => {
|
|
22
|
+
const xAxisId = series[seriesId].xAxisId ?? defaultXAxisId;
|
|
23
|
+
const yAxisId = series[seriesId].yAxisId ?? defaultYAxisId;
|
|
24
|
+
const xAxisConfig = xAxes[xAxisId];
|
|
25
|
+
const yAxisConfig = yAxes[yAxisId];
|
|
26
|
+
const verticalLayout = series[seriesId].layout === 'vertical';
|
|
27
|
+
checkBarChartScaleErrors(verticalLayout, seriesId, series[seriesId].data.length, xAxisId, xAxes, yAxisId, yAxes);
|
|
28
|
+
const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
|
|
29
|
+
const xScale = xAxisConfig.scale;
|
|
30
|
+
const yScale = yAxisConfig.scale;
|
|
31
|
+
const xOrigin = Math.round(xScale(0) ?? 0);
|
|
32
|
+
const yOrigin = Math.round(yScale(0) ?? 0);
|
|
33
|
+
const colorGetter = getColor(series[seriesId], xAxes[xAxisId], yAxes[yAxisId]);
|
|
34
|
+
const bandWidth = baseScaleConfig.scale.bandwidth();
|
|
35
|
+
const {
|
|
36
|
+
barWidth,
|
|
37
|
+
offset
|
|
38
|
+
} = getBandSize(bandWidth, seriesOrder.length, baseScaleConfig.barGapRatio);
|
|
39
|
+
const barOffset = seriesIndex * (barWidth + offset);
|
|
40
|
+
const {
|
|
41
|
+
data: currentSeriesData,
|
|
42
|
+
layout
|
|
43
|
+
} = series[seriesId];
|
|
44
|
+
const seriesDataPoints = [];
|
|
45
|
+
for (let dataIndex = 0; dataIndex < baseScaleConfig.data.length; dataIndex += 1) {
|
|
46
|
+
const baseValue = baseScaleConfig.data[dataIndex];
|
|
47
|
+
const seriesValue = currentSeriesData[dataIndex];
|
|
48
|
+
if (seriesValue == null) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const valueCoordinates = seriesValue.map(v => verticalLayout ? yScale(v) : xScale(v));
|
|
52
|
+
const minValueCoord = Math.round(Math.min(...valueCoordinates));
|
|
53
|
+
const maxValueCoord = Math.round(Math.max(...valueCoordinates));
|
|
54
|
+
const barSize = maxValueCoord - minValueCoord;
|
|
55
|
+
const result = {
|
|
56
|
+
seriesId,
|
|
57
|
+
dataIndex,
|
|
58
|
+
x: verticalLayout ? xScale(baseValue) + barOffset : minValueCoord,
|
|
59
|
+
y: verticalLayout ? minValueCoord : yScale(baseValue) + barOffset,
|
|
60
|
+
height: verticalLayout ? barSize : barWidth,
|
|
61
|
+
width: verticalLayout ? barWidth : barSize,
|
|
62
|
+
color: colorGetter(dataIndex),
|
|
63
|
+
value: currentSeriesData[dataIndex]
|
|
64
|
+
};
|
|
65
|
+
if (result.x > xMax || result.x + result.width < xMin || result.y > yMax || result.y + result.height < yMin) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
seriesDataPoints.push(result);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
seriesId,
|
|
72
|
+
data: seriesDataPoints,
|
|
73
|
+
layout,
|
|
74
|
+
xOrigin,
|
|
75
|
+
yOrigin
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
return data;
|
|
79
|
+
}
|
|
80
|
+
export function getRangeBarDimensions(layout, xAxis, yAxis, seriesData, dataIndex, seriesCount, seriesIndex) {
|
|
81
|
+
const xScale = xAxis.scale;
|
|
82
|
+
const yScale = yAxis.scale;
|
|
83
|
+
const verticalLayout = layout === 'vertical';
|
|
84
|
+
const baseScaleConfig = verticalLayout ? xAxis : yAxis;
|
|
85
|
+
const baseValue = baseScaleConfig.data[dataIndex];
|
|
86
|
+
const seriesValue = seriesData[dataIndex];
|
|
87
|
+
const {
|
|
88
|
+
barWidth,
|
|
89
|
+
offset
|
|
90
|
+
} = getBandSize(baseScaleConfig.scale.bandwidth(), seriesCount, baseScaleConfig.barGapRatio);
|
|
91
|
+
const barOffset = seriesIndex * (barWidth + offset);
|
|
92
|
+
if (seriesValue == null) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
const valueCoordinates = seriesValue.map(v => verticalLayout ? yScale(v) : xScale(v));
|
|
96
|
+
const minValueCoord = Math.round(Math.min(...valueCoordinates));
|
|
97
|
+
const maxValueCoord = Math.round(Math.max(...valueCoordinates));
|
|
98
|
+
const barSize = maxValueCoord - minValueCoord;
|
|
99
|
+
return {
|
|
100
|
+
x: verticalLayout ? xScale(baseValue) + barOffset : minValueCoord,
|
|
101
|
+
y: verticalLayout ? minValueCoord : yScale(baseValue) + barOffset,
|
|
102
|
+
height: verticalLayout ? barSize : barWidth,
|
|
103
|
+
width: verticalLayout ? barWidth : barSize
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface RangeBarClasses {
|
|
2
|
+
/** Styles applied to the range bar plot element. */
|
|
3
|
+
root: string;
|
|
4
|
+
/** Styles applied to the group surrounding a series' bar elements. */
|
|
5
|
+
series: string;
|
|
6
|
+
/** Styles applied to the group surrounding a series' labels. */
|
|
7
|
+
seriesLabels: string;
|
|
8
|
+
}
|
|
9
|
+
export type RangeBarClassKey = keyof RangeBarClasses;
|
|
10
|
+
export declare function getRangeBarUtilityClass(slot: string): string;
|
|
11
|
+
export declare const rangeBarClasses: RangeBarClasses;
|
|
12
|
+
export declare const useUtilityClasses: (classes?: Partial<RangeBarClasses>) => Record<"series" | "root" | "seriesLabels", string>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
2
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
3
|
+
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
4
|
+
export function getRangeBarUtilityClass(slot) {
|
|
5
|
+
return generateUtilityClass('MuiRangeBar', slot);
|
|
6
|
+
}
|
|
7
|
+
export const rangeBarClasses = generateUtilityClasses('MuiRangeBar', ['root', 'series', 'seriesLabels']);
|
|
8
|
+
export const useUtilityClasses = classes => {
|
|
9
|
+
const slots = {
|
|
10
|
+
root: ['root'],
|
|
11
|
+
series: ['series'],
|
|
12
|
+
seriesLabels: ['seriesLabels']
|
|
13
|
+
};
|
|
14
|
+
return composeClasses(slots, getRangeBarUtilityClass, classes);
|
|
15
|
+
};
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export * from "./BarChartPremium.js";
|
|
2
|
-
export * from "./BarChartPremium.plugins.js";
|
|
2
|
+
export * from "./BarChartPremium.plugins.js";
|
|
3
|
+
export * from "./RangeBar/RangeBarPlot.js";
|
|
4
|
+
export { rangeBarClasses, type RangeBarClasses, type RangeBarClassKey } from "./RangeBar/useUtilityClasses.js";
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { type BarChartPluginSignatures } from '@mui/x-charts/BarChart';
|
|
2
|
+
import { type ChartContainerProps } from '@mui/x-charts/ChartContainer';
|
|
1
3
|
import { type BarChartPremiumProps } from "./BarChartPremium.js";
|
|
4
|
+
import { type RangeBarPlotProps } from "./RangeBar/RangeBarPlot.js";
|
|
2
5
|
/**
|
|
3
6
|
* A helper function that extracts BarChartPremiumProps from the input props
|
|
4
7
|
* and returns an object with props for the children components of BarChartPremium.
|
|
@@ -7,8 +10,9 @@ import { type BarChartPremiumProps } from "./BarChartPremium.js";
|
|
|
7
10
|
* @returns An object with props for the children components of BarChartPremium
|
|
8
11
|
*/
|
|
9
12
|
export declare function useBarChartPremiumProps(props: BarChartPremiumProps): {
|
|
13
|
+
chartContainerProps: ChartContainerProps<"bar" | "rangeBar", BarChartPluginSignatures>;
|
|
14
|
+
rangeBarPlotProps: RangeBarPlotProps;
|
|
10
15
|
chartsWrapperProps: Omit<import("@mui/x-charts").ChartsWrapperProps, "children">;
|
|
11
|
-
chartContainerProps: import("@mui/x-charts").ChartContainerProps<"bar", import("@mui/x-charts").BarChartPluginSignatures>;
|
|
12
16
|
barPlotProps: import("@mui/x-charts").BarPlotProps;
|
|
13
17
|
gridProps: import("@mui/x-charts").ChartsGridProps;
|
|
14
18
|
clipPathProps: import("@mui/x-charts").ChartsClipPathProps;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["chartContainerProps"];
|
|
1
4
|
import { useBarChartProps } from '@mui/x-charts/internals';
|
|
2
5
|
/**
|
|
3
6
|
* A helper function that extracts BarChartPremiumProps from the input props
|
|
@@ -7,5 +10,19 @@ import { useBarChartProps } from '@mui/x-charts/internals';
|
|
|
7
10
|
* @returns An object with props for the children components of BarChartPremium
|
|
8
11
|
*/
|
|
9
12
|
export function useBarChartPremiumProps(props) {
|
|
10
|
-
|
|
13
|
+
const _useBarChartProps = useBarChartProps(props),
|
|
14
|
+
{
|
|
15
|
+
chartContainerProps
|
|
16
|
+
} = _useBarChartProps,
|
|
17
|
+
barChartProps = _objectWithoutPropertiesLoose(_useBarChartProps, _excluded);
|
|
18
|
+
const rangeBarPlotProps = {
|
|
19
|
+
onItemClick: props.onItemClick,
|
|
20
|
+
slots: props.slots,
|
|
21
|
+
slotProps: props.slotProps,
|
|
22
|
+
borderRadius: props.borderRadius
|
|
23
|
+
};
|
|
24
|
+
return _extends({}, barChartProps, {
|
|
25
|
+
chartContainerProps: chartContainerProps,
|
|
26
|
+
rangeBarPlotProps
|
|
27
|
+
});
|
|
11
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type ChartSeriesType, type ChartAnyPluginSignature, type ChartProviderProps } from '@mui/x-charts/internals';
|
|
2
|
-
import { type ChartDataProviderProProps } from '@mui/x-charts-pro/ChartDataProviderPro';
|
|
1
|
+
import { type ChartSeriesType, type ChartAnyPluginSignature, type ChartProviderProps, type ChartSeriesConfig } from '@mui/x-charts/internals';
|
|
3
2
|
import { type ChartsSlotPropsPro, type ChartsSlotsPro } from '@mui/x-charts-pro/internals';
|
|
3
|
+
import { type ChartDataProviderProProps } from '@mui/x-charts-pro/ChartDataProviderPro';
|
|
4
4
|
import { type AllPluginSignatures } from "../internals/plugins/allPlugins.js";
|
|
5
5
|
export type ChartDataProviderPremiumProps<TSeries extends ChartSeriesType = ChartSeriesType, TSignatures extends readonly ChartAnyPluginSignature[] = AllPluginSignatures<TSeries>> = ChartDataProviderProProps<TSeries, TSignatures> & ChartProviderProps<TSeries, TSignatures>['pluginParams'] & {
|
|
6
6
|
/**
|
|
@@ -12,6 +12,7 @@ export type ChartDataProviderPremiumProps<TSeries extends ChartSeriesType = Char
|
|
|
12
12
|
*/
|
|
13
13
|
slotProps?: Partial<ChartsSlotPropsPro>;
|
|
14
14
|
};
|
|
15
|
+
export declare const defaultSeriesConfigPremium: ChartSeriesConfig<'bar' | 'rangeBar' | 'scatter' | 'line' | 'pie'>;
|
|
15
16
|
/**
|
|
16
17
|
* Orchestrates the data providers for the chart components and hooks.
|
|
17
18
|
*
|
|
@@ -6,11 +6,17 @@ import { Watermark } from '@mui/x-license/Watermark';
|
|
|
6
6
|
import { ChartProvider, ChartsSlotsProvider, defaultSlotsMaterial } from '@mui/x-charts/internals';
|
|
7
7
|
import { ChartsLocalizationProvider } from '@mui/x-charts/ChartsLocalizationProvider';
|
|
8
8
|
import { useLicenseVerifier } from '@mui/x-license/useLicenseVerifier';
|
|
9
|
+
import { defaultSeriesConfigPro } from '@mui/x-charts-pro/internals';
|
|
10
|
+
import { rangeBarSeriesConfig } from "../BarChartPremium/RangeBar/seriesConfig/index.js";
|
|
9
11
|
import { DEFAULT_PLUGINS } from "../internals/plugins/allPlugins.js";
|
|
10
12
|
import { useChartDataProviderPremiumProps } from "./useChartDataProviderPremiumProps.js";
|
|
11
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
-
const releaseInfo = "
|
|
14
|
+
const releaseInfo = "MTc2NzgzMDQwMDAwMA==";
|
|
13
15
|
const packageIdentifier = 'x-charts-premium';
|
|
16
|
+
export const defaultSeriesConfigPremium = _extends({}, defaultSeriesConfigPro, {
|
|
17
|
+
rangeBar: rangeBarSeriesConfig
|
|
18
|
+
});
|
|
19
|
+
|
|
14
20
|
/**
|
|
15
21
|
* Orchestrates the data providers for the chart components and hooks.
|
|
16
22
|
*
|
|
@@ -46,6 +52,7 @@ function ChartDataProviderPremium(props) {
|
|
|
46
52
|
slots,
|
|
47
53
|
slotProps
|
|
48
54
|
} = useChartDataProviderPremiumProps(_extends({}, props, {
|
|
55
|
+
seriesConfig: props.seriesConfig ?? defaultSeriesConfigPremium,
|
|
49
56
|
plugins: props.plugins ?? DEFAULT_PLUGINS
|
|
50
57
|
}));
|
|
51
58
|
useLicenseVerifier(packageIdentifier, releaseInfo);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { ChartDataProviderPremium, type ChartDataProviderPremiumProps } from "./ChartDataProviderPremium.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { ChartDataProviderPremium } from "./ChartDataProviderPremium.js";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { selectorChartPreviewComputedXAxis, selectorChartPreviewComputedYAxis, useStore } from '@mui/x-charts/internals';
|
|
2
|
+
import { BarElement } from '@mui/x-charts/BarChart';
|
|
3
|
+
import { useRangeBarPlotData } from "../../../BarChartPremium/RangeBar/useRangeBarPlotData.js";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
export function RangeBarPreviewPlot(props) {
|
|
6
|
+
const drawingArea = {
|
|
7
|
+
left: props.x,
|
|
8
|
+
top: props.y,
|
|
9
|
+
width: props.width,
|
|
10
|
+
height: props.height,
|
|
11
|
+
right: props.x + props.width,
|
|
12
|
+
bottom: props.y + props.height
|
|
13
|
+
};
|
|
14
|
+
const completedData = useBarPreviewData(props.axisId, drawingArea);
|
|
15
|
+
return /*#__PURE__*/_jsx("g", {
|
|
16
|
+
children: completedData.map(({
|
|
17
|
+
seriesId,
|
|
18
|
+
layout,
|
|
19
|
+
xOrigin,
|
|
20
|
+
yOrigin,
|
|
21
|
+
data
|
|
22
|
+
}) => /*#__PURE__*/_jsx("g", {
|
|
23
|
+
children: data.map(({
|
|
24
|
+
dataIndex,
|
|
25
|
+
color,
|
|
26
|
+
x,
|
|
27
|
+
y,
|
|
28
|
+
width,
|
|
29
|
+
height
|
|
30
|
+
}) => {
|
|
31
|
+
return /*#__PURE__*/_jsx(BarElement, {
|
|
32
|
+
id: seriesId,
|
|
33
|
+
dataIndex: dataIndex,
|
|
34
|
+
color: color,
|
|
35
|
+
skipAnimation: true,
|
|
36
|
+
layout: layout ?? 'vertical',
|
|
37
|
+
x: x,
|
|
38
|
+
xOrigin: xOrigin,
|
|
39
|
+
y: y,
|
|
40
|
+
yOrigin: yOrigin,
|
|
41
|
+
width: width,
|
|
42
|
+
height: height
|
|
43
|
+
}, dataIndex);
|
|
44
|
+
})
|
|
45
|
+
}, seriesId))
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function useBarPreviewData(axisId, drawingArea) {
|
|
49
|
+
const store = useStore();
|
|
50
|
+
const xAxes = store.use(selectorChartPreviewComputedXAxis, axisId);
|
|
51
|
+
const yAxes = store.use(selectorChartPreviewComputedYAxis, axisId);
|
|
52
|
+
return useRangeBarPlotData(drawingArea, xAxes, yAxes);
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useAnimateRangeBar.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./useAnimateRangeBar.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type AnimatedRangeBarElementProps } from "../../BarChartPremium/RangeBar/AnimatedRangeBarElement.js";
|
|
3
|
+
type UseAnimateRangeBarParams = Pick<AnimatedRangeBarElementProps, 'x' | 'y' | 'xOrigin' | 'yOrigin' | 'width' | 'height' | 'skipAnimation' | 'layout'> & {
|
|
4
|
+
ref?: React.Ref<SVGRectElement>;
|
|
5
|
+
};
|
|
6
|
+
type UseAnimateRangeBarReturnValue = {
|
|
7
|
+
ref: React.Ref<SVGRectElement>;
|
|
8
|
+
} & Pick<AnimatedRangeBarElementProps, 'x' | 'y' | 'width' | 'height'>;
|
|
9
|
+
/**
|
|
10
|
+
* Animates a range bar from its center outwards.
|
|
11
|
+
* The animation only happens in the direction of the numerical axis (x-axis for vertical layout, y-axis for horizontal layout).
|
|
12
|
+
* The other direction remains constant during the animation.
|
|
13
|
+
*
|
|
14
|
+
* The props object also accepts a `ref` which will be merged with the ref returned from this hook. This means you can
|
|
15
|
+
* pass the ref returned by this hook to the `path` element and the `ref` provided as argument will also be called.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useAnimateRangeBar(props: UseAnimateRangeBarParams): UseAnimateRangeBarReturnValue;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { interpolateNumber } from '@mui/x-charts-vendor/d3-interpolate';
|
|
2
|
+
import { useAnimate } from '@mui/x-charts/hooks';
|
|
3
|
+
function rangeBarPropsInterpolator(from, to) {
|
|
4
|
+
const interpolateX = interpolateNumber(from.x, to.x);
|
|
5
|
+
const interpolateY = interpolateNumber(from.y, to.y);
|
|
6
|
+
const interpolateWidth = interpolateNumber(from.width, to.width);
|
|
7
|
+
const interpolateHeight = interpolateNumber(from.height, to.height);
|
|
8
|
+
return t => {
|
|
9
|
+
return {
|
|
10
|
+
x: interpolateX(t),
|
|
11
|
+
y: interpolateY(t),
|
|
12
|
+
width: interpolateWidth(t),
|
|
13
|
+
height: interpolateHeight(t)
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Animates a range bar from its center outwards.
|
|
20
|
+
* The animation only happens in the direction of the numerical axis (x-axis for vertical layout, y-axis for horizontal layout).
|
|
21
|
+
* The other direction remains constant during the animation.
|
|
22
|
+
*
|
|
23
|
+
* The props object also accepts a `ref` which will be merged with the ref returned from this hook. This means you can
|
|
24
|
+
* pass the ref returned by this hook to the `path` element and the `ref` provided as argument will also be called.
|
|
25
|
+
*/
|
|
26
|
+
export function useAnimateRangeBar(props) {
|
|
27
|
+
const initialProps = {
|
|
28
|
+
x: props.layout === 'vertical' ? props.x : props.x + props.width / 2,
|
|
29
|
+
y: props.layout === 'vertical' ? props.y + props.height / 2 : props.y,
|
|
30
|
+
width: props.layout === 'vertical' ? props.width : 0,
|
|
31
|
+
height: props.layout === 'vertical' ? 0 : props.height
|
|
32
|
+
};
|
|
33
|
+
return useAnimate({
|
|
34
|
+
x: props.x,
|
|
35
|
+
y: props.y,
|
|
36
|
+
width: props.width,
|
|
37
|
+
height: props.height
|
|
38
|
+
}, {
|
|
39
|
+
createInterpolator: rangeBarPropsInterpolator,
|
|
40
|
+
applyProps(element, animatedProps) {
|
|
41
|
+
element.setAttribute('x', animatedProps.x.toString());
|
|
42
|
+
element.setAttribute('y', animatedProps.y.toString());
|
|
43
|
+
element.setAttribute('width', animatedProps.width.toString());
|
|
44
|
+
element.setAttribute('height', animatedProps.height.toString());
|
|
45
|
+
},
|
|
46
|
+
transformProps: p => p,
|
|
47
|
+
initialProps,
|
|
48
|
+
skip: props.skipAnimation,
|
|
49
|
+
ref: props.ref
|
|
50
|
+
});
|
|
51
|
+
}
|
package/esm/hooks/index.d.ts
CHANGED
package/esm/hooks/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
// This re-export-block is automatically generated, to customize, simply remove the block.
|
|
2
2
|
export * from '@mui/x-charts-pro/hooks';
|
|
3
|
-
// End of re-export-block
|
|
3
|
+
// End of re-export-block
|
|
4
|
+
|
|
5
|
+
export * from "./animation/index.js";
|
|
6
|
+
export * from "./useRangeBarSeries.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ChartSeriesDefaultized, type ProcessedSeries } from '@mui/x-charts/internals';
|
|
2
|
+
import { type SeriesId } from '@mui/x-charts/models';
|
|
3
|
+
export type UseRangeBarSeriesReturnValue = ChartSeriesDefaultized<'rangeBar'>;
|
|
4
|
+
export type UseRangeBarSeriesContextReturnValue = ProcessedSeries['rangeBar'];
|
|
5
|
+
/**
|
|
6
|
+
* Get access to the internal state of range bar series.
|
|
7
|
+
*
|
|
8
|
+
* @param {SeriesId} seriesId The id of the series to get.
|
|
9
|
+
* @returns {UseRangeBarSeriesReturnValue} the range bar series
|
|
10
|
+
*/
|
|
11
|
+
export declare function useRangeBarSeries(seriesId: SeriesId): UseRangeBarSeriesReturnValue | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Get access to the internal state of range bar series.
|
|
14
|
+
*
|
|
15
|
+
* When called without arguments, it returns all range bar series.
|
|
16
|
+
*
|
|
17
|
+
* @returns {UseRangeBarSeriesReturnValue[]} the range bar series
|
|
18
|
+
*/
|
|
19
|
+
export declare function useRangeBarSeries(): UseRangeBarSeriesReturnValue[];
|
|
20
|
+
/**
|
|
21
|
+
* Get access to the internal state of range bar series.
|
|
22
|
+
*
|
|
23
|
+
* @param {SeriesId[]} seriesIds The ids of the series to get. Order is preserved.
|
|
24
|
+
* @returns {UseRangeBarSeriesReturnValue[]} the range bar series
|
|
25
|
+
*/
|
|
26
|
+
export declare function useRangeBarSeries(seriesIds: SeriesId[]): UseRangeBarSeriesReturnValue[];
|
|
27
|
+
/**
|
|
28
|
+
* Get access to the internal state of range bar series.
|
|
29
|
+
* The returned object contains:
|
|
30
|
+
* - series: a mapping from ids to series attributes.
|
|
31
|
+
* - seriesOrder: the array of series ids.
|
|
32
|
+
* @returns the range bar series
|
|
33
|
+
*/
|
|
34
|
+
export declare function useRangeBarSeriesContext(): UseRangeBarSeriesContextReturnValue;
|