Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

scaling also considers node sizes in Graph.rescale()

  • Loading branch information...
commit 63e8e6bfe50e66ff9dce15d5b9ecbd89e07dbb8f 1 parent 8279471
@jacomyal authored
Showing with 14 additions and 19 deletions.
  1. +14 −19 src/core/graph.js
View
33 src/core/graph.js
@@ -441,17 +441,17 @@ function Graph() {
yMin = Math.min(node['y'], yMin || node['y']);
});
+ xMax += self.p.maxNodeSize || sizeMax;
+ xMin -= self.p.maxNodeSize || sizeMax;
+ yMax += self.p.maxNodeSize || sizeMax;
+ yMin -= self.p.maxNodeSize || sizeMax;
+
var scale = self.p.scalingMode == 'outside' ?
Math.max(w / Math.max(xMax - xMin, 1),
h / Math.max(yMax - yMin, 1)) :
Math.min(w / Math.max(xMax - xMin, 1),
h / Math.max(yMax - yMin, 1));
- xMax += self.p.maxNodeSize;
- xMin -= self.p.maxNodeSize;
- yMax += self.p.maxNodeSize;
- yMin -= self.p.maxNodeSize;
-
// Size homothetic parameters:
var a, b;
if (!self.p.maxNodeSize && !self.p.minNodeSize) {
@@ -481,20 +481,15 @@ function Graph() {
parseNodes && self.nodes.forEach(function(node) {
node['displaySize'] = node['size'] * a + b;
- if (!node['fixed']) {
- node['displayX'] = (node['x'] - (xMax + xMin) / 2) * scale + w / 2;
- node['displayY'] = (node['y'] - (yMax + yMin) / 2) * scale + h / 2;
-
- if(node['displayX'] < self.p.maxNodeSize) {
- node['displayX'] += self.p.maxNodeSize;
- } else if(node['displayX'] >= (w - self.p.maxNodeSize)) {
- node['displayX'] -= self.p.maxNodeSize;
- }
- if(node['displayY'] < self.p.maxNodeSize) {
- node['displayY'] += self.p.maxNodeSize;
- } else if(node['displayY'] >= (h - self.p.maxNodeSize)) {
- node['displayY'] -= self.p.maxNodeSize;
- }
+ if (
+ !node['fixed'] ||
+ node['displayX'] == undefined ||
+ node['displayY'] == undefined
+ ) {
+ node['displayX'] = (node['x'] - (xMax + xMin) / 2) * scale +
+ w / 2;
+ node['displayY'] = (node['y'] - (yMax + yMin) / 2) * scale +
+ h / 2;
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.