Fixing the tooltip so it correctly walks up the branch

This commit is contained in:
Chris Cowan 2014-10-20 19:18:23 -07:00
parent 6069ca2e64
commit b1e3d4b741

View file

@ -19,27 +19,39 @@ define(function (require) {
} }
var rows = $tooltipScope.rows = []; var rows = $tooltipScope.rows = [];
for (parent = datum; parent.parent; parent = parent.parent) {
var i = parent.depth - 1;
var col = columns[i];
// field/agg details // walk up the branch for each parent
var group = (col.field && col.field.name) || col.label || ('level ' + datum.depth); (function walk(item) {
// record the the depth
var i = item.depth - 1;
// field value that defines the bucket // Using the aggConfig determin what the field name is. If the aggConfig
var bucket = parent.name; // doesn't exist (which means it's an _all agg) then use the level for
if (col.field) bucket = col.field.format.convert(bucket); // the field name
var col = item.aggConfig;
var field = (col && col.params && col.params.field && col.params.field.name)
|| (col && col.label)
|| ('level ' + datum.depth);
// metric for the bucket // Set the bucket name, and use the converter to format the field if
var val = parent.value; // the field exists.
var bucket = item.name;
if (col && col.field) bucket = col.field.format.convert(bucket);
// Add the row to the tooltipScope.rows
rows.unshift({ rows.unshift({
spacer: $sce.trustAsHtml(_.repeat(' ', i)), spacer: $sce.trustAsHtml(_.repeat(' ', i)),
field: group, field: field,
bucket: bucket, bucket: bucket,
metric: val + ' (' + Math.round((parent.value / sum) * 100) + '%)' metric: item.value + ' (' + Math.round((item.value / sum) * 100) + '%)'
}); });
}
// If the item has a parent and it's also a child then continue walking
// up the branch
if (item.parent && item.parent.parent) {
walk(item.parent);
}
})(datum);
$tooltipScope.metricCol = _.find(columns, { categoryName: 'metric' }); $tooltipScope.metricCol = _.find(columns, { categoryName: 'metric' });