@visactor/vchart
Version:
charts lib based @visactor/VGrammar
82 lines (73 loc) • 5.17 kB
JavaScript
var __rest = this && this.__rest || function(s, e) {
var t = {};
for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
if (null != s && "function" == typeof Object.getOwnPropertySymbols) {
var i = 0;
for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
}
return t;
};
import { cloneDeep, isEmpty, isFunction, isValid } from "@visactor/vutils";
import { isPercent, isValidOrient } from "../../../util/space";
import { mergeSpec } from "@visactor/vutils-extension";
import { transformComponentStyle, transformToGraphic } from "../../../util/style";
import { transformLegendTitleAttributes } from "../util";
function normalizeLegendShapeTextureStyle(style) {
return isValid(null == style ? void 0 : style.texture) ? Object.assign(Object.assign({}, style), {
texturePadding: isValid(style.texturePadding) ? style.texturePadding : 1,
textureSize: isValid(style.textureSize) ? style.textureSize : 4
}) : style;
}
function normalizeLegendShapeTextureConfig(shape) {
const normalizeStyle = style => normalizeLegendShapeTextureStyle(style);
if (isFunction(shape.style)) {
const style = shape.style;
shape.style = (...args) => normalizeStyle(style(...args));
} else isEmpty(shape.style) || (shape.style = normalizeStyle(shape.style));
return isEmpty(shape.state) || Object.keys(shape.state).forEach((key => {
if (isFunction(shape.state[key])) {
const stateStyle = shape.state[key];
shape.state[key] = (...args) => normalizeStyle(stateStyle(...args));
} else isEmpty(shape.state[key]) || (shape.state[key] = normalizeStyle(shape.state[key]));
})), shape;
}
export function getLegendAttributes(spec, rect, layoutOrient) {
const {title: titleSpec = {}, item: itemSpec = {}, pager: pagerSpec = {}, background: backgroundSpec = {}, type: type, id: id, visible: visible, orient: orient, position: position, data: data, filter: filter, regionId: regionId, regionIndex: regionIndex, seriesIndex: seriesIndex, seriesId: seriesId, padding: padding} = spec, restSpec = __rest(spec, [ "title", "item", "pager", "background", "type", "id", "visible", "orient", "position", "data", "filter", "regionId", "regionIndex", "seriesIndex", "seriesId", "padding" ]);
let {title: title = {}, item: item = {}, pager: pager = {}, background: background = {}} = spec;
title = cloneDeep(title), item = cloneDeep(item), pager = cloneDeep(pager), background = cloneDeep(background);
const attrs = restSpec, pagerLayout = pager.layout, pagerPosition = pager.position;
if (isFunction(attrs.maxRow) || isFunction(attrs.maxCol) || isFunction(pagerLayout) || isFunction(pagerPosition)) {
const resolvedOrient = isValidOrient(layoutOrient) ? layoutOrient : isValidOrient(orient) ? orient : "left";
isFunction(attrs.maxRow) && (attrs.maxRow = attrs.maxRow({
rect: rect,
orient: resolvedOrient,
id: id
})), isFunction(attrs.maxCol) && (attrs.maxCol = attrs.maxCol({
rect: rect,
orient: resolvedOrient,
id: id
}));
const isArrowPager = "scrollbar" !== pager.type, pagerContext = {
rect: rect,
orient: resolvedOrient,
id: id,
maxRow: attrs.maxRow,
maxCol: attrs.maxCol
};
isArrowPager && isFunction(pagerLayout) && (pager.layout = pagerLayout(pagerContext)),
isArrowPager && isFunction(pagerPosition) && (pager.position = pagerPosition(pagerContext));
}
return title.visible ? attrs.title = transformLegendTitleAttributes(title) : attrs.title = {
visible: !1
}, isEmpty(item.focusIconStyle) || transformToGraphic(item.focusIconStyle), item.shape && (item.shape = normalizeLegendShapeTextureConfig(transformComponentStyle(item.shape))),
item.label && (item.label = transformComponentStyle(item.label)), item.value && (item.value = transformComponentStyle(item.value)),
item.background && (item.background = transformComponentStyle(item.background)),
isPercent(item.maxWidth) && (item.maxWidth = Number(item.maxWidth.substring(0, item.maxWidth.length - 1)) * rect.width / 100),
isPercent(item.width) && (item.width = Number(item.width.substring(0, item.width.length - 1)) * rect.width / 100),
isPercent(item.height) && (item.height = Number(item.height.substring(0, item.height.length - 1)) * rect.width / 100),
attrs.item = item, "scrollbar" === pager.type ? (isEmpty(pager.railStyle) || transformToGraphic(pager.railStyle),
isEmpty(pager.sliderStyle) || transformToGraphic(pager.sliderStyle)) : (isEmpty(pager.textStyle) || transformToGraphic(pager.textStyle),
pager.handler && transformComponentStyle(pager.handler)), attrs.pager = pager, background.visible && !isEmpty(background.style) && (mergeSpec(attrs, background.style),
isValid(background.padding) && (attrs.padding = background.padding)), attrs;
}
//# sourceMappingURL=util.js.map