Game-Collisions
view release on metacpan or search on metacpan
nytprof/js/jit/jit.js view on Meta::CPAN
align: "center"
},
Edge: {
overridable: false,
type: 'line',
color: '#ccc',
dim: 15,
lineWidth: 1
},
duration: 700,
fps: 25,
transition: Trans.Quart.easeInOut
};
this.controller = this.config = $merge(config, innerController, controller);
this.canvas = canvas;
this.graphOptions = {
'complex': true
};
this.graph = new Graph(this.graphOptions);
this.fx = new ST.Plot(this);
this.op = new ST.Op(this);
this.group = new ST.Group(this);
this.geom = new ST.Geom(this);
this.clickedNode= null;
},
/*
Method: plot
Plots the tree. Usually this method is called right after computing nodes' positions.
*/
plot: function() { this.fx.plot(this.controller); },
/*
Method: switchPosition
Switches the tree orientation.
Parameters:
pos - The new tree orientation. Possible values are "top", "left", "right" and "bottom".
method - Set this to "animate" if you want to animate the tree when switching its position. You can also set this parameter to "replot" to just replot the subtree.
onComplete - _optional_ This callback is called once the "switching" animation is complete.
Example:
(start code js)
st.switchPosition("right", "animate", {
onComplete: function() {
alert('completed!');
}
});
(end code)
*/
switchPosition: function(pos, method, onComplete) {
var Geom = this.geom, Plot = this.fx, that = this;
if(!Plot.busy) {
Plot.busy = true;
this.contract({
onComplete: function() {
Geom.switchOrientation(pos);
that.compute('endPos', false);
Plot.busy = false;
if(method == 'animate') {
that.onClick(that.clickedNode.id, onComplete);
} else if(method == 'replot') {
that.select(that.clickedNode.id, onComplete);
}
}
}, pos);
}
},
/*
Method: switchAlignment
Switches the tree alignment.
Parameters:
align - The new tree alignment. Possible values are "left", "center" and "right".
method - Set this to "animate" if you want to animate the tree after aligning its position. You can also set this parameter to "replot" to just replot the subtree.
onComplete - _optional_ This callback is called once the "switching" animation is complete.
Example:
(start code js)
st.switchAlignment("right", "animate", {
onComplete: function() {
alert('completed!');
}
});
(end code)
*/
switchAlignment: function(align, method, onComplete) {
this.config.align = align;
if(method == 'animate') {
this.select(this.clickedNode.id, onComplete);
} else if(method == 'replot') {
this.onClick(this.clickedNode.id, onComplete);
}
},
/*
Method: addNodeInPath
Adds a node to the current path as selected node. This node will be visible (as in non-collapsed) at all times.
Parameters:
id - A <Graph.Node> id.
Example:
(start code js)
st.addNodeInPath("somenodeid");
(end code)
*/
addNodeInPath: function(id) {
nodesInPath.push(id);
this.select((this.clickedNode && this.clickedNode.id) || this.root);
},
nytprof/js/jit/jit.js view on Meta::CPAN
Graph.Util.eachNode(that.graph, function(n) {
var pos = n.pos.getc(true);
n.startPos.setc(pos.x, pos.y);
n.endPos.setc(pos.x, pos.y);
n.visited = false;
});
that.geom.translate(node.endPos.scale(-1), ["pos", "startPos", "endPos"]);
group.show(getNodesToShow.call(that));
that.plot();
complete.onAfterCompute(that.clickedNode);
complete.onComplete();
}
});
},
/*
Method: onClick
This method is called when clicking on a tree node. It mainly performs all calculations and the animation of contracting, translating and expanding pertinent nodes.
Parameters:
id - A node id.
options - A group of options and callbacks such as
- _onComplete_ an object callback called when the animation finishes.
- _Move_ an object that has as properties _offsetX_ or _offsetY_ for adding some offset position to the centered node.
Example:
(start code js)
st.onClick('mynodeid', {
Move: {
enable: true,
offsetX: 30,
offsetY: 5
},
onComplete: function() {
alert('yay!');
}
});
(end code)
*/
onClick: function (id, options) {
var canvas = this.canvas, that = this, Fx = this.fx, Util = Graph.Util, Geom = this.geom;
var innerController = {
Move: {
enable: true,
offsetX: 0,
offsetY: 0
},
onBeforeRequest: $empty,
onBeforeContract: $empty,
onBeforeMove: $empty,
onBeforeExpand: $empty
};
var complete = $merge(this.controller, innerController, options);
if(!this.busy) {
this.busy= true;
var node= this.graph.getNode(id);
this.selectPath(node, this.clickedNode);
this.clickedNode= node;
complete.onBeforeCompute(node);
complete.onBeforeRequest(node);
this.requestNodes(node, {
onComplete: function() {
complete.onBeforeContract(node);
that.contract({
onComplete: function() {
Geom.setRightLevelToShow(node, canvas);
complete.onBeforeMove(node);
that.move(node, {
Move: complete.Move,
onComplete: function() {
complete.onBeforeExpand(node);
that.expand(node, {
onComplete: function() {
that.busy = false;
complete.onAfterCompute(id);
complete.onComplete();
}
}); //expand
}
}); //move
}
});//contract
}
});//request
}
}
});
})();
/*
Class: ST.Op
Performs advanced operations on trees and graphs.
Extends:
All <Graph.Op> methods
Access:
This instance can be accessed with the _op_ parameter of the st instance created.
Example:
(start code js)
var st = new ST(canvas, config);
st.op.morph //or can also call any other <Graph.Op> method
(end code)
*/
ST.Op = new Class({
Implements: Graph.Op,
initialize: function(viz) {
this.viz = viz;
}
});
/*
Performs operations on group of nodes.
*/
ST.Group = new Class({
initialize: function(viz) {
this.viz = viz;
this.canvas = viz.canvas;
this.config = viz.config;
this.animation = new Animation;
this.nodes = null;
},
nytprof/js/jit/jit.js view on Meta::CPAN
Implements: [Loader, AngularWidth],
initialize: function(canvas, controller) {
var config= {
labelContainer: canvas.id + '-label',
interpolation: 'linear',
levelDistance: 100,
withLabels: true,
Node: {
overridable: false,
type: 'circle',
dim: 3,
color: '#ccb',
width: 5,
height: 5,
lineWidth: 1
},
Edge: {
overridable: false,
type: 'line',
color: '#ccb',
lineWidth: 1
},
fps:40,
duration: 2500,
transition: Trans.Quart.easeInOut,
clearCanvas: true
};
var innerController = {
onBeforeCompute: $empty,
onAfterCompute: $empty,
onCreateLabel: $empty,
onPlaceLabel: $empty,
onComplete: $empty,
onBeforePlotLine:$empty,
onAfterPlotLine: $empty,
onBeforePlotNode:$empty,
onAfterPlotNode: $empty
};
this.controller = this.config = $merge(config, innerController, controller);
this.graphOptions = {
'complex': false,
'Node': {
'selected': false,
'exist': true,
'drawn': true
}
};
this.graph = new Graph(this.graphOptions);
this.fx = new RGraph.Plot(this);
this.op = new RGraph.Op(this);
this.json = null;
this.canvas = canvas;
this.root = null;
this.busy = false;
this.parent = false;
},
/*
Method: refresh
Computes nodes' positions and replots the tree.
*/
refresh: function() {
this.compute();
this.plot();
},
/*
Method: reposition
An alias for computing new positions to _endPos_
See also:
<RGraph.compute>
*/
reposition: function() {
this.compute('endPos');
},
/*
Method: plot
Plots the RGraph
*/
plot: function() {
this.fx.plot();
},
/*
Method: compute
Computes nodes' positions.
Parameters:
property - _optional_ A <Graph.Node> position property to store the new positions. Possible values are 'pos', 'endPos' or 'startPos'.
*/
compute: function(property) {
var prop = property || ['pos', 'startPos', 'endPos'];
var node = this.graph.getNode(this.root);
node._depth = 0;
Graph.Util.computeLevels(this.graph, this.root, 0, "ignore");
this.computeAngularWidths();
this.computePositions(prop);
},
/*
computePositions
Performs the main algorithm for computing node positions.
*/
nytprof/js/jit/jit.js view on Meta::CPAN
Returns the _parent_ of the given node, also calculating its angle span.
*/
getNodeAndParentAngle: function(id) {
var theta = false;
var n = this.graph.getNode(id);
var ps = Graph.Util.getParents(n);
var p = (ps.length > 0)? ps[0] : false;
if(p) {
var posParent = p.pos.getc(), posChild = n.pos.getc();
var newPos = posParent.add(posChild.scale(-1));
theta = Math.atan2(newPos.y, newPos.x);
if(theta < 0) theta += 2 * Math.PI;
}
return {parent: p, theta: theta};
},
/*
tagChildren
Enumerates the children in order to mantain child ordering (second constraint of the paper).
*/
tagChildren: function(par, id) {
if(par.angleSpan) {
var adjs = [];
Graph.Util.eachAdjacency(par, function(elem) {
adjs.push(elem.nodeTo);
}, "ignore");
var len = adjs.length;
for(var i=0; i < len && id != adjs[i].id; i++);
for(var j= (i+1) % len, k = 0; id != adjs[j].id; j = (j+1) % len) {
adjs[j].dist = k++;
}
}
},
/*
Method: onClick
Performs all calculations and animations to center the node specified by _id_.
Parameters:
id - A <Graph.Node> id.
opt - _optional_ An object containing some extra properties like
- _hideLabels_ Hide labels when performing the animation. Default's *true*.
Example:
(start code js)
rgraph.onClick('someid');
//or also...
rgraph.onClick('someid', {
hideLabels: false
});
(end code)
*/
onClick: function(id, opt) {
if(this.root != id && !this.busy) {
this.busy = true;
this.root = id;
that = this;
this.controller.onBeforeCompute(this.graph.getNode(id));
var obj = this.getNodeAndParentAngle(id);
//second constraint
this.tagChildren(obj.parent, id);
this.parent = obj.parent;
this.compute('endPos');
//first constraint
var thetaDiff = obj.theta - obj.parent.endPos.theta;
Graph.Util.eachNode(this.graph, function(elem) {
elem.endPos.set(elem.endPos.getp().add($P(thetaDiff, 0)));
});
var mode = this.config.interpolation;
opt = $merge({ onComplete: $empty }, opt || {});
this.fx.animate($merge({
hideLabels: true,
modes: [mode]
}, opt, {
onComplete: function() {
that.busy = false;
opt.onComplete();
}
}));
}
}
});
/*
Class: RGraph.Op
Performs advanced operations on trees and graphs.
Extends:
All <Graph.Op> methods
Access:
This instance can be accessed with the _op_ parameter of the <RGraph> instance created.
Example:
(start code js)
var rgraph = new RGraph(canvas, config);
rgraph.op.morph //or can also call any other <Graph.Op> method
(end code)
*/
RGraph.Op = new Class({
Implements: Graph.Op,
initialize: function(viz) {
this.viz = viz;
}
});
/*
Class: RGraph.Plot
Performs plotting operations.
Extends:
All <Graph.Plot> methods
Access:
This instance can be accessed with the _fx_ parameter of the <RGraph> instance created.
Example:
(start code js)
var rgraph = new RGraph(canvas, config);
rgraph.fx.placeLabel //or can also call any other <RGraph.Plot> method
(end code)
*/
RGraph.Plot = new Class({
nytprof/js/jit/jit.js view on Meta::CPAN
Implements: [Loader, AngularWidth],
initialize: function(canvas, controller) {
var config = {
labelContainer: canvas.id + '-label',
withLabels: true,
Node: {
overridable: false,
type: 'circle',
dim: 7,
color: '#ccb',
width: 5,
height: 5,
lineWidth: 1,
transform: true
},
Edge: {
overridable: false,
type: 'hyperline',
color: '#ccb',
lineWidth: 1
},
clearCanvas: true,
fps:40,
duration: 1500,
transition: Trans.Quart.easeInOut
};
var innerController = {
onBeforeCompute: $empty,
onAfterCompute: $empty,
onCreateLabel: $empty,
onPlaceLabel: $empty,
onComplete: $empty,
onBeforePlotLine:$empty,
onAfterPlotLine: $empty,
onBeforePlotNode:$empty,
onAfterPlotNode: $empty
};
this.controller = this.config = $merge(config, innerController, controller);
this.graphOptions = {
'complex': false,
'Node': {
'selected': false,
'exist': true,
'drawn': true
}
};
this.graph = new Graph(this.graphOptions);
this.fx = new Hypertree.Plot(this);
this.op = new Hypertree.Op(this);
this.json = null;
this.canvas = canvas;
this.root = null;
this.busy = false;
},
/*
Method: refresh
Computes nodes' positions and replots the tree.
Parameters:
reposition - _optional_ Set this to *true* to force repositioning.
See also:
<Hypertree.reposition>
*/
refresh: function(reposition) {
if(reposition) {
this.reposition();
Graph.Util.eachNode(this.graph, function(node) {
node.startPos.rho = node.pos.rho = node.endPos.rho;
node.startPos.theta = node.pos.theta = node.endPos.theta;
});
} else {
this.compute();
}
this.plot();
},
/*
Method: reposition
Computes nodes' positions and restores the tree to its previous position.
For calculating nodes' positions the root must be placed on its origin. This method does this
and then attemps to restore the hypertree to its previous position.
*/
reposition: function() {
this.compute('endPos');
var vector = this.graph.getNode(this.root).pos.getc().scale(-1);
Graph.Util.moebiusTransformation(this.graph, [vector], ['endPos'], 'endPos', "ignore");
Graph.Util.eachNode(this.graph, function(node) {
if (node.ignore) {
node.endPos.rho = node.pos.rho;
node.endPos.theta = node.pos.theta;
}
});
},
/*
Method: plot
Plots the Hypertree
*/
plot: function() {
this.fx.plot();
},
nytprof/js/jit/jit.js view on Meta::CPAN
child._rel = child._treeAngularWidth / totalAngularWidths;
var angleProportion = child._rel * angleSpan;
var theta = angleInit + angleProportion / 2;
for(var i=0; i<propArray.length; i++)
child[propArray[i]] = $P(theta, rho);
child.angleSpan = {
begin: angleInit,
end: angleInit + angleProportion
};
angleInit += angleProportion;
}
}, "ignore");
}, "ignore");
},
/*
Method: onClick
Performs all calculations and animations to center the node specified by _id_.
Parameters:
id - A <Graph.Node> id.
opt - _optional_ An object containing some extra properties like
- _hideLabels_ Hide labels when performing the animation. Default's *true*.
Example:
(start code js)
ht.onClick('someid');
//or also...
ht.onClick('someid', {
hideLabels: false
});
(end code)
*/
onClick: function(id, opt) {
var pos = this.graph.getNode(id).pos.getc(true);
this.move(pos, opt);
},
/*
Method: move
Translates the tree to the given position.
Parameters:
pos - A <Complex> number determining the position to move the tree to.
opt - _optional_ An object containing some extra properties defined in <Hypertree.onClick>
*/
move: function(pos, opt) {
var versor = $C(pos.x, pos.y);
if(this.busy === false && versor.norm() < 1) {
var GUtil = Graph.Util;
this.busy = true;
var root = GUtil.getClosestNodeToPos(this.graph, versor), that = this;
GUtil.computeLevels(this.graph, root.id, 0);
this.controller.onBeforeCompute(root);
if (versor.norm() < 1) {
opt = $merge({ onComplete: $empty }, opt || {});
this.fx.animate($merge({
modes: ['moebius'],
hideLabels: true
}, opt, {
onComplete: function(){
that.busy = false;
opt.onComplete();
}
}), versor);
}
}
}
});
/*
Class: Hypertree.Op
Performs advanced operations on trees and graphs.
Extends:
All <Graph.Op> methods
Access:
This instance can be accessed with the _op_ parameter of the hypertree instance created.
Example:
(start code js)
var ht = new Hypertree(canvas, config);
ht.op.morph //or can also call any other <Graph.Op> method
(end code)
*/
Hypertree.Op = new Class({
Implements: Graph.Op,
initialize: function(viz) {
this.viz = viz;
}
});
/*
Class: Hypertree.Plot
Performs plotting operations.
Extends:
All <Graph.Plot> methods
Access:
This instance can be accessed with the _fx_ parameter of the hypertree instance created.
Example:
(start code js)
var ht = new Hypertree(canvas, config);
ht.fx.placeLabel //or can also call any other <Hypertree.Plot> method
(end code)
*/
Hypertree.Plot = new Class({
( run in 1.666 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )