@antv/g6 5.0.0-beta.22 → 5.0.0-beta.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/esm/index.d.ts +1 -1
  3. package/esm/index.js +1 -1
  4. package/esm/item/combo.js +1 -0
  5. package/esm/item/combo.js.map +1 -1
  6. package/esm/item/edge.js +2 -1
  7. package/esm/item/edge.js.map +1 -1
  8. package/esm/item/item.js +3 -4
  9. package/esm/item/item.js.map +1 -1
  10. package/esm/runtime/controller/layout.d.ts +1 -0
  11. package/esm/runtime/controller/layout.js +39 -4
  12. package/esm/runtime/controller/layout.js.map +1 -1
  13. package/esm/runtime/controller/viewport.js +19 -3
  14. package/esm/runtime/controller/viewport.js.map +1 -1
  15. package/esm/runtime/graph.js +28 -4
  16. package/esm/runtime/graph.js.map +1 -1
  17. package/esm/stdlib/plugin/legend/index.d.ts +1 -0
  18. package/esm/stdlib/plugin/legend/index.js +2 -0
  19. package/esm/stdlib/plugin/legend/index.js.map +1 -1
  20. package/esm/stdlib/theme/dark.js +22 -22
  21. package/esm/stdlib/theme/light.js +20 -20
  22. package/esm/types/view.d.ts +3 -0
  23. package/esm/util/animate.d.ts +1 -1
  24. package/esm/util/animate.js +45 -17
  25. package/esm/util/animate.js.map +1 -1
  26. package/lib/index.d.ts +1 -1
  27. package/lib/index.js +1 -1
  28. package/lib/item/combo.js +1 -0
  29. package/lib/item/combo.js.map +1 -1
  30. package/lib/item/edge.js +2 -1
  31. package/lib/item/edge.js.map +1 -1
  32. package/lib/item/item.js +3 -4
  33. package/lib/item/item.js.map +1 -1
  34. package/lib/runtime/controller/layout.d.ts +1 -0
  35. package/lib/runtime/controller/layout.js +38 -3
  36. package/lib/runtime/controller/layout.js.map +1 -1
  37. package/lib/runtime/controller/viewport.js +19 -3
  38. package/lib/runtime/controller/viewport.js.map +1 -1
  39. package/lib/runtime/graph.js +28 -4
  40. package/lib/runtime/graph.js.map +1 -1
  41. package/lib/stdlib/plugin/legend/index.d.ts +1 -0
  42. package/lib/stdlib/plugin/legend/index.js +2 -0
  43. package/lib/stdlib/plugin/legend/index.js.map +1 -1
  44. package/lib/stdlib/theme/dark.js +22 -22
  45. package/lib/stdlib/theme/light.js +20 -20
  46. package/lib/types/view.d.ts +3 -0
  47. package/lib/util/animate.d.ts +1 -1
  48. package/lib/util/animate.js +45 -17
  49. package/lib/util/animate.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/index.ts +1 -1
  52. package/src/item/combo.ts +1 -0
  53. package/src/item/edge.ts +2 -1
  54. package/src/item/item.ts +7 -4
  55. package/src/runtime/controller/layout.ts +37 -4
  56. package/src/runtime/controller/viewport.ts +27 -3
  57. package/src/runtime/graph.ts +40 -8
  58. package/src/stdlib/plugin/legend/index.ts +2 -0
  59. package/src/stdlib/theme/dark.ts +22 -22
  60. package/src/stdlib/theme/light.ts +20 -20
  61. package/src/types/view.ts +3 -0
  62. package/src/util/animate.ts +62 -25
@@ -6,14 +6,10 @@ import {
6
6
  Path,
7
7
  Polyline,
8
8
  } from '@antv/g';
9
- import {
10
- AnimateTiming,
11
- IAnimate,
12
- IAnimates,
13
- IStateAnimate,
14
- } from '../types/animate';
15
- import { ItemDisplayModel, ItemShapeStyles, ShapeStyle } from '../types/item';
9
+ import { AnimateTiming, IAnimate, IAnimates } from '../types/animate';
10
+ import { ItemShapeStyles, ShapeStyle } from '../types/item';
16
11
  import { isArrayOverlap, replaceElements } from './array';
12
+ import { clone, isString, uniq } from '@antv/util';
17
13
 
