Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
each(steps, (subSteps) => {
each(subSteps, (step) => {
if (isFunction(step.action)) {
// 如果传入回调函数,则直接生成 CallbackAction
step.actionObject = {
action: createCallbackAction(step.action, context),
methodName: 'execute',
};
} else if (isString(step.action)) {
// 如果是字符串,则根据名称生成对应的 Action
const arr = step.action.split(':');
const actionName = arr[0];
// 如果已经初始化过 action ,则直接引用之前的 action
const action = context.getAction(actionName) || createAction(actionName, context);
const methodName = arr[1];
step.actionObject = {
action,
methodName,
const axisShapes: Shape[] = getShapes(backgroundGroup, viewId);
const cacheShapes = shapes.concat(axisShapes);
canvas.setSilent(`${viewId}caches`, cache(cacheShapes));
let drawn;
if (newIsUpdate) {
// 执行更新动画
drawn = addAnimate(caches, cacheShapes, canvas);
} else {
// 初入场动画
// drawn = addAnimate(caches, shapes, canvas, newIsUpdate);
let animateCfg;
let animate;
const elements = view.get('elements');
const coord = view.get('coord');
_.each(elements, (element: Element) => {
const type = element.get('type');
const elementAnimateOption = element.get('animateOptions');
if (elementAnimateOption !== false) {
// 用户为关闭动画
animateCfg = getAnimateCfg(type, 'appear', elementAnimateOption);
if (!animateCfg) {
return true;
} // 用户关闭了初始动画
animate = getAnimate(type, coord, 'appear', animateCfg.animation);
if (_.isFunction(animate)) {
if (animate.animationName.indexOf('group') === 0) {
// 执行全局动画
const yScale = element.getYScale();
const zeroY = coord.convertPoint({
x: 0,
function getInterpolateShapeAttrs(cfg: ShapeInfo, shapeType: string) {
const points = getPathPoints(cfg.points, cfg.connectNulls); // 根据 connectNulls 值处理 points
let path = [];
each(points, (eachLinePoints) => {
const interpolatePoints = getInterpolatePoints(eachLinePoints, shapeType);
path = path.concat(getInterpolatePath(interpolatePoints));
});
return {
...getStyle(cfg, true, false, 'lineWidth'),
path,
};
}
public destroy() {
this.view = null;
this.event = null;
// 先销毁 action 再清空,一边遍历,一边删除,所以数组需要更新引用
each(this.actions.slice(), (action) => {
action.destroy();
});
this.actions = null;
this.cacheMap = null;
}
}
private onLayerEvent(layers: Layer[], eventObj: EventObj, eventName: string) {
_.each(layers, (layer) => {
const bbox = layer.getGlobalBBox();
if (isPointInBBox({ x: eventObj.x, y: eventObj.y }, bbox)) {
layer.emit(`${eventName}`, eventObj);
const subLayers = layer.layers;
if (subLayers.length > 0) {
this.onLayerEvent(subLayers, eventObj, eventName);
}
}
});
}
}
private circleToRect(shapes) {
const gridSize = this.gridSize;
_.each(shapes, (shape) => {
const { x, y, size } = shape.get('origin');
let sizeRatio = (size * 2) / Math.min(gridSize[0], gridSize[1]);
if (!this.options.sizeField) {
sizeRatio = 1;
}
const curvePath = getCircleCurve(x, y, size);
const rectPath = getRectPath(x, y, gridSize[0], gridSize[1], sizeRatio);
shape.stopAnimate();
shape.attr('path', curvePath);
shape.animate(
{
path: rectPath,
},
1000,
'easeCubic'
);
private applyResponsive(stage) {
const methods = responsiveMethods[stage];
_.each(methods, (r) => {
const responsive = r as IAttrs;
responsive.method(this);
});
}
protected setElementsStateByItem(elements: Element[], field: string, item: ListItem, enable: boolean) {
each(elements, (el) => {
if (this.isMathItem(el, field, item)) {
el.setState(this.stateName, enable);
}
});
}
private _drawLines() {
const intervals = this.intervals;
_.each(intervals, (i) => {
const percent = this.scale.scale(i);
const point = this._getPointByPercent(percent, 'x');
this.container.addShape('line', {
attrs: {
x1: point,
y1: 0,
x2: point,
y2: LINEHEIGHT,
stroke: '#ccc',
lineWidth: 1,
},
});
});
}
protected setElementsState(elements: Element[], enable) {
each(elements, (el) => {
this.setElementState(el, enable);
});
}