Skip to content

Commit

Permalink
Moved plotTree to Graph.Plot from ST.Plot
Browse files Browse the repository at this point in the history
  • Loading branch information
philogb committed Jan 17, 2010
1 parent b80dc4f commit e28e00a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 57 deletions.
6 changes: 3 additions & 3 deletions Source/Complex.js
Expand Up @@ -81,9 +81,9 @@ Complex.prototype = {
*/
set: function(c) {
c = c.getc(true);
this.x = c.x;
this.y = c.y;
c = c.getc(true);
this.x = c.x;
this.y = c.y;
},

/*
Expand Down
60 changes: 48 additions & 12 deletions Source/Graph.Plot.js
Expand Up @@ -452,6 +452,38 @@ Graph.Plot = {
});
},

/*
Plots a Subtree.
*/
plotTree: function(node, opt, animating) {
var that = this,
viz = this.viz,
canvas = viz.canvas,
config = this.config,
ctx = canvas.getCtx();
var nodeAlpha = node.getData('alpha');
Graph.Util.eachSubnode(node, function(elem) {
if(opt.plotSubtree(node, elem) && elem.exist && elem.drawn) {
var adj = node.getAdjacency(elem.id);
!animating && opt.onBeforePlotLine(adj);
ctx.globalAlpha = Math.min(nodeAlpha, elem.getData('alpha'));
that.plotLine(adj, canvas, animating);
!animating && opt.onAfterPlotLine(adj);
that.plotTree(elem, opt, animating);
}
});
if(node.drawn) {
!animating && opt.onBeforePlotNode(node);
this.plotNode(node, canvas, animating);
!animating && opt.onAfterPlotNode(node);
if(!opt.hideLabels && opt.withLabels && nodeAlpha >= 0.95)
this.labels.plotLabel(canvas, node, opt);
else
this.labels.hideLabel(node, false);
} else {
this.labels.hideLabel(node, true);
}
},

/*
Method: plotNode
Expand All @@ -465,18 +497,20 @@ Graph.Plot = {
*/
plotNode: function(node, canvas, animating) {
var width = node.getData('lineWidth');
var color = node.getData('color');
var alpha = node.getData('alpha');
var ctx = canvas.getCtx();

ctx.lineWidth = width;
ctx.fillStyle = color;
ctx.strokeStyle = color;
ctx.globalAlpha = alpha;

var f = node.getData('type');
this.nodeTypes[f].render.call(this, node, canvas, animating);
if(f != 'none') {
var width = node.getData('lineWidth');
var color = node.getData('color');
var alpha = node.getData('alpha');
var ctx = canvas.getCtx();

ctx.lineWidth = width;
ctx.fillStyle = color;
ctx.strokeStyle = color;
ctx.globalAlpha = alpha;

this.nodeTypes[f].render.call(this, node, canvas, animating);
}
},

/*
Expand All @@ -491,6 +525,8 @@ Graph.Plot = {
*/
plotLine: function(adj, canvas, animating) {
var f = adj.getData('type');
if(f != 'none') {
var width = adj.getData('lineWidth');
var color = adj.getData('color');
var ctx = canvas.getCtx();
Expand All @@ -499,8 +535,8 @@ Graph.Plot = {
ctx.fillStyle = color;
ctx.strokeStyle = color;

var f = adj.getData('type');
this.edgeTypes[f].call(this, adj, canvas, animating);
}
}

};
Expand Down
4 changes: 2 additions & 2 deletions Source/Graph.js
Expand Up @@ -894,8 +894,8 @@ Graph.Util = {
levelEnd = Number.MAX_VALUE - node._depth;
}
this.eachLevel(node, levelStart, levelEnd, function(n) {
ans.push(n);
}, flags);
ans.push(n);
}, flags);
return ans;
},

Expand Down
51 changes: 11 additions & 40 deletions Source/Spacetree.js
Expand Up @@ -1245,7 +1245,7 @@ ST.Plot = new Class({
Plots a subtree from the spacetree.
*/
plotSubtree: function(node, opt, scale, animating) {
var viz = this.viz, canvas = viz.canvas;
var viz = this.viz, canvas = viz.canvas, config = viz.config;
scale = Math.min(Math.max(0.001, scale), 1);
if(scale >= 0) {
node.drawn = false;
Expand All @@ -1254,46 +1254,17 @@ ST.Plot = new Class({
ctx.translate(diff.x, diff.y);
ctx.scale(scale, scale);
}
this.plotTree(node, !scale, opt, animating);
this.plotTree(node, $merge(opt, {
'withLabels': true,
'hideLabels': !!scale,
'plotSubtree': function(n, ch) {
var root = config.multitree && !('$orn' in node.data);
var orns = root && node.getData('orns');
return !root || orns.indexOf(elem.getData('orn')) > -1;
}
}), animating);
if(scale >= 0) node.drawn = true;
},
/*
Plots a Subtree.
*/
plotTree: function(node, plotLabel, opt, animating) {
var that = this,
viz = this.viz,
canvas = viz.canvas,
config = this.config,
ctx = canvas.getCtx();
var root = config.multitree && !('$orn' in node.data);
var orns = root && node.data.$orns;
var nodeAlpha = node.getData('alpha');
Graph.Util.eachSubnode(node, function(elem) {
//multitree root node check
if((!root || orns.indexOf(elem.data.$orn) > 0)
&& elem.exist && elem.drawn) {
var adj = node.getAdjacency(elem.id);
!animating && opt.onBeforePlotLine(adj);
ctx.globalAlpha = Math.min(nodeAlpha, elem.getData('alpha'));
that.plotLine(adj, canvas, animating);
!animating && opt.onAfterPlotLine(adj);
that.plotTree(elem, plotLabel, opt, animating);
}
});
if(node.drawn) {
!animating && opt.onBeforePlotNode(node);
this.plotNode(node, canvas, animating);
!animating && opt.onAfterPlotNode(node);
if(plotLabel && nodeAlpha >= 0.95)
this.labels.plotLabel(canvas, node, opt);
else
this.labels.hideLabel(node, false);
} else {
this.labels.hideLabel(node, true);
}
},

},

getAlignedPos: function(pos, width, height) {
var nconfig = this.node;
Expand Down

0 comments on commit e28e00a

Please sign in to comment.