@mui/x-charts
Version:
The community edition of MUI X Charts components.
82 lines (81 loc) • 4.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.selectorIsBrushSelectionActive = exports.selectorIsBrushEnabled = exports.selectorBrushState = exports.selectorBrushStartY = exports.selectorBrushStartX = exports.selectorBrushStart = exports.selectorBrushShouldPreventTooltip = exports.selectorBrushShouldPreventAxisHighlight = exports.selectorBrushCurrentY = exports.selectorBrushCurrentX = exports.selectorBrushCurrent = exports.selectorBrushConfigZoom = exports.selectorBrushConfigNoZoom = exports.selectorBrushConfig = exports.selectorBrush = void 0;
var _store = require("@mui/x-internals/store");
var _useChartCartesianAxisRendering = require("../useChartCartesianAxis/useChartCartesianAxisRendering.selectors");
var _useChartSeries = require("../../corePlugins/useChartSeries");
const selectorBrush = state => state.brush;
exports.selectorBrush = selectorBrush;
const selectorBrushStart = exports.selectorBrushStart = (0, _store.createSelector)(selectorBrush, brush => brush?.start);
const selectorBrushCurrent = exports.selectorBrushCurrent = (0, _store.createSelector)(selectorBrush, brush => brush?.current);
const selectorBrushStartX = exports.selectorBrushStartX = (0, _store.createSelector)(selectorBrush, brush => brush?.start?.x ?? null);
const selectorBrushStartY = exports.selectorBrushStartY = (0, _store.createSelector)(selectorBrush, brush => brush?.start?.y ?? null);
const selectorBrushCurrentX = exports.selectorBrushCurrentX = (0, _store.createSelector)(selectorBrush, brush => brush?.current?.x ?? null);
const selectorBrushCurrentY = exports.selectorBrushCurrentY = (0, _store.createSelector)(selectorBrush, brush => brush?.current?.y ?? null);
const selectorBrushState = exports.selectorBrushState = (0, _store.createSelectorMemoized)(selectorBrushStartX, selectorBrushStartY, selectorBrushCurrentX, selectorBrushCurrentY, (startX, startY, currentX, currentY) => {
if (startX === null || startY === null || currentX === null || currentY === null) {
return null;
}
return {
start: {
x: startX,
y: startY
},
current: {
x: currentX,
y: currentY
}
};
});
const selectorBrushConfigNoZoom = exports.selectorBrushConfigNoZoom = (0, _store.createSelector)(_useChartSeries.selectorChartSeriesProcessed, series => {
let hasHorizontal = false;
let isBothDirections = false;
if (series) {
Object.entries(series).forEach(([seriesType, seriesData]) => {
if (Object.values(seriesData.series).some(s => s.layout === 'horizontal')) {
hasHorizontal = true;
}
if (seriesType === 'scatter' && seriesData.seriesOrder.length > 0) {
isBothDirections = true;
}
});
}
if (isBothDirections) {
return 'xy';
}
if (hasHorizontal) {
return 'y';
}
return 'x';
});
const selectorBrushConfigZoom = exports.selectorBrushConfigZoom = (0, _store.createSelector)(_useChartCartesianAxisRendering.selectorChartZoomOptionsLookup, function selectorBrushConfigZoom(optionsLookup) {
let hasX = false;
let hasY = false;
Object.values(optionsLookup).forEach(options => {
if (options.axisDirection === 'y') {
hasY = true;
}
if (options.axisDirection === 'x') {
hasX = true;
}
});
if (hasX && hasY) {
return 'xy';
}
if (hasY) {
return 'y';
}
if (hasX) {
return 'x';
}
return null;
});
const selectorBrushConfig = exports.selectorBrushConfig = (0, _store.createSelector)(selectorBrushConfigNoZoom, selectorBrushConfigZoom, (configNoZoom, configZoom) => configZoom ?? configNoZoom);
const selectorIsBrushEnabled = exports.selectorIsBrushEnabled = (0, _store.createSelector)(selectorBrush, brush => brush?.enabled || brush?.isZoomBrushEnabled);
const selectorIsBrushSelectionActive = exports.selectorIsBrushSelectionActive = (0, _store.createSelector)(selectorIsBrushEnabled, selectorBrush, (isBrushEnabled, brush) => {
return isBrushEnabled && brush?.start !== null && brush?.current !== null;
});
const selectorBrushShouldPreventAxisHighlight = exports.selectorBrushShouldPreventAxisHighlight = (0, _store.createSelector)(selectorBrush, selectorIsBrushSelectionActive, (brush, isBrushSelectionActive) => isBrushSelectionActive && brush?.preventHighlight);
const selectorBrushShouldPreventTooltip = exports.selectorBrushShouldPreventTooltip = (0, _store.createSelector)(selectorBrush, selectorIsBrushSelectionActive, (brush, isBrushSelectionActive) => isBrushSelectionActive && brush?.preventTooltip);