Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_.each(shapes, (shape) => {
if (!shape.id || shape.get('isClip')) {
return;
}
const id = shape.id;
rst[id] = {
id,
type: shape.get('type'),
attrs: _.clone(shape.attr()),
// 原始属性
name: shape.name,
index: shape.get('index'),
animateCfg: shape.get('animateOptions'),
coord: shape.get('coord'),
};
});
return rst;
private _getInnerAutoPadding() {
const props = this.plot.options;
const view = this.plot.view;
const viewRange: BBox = view.get('viewRange');
const { maxX, maxY } = viewRange;
const bleeding = this.plot.config.theme.bleeding;
if (_.isArray(bleeding)) {
_.each(bleeding, (it, index) => {
if (typeof bleeding[index] === 'function') {
bleeding[index] = bleeding[index](props);
}
});
}
this.plot.config.theme.legend.margin = bleeding;
this.bleeding = _.clone(bleeding);
// 参与auto padding的components: axis legend
const components_bbox = [view.get('panelRange')];
this._getAxis(view, components_bbox);
let box = this._mergeBBox(components_bbox);
this._getLegend(view, components_bbox, box);
box = this._mergeBBox(components_bbox);
// 参与auto padding的自定义组件
const components = this.innerPaddingComponents;
_.each(components, (obj) => {
const component = obj as Element;
const bbox = component.getBBox();
components_bbox.push(bbox);
});
box = this._mergeBBox(components_bbox);
let minY = box.minY;
/** 极坐标下padding计算错误问题 */
public render(coord: Coordinate, group: Group) {
const point = this.parsePoint(coord, this.get('position'));
const textStyle = _.clone(this.get('style'));
const offsetX = this.get('offsetX');
const offsetY = this.get('offsetY');
if (offsetX) {
point.x += offsetX;
}
if (offsetY) {
point.y += offsetY;
}
if (textStyle.rotate) {
textStyle.rotate = (textStyle.rotate * Math.PI) / 180; // 将角度转换为弧度
}
const guideText = group.addShape('Text', {
protected renderVertical(min, max, colors) {
const gridWidth = this.width;
const gridHeight = this.height / colors.length;
const gridLineContainer = new Group();
const gridColors = clone(colors).reverse();
const valueStep = (max - min) / colors.length;
// 绘制色彩格子
each(gridColors, (c, i) => {
const y = gridHeight * i;
// 记录每个grid代表的区间信息用于legend交互
const appendInfo = { to: max - valueStep * i, from: max - valueStep * (i + 1) };
const rect = this.container.addShape('rect', {
attrs: {
x: 0,
y,
width: gridWidth,
height: gridHeight,
fill: c,
opacity: ACTIVE_OPACITY,
cursor: 'pointer',
},
public init() {
const originXAxisConfig = this.options.xAxis ? _.clone(this.options.xAxis) : {};
this.options.xField = 'value';
this.options.yField = 'density';
this.options.xAxis = _.deepMix({}, originXAxisConfig, { type: 'linear' });
this.options.smooth = true;
super.init();
}
}
if (axisCfg.autoRotate) {
axisCfg.autoRotateTitle = axisCfg.autoRotate;
}
axisCfg.title = _.clone(axis.title);
if (axisCfg.title.style) {
axisCfg.title.textStyle = axisCfg.title.style;
delete axisCfg.title.style;
}
}
}
if (axis.tickLine) {
if (axis.tickLine.visible === false) {
axisCfg.tickLine = null;
} else if (axis.tickLine.style) {
axisCfg.tickLine = _.clone(axis.tickLine.style);
}
}
if (Object.prototype.hasOwnProperty.call(axis, 'autoHideLabel')) {
axisCfg.autoHideLabel = axis.autoHideLabel;
}
if (Object.prototype.hasOwnProperty.call(axis, 'autoRotateLabel')) {
axisCfg.autoRotateLabel = axis.autoRotateLabel;
}
if (axis.label) {
if (axis.label.visible === false) {
axisCfg.label = null;
} else {
const newLabel = _.clone(axis.label);
if (newLabel.style) {
newLabel.textStyle = newLabel.style;
delete newLabel.style;
function getMedian(array) {
const list = _.clone(array);
list.sort((a, b) => {
return a - b;
});
const half = Math.floor(list.length / 2);
if (list.length % 2) {
return list[half];
}
return list[half];
}
private _getLabelBbox(text) {
const plot: ViewLayer = this.get('labelOptions').plot;
const labelStyle = _.clone(plot.theme.label.textStyle);
labelStyle.fontSize = DEFAULT_SIZE;
const tShape = new Text({
attrs: {
text,
x: 0,
y: 0,
...labelStyle,
},
});
return tShape.getBBox();
}
protected parseColorProps(props) {
let colorOption;
if (props.color) {
if (_.isFunction(props.color)) {
colorOption = props.color(props.percent);
} else {
colorOption = props.color;
}
if (_.isString(colorOption)) {
const color = _.clone(DEFAULT_COLOR);
color[0] = colorOption;
return color;
} else {
return colorOption;
}
}
return props.color;
}