Browse Source

svg timeline work and refactoring.

css_transitions
Alex de Mulder 10 years ago
parent
commit
9335aec242
4 changed files with 121 additions and 46 deletions
  1. +63
    -0
      examples/graph/02_random_nodes.html
  2. +0
    -42
      src/graph/graphMixins/MixinLoader.js
  3. +44
    -0
      src/graph/graphMixins/physics/PhysicsMixin.js
  4. +14
    -4
      src/svgTimeline/svgTimeline.js

+ 63
- 0
examples/graph/02_random_nodes.html View File

@ -107,6 +107,69 @@
<input id="nodeCount" type="text" value="25" style="width: 50px;">
<input type="submit" value="Go">
</form>
<input type="radio" name="physicsMethod" value="Barnes Hut" checked="checked">Barnes Hut <br />
<input type="radio" name="physicsMethod" value="Repulsion">Repulsion <br />
<input type="radio" name="physicsMethod" value="Hierarchical Repulsion">Hierarchical Repulsion <br />
<table class="graphPhysicsTable">
<tr>
<td><b>Barnes Hut</b></td>
</tr>
<tr>
<td>gravitationalConstant</td><td>-500</td><td><input type="range" min="500" max="20000" value="2000" step="50" style="width:300px"></td><td>-20000</td><td><input value="2000"></td>
</tr>
<tr>
<td>centralGravity</td><td>0.0</td><td><input type="range" min="0" max="3" value="0.3" step="0.1" style="width:300px"></td><td>3</td><td><input value="0.03"></td>
</tr>
<tr>
<td>springLength</td><td>0</td><td><input type="range" min="0" max="500" value="100" step="1" style="width:300px"></td><td>500</td><td><input value="100"></td>
</tr>
<tr>
<td>springConstant</td><td>0</td><td><input type="range" min="0" max="0.5" value="0.05" step="0.01" style="width:300px"></td><td>0.5</td><td><input value="0.05"></td>
</tr>
<tr>
<td>damping</td><td>0</td><td><input type="range" min="0" max="0.3" value="0.09" step="0.01" style="width:300px"></td><td>0.3</td><td><input value="0.09"></td>
</tr>
</table>
<table class="graphPhysicsTable">
<tr>
<td><b>Repulsion</b></td>
</tr>
<tr>
<td>nodeDistance</td><td>0</td><td><input type="range" min="0" max="300" value="100" step="50" style="width:300px"></td><td>300</td><td><input value="100"></td>
</tr>
<tr>
<td>centralGravity</td><td>0.0</td><td><input type="range" min="0" max="3" value="0.1" step="0.1" style="width:300px"></td><td>3</td><td><input value="0.01"></td>
</tr>
<tr>
<td>springLength</td><td>0</td><td><input type="range" min="0" max="500" value="200" step="1" style="width:300px"></td><td>500</td><td><input value="200"></td>
</tr>
<tr>
<td>springConstant</td><td>0</td><td><input type="range" min="0" max="0.5" value="0.05" step="0.01" style="width:300px"></td><td>0.5</td><td><input value="0.05"></td>
</tr>
<tr>
<td>damping</td><td>0</td><td><input type="range" min="0" max="0.3" value="0.09" step="0.01" style="width:300px"></td><td>0.3</td><td><input value="0.09"></td>
</tr>
</table>
<table class="graphPhysicsTable">
<tr>
<td><b>Hierarchical Repulsion</b></td>
</tr>
<tr>
<td>nodeDistance</td><td>0</td><td><input type="range" min="0" max="300" value="60" step="50" style="width:300px"></td><td>300</td><td><input value="60"></td>
</tr>
<tr>
<td>centralGravity</td><td>0.0</td><td><input type="range" min="0" max="3" value="0" step="0.1" style="width:300px"></td><td>3</td><td><input value="0"></td>
</tr>
<tr>
<td>springLength</td><td>0</td><td><input type="range" min="0" max="500" value="100" step="1" style="width:300px"></td><td>500</td><td><input value="100"></td>
</tr>
<tr>
<td>springConstant</td><td>0</td><td><input type="range" min="0" max="0.5" value="0.01" step="0.01" style="width:300px"></td><td>0.5</td><td><input value="0.01"></td>
</tr>
<tr>
<td>damping</td><td>0</td><td><input type="range" min="0" max="0.3" value="0.09" step="0.01" style="width:300px"></td><td>0.3</td><td><input value="0.09"></td>
</tr>
</table>
<br>
<div id="mygraph"></div>

