Skip to content
This repository

Added support for preserving Cartesian coordinates. #77

Closed
wants to merge 1 commit into from

3 participants

Tim Crain computermacgyver Alexis Jacomy
Tim Crain

Currently node positions are not preserved when re-scaling the graph. This patch lets Cartesian coordinates be preserved if specified.

computermacgyver computermacgyver referenced this pull request in oxfordinternetinstitute/gephi-plugins
Open

Sigma and Gephi have inverse y axes #5

computermacgyver

This has been noted by several users of my gephi plugin using Sigma, and it would be great to get this pulled into the main repository.

Alexis Jacomy
Owner

I cannot merge this pull request since the code has recently been completely rewritten. Sorry, for this.
The old version is still accessible in the deprecated-v0.1 branch.

Alexis Jacomy
Owner

But it would be easy to port in the current version. The scaling part is now in the related middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 04, 2013
Tim Crain timdcrain Added support for preserving Cartesian coordinates. 3d9e1fa
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 13 additions and 3 deletions. Show diff stats Hide diff stats

  1. +13 3 src/core/graph.js
16 src/core/graph.js
@@ -31,7 +31,8 @@ function Graph() {
31 31 // - 'outside'
32 32 scalingMode: 'inside',
33 33 nodesPowRatio: 0.5,
34   - edgesPowRatio: 0
  34 + edgesPowRatio: 0,
  35 + cartesian: false
35 36 };
36 37
37 38 /**
@@ -468,6 +469,10 @@ function Graph() {
468 469 yMax += margin;
469 470 yMin -= margin;
470 471
  472 + // x- and y-ratios for preserving cartesian coordinates.
  473 + var xScale = w / (2 * Math.max(Math.abs(xMax), Math.abs(xMin)) + 2 * margin);
  474 + var yScale = h / (2 * Math.max(Math.abs(yMax), Math.abs(yMin)) + 2 * margin);
  475 +
471 476 scale = self.p.scalingMode == 'outside' ?
472 477 Math.max(w / Math.max(xMax - xMin, 1),
473 478 h / Math.max(yMax - yMin, 1)) :
@@ -504,8 +509,13 @@ function Graph() {
504 509 node['displaySize'] = node['size'] * a + b;
505 510
506 511 if (!node['fixed']) {
507   - node['displayX'] = (node['x'] - (xMax + xMin) / 2) * scale + w / 2;
508   - node['displayY'] = (node['y'] - (yMax + yMin) / 2) * scale + h / 2;
  512 + if (self.p.cartesian) {
  513 + node['displayX'] = node['x'] * xScale + w / 2;
  514 + node['displayY'] = -node['y'] * yScale + h / 2;
  515 + } else {
  516 + node['displayX'] = (node['x'] - (xMax + xMin) / 2) * scale + w / 2;
  517 + node['displayY'] = (node['y'] - (yMax + yMin) / 2) * scale + h / 2;
  518 + }
509 519 }
510 520 });
511 521

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.