Compare commits

...

31 Commits

Author SHA1 Message Date
Robin Hu ca5f59b97d Fleshing out renderWatch for pieChart. 10 years ago
Robin Hu a513f414b1 Fleshing out renderWatch for stackedAreaChart. 10 years ago
Robin Hu 3b5e14167b Fleshing out renderWatch for multiBarHorizontalChart. 10 years ago
Robin Hu 6ca59f96a5 Fleshing out renderWatch for discreteBarChart. 10 years ago
Robin Hu e8c18f82c5 Added renderWatch to stackedAreaChart. 10 years ago
David Souther 4ca0448fa9 Merge pull request #435 from DavidSouther/development
Added Fn::bind polyfill.
10 years ago
David Souther 6ec05d686b Added Fn::bind polyfill.
Built.
10 years ago
Robin Hu 3ec2e500c2 Adding renderWatch to pieChart. 10 years ago
Robin Hu d40193aa2d Adding renderWatch to multibar horizontal chart. 10 years ago
Robin Hu fb7d07a298 Adding renderwatch renderEnd to discreteBarChart. 10 years ago
Robin Hu 4d2de136e7 Adding 'renderEnd' dispatch to discreteBar and multibarHorizontal.ç 10 years ago
frank shao 9201272013 built 10 years ago
frank shao 48e2684edf RenderWatch: Scatterpluslinechart 10 years ago
frank shao 0ef0e39384 RenderWatch: added to scatter plus line chart 10 years ago
David Souther 7364da25d5 Built. 10 years ago
David Souther 9800adeba6 Added watch on scatterPlusLineChart render end. 10 years ago
Robin Hu 8d8b727bb2 Renderwatch: Adding renderEnd dispatch to scatterPlusLineChart 10 years ago
frank shao 5da5323859 RenderWatch: added renderwatch api to selection.prototype 10 years ago
frank shao 504b5b0c9d RenderWatch: added render watch to cumulative line chart; various fixes 10 years ago
frank shao e177cae4d2 RenderWatch: added render watch to lineChart 10 years ago
frank shao 204a2e9e19 RenderWatch: Added render watch to scatterchart and submodels 10 years ago
frank shao a41d985c19 RenderWatch: Fixes 10 years ago
frank shao 5e1a7490b5 renderWatch: Modified addModels to accept list of models 10 years ago
frank shao 95fd1026b3 RenderWatch: fixes to axis.js 10 years ago
frank shao 7b490d2c85 Added util to watch for end of render; applied to multibarchart and its sub-models 10 years ago
frank shao 23fbe55024 Merge branch 'development' of https://github.com/novus/nvd3 into development 10 years ago
frank shao 7ad5580db3 Deprecated 'multibar.delay'. Use multibar.duration instead 10 years ago
Robin Hu e75bfb274e Merge branch 'master' into development 10 years ago
frank shao 4672f4b6ca build dist 11 years ago
frank shao fd61caaff6 Merge branch 'development' of https://github.com/novus/nvd3 into development 11 years ago
frank shao f621237ff8 Added tooltip adjustment so that it can also be dom element 11 years ago