18
14
  /**
19
15
  * Initial(timing = show) shape animation start from init shape styles, and end to the shape's style config.
@@ -28,9 +24,8 @@ export const getShapeAnimateBeginStyles = (shape) => {
28
24
  offsetDistance: 0,
29
25
  };
30
26
  if (['line', 'polyline', 'path'].includes(shapeType)) {
31
- const totalLength = shape.getTotalLength();
32
27
  return {
33
- lineDash: [0, totalLength],
28
+ lineDash: [0, '100%'],
34
29
  ...commonStyles,
35
30
  };
36
31
  } else if (shapeType === 'circle') {
@@ -136,13 +131,11 @@ const groupTimingAnimates = (
136
131
  const isStateUpdate = segmentedTiming === 'stateUpdate';
137
132
  animates[isStateUpdate ? 'update' : segmentedTiming].forEach((item: any) => {
138
133
  const { order = 0, states } = item;
139
- if (
140
- !isStateUpdate ||
141
- (isStateUpdate && isArrayOverlap(states, changedStates))
142
- ) {
143
- timingAnimateGroups[order] = timingAnimateGroups[order] || [];
144
- timingAnimateGroups[order].push(item);
134
+ if (states?.length) {
135
+ if (!isArrayOverlap(states, changedStates)) return;
145
136
  }
137
+ timingAnimateGroups[order] = timingAnimateGroups[order] || [];
138
+ timingAnimateGroups[order].push(item);
146
139
  });
147
140
  return timingAnimateGroups;
148
141
  };
@@ -255,7 +248,13 @@ const runAnimateGroupOnShapes = (
255
248
  }
256
249
  return animation;
257
250
  });
258
- if (maxDurationIdx > -1) animations[maxDurationIdx].onfinish = onfinish;
251
+ if (maxDurationIdx > -1) {
252
+ const selfOnfinish = animations[maxDurationIdx].onfinish;
253
+ animations[maxDurationIdx].onfinish = () => {
254
+ selfOnfinish?.();
255
+ onfinish?.();
256
+ };
257
+ }
259
258
  return animations;
260
259
  };
261
260
 
@@ -276,19 +275,51 @@ const runAnimateOnShape = (
276
275
  animateConfig,
277
276
  ) => {
278
277
  let animateArr;
278
+ let percentLineDash = false;
279
279
  if (!fields?.length) {
280
280
  animateArr = getStyleDiff(shape.attributes, targetStyle);
281
281
  } else {
282
282
  animateArr = [{}, {}];
283
283
  fields.forEach((key) => {
284
- animateArr[0][key] = shape.attributes.hasOwnProperty(key)
285
- ? shape.style[key]
286
- : beginStyle[key];
287
- animateArr[1][key] =
288
- targetStyle[key] === undefined ? animateArr[0][key] : targetStyle[key];
289
- if (key === 'lineDash' && animateArr[1][key].includes('100%')) {
290
- const totalLength = (shape as Line | Polyline | Path).getTotalLength();
291
- replaceElements(animateArr[1][key], '100%', totalLength);
284
+ animateArr[0][key] =
285
+ shape.style[key] === undefined
286
+ ? clone(beginStyle[key])
287
+ : clone(shape.style[key]);
288
+ if (targetStyle[key] === undefined) return;
289
+ animateArr[1][key] = clone(targetStyle[key]);
290
+ if (key === 'lineDash') {
291
+ const beginPercents = uniq(
292
+ animateArr[0][key].filter(
293
+ (val) => isString(val) && val.includes('%'),
294
+ ),
295
+ );
296
+ const targetPercents = uniq(
297
+ animateArr[1][key].filter(
298
+ (val) => isString(val) && val.includes('%'),
299
+ ),
300
+ );
301
+ if (beginPercents.length || targetPercents.length) {
302
+ percentLineDash = clone(animateArr[0].lineDash);
303
+ const totalLength = (
304
+ shape as Line | Polyline | Path
305
+ ).getTotalLength();
306
+ beginPercents.forEach((percent, i) => {
307
+ replaceElements(
308
+ animateArr[0][key],
309
+ percent,
310
+ (Number(percent.replace('%', '')) / 100) * totalLength,
311
+ );
312
+ });
313
+ targetPercents.forEach((percent, i) => {
314
+ replaceElements(
315
+ animateArr[1][key],
316
+ percent,
317
+ (Number(percent.replace('%', '')) / 100) * totalLength,
318
+ );
319
+ });
320
+ }
321
+ } else if (key === 'offsetDistance') {
322
+ animateArr[1][key] = animateArr[1][key] || 1;
292
323
  }
293
324
  });
294
325
  }
@@ -300,7 +331,13 @@ const runAnimateOnShape = (
300
331
  );
301
332
  return;
302
333
  }
303
- return shape.animate(animateArr, animateConfig);
334
+ const animation = shape.animate(animateArr, animateConfig);
335
+ if (percentLineDash) {
336
+ animation.onfinish = () => {
337
+ shape.style.lineDash = percentLineDash;
338
+ };
339
+ }
340
+ return animation;
304
341
  };
305
342
 
306
343
  /**