+ 0
- 42
src/graph/graphMixins/MixinLoader.js View File

@ -46,48 +46,6 @@ var graphMixinLoaders = {
},
/**
* This loads the node force solver based on the barnes hut or repulsion algorithm
*
* @private
*/
_loadSelectedForceSolver : function() {
// this overloads the this._calculateNodeForces
if (this.constants.physics.barnesHut.enabled == true) {
this._clearMixin(repulsionMixin);
this._clearMixin(hierarchalRepulsionMixin);
this.constants.physics.centralGravity = this.constants.physics.barnesHut.centralGravity;
this.constants.physics.springLength = this.constants.physics.barnesHut.springLength;
this.constants.physics.springConstant = this.constants.physics.barnesHut.springConstant;
this.constants.physics.damping = this.constants.physics.barnesHut.damping;
this._loadMixin(barnesHutMixin);
}
else if (this.constants.physics.hierarchicalRepulsion.enabled == true) {
this._clearMixin(barnesHutMixin);
this._clearMixin(repulsionMixin);
this.constants.physics.centralGravity = this.constants.physics.hierarchicalRepulsion.centralGravity;
this.constants.physics.springLength = this.constants.physics.hierarchicalRepulsion.springLength;
this.constants.physics.springConstant = this.constants.physics.hierarchicalRepulsion.springConstant;
this.constants.physics.damping = this.constants.physics.hierarchicalRepulsion.damping;
this._loadMixin(hierarchalRepulsionMixin);
}
else {
this._clearMixin(barnesHutMixin);
this._clearMixin(hierarchalRepulsionMixin);
this.barnesHutTree = undefined;
this.constants.physics.centralGravity = this.constants.physics.repulsion.centralGravity;
this.constants.physics.springLength = this.constants.physics.repulsion.springLength;
this.constants.physics.springConstant = this.constants.physics.repulsion.springConstant;
this.constants.physics.damping = this.constants.physics.repulsion.damping;
this._loadMixin(repulsionMixin);
}
},
/**

+ 44
- 0
src/graph/graphMixins/physics/PhysicsMixin.js View File

@ -18,6 +18,50 @@ var physicsMixin = {
},
/**
* This loads the node force solver based on the barnes hut or repulsion algorithm
*
* @private
*/
_loadSelectedForceSolver : function() {
// this overloads the this._calculateNodeForces
if (this.constants.physics.barnesHut.enabled == true) {
this._clearMixin(repulsionMixin);
this._clearMixin(hierarchalRepulsionMixin);
this.constants.physics.centralGravity = this.constants.physics.barnesHut.centralGravity;
this.constants.physics.springLength = this.constants.physics.barnesHut.springLength;
this.constants.physics.springConstant = this.constants.physics.barnesHut.springConstant;
this.constants.physics.damping = this.constants.physics.barnesHut.damping;
this._loadMixin(barnesHutMixin);
}
else if (this.constants.physics.hierarchicalRepulsion.enabled == true) {
this._clearMixin(barnesHutMixin);
this._clearMixin(repulsionMixin);
this.constants.physics.centralGravity = this.constants.physics.hierarchicalRepulsion.centralGravity;
this.constants.physics.springLength = this.constants.physics.hierarchicalRepulsion.springLength;
this.constants.physics.springConstant = this.constants.physics.hierarchicalRepulsion.springConstant;
this.constants.physics.damping = this.constants.physics.hierarchicalRepulsion.damping;
this._loadMixin(hierarchalRepulsionMixin);
}
else {
this._clearMixin(barnesHutMixin);
this._clearMixin(hierarchalRepulsionMixin);
this.barnesHutTree = undefined;
this.constants.physics.centralGravity = this.constants.physics.repulsion.centralGravity;
this.constants.physics.springLength = this.constants.physics.repulsion.springLength;
this.constants.physics.springConstant = this.constants.physics.repulsion.springConstant;
this.constants.physics.damping = this.constants.physics.repulsion.damping;
this._loadMixin(repulsionMixin);
}
},
/**
* Before calculating the forces, we check if we need to cluster to keep up performance and we check
* if there is more than one node. If it is just one node, we dont calculate anything.

+ 14
- 4
src/svgTimeline/svgTimeline.js View File

@ -269,6 +269,7 @@ SvgTimeline.prototype._update = function() {
};
SvgTimeline.prototype._getActiveItems = function() {
// reset all currently active items to inactive
for (var itemId in this.activeItems) {
if (this.activeItems.hasOwnProperty(itemId)) {
this.activeItems[itemId].active = false;
@ -311,11 +312,19 @@ SvgTimeline.prototype._updateItems = function() {
for (var i = 0; i < this.sortedActiveItems.length; i++) {
var item = this.sortedActiveItems[i];
if (item.svg == null) {
// item.svg = d3.select("svg#main")
// .append("rect")
// .attr("class","item")
// .style("stroke", "rgb(6,120,155)")
// .style("fill", "rgb(6,120,155)");
item.svg = d3.select("svg#main")
.append("rect")
.attr("class","item")
.style("stroke", "rgb(6,120,155)")
.style("fill", "rgb(6,120,155)");
.append("foreignObject")
item.svgContent = item.svg.append("xhtml:body")
.style("font", "14px 'Helvetica Neue'")
.style("background-color", "#ff00ff")
.html("<h1>An HTML Foreign Object in SVG</h1><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eu enim quam. Quisque nisi risus, sagittis quis tempor nec, aliquam eget neque. Nulla bibendum semper lorem non ullamcorper. Nulla non ligula lorem. Praesent porttitor, tellus nec suscipit aliquam, enim elit posuere lorem, at laoreet enim ligula sed tortor. Ut sodales, urna a aliquam semper, nibh diam gravida sapien, sit amet fermentum purus lacus eget massa. Donec ac arcu vel magna consequat pretium et vel ligula. Donec sit amet erat elit. Vivamus eu metus eget est hendrerit rutrum. Curabitur vitae orci et leo interdum egestas ut sit amet dui. In varius enim ut sem posuere in tristique metus ultrices.<p>Integer mollis massa at orci porta vestibulum. Pellentesque dignissim turpis ut tortor ultricies condimentum et quis nibh. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer euismod lorem vulputate dui pharetra luctus. Sed vulputate, nunc quis porttitor scelerisque, dui est varius ipsum, eu blandit mauris nibh pellentesque tortor. Vivamus ultricies ante eget ipsum pulvinar ac tempor turpis mollis. Morbi tortor orci, euismod vel sagittis ac, lobortis nec est. Quisque euismod venenatis felis at dapibus. Vestibulum dignissim nulla ut nisi tristique porttitor. Proin et nunc id arcu cursus dapibus non quis libero. Nunc ligula mi, bibendum non mattis nec, luctus id neque. Suspendisse ut eros lacus. Praesent eget lacus eget risus congue vestibulum. Morbi tincidunt pulvinar lacus sed faucibus. Phasellus sed vestibulum sapien.");
if (item.end == 0) {
item.svgLine = d3.select("svg#main")
@ -329,6 +338,7 @@ SvgTimeline.prototype._updateItems = function() {
.attr("x",this._getXforItem(item))
.attr("y",this._getYforItem(item, i))
.attr('height',25)
if (item.end == 0) {
item.svgLine.attr('y2',item.y)

Loading…
Cancel
Save