|
|
|
@ -3311,35 +3311,46 @@ nv.models.lineChart = function() {
|
|
|
|
|
// Public Variables with Default Settings
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
var margin = {top: 30, right: 20, bottom: 50, left: 60},
|
|
|
|
|
color = nv.utils.defaultColor(),
|
|
|
|
|
width = null,
|
|
|
|
|
height = null,
|
|
|
|
|
showLegend = true,
|
|
|
|
|
tooltips = true,
|
|
|
|
|
tooltip = function(key, x, y, e, graph) {
|
|
|
|
|
var lines = nv.models.line()
|
|
|
|
|
, xAxis = nv.models.axis()
|
|
|
|
|
, yAxis = nv.models.axis()
|
|
|
|
|
, legend = nv.models.legend()
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
var margin = {top: 30, right: 20, bottom: 50, left: 60}
|
|
|
|
|
, color = nv.utils.defaultColor()
|
|
|
|
|
, width = null
|
|
|
|
|
, height = null
|
|
|
|
|
, showLegend = true
|
|
|
|
|
, tooltips = true
|
|
|
|
|
, tooltip = function(key, x, y, e, graph) {
|
|
|
|
|
return '<h3>' + key + '</h3>' +
|
|
|
|
|
'<p>' + y + ' at ' + x + '</p>'
|
|
|
|
|
},
|
|
|
|
|
x,//can be accessed via chart.lines.[x/y]Scale()
|
|
|
|
|
y,
|
|
|
|
|
noData = "No Data Available."
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
, x
|
|
|
|
|
, y
|
|
|
|
|
, noData = "No Data Available."
|
|
|
|
|
, dispatch = d3.dispatch('tooltipShow', 'tooltipHide')
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
xAxis
|
|
|
|
|
.orient('bottom')
|
|
|
|
|
.tickPadding(5)
|
|
|
|
|
;
|
|
|
|
|
yAxis
|
|
|
|
|
.orient('left')
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
// Private Variables
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
var lines = nv.models.line(),
|
|
|
|
|
xAxis = nv.models.axis().orient('bottom').tickPadding(5),
|
|
|
|
|
yAxis = nv.models.axis().orient('left'),
|
|
|
|
|
legend = nv.models.legend().height(30),
|
|
|
|
|
dispatch = d3.dispatch('tooltipShow', 'tooltipHide');
|
|
|
|
|
|
|
|
|
|
var showTooltip = function(e, offsetElement) {
|
|
|
|
|
|
|
|
|
|
// New addition to calculate position if SVG is scaled with viewBox, may move
|
|
|
|
|
// New addition to calculate position if SVG is scaled with viewBox, may move TODO: consider implementing everywhere else
|
|
|
|
|
if (offsetElement) {
|
|
|
|
|
var svg = d3.select(offsetElement).select('svg');
|
|
|
|
|
var viewBox = svg.attr('viewBox');
|
|
|
|
@ -3360,6 +3371,8 @@ nv.models.lineChart = function() {
|
|
|
|
|
nv.tooltip.show([left, top], content, null, null, offsetElement);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function chart(selection) {
|
|
|
|
|
selection.each(function(data) {
|
|
|
|
@ -3373,7 +3386,7 @@ nv.models.lineChart = function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Display No Data message if there's nothing to show.
|
|
|
|
|
// Display noData message if there's nothing to show.
|
|
|
|
|
|
|
|
|
|
if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) {
|
|
|
|
|
container.append('text')
|
|
|
|
@ -3391,23 +3404,34 @@ nv.models.lineChart = function() {
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Setup Scales
|
|
|
|
|
|
|
|
|
|
x = lines.xScale();
|
|
|
|
|
y = lines.yScale();
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Setup containers and skeleton of chart
|
|
|
|
|
|
|
|
|
|
var wrap = container.selectAll('g.nv-wrap.nv-lineChart').data([data]);
|
|
|
|
|
var gEnter = wrap.enter().append('g').attr('class', 'nvd3 nv-wrap nv-lineChart').append('g');
|
|
|
|
|
var g = wrap.select('g');
|
|
|
|
|
|
|
|
|
|
gEnter.append('g').attr('class', 'nv-x nv-axis');
|
|
|
|
|
gEnter.append('g').attr('class', 'nv-y nv-axis');
|
|
|
|
|
gEnter.append('g').attr('class', 'nv-linesWrap');
|
|
|
|
|
gEnter.append('g').attr('class', 'nv-legendWrap');
|
|
|
|
|
|
|
|
|
|
wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
|
|
|
|
|
|
|
|
|
var g = wrap.select('g');
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Legend
|
|
|
|
|
|
|
|
|
|
if (showLegend) {
|
|
|
|
|
legend.width(availableWidth);
|
|
|
|
@ -3422,10 +3446,15 @@ nv.models.lineChart = function() {
|
|
|
|
|
- margin.top - margin.bottom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g.select('.nv-legendWrap')
|
|
|
|
|
wrap.select('.nv-legendWrap')
|
|
|
|
|
.attr('transform', 'translate(0,' + (-margin.top) +')')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Main Chart Component(s)
|
|
|
|
|
|
|
|
|
|
lines
|
|
|
|
|
.width(availableWidth)
|
|
|
|
@ -3435,17 +3464,17 @@ nv.models.lineChart = function() {
|
|
|
|
|
}).filter(function(d,i) { return !data[i].disabled }));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var linesWrap = g.select('.nv-linesWrap')
|
|
|
|
|
.datum(data.filter(function(d) { return !d.disabled }))
|
|
|
|
|
|
|
|
|
|
d3.transition(linesWrap).call(lines);
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Setup Axes
|
|
|
|
|
|
|
|
|
|
xAxis
|
|
|
|
|
.scale(x)
|
|
|
|
|
.ticks( availableWidth / 100 )
|
|
|
|
@ -3465,6 +3494,7 @@ nv.models.lineChart = function() {
|
|
|
|
|
d3.transition(g.select('.nv-y.nv-axis'))
|
|
|
|
|
.call(yAxis);
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
@ -3501,12 +3531,13 @@ nv.models.lineChart = function() {
|
|
|
|
|
if (tooltips) showTooltip(e, that.parentNode);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: decide if this is a good idea, and if it should be in all models
|
|
|
|
|
chart.update = function() { chart(selection) };
|
|
|
|
|
chart.container = this; // I need a reference to the container in order to have outside code check if the chart is visible or not
|
|
|
|
|
chart.update = function() { chart(selection) };
|
|
|
|
|
chart.container = this;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return chart;
|
|
|
|
|
}
|
|
|
|
@ -3529,19 +3560,22 @@ nv.models.lineChart = function() {
|
|
|
|
|
if (tooltips) nv.tooltip.cleanup();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
// Global getters and setters
|
|
|
|
|
// Expose Public Variables
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// expose chart's sub-components
|
|
|
|
|
chart.dispatch = dispatch;
|
|
|
|
|
chart.lines = lines;
|
|
|
|
|
chart.legend = legend;
|
|
|
|
|
chart.xAxis = xAxis;
|
|
|
|
|
chart.yAxis = yAxis;
|
|
|
|
|
|
|
|
|
|
d3.rebind(chart, lines, 'defined', 'isArea', 'x', 'y', 'size', 'xScale', 'yScale', 'xDomain', 'yDomain', 'forceX', 'forceY', 'interactive', 'clipEdge', 'clipVoronoi', 'id', 'interpolate');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chart.margin = function(_) {
|
|
|
|
|
if (!arguments.length) return margin;
|
|
|
|
|
margin = _;
|
|
|
|
@ -3591,6 +3625,8 @@ nv.models.lineChart = function() {
|
|
|
|
|
return chart;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return chart;
|
|
|
|
|
}
|
|
|
|
@ -7658,7 +7694,9 @@ nv.models.scatterChart = function() {
|
|
|
|
|
, controls = nv.models.legend()
|
|
|
|
|
, distX = nv.models.distribution()
|
|
|
|
|
, distY = nv.models.distribution()
|
|
|
|
|
, margin = {top: 30, right: 20, bottom: 50, left: 60}
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
var margin = {top: 30, right: 20, bottom: 50, left: 60}
|
|
|
|
|
, width = null
|
|
|
|
|
, height = null
|
|
|
|
|
, color = nv.utils.defaultColor()
|
|
|
|
@ -7679,7 +7717,6 @@ nv.models.scatterChart = function() {
|
|
|
|
|
, noData = "No Data Available."
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
// Setup sub-components
|
|
|
|
|
scatter
|
|
|
|
|
.xScale(x)
|
|
|
|
|
.yScale(y)
|
|
|
|
@ -7747,7 +7784,7 @@ nv.models.scatterChart = function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Show noData message if there is no data
|
|
|
|
|
// Display noData message if there's nothing to show.
|
|
|
|
|
|
|
|
|
|
if (!data || !data.length || !data.filter(function(d) { return d.values.length }).length) {
|
|
|
|
|
container.append('text')
|
|
|
|
@ -7840,7 +7877,6 @@ nv.models.scatterChart = function() {
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
// Main Chart Component(s)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scatter
|
|
|
|
|
.width(availableWidth)
|
|
|
|
|
.height(availableHeight)
|
|
|
|
@ -8061,6 +8097,7 @@ nv.models.scatterChart = function() {
|
|
|
|
|
|
|
|
|
|
// expose chart's sub-components
|
|
|
|
|
chart.dispatch = dispatch;
|
|
|
|
|
chart.scatter = scatter;
|
|
|
|
|
chart.legend = legend;
|
|
|
|
|
chart.controls = controls;
|
|
|
|
|
chart.xAxis = xAxis;
|
|
|
|
|