147 lines
4.1 KiB
JavaScript
147 lines
4.1 KiB
JavaScript
"use strict";
|
|
'use client';
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.useLineChartProps = void 0;
|
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
var React = _interopRequireWildcard(require("react"));
|
|
var _useId = _interopRequireDefault(require("@mui/utils/useId"));
|
|
var _constants = require("../constants");
|
|
var _LineChart = require("./LineChart.plugins");
|
|
const _excluded = ["xAxis", "yAxis", "series", "width", "height", "margin", "colors", "dataset", "sx", "onAreaClick", "onLineClick", "onMarkClick", "axisHighlight", "disableLineItemHighlight", "hideLegend", "grid", "children", "slots", "slotProps", "skipAnimation", "loading", "highlightedItem", "onHighlightChange", "className", "showToolbar"];
|
|
/**
|
|
* A helper function that extracts LineChartProps from the input props
|
|
* and returns an object with props for the children components of LineChart.
|
|
*
|
|
* @param props The input props for LineChart
|
|
* @returns An object with props for the children components of LineChart
|
|
*/
|
|
const useLineChartProps = props => {
|
|
const {
|
|
xAxis,
|
|
yAxis,
|
|
series,
|
|
width,
|
|
height,
|
|
margin,
|
|
colors,
|
|
dataset,
|
|
sx,
|
|
onAreaClick,
|
|
onLineClick,
|
|
onMarkClick,
|
|
axisHighlight,
|
|
disableLineItemHighlight,
|
|
grid,
|
|
children,
|
|
slots,
|
|
slotProps,
|
|
skipAnimation,
|
|
loading,
|
|
highlightedItem,
|
|
onHighlightChange,
|
|
className
|
|
} = props,
|
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
const id = (0, _useId.default)();
|
|
const clipPathId = `${id}-clip-path`;
|
|
const seriesWithDefault = React.useMemo(() => series.map(s => (0, _extends2.default)({
|
|
disableHighlight: !!disableLineItemHighlight,
|
|
type: 'line'
|
|
}, s)), [disableLineItemHighlight, series]);
|
|
const chartContainerProps = (0, _extends2.default)({}, other, {
|
|
series: seriesWithDefault,
|
|
width,
|
|
height,
|
|
margin,
|
|
colors,
|
|
dataset,
|
|
xAxis: xAxis ?? [{
|
|
id: _constants.DEFAULT_X_AXIS_KEY,
|
|
scaleType: 'point',
|
|
data: Array.from({
|
|
length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
|
|
}, (_, index) => index)
|
|
}],
|
|
yAxis,
|
|
highlightedItem,
|
|
onHighlightChange,
|
|
disableAxisListener: slotProps?.tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
className,
|
|
skipAnimation,
|
|
plugins: _LineChart.LINE_CHART_PLUGINS
|
|
});
|
|
const gridProps = {
|
|
vertical: grid?.vertical,
|
|
horizontal: grid?.horizontal
|
|
};
|
|
const clipPathGroupProps = {
|
|
clipPath: `url(#${clipPathId})`
|
|
};
|
|
const clipPathProps = {
|
|
id: clipPathId
|
|
};
|
|
const areaPlotProps = {
|
|
slots,
|
|
slotProps,
|
|
onItemClick: onAreaClick
|
|
};
|
|
const linePlotProps = {
|
|
slots,
|
|
slotProps,
|
|
onItemClick: onLineClick
|
|
};
|
|
const markPlotProps = {
|
|
slots,
|
|
slotProps,
|
|
onItemClick: onMarkClick,
|
|
skipAnimation
|
|
};
|
|
const overlayProps = {
|
|
slots,
|
|
slotProps,
|
|
loading
|
|
};
|
|
const chartsAxisProps = {
|
|
slots,
|
|
slotProps
|
|
};
|
|
const axisHighlightProps = (0, _extends2.default)({
|
|
x: 'line'
|
|
}, axisHighlight);
|
|
const lineHighlightPlotProps = {
|
|
slots,
|
|
slotProps
|
|
};
|
|
const legendProps = {
|
|
slots,
|
|
slotProps
|
|
};
|
|
const chartsWrapperProps = {
|
|
sx,
|
|
legendPosition: props.slotProps?.legend?.position,
|
|
legendDirection: props.slotProps?.legend?.direction
|
|
};
|
|
return {
|
|
chartsWrapperProps,
|
|
chartContainerProps,
|
|
gridProps,
|
|
clipPathProps,
|
|
clipPathGroupProps,
|
|
areaPlotProps,
|
|
linePlotProps,
|
|
markPlotProps,
|
|
overlayProps,
|
|
chartsAxisProps,
|
|
axisHighlightProps,
|
|
lineHighlightPlotProps,
|
|
legendProps,
|
|
children
|
|
};
|
|
};
|
|
exports.useLineChartProps = useLineChartProps; |