UNPKG

@visactor/vchart

Version:

charts lib based @visactor/VGrammar

66 lines (57 loc) 3.39 kB
import { degreeToRadian, isEmpty, isFunction } from "@visactor/vutils"; function getComponentStyleCallbackItem(item) { const rawDatum = null == item ? void 0 : item.datum; return rawDatum && "object" == typeof rawDatum ? Object.assign(Object.assign({}, rawDatum), item) : item; } function hasFunctionStyleValue(style) { return !isFunction(style) && !isEmpty(style) && Object.keys(style).some((key => isFunction(style[key]))); } function transformComponentStyleValue(style, item, isSelected, index, allItems) { const callbackItem = getComponentStyleCallbackItem(item); if (isFunction(style)) return transformToGraphic(style(callbackItem, isSelected, index, allItems)); if (hasFunctionStyleValue(style)) { const nextStyle = Object.assign({}, style); return Object.keys(nextStyle).forEach((key => { isFunction(nextStyle[key]) && (nextStyle[key] = nextStyle[key](callbackItem, isSelected, index, allItems)); })), transformToGraphic(nextStyle); } return transformToGraphic(style); } export function transformComponentStyle(cfg = {}) { const newConfig = Object.assign({}, cfg); if (isFunction(cfg.style) || hasFunctionStyleValue(cfg.style) ? newConfig.style = (item, isSelected, index, allItems) => transformComponentStyleValue(cfg.style, item, isSelected, index, allItems) : isEmpty(cfg.style) || (newConfig.style = transformToGraphic(cfg.style)), !isEmpty(cfg.state)) { const newStateStyle = {}; Object.keys(cfg.state).forEach((key => { isFunction(cfg.state[key]) || hasFunctionStyleValue(cfg.state[key]) ? newStateStyle[key] = (item, isSelected, index, allItems) => transformComponentStyleValue(cfg.state[key], item, isSelected, index, allItems) : isEmpty(cfg.state[key]) || (newStateStyle[key] = transformToGraphic(cfg.state[key])); })), newConfig.state = newStateStyle; } return newConfig; } export function transformStateStyle(stateStyle) { if (isEmpty(stateStyle)) return null; const newStateStyle = {}; return Object.keys(stateStyle).forEach((key => { isFunction(stateStyle[key]) ? newStateStyle[key] = (value, index, datum, data) => transformToGraphic(stateStyle[key](value, index, datum, data)) : isEmpty(stateStyle[key]) || (newStateStyle[key] = transformToGraphic(stateStyle[key])); })), newStateStyle; } export function transformAxisLabelStateStyle(stateStyle) { if (isEmpty(stateStyle)) return null; const newStateStyle = {}; return Object.keys(stateStyle).forEach((key => { isFunction(stateStyle[key]) ? newStateStyle[key] = (datum, index, data, layer) => transformToGraphic(stateStyle[key](datum.rawValue, index, datum, data, layer)) : isEmpty(stateStyle[key]) || (newStateStyle[key] = transformToGraphic(stateStyle[key])); })), newStateStyle; } export function transformIndicatorStyle(style, datum) { if (isEmpty(style)) return null; const newStateStyle = {}; return Object.keys(style).forEach((key => { isFunction(style[key]) ? newStateStyle[key] = style[key](datum) : newStateStyle[key] = style[key]; })), transformToGraphic(newStateStyle); } export function transformToGraphic(style) { return (null == style ? void 0 : style.angle) ? Object.assign(Object.assign({}, style), { angle: degreeToRadian(style.angle) }) : style; } //# sourceMappingURL=style.js.map