diff --git a/src/models/discreteBarChart.js b/src/models/discreteBarChart.js index e0c5c82..cd7a676 100644 --- a/src/models/discreteBarChart.js +++ b/src/models/discreteBarChart.js @@ -47,10 +47,11 @@ nv.models.discreteBarChart = function() { function chart(selection) { selection.each(function(data) { + var container = d3.select(this); - var availableWidth = (width || parseInt(d3.select(this).style('width')) || 960) + var availableWidth = (width || parseInt(container.style('width')) || 960) - margin.left - margin.right, - availableHeight = (height || parseInt(d3.select(this).style('height')) || 400) + availableHeight = (height || parseInt(container.style('height')) || 400) - margin.top - margin.bottom; @@ -59,7 +60,7 @@ nv.models.discreteBarChart = function() { .height(availableHeight); - var wrap = d3.select(this).selectAll('g.wrap.discreteBarWithAxes').data([data]); + var wrap = container.selectAll('g.wrap.discreteBarWithAxes').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 discreteBarWithAxes').append('g'); gEnter.append('g').attr('class', 'x axis'); @@ -112,7 +113,7 @@ nv.models.discreteBarChart = function() { e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top]; dispatch.tooltipShow(e); }); - if (tooltips) dispatch.on('tooltipShow', function(e) { showTooltip(e, this) } ); // TODO: maybe merge with above? + if (tooltips) dispatch.on('tooltipShow', function(e) { showTooltip(e, container[0][0]) } ); // TODO: maybe merge with above? discretebar.dispatch.on('elementMouseout.tooltip', function(e) { dispatch.tooltipHide(e); diff --git a/src/models/lineChart.js b/src/models/lineChart.js index 2efc8bd..2ad5423 100644 --- a/src/models/lineChart.js +++ b/src/models/lineChart.js @@ -36,10 +36,11 @@ nv.models.lineChart = function() { function chart(selection) { selection.each(function(data) { + var container = d3.select(this); - var availableWidth = (width || parseInt(d3.select(this).style('width')) || 960) + var availableWidth = (width || parseInt(container.style('width')) || 960) - margin.left - margin.right, - availableHeight = (height || parseInt(d3.select(this).style('height')) || 400) + availableHeight = (height || parseInt(container.style('height')) || 400) - margin.top - margin.bottom; @@ -51,7 +52,7 @@ nv.models.lineChart = function() { }).filter(function(d,i) { return !data[i].disabled })); - var wrap = d3.select(this).selectAll('g.wrap.lineWithLegend').data([data]); + var wrap = container.selectAll('g.wrap.lineWithLegend').data([data]); var gEnter = wrap.enter().append('g').attr('class', 'wrap nvd3 lineWithLegend').append('g'); gEnter.append('g').attr('class', 'x axis'); @@ -138,7 +139,7 @@ nv.models.lineChart = function() { e.pos = [e.pos[0] + margin.left, e.pos[1] + margin.top]; dispatch.tooltipShow(e); }); - dispatch.on('tooltipShow', function(e) { showTooltip(e, this) } ); // TODO: maybe merge with above? + dispatch.on('tooltipShow', function(e) { showTooltip(e, container[0][0]) } ); // TODO: maybe merge with above? lines.dispatch.on('elementMouseout.tooltip', function(e) { dispatch.tooltipHide(e);