Skip to content

Commit

Permalink
Add new test cases for single node sunburst visualization.
Browse files Browse the repository at this point in the history
  • Loading branch information
philogb committed Nov 16, 2010
1 parent afb8a38 commit 9d5962e
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Templates/Sunburst/test5.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$def with (model)

<div id="inner-details"></div>
134 changes: 134 additions & 0 deletions Tests/Sunburst/test5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
var labelType, useGradients, nativeTextSupport, animate;

(function() {
var ua = navigator.userAgent,
iStuff = ua.match(/iPhone/i) || ua.match(/iPad/i),
typeOfCanvas = typeof HTMLCanvasElement,
nativeCanvasSupport = (typeOfCanvas == 'object' || typeOfCanvas == 'function'),
textSupport = nativeCanvasSupport
&& (typeof document.createElement('canvas').getContext('2d').fillText == 'function');
//I'm setting this based on the fact that ExCanvas provides text support for IE
//and that as of today iPhone/iPad current text support is lame
labelType = (!nativeCanvasSupport || (textSupport && !iStuff))? 'Native' : 'HTML';
nativeTextSupport = labelType == 'Native';
useGradients = nativeCanvasSupport;
animate = !(iStuff || !nativeCanvasSupport);
})();

var Log = {
elem: false,
write: function(text){
if (!this.elem)
this.elem = document.getElementById('log');
this.elem.innerHTML = text;
this.elem.style.left = (500 - this.elem.offsetWidth / 2) + 'px';
}
};


function init(){
//init data
var json = {
"id": "root",
"name": "root",
"data": {
"$type": "none"
},
"children": [{
"id":"child1",
"name": "child1"
}]
};
//end
//init Sunburst
var sb = new $jit.Sunburst({
//id container for the visualization
injectInto: 'infovis',
//Change node and edge styles such as
//color, width, lineWidth and edge types
Node: {
overridable: true,
type: useGradients? 'gradient-multipie' : 'multipie'
},
Edge: {
overridable: false,
type: 'none'
},
//Draw canvas text. Can also be
//'HTML' or 'SVG' to draw DOM labels
Label: {
type: nativeTextSupport? 'Native' : 'SVG'
},
//Add animations when hovering and clicking nodes
NodeStyles: {
enable: true,
type: 'Native',
stylesClick: {
'color': '#33dddd'
},
stylesHover: {
'color': '#dd3333'
},
duration: 700
},
Events: {
enable: true,
type: 'Native',
//List node connections onClick
onClick: function(node, eventInfo, e){
if (!node) return;
var html = "<h4>" + node.name + " connections</h4><ul><li>", ans = [];
node.eachAdjacency(function(adj){
// if on the same level i.e siblings
if (adj.nodeTo._depth == node._depth) {
ans.push(adj.nodeTo.name);
}
});
$jit.id('inner-details').innerHTML = html + ans.join("</li><li>") + "</li></ul>";
}
},
levelDistance: 90,
// Only used when Label type is 'HTML' or 'SVG'
// Add text to the labels.
// This method is only triggered on label creation
onCreateLabel: function(domElement, node){
var labels = sb.config.Label.type;
if (labels === 'HTML') {
domElement.innerHTML = node.name;
} else if (labels === 'SVG') {
domElement.firstChild.appendChild(document.createTextNode(node.name));
}
},
// Only used when Label type is 'HTML' or 'SVG'
// Change node styles when labels are placed
// or moved.
onPlaceLabel: function(domElement, node){
var labels = sb.config.Label.type;
if (labels === 'SVG') {
var fch = domElement.firstChild;
var style = fch.style;
style.display = '';
style.cursor = 'pointer';
style.fontSize = "0.8em";
fch.setAttribute('fill', "#fff");
} else if (labels === 'HTML') {
var style = domElement.style;
style.display = '';
style.cursor = 'pointer';
if (node._depth <= 1) {
style.fontSize = "0.8em";
style.color = "#ddd";
}
var left = parseInt(style.left);
var w = domElement.offsetWidth;
style.left = (left - w / 2) + 'px';
}
}
});
// load JSON data.
sb.loadJSON(json);
// compute positions and plot.
sb.refresh();
//end
}

11 changes: 10 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@
'Extras': ['excanvas.js'],
'Example':True
},
{
{
'Title': 'Sunburst of a Directory Tree',
'Description':
"""
Expand All @@ -694,6 +694,15 @@
'Extras': ['excanvas.js'],
'Example':True
},
{
'Title': 'Mono node Sunburst',
'Description':
"""
""",
'Extras': ['excanvas.js'],
'Example': False
},


],

Expand Down

0 comments on commit 9d5962e

Please sign in to comment.