diff --git a/nv.d3.js b/nv.d3.js index 702e43b..ba47af5 100644 --- a/nv.d3.js +++ b/nv.d3.js @@ -7780,6 +7780,7 @@ nv.models.pie = function() { , getValues = function(d) { return d.values } , getX = function(d) { return d.x } , getY = function(d) { return d.y } + , getDescription = function(d) { return d.description } , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , color = nv.utils.defaultColor() , valueFormat = d3.format(',.2f') @@ -8069,6 +8070,12 @@ nv.models.pie = function() { getY = d3.functor(_); return chart; }; + + chart.description = function(_) { + if (!arguments.length) return getDescription; + getDescription = _; + return chart; + }; chart.showLabels = function(_) { if (!arguments.length) return showLabels; @@ -8162,10 +8169,11 @@ nv.models.pieChart = function() { //------------------------------------------------------------ var showTooltip = function(e, offsetElement) { + var tooltipLabel = pie.description()(e.point) || pie.x()(e.point) var left = e.pos[0] + ( (offsetElement && offsetElement.offsetLeft) || 0 ), top = e.pos[1] + ( (offsetElement && offsetElement.offsetTop) || 0), y = pie.valueFormat()(pie.y()(e.point)), - content = tooltip(pie.x()(e.point), y, e, chart); + content = tooltip(tooltipLabel, y, e, chart); nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's', null, offsetElement); }; @@ -8344,7 +8352,7 @@ nv.models.pieChart = function() { chart.dispatch = dispatch; chart.pie = pie; - d3.rebind(chart, pie, 'valueFormat', 'values', 'x', 'y', 'id', 'showLabels', 'donutLabelsOutside', 'pieLabelsOutside', 'donut', 'labelThreshold'); + d3.rebind(chart, pie, 'valueFormat', 'values', 'x', 'y', 'description', 'id', 'showLabels', 'donutLabelsOutside', 'pieLabelsOutside', 'donut', 'labelThreshold'); chart.margin = function(_) { if (!arguments.length) return margin; diff --git a/src/models/pie.js b/src/models/pie.js index 51bd3b5..43e99f6 100644 --- a/src/models/pie.js +++ b/src/models/pie.js @@ -11,6 +11,7 @@ nv.models.pie = function() { , getValues = function(d) { return d.values } , getX = function(d) { return d.x } , getY = function(d) { return d.y } + , getDescription = function(d) { return d.description } , id = Math.floor(Math.random() * 10000) //Create semi-unique ID in case user doesn't select one , color = nv.utils.defaultColor() , valueFormat = d3.format(',.2f') @@ -300,6 +301,12 @@ nv.models.pie = function() { getY = d3.functor(_); return chart; }; + + chart.description = function(_) { + if (!arguments.length) return getDescription; + getDescription = _; + return chart; + }; chart.showLabels = function(_) { if (!arguments.length) return showLabels; diff --git a/src/models/pieChart.js b/src/models/pieChart.js index 12df8a6..75d85ac 100644 --- a/src/models/pieChart.js +++ b/src/models/pieChart.js @@ -32,10 +32,11 @@ nv.models.pieChart = function() { //------------------------------------------------------------ var showTooltip = function(e, offsetElement) { + var tooltipLabel = pie.description()(e.point) || pie.x()(e.point) var left = e.pos[0] + ( (offsetElement && offsetElement.offsetLeft) || 0 ), top = e.pos[1] + ( (offsetElement && offsetElement.offsetTop) || 0), y = pie.valueFormat()(pie.y()(e.point)), - content = tooltip(pie.x()(e.point), y, e, chart); + content = tooltip(tooltipLabel, y, e, chart); nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's', null, offsetElement); }; @@ -214,7 +215,7 @@ nv.models.pieChart = function() { chart.dispatch = dispatch; chart.pie = pie; - d3.rebind(chart, pie, 'valueFormat', 'values', 'x', 'y', 'id', 'showLabels', 'donutLabelsOutside', 'pieLabelsOutside', 'donut', 'labelThreshold'); + d3.rebind(chart, pie, 'valueFormat', 'values', 'x', 'y', 'description', 'id', 'showLabels', 'donutLabelsOutside', 'pieLabelsOutside', 'donut', 'labelThreshold'); chart.margin = function(_) { if (!arguments.length) return margin;