@visactor/vchart
Version:
charts lib based @visactor/VGrammar
41 lines (33 loc) • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.removeGraphicState = exports.addGraphicState = exports.setGraphicStates = void 0;
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]));
}, 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);
};
exports.setGraphicStates = setGraphicStates;
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 ];
(0, exports.setGraphicStates)(graphic, nextStates, hasAnimation);
};
exports.addGraphicState = addGraphicState;
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)));
(0, exports.setGraphicStates)(graphic, nextStates, hasAnimation);
};
exports.removeGraphicState = removeGraphicState;
//# sourceMappingURL=graphic-state.js.map