diff --git a/src/models/bullet.js b/src/models/bullet.js index a51e3a1..00e0298 100644 --- a/src/models/bullet.js +++ b/src/models/bullet.js @@ -29,7 +29,9 @@ nv.models.bullet = function() { selection.each(function(d, i) { var availableWidth = width - margin.left - margin.right, availableHeight = height - margin.top - margin.bottom, - container = d3.select(this); + container = d3.select(this), + mainGroup = this.parentNode.parentNode.getAttribute('transform') + heightFromTop = parseInt(mainGroup.replace(/.*,(\d+)\)/,"$1")) //TODO: There should be a smarter way to get this value var rangez = ranges.call(this, d, i).slice().sort(d3.descending), markerz = markers.call(this, d, i).slice().sort(d3.descending), @@ -41,8 +43,9 @@ nv.models.bullet = function() { // Setup Scales // Compute the new x-scale. + var MaxX = Math.max(rangez[0] ? rangez[0]:0 , markerz[0] ? markerz[0] : 0 , measurez[0] ? measurez[0] : 0) var x1 = d3.scale.linear() - .domain([0, Math.max(rangez[0], markerz[0], measurez[0])]) // TODO: need to allow forceX and forceY, and xDomain, yDomain + .domain([0, MaxX]).nice() // TODO: need to allow forceX and forceY, and xDomain, yDomain .range(reverse ? [availableWidth, 0] : [0, availableWidth]); // Retrieve the old x-scale, if this is an update. @@ -87,7 +90,7 @@ nv.models.bullet = function() { dispatch.elementMouseover({ value: d, label: (i <= 0) ? 'Maximum' : (i > 1) ? 'Minimum' : 'Mean', //TODO: make these labels a variable - pos: [x1(d), availableHeight/2] + pos: [x1(d), heightFromTop] }) }) .on('mouseout', function(d,i) { @@ -117,7 +120,7 @@ nv.models.bullet = function() { dispatch.elementMouseover({ value: d, label: 'Current', //TODO: make these labels a variable - pos: [x1(d), availableHeight/2] + pos: [x1(d), heightFromTop] }) }) .on('mouseout', function(d) { @@ -148,7 +151,7 @@ nv.models.bullet = function() { dispatch.elementMouseover({ value: d, label: 'Previous', - pos: [x1(d), availableHeight/2] + pos: [x1(d), heightFromTop] }) }) .on('mouseout', function(d,i) { diff --git a/src/models/bulletChart.js b/src/models/bulletChart.js index 493463c..a2a0f07 100644 --- a/src/models/bulletChart.js +++ b/src/models/bulletChart.js @@ -36,15 +36,15 @@ nv.models.bulletChart = function() { // Private Variables //------------------------------------------------------------ - var showTooltip = function(e, offsetElement) { - var offsetElement = document.getElementById("chart"), + var showTooltip = function(e, parentElement) { + var offsetElement = parentElement.parentNode.parentNode, left = e.pos[0] + offsetElement.offsetLeft + margin.left, top = e.pos[1] + offsetElement.offsetTop + margin.top; var content = '

' + e.label + '

' + '

' + e.value + '

'; - nv.tooltip.show([left, top], content, e.value < 0 ? 'e' : 'w', null, offsetElement); + nv.tooltip.show([left, top], content, e.value < 0 ? 'e' : 'w', null, offsetElement.parentNode); }; //============================================================ @@ -107,14 +107,15 @@ nv.models.bulletChart = function() { gEnter.append('g').attr('class', 'nv-bulletWrap'); gEnter.append('g').attr('class', 'nv-titles'); - wrap.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); + wrap.attr('transform', 'translate(' + margin.left + ',' + ( margin.top + i*height )+ ')'); //------------------------------------------------------------ // Compute the new x-scale. + var MaxX = Math.max(rangez[0] ? rangez[0]:0 , markerz[0] ? markerz[0] : 0 , measurez[0] ? measurez[0] : 0) var x1 = d3.scale.linear() - .domain([0, Math.max(rangez[0], markerz[0], measurez[0])]) // TODO: need to allow forceX and forceY, and xDomain, yDomain + .domain([0, MaxX]).nice() // TODO: need to allow forceX and forceY, and xDomain, yDomain .range(reverse ? [availableWidth, 0] : [0, availableWidth]); // Retrieve the old x-scale, if this is an update.