Skip to content

Commit

Permalink
voronoi prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
ZHANG Bei authored and philogb committed Feb 7, 2012
1 parent 21a120e commit b3a76f5
Show file tree
Hide file tree
Showing 17 changed files with 2,098 additions and 16 deletions.
59 changes: 57 additions & 2 deletions Source/Graph/Graph.Plot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* File: Graph.Plot.js
*/

Expand All @@ -20,6 +20,7 @@ Graph.Plot = {
this.node = viz.config.Node;
this.edge = viz.config.Edge;
this.animation = new Animation;
debugger;
this.nodeTypes = new klass.Plot.NodeTypes;
this.edgeTypes = new klass.Plot.EdgeTypes;
this.labels = viz.labels;
Expand All @@ -42,7 +43,8 @@ Graph.Plot = {
'angularWidth':'number',
'span':'number',
'valueArray':'array-number',
'dimArray':'array-number'
'dimArray':'array-number',
'vertics':'polygon'
//'colorArray':'array-color'
},

Expand Down Expand Up @@ -170,6 +172,59 @@ Graph.Plot = {

'edge-style': function(elem, props, delta) {
this['edge'](elem, props, delta, 'canvas', 'getCanvasStyle', 'setCanvasStyle');
},

'polygon': function(elem, prop, delta, getter, setter) {
var from = elem[getter](prop, 'start'),
to = elem[getter](prop, 'end'),
cur = [];
var dist = function (c1, c2) {
var dx = c1.x - c2.x, dy = c1.y - c2.y;
return dx * dx + dy * dy;
};
if(typeof from.offset == 'undefined') {
if(from === 0) {
from = $.map(to,function(){return new $jit.Complex(0, 0);});
from.offset = 0;
}
else {
if(from.length == 0) {
from.push(new $jit.Complex(0, 0));
}
while(from.length < to.length) {
from.push(from[0]);
}
while(from.length > to.length) {
to.push(to[0]);
}
from = from.map(function(t){ return t || new $jit.Complex(0, 0);});
to = to.map(function(t){ return t || new $jit.Complex(0, 0);});
if (from.length == 0) return;
var l = from.length;
var minDist = 1e300;
for(var offset = 0; offset < l; offset ++) {
var d = 0;
for(var i = 0; i < l; i++){
d += dist(from[(offset + i) % l], to[i]);
}
if (d < minDist)
{
from.offset = offset;
minDist = d;
}
}
}
}

for(var i=0, l=from.length; i<l; i++) {
var fromi = from[(i + from.offset) % l], toi = to[i];
cur.push(new $jit.Complex(
this.compute(fromi.x, toi.x, delta),
this.compute(fromi.y, toi.y, delta)
));
}
elem[setter](prop, cur);

}
},

Expand Down
21 changes: 14 additions & 7 deletions Source/Visualizations/Treemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ TM.Base = {
//right, Firefox?
width: 3,
height: 3,
color: '#444'
color: '#444',
props: 'node-property:width:height'
},
Label: {
textAlign: 'center',
Expand Down Expand Up @@ -120,7 +121,10 @@ TM.Base = {
}, canvasConfig.background);
}
this.canvas = new Canvas(this, canvasConfig);
this.config.labelContainer = (typeof canvasConfig.injectInto == 'string'? canvasConfig.injectInto : canvasConfig.injectInto.id) + '-label';
this.config.labelContainer = (
typeof canvasConfig.injectInto == 'string'?
canvasConfig.injectInto :
canvasConfig.injectInto.id) + '-label';
}

this.graphOptions = {
Expand Down Expand Up @@ -158,7 +162,7 @@ TM.Base = {
this.config.levelsToShow > 0 && this.geom.setRightLevelToShow(this.graph.getNode(this.clickedNode
&& this.clickedNode.id || this.root));
this.fx.animate($.merge(this.config, {
modes: ['linear', 'node-property:width:height'],
modes: ['linear', this.config.Node.props],
onComplete: function() {
that.busy = false;
}
Expand Down Expand Up @@ -216,7 +220,6 @@ TM.Base = {
enter: function(n){
if(this.busy) return;
this.busy = true;

var that = this,
config = this.config,
graph = this.graph,
Expand Down Expand Up @@ -248,8 +251,8 @@ TM.Base = {
//TODO(nico) commenting this line didn't seem to throw errors...
that.clickedNode = previousClickedNode;
that.fx.animate({
modes:['linear', 'node-property:width:height'],
duration: 2 * that.config.duration / 3,
modes:['linear', that.config.Node.props],
onComplete: function() {
that.busy = false;
//TODO(nico) check comment above
Expand Down Expand Up @@ -297,7 +300,7 @@ TM.Base = {
return;
}
//final plot callback
callback = {
var callback = {
onComplete: function() {
that.clickedNode = parent;
if(config.request) {
Expand Down Expand Up @@ -325,8 +328,13 @@ TM.Base = {
//animate the visible subtree only
this.clickedNode = previousClickedNode;
this.fx.animate({
<<<<<<< HEAD
modes:['linear', 'node-property:width:height'],
duration: 2 * this.config.duration / 3,
=======
modes:['linear', this.config.Node.props],
duration: 1000,
>>>>>>> voronoi prototype
onComplete: function() {
//animate the parent subtree
that.clickedNode = clickedNode;
Expand Down Expand Up @@ -561,7 +569,6 @@ TM.Label.Native = new Class({
height = node.getData('height'),
x = pos.x + width/2,
y = pos.y;

ctx.fillText(node.name, x, y, width);
}
});
Expand Down
Loading

0 comments on commit b3a76f5

Please sign in to comment.