recharts
Version:
React charts
37 lines (35 loc) • 1.5 kB
JavaScript
import { createSlice } from '@reduxjs/toolkit';
/**
* Chart-level zoom configuration shared across zoom consumers.
*
* The geometric state (the viewport itself) lives in the `zoom` slice; this one holds the
* configuration registered by the chart's zoom setup (`<ZoomAndPan />` or the `zoom` prop), so
* window editors that come with their own defaults - Brush zoom mode, Minimap - can fall back to
* the chart-wide `minZoom`/`maxZoom` instead of silently using different limits.
*/
var initialState = {
limits: null,
axis: null
};
var zoomSettingsSlice = createSlice({
name: 'zoomSettings',
initialState,
reducers: {
setZoomLimits(state, action) {
var _state$limits, _state$limits2;
var next = action.payload;
if (((_state$limits = state.limits) === null || _state$limits === void 0 ? void 0 : _state$limits.minZoom) === (next === null || next === void 0 ? void 0 : next.minZoom) && ((_state$limits2 = state.limits) === null || _state$limits2 === void 0 ? void 0 : _state$limits2.maxZoom) === (next === null || next === void 0 ? void 0 : next.maxZoom)) {
return;
}
state.limits = next;
},
setZoomAxis(state, action) {
state.axis = action.payload;
}
}
});
var _zoomSettingsSlice$ac = zoomSettingsSlice.actions,
setZoomAxis = _zoomSettingsSlice$ac.setZoomAxis,
setZoomLimits = _zoomSettingsSlice$ac.setZoomLimits;
export { setZoomAxis, setZoomLimits };
export var zoomSettingsReducer = zoomSettingsSlice.reducer;