From 50bb0cc1cbf1844a2922a49660ce4d5baf4a7bce Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 22 Feb 2024 15:56:21 +0800 Subject: [PATCH] refactor(runtime): adapt polyline and cubic edges (#5458) * refactor(registry): register built-in edges * fix(utils): fix getEllipseIntersectPoint get NaN result * refactor(runtime): adapt more edges * fix: fix cr issues --- .../demo/static/controller-layout-dagre.ts | 1 - .../static/controller-layout-dendrogram.ts | 10 +- .../demo/static/controller-layout-indented.ts | 1 - .../controller-element-1000(3_3).svg | 4 +- .../animation/controller-element-200(2_3).svg | 12 +- .../animation/controller-element-50(1_3).svg | 12 +- .../controller-element-position-1000(3_3).svg | 36 +-- .../controller-element-position-200(2_3).svg | 36 +-- .../controller-element-state-0(1_2).svg | 12 +- .../controller-element-state-1000(2_2).svg | 12 +- .../static/controller-element-position.svg | 36 +-- .../static/controller-element-visibility.svg | 12 +- .../controller-element-visibility__hidden.svg | 12 +- .../snapshots/static/controller-element.svg | 12 +- .../static/controller-layout-circular.svg | 256 +++++++++--------- .../static/controller-layout-d3-force.svg | 256 +++++++++--------- .../static/controller-layout-dagre.svg | 48 ++-- .../static/controller-layout-dendrogram.svg | 60 ++-- .../static/controller-layout-grid.svg | 256 +++++++++--------- .../snapshots/static/graph-element.svg | 240 ++++++++-------- packages/g6/__tests__/unit/registry.spec.ts | 16 +- .../g6/__tests__/unit/runtime/element.spec.ts | 8 - .../g6/__tests__/unit/utils/point.spec.ts | 16 ++ packages/g6/src/animations/executor.ts | 32 +-- packages/g6/src/elements/index.ts | 2 +- packages/g6/src/registry/build-in.ts | 16 +- packages/g6/src/runtime/element.ts | 41 ++- packages/g6/src/themes/dark.ts | 2 +- packages/g6/src/themes/light.ts | 2 +- packages/g6/src/utils/animation.ts | 5 +- packages/g6/src/utils/layout.ts | 2 +- packages/g6/src/utils/point.ts | 9 +- 32 files changed, 755 insertions(+), 720 deletions(-) diff --git a/packages/g6/__tests__/demo/static/controller-layout-dagre.ts b/packages/g6/__tests__/demo/static/controller-layout-dagre.ts index 921cb57ae7e..8b004375a4a 100644 --- a/packages/g6/__tests__/demo/static/controller-layout-dagre.ts +++ b/packages/g6/__tests__/demo/static/controller-layout-dagre.ts @@ -21,7 +21,6 @@ export const controllerLayoutDagre: StaticTestCase = async ({ canvas, animation edge: { style: { type: 'polyline', - // TODO polyline }, }, }; diff --git a/packages/g6/__tests__/demo/static/controller-layout-dendrogram.ts b/packages/g6/__tests__/demo/static/controller-layout-dendrogram.ts index 85a2577ad84..7fdf3f9c4cf 100644 --- a/packages/g6/__tests__/demo/static/controller-layout-dendrogram.ts +++ b/packages/g6/__tests__/demo/static/controller-layout-dendrogram.ts @@ -17,11 +17,17 @@ export const controllerLayoutDendrogram: StaticTestCase = async ({ canvas, anima animation, }, node: { - style: { width: 20, height: 20, labelText: (data) => data.id, labelPosition: 'right', labelMaxWidth: 200 }, + style: { + width: 20, + height: 20, + labelText: (data) => data.id, + labelPosition: 'right', + labelMaxWidth: 200, + }, }, edge: { style: { - type: 'polyline', + type: 'cubic-horizontal', }, }, zoom: 0.5, diff --git a/packages/g6/__tests__/demo/static/controller-layout-indented.ts b/packages/g6/__tests__/demo/static/controller-layout-indented.ts index 43190c0f987..a015f01baab 100644 --- a/packages/g6/__tests__/demo/static/controller-layout-indented.ts +++ b/packages/g6/__tests__/demo/static/controller-layout-indented.ts @@ -26,7 +26,6 @@ export const controllerLayoutIndented: StaticTestCase = async ({ canvas, animati edge: { style: { type: 'polyline', - // TODO polyline }, }, zoom: 0.5, diff --git a/packages/g6/__tests__/integration/snapshots/animation/controller-element-1000(3_3).svg b/packages/g6/__tests__/integration/snapshots/animation/controller-element-1000(3_3).svg index 44d6c221bf9..dbb392e66c0 100644 --- a/packages/g6/__tests__/integration/snapshots/animation/controller-element-1000(3_3).svg +++ b/packages/g6/__tests__/integration/snapshots/animation/controller-element-1000(3_3).svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/animation/controller-element-200(2_3).svg b/packages/g6/__tests__/integration/snapshots/animation/controller-element-200(2_3).svg index 6d6895ebfe5..afca458861e 100644 --- a/packages/g6/__tests__/integration/snapshots/animation/controller-element-200(2_3).svg +++ b/packages/g6/__tests__/integration/snapshots/animation/controller-element-200(2_3).svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + - + @@ -53,11 +53,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + - + - + @@ -53,11 +53,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -69,11 +69,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -86,11 +86,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -103,11 +103,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -120,11 +120,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -137,11 +137,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -154,11 +154,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/animation/controller-element-position-200(2_3).svg b/packages/g6/__tests__/integration/snapshots/animation/controller-element-position-200(2_3).svg index 75fc1af3b4b..ed6a18b3d17 100644 --- a/packages/g6/__tests__/integration/snapshots/animation/controller-element-position-200(2_3).svg +++ b/packages/g6/__tests__/integration/snapshots/animation/controller-element-position-200(2_3).svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -69,11 +69,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -86,11 +86,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -103,11 +103,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -120,11 +120,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -137,11 +137,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -154,11 +154,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/animation/controller-element-state-0(1_2).svg b/packages/g6/__tests__/integration/snapshots/animation/controller-element-state-0(1_2).svg index 211661af310..38ae63552cf 100644 --- a/packages/g6/__tests__/integration/snapshots/animation/controller-element-state-0(1_2).svg +++ b/packages/g6/__tests__/integration/snapshots/animation/controller-element-state-0(1_2).svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/animation/controller-element-state-1000(2_2).svg b/packages/g6/__tests__/integration/snapshots/animation/controller-element-state-1000(2_2).svg index 4e96506e46f..34cceb450c9 100644 --- a/packages/g6/__tests__/integration/snapshots/animation/controller-element-state-1000(2_2).svg +++ b/packages/g6/__tests__/integration/snapshots/animation/controller-element-state-1000(2_2).svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/static/controller-element-position.svg b/packages/g6/__tests__/integration/snapshots/static/controller-element-position.svg index 2c9d7315a08..4c068dc837e 100644 --- a/packages/g6/__tests__/integration/snapshots/static/controller-element-position.svg +++ b/packages/g6/__tests__/integration/snapshots/static/controller-element-position.svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -69,11 +69,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -86,11 +86,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -103,11 +103,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -120,11 +120,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -137,11 +137,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -154,11 +154,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/static/controller-element-visibility.svg b/packages/g6/__tests__/integration/snapshots/static/controller-element-visibility.svg index b42832ab27c..4b0b372e518 100644 --- a/packages/g6/__tests__/integration/snapshots/static/controller-element-visibility.svg +++ b/packages/g6/__tests__/integration/snapshots/static/controller-element-visibility.svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + - + - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + - + - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/static/controller-layout-circular.svg b/packages/g6/__tests__/integration/snapshots/static/controller-layout-circular.svg index 05c77300c4f..b4b075af413 100644 --- a/packages/g6/__tests__/integration/snapshots/static/controller-layout-circular.svg +++ b/packages/g6/__tests__/integration/snapshots/static/controller-layout-circular.svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -69,11 +69,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -86,11 +86,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -103,11 +103,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -120,11 +120,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -137,11 +137,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -154,11 +154,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -171,11 +171,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -188,11 +188,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -205,11 +205,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -222,11 +222,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -239,11 +239,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -256,11 +256,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -273,11 +273,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -290,11 +290,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -307,11 +307,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -324,11 +324,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -341,11 +341,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -358,11 +358,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -375,11 +375,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -392,11 +392,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -409,11 +409,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -426,11 +426,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -443,11 +443,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -460,11 +460,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -477,11 +477,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -494,11 +494,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -511,11 +511,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -528,11 +528,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -545,11 +545,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -562,11 +562,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -579,11 +579,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -596,11 +596,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -613,11 +613,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -630,11 +630,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -647,11 +647,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -664,11 +664,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -681,11 +681,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -698,11 +698,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -715,11 +715,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -732,11 +732,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -749,11 +749,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -766,11 +766,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -783,11 +783,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -800,11 +800,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -817,11 +817,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -834,11 +834,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -851,11 +851,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -868,11 +868,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -885,11 +885,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -902,11 +902,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -919,11 +919,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -936,11 +936,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -953,11 +953,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -970,11 +970,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -987,11 +987,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1004,11 +1004,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1021,11 +1021,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1038,11 +1038,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1055,11 +1055,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1072,11 +1072,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1089,11 +1089,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/static/controller-layout-d3-force.svg b/packages/g6/__tests__/integration/snapshots/static/controller-layout-d3-force.svg index 68bac37bfac..3a2389a122f 100644 --- a/packages/g6/__tests__/integration/snapshots/static/controller-layout-d3-force.svg +++ b/packages/g6/__tests__/integration/snapshots/static/controller-layout-d3-force.svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -69,11 +69,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -86,11 +86,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -103,11 +103,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -120,11 +120,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -137,11 +137,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -154,11 +154,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -171,11 +171,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -188,11 +188,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -205,11 +205,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -222,11 +222,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -239,11 +239,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -256,11 +256,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -273,11 +273,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -290,11 +290,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -307,11 +307,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -324,11 +324,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -341,11 +341,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -358,11 +358,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -375,11 +375,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -392,11 +392,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -409,11 +409,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -426,11 +426,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -443,11 +443,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -460,11 +460,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -477,11 +477,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -494,11 +494,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -511,11 +511,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -528,11 +528,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -545,11 +545,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -562,11 +562,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -579,11 +579,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -596,11 +596,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -613,11 +613,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -630,11 +630,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -647,11 +647,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -664,11 +664,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -681,11 +681,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -698,11 +698,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -715,11 +715,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -732,11 +732,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -749,11 +749,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -766,11 +766,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -783,11 +783,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -800,11 +800,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -817,11 +817,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -834,11 +834,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -851,11 +851,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -868,11 +868,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -885,11 +885,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -902,11 +902,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -919,11 +919,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -936,11 +936,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -953,11 +953,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -970,11 +970,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -987,11 +987,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1004,11 +1004,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1021,11 +1021,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1038,11 +1038,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1055,11 +1055,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1072,11 +1072,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1089,11 +1089,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/static/controller-layout-dagre.svg b/packages/g6/__tests__/integration/snapshots/static/controller-layout-dagre.svg index e510e0c783f..044e8a7df9f 100644 --- a/packages/g6/__tests__/integration/snapshots/static/controller-layout-dagre.svg +++ b/packages/g6/__tests__/integration/snapshots/static/controller-layout-dagre.svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -69,11 +69,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -86,11 +86,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -103,11 +103,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -120,11 +120,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -137,11 +137,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -154,11 +154,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -171,11 +171,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -188,11 +188,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -205,11 +205,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/static/controller-layout-dendrogram.svg b/packages/g6/__tests__/integration/snapshots/static/controller-layout-dendrogram.svg index 24f6e304584..2aafeae188f 100644 --- a/packages/g6/__tests__/integration/snapshots/static/controller-layout-dendrogram.svg +++ b/packages/g6/__tests__/integration/snapshots/static/controller-layout-dendrogram.svg @@ -22,7 +22,7 @@ @@ -39,7 +39,7 @@ @@ -56,7 +56,7 @@ @@ -73,7 +73,7 @@ @@ -90,7 +90,7 @@ @@ -107,7 +107,7 @@ @@ -124,7 +124,7 @@ @@ -141,7 +141,7 @@ @@ -158,7 +158,7 @@ @@ -175,7 +175,7 @@ @@ -192,7 +192,7 @@ @@ -209,7 +209,7 @@ @@ -226,7 +226,7 @@ @@ -243,7 +243,7 @@ @@ -260,7 +260,7 @@ @@ -277,7 +277,7 @@ @@ -294,7 +294,7 @@ @@ -311,7 +311,7 @@ @@ -328,7 +328,7 @@ @@ -345,7 +345,7 @@ @@ -362,7 +362,7 @@ @@ -379,7 +379,7 @@ @@ -396,7 +396,7 @@ @@ -413,7 +413,7 @@ @@ -430,7 +430,7 @@ @@ -447,7 +447,7 @@ @@ -464,7 +464,7 @@ @@ -481,7 +481,7 @@ @@ -498,7 +498,7 @@ @@ -515,7 +515,7 @@ diff --git a/packages/g6/__tests__/integration/snapshots/static/controller-layout-grid.svg b/packages/g6/__tests__/integration/snapshots/static/controller-layout-grid.svg index 8e41033de8f..ed13d8586f0 100644 --- a/packages/g6/__tests__/integration/snapshots/static/controller-layout-grid.svg +++ b/packages/g6/__tests__/integration/snapshots/static/controller-layout-grid.svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -69,11 +69,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -86,11 +86,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -103,11 +103,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -120,11 +120,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -137,11 +137,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -154,11 +154,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -171,11 +171,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -188,11 +188,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -205,11 +205,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -222,11 +222,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -239,11 +239,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -256,11 +256,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -273,11 +273,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -290,11 +290,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -307,11 +307,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -324,11 +324,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -341,11 +341,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -358,11 +358,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -375,11 +375,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -392,11 +392,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -409,11 +409,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -426,11 +426,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -443,11 +443,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -460,11 +460,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -477,11 +477,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -494,11 +494,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -511,11 +511,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -528,11 +528,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -545,11 +545,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -562,11 +562,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -579,11 +579,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -596,11 +596,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -613,11 +613,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -630,11 +630,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -647,11 +647,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -664,11 +664,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -681,11 +681,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -698,11 +698,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -715,11 +715,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -732,11 +732,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -749,11 +749,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -766,11 +766,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -783,11 +783,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -800,11 +800,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -817,11 +817,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -834,11 +834,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -851,11 +851,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -868,11 +868,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -885,11 +885,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -902,11 +902,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -919,11 +919,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -936,11 +936,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -953,11 +953,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -970,11 +970,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -987,11 +987,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1004,11 +1004,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1021,11 +1021,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1038,11 +1038,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1055,11 +1055,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1072,11 +1072,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1089,11 +1089,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/integration/snapshots/static/graph-element.svg b/packages/g6/__tests__/integration/snapshots/static/graph-element.svg index 23e1433fa86..6c48a3e9266 100644 --- a/packages/g6/__tests__/integration/snapshots/static/graph-element.svg +++ b/packages/g6/__tests__/integration/snapshots/static/graph-element.svg @@ -18,11 +18,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -35,11 +35,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -52,11 +52,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -69,11 +69,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -86,11 +86,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -103,11 +103,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -120,11 +120,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -137,11 +137,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -154,11 +154,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -171,11 +171,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -188,11 +188,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -205,11 +205,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -222,11 +222,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -239,11 +239,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -256,11 +256,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -273,11 +273,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -290,11 +290,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -307,11 +307,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -324,11 +324,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -341,11 +341,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -358,11 +358,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -375,11 +375,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -392,11 +392,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -409,11 +409,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -426,11 +426,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -443,11 +443,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -460,11 +460,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -477,11 +477,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -494,11 +494,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -511,11 +511,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -528,11 +528,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -545,11 +545,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -562,11 +562,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -579,11 +579,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -596,11 +596,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -613,11 +613,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -630,11 +630,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -647,11 +647,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -664,11 +664,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -681,11 +681,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -698,11 +698,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -715,11 +715,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -732,11 +732,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -749,11 +749,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -766,11 +766,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -783,11 +783,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -800,11 +800,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -817,11 +817,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -834,11 +834,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -851,11 +851,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -868,11 +868,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -885,11 +885,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -902,11 +902,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -919,11 +919,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -936,11 +936,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -953,11 +953,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -970,11 +970,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -987,11 +987,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1004,11 +1004,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + @@ -1021,11 +1021,11 @@ marker-end="false" transform="matrix(1,0,0,1,0,0)" > - + diff --git a/packages/g6/__tests__/unit/registry.spec.ts b/packages/g6/__tests__/unit/registry.spec.ts index 467aeebef69..9b809faed10 100644 --- a/packages/g6/__tests__/unit/registry.spec.ts +++ b/packages/g6/__tests__/unit/registry.spec.ts @@ -1,5 +1,17 @@ import { pick } from '@antv/util'; -import { Circle, Cubic, Ellipse, Line, Polyline, Quadratic, Rect, Star, Triangle } from '../../src/elements'; +import { + Circle, + Cubic, + CubicHorizontal, + CubicVertical, + Ellipse, + Line, + Polyline, + Quadratic, + Rect, + Star, + Triangle, +} from '../../src/elements'; import { getPlugin, getPlugins, register, registerBuiltInPlugins } from '../../src/registry'; import { dark, light } from '../../src/themes'; @@ -19,6 +31,8 @@ describe('registry', () => { line: Line, polyline: Polyline, quadratic: Quadratic, + 'cubic-horizontal': CubicHorizontal, + 'cubic-vertical': CubicVertical, }); expect(getPlugins('combo')).toEqual({}); expect(getPlugins('theme')).toEqual({ diff --git a/packages/g6/__tests__/unit/runtime/element.spec.ts b/packages/g6/__tests__/unit/runtime/element.spec.ts index 5a21516d8b6..28ca03010e2 100644 --- a/packages/g6/__tests__/unit/runtime/element.spec.ts +++ b/packages/g6/__tests__/unit/runtime/element.spec.ts @@ -157,8 +157,6 @@ describe('ElementController', () => { expect(omit(elementController.getElementComputedStyle('edge', edge1Id), ['sourceNode', 'targetNode'])).toEqual({ ...LIGHT_THEME.edge?.style, - sourcePoint: [0, 0, 0], - targetPoint: [0, 0, 0], color: BUILT_IN_PALETTES.oranges.at(-1), }); @@ -168,12 +166,6 @@ describe('ElementController', () => { ...LIGHT_THEME.edge?.state?.selected, lineWidth: 4, stroke: 'red', - // 在运行时环境测试 / Test in runtime environment - sourceNode: undefined, - targetNode: undefined, - // 暂未实现 / Not implemented yet - sourcePoint: [0, 0, 0], - targetPoint: [0, 0, 0], color: BUILT_IN_PALETTES.oranges.at(-2), }); diff --git a/packages/g6/__tests__/unit/utils/point.spec.ts b/packages/g6/__tests__/unit/utils/point.spec.ts index e045e69bd16..3d6393b4ae3 100644 --- a/packages/g6/__tests__/unit/utils/point.spec.ts +++ b/packages/g6/__tests__/unit/utils/point.spec.ts @@ -129,6 +129,22 @@ describe('Point Functions', () => { }, }); expect(getEllipseIntersectPoint([110, 100], circle.getBounds())).toEqual([101, 100]); + + const circle2 = new Circle({ + style: { + r: 20, + }, + }); + expect(getEllipseIntersectPoint([0, 0], circle2.getBounds())).toEqual([0, 0, 0]); + + const circle3 = new Circle({ + style: { + cx: 100, + cy: 100, + r: 20, + }, + }); + expect(getEllipseIntersectPoint([100, 100], circle3.getBounds())).toEqual([100, 100, 0]); }); it('findNearestPoints', () => { diff --git a/packages/g6/src/animations/executor.ts b/packages/g6/src/animations/executor.ts index 7855d2368e9..c848e9ab74a 100644 --- a/packages/g6/src/animations/executor.ts +++ b/packages/g6/src/animations/executor.ts @@ -15,13 +15,13 @@ const DEFAULT_ANIMATION_OPTIONS: KeyframeAnimationOptions = { * 动画 Spec 执行器 * * Animation Spec Executor - * @param shape - 要执行动画的图形 | shape to execute animation + * @param element - 要执行动画的图形 | shape to execute animation * @param animation - 动画 Spec | animation specification * @param commonEffectTiming - 动画公共配置 | common animation configuration * @param context - 动画执行上下文 | animation execution context * @returns 动画实例 | animation instance */ -export const executor: AnimationExecutor = (shape, animation, commonEffectTiming, context) => { +export const executor: AnimationExecutor = (element, animation, commonEffectTiming, context) => { if (!animation) return null; const { animationsFilter = () => true } = context; @@ -42,21 +42,21 @@ export const executor: AnimationExecutor = (shape, animation, commonEffectTiming */ const getKeyframeStyle = (shapeID?: string) => { if (shapeID) { - const target = shape.getElementById(shapeID) as DisplayObject; - const name = `get${upperFirst(shapeID)}Style` as keyof typeof shape; + const shape = element.getElementById(shapeID) as DisplayObject; + const name = `get${upperFirst(shapeID)}Style` as keyof typeof element; - const caller: (attrs?: Record) => Record = - shape?.[name]?.bind(shape) || ((attrs) => attrs); + const styler: (attrs?: Record) => Record = + element?.[name]?.bind(element) || ((attrs) => attrs); - const fromStyle = caller?.(originalStyle) || {}; - const toStyle = caller?.() || {}; + const fromStyle = styler?.({ ...element.attributes, ...originalStyle }) || {}; + const toStyle = { ...shape.attributes }; - return { target, fromStyle, toStyle }; + return { shape, fromStyle, toStyle }; } else { - const target = shape; + const shape = element; const fromStyle = originalStyle; - const toStyle = { ...target.attributes, ...modifiedStyle }; - return { target, fromStyle, toStyle }; + const toStyle = { ...shape.attributes, ...modifiedStyle }; + return { shape, fromStyle, toStyle }; } }; @@ -65,9 +65,9 @@ export const executor: AnimationExecutor = (shape, animation, commonEffectTiming const results = animations .map(({ fields, shape: shapeID, states: enabledStates, ...individualEffectTiming }) => { if (enabledStates === undefined || enabledStates?.some((state) => states.includes(state))) { - const { target, fromStyle, toStyle } = getKeyframeStyle(shapeID); + const { shape, fromStyle, toStyle } = getKeyframeStyle(shapeID); - if (!target) return null; + if (!shape) return null; const keyframes: Keyframe[] = [{}, {}]; @@ -76,7 +76,7 @@ export const executor: AnimationExecutor = (shape, animation, commonEffectTiming Object.assign(keyframes[1], { [attr]: toStyle[attr] ?? inferDefaultValue(attr) }); }); - const result = executeAnimation(target, preprocessKeyframes(keyframes), { + const result = executeAnimation(shape, preprocessKeyframes(keyframes), { ...DEFAULT_ANIMATION_OPTIONS, ...commonEffectTiming, ...individualEffectTiming, @@ -92,7 +92,7 @@ export const executor: AnimationExecutor = (shape, animation, commonEffectTiming const mainResult = keyResult! || results?.[0]; - if (mainResult === null) return null; + if (!mainResult) return null; return createAnimationsProxy( mainResult, diff --git a/packages/g6/src/elements/index.ts b/packages/g6/src/elements/index.ts index 56071beac38..bedb8915233 100644 --- a/packages/g6/src/elements/index.ts +++ b/packages/g6/src/elements/index.ts @@ -1,2 +1,2 @@ -export { Cubic, Line, Polyline, Quadratic } from './edges'; +export { Cubic, CubicHorizontal, CubicVertical, Line, Polyline, Quadratic } from './edges'; export { Circle, Ellipse, Rect, Star, Triangle } from './nodes'; diff --git a/packages/g6/src/registry/build-in.ts b/packages/g6/src/registry/build-in.ts index 1aafafa63e5..48cc1485aac 100644 --- a/packages/g6/src/registry/build-in.ts +++ b/packages/g6/src/registry/build-in.ts @@ -1,5 +1,17 @@ import { fade, translate } from '../animations'; -import { Circle, Cubic, Ellipse, Line, Polyline, Quadratic, Rect, Star, Triangle } from '../elements'; +import { + Circle, + Cubic, + CubicHorizontal, + CubicVertical, + Ellipse, + Line, + Polyline, + Quadratic, + Rect, + Star, + Triangle, +} from '../elements'; import { CircularLayout, ComboCombinedLayout, @@ -37,6 +49,8 @@ export const BUILT_IN_PLUGINS = { line: Line, polyline: Polyline, quadratic: Quadratic, + 'cubic-horizontal': CubicHorizontal, + 'cubic-vertical': CubicVertical, }, layout: { 'combo-combined': ComboCombinedLayout, diff --git a/packages/g6/src/runtime/element.ts b/packages/g6/src/runtime/element.ts index c1da95a1c25..002c4975d75 100644 --- a/packages/g6/src/runtime/element.ts +++ b/packages/g6/src/runtime/element.ts @@ -411,12 +411,7 @@ export class ElementController { const sourceNode = this.getElement>(source); const targetNode = this.getElement>(target); - const sourcePoint = sourceNode?.getCenter() || [0, 0, 0]; - const targetPoint = targetNode?.getCenter() || [0, 0, 0]; - return { - sourcePoint, - targetPoint, sourceNode, targetNode, }; @@ -531,27 +526,26 @@ export class ElementController { // 创建渲染任务 / Create render task const renderContext = { animation: true }; - const destroyTasks = this.getDestroyTasks( - { nodes: nodesToRemove, edges: edgesToRemove, combos: combosToRemove }, - renderContext, - ); + const dataToDestroy = { nodes: nodesToRemove, edges: edgesToRemove, combos: combosToRemove }; + const destroyTasks = this.getDestroyTasks(dataToDestroy, renderContext); - const createTasks = this.getCreateTasks( - { nodes: nodesToAdd, edges: edgesToAdd, combos: combosToAdd }, - renderContext, - ); + const dataToCreate = { nodes: nodesToAdd, edges: edgesToAdd, combos: combosToAdd }; + const createTasks = this.getCreateTasks(dataToCreate, renderContext); - const updateTasks = this.getUpdateTasks( - { nodes: nodesToUpdate, edges: deduplicate(edgesToUpdate, idOf), combos: deduplicate(combosToUpdate, idOf) }, - renderContext, - ); + const dataToUpdate = { + nodes: nodesToUpdate, + edges: deduplicate(edgesToUpdate, idOf), + combos: deduplicate(combosToUpdate, idOf), + }; + const updateTasks = this.getUpdateTasks(dataToUpdate, renderContext); + const diffData = { create: dataToCreate, update: dataToUpdate, destroy: dataToDestroy }; return executeAnimatableTasks([...destroyTasks, ...createTasks, ...updateTasks], { before: () => this.emit(new DrawEvent(GraphEvent.BEFORE_DRAW)), beforeAnimate: (animation) => - this.emit(new AnimateEvent(GraphEvent.BEFORE_ANIMATE, AnimationTypeEnum.DRAW, animation)), + this.emit(new AnimateEvent(GraphEvent.BEFORE_ANIMATE, AnimationTypeEnum.DRAW, animation, diffData)), afterAnimate: (animation) => - this.emit(new AnimateEvent(GraphEvent.AFTER_ANIMATE, AnimationTypeEnum.DRAW, animation)), + this.emit(new AnimateEvent(GraphEvent.AFTER_ANIMATE, AnimationTypeEnum.DRAW, animation, diffData)), after: () => this.emit(new DrawEvent(GraphEvent.AFTER_DRAW)), })?.finished.then(() => {}); } @@ -573,7 +567,6 @@ export class ElementController { const id = idOf(datum); const currentShape = this.getElement(id); if (currentShape) return () => null; - const renderData = this.getElementComputedStyle(elementType, id); // get shape constructor @@ -701,11 +694,9 @@ export class ElementController { const { nodes: nodeLikeResults, edges: edgeResults } = layoutResult; if (Object.keys(nodeLikeResults).length === 0 && Object.keys(edgeResults).length === 0) return null; - // TODO dagre 布局计算出来的 controlPoints 会导致边异常,需要处理 - // controlPoints calculated by dagre layout will cause the edge to be abnormal and need to be handled - // Object.entries(edgeResults).forEach(([id, style]) => { - // this.setRuntimeStyle(id, style); - // }); + Object.entries(edgeResults).forEach(([id, style]) => { + this.setRuntimeStyle(id, style); + }); this.updateNodeLikePosition(nodeLikeResults, animation, Object.keys(edgeResults)); } diff --git a/packages/g6/src/themes/dark.ts b/packages/g6/src/themes/dark.ts index 39750640f09..4d0204a1a1e 100644 --- a/packages/g6/src/themes/dark.ts +++ b/packages/g6/src/themes/dark.ts @@ -23,7 +23,7 @@ export const dark: Theme = { state: {}, animation: { enter: 'fade', - update: [{ fields: ['sourcePoint', 'targetPoint', 'stroke'] }], + update: [{ fields: ['stroke'] }, { fields: ['path'], shape: 'key' }], exit: 'fade', show: 'fade', hide: 'fade', diff --git a/packages/g6/src/themes/light.ts b/packages/g6/src/themes/light.ts index 2f4c1aa48a0..b2822a10d90 100644 --- a/packages/g6/src/themes/light.ts +++ b/packages/g6/src/themes/light.ts @@ -23,7 +23,7 @@ export const light: Theme = { state: {}, animation: { enter: 'fade', - update: [{ fields: ['sourcePoint', 'targetPoint', 'stroke'] }], + update: [{ fields: ['stroke'] }, { fields: ['path'], shape: 'key' }], exit: 'fade', show: 'fade', hide: 'fade', diff --git a/packages/g6/src/utils/animation.ts b/packages/g6/src/utils/animation.ts index 2e9c6464d13..b19d5f93ace 100644 --- a/packages/g6/src/utils/animation.ts +++ b/packages/g6/src/utils/animation.ts @@ -1,6 +1,7 @@ import type { DisplayObject, IAnimation } from '@antv/g'; import { isEqual, isNil } from '@antv/util'; import type { AnimatableTask, Keyframe } from '../types'; +import { isNode } from './is'; import { getDescendantShapes } from './shape'; export function createAnimationsProxy(animations: IAnimation[]): IAnimation | null; @@ -72,7 +73,8 @@ export function preprocessKeyframes(keyframes: Keyframe[]): Keyframe[] { // 属性值不能为空 / property value cannot be empty values.some((value) => isNil(value)) || // 属性值必须不完全一致 / property value must not be exactly the same - values.every((value) => isEqual(value, values[0])) + // 属性值可以是同一节点 / property value can be the same node + values.every((value) => !isNode(value) && isEqual(value, values[0])) ) { delete propertyIndexedKeyframes[key]; } @@ -107,6 +109,7 @@ export function executeAnimation( keyframes: Keyframe[], options: KeyframeAnimationOptions, ) { + if (keyframes.length === 0) return null; const inheritedAttrs = ['opacity']; const needInheritAnimation = keyframes.some((keyframe) => diff --git a/packages/g6/src/utils/layout.ts b/packages/g6/src/utils/layout.ts index 7277d67f0bf..ef5eae9ec28 100644 --- a/packages/g6/src/utils/layout.ts +++ b/packages/g6/src/utils/layout.ts @@ -58,7 +58,7 @@ export function pickLayoutResult(result: LayoutMapping): LayoutResult { const { data } = edge; const result: Record = {}; if ('controlPoints' in data) result.controlPoints = data.controlPoints!.map(parsePoint); - if ('points' in data) result.points = data.points!.map(parsePoint); + // if ('points' in data) result.points = data.points!.map(parsePoint); return [id, result]; }), ), diff --git a/packages/g6/src/utils/point.ts b/packages/g6/src/utils/point.ts index 0514aab433d..a7e04d422c7 100644 --- a/packages/g6/src/utils/point.ts +++ b/packages/g6/src/utils/point.ts @@ -203,14 +203,15 @@ export function getRectIntersectPoint(p: Point, bbox: AABB): Point { * @returns 交点 | intersection */ export function getEllipseIntersectPoint(p: Point, bbox: AABB): Point { - const rx = getBBoxWidth(bbox) / 2; - const ry = getBBoxHeight(bbox) / 2; const center = bbox.center; - const vec = subtract(p, center); - let radians = angle(vec, [1, 0, 0]); + if (isNaN(radians)) return center; + if (radians < 0) radians += Math.PI * 2; + + const rx = getBBoxWidth(bbox) / 2; + const ry = getBBoxHeight(bbox) / 2; return [ center[0] + Math.abs(rx * Math.cos(radians)) * Math.sign(vec[0]), center[1] + Math.abs(ry * Math.sin(radians)) * Math.sign(vec[1]),