State management in almost all chart models

master-patched
Bob Monteverde 12 years ago
parent 6213a74e3b
commit 22b850e001

@ -3947,8 +3947,9 @@ nv.models.lineChart = function() {
}
, x
, y
, state = {}
, noData = 'No Data Available.'
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
;
xAxis
@ -4139,6 +4140,9 @@ nv.models.lineChart = function() {
});
}
state.disabled = data.map(function(d) { return !!d.disabled });
dispatch.stateChange(state);
selection.transition().call(chart);
});
@ -4158,6 +4162,20 @@ nv.models.lineChart = function() {
if (tooltips) showTooltip(e, that.parentNode);
});
dispatch.on('changeState', function(e) {
if (typeof e.disabled !== 'undefined') {
data.forEach(function(series,i) {
series.disabled = e.disabled[i];
});
state.disabled = e.disabled;
}
selection.call(chart);
});
//============================================================
});
@ -4287,7 +4305,7 @@ nv.models.linePlusBarChart = function() {
, y1
, y2
, noData = "No Data Available."
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
;
bars
@ -4316,15 +4334,17 @@ nv.models.linePlusBarChart = function() {
// Private Variables
//------------------------------------------------------------
var showTooltip = function(e, offsetElement) {
var left = e.pos[0] + ( offsetElement.offsetLeft || 0 ),
top = e.pos[1] + ( offsetElement.offsetTop || 0),
x = xAxis.tickFormat()(lines.x()(e.point, e.pointIndex)),
y = (e.series.bar ? y1Axis : y2Axis).tickFormat()(lines.y()(e.point, e.pointIndex)),
content = tooltip(e.series.key, x, y, e, chart);
var state = {},
showTooltip = function(e, offsetElement) {
var left = e.pos[0] + ( offsetElement.offsetLeft || 0 ),
top = e.pos[1] + ( offsetElement.offsetTop || 0),
x = xAxis.tickFormat()(lines.x()(e.point, e.pointIndex)),
y = (e.series.bar ? y1Axis : y2Axis).tickFormat()(lines.y()(e.point, e.pointIndex)),
content = tooltip(e.series.key, x, y, e, chart);
nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's', null, offsetElement);
};
nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's', null, offsetElement);
}
;
//------------------------------------------------------------
@ -4518,6 +4538,9 @@ nv.models.linePlusBarChart = function() {
});
}
state.disabled = data.map(function(d) { return !!d.disabled });
dispatch.stateChange(state);
selection.transition().call(chart);
});
@ -4525,6 +4548,21 @@ nv.models.linePlusBarChart = function() {
if (tooltips) showTooltip(e, that.parentNode);
});
// Update chart from a state object passed to event handler
dispatch.on('changeState', function(e) {
if (typeof e.disabled !== 'undefined') {
data.forEach(function(series,i) {
series.disabled = e.disabled[i];
});
state.disabled = e.disabled;
}
selection.call(chart);
});
//============================================================
@ -5611,8 +5649,9 @@ nv.models.multiBarChart = function() {
}
, x //can be accessed via chart.xScale()
, y //can be accessed via chart.yScale()
, state = { stacked: false }
, noData = "No Data Available."
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
;
multibar
@ -5840,6 +5879,9 @@ nv.models.multiBarChart = function() {
});
}
state.disabled = data.map(function(d) { return !!d.disabled });
dispatch.stateChange(state);
selection.transition().call(chart);
});
@ -5860,6 +5902,9 @@ nv.models.multiBarChart = function() {
break;
}
state.stacked = multibar.stacked();
dispatch.stateChange(state);
selection.transition().call(chart);
});
@ -5867,6 +5912,25 @@ nv.models.multiBarChart = function() {
if (tooltips) showTooltip(e, that.parentNode)
});
// Update chart from a state object passed to event handler
dispatch.on('changeState', function(e) {
if (typeof e.disabled !== 'undefined') {
data.forEach(function(series,i) {
series.disabled = e.disabled[i];
});
state.disabled = e.disabled;
}
if (typeof e.stacked !== 'undefined') {
multibar.stacked(e.stacked);
state.stacked = e.stacked;
}
selection.call(chart);
});
//============================================================
@ -6387,8 +6451,9 @@ nv.models.multiBarHorizontalChart = function() {
}
, x //can be accessed via chart.xScale()
, y //can be accessed via chart.yScale()
, state = { stacked: stacked }
, noData = 'No Data Available.'
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
;
multibar
@ -6600,6 +6665,9 @@ nv.models.multiBarHorizontalChart = function() {
});
}
state.disabled = data.map(function(d) { return !!d.disabled });
dispatch.stateChange(state);
selection.transition().call(chart);
});
@ -6620,6 +6688,9 @@ nv.models.multiBarHorizontalChart = function() {
break;
}
state.stacked = multibar.stacked();
dispatch.stateChange(state);
selection.transition().call(chart);
});
@ -6627,6 +6698,24 @@ nv.models.multiBarHorizontalChart = function() {
if (tooltips) showTooltip(e, that.parentNode);
});
// Update chart from a state object passed to event handler
dispatch.on('changeState', function(e) {
if (typeof e.disabled !== 'undefined') {
data.forEach(function(series,i) {
series.disabled = e.disabled[i];
});
state.disabled = e.disabled;
}
if (typeof e.stacked !== 'undefined') {
multibar.stacked(e.stacked);
state.stacked = e.stacked;
}
selection.call(chart);
});
//============================================================
@ -7883,8 +7972,9 @@ nv.models.pieChart = function() {
return '<h3>' + key + '</h3>' +
'<p>' + y + '</p>'
}
, state = {}
, noData = "No Data Available."
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
;
//============================================================
@ -8016,6 +8106,9 @@ nv.models.pieChart = function() {
});
}
state.disabled = data[0].map(function(d) { return !!d.disabled });
dispatch.stateChange(state);
selection.transition().call(chart)
});
@ -8023,6 +8116,20 @@ nv.models.pieChart = function() {
dispatch.tooltipHide(e);
});
// Update chart from a state object passed to event handler
dispatch.on('changeState', function(e) {
if (typeof e.disabled !== 'undefined') {
data[0].forEach(function(series,i) {
series.disabled = e.disabled[i];
});
state.disabled = e.disabled;
}
selection.call(chart);
});
//============================================================
@ -8772,7 +8879,7 @@ nv.models.scatterChart = function() {
, tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' }
//, tooltip = function(key, x, y) { return '<h3>' + key + '</h3>' }
, tooltip = null
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, noData = "No Data Available."
;
@ -8802,7 +8909,8 @@ nv.models.scatterChart = function() {
// Private Variables
//------------------------------------------------------------
var x0, y0;
var state = {},
x0, y0;
var showTooltip = function(e, offsetElement) {
//TODO: make tooltip style an option between single or dual on axes (maybe on all charts with axes?)
@ -9103,6 +9211,9 @@ nv.models.scatterChart = function() {
});
}
state.disabled = data.map(function(d) { return !!d.disabled });
dispatch.stateChange(state);
chart(selection);
});
@ -9132,6 +9243,20 @@ nv.models.scatterChart = function() {
if (tooltips) showTooltip(e, that.parentNode);
});
// Update chart from a state object passed to event handler
dispatch.on('changeState', function(e) {
if (typeof e.disabled !== 'undefined') {
data.forEach(function(series,i) {
series.disabled = e.disabled[i];
});
state.disabled = e.disabled;
}
selection.call(chart);
});
//============================================================
@ -9322,7 +9447,7 @@ nv.models.scatterPlusLineChart = function() {
, tooltip = function(key, x, y, date) { return '<h3>' + key + '</h3>'
+ '<p>' + date + '</p>' }
//, tooltip = null
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, noData = "No Data Available."
;
@ -9352,7 +9477,8 @@ nv.models.scatterPlusLineChart = function() {
// Private Variables
//------------------------------------------------------------
var x0, y0;
var state = {},
x0, y0;
var showTooltip = function(e, offsetElement) {
//TODO: make tooltip style an option between single or dual on axes (maybe on all charts with axes?)
@ -9668,6 +9794,9 @@ nv.models.scatterPlusLineChart = function() {
});
}
state.disabled = data.map(function(d) { return !!d.disabled });
dispatch.stateChange(state);
chart(selection);
});
@ -9697,6 +9826,20 @@ nv.models.scatterPlusLineChart = function() {
if (tooltips) showTooltip(e, that.parentNode);
});
// Update chart from a state object passed to event handler
dispatch.on('changeState', function(e) {
if (typeof e.disabled !== 'undefined') {
data.forEach(function(series,i) {
series.disabled = e.disabled[i];
});
state.disabled = e.disabled;
}
selection.call(chart);
});
//============================================================
@ -10675,8 +10818,9 @@ nv.models.stackedAreaChart = function() {
, x //can be accessed via chart.xScale()
, y //can be accessed via chart.yScale()
, yAxisTickFormat = d3.format(',.2f')
, state = { style: stacked.style() }
, noData = 'No Data Available.'
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
;
xAxis
@ -10909,6 +11053,9 @@ nv.models.stackedAreaChart = function() {
});
}
state.disabled = data.map(function(d) { return !!d.disabled });
dispatch.stateChange(state);
//selection.transition().call(chart);
chart(selection);
});
@ -10934,6 +11081,9 @@ nv.models.stackedAreaChart = function() {
break;
}
state.style = stacked.style();
dispatch.stateChange(state);
//selection.transition().call(chart);
chart(selection);
});
@ -10942,6 +11092,24 @@ nv.models.stackedAreaChart = function() {
if (tooltips) showTooltip(e, that.parentNode);
});
// Update chart from a state object passed to event handler
dispatch.on('changeState', function(e) {
if (typeof e.disabled !== 'undefined') {
data.forEach(function(series,i) {
series.disabled = e.disabled[i];
});
state.disabled = e.disabled;
}
if (typeof e.style !== 'undefined') {
stacked.style(e.style);
}
selection.call(chart);
});
});

10
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save