@mui/x-charts
Version:
The community edition of MUI X Charts components.
96 lines (93 loc) • 6.31 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.selectorChartsHighlightYAxisValue = exports.selectorChartsHighlightYAxisIndex = exports.selectorChartsHighlightYAxis = exports.selectorChartsHighlightXAxisValue = exports.selectorChartsHighlightXAxisIndex = exports.selectorChartsHighlightXAxis = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _store = require("@mui/x-internals/store");
var _useChartCartesianAxisRendering = require("./useChartCartesianAxisRendering.selectors");
var _useChartCartesianInteraction = require("./useChartCartesianInteraction.selectors");
var _useChartKeyboardNavigation = require("../useChartKeyboardNavigation/useChartKeyboardNavigation.selectors");
var _useChartInteraction = require("../useChartInteraction/useChartInteraction.selectors");
var _useChartBrush = require("../useChartBrush");
/**
* The return type of the `selectAxisHighlightWithValue`.
*/
function getAxisHighlight(lastInteractionUpdate, pointerHighlight, keyboardHighlight) {
if (lastInteractionUpdate === 'pointer') {
if (pointerHighlight) {
return [pointerHighlight];
}
if (keyboardHighlight) {
return [keyboardHighlight];
}
}
if (lastInteractionUpdate === 'keyboard') {
if (keyboardHighlight) {
return [keyboardHighlight];
}
if (pointerHighlight) {
return [pointerHighlight];
}
}
return [];
}
const selectorChartControlledCartesianAxisHighlight = state => state.controlledCartesianAxisHighlight;
const selectAxisHighlight = (computedIndex, axis, controlledAxisItems, keyboardAxisItem, lastInteractionUpdate, isBrushSelectionActive) => {
if (isBrushSelectionActive) {
return [];
}
if (controlledAxisItems !== undefined) {
return controlledAxisItems.filter(item => axis.axis[item.axisId] !== undefined).map(item => item);
}
const pointerHighlight = computedIndex !== null && {
axisId: axis.axisIds[0],
dataIndex: computedIndex
};
const keyboardHighlight = keyboardAxisItem != null && keyboardAxisItem;
return getAxisHighlight(lastInteractionUpdate, pointerHighlight, keyboardHighlight);
};
const selectorChartsHighlightXAxisIndex = exports.selectorChartsHighlightXAxisIndex = (0, _store.createSelectorMemoized)(_useChartCartesianInteraction.selectorChartsInteractionXAxisIndex, _useChartCartesianAxisRendering.selectorChartXAxis, selectorChartControlledCartesianAxisHighlight, _useChartKeyboardNavigation.selectorChartsKeyboardXAxisIndex, _useChartInteraction.selectorChartsLastInteraction, _useChartBrush.selectorBrushShouldPreventAxisHighlight, selectAxisHighlight);
const selectorChartsHighlightYAxisIndex = exports.selectorChartsHighlightYAxisIndex = (0, _store.createSelectorMemoized)(_useChartCartesianInteraction.selectorChartsInteractionYAxisIndex, _useChartCartesianAxisRendering.selectorChartYAxis, selectorChartControlledCartesianAxisHighlight, _useChartKeyboardNavigation.selectorChartsKeyboardYAxisIndex, _useChartInteraction.selectorChartsLastInteraction, _useChartBrush.selectorBrushShouldPreventAxisHighlight, selectAxisHighlight);
const selectAxisHighlightWithValue = (computedIndex, computedValue, axis, controlledAxisItems, keyboardAxisItem, lastInteractionUpdate, isBrushSelectionActive) => {
if (isBrushSelectionActive) {
return [];
}
if (controlledAxisItems !== undefined) {
return controlledAxisItems.map(item => (0, _extends2.default)({}, item, {
value: axis.axis[item.axisId]?.data?.[item.dataIndex]
})).filter(({
value
}) => value !== undefined);
}
const pointerHighlight = computedValue != null && {
axisId: axis.axisIds[0],
value: computedValue
};
if (pointerHighlight && computedIndex != null) {
pointerHighlight.dataIndex = computedIndex;
}
const keyboardValue = keyboardAxisItem != null && axis.axis[keyboardAxisItem.axisId]?.data?.[keyboardAxisItem.dataIndex];
const keyboardHighlight = keyboardAxisItem != null && keyboardValue != null && (0, _extends2.default)({}, keyboardAxisItem, {
value: keyboardValue
});
return getAxisHighlight(lastInteractionUpdate, pointerHighlight, keyboardHighlight);
};
const selectorChartsHighlightXAxisValue = exports.selectorChartsHighlightXAxisValue = (0, _store.createSelectorMemoized)(_useChartCartesianInteraction.selectorChartsInteractionXAxisIndex, _useChartCartesianInteraction.selectorChartsInteractionXAxisValue, _useChartCartesianAxisRendering.selectorChartXAxis, selectorChartControlledCartesianAxisHighlight, _useChartKeyboardNavigation.selectorChartsKeyboardXAxisIndex, _useChartInteraction.selectorChartsLastInteraction, _useChartBrush.selectorBrushShouldPreventAxisHighlight, selectAxisHighlightWithValue);
const selectorChartsHighlightYAxisValue = exports.selectorChartsHighlightYAxisValue = (0, _store.createSelectorMemoized)(_useChartCartesianInteraction.selectorChartsInteractionYAxisIndex, _useChartCartesianInteraction.selectorChartsInteractionYAxisValue, _useChartCartesianAxisRendering.selectorChartYAxis, selectorChartControlledCartesianAxisHighlight, _useChartKeyboardNavigation.selectorChartsKeyboardYAxisIndex, _useChartInteraction.selectorChartsLastInteraction, _useChartBrush.selectorBrushShouldPreventAxisHighlight, selectAxisHighlightWithValue);
/**
* Get the scale of the axis with highlight if controlled. The default axis otherwise.
* @param controlledItem The controlled value of highlightedAxis
* @param axis The axis state after all the processing
* @returns axis state
*/
const selectAxis = (axisItems, axis) => {
if (axisItems === undefined) {
return [axis.axis[axis.axisIds[0]]];
}
const filteredAxes = axisItems.map(item => axis.axis[item.axisId] ?? null).filter(item => item !== null);
return filteredAxes;
};
const selectorChartsHighlightXAxis = exports.selectorChartsHighlightXAxis = (0, _store.createSelector)(selectorChartControlledCartesianAxisHighlight, _useChartCartesianAxisRendering.selectorChartXAxis, selectAxis);
const selectorChartsHighlightYAxis = exports.selectorChartsHighlightYAxis = (0, _store.createSelector)(selectorChartControlledCartesianAxisHighlight, _useChartCartesianAxisRendering.selectorChartYAxis, selectAxis);