Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private drawLabelLine(labelCfg: LabelItem, container: IGroup) {
if (!labelCfg.labelLine) {
// labelLine: null | false,关闭 label 对应的 labelLine
return;
}
const labelLineCfg = get(labelCfg, 'labelLine', {});
let path = labelLineCfg.path;
if (!path) {
const start = labelCfg.start;
path = [
['M', start.x, start.y],
['L', labelCfg.x, labelCfg.y],
];
}
container.addShape('path', {
capture: false, // labelLine 默认不参与事件捕获
attrs: {
path,
stroke: labelCfg.color ? labelCfg.color : get(labelCfg, ['style', 'fill'], '#000'),
fill: null,
...labelLineCfg.style,
},
max: Math.max(Math.max.apply(null, yScale.values), yScale.max),
});
} else {
// 柱状图数值轴默认从 0 开始
const scaleDefs = this.scaleDefs;
const { field, min, max, type } = yScale;
if (type !== 'time') {
// time 类型不做调整
// 柱状图的 Y 轴要从 0 开始生长,但是如果用户设置了则以用户的为准
if (min > 0 && !get(scaleDefs, [field, 'min'])) {
yScale.change({
min: 0,
});
}
// 柱当柱状图全为负值时也需要从 0 开始生长,但是如果用户设置了则以用户的为准
if (max <= 0 && !get(scaleDefs, [field, 'max'])) {
yScale.change({
max: 0,
});
}
}
}
}
}
private getCategoryCfg(geometry: Geometry, attr: Attribute, scale: Scale, legendOption: any): object {
const container = this.container;
// if position is not set, use top as default
const direction = get(legendOption, 'position', DIRECTION.BOTTOM);
// the default marker style
const themeMarker = get(this.view.getTheme(), ['components', 'legend', direction, 'marker']);
const userMarker = get(legendOption, 'marker');
const layout = getLegendLayout(direction);
const baseCfg = {
container,
layout,
items: getLegendItems(this.view, geometry, attr, themeMarker, userMarker),
...this.getCategoryLegendSizeCfg(layout),
};
return this.mergeLegendCfg(baseCfg, legendOption, direction);
}
each(lastShapesMap, (deleteShape) => {
const animateCfg = get(deleteShape.get('animateCfg'), 'leave');
if (animateCfg) {
doAnimate(deleteShape, animateCfg, {
toAttrs: null,
coordinate: deleteShape.get('coordinate'),
});
} else {
deleteShape.remove(true); // 移除
}
});
function getAxisOption(axes: Record | boolean, field: string) {
if (isBoolean(axes)) {
return axes === false ? false : {};
} else {
return get(axes, [field]);
}
}
public updateCanvasTheme() {
const { theme } = this.plot;
const globalTheme = ThemeController.getGlobalTheme(theme);
const fill: string = _.get(globalTheme, 'backgroundStyle.fill');
if (fill) {
this.updateCanvasStyle({
backgroundColor: fill,
});
}
}
private _getColorMappingField(props) {
for (const m of COLOR_MAPPER) {
if (_.get(props, m)) {
return [props[m]];
}
}
}
}
getMarker(shapeType: string, markerCfg: ShapeMarkerCfg): ShapeMarkerAttrs {
let shape = this.getShape(shapeType);
if (!shape.getMarker) {
const defaultShapeType = this.defaultShapeType;
shape = this.getShape(defaultShapeType);
}
const theme = this.theme;
const shapeStyle = get(theme, [shapeType, 'default'], {});
const markerStyle = shape.getMarker(markerCfg);
return deepMix({}, { style: shapeStyle }, markerStyle);
},
/**
private _getColorMappingField() {
const props = this.plot.options;
const colorMapper = ['stackField', 'seriesField'];
for (const m of colorMapper) {
if (_.get(props, m)) {
return [props[m]];
}
}
}
}
private _titleParser() {
const titleConfig: DataPointType = { ...this.localProps.title };
const { visible, style, text } = this.localProps.title;
if (!visible) {
this.config.showTitle = false;
} else {
this.config.showTitle = true;
if (style) {
titleConfig.textStyle = style;
}
titleConfig.textStyle = _.deepMix({}, _.get(this.config, 'title.style'), titleConfig.textStyle);
if (text) {
titleConfig.text = text;
}
}
this.config.title = titleConfig;
}