@ -46,6 +46,7 @@ nv.models.scatterChart = function() {
//nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's');
};
var renderWatch = nv.utils.renderWatch(dispatch);
function chart(selection) {
selection.each(function(data) {

@ -59,19 +59,22 @@ text {
// Wrapping in nv.addGraph allows for '0 timeout render', stores rendered charts in nv.graphs, and may do more in the future... it's NOT required
nv.addGraph(function() {
var chart = nv.models.cumulativeLineChart()
.useInteractiveGuideline(true)
.x(function(d) { return d[0] })
.y(function(d) { return d[1]/100 })
.color(d3.scale.category10().range())
.average(function(d) { return d.mean/100; })
.transitionDuration(300)
.clipVoronoi(false);
var chart = nv.models.cumulativeLineChart()
.useInteractiveGuideline(true)
.x(function(d) { return d[0] })
.y(function(d) { return d[1]/100 })
.color(d3.scale.category10().range())
.average(function(d) { return d.mean/100; })
.duration(300)
.clipVoronoi(false);
chart.dispatch.on('renderEnd', function() {
console.log('render complete: cumulative line with guide line');
});
chart.xAxis
.tickFormat(function(d) {
return d3.time.format('%m/%d/%y')(new Date(d))
});
chart.xAxis
.tickFormat(function(d) {
return d3.time.format('%m/%d/%y')(new Date(d))
});
chart.yAxis
.tickFormat(d3.format(',.1%'));
@ -97,8 +100,13 @@ nv.addGraph(function() {
.y(function(d) { return d[1]/100 })
.color(d3.scale.category10().range())
.average(function(d) { return d.mean/100; })
.duration(300)
.clipVoronoi(false);
chart.dispatch.on('renderEnd', function() {
console.log('render complete: cumulative line without guide line');
});
chart.xAxis
.tickFormat(function(d) {
return d3.time.format('%m/%d/%y')(new Date(d))

@ -32,6 +32,9 @@ nv.addGraph({
.height(height)
.margin({top: 20, right: 20, bottom: 20, left: 20})
chart.dispatch.on('renderEnd', function(){
console.log('render complete');
});
d3.select('#test1')
.attr('width', width)

@ -62,19 +62,24 @@ nv.addGraph(function() {
x: function(d,i) { return i},
showXAxis: true,
showYAxis: true,
transitionDuration: 250
transitionDuration: 300,
useInteractiveGuideline: true
})
;
// chart sub-models (ie. xAxis, yAxis, etc) when accessed directly, return themselves, not the parent chart, so need to chain separately
chart.xAxis
.axisLabel("Time (s)")
.tickFormat(d3.format(',.1f'));
.tickFormat(d3.format(',.1f'))
;
chart.yAxis
.axisLabel('Voltage (v)')
.tickFormat(d3.format(',.2f'))
;
chart.dispatch.on('renderEnd', function(){
console.log('render complete');
});
d3.select('#chart1 svg')
.datum(sinAndCos())

@ -48,14 +48,19 @@ nv.addGraph({
.width(width)
.height(height)
.stacked(true)
.delay(0)
chart.dispatch.on('renderEnd', function(){
console.log('Render Complete');
});
var svg = d3.select('#test1 svg')
.attr('width', width)
.attr('height', height)
.datum(test_data);
svg.transition().duration(500).call(chart);
console.log('calling chart');
svg.transition().duration(0).call(chart);
return chart;
},
@ -79,10 +84,11 @@ nv.addGraph({
.width(width)
.height(height);
console.log('calling chart');
d3.select('#test1 svg')
.attr('width', width)
.attr('height', height)
transition().duration(500)
transition().duration(0)
.call(graph);
};

@ -69,24 +69,34 @@ nv.addGraph(function() {
chart = nv.models.multiBarChart()
.barColor(d3.scale.category20().range())
.margin({bottom: 100})
.transitionDuration(300)
.delay(0)
.duration(300)
.rotateLabels(45)
.groupSpacing(0.1)
;
chart.multibar
.hideable(true);
.hideable(true)
// .duration(4000)
;
chart.reduceXTicks(false).staggerLabels(true);
chart.xAxis
.axisLabel("Current Index")
.showMaxMin(true)
.tickFormat(d3.format(',.6f'));
.tickFormat(d3.format(',.6f'))
;
chart.yAxis
.tickFormat(d3.format(',.1f'));
.tickFormat(d3.format(',.1f'))
// .duration(2000)
;
chart.dispatch.on('renderEnd', function(){
console.log('Render Complete');
});
d3.select('#chart1 svg')
.datum(negative_test_data)
@ -96,9 +106,18 @@ nv.addGraph(function() {
chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });
return chart;
});
// setTimeout(function(){
// negative_test_data.forEach(function(d){
// d.values.forEach(function(e){
// e.y = 10;
// });
// });
// chart.update();
// }, 2000);

@ -35,7 +35,6 @@ nv.addGraph({
.useVoronoi(false)
//.interactive(false)
d3.select('#test1')
.attr('width', width)
.attr('height', height)

@ -70,6 +70,9 @@ nv.addGraph(function() {
.color(d3.scale.category10().range())
.transitionDuration(300)
;
chart.dispatch.on('renderEnd', function(){
console.log('render complete');
});
chart.xAxis.tickFormat(d3.format('.02f'));
chart.yAxis.tickFormat(d3.format('.02f'));

@ -69,6 +69,10 @@ nv.addGraph(function() {
.transitionDuration(300)
.color(d3.scale.category10().range());
chart.dispatch.on('renderEnd', function(){
console.log('render complete');
});
chart.xAxis.tickFormat(d3.format('.02f'))
chart.yAxis.tickFormat(d3.format('.02f'))

File diff suppressed because it is too large Load Diff

12
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -16,6 +16,33 @@ nv.logs = {}; //stores some statistics and potential error messages
nv.dispatch = d3.dispatch('render_start', 'render_end');
// *************************************************************************
// Function bind polyfill, from MDN
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Compatibility
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
// *************************************************************************
// Development render timers - disabled if dev = false
@ -48,6 +75,11 @@ nv.log = function() {
return arguments[arguments.length - 1];
};
nv.deprecated = function(name) {
if (nv.dev && console && console.warn)
console.warn('`' + name + '` has been deprecated.');
}
nv.render = function render(step) {
step = step || 1; // number of graphs to generate in each timeout loop

@ -20,8 +20,11 @@ nv.models.axis = function() {
, isOrdinal = false
, ticks = null
, axisLabelDistance = 12 //The larger this number is, the closer the axis label is to the axis.
, duration = 250
, dispatch = d3.dispatch('renderEnd')
, axisRendered = false
, maxMinRendered = false
;
axis
.scale(scale)
.orient('bottom')
@ -35,16 +38,17 @@ nv.models.axis = function() {
// Private Variables
//------------------------------------------------------------
var scale0;
var scale0
, renderWatch = nv.utils.renderWatch(dispatch, duration)
;
//============================================================
function chart(selection) {
renderWatch.reset();
selection.each(function(data) {
var container = d3.select(this);
//------------------------------------------------------------
// Setup containers and skeleton of chart
@ -63,9 +67,7 @@ nv.models.axis = function() {
//TODO: consider calculating width/height based on whether or not label is added, for reference in charts using this component
g.transition().call(axis);
g.watchTransition(renderWatch, 'axis').call(axis);
scale0 = scale0 || axis.scale();
@ -102,7 +104,7 @@ nv.models.axis = function() {
var v = fmt(d);
return ('' + v).match('NaN') ? '' : v;
});
axisMaxMin.transition()
axisMaxMin.watchTransition(renderWatch, 'min-max top')
.attr('transform', function(d,i) {
return 'translate(' + scale.range()[i] + ',0)'
});
@ -152,10 +154,8 @@ nv.models.axis = function() {
var v = fmt(d);
return ('' + v).match('NaN') ? '' : v;
});
axisMaxMin.transition()
axisMaxMin.watchTransition(renderWatch, 'min-max bottom')
.attr('transform', function(d,i) {
//return 'translate(' + scale.range()[i] + ',0)'
//return 'translate(' + scale(d) + ',0)'
return 'translate(' + (scale(d) + (isOrdinal ? scale.rangeBand() / 2 : 0)) + ',0)'
});
}
@ -190,7 +190,7 @@ nv.models.axis = function() {
var v = fmt(d);
return ('' + v).match('NaN') ? '' : v;
});
axisMaxMin.transition()
axisMaxMin.watchTransition(renderWatch, 'min-max right')
.attr('transform', function(d,i) {
return 'translate(0,' + scale.range()[i] + ')'
})
@ -232,7 +232,7 @@ nv.models.axis = function() {
var v = fmt(d);
return ('' + v).match('NaN') ? '' : v;
});
axisMaxMin.transition()
axisMaxMin.watchTransition(renderWatch, 'min-max right')
.attr('transform', function(d,i) {
return 'translate(0,' + scale.range()[i] + ')'
})
@ -303,7 +303,8 @@ nv.models.axis = function() {
scale0 = scale.copy();
});
renderWatch.renderEnd('axis immediate');
return chart;
}
@ -314,6 +315,7 @@ nv.models.axis = function() {
// expose chart's sub-components
chart.axis = axis;
chart.dispatch = dispatch;
d3.rebind(chart, axis, 'orient', 'tickValues', 'tickSubdivide', 'tickSize', 'tickPadding', 'tickFormat');
d3.rebind(chart, scale, 'domain', 'range', 'rangeBand', 'rangeBands'); //these are also accessible by chart.scale(), but added common ones directly for ease of use
@ -398,6 +400,14 @@ nv.models.axis = function() {
return chart;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
return chart;
};
//============================================================

@ -36,8 +36,9 @@ nv.models.cumulativeLineChart = function() {
, defaultState = null
, noData = 'No Data Available.'
, average = function(d) { return d.average }
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState', 'renderEnd')
, transitionDuration = 250
, duration = 250
, noErrorCheck = false //if set to TRUE, will bypass an error check in the indexify function.
;
@ -56,9 +57,11 @@ nv.models.cumulativeLineChart = function() {
// Private Variables
//------------------------------------------------------------
var dx = d3.scale.linear()
, index = {i: 0, x: 0}
;
var dx = d3.scale.linear()
, index = {i: 0, x: 0}
, renderWatch = nv.utils.renderWatch(dispatch, duration)
;
var showTooltip = function(e, offsetElement) {
var left = e.pos[0] + ( offsetElement.offsetLeft || 0 ),
@ -73,6 +76,10 @@ nv.models.cumulativeLineChart = function() {
//============================================================
function chart(selection) {
renderWatch.reset();
renderWatch.models(lines);
if (showXAxis) renderWatch.models(xAxis);
if (showYAxis) renderWatch.models(yAxis);
selection.each(function(data) {
var container = d3.select(this).classed('nv-chart-' + id, true),
that = this;
@ -83,7 +90,12 @@ nv.models.cumulativeLineChart = function() {
- margin.top - margin.bottom;
chart.update = function() { container.transition().duration(transitionDuration).call(chart) };
chart.update = function() {
if (duration === 0)
container.call(chart);
else
container.transition().duration(duration).call(chart)
};
chart.container = this;
//set state.disabled
@ -394,7 +406,7 @@ nv.models.cumulativeLineChart = function() {
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
d3.transition(g.select('.nv-x.nv-axis'))
g.select('.nv-x.nv-axis')
.call(xAxis);
}
@ -405,7 +417,7 @@ nv.models.cumulativeLineChart = function() {
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
d3.transition(g.select('.nv-y.nv-axis'))
g.select('.nv-y.nv-axis')
.call(yAxis);
}
//------------------------------------------------------------
@ -422,10 +434,10 @@ nv.models.cumulativeLineChart = function() {
//When dragging the index line, turn off line transitions.
// Then turn them back on when done dragging.
var oldDuration = chart.transitionDuration();
chart.transitionDuration(0);
var oldDuration = chart.duration();
chart.duration(0);
chart.update();
chart.transitionDuration(oldDuration);
chart.duration(oldDuration);
}
g.select('.nv-background rect')
@ -564,6 +576,8 @@ nv.models.cumulativeLineChart = function() {
});
renderWatch.renderEnd('cumulativeLineChart immediate');
return chart;
}
@ -716,8 +730,17 @@ nv.models.cumulativeLineChart = function() {
};
chart.transitionDuration = function(_) {
if (!arguments.length) return transitionDuration;
transitionDuration = _;
nv.deprecated('cumulativeLineChart.transitionDuration');
return chart.duration(_);
};
chart.duration = function(_) {
if(!arguments.length) return duration;
duration = _;
lines.duration(duration);
xAxis.duration(duration);
yAxis.duration(duration);
renderWatch.reset(duration);
return chart;
};

@ -21,8 +21,9 @@ nv.models.discreteBar = function() {
, yDomain
, xRange
, yRange
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout','renderEnd')
, rectClass = 'discreteBar'
, duration = 250
;
//============================================================
@ -33,11 +34,13 @@ nv.models.discreteBar = function() {
//------------------------------------------------------------
var x0, y0;
var renderWatch = nv.utils.renderWatch(dispatch, duration);
//============================================================
function chart(selection) {
renderWatch.reset();
selection.each(function(data) {
var availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom,
@ -103,7 +106,7 @@ nv.models.discreteBar = function() {
.style('stroke-opacity', 1e-6)
.style('fill-opacity', 1e-6);
groups.exit()
.transition()
.watchTransition(renderWatch, 'discreteBar: exit groups')
.style('stroke-opacity', 1e-6)
.style('fill-opacity', 1e-6)
.remove();
@ -111,7 +114,7 @@ nv.models.discreteBar = function() {
.attr('class', function(d,i) { return 'nv-group nv-series-' + i })
.classed('hover', function(d) { return d.hover });
groups
.transition()
.watchTransition(renderWatch, 'discreteBar: groups')
.style('stroke-opacity', 1)
.style('fill-opacity', .75);
@ -185,7 +188,7 @@ nv.models.discreteBar = function() {
bars.select('text')
.text(function(d,i) { return valueFormat(getY(d,i)) })
.transition()
.watchTransition(renderWatch, 'discreteBar: bars text')
.attr('x', x.rangeBand() * .9 / 2)
.attr('y', function(d,i) { return getY(d,i) < 0 ? y(getY(d,i)) - y(0) + 12 : -4 })
@ -200,9 +203,9 @@ nv.models.discreteBar = function() {
.style('stroke', function(d,i) { return d.color || color(d,i) })
.select('rect')
.attr('class', rectClass)
.transition()
.watchTransition(renderWatch, 'discreteBar: bars rect')
.attr('width', x.rangeBand() * .9 / data.length);
bars.transition()
bars.watchTransition(renderWatch, 'discreteBar: bars')
//.delay(function(d,i) { return i * 1200 / data[0].values.length })
.attr('transform', function(d,i) {
var left = x(getX(d,i)) + x.rangeBand() * .05,
@ -226,6 +229,7 @@ nv.models.discreteBar = function() {
});
renderWatch.renderEnd('discreteBar immediate');
return chart;
}
@ -342,6 +346,13 @@ nv.models.discreteBar = function() {
rectClass = _;
return chart;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
return chart;
};
//============================================================

@ -26,8 +26,8 @@ nv.models.discreteBarChart = function() {
, x
, y
, noData = "No Data Available."
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'beforeUpdate')
, transitionDuration = 250
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'beforeUpdate','renderEnd')
, duration = 250
;
xAxis
@ -58,10 +58,16 @@ nv.models.discreteBarChart = function() {
nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's', null, offsetElement);
};
var renderWatch = nv.utils.renderWatch(dispatch, duration);
//============================================================
function chart(selection) {
renderWatch.reset();
renderWatch.models(discretebar);
if (showXAxis) renderWatch.models(xAxis);
if (showYAxis) renderWatch.models(yAxis);
selection.each(function(data) {
var container = d3.select(this),
that = this;
@ -72,9 +78,9 @@ nv.models.discreteBarChart = function() {
- margin.top - margin.bottom;
chart.update = function() {
dispatch.beforeUpdate();
container.transition().duration(transitionDuration).call(chart);
chart.update = function() {
dispatch.beforeUpdate();
container.transition().duration(duration).call(chart);
};
chart.container = this;
@ -124,7 +130,7 @@ nv.models.discreteBarChart = function() {
gEnter.append('g').attr('class', 'nv-y nv-axis')
.append('g').attr('class', 'nv-zeroLine')
.append('line');
gEnter.append('g').attr('class', 'nv-barsWrap');
g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
@ -175,9 +181,8 @@ nv.models.discreteBarChart = function() {
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + (y.range()[0] + ((discretebar.showValues() && y.domain()[0] < 0) ? 16 : 0)) + ')');
//d3.transition(g.select('.nv-x.nv-axis'))
g.select('.nv-x.nv-axis').transition()
.call(xAxis);
g.select('.nv-x.nv-axis').call(xAxis);
var xTicks = g.select('.nv-x.nv-axis').selectAll('g');
@ -195,8 +200,7 @@ nv.models.discreteBarChart = function() {
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
g.select('.nv-y.nv-axis').transition()
.call(yAxis);
g.select('.nv-y.nv-axis').call(yAxis);
}
// Zero line
@ -223,6 +227,7 @@ nv.models.discreteBarChart = function() {
});
renderWatch.renderEnd('discreteBar chart immediate');
return chart;
}
@ -259,7 +264,7 @@ nv.models.discreteBarChart = function() {
d3.rebind(chart, discretebar, 'x', 'y', 'xDomain', 'yDomain', 'xRange', 'yRange', 'forceX', 'forceY', 'id', 'showValues', 'valueFormat');
chart.options = nv.utils.optionsFunc.bind(chart);
chart.margin = function(_) {
if (!arguments.length) return margin;
margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
@ -332,8 +337,17 @@ nv.models.discreteBarChart = function() {
};
chart.transitionDuration = function(_) {
if (!arguments.length) return transitionDuration;
transitionDuration = _;
nv.deprecated('discreteBar.transitionDuration');
return chart.duration(_);
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
discretebar.duration(duration);
xAxis.duration(duration);
yAxis.duration(duration);
return chart;
};

@ -13,6 +13,8 @@ nv.models.distribution = function() {
, color = nv.utils.defaultColor()
, scale = d3.scale.linear()
, domain
, duration = 250
, dispatch = d3.dispatch('renderEnd')
;
//============================================================
@ -23,11 +25,13 @@ nv.models.distribution = function() {
//------------------------------------------------------------
var scale0;
var renderWatch = nv.utils.renderWatch(dispatch, duration);
//============================================================
function chart(selection) {
renderWatch.reset();
selection.each(function(data) {
var availableLength = width - (axis === 'x' ? margin.left + margin.right : margin.top + margin.bottom),
naxis = axis == 'x' ? 'y' : 'x',
@ -68,8 +72,8 @@ nv.models.distribution = function() {
dist.enter().append('line')
.attr(axis + '1', function(d,i) { return scale0(getData(d,i)) })
.attr(axis + '2', function(d,i) { return scale0(getData(d,i)) })
distWrap.exit().selectAll('line.nv-dist' + axis)
.transition()
renderWatch.transition(distWrap.exit().selectAll('line.nv-dist' + axis), 'dist exit')
// .transition()
.attr(axis + '1', function(d,i) { return scale(getData(d,i)) })
.attr(axis + '2', function(d,i) { return scale(getData(d,i)) })
.style('stroke-opacity', 0)
@ -78,8 +82,8 @@ nv.models.distribution = function() {
.attr('class', function(d,i) { return 'nv-dist' + axis + ' nv-dist' + axis + '-' + i })
.attr(naxis + '1', 0)
.attr(naxis + '2', size);
dist
.transition()
renderWatch.transition(dist, 'dist')
// .transition()
.attr(axis + '1', function(d,i) { return scale(getData(d,i)) })
.attr(axis + '2', function(d,i) { return scale(getData(d,i)) })
@ -87,7 +91,7 @@ nv.models.distribution = function() {
scale0 = scale.copy();
});
renderWatch.renderEnd('distribution immediate');
return chart;
}
@ -96,6 +100,7 @@ nv.models.distribution = function() {
// Expose Public Variables
//------------------------------------------------------------
chart.options = nv.utils.optionsFunc.bind(chart);
chart.dispatch = dispatch;
chart.margin = function(_) {
if (!arguments.length) return margin;
@ -141,6 +146,13 @@ nv.models.distribution = function() {
color = nv.utils.getColor(_);
return chart;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
return chart;
};
//============================================================

@ -20,6 +20,8 @@ nv.models.line = function() {
, x //can be accessed via chart.xScale()
, y //can be accessed via chart.yScale()
, interpolate = "linear" // controls the line interpolation
, duration = 250
, dispatch = d3.dispatch('elementClick', 'elementMouseover', 'elementMouseout', 'renderEnd')
;
scatter
@ -35,12 +37,15 @@ nv.models.line = function() {
//------------------------------------------------------------
var x0, y0 //used to store previous scales
;
, renderWatch = nv.utils.renderWatch(dispatch, duration)
;
//============================================================
function chart(selection) {
renderWatch.reset();
renderWatch.models(scatter);
selection.each(function(data) {
var availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom,
@ -84,7 +89,7 @@ nv.models.line = function() {
var scatterWrap = wrap.select('.nv-scatterWrap');
//.datum(data); // Data automatically trickles down from the wrap
scatterWrap.transition().call(scatter);
scatterWrap.call(scatter);
@ -102,7 +107,6 @@ nv.models.line = function() {
var groups = wrap.select('.nv-groups').selectAll('.nv-group')
.data(function(d) { return d }, function(d) { return d.key });
groups.enter().append('g')
@ -116,8 +120,7 @@ nv.models.line = function() {
.classed('hover', function(d) { return d.hover })
.style('fill', function(d,i){ return color(d, i) })
.style('stroke', function(d,i){ return color(d, i)});
groups
.transition()
groups.watchTransition(renderWatch, 'line: groups')
.style('stroke-opacity', 1)
.style('fill-opacity', .5);
@ -140,8 +143,7 @@ nv.models.line = function() {
groups.exit().selectAll('path.nv-area')
.remove();
areaPaths
.transition()
areaPaths.watchTransition(renderWatch, 'line: areaPaths')
.attr('d', function(d) {
return d3.svg.area()
.interpolate(interpolate)
@ -167,8 +169,7 @@ nv.models.line = function() {
.y(function(d,i) { return nv.utils.NaNtoZero(y0(getY(d,i))) })
);
linePaths
.transition()
linePaths.watchTransition(renderWatch, 'line: linePaths')
.attr('d',
d3.svg.line()
.interpolate(interpolate)
@ -184,7 +185,7 @@ nv.models.line = function() {
y0 = y.copy();
});
renderWatch.renderEnd('line immediate');
return chart;
}
@ -193,8 +194,12 @@ nv.models.line = function() {
// Expose Public Variables
//------------------------------------------------------------
chart.dispatch = scatter.dispatch;
chart.dispatch = dispatch;
chart.scatter = scatter;
// Pass through events
scatter.dispatch.on('elementClick', function(){ dispatch.elementClick.apply(this, arguments); })
scatter.dispatch.on('elementMouseover', function(){ dispatch.elementMouseover.apply(this, arguments); })
scatter.dispatch.on('elementMouseout', function(){ dispatch.elementMouseout.apply(this, arguments); })
d3.rebind(chart, scatter, 'id', 'interactive', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain', 'xRange', 'yRange',
'sizeDomain', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'useVoronoi', 'clipRadius', 'padData','highlightPoint','clearHighlights');
@ -267,6 +272,14 @@ nv.models.line = function() {
return chart;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
scatter.duration(duration);
return chart;
};
//============================================================

@ -31,8 +31,8 @@ nv.models.lineChart = function() {
, state = {}
, defaultState = null
, noData = 'No Data Available.'
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, transitionDuration = 250
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState', 'renderEnd')
, duration = 250
;
xAxis
@ -60,10 +60,17 @@ nv.models.lineChart = function() {
nv.tooltip.show([left, top], content, null, null, offsetElement);
};
var renderWatch = nv.utils.renderWatch(dispatch, duration);
//============================================================
function chart(selection) {
renderWatch.reset();
renderWatch.models(lines);
if (showXAxis) renderWatch.models(xAxis);
if (showYAxis) renderWatch.models(yAxis);
selection.each(function(data) {
var container = d3.select(this),
that = this;
@ -74,7 +81,12 @@ nv.models.lineChart = function() {
- margin.top - margin.bottom;
chart.update = function() { container.transition().duration(transitionDuration).call(chart) };
chart.update = function() {
if (duration === 0)
container.call(chart);
else
container.transition().duration(duration).call(chart)
};
chart.container = this;
//set state.disabled
@ -199,7 +211,7 @@ nv.models.lineChart = function() {
var linesWrap = g.select('.nv-linesWrap')
.datum(data.filter(function(d) { return !d.disabled }))
linesWrap.transition().call(lines);
linesWrap.call(lines);
//------------------------------------------------------------
@ -216,7 +228,6 @@ nv.models.lineChart = function() {
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
g.select('.nv-x.nv-axis')
.transition()
.call(xAxis);
}
@ -227,7 +238,6 @@ nv.models.lineChart = function() {
.tickSize( -availableWidth, 0);
g.select('.nv-y.nv-axis')
.transition()
.call(yAxis);
}
//------------------------------------------------------------
@ -320,6 +330,7 @@ nv.models.lineChart = function() {
});
renderWatch.renderEnd('lineChart immediate');
return chart;
}
@ -455,8 +466,17 @@ nv.models.lineChart = function() {
};
chart.transitionDuration = function(_) {
if (!arguments.length) return transitionDuration;
transitionDuration = _;
nv.deprecated('lineChart.transitionDuration');
return chart.duration(_);
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
lines.duration(duration);
xAxis.duration(duration);
yAxis.duration(duration);
return chart;
};

@ -21,13 +21,13 @@ nv.models.multiBar = function() {
, hideable = false
, barColor = null // adding the ability to set the color for each rather than the whole group
, disabled // used in conjunction with barColor to communicate from multiBarHorizontalChart what series are disabled
, delay = 1200
, duration = 1000
, xDomain
, yDomain
, xRange
, yRange
, groupSpacing = 0.1
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'renderEnd')
;
//============================================================
@ -38,17 +38,30 @@ nv.models.multiBar = function() {
//------------------------------------------------------------
var x0, y0 //used to store previous scales
, renderWatch = nv.utils.renderWatch(dispatch, duration)
;
//============================================================
function chart(selection) {
renderWatch.reset();
selection.each(function(data) {
var availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom,
container = d3.select(this);
// This function defines the requirements for render complete
var endFn = function(d, i) {
if (d.series === data.length - 1 && i === data[0].values.length - 1)
return true;
return false;
}
if(hideable && data.length) hideable = [{
values: data[0].values.map(function(d) {
return {
@ -156,31 +169,29 @@ nv.models.multiBar = function() {
g .attr('clip-path', clipEdge ? 'url(#nv-edge-clip-' + id + ')' : '');
var groups = wrap.select('.nv-groups').selectAll('.nv-group')
.data(function(d) { return d }, function(d,i) { return i });
groups.enter().append('g')
.style('stroke-opacity', 1e-6)
.style('fill-opacity', 1e-6);
groups.exit()
.transition()
.selectAll('rect.nv-bar')
.delay(function(d,i) {
return i * delay/ data[0].values.length;
})
var exitTransition = renderWatch
.transition(groups.exit().selectAll('rect.nv-bar'), 'multibarExit', Math.min(250, duration))
.attr('y', function(d) { return stacked ? y0(d.y0) : y0(0) })
.attr('height', 0)
.remove();
if (exitTransition.delay)
exitTransition.delay(function(d,i) {
return i * duration / data[0].values.length;
});
groups
.attr('class', function(d,i) { return 'nv-group nv-series-' + i })
.classed('hover', function(d) { return d.hover })
.style('fill', function(d,i){ return color(d, i) })
.style('stroke', function(d,i){ return color(d, i) });
groups
.transition()
.style('stroke-opacity', 1)
.style('fill-opacity', .75);
.style('fill-opacity', 0.75);
var bars = groups.selectAll('rect.nv-bar')
@ -251,7 +262,6 @@ nv.models.multiBar = function() {
});
bars
.attr('class', function(d,i) { return getY(d,i) < 0 ? 'nv-bar negative' : 'nv-bar positive'})
.transition()
.attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',0)'; })
if (barColor) {
@ -261,63 +271,61 @@ nv.models.multiBar = function() {
.style('stroke', function(d,i,j) { return d3.rgb(barColor(d,i)).darker( disabled.map(function(d,i) { return i }).filter(function(d,i){ return !disabled[i] })[j] ).toString(); });
}
var barSelection =
bars.watchTransition(renderWatch, 'multibar', Math.min(250, duration))
.delay(function(d,i) {
return i * duration / data[0].values.length;
});
if (stacked)
bars.transition()
.delay(function(d,i) {
return i * delay / data[0].values.length;
})
barSelection
.attr('y', function(d,i) {
return y((stacked ? d.y1 : 0));
})
.attr('height', function(d,i) {
return Math.max(Math.abs(y(d.y + (stacked ? d.y0 : 0)) - y((stacked ? d.y0 : 0))),1);
})
.attr('x', function(d,i) {
return stacked ? 0 : (d.series * x.rangeBand() / data.length )
return stacked ? 0 : (d.series * x.rangeBand() / data.length )
})
.attr('width', x.rangeBand() / (stacked ? 1 : data.length) );
else
bars.transition()
.delay(function(d,i) {
return i * delay/ data[0].values.length;
})
barSelection
.attr('x', function(d,i) {
return d.series * x.rangeBand() / data.length
})
.attr('width', x.rangeBand() / data.length)
.attr('y', function(d,i) {
return getY(d,i) < 0 ?
y(0) :
y(0) - y(getY(d,i)) < 1 ?
y(0) - 1 :
y(getY(d,i)) || 0;
return getY(d,i) < 0 ?
y(0) :
y(0) - y(getY(d,i)) < 1 ?
y(0) - 1 :
y(getY(d,i)) || 0;
})
.attr('height', function(d,i) {
return Math.max(Math.abs(y(getY(d,i)) - y(0)),1) || 0;
return Math.max(Math.abs(y(getY(d,i)) - y(0)),1) || 0;
});
//store old scales for use in transitions on update
x0 = x.copy();
y0 = y.copy();
});
renderWatch.renderEnd('multibar immediate');
return chart;
}
//============================================================
// Expose Public Variables
//------------------------------------------------------------
chart.dispatch = dispatch;
// As a getter, returns a new instance of d3 dispatch and sets appropriate vars.
// As a setter, sets dispatch.
// Useful when same chart instance is used to render several data models.
// Since dispatch is instance-specific, it cannot be contained inside chart model.
chart.options = nv.utils.optionsFunc.bind(chart);
chart.dispatch = dispatch;
chart.x = function(_) {
if (!arguments.length) return getX;
@ -442,20 +450,33 @@ nv.models.multiBar = function() {
return chart;
};
chart.delay = function(_) {
if (!arguments.length) return delay;
delay = _;
return chart;
};
chart.groupSpacing = function(_) {
if (!arguments.length) return groupSpacing;
groupSpacing = _;
return chart;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
return chart;
}
//============================================================
// Deprecated Methods
//------------------------------------------------------------
chart.delay = function(_) {
nv.deprecated('multiBar.delay');
return chart.duration(_);
};
chart.options = nv.utils.optionsFunc.bind(chart);
//============================================================
return chart;
}

@ -34,9 +34,10 @@ nv.models.multiBarChart = function() {
, state = { stacked: false }
, defaultState = null
, noData = "No Data Available."
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState', 'renderEnd')
, controlWidth = function() { return showControls ? 180 : 0 }
, transitionDuration = 250
, duration = 250
;
multibar
@ -61,7 +62,8 @@ nv.models.multiBarChart = function() {
//============================================================
// Private Variables
//------------------------------------------------------------
var renderWatch = nv.utils.renderWatch(dispatch);
var showTooltip = function(e, offsetElement) {
var left = e.pos[0] + ( offsetElement.offsetLeft || 0 ),
top = e.pos[1] + ( offsetElement.offsetTop || 0),
@ -76,6 +78,11 @@ nv.models.multiBarChart = function() {
function chart(selection) {
renderWatch.reset();
renderWatch.models(multibar);
if (showXAxis) renderWatch.models(xAxis);
if (showYAxis) renderWatch.models(yAxis);
selection.each(function(data) {
var container = d3.select(this),
that = this;
@ -85,7 +92,14 @@ nv.models.multiBarChart = function() {
availableHeight = (height || parseInt(container.style('height')) || 400)
- margin.top - margin.bottom;
chart.update = function() { container.transition().duration(transitionDuration).call(chart) };
chart.update = function() {
if (duration === 0)
container.call(chart);
else
container.transition()
.duration(duration)
.call(chart);
};
chart.container = this;
//set state.disabled
@ -219,7 +233,7 @@ nv.models.multiBarChart = function() {
var barsWrap = g.select('.nv-barsWrap')
.datum(data.filter(function(d) { return !d.disabled }))
barsWrap.transition().call(multibar);
barsWrap.call(multibar);
//------------------------------------------------------------
@ -235,7 +249,7 @@ nv.models.multiBarChart = function() {
g.select('.nv-x.nv-axis')
.attr('transform', 'translate(0,' + y.range()[0] + ')');
g.select('.nv-x.nv-axis').transition()
g.select('.nv-x.nv-axis')
.call(xAxis);
var xTicks = g.select('.nv-x.nv-axis > g').selectAll('g');
@ -283,13 +297,13 @@ nv.models.multiBarChart = function() {
}
if (showYAxis) {
if (showYAxis) {
yAxis
.scale(y)
.ticks( availableHeight / 36 )
.tickSize( -availableWidth, 0);
g.select('.nv-y.nv-axis').transition()
g.select('.nv-y.nv-axis')
.call(yAxis);
}
@ -359,6 +373,8 @@ nv.models.multiBarChart = function() {
});
renderWatch.renderEnd('multibarchart immediate');
return chart;
}
@ -379,6 +395,7 @@ nv.models.multiBarChart = function() {
if (tooltips) nv.tooltip.cleanup();
});
//============================================================
@ -414,12 +431,14 @@ nv.models.multiBarChart = function() {
};
chart.height = function(_) {
if (!arguments.length) return height;
height = _;
return chart;
};
chart.color = function(_) {
if (!arguments.length) return color;
color = nv.utils.getColor(_);
legend.color(color);
@ -512,11 +531,20 @@ nv.models.multiBarChart = function() {
};
chart.transitionDuration = function(_) {
if (!arguments.length) return transitionDuration;
transitionDuration = _;
return chart;
nv.deprecated('multiBarChart.transitionDuration');
return chart.duration(_);
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
multibar.duration(duration);
xAxis.duration(duration);
yAxis.duration(duration);
renderWatch.reset(duration);
return chart;
}
//============================================================

@ -27,7 +27,8 @@ nv.models.multiBarHorizontal = function() {
, yDomain
, xRange
, yRange
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
, duration = 250
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout','renderEnd')
;
//============================================================
@ -37,13 +38,15 @@ nv.models.multiBarHorizontal = function() {
// Private Variables
//------------------------------------------------------------
var x0, y0 //used to store previous scales
;
var x0, y0; //used to store previous scales
var renderWatch = nv.utils.renderWatch(dispatch, duration);
//============================================================
function chart(selection) {
renderWatch.reset();
selection.each(function(data) {
var availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom,
@ -138,7 +141,7 @@ nv.models.multiBarHorizontal = function() {
groups.enter().append('g')
.style('stroke-opacity', 1e-6)
.style('fill-opacity', 1e-6);
groups.exit().transition()
groups.exit().watchTransition(renderWatch, 'multibarhorizontal: exit groups')
.style('stroke-opacity', 1e-6)
.style('fill-opacity', 1e-6)
.remove();
@ -147,7 +150,7 @@ nv.models.multiBarHorizontal = function() {
.classed('hover', function(d) { return d.hover })
.style('fill', function(d,i){ return color(d, i) })
.style('stroke', function(d,i){ return color(d, i) });
groups.transition()
groups.watchTransition(renderWatch, 'multibarhorizontal: groups')
.style('stroke-opacity', 1)
.style('fill-opacity', .75);
@ -225,7 +228,7 @@ nv.models.multiBarHorizontal = function() {
.attr('y', x.rangeBand() / (data.length * 2))
.attr('dy', '.32em')
.text(function(d,i) { return valueFormat(getY(d,i)) })
bars.transition()
bars.watchTransition(renderWatch, 'multibarhorizontal: bars')
.select('text')
.attr('x', function(d,i) { return getY(d,i) < 0 ? -4 : y(getY(d,i)) - y(0) + 4 })
} else {
@ -239,7 +242,7 @@ nv.models.multiBarHorizontal = function() {
.attr('y', x.rangeBand() / (data.length * 2))
.attr('dy', '.32em')
.text(function(d,i) { return getX(d,i) });
bars.transition()
bars.watchTransition(renderWatch, 'multibarhorizontal: bars')
.select('text.nv-bar-label')
.attr('x', function(d,i) { return getY(d,i) < 0 ? y(0) - y(getY(d,i)) + 4 : -4 });
}
@ -258,7 +261,7 @@ nv.models.multiBarHorizontal = function() {
}
if (stacked)
bars.transition()
bars.watchTransition(renderWatch, 'multibarhorizontal: bars')
.attr('transform', function(d,i) {
return 'translate(' + y(d.y1) + ',' + x(getX(d,i)) + ')'
})
@ -268,7 +271,7 @@ nv.models.multiBarHorizontal = function() {
})
.attr('height', x.rangeBand() );
else
bars.transition()
bars.watchTransition(renderWatch, 'multibarhorizontal: bars')
.attr('transform', function(d,i) {
//TODO: stacked must be all positive or all negative, not both?
return 'translate(' +
@ -292,6 +295,7 @@ nv.models.multiBarHorizontal = function() {
});
renderWatch.renderEnd('multibarHorizontal immediate');
return chart;
}
@ -440,6 +444,13 @@ nv.models.multiBarHorizontal = function() {
return chart;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
return chart;
};
//============================================================

@ -31,9 +31,9 @@ nv.models.multiBarHorizontalChart = function() {
, state = { stacked: stacked }
, defaultState = null
, noData = 'No Data Available.'
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState','renderEnd')
, controlWidth = function() { return showControls ? 180 : 0 }
, transitionDuration = 250
, duration = 250
;
multibar
@ -70,9 +70,14 @@ nv.models.multiBarHorizontalChart = function() {
};
//============================================================
var renderWatch = nv.utils.renderWatch(dispatch, duration);
function chart(selection) {
renderWatch.reset();
renderWatch.models(multibar);
if (showXAxis) renderWatch.models(xAxis);
if (showYAxis) renderWatch.models(yAxis);
selection.each(function(data) {
var container = d3.select(this),
that = this;
@ -82,7 +87,7 @@ nv.models.multiBarHorizontalChart = function() {
availableHeight = (height || parseInt(container.style('height')) || 400)
- margin.top - margin.bottom;
chart.update = function() { container.transition().duration(transitionDuration).call(chart) };
chart.update = function() { container.transition().duration(duration).call(chart) };
chart.container = this;
//set state.disabled
@ -229,8 +234,7 @@ nv.models.multiBarHorizontalChart = function() {
.ticks( availableHeight / 24 )
.tickSize(-availableWidth, 0);
g.select('.nv-x.nv-axis').transition()
.call(xAxis);
g.select('.nv-x.nv-axis').call(xAxis);
var xTicks = g.select('.nv-x.nv-axis').selectAll('g');
@ -246,8 +250,7 @@ nv.models.multiBarHorizontalChart = function() {
g.select('.nv-y.nv-axis')
.attr('transform', 'translate(0,' + availableHeight + ')');
g.select('.nv-y.nv-axis').transition()
.call(yAxis);
g.select('.nv-y.nv-axis').call(yAxis);
}
// Zero line
@ -319,9 +322,8 @@ nv.models.multiBarHorizontalChart = function() {
});
//============================================================
});
renderWatch.renderEnd('multibar horizontal chart immediate');
return chart;
}
@ -450,8 +452,17 @@ nv.models.multiBarHorizontalChart = function() {
};
chart.transitionDuration = function(_) {
if (!arguments.length) return transitionDuration;
transitionDuration = _;
nv.deprecated('multiBarHorizontalChart.transitionDuration');
return chart.duration(_);
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
multibar.duration(duration);
xAxis.duration(duration);
yAxis.duration(duration);
return chart;
};
//============================================================

@ -23,13 +23,15 @@ nv.models.pie = function() {
, startAngle = false
, endAngle = false
, donutRatio = 0.5
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout')
, duration = 250
, dispatch = d3.dispatch('chartClick', 'elementClick', 'elementDblClick', 'elementMouseover', 'elementMouseout', 'renderEnd')
;
//============================================================
var renderWatch = nv.utils.renderWatch(dispatch);
function chart(selection) {
renderWatch.reset();
selection.each(function(data) {
var availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom,
@ -198,7 +200,7 @@ nv.models.pie = function() {
return Math.floor(coordinates[0]/avgWidth) * avgWidth + ',' + Math.floor(coordinates[1]/avgHeight) * avgHeight;
};
pieLabels.transition()
pieLabels.watchTransition(renderWatch,'pie labels')
.attr('transform', function(d) {
if (labelSunbeamLayout) {
d.outerRadius = arcRadius + 10; // Set Outer Coordinate
@ -269,6 +271,7 @@ nv.models.pie = function() {
});
renderWatch.renderEnd('pie immediate');
return chart;
}
@ -402,6 +405,13 @@ nv.models.pie = function() {
labelThreshold = _;
return chart;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
return chart;
};
//============================================================

@ -21,7 +21,8 @@ nv.models.pieChart = function() {
, state = {}
, defaultState = null
, noData = "No Data Available."
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, duration = 250
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState','renderEnd')
;
//============================================================
@ -41,10 +42,14 @@ nv.models.pieChart = function() {
nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's', null, offsetElement);
};
var renderWatch = nv.utils.renderWatch(dispatch);
//============================================================
function chart(selection) {
renderWatch.reset();
renderWatch.models(pie);
selection.each(function(data) {
var container = d3.select(this),
that = this;
@ -185,6 +190,7 @@ nv.models.pieChart = function() {
});
renderWatch.renderEnd('pieChart immediate');
return chart;
}
@ -219,7 +225,7 @@ nv.models.pieChart = function() {
d3.rebind(chart, pie, 'valueFormat', 'values', 'x', 'y', 'description', 'id', 'showLabels', 'donutLabelsOutside', 'pieLabelsOutside', 'labelType', 'donut', 'donutRatio', 'labelThreshold');
chart.options = nv.utils.optionsFunc.bind(chart);
chart.margin = function(_) {
if (!arguments.length) return margin;
margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
@ -285,6 +291,14 @@ nv.models.pieChart = function() {
return chart;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
pie.duration(duration);
return chart;
};
//============================================================

@ -36,8 +36,9 @@ nv.models.scatter = function() {
, sizeDomain = null // Override point size domain
, sizeRange = null
, singlePoint = false
, dispatch = d3.dispatch('elementClick', 'elementMouseover', 'elementMouseout')
, dispatch = d3.dispatch('elementClick', 'elementMouseover', 'elementMouseout', 'renderEnd')
, useVoronoi = true
, duration = 250
;
//============================================================
@ -50,12 +51,14 @@ nv.models.scatter = function() {
var x0, y0, z0 // used to store previous scales
, timeoutID
, needsUpdate = false // Flag for when the points are visually updating, but the interactive layer is behind, to disable tooltips
, renderWatch = nv.utils.renderWatch(dispatch, duration)
;
//============================================================
function chart(selection) {
renderWatch.reset();
selection.each(function(data) {
var availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom,
@ -333,7 +336,6 @@ nv.models.scatter = function() {
}
needsUpdate = true;
var groups = wrap.select('.nv-groups').selectAll('.nv-group')
.data(function(d) { return d }, function(d) { return d.key });
groups.enter().append('g')
@ -344,8 +346,7 @@ nv.models.scatter = function() {
groups
.attr('class', function(d,i) { return 'nv-group nv-series-' + i })
.classed('hover', function(d) { return d.hover });
groups
.transition()
groups.watchTransition(renderWatch, 'scatter: groups')
.style('fill', function(d,i) { return color(d, i) })
.style('stroke', function(d,i) { return color(d, i) })
.style('stroke-opacity', 1)
@ -353,7 +354,6 @@ nv.models.scatter = function() {
if (onlyCircles) {
var points = groups.selectAll('circle.nv-point')
.data(function(d) { return d.values }, pointKey);
points.enter().append('circle')
@ -363,7 +363,8 @@ nv.models.scatter = function() {
.attr('cy', function(d,i) { return nv.utils.NaNtoZero(y0(getY(d,i))) })
.attr('r', function(d,i) { return Math.sqrt(z(getSize(d,i))/Math.PI) });
points.exit().remove();
groups.exit().selectAll('path.nv-point').transition()
groups.exit().selectAll('path.nv-point')
.watchTransition(renderWatch, 'scatter exit')
.attr('cx', function(d,i) { return nv.utils.NaNtoZero(x(getX(d,i))) })
.attr('cy', function(d,i) { return nv.utils.NaNtoZero(y(getY(d,i))) })
.remove();
@ -374,7 +375,8 @@ nv.models.scatter = function() {
.classed('hover',false)
;
});
points.transition()
points
.watchTransition(renderWatch, 'scatter points')
.attr('cx', function(d,i) { return nv.utils.NaNtoZero(x(getX(d,i))) })
.attr('cy', function(d,i) { return nv.utils.NaNtoZero(y(getY(d,i))) })
.attr('r', function(d,i) { return Math.sqrt(z(getSize(d,i))/Math.PI) });
@ -396,7 +398,7 @@ nv.models.scatter = function() {
);
points.exit().remove();
groups.exit().selectAll('path.nv-point')
.transition()
.watchTransition(renderWatch, 'scatter exit')
.attr('transform', function(d,i) {
return 'translate(' + x(getX(d,i)) + ',' + y(getY(d,i)) + ')'
})
@ -408,7 +410,8 @@ nv.models.scatter = function() {
.classed('hover',false)
;
});
points.transition()
points
.watchTransition(renderWatch, 'scatter points')
.attr('transform', function(d,i) {
//nv.log(d,i,getX(d,i), x(getX(d,i)));
return 'translate(' + x(getX(d,i)) + ',' + y(getY(d,i)) + ')'
@ -432,7 +435,7 @@ nv.models.scatter = function() {
z0 = z.copy();
});
renderWatch.renderEnd('scatter immediate');
return chart;
}
@ -667,6 +670,13 @@ nv.models.scatter = function() {
return chart;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
return chart;
};
//============================================================

@ -36,9 +36,10 @@ nv.models.scatterChart = function() {
, tooltip = null
, state = {}
, defaultState = null
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState', 'renderEnd')
, noData = "No Data Available."
, transitionDuration = 250
, duration = 250
;
scatter
@ -70,6 +71,7 @@ nv.models.scatterChart = function() {
//------------------------------------------------------------
var x0, y0;
var renderWatch = nv.utils.renderWatch(dispatch, duration);
var showTooltip = function(e, offsetElement) {
//TODO: make tooltip style an option between single or dual on axes (maybe on all charts with axes?)
@ -99,6 +101,13 @@ nv.models.scatterChart = function() {
function chart(selection) {
renderWatch.reset();
renderWatch.models(scatter);
if (showXAxis) renderWatch.models(xAxis);
if (showYAxis) renderWatch.models(yAxis);
if (showDistX) renderWatch.models(distX);
if (showDistY) renderWatch.models(distY);
selection.each(function(data) {
var container = d3.select(this),
that = this;
@ -108,7 +117,12 @@ nv.models.scatterChart = function() {
availableHeight = (height || parseInt(container.style('height')) || 400)
- margin.top - margin.bottom;
chart.update = function() { container.transition().duration(transitionDuration).call(chart); };
chart.update = function() {
if (duration === 0)
container.call(chart);
else
container.transition().duration(duration).call(chart);
};
chart.container = this;
//set state.disabled
@ -239,7 +253,6 @@ nv.models.scatterChart = function() {
if (yPadding !== 0)
scatter.yDomain(null);
wrap.select('.nv-scatterWrap')
.datum(data.filter(function(d) { return !d.disabled }))
.call(scatter);
@ -440,7 +453,7 @@ nv.models.scatterChart = function() {
});
renderWatch.renderEnd('scatterChart immediate');
return chart;
}
@ -614,11 +627,20 @@ nv.models.scatterChart = function() {
noData = _;
return chart;
};
chart.transitionDuration = function(_) {
if (!arguments.length) return transitionDuration;
transitionDuration = _;
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
scatter.duration(duration);
xAxis.duration(duration);
yAxis.duration(duration);
distX.duration(duration);
distY.duration(duration);
return chart;
}
chart.transitionDuration = function(_) {
nv.deprecated('scatterChart.transitionDuration');
return chart.duration(_);
};
//============================================================

@ -32,13 +32,13 @@ nv.models.scatterPlusLineChart = function() {
, tooltips = true
, tooltipX = function(key, x, y) { return '<strong>' + x + '</strong>' }
, tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' }
, tooltip = function(key, x, y, date) { return '<h3>' + key + '</h3>'
, tooltip = function(key, x, y, date) { return '<h3>' + key + '</h3>'
+ '<p>' + date + '</p>' }
, state = {}
, defaultState = null
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState', 'renderEnd')
, noData = "No Data Available."
, transitionDuration = 250
, duration = 250
;
scatter
@ -59,7 +59,7 @@ nv.models.scatterPlusLineChart = function() {
distY
.axis('y')
;
controls.updateState(false);
//============================================================
@ -68,7 +68,9 @@ nv.models.scatterPlusLineChart = function() {
// Private Variables
//------------------------------------------------------------
var x0, y0;
var x0, y0
, renderWatch = nv.utils.renderWatch(dispatch, duration)
;
var showTooltip = function(e, offsetElement) {
//TODO: make tooltip style an option between single or dual on axes (maybe on all charts with axes?)
@ -98,6 +100,13 @@ nv.models.scatterPlusLineChart = function() {
function chart(selection) {
renderWatch.reset();
renderWatch.models(scatter);
if (showXAxis) renderWatch.models(xAxis);
if (showYAxis) renderWatch.models(yAxis);
if (showDistX) renderWatch.models(distX);
if (showDistY) renderWatch.models(distY);
selection.each(function(data) {
var container = d3.select(this),
that = this;
@ -107,7 +116,12 @@ nv.models.scatterPlusLineChart = function() {
availableHeight = (height || parseInt(container.style('height')) || 400)
- margin.top - margin.bottom;
chart.update = function() { container.transition().duration(transitionDuration).call(chart); };
chart.update = function() {
if (duration === 0)
container.call(chart);
else
container.transition().duration(duration).call(chart);
};
chart.container = this;
//set state.disabled
@ -139,7 +153,9 @@ nv.models.scatterPlusLineChart = function() {
.attr('x', margin.left + availableWidth / 2)
.attr('y', margin.top + availableHeight / 2)
.text(function(d) { return d });
renderWatch.renderEnd('scatter immediate');
return chart;
} else {
container.selectAll('.nv-noData').remove();
@ -245,7 +261,7 @@ nv.models.scatterPlusLineChart = function() {
var regWrap = wrap.select('.nv-regressionLinesWrap').selectAll('.nv-regLines')
.data(function(d) {return d });
regWrap.enter().append('g').attr('class', 'nv-regLines');
var regLine = regWrap.selectAll('.nv-regLine').data(function(d){return [d]});
@ -254,14 +270,14 @@ nv.models.scatterPlusLineChart = function() {
.style('stroke-opacity', 0);
regLine
.transition()
.watchTransition(renderWatch, 'scatterPlusLineChart: regline')
.attr('x1', x.range()[0])
.attr('x2', x.range()[1])
.attr('y1', function(d,i) {return y(x.domain()[0] * d.slope + d.intercept) })
.attr('y2', function(d,i) { return y(x.domain()[1] * d.slope + d.intercept) })
.style('stroke', function(d,i,j) { return color(d,j) })
.style('stroke-opacity', function(d,i) {
return (d.disabled || typeof d.slope === 'undefined' || typeof d.intercept === 'undefined') ? 0 : 1
return (d.disabled || typeof d.slope === 'undefined' || typeof d.intercept === 'undefined') ? 0 : 1
});
//------------------------------------------------------------
@ -342,6 +358,8 @@ nv.models.scatterPlusLineChart = function() {
});
}
// At this point, everything has been selected and bound... I think
function updateFisheye() {
if (pauseFisheye) {
@ -364,7 +382,7 @@ nv.models.scatterPlusLineChart = function() {
if (showYAxis)
g.select('.nv-y.nv-axis').call(yAxis);
g.select('.nv-distributionX')
.datum(data.filter(function(d) { return !d.disabled }))
.call(distX);
@ -400,7 +418,7 @@ nv.models.scatterPlusLineChart = function() {
chart.update();
});
legend.dispatch.on('stateChange', function(newState) {
legend.dispatch.on('stateChange', function(newState) {
state = newState;
dispatch.stateChange(state);
chart.update();
@ -445,10 +463,10 @@ nv.models.scatterPlusLineChart = function() {
});
renderWatch.renderEnd('scatter with line immediate');
return chart;
}
//============================================================
// Event Handling/Dispatching (out of chart's scope)
//------------------------------------------------------------
@ -485,7 +503,7 @@ nv.models.scatterPlusLineChart = function() {
d3.rebind(chart, scatter, 'id', 'interactive', 'pointActive', 'x', 'y', 'shape', 'size', 'xScale', 'yScale', 'zScale', 'xDomain', 'yDomain', 'xRange', 'yRange', 'sizeDomain', 'sizeRange', 'forceX', 'forceY', 'forceSize', 'clipVoronoi', 'clipRadius', 'useVoronoi');
chart.options = nv.utils.optionsFunc.bind(chart);
chart.margin = function(_) {
if (!arguments.length) return margin;
margin.top = typeof _.top != 'undefined' ? _.top : margin.top;
@ -608,8 +626,13 @@ nv.models.scatterPlusLineChart = function() {
};
chart.transitionDuration = function(_) {
if (!arguments.length) return transitionDuration;
transitionDuration = _;
nv.deprecated('scatterPlusLineChart.transitionDuration')
return chart.duration(_);
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
return chart;
};

@ -20,7 +20,8 @@ nv.models.stackedArea = function() {
, x //can be accessed via chart.xScale()
, y //can be accessed via chart.yScale()
, scatter = nv.models.scatter()
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'areaClick', 'areaMouseover', 'areaMouseout')
, duration = 250
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'areaClick', 'areaMouseover', 'areaMouseout','renderEnd')
;
scatter
@ -41,9 +42,12 @@ nv.models.stackedArea = function() {
************************************/
//============================================================
var renderWatch = nv.utils.renderWatch(dispatch, duration);
function chart(selection) {
renderWatch.reset();
renderWatch.models(scatter);
selection.each(function(data) {
var availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom,
@ -189,7 +193,7 @@ nv.models.stackedArea = function() {
return d.color || color(d, d.seriesIndex)
})
.style('stroke', function(d,i){ return d.color || color(d, d.seriesIndex) });
path.transition()
path.watchTransition(renderWatch,'stackedArea path')
.attr('d', function(d,i) {
return area(d.values,i)
});
@ -234,7 +238,7 @@ nv.models.stackedArea = function() {
});
renderWatch.renderEnd('stackedArea immediate');
return chart;
}
@ -361,6 +365,15 @@ nv.models.stackedArea = function() {
interpolate = _;
return chart;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
scatter.duration(duration);
return chart;
};
//============================================================

@ -34,11 +34,11 @@ nv.models.stackedAreaChart = function() {
, state = { style: stacked.style() }
, defaultState = null
, noData = 'No Data Available.'
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState','renderEnd')
, controlWidth = 250
, cData = ['Stacked','Stream','Expanded']
, controlLabels = {}
, transitionDuration = 250
, duration = 250
;
xAxis
@ -56,6 +56,7 @@ nv.models.stackedAreaChart = function() {
//============================================================
// Private Variables
//------------------------------------------------------------
var renderWatch = nv.utils.renderWatch(dispatch);
var showTooltip = function(e, offsetElement) {
var left = e.pos[0] + ( offsetElement.offsetLeft || 0 ),
@ -71,6 +72,11 @@ nv.models.stackedAreaChart = function() {
function chart(selection) {
renderWatch.reset();
renderWatch.models(stacked);
if (showXAxis) renderWatch.models(xAxis);
if (showYAxis) renderWatch.models(yAxis);
selection.each(function(data) {
var container = d3.select(this),
that = this;
@ -80,7 +86,7 @@ nv.models.stackedAreaChart = function() {
availableHeight = (height || parseInt(container.style('height')) || 400)
- margin.top - margin.bottom;
chart.update = function() { container.transition().duration(transitionDuration).call(chart); };
chart.update = function() { container.transition().duration(duration).call(chart); };
chart.container = this;
//set state.disabled
@ -444,7 +450,7 @@ nv.models.stackedAreaChart = function() {
});
renderWatch.renderEnd('stacked Area chart immediate');
return chart;
}
@ -602,9 +608,8 @@ nv.models.stackedAreaChart = function() {
};
chart.transitionDuration = function(_) {
if (!arguments.length) return transitionDuration;
transitionDuration = _;
return chart;
nv.deprecated('lineChart.transitionDuration');
return chart.duration(_);
};
chart.controlsData = function(_) {
@ -628,6 +633,16 @@ nv.models.stackedAreaChart = function() {
return yAxis;
};
chart.duration = function(_) {
if (!arguments.length) return duration;
duration = _;
renderWatch.reset(duration);
stacked.duration(duration);
xAxis.duration(duration);
yAxis.duration(duration);
return chart;
};
//============================================================

@ -337,7 +337,11 @@ window.nv.tooltip.* also has various helper methods.
container.style.left = 0;
container.style.top = 0;
container.style.opacity = 0;
container.innerHTML = content;
// Content can also be dom element
if (typeof content !== 'string')
container.appendChild(content);
else
container.innerHTML = content;
body.appendChild(container);
//If the parent container is an overflow <div> with scrollbars, subtract the scroll offsets.

@ -130,6 +130,90 @@ nv.utils.NaNtoZero = function(n) {
return n;
};
// This utility class watches for d3 transition ends.
(function(){
d3.selection.prototype.watchTransition = function(renderWatch){
var args = [this].concat([].slice.call(arguments, 1));
return renderWatch.transition.apply(renderWatch, args);
}
})();
nv.utils.renderWatch = function(dispatch, duration) {
if (!(this instanceof nv.utils.renderWatch))
return new nv.utils.renderWatch(dispatch, duration);
var _duration = duration !== undefined ? duration : 250;
var renderStack = [];
var self = this;
this.models = function(models) {
models = [].slice.call(arguments, 0);
models.forEach(function(model){
model.__rendered = false;
(function(m){
m.dispatch.on('renderEnd', function(arg){
// nv.log('nv.utils renderEnd', arg);
m.__rendered = true;
self.renderEnd('model');
});
})(model);
if (renderStack.indexOf(model) < 0)
renderStack.push(model);
});
return this;
}
this.reset = function(duration) {
if (duration !== undefined) _duration = duration;
renderStack = [];
}
this.transition = function(selection, args, duration) {
args = arguments.length > 1 ? [].slice.call(arguments, 1) : [];
duration = args.length > 1 ? args.pop() :
_duration !== undefined ? _duration :
250;
selection.__rendered = false;
if (renderStack.indexOf(selection) < 0)
renderStack.push(selection);
if (duration === 0)
{
selection.__rendered = true;
selection.delay = function(){console.warn('`delay` not specified for selection.'); return this;}
selection.duration = function(){console.warn('`duration` not specified for selection.'); return this;}
return selection;
}
else
{
selection.__rendered = selection.length === 0 ? true :
selection.every( function(d){ return !d.length; }) ? true :
false;
var n = 0;
return selection
.transition()
.duration(duration)
.each(function(){ ++n; })
.each('end', function(d, i){
if (--n === 0)
{
selection.__rendered = true;
self.renderEnd.apply(this, args);
}
});
}
}
this.renderEnd = function() {
if (renderStack.every( function(d){ return d.__rendered; } ))
{
renderStack.forEach( function(d){ d.__rendered = false; });
dispatch.renderEnd.apply(this, arguments);
}
}
}
/*
Snippet of code you can insert into each nv.models.* to give you the ability to
do things like:
@ -142,6 +226,7 @@ To enable in the chart:
chart.options = nv.utils.optionsFunc.bind(chart);
*/
nv.utils.optionsFunc = function(args) {
nv.deprecated('nv.utils.optionsFunc');
if (args) {
d3.map(args).forEach((function(key,value) {
if (typeof this[key] === "function") {
@ -150,4 +235,5 @@ nv.utils.optionsFunc = function(args) {
}).bind(this));
}
return this;
};
};

Loading…
Cancel
Save