Issue #68 updated pie model to standard format

master-patched
Bob Monteverde 12 years ago
parent 6b5e4390ca
commit 7ffc993a5d

@ -6520,50 +6520,63 @@ nv.models.ohlcBar = function() {
}
nv.models.pie = function() {
var margin = {top: 0, right: 0, bottom: 0, left: 0},
width = 500,
height = 500,
getValues = function(d) { return d.values },
getX = function(d) { return d.x },
getY = function(d) { return d.y },
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'),
showLabels = true,
donutLabelsOutside = false,
labelThreshold = .02, //if slice percentage is under this, don't show label
donut = false;
var dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout');
//============================================================
// Public Variables with Default Settings
//------------------------------------------------------------
var margin = {top: 0, right: 0, bottom: 0, left: 0}
, width = 500
, height = 500
, getValues = function(d) { return d.values }
, getX = function(d) { return d.x }
, getY = function(d) { return d.y }
, 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')
, showLabels = true
, donutLabelsOutside = false
, labelThreshold = .02 //if slice percentage is under this, don't show label
, donut = false
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
;
//============================================================
function chart(selection) {
selection.each(function(data) {
var availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom,
radius = Math.min(availableWidth, availableHeight) / 2;
radius = Math.min(availableWidth, availableHeight) / 2,
container = d3.select(this);
var container = d3.select(this)
.on('click', function(d,i) {
dispatch.chartClick({
data: d,
index: i,
pos: d3.event,
id: id
});
});
//------------------------------------------------------------
// Setup containers and skeleton of chart
var wrap = container.selectAll('.nv-wrap.nv-pie').data([getValues(data[0])]);
var wrapEnter = wrap.enter().append('g').attr('class','nvd3 nv-wrap nv-pie nv-chart-' + id);
var gEnter = wrapEnter.append('g');
var g = wrap.select('g')
var g = wrap.select('g');
gEnter.append('g').attr('class', 'nv-pie');
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
g.select('.nv-pie').attr('transform', 'translate(' + availableWidth / 2 + ',' + availableHeight / 2 + ')');
//------------------------------------------------------------
container
.on('click', function(d,i) {
dispatch.chartClick({
data: d,
index: i,
pos: d3.event,
id: id
});
});
var arc = d3.svg.arc()
@ -6638,9 +6651,7 @@ nv.models.pie = function() {
d3.transition(slices.select('path'))
.attr('d', arc)
//.ease('bounce')
.attrTween('d', arcTween);
//.attrTween('d', tweenPie);
if (showLabels) {
// This does the normal label
@ -6730,6 +6741,10 @@ nv.models.pie = function() {
}
//============================================================
// Expose Public Variables
//------------------------------------------------------------
chart.dispatch = dispatch;
chart.margin = function(_) {
@ -6810,6 +6825,8 @@ nv.models.pie = function() {
return chart;
};
//============================================================
return chart;
}

2
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -1,49 +1,62 @@
nv.models.pie = function() {
var margin = {top: 0, right: 0, bottom: 0, left: 0},
width = 500,
height = 500,
getValues = function(d) { return d.values },
getX = function(d) { return d.x },
getY = function(d) { return d.y },
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'),
showLabels = true,
donutLabelsOutside = false,
labelThreshold = .02, //if slice percentage is under this, don't show label
donut = false;
var dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout');
//============================================================
// Public Variables with Default Settings
//------------------------------------------------------------
var margin = {top: 0, right: 0, bottom: 0, left: 0}
, width = 500
, height = 500
, getValues = function(d) { return d.values }
, getX = function(d) { return d.x }
, getY = function(d) { return d.y }
, 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')
, showLabels = true
, donutLabelsOutside = false
, labelThreshold = .02 //if slice percentage is under this, don't show label
, donut = false
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
;
//============================================================
function chart(selection) {
selection.each(function(data) {
var availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom,
radius = Math.min(availableWidth, availableHeight) / 2;
radius = Math.min(availableWidth, availableHeight) / 2,
container = d3.select(this);
var container = d3.select(this)
.on('click', function(d,i) {
dispatch.chartClick({
data: d,
index: i,
pos: d3.event,
id: id
});
});
//------------------------------------------------------------
// Setup containers and skeleton of chart
var wrap = container.selectAll('.nv-wrap.nv-pie').data([getValues(data[0])]);
var wrapEnter = wrap.enter().append('g').attr('class','nvd3 nv-wrap nv-pie nv-chart-' + id);
var gEnter = wrapEnter.append('g');
var g = wrap.select('g')
var g = wrap.select('g');
gEnter.append('g').attr('class', 'nv-pie');
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
g.select('.nv-pie').attr('transform', 'translate(' + availableWidth / 2 + ',' + availableHeight / 2 + ')');
//------------------------------------------------------------
container
.on('click', function(d,i) {
dispatch.chartClick({
data: d,
index: i,
pos: d3.event,
id: id
});
});
var arc = d3.svg.arc()
@ -118,9 +131,7 @@ nv.models.pie = function() {
d3.transition(slices.select('path'))
.attr('d', arc)
//.ease('bounce')
.attrTween('d', arcTween);
//.attrTween('d', tweenPie);
if (showLabels) {
// This does the normal label
@ -210,6 +221,10 @@ nv.models.pie = function() {
}
//============================================================
// Expose Public Variables
//------------------------------------------------------------
chart.dispatch = dispatch;
chart.margin = function(_) {
@ -290,6 +305,8 @@ nv.models.pie = function() {
return chart;
};
//============================================================
return chart;
}

Loading…
Cancel
Save