-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: xinming <xinming.lxj@antfin.com>
- Loading branch information
Showing
16 changed files
with
418 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Coordinate } from '@antv/coord'; | ||
import { IGroup, IShape } from '@antv/g-base'; | ||
import { each, get } from '@antv/util'; | ||
import { doAnimate } from '../animate'; | ||
import { getReplaceAttrs } from '../util/graphics'; | ||
|
||
/** label 的必要配置 */ | ||
type Cfg = { | ||
data: any; | ||
origin: any; | ||
animateCfg: any; | ||
coordinate: Coordinate; | ||
}; | ||
|
||
/** | ||
* @desc 更新 label (目前没有根据 id 索引,还是会存在一点小问题的,只能根据 idx 索引) | ||
* @done shape 属性更新 | ||
* @done shape delete | ||
* @done shape append | ||
* | ||
* @param fromShape old labelShape | ||
* @param toShape new labelShape | ||
* @param cfg | ||
*/ | ||
export function updateLabel(fromShape: IGroup, toShape: IGroup, cfg: Cfg): void { | ||
const { data, origin, animateCfg, coordinate } = cfg; | ||
const updateAnimateCfg = get(animateCfg, 'update'); | ||
|
||
fromShape.set('data', data); | ||
fromShape.set('origin', origin); | ||
fromShape.set('animateCfg', animateCfg); | ||
fromShape.set('coordinate', coordinate); | ||
|
||
fromShape.getChildren().forEach((fromChild, idx) => { | ||
const toChild = toShape.getChildByIndex(idx) as IShape; | ||
if (!toChild) { | ||
fromShape.removeChild(fromChild); | ||
fromChild.remove(true); | ||
} else { | ||
fromChild.set('data', data); | ||
fromChild.set('origin', origin); | ||
fromChild.set('animateCfg', animateCfg); | ||
fromChild.set('coordinate', coordinate); | ||
|
||
const newAttrs = getReplaceAttrs(fromChild as IShape, toChild); | ||
if (updateAnimateCfg) { | ||
doAnimate(fromChild as IShape, updateAnimateCfg, { | ||
toAttrs: newAttrs, | ||
coordinate, | ||
}); | ||
} else { | ||
fromChild.attr(newAttrs); | ||
} | ||
if (toChild.isGroup()) { | ||
updateLabel(fromChild as any, toChild as any, cfg); | ||
} | ||
} | ||
}); | ||
|
||
// append | ||
each(toShape.getChildren(), (child, idx) => { | ||
if (idx >= fromShape.getCount()) { | ||
if (!child.destroyed) { | ||
fromShape.add(child); | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.