UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

57 lines (53 loc) 3.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectorChartsInteractionYAxisValue = exports.selectorChartsInteractionYAxisIndex = exports.selectorChartsInteractionXAxisValue = exports.selectorChartsInteractionXAxisIndex = exports.selectorChartAxisInteraction = exports.selectChartsInteractionAxisIndex = void 0; var _store = require("@mui/x-internals/store"); var _useChartInteraction = require("../useChartInteraction/useChartInteraction.selectors"); var _getAxisValue = require("./getAxisValue"); var _useChartCartesianAxisRendering = require("./useChartCartesianAxisRendering.selectors"); /** * Get interaction indexes */ function indexGetter(value, axes, ids = axes.axisIds[0]) { return Array.isArray(ids) ? ids.map(id => (0, _getAxisValue.getAxisIndex)(axes.axis[id], value)) : (0, _getAxisValue.getAxisIndex)(axes.axis[ids], value); } const selectChartsInteractionAxisIndex = (value, axes, id) => { if (value === null) { return null; } const index = indexGetter(value, axes, id); return index === -1 ? null : index; }; exports.selectChartsInteractionAxisIndex = selectChartsInteractionAxisIndex; const selectorChartsInteractionXAxisIndex = exports.selectorChartsInteractionXAxisIndex = (0, _store.createSelector)(_useChartInteraction.selectorChartsInteractionPointerX, _useChartCartesianAxisRendering.selectorChartXAxis, selectChartsInteractionAxisIndex); const selectorChartsInteractionYAxisIndex = exports.selectorChartsInteractionYAxisIndex = (0, _store.createSelector)(_useChartInteraction.selectorChartsInteractionPointerY, _useChartCartesianAxisRendering.selectorChartYAxis, selectChartsInteractionAxisIndex); const selectorChartAxisInteraction = exports.selectorChartAxisInteraction = (0, _store.createSelector)(_useChartInteraction.selectorChartsInteractionPointerX, _useChartInteraction.selectorChartsInteractionPointerY, _useChartCartesianAxisRendering.selectorChartXAxis, _useChartCartesianAxisRendering.selectorChartYAxis, (x, y, xAxis, yAxis) => [...(x === null ? [] : xAxis.axisIds.map(axisId => ({ axisId, dataIndex: indexGetter(x, xAxis, axisId) }))), ...(y === null ? [] : yAxis.axisIds.map(axisId => ({ axisId, dataIndex: indexGetter(y, yAxis, axisId) })))].filter(item => item.dataIndex !== null && item.dataIndex >= 0)); /** * Get interaction values */ function valueGetter(value, axes, indexes, ids = axes.axisIds[0]) { return Array.isArray(ids) ? ids.map((id, axisIndex) => { const axis = axes.axis[id]; return (0, _getAxisValue.getAxisValue)(axis.scale, axis.data, value, indexes[axisIndex]); }) : (0, _getAxisValue.getAxisValue)(axes.axis[ids].scale, axes.axis[ids].data, value, indexes); } const selectorChartsInteractionXAxisValue = exports.selectorChartsInteractionXAxisValue = (0, _store.createSelector)(_useChartInteraction.selectorChartsInteractionPointerX, _useChartCartesianAxisRendering.selectorChartXAxis, selectorChartsInteractionXAxisIndex, (x, xAxes, xIndex, id) => { if (x === null || xAxes.axisIds.length === 0) { return null; } return valueGetter(x, xAxes, xIndex, id); }); const selectorChartsInteractionYAxisValue = exports.selectorChartsInteractionYAxisValue = (0, _store.createSelector)(_useChartInteraction.selectorChartsInteractionPointerY, _useChartCartesianAxisRendering.selectorChartYAxis, selectorChartsInteractionYAxisIndex, (y, yAxes, yIndex, id) => { if (y === null || yAxes.axisIds.length === 0) { return null; } return valueGetter(y, yAxes, yIndex, id); });