|
|
@ -2,21 +2,26 @@
|
|
|
|
//TODO: Finish merging this chart into the NVD3 style!
|
|
|
|
//TODO: Finish merging this chart into the NVD3 style!
|
|
|
|
nv.models.indentedTree = function() {
|
|
|
|
nv.models.indentedTree = function() {
|
|
|
|
//Default Settings
|
|
|
|
//Default Settings
|
|
|
|
var margin = {top: 0, right: 0, bottom: 0, left: 0},
|
|
|
|
var margin = {top: 0, right: 0, bottom: 0, left: 0}, //TODO: implement, maybe as margin on the containing div
|
|
|
|
width = 960,
|
|
|
|
width = 960,
|
|
|
|
height = 500,
|
|
|
|
height = 500,
|
|
|
|
color = d3.scale.category20().range(), // array of colors to be used in order
|
|
|
|
color = d3.scale.category20().range(),
|
|
|
|
id = Math.floor(Math.random() * 10000), //Create semi-unique ID incase user doesn't select one
|
|
|
|
id = Math.floor(Math.random() * 10000),
|
|
|
|
|
|
|
|
header = true,
|
|
|
|
|
|
|
|
noResultsText = 'No Results found.'
|
|
|
|
childIndent = 20,
|
|
|
|
childIndent = 20,
|
|
|
|
berHeight = 20,
|
|
|
|
options = {columns:[{key:'key', label: 'Name', type:'text'}]}, //TODO: get rid of
|
|
|
|
options = {columns:[{key:'key', label: 'Name', type:'text'}]},
|
|
|
|
tableClass = null,
|
|
|
|
tableClass = null;
|
|
|
|
iconOpen = 'images/grey-plus.png', //TODO: consider removing this and replacing with a '+' or '-' unless user defines images
|
|
|
|
|
|
|
|
iconClose = 'images/grey-minus.png';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dispatch = d3.dispatch('elementClick', 'elementDblclick', 'elementMouseover', 'elementMouseout');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function chart(selection) {
|
|
|
|
function chart(selection) {
|
|
|
|
selection.each(function(data) {
|
|
|
|
selection.each(function(data) {
|
|
|
|
var availableWidth = width - margin.left - margin.right,
|
|
|
|
var availableWidth = width - margin.left - margin.right, //TODO: decide if there is any use for these
|
|
|
|
availableHeight = height - margin.top - margin.bottom;
|
|
|
|
availableHeight = height - margin.top - margin.bottom;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -30,7 +35,7 @@ nv.models.indentedTree = function() {
|
|
|
|
.size([height, childIndent]); //Not sure if this is needed now that the result is HTML
|
|
|
|
.size([height, childIndent]); //Not sure if this is needed now that the result is HTML
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!data[0].key) data[0].key = options.noResults || "Nothing to show";
|
|
|
|
if (!data[0].key) data[0].key = noResultsText;
|
|
|
|
|
|
|
|
|
|
|
|
var nodes = tree.nodes(data[0]);
|
|
|
|
var nodes = tree.nodes(data[0]);
|
|
|
|
|
|
|
|
|
|
|
@ -41,12 +46,8 @@ nv.models.indentedTree = function() {
|
|
|
|
var table = wrap.select('table').attr('width', '100%').attr('class', tableClass);
|
|
|
|
var table = wrap.select('table').attr('width', '100%').attr('class', tableClass);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//clear the container, start from scratch
|
|
|
|
|
|
|
|
//d3.select("#" + container + " .indentedtree").remove();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (options.header) {
|
|
|
|
if (header) {
|
|
|
|
var thead = tableEnter.append('thead');
|
|
|
|
var thead = tableEnter.append('thead');
|
|
|
|
|
|
|
|
|
|
|
|
var theadRow1 = thead.append('tr');
|
|
|
|
var theadRow1 = thead.append('tr');
|
|
|
@ -61,7 +62,6 @@ nv.models.indentedTree = function() {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//tableEnter.append('tbody');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tbody = table.selectAll('tbody')
|
|
|
|
var tbody = table.selectAll('tbody')
|
|
|
|
.data(function(d) {return d });
|
|
|
|
.data(function(d) {return d });
|
|
|
@ -69,59 +69,57 @@ nv.models.indentedTree = function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//compute max generations
|
|
|
|
//compute max generations
|
|
|
|
depth = d3.max(nodes, function(node) { return node.depth });
|
|
|
|
depth = d3.max(nodes, function(node) { return node.depth });
|
|
|
|
tree.size([height, depth * childIndent]);
|
|
|
|
tree.size([height, depth * childIndent]); //TODO: see if this is necessary at all
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update the nodes…
|
|
|
|
// Update the nodes…
|
|
|
|
var node = tbody.selectAll("tr")
|
|
|
|
var node = tbody.selectAll('tr')
|
|
|
|
//.data(nodes, function(d) { return d.id || (d.id = ++i); })
|
|
|
|
.data(function(d) { return d }, function(d) { return d.id || (d.id == ++i)});
|
|
|
|
.data(function(d) { return d }, function(d) { return d.id || (d.id == ++i)})
|
|
|
|
//.style('display', 'table-row'); //TODO: see if this does anything
|
|
|
|
.style('display', 'table-row');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
node.exit().remove();
|
|
|
|
node.exit().remove();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
if (options.click)
|
|
|
|
if (options.click)
|
|
|
|
node.on('click', options.click);
|
|
|
|
node.on('click', options.click);
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
node.select("img.treeicon")
|
|
|
|
node.select('img.treeicon')
|
|
|
|
.attr("src", icon)
|
|
|
|
.attr('src', icon)
|
|
|
|
.classed('folded', folded);
|
|
|
|
.classed('folded', folded);
|
|
|
|
|
|
|
|
|
|
|
|
var nodeEnter = node.enter().append("tr");
|
|
|
|
var nodeEnter = node.enter().append('tr');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
options.columns.forEach(function(column, index) {
|
|
|
|
options.columns.forEach(function(column, index) {
|
|
|
|
|
|
|
|
|
|
|
|
var nodeName = nodeEnter.append("td")
|
|
|
|
var nodeName = nodeEnter.append('td')
|
|
|
|
.style("padding-left", function(d) { return (index ? 0 : d.depth * childIndent + 12 + (icon(d) ? 0 : 16)) + 'px' }, 'important') //TODO: check why I did the ternary here
|
|
|
|
.style('padding-left', function(d) { return (index ? 0 : d.depth * childIndent + 12 + (icon(d) ? 0 : 16)) + 'px' }, 'important') //TODO: check why I did the ternary here
|
|
|
|
.style('text-align', column.type == 'numeric' ? 'right' : 'left');
|
|
|
|
.style('text-align', column.type == 'numeric' ? 'right' : 'left');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
if (index == 0) {
|
|
|
|
nodeName.append("img")
|
|
|
|
nodeName.append('img')
|
|
|
|
.classed('treeicon', true)
|
|
|
|
.classed('treeicon', true)
|
|
|
|
.classed('folded', folded)
|
|
|
|
.classed('folded', folded)
|
|
|
|
.attr('src', icon)
|
|
|
|
.attr('src', icon)
|
|
|
|
.style("width", '14px')
|
|
|
|
.style('width', '14px')
|
|
|
|
.style("height", '14px')
|
|
|
|
.style('height', '14px')
|
|
|
|
.style('padding', '0 1px')
|
|
|
|
.style('padding', '0 1px')
|
|
|
|
.style('display', function(d) { return icon(d) ? 'inline-block' : 'none'; })
|
|
|
|
.style('display', function(d) { return icon(d) ? 'inline-block' : 'none'; })
|
|
|
|
.on("click", click);
|
|
|
|
.on('click', click);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nodeName.append("span")
|
|
|
|
nodeName.append('span')
|
|
|
|
.attr('class', d3.functor(column.classes) )
|
|
|
|
.attr('class', d3.functor(column.classes) )
|
|
|
|
.text(function(d) { return column.format ? column.format(d) :
|
|
|
|
.text(function(d) { return column.format ? column.format(d) :
|
|
|
|
(d[column.key] || '-') });
|
|
|
|
(d[column.key] || '-') });
|
|
|
|
|
|
|
|
|
|
|
|
if (column.showCount)
|
|
|
|
if (column.showCount)
|
|
|
|
nodeName.append("span")
|
|
|
|
nodeName.append('span')
|
|
|
|
.attr('class', 'childrenCount')
|
|
|
|
.attr('class', 'childrenCount')
|
|
|
|
.text(function(d) {
|
|
|
|
.text(function(d) {
|
|
|
|
return ((d.values && d.values.length) || (d._values && d._values.length)) ?
|
|
|
|
return ((d.values && d.values.length) || (d._values && d._values.length)) ?
|
|
|
@ -130,17 +128,45 @@ nv.models.indentedTree = function() {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tbody.selectAll("tr")
|
|
|
|
|
|
|
|
//.data(nodes, function(d) { return d.id || (d.id = ++i); })
|
|
|
|
|
|
|
|
.order()
|
|
|
|
|
|
|
|
//.classed('highlight', function(_,i) { return i % 2;}); //used to alternate background color
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (column.click)
|
|
|
|
if (column.click)
|
|
|
|
nodeName.select('span').on('click', column.click);
|
|
|
|
nodeName.select('span').on('click', column.click);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
node
|
|
|
|
|
|
|
|
.order()
|
|
|
|
|
|
|
|
.on('click', function(d) {
|
|
|
|
|
|
|
|
dispatch.elementClick({
|
|
|
|
|
|
|
|
row: this, //TODO: decide whether or not this should be consistent with scatter/line events
|
|
|
|
|
|
|
|
data: d,
|
|
|
|
|
|
|
|
pos: [d.x, d.y]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.on('dblclick', function(d) {
|
|
|
|
|
|
|
|
dispatch.elementDblclick({
|
|
|
|
|
|
|
|
row: this,
|
|
|
|
|
|
|
|
data: d,
|
|
|
|
|
|
|
|
pos: [d.x, d.y]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.on('mouseover', function(d) {
|
|
|
|
|
|
|
|
dispatch.elementMouseover({
|
|
|
|
|
|
|
|
row: this,
|
|
|
|
|
|
|
|
data: d,
|
|
|
|
|
|
|
|
pos: [d.x, d.y]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.on('mouseout', function(d) {
|
|
|
|
|
|
|
|
dispatch.elementMouseout({
|
|
|
|
|
|
|
|
row: this,
|
|
|
|
|
|
|
|
data: d,
|
|
|
|
|
|
|
|
pos: [d.x, d.y]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Toggle children on click.
|
|
|
|
// Toggle children on click.
|
|
|
|
function click(d, _, unshift) {
|
|
|
|
function click(d, _, unshift) {
|
|
|
@ -173,7 +199,7 @@ nv.models.indentedTree = function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function icon(d) {
|
|
|
|
function icon(d) {
|
|
|
|
return (d._values && d._values.length) ? "images/grey-plus.png" : (d.values && d.values.length) ? "images/grey-minus.png" : "";
|
|
|
|
return (d._values && d._values.length) ? iconOpen : (d.values && d.values.length) ? iconClose : '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function folded(d) {
|
|
|
|
function folded(d) {
|
|
|
@ -225,6 +251,18 @@ nv.models.indentedTree = function() {
|
|
|
|
return chart;
|
|
|
|
return chart;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chart.header = function(_) {
|
|
|
|
|
|
|
|
if (!arguments.length) return header;
|
|
|
|
|
|
|
|
header = _;
|
|
|
|
|
|
|
|
return chart;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chart.noResultsText = function(_) {
|
|
|
|
|
|
|
|
if (!arguments.length) return noResultsText;
|
|
|
|
|
|
|
|
noResultsText = _;
|
|
|
|
|
|
|
|
return chart;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
chart.options = function(_) {
|
|
|
|
chart.options = function(_) {
|
|
|
|
if (!arguments.length) return options;
|
|
|
|
if (!arguments.length) return options;
|
|
|
|
options = _;
|
|
|
|
options = _;
|
|
|
|