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CAAC,CAAC;YAC5B,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YAChC,SAAS,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;YACxC,SAAS,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;YAExC,IAAM,QAAQ,GAAG,eAAe,CAAC,SAAmB,EAAE,OAAO,CAAC,CAAC;YAC/D,IAAI,gBAAgB,EAAE;gBACpB,SAAS,CAAC,SAAmB,EAAE,gBAAgB,EAAE;oBAC/C,OAAO,EAAE,QAAQ;oBACjB,UAAU,YAAA;iBACX,CAAC,CAAC;aACJ;iBAAM;gBACL,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aAC1B;YACD,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE;gBACrB,WAAW,CAAC,SAAgB,EAAE,OAAc,EAAE,GAAG,CAAC,CAAC;aACpD;SACF;IACH,CAAC,CAAC,CAAC;IAEH,SAAS;IACT,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,UAAC,KAAK,EAAE,GAAG;QACrC,IAAI,GAAG,IAAI,SAAS,CAAC,QAAQ,EAAE,EAAE;YAC/B,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE;gBACpB,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;aACtB;SACF;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Coordinate } from '@antv/coord';\nimport { IGroup, IShape } from '@antv/g-base';\nimport { each, get } from '@antv/util';\nimport { doAnimate } from '../animate';\nimport { getReplaceAttrs } from '../util/graphics';\n\n/** label 的必要配置 */\ntype Cfg = {\n data: any;\n origin: any;\n animateCfg: any;\n coordinate: Coordinate;\n};\n\n/**\n * @desc 更新 label (目前没有根据 id 索引,还是会存在一点小问题的,只能根据 idx 索引)\n * @done shape 属性更新\n * @done shape delete\n * @done shape append\n *\n * @param fromShape old labelShape\n * @param toShape new labelShape\n * @param cfg\n */\nexport function updateLabel(fromShape: IGroup, toShape: IGroup, cfg: Cfg): void {\n const { data, origin, animateCfg, coordinate } = cfg;\n const updateAnimateCfg = get(animateCfg, 'update');\n\n fromShape.set('data', data);\n fromShape.set('origin', origin);\n fromShape.set('animateCfg', animateCfg);\n fromShape.set('coordinate', coordinate);\n fromShape.set('visible', toShape.get('visible'));\n\n (fromShape.getChildren() || []).forEach((fromChild, idx) => {\n const toChild = toShape.getChildByIndex(idx) as IShape;\n if (!toChild) {\n fromShape.removeChild(fromChild);\n fromChild.remove(true);\n } else {\n fromChild.set('data', data);\n fromChild.set('origin', origin);\n fromChild.set('animateCfg', animateCfg);\n fromChild.set('coordinate', coordinate);\n\n const newAttrs = getReplaceAttrs(fromChild as IShape, toChild);\n if (updateAnimateCfg) {\n doAnimate(fromChild as IShape, updateAnimateCfg, {\n toAttrs: newAttrs,\n coordinate,\n });\n } else {\n fromChild.attr(newAttrs);\n }\n if (toChild.isGroup()) {\n updateLabel(fromChild as any, toChild as any, cfg);\n }\n }\n });\n\n // append\n each(toShape.getChildren(), (child, idx) => {\n if (idx >= fromShape.getCount()) {\n if (!child.destroyed) {\n fromShape.add(child);\n }\n }\n });\n}\n"]}
\No newline at end of file