File size: 2,017 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { StackOffsetType } from '../util/types';
import { SyncMethod } from '../synchronisation/types';
/**
* These are chart options that users can choose - which means they can also
* choose to change them which should trigger a re-render.
*/
export type UpdatableChartOptions = {
accessibilityLayer: boolean;
barCategoryGap: number | string;
barGap: number | string;
barSize: string | number | undefined;
/**
* Useful for debugging which chart is which when synchronising.
* The className is also passed to the root element of the chart but that's done in the JSX, not through Redux.
*/
className: string | undefined;
maxBarSize: number | undefined;
stackOffset: StackOffsetType;
/**
* Charts that share the same syncId will have their Tooltip and Brush synchronised.
*/
syncId: number | string | undefined;
syncMethod: SyncMethod;
};
export const initialState: UpdatableChartOptions = {
accessibilityLayer: true,
barCategoryGap: '10%',
barGap: 4,
barSize: undefined,
className: undefined,
maxBarSize: undefined,
stackOffset: 'none',
syncId: undefined,
syncMethod: 'index',
};
const rootPropsSlice = createSlice({
name: 'rootProps',
initialState,
reducers: {
updateOptions: (state: UpdatableChartOptions, action: PayloadAction<UpdatableChartOptions>) => {
state.accessibilityLayer = action.payload.accessibilityLayer;
state.barCategoryGap = action.payload.barCategoryGap;
state.barGap = action.payload.barGap ?? initialState.barGap;
state.barSize = action.payload.barSize;
state.maxBarSize = action.payload.maxBarSize;
state.stackOffset = action.payload.stackOffset;
state.syncId = action.payload.syncId;
state.syncMethod = action.payload.syncMethod;
state.className = action.payload.className;
},
},
});
export const rootPropsReducer = rootPropsSlice.reducer;
export const { updateOptions } = rootPropsSlice.actions;
|