Skip to content

Commit

Permalink
feat: fix the initial positions by equably distributing for layout to…
Browse files Browse the repository at this point in the history
… produce similar result.
  • Loading branch information
Yanyan-Wang committed Jul 22, 2020
1 parent 800fe3c commit af7d93f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
- fix: combo edge with uncorrect end points;
- fix: combo polyline edge with wrong path;
- fix: getViewCenter with padding problem;
- feat: allow user to configure the initial positions for empty combos;
- fix: cannot read property 'getModel' of null problem on contextmenu when the target is not an item;
- feat: optimize by hiding edges and shapes which are not keyShape while dragging canvas.
- feat: allow user to configure the initial positions for empty combos;
- feat: optimize by hiding edges and shapes which are not keyShape while dragging canvas;
- feat: fix the initial positions by equably distributing for layout to produce similar result.

#### 3.5.10
- fix: fitView and fitCenter with animate in the initial state;
Expand Down
4 changes: 2 additions & 2 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
window.g6 = require('./src/index.ts'); // import the source for debugging
// window.g6 = require('./dist/g6.min.js'); // import the package for webworker
// window.g6 = require('./src/index.ts'); // import the source for debugging
window.g6 = require('./dist/g6.min.js'); // import the package for webworker
window.insertCss = require('insert-css');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"site:deploy": "npm run site:build && gh-pages -d public",
"start": "npm run site:develop",
"test": "jest",
"test-live": "DEBUG_MODE=1 jest --watch ./tests/unit/behavior/drag-node-spec.ts",
"test-live": "DEBUG_MODE=1 jest --watch ./tests/unit/layout/force-spec.ts",
"lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx",
"watch": "father build -w",
"cdn": "antv-bin upload -n @antv/g6"
Expand Down
3 changes: 0 additions & 3 deletions src/graph/controller/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ export default class ItemController {
group: parent.addGroup(),
});
} else if (type === NODE) {
model.x = model.x || 0;
model.y = model.y || 0;

item = new Node({
model,
styles,
Expand Down
16 changes: 13 additions & 3 deletions src/graph/controller/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LAYOUT_MESSAGE } from '../../layout/worker/layoutConst';
import { isNaN } from '../../util/base';

import { IGraph } from '../../interface/graph';
import { path2Absolute } from '@antv/path-util';

const helper = {
// pollyfill
Expand Down Expand Up @@ -463,14 +464,23 @@ export default class LayoutController {
return false;
}
let allHavePos = true;
nodes.forEach(node => {
const width = graph.get('width') * 0.85;
const height = graph.get('height') * 0.85;
const nodeNum = nodes.length;
const horiNum = Math.sqrt(width * nodeNum / height);
const vertiNum = horiNum * height / width;
const horiGap = width / (horiNum - 1);
const vertiGap = height / (vertiNum - 1);
const beginX = center[0] - width / 2;
const beginY = center[1] - height / 2;
nodes.forEach((node, i) => {
if (isNaN(node.x)) {
allHavePos = false;
node.x = (Math.random() - 0.5) * 0.7 * graph.get('width') + center[0];
node.x = i % horiNum * horiGap + beginX;
}
if (isNaN(node.y)) {
allHavePos = false;
node.y = (Math.random() - 0.5) * 0.7 * graph.get('height') + center[1];
node.y = i / horiNum * vertiGap + beginY;
}
});
return allHavePos;
Expand Down
1 change: 0 additions & 1 deletion src/shape/edges/polyline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Shape.registerEdge(
offset,
);
const res = pointsToPolygon(polylinePoints);
console.log('path of polyline', points, source, target, polylinePoints, res)
return res;
},
},
Expand Down

0 comments on commit af7d93f

Please sign in to comment.