UNPKG

2.02 kBJavaScriptView Raw
1import { each, get } from '@antv/util';
2import { doAnimate } from '../animate';
3import { getReplaceAttrs } from '../util/graphics';
4/**
5 * @desc 更新 label (目前没有根据 id 索引,还是会存在一点小问题的,只能根据 idx 索引)
6 * @done shape 属性更新
7 * @done shape delete
8 * @done shape append
9 *
10 * @param fromShape old labelShape
11 * @param toShape new labelShape
12 * @param cfg
13 */
14export function updateLabel(fromShape, toShape, cfg) {
15 var data = cfg.data, origin = cfg.origin, animateCfg = cfg.animateCfg, coordinate = cfg.coordinate;
16 var updateAnimateCfg = get(animateCfg, 'update');
17 fromShape.set('data', data);
18 fromShape.set('origin', origin);
19 fromShape.set('animateCfg', animateCfg);
20 fromShape.set('coordinate', coordinate);
21 fromShape.set('visible', toShape.get('visible'));
22 (fromShape.getChildren() || []).forEach(function (fromChild, idx) {
23 var toChild = toShape.getChildByIndex(idx);
24 if (!toChild) {
25 fromShape.removeChild(fromChild);
26 fromChild.remove(true);
27 }
28 else {
29 fromChild.set('data', data);
30 fromChild.set('origin', origin);
31 fromChild.set('animateCfg', animateCfg);
32 fromChild.set('coordinate', coordinate);
33 var newAttrs = getReplaceAttrs(fromChild, toChild);
34 if (updateAnimateCfg) {
35 doAnimate(fromChild, updateAnimateCfg, {
36 toAttrs: newAttrs,
37 coordinate: coordinate,
38 });
39 }
40 else {
41 fromChild.attr(newAttrs);
42 }
43 if (toChild.isGroup()) {
44 updateLabel(fromChild, toChild, cfg);
45 }
46 }
47 });
48 // append
49 each(toShape.getChildren(), function (child, idx) {
50 if (idx >= fromShape.getCount()) {
51 if (!child.destroyed) {
52 fromShape.add(child);
53 }
54 }
55 });
56}
57//# sourceMappingURL=update-label.js.map
\No newline at end of file