You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2019/09/18 13:55:16 UTC

[incubator-echarts] 01/01: feat(force): Add initial friction config in force layout #11024

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch force-enhance
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git

commit c1507f2b5324b963ad938cb49b4c8e0e2ff1a1e3
Author: pissang <bm...@gmail.com>
AuthorDate: Wed Sep 18 21:54:52 2019 +0800

    feat(force): Add initial friction config in force layout #11024
---
 src/chart/graph/GraphSeries.js | 2 ++
 src/chart/graph/forceHelper.js | 5 +++--
 src/chart/graph/forceLayout.js | 3 ++-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/chart/graph/GraphSeries.js b/src/chart/graph/GraphSeries.js
index a69f7ad..2ea09b2 100644
--- a/src/chart/graph/GraphSeries.js
+++ b/src/chart/graph/GraphSeries.js
@@ -215,6 +215,8 @@ var GraphSeries = echarts.extendSeriesModel({
             // Node repulsion. Can be an array to represent range.
             repulsion: [0, 50],
             gravity: 0.1,
+            // Initial friction
+            friction: 0.6,
 
             // Edge length. Can be an array to represent range.
             edgeLength: 30,
diff --git a/src/chart/graph/forceHelper.js b/src/chart/graph/forceHelper.js
index bce7981..291d965 100644
--- a/src/chart/graph/forceHelper.js
+++ b/src/chart/graph/forceHelper.js
@@ -69,11 +69,12 @@ export function forceLayout(nodes, edges, opts) {
     // var k = scale * Math.sqrt(width * height / nodes.length);
     // var k2 = k * k;
 
-    var friction = 0.6;
+    var initialFriction = opts.friction == null ? 0.6 : opts.friction;
+    var friction = initialFriction;
 
     return {
         warmUp: function () {
-            friction = 0.5;
+            friction = initialFriction * 0.8;
         },
 
         setFixed: function (idx) {
diff --git a/src/chart/graph/forceLayout.js b/src/chart/graph/forceLayout.js
index af999bf..53ffcec 100644
--- a/src/chart/graph/forceLayout.js
+++ b/src/chart/graph/forceLayout.js
@@ -95,7 +95,8 @@ export default function (ecModel) {
             var rect = coordSys.getBoundingRect();
             var forceInstance = forceLayout(nodes, edges, {
                 rect: rect,
-                gravity: forceModel.get('gravity')
+                gravity: forceModel.get('gravity'),
+                friction: forceModel.get('friction')
             });
             var oldStep = forceInstance.step;
             forceInstance.step = function (cb) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org