1 | import { each, get } from '@antv/util';
|
2 | import { doAnimate } from '../animate';
|
3 | import { getReplaceAttrs } from '../util/graphics';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export 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 |
|
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 |
|
\ | No newline at end of file |