Merge branch 'development' into d3v3_Upgrade

master
Dingo 11 years ago
commit dd94b599fe

@ -17,6 +17,7 @@ JS_FILES = \
src/models/lineChart.js \ src/models/lineChart.js \
src/models/linePlusBarChart.js \ src/models/linePlusBarChart.js \
src/models/lineWithFocusChart.js \ src/models/lineWithFocusChart.js \
src/models/linePlusBarWithFocusChart.js \
src/models/multiBar.js \ src/models/multiBar.js \
src/models/multiBarChart.js \ src/models/multiBarChart.js \
src/models/multiBarHorizontal.js \ src/models/multiBarHorizontal.js \

@ -106,7 +106,7 @@ nv.addGraph(function() {
key: 'stream3' key: 'stream3'
} }
]); ]);
nv.log(data);
d3.select('#chart svg') d3.select('#chart svg')
.datum(data) .datum(data)
.transition().duration(500) .transition().duration(500)

@ -88,6 +88,7 @@ nv.addGraph(function() {
.color(d3.scale.category10().range()); .color(d3.scale.category10().range());
chart.xAxis.tickFormat(function(d) { chart.xAxis.tickFormat(function(d) {
var dx = testdata[0].values[d] && testdata[0].values[d].x || 0; var dx = testdata[0].values[d] && testdata[0].values[d].x || 0;
if (dx > 0) { if (dx > 0) {
return d3.time.format('%x')(new Date(dx)) return d3.time.format('%x')(new Date(dx))
@ -115,7 +116,7 @@ nv.addGraph(function() {
chart.bars.forceY([0]); chart.bars.forceY([0]);
chart.bars2.forceY([0]); chart.bars2.forceY([0]);
//chart.lines.forceY([0]); //chart.lines.forceY([0]);
nv.log(testdata);
d3.select('#chart1 svg') d3.select('#chart1 svg')
.datum(testdata) .datum(testdata)
.transition().duration(500).call(chart); .transition().duration(500).call(chart);

@ -69,6 +69,9 @@ nv.addGraph(function() {
chart = nv.models.multiBarChart() chart = nv.models.multiBarChart()
.barColor(d3.scale.category20().range()); .barColor(d3.scale.category20().range());
chart.multibar
.hideable(true);
chart.xAxis chart.xAxis
.showMaxMin(true) .showMaxMin(true)
.tickFormat(d3.format(',f')); .tickFormat(d3.format(',f'));

1049
nv.d3.js

File diff suppressed because it is too large Load Diff

5
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -28,6 +28,7 @@ nv.models.cumulativeLineChart = function() {
, y //can be accessed via chart.yScale() , y //can be accessed via chart.yScale()
, id = lines.id() , id = lines.id()
, state = { index: 0, rescaleY: rescaleY } , state = { index: 0, rescaleY: rescaleY }
, defaultState = null
, noData = 'No Data Available.' , noData = 'No Data Available.'
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
; ;
@ -108,6 +109,17 @@ nv.models.cumulativeLineChart = function() {
//set state.disabled //set state.disabled
state.disabled = data.map(function(d) { return !!d.disabled }); state.disabled = data.map(function(d) { return !!d.disabled });
if (!defaultState) {
var key;
defaultState = {};
for (key in state) {
if (state[key] instanceof Array)
defaultState[key] = state[key].slice(0);
else
defaultState[key] = state[key];
}
}
var indexDrag = d3.behavior.drag() var indexDrag = d3.behavior.drag()
.on('dragstart', dragStart) .on('dragstart', dragStart)
.on('drag', dragMove) .on('drag', dragMove)
@ -567,6 +579,12 @@ nv.models.cumulativeLineChart = function() {
return chart; return chart;
}; };
chart.defaultState = function(_) {
if (!arguments.length) return defaultState;
defaultState = _;
return chart;
};
chart.noData = function(_) { chart.noData = function(_) {
if (!arguments.length) return noData; if (!arguments.length) return noData;
noData = _; noData = _;

@ -25,6 +25,7 @@ nv.models.lineChart = function() {
, x , x
, y , y
, state = {} , state = {}
, defaultState = null
, noData = 'No Data Available.' , noData = 'No Data Available.'
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
; ;
@ -87,6 +88,16 @@ nv.models.lineChart = function() {
//set state.disabled //set state.disabled
state.disabled = data.map(function(d) { return !!d.disabled }); state.disabled = data.map(function(d) { return !!d.disabled });
if (!defaultState) {
var key;
defaultState = {};
for (key in state) {
if (state[key] instanceof Array)
defaultState[key] = state[key].slice(0);
else
defaultState[key] = state[key];
}
}
//------------------------------------------------------------ //------------------------------------------------------------
// Display noData message if there's nothing to show. // Display noData message if there's nothing to show.
@ -349,6 +360,12 @@ nv.models.lineChart = function() {
return chart; return chart;
}; };
chart.defaultState = function(_) {
if (!arguments.length) return defaultState;
defaultState = _;
return chart;
};
chart.noData = function(_) { chart.noData = function(_) {
if (!arguments.length) return noData; if (!arguments.length) return noData;
noData = _; noData = _;

@ -28,6 +28,8 @@ nv.models.linePlusBarChart = function() {
, x , x
, y1 , y1
, y2 , y2
, state = {}
, defaultState = null
, noData = "No Data Available." , noData = "No Data Available."
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
; ;
@ -58,17 +60,16 @@ nv.models.linePlusBarChart = function() {
// Private Variables // Private Variables
//------------------------------------------------------------ //------------------------------------------------------------
var state = {}, var showTooltip = function(e, offsetElement) {
showTooltip = function(e, offsetElement) { var left = e.pos[0] + ( offsetElement.offsetLeft || 0 ),
var left = e.pos[0] + ( offsetElement.offsetLeft || 0 ), top = e.pos[1] + ( offsetElement.offsetTop || 0),
top = e.pos[1] + ( offsetElement.offsetTop || 0), x = xAxis.tickFormat()(lines.x()(e.point, e.pointIndex)),
x = xAxis.tickFormat()(lines.x()(e.point, e.pointIndex)), y = (e.series.bar ? y1Axis : y2Axis).tickFormat()(lines.y()(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);
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);
} }
; ;
//------------------------------------------------------------ //------------------------------------------------------------
@ -90,6 +91,16 @@ nv.models.linePlusBarChart = function() {
//set state.disabled //set state.disabled
state.disabled = data.map(function(d) { return !!d.disabled }); state.disabled = data.map(function(d) { return !!d.disabled });
if (!defaultState) {
var key;
defaultState = {};
for (key in state) {
if (state[key] instanceof Array)
defaultState[key] = state[key].slice(0);
else
defaultState[key] = state[key];
}
}
//------------------------------------------------------------ //------------------------------------------------------------
// Display No Data message if there's nothing to show. // Display No Data message if there's nothing to show.
@ -200,7 +211,7 @@ nv.models.linePlusBarChart = function() {
.datum(dataBars.length ? dataBars : [{values:[]}]) .datum(dataBars.length ? dataBars : [{values:[]}])
var linesWrap = g.select('.nv-linesWrap') var linesWrap = g.select('.nv-linesWrap')
.datum(!dataLines[0].disabled ? dataLines : [{values:[]}] ); .datum(dataLines[0] && !dataLines[0].disabled ? dataLines : [{values:[]}] );
//.datum(!dataLines[0].disabled ? dataLines : [{values:dataLines[0].values.map(function(d) { return [d[0], null] }) }] ); //.datum(!dataLines[0].disabled ? dataLines : [{values:dataLines[0].values.map(function(d) { return [d[0], null] }) }] );
d3.transition(barsWrap).call(bars); d3.transition(barsWrap).call(bars);
@ -412,6 +423,12 @@ nv.models.linePlusBarChart = function() {
return chart; return chart;
}; };
chart.defaultState = function(_) {
if (!arguments.length) return defaultState;
defaultState = _;
return chart;
};
chart.noData = function(_) { chart.noData = function(_) {
if (!arguments.length) return noData; if (!arguments.length) return noData;
noData = _; noData = _;

@ -424,6 +424,7 @@ nv.models.linePlusBarWithFocusChart = function() {
return d.color || color(d, i); return d.color || color(d, i);
}).filter(function(d,i) { return !data[i].disabled && data[i].bar })); }).filter(function(d,i) { return !data[i].disabled && data[i].bar }));
lines lines
.width(availableWidth) .width(availableWidth)
.height(availableHeight1) .height(availableHeight1)
@ -650,6 +651,13 @@ nv.models.linePlusBarWithFocusChart = function() {
return chart; return chart;
}; };
chart.brushExtent = function(_) {
if (!arguments.length) return brushExtent;
brushExtent = _;
return chart;
};
//============================================================ //============================================================

@ -17,6 +17,7 @@ nv.models.multiBar = function() {
, clipEdge = true , clipEdge = true
, stacked = false , stacked = false
, color = nv.utils.defaultColor() , color = nv.utils.defaultColor()
, hideable = false
, barColor = null // adding the ability to set the color for each rather than the whole group , 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 , disabled // used in conjunction with barColor to communicate from multiBarHorizontalChart what series are disabled
, delay = 1200 , delay = 1200
@ -44,12 +45,22 @@ nv.models.multiBar = function() {
availableHeight = height - margin.top - margin.bottom, availableHeight = height - margin.top - margin.bottom,
container = d3.select(this); container = d3.select(this);
if(hideable && data.length) hideable = [{
values: data[0].values.map(function(d) {
return {
x: d.x,
y: 0,
series: d.series,
size: 0.01
};}
)}];
if (stacked) if (stacked)
data = d3.layout.stack() data = d3.layout.stack()
.offset('zero') .offset('zero')
.values(function(d){ return d.values }) .values(function(d){ return d.values })
.y(getY) .y(getY)
(data); (!data.length && hideable ? hideable : data);
//add series index to each data point for reference //add series index to each data point for reference
@ -170,7 +181,7 @@ nv.models.multiBar = function() {
var bars = groups.selectAll('rect.nv-bar') var bars = groups.selectAll('rect.nv-bar')
.data(function(d) { return d.values }); .data(function(d) { return (hideable && !data.length) ? hideable.values : d.values });
bars.exit().remove(); bars.exit().remove();
@ -403,6 +414,12 @@ nv.models.multiBar = function() {
return chart; return chart;
}; };
chart.hideable = function(_) {
if (!arguments.length) return hideable;
hideable = _;
return chart;
};
chart.delay = function(_) { chart.delay = function(_) {
if (!arguments.length) return delay; if (!arguments.length) return delay;
delay = _; delay = _;

@ -28,6 +28,7 @@ nv.models.multiBarChart = function() {
, x //can be accessed via chart.xScale() , x //can be accessed via chart.xScale()
, y //can be accessed via chart.yScale() , y //can be accessed via chart.yScale()
, state = { stacked: false } , state = { stacked: false }
, defaultState = null
, noData = "No Data Available." , noData = "No Data Available."
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, controlWidth = function() { return showControls ? 180 : 0 } , controlWidth = function() { return showControls ? 180 : 0 }
@ -84,7 +85,16 @@ nv.models.multiBarChart = function() {
//set state.disabled //set state.disabled
state.disabled = data.map(function(d) { return !!d.disabled }); state.disabled = data.map(function(d) { return !!d.disabled });
if (!defaultState) {
var key;
defaultState = {};
for (key in state) {
if (state[key] instanceof Array)
defaultState[key] = state[key].slice(0);
else
defaultState[key] = state[key];
}
}
//------------------------------------------------------------ //------------------------------------------------------------
// Display noData message if there's nothing to show. // Display noData message if there's nothing to show.
@ -436,6 +446,12 @@ nv.models.multiBarChart = function() {
return chart; return chart;
}; };
chart.defaultState = function(_) {
if (!arguments.length) return defaultState;
defaultState = _;
return chart;
};
chart.noData = function(_) { chart.noData = function(_) {
if (!arguments.length) return noData; if (!arguments.length) return noData;
noData = _; noData = _;

@ -27,6 +27,7 @@ nv.models.multiBarHorizontalChart = function() {
, x //can be accessed via chart.xScale() , x //can be accessed via chart.xScale()
, y //can be accessed via chart.yScale() , y //can be accessed via chart.yScale()
, state = { stacked: stacked } , state = { stacked: stacked }
, defaultState = null
, noData = 'No Data Available.' , noData = 'No Data Available.'
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, controlWidth = function() { return showControls ? 180 : 0 } , controlWidth = function() { return showControls ? 180 : 0 }
@ -83,6 +84,16 @@ nv.models.multiBarHorizontalChart = function() {
//set state.disabled //set state.disabled
state.disabled = data.map(function(d) { return !!d.disabled }); state.disabled = data.map(function(d) { return !!d.disabled });
if (!defaultState) {
var key;
defaultState = {};
for (key in state) {
if (state[key] instanceof Array)
defaultState[key] = state[key].slice(0);
else
defaultState[key] = state[key];
}
}
//------------------------------------------------------------ //------------------------------------------------------------
// Display No Data message if there's nothing to show. // Display No Data message if there's nothing to show.
@ -406,6 +417,12 @@ nv.models.multiBarHorizontalChart = function() {
return chart; return chart;
}; };
chart.defaultState = function(_) {
if (!arguments.length) return defaultState;
defaultState = _;
return chart;
};
chart.noData = function(_) { chart.noData = function(_) {
if (!arguments.length) return noData; if (!arguments.length) return noData;
noData = _; noData = _;

@ -19,6 +19,7 @@ nv.models.pieChart = function() {
'<p>' + y + '</p>' '<p>' + y + '</p>'
} }
, state = {} , state = {}
, defaultState = null
, noData = "No Data Available." , noData = "No Data Available."
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
; ;
@ -59,6 +60,17 @@ nv.models.pieChart = function() {
//set state.disabled //set state.disabled
state.disabled = data[0].map(function(d) { return !!d.disabled }); state.disabled = data[0].map(function(d) { return !!d.disabled });
if (!defaultState) {
var key;
defaultState = {};
for (key in state) {
if (state[key] instanceof Array)
defaultState[key] = state[key].slice(0);
else
defaultState[key] = state[key];
}
}
//------------------------------------------------------------ //------------------------------------------------------------
// Display No Data message if there's nothing to show. // Display No Data message if there's nothing to show.
@ -271,6 +283,12 @@ nv.models.pieChart = function() {
return chart; return chart;
}; };
chart.defaultState = function(_) {
if (!arguments.length) return defaultState;
defaultState = _;
return chart;
};
chart.noData = function(_) { chart.noData = function(_) {
if (!arguments.length) return noData; if (!arguments.length) return noData;
noData = _; noData = _;

@ -33,6 +33,8 @@ nv.models.scatterChart = function() {
, tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' } , tooltipY = function(key, x, y) { return '<strong>' + y + '</strong>' }
//, tooltip = function(key, x, y) { return '<h3>' + key + '</h3>' } //, tooltip = function(key, x, y) { return '<h3>' + key + '</h3>' }
, tooltip = null , tooltip = null
, state = {}
, defaultState = null
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, noData = "No Data Available." , noData = "No Data Available."
; ;
@ -63,8 +65,7 @@ nv.models.scatterChart = function() {
// Private Variables // Private Variables
//------------------------------------------------------------ //------------------------------------------------------------
var state = {}, var x0, y0;
x0, y0;
var showTooltip = function(e, offsetElement) { var showTooltip = function(e, offsetElement) {
//TODO: make tooltip style an option between single or dual on axes (maybe on all charts with axes?) //TODO: make tooltip style an option between single or dual on axes (maybe on all charts with axes?)
@ -109,6 +110,16 @@ nv.models.scatterChart = function() {
//set state.disabled //set state.disabled
state.disabled = data.map(function(d) { return !!d.disabled }); state.disabled = data.map(function(d) { return !!d.disabled });
if (!defaultState) {
var key;
defaultState = {};
for (key in state) {
if (state[key] instanceof Array)
defaultState[key] = state[key].slice(0);
else
defaultState[key] = state[key];
}
}
//------------------------------------------------------------ //------------------------------------------------------------
// Display noData message if there's nothing to show. // Display noData message if there's nothing to show.
@ -149,10 +160,10 @@ nv.models.scatterChart = function() {
var wrap = container.selectAll('g.nv-wrap.nv-scatterChart').data([data]); var wrap = container.selectAll('g.nv-wrap.nv-scatterChart').data([data]);
var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-scatterChart nv-chart-' + scatter.id()); var wrapEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-scatterChart nv-chart-' + scatter.id());
var gEnter = wrapEnter.append('g'); var gEnter = wrapEnter.append('g');
var g = wrap.select('g') var g = wrap.select('g');
// background for pointer events // background for pointer events
gEnter.append('rect').attr('class', 'nvd3 nv-background') gEnter.append('rect').attr('class', 'nvd3 nv-background');
gEnter.append('g').attr('class', 'nv-x nv-axis'); gEnter.append('g').attr('class', 'nv-x nv-axis');
gEnter.append('g').attr('class', 'nv-y nv-axis'); gEnter.append('g').attr('class', 'nv-y nv-axis');
@ -565,6 +576,12 @@ nv.models.scatterChart = function() {
return chart; return chart;
}; };
chart.defaultState = function(_) {
if (!arguments.length) return defaultState;
defaultState = _;
return chart;
};
chart.noData = function(_) { chart.noData = function(_) {
if (!arguments.length) return noData; if (!arguments.length) return noData;
noData = _; noData = _;

@ -32,6 +32,8 @@ nv.models.scatterPlusLineChart = function() {
, tooltip = function(key, x, y, date) { return '<h3>' + key + '</h3>' , tooltip = function(key, x, y, date) { return '<h3>' + key + '</h3>'
+ '<p>' + date + '</p>' } + '<p>' + date + '</p>' }
//, tooltip = null //, tooltip = null
, state = {}
, defaultState = null
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, noData = "No Data Available." , noData = "No Data Available."
; ;
@ -62,8 +64,7 @@ nv.models.scatterPlusLineChart = function() {
// Private Variables // Private Variables
//------------------------------------------------------------ //------------------------------------------------------------
var state = {}, var x0, y0;
x0, y0;
var showTooltip = function(e, offsetElement) { var showTooltip = function(e, offsetElement) {
//TODO: make tooltip style an option between single or dual on axes (maybe on all charts with axes?) //TODO: make tooltip style an option between single or dual on axes (maybe on all charts with axes?)
@ -108,6 +109,16 @@ nv.models.scatterPlusLineChart = function() {
//set state.disabled //set state.disabled
state.disabled = data.map(function(d) { return !!d.disabled }); state.disabled = data.map(function(d) { return !!d.disabled });
if (!defaultState) {
var key;
defaultState = {};
for (key in state) {
if (state[key] instanceof Array)
defaultState[key] = state[key].slice(0);
else
defaultState[key] = state[key];
}
}
//------------------------------------------------------------ //------------------------------------------------------------
// Display noData message if there's nothing to show. // Display noData message if there's nothing to show.
@ -567,6 +578,12 @@ nv.models.scatterPlusLineChart = function() {
return chart; return chart;
}; };
chart.defaultState = function(_) {
if (!arguments.length) return defaultState;
defaultState = _;
return chart;
};
chart.noData = function(_) { chart.noData = function(_) {
if (!arguments.length) return noData; if (!arguments.length) return noData;
noData = _; noData = _;

@ -27,6 +27,7 @@ nv.models.stackedAreaChart = function() {
, y //can be accessed via chart.yScale() , y //can be accessed via chart.yScale()
, yAxisTickFormat = d3.format(',.2f') , yAxisTickFormat = d3.format(',.2f')
, state = { style: stacked.style() } , state = { style: stacked.style() }
, defaultState = null
, noData = 'No Data Available.' , noData = 'No Data Available.'
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState') , dispatch = d3.dispatch('tooltipShow', 'tooltipHide', 'stateChange', 'changeState')
, controlWidth = 250 , controlWidth = 250
@ -82,6 +83,16 @@ nv.models.stackedAreaChart = function() {
//set state.disabled //set state.disabled
state.disabled = data.map(function(d) { return !!d.disabled }); state.disabled = data.map(function(d) { return !!d.disabled });
if (!defaultState) {
var key;
defaultState = {};
for (key in state) {
if (state[key] instanceof Array)
defaultState[key] = state[key].slice(0);
else
defaultState[key] = state[key];
}
}
//------------------------------------------------------------ //------------------------------------------------------------
// Display No Data message if there's nothing to show. // Display No Data message if there's nothing to show.
@ -441,6 +452,12 @@ nv.models.stackedAreaChart = function() {
return chart; return chart;
}; };
chart.defaultState = function(_) {
if (!arguments.length) return defaultState;
defaultState = _;
return chart;
};
chart.noData = function(_) { chart.noData = function(_) {
if (!arguments.length) return noData; if (!arguments.length) return noData;
noData = _; noData = _;
@ -448,6 +465,7 @@ nv.models.stackedAreaChart = function() {
}; };
yAxis.setTickFormat = yAxis.tickFormat; yAxis.setTickFormat = yAxis.tickFormat;
yAxis.tickFormat = function(_) { yAxis.tickFormat = function(_) {
if (!arguments.length) return yAxisTickFormat; if (!arguments.length) return yAxisTickFormat;
yAxisTickFormat = _; yAxisTickFormat = _;

Loading…
Cancel
Save