Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few additions to springyui.js #108

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions springyui.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ Copyright (c) 2010 Dennis Hotson

jQuery.fn.springy = function(params) {
var graph = this.graph = params.graph || new Springy.Graph();
var nodeFont = "16px Verdana, sans-serif";
var edgeFont = "8px Verdana, sans-serif";
var nodeFont = params.nodeFont || "16px Verdana, sans-serif";
var edgeFont = params.edgeFont || "8px Verdana, sans-serif";
var stiffness = params.stiffness || 400.0;
var repulsion = params.repulsion || 400.0;
var damping = params.damping || 0.5;
var minEnergyThreshold = params.minEnergyThreshold || 0.00001;
var maxSpeed = params.maxSpeed || Infinity;
var nodeSelected = params.nodeSelected || null;
var nodeImages = {};
var edgeLabelsUpright = true;

var canvas = this[0];
var ctx = canvas.getContext("2d");

var layout = this.layout = new Springy.Layout.ForceDirected(graph, stiffness, repulsion, damping, minEnergyThreshold);
var layout = this.layout = new Springy.Layout.ForceDirected(graph, stiffness, repulsion, damping, minEnergyThreshold, maxSpeed);

// calculate bounding box of graph layout.. with ease-in
var currentBB = layout.getBoundingBox();
Expand Down Expand Up @@ -93,6 +94,9 @@ jQuery.fn.springy = function(params) {
}
}

if (nearest.node && nearest.node.data && nearest.node.data.onmousedown) {
nearest.node.data.onmousedown(selected, e, toScreen(nearest.point.p));
}
renderer.start();
});

Expand All @@ -101,9 +105,8 @@ jQuery.fn.springy = function(params) {
var pos = jQuery(this).offset();
var p = fromScreen({x: e.pageX - pos.left, y: e.pageY - pos.top});
selected = layout.nearest(p);
node = selected.node;
if (node && node.data && node.data.ondoubleclick) {
node.data.ondoubleclick();
if (selected && selected.node && selected.node.data && selected.node.data.ondoubleclick) {
selected.node.data.ondoubleclick(selected, e, toScreen(layout.point(node).p));
}
});

Expand All @@ -117,6 +120,9 @@ jQuery.fn.springy = function(params) {
dragged.point.p.y = p.y;
}

if (nearest.node && nearest.node.data && nearest.node.data.onmousemove) {
nearest.node.data.onmousemove(nearest, e, toScreen(nearest.point.p));
}
renderer.start();
});

Expand Down