UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

31 lines (27 loc) 1.71 kB
const normalizeStates = states => Array.isArray(states) ? states : states ? [ states ] : [], isSameStates = (currentStates, nextStates) => { const current = null != currentStates ? currentStates : []; return current.length === nextStates.length && current.every(((stateName, index) => stateName === nextStates[index])); }; export const setGraphicStates = (graphic, nextStates, hasAnimation) => { var _a; if (graphic.setStates) return void graphic.setStates(nextStates, { animate: hasAnimation, animateSameStatePatchChange: !0 }); const normalizedNextStates = null != nextStates ? nextStates : []; isSameStates(graphic.currentStates, normalizedNextStates) ? null === (_a = graphic.invalidateResolver) || void 0 === _a || _a.call(graphic) : normalizedNextStates.length ? graphic.useStates(normalizedNextStates, hasAnimation) : graphic.clearStates(hasAnimation); }; export const addGraphicState = (graphic, state, keepCurrentStates = !0, hasAnimation) => { var _a; if (!state) return; const currentStates = keepCurrentStates && null !== (_a = graphic.currentStates) && void 0 !== _a ? _a : [], nextStates = keepCurrentStates ? Array.from(new Set([ ...currentStates, state ])) : [ state ]; setGraphicStates(graphic, nextStates, hasAnimation); }; export const removeGraphicState = (graphic, state, hasAnimation) => { var _a; const states = normalizeStates(state); if (!states.length) return; const nextStates = (null !== (_a = graphic.currentStates) && void 0 !== _a ? _a : []).filter((stateName => !states.includes(stateName))); setGraphicStates(graphic, nextStates, hasAnimation); }; //# sourceMappingURL=graphic-state.js.map