Skip to content

Commit

Permalink
fix: fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
simaQ authored and hustcc committed Nov 28, 2019
1 parent 397b20c commit 79047d4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
10 changes: 5 additions & 5 deletions src/geometry/animate/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { Point, ShapeInfo } from '../../interface';
import { getAngle, getSectorPath } from '../../util/graphics';
import { getCoordinateClipCfg } from './util';

// 传递给 G 的动画配置,easing, animation, duration 必须提供
// 传递给 G 的动画配置,duration 必须提供
export interface AnimateCfg {
/** 动画缓动函数 */
readonly easing: string;
/** 动画执行函数 */
readonly animation: string;
/** 动画执行时间 */
readonly duration: number;
/** 动画缓动函数 */
readonly easing?: string;
/** 动画执行函数 */
readonly animation?: string;
/** 动画延迟时间 */
readonly delay?: number;
/** 动画执行结束后的回调函数 */
Expand Down
1 change: 1 addition & 0 deletions src/geometry/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ export default class Geometry {
if (offscreenGroup) {
offscreenGroup.remove(true);
}
this.offscreenGroup = null;
}

/**
Expand Down
29 changes: 14 additions & 15 deletions src/geometry/element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import EE from '@antv/event-emitter';
import * as _ from '@antv/util';
import { IGroup, IShape } from '../../dependents';
import { AnimateOption, Datum, LooseObject, ShapeFactory, ShapeInfo } from '../../interface';
import { getDefaultAnimateCfg } from '../animate';
import { doAnimate } from '../animate/index';
import { doAnimate, getDefaultAnimateCfg } from '../animate';

interface ElementCfg {
/** 原始数据 */
Expand Down Expand Up @@ -280,38 +279,38 @@ export default class Element extends EE {

// 更新当前 shape 的样式
private syncShapeStyle(
shape: IGroup | IShape,
newShape: IGroup | IShape,
sourceShape: IGroup | IShape,
targetShape: IGroup | IShape,
state: string = '',
animateCfg,
index: number = 0
) {
if (shape.isGroup()) {
const children = shape.get('children');
const newChildren = newShape.get('children');
if (sourceShape.isGroup()) {
const children = sourceShape.get('children');
const newChildren = targetShape.get('children');
for (let i = 0; i < children.length; i++) {
this.syncShapeStyle(children[i], newChildren[i], state, animateCfg, index + i);
}
} else {
if (state) {
const stateStyle = this.getStateStyle(state, shape.get('name') || index); // 如果用户没有设置 name,则默认根据索引值
newShape.attr(stateStyle);
const stateStyle = this.getStateStyle(state, sourceShape.get('name') || index); // 如果用户没有设置 name,则默认根据索引值
targetShape.attr(stateStyle);
}
const newAttrs = this.getReplaceAttrs(shape as IShape, newShape as IShape);
const newAttrs = this.getReplaceAttrs(sourceShape as IShape, targetShape as IShape);

if (animateCfg) {
// 需要进行动画
doAnimate(shape, animateCfg, this.shapeFactory.coordinate, newAttrs);
doAnimate(sourceShape, animateCfg, this.shapeFactory.coordinate, newAttrs);
} else {
shape.attr(newAttrs);
sourceShape.attr(newAttrs);
}
}
}

// 获取需要替换的属性,如果原先图形元素存在,而新图形不存在,则设置 undefined
private getReplaceAttrs(shape: IShape, newShape: IShape) {
const originAttrs = shape.attr();
const newAttrs = newShape.attr();
private getReplaceAttrs(sourceShape: IShape, targetShape: IShape) {
const originAttrs = sourceShape.attr();
const newAttrs = targetShape.attr();
_.each(originAttrs, (v, k) => {
if (newAttrs[k] === undefined) {
newAttrs[k] = undefined;
Expand Down
12 changes: 2 additions & 10 deletions src/geometry/util/is-model-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ import { ShapeInfo } from '../../interface';
* @returns
*/
export function isModelChange(currentModel: ShapeInfo, preModel: ShapeInfo) {
let result = false;
// 判断映射数据以及原始数据是否发生改变
const keys = ['color', 'shape', 'size', 'x', 'y', 'isInCircle', 'data', 'style'];
_.each(keys, (key) => {
if (!_.isEqual(currentModel[key], preModel[key])) {
result = true;
return false;
}
return _.some(['color', 'shape', 'size', 'x', 'y', 'isInCircle', 'data', 'style'], (key: string) => {
return !_.isEqual(currentModel[key], preModel[key]);
});

return result;
}

0 comments on commit 79047d4

Please sign in to comment.