From b8e86d3faf764361ba6134c132de2d70e4162f4d Mon Sep 17 00:00:00 2001 From: Diego Rabatone Oliveira Date: Thu, 20 Sep 2012 01:28:14 -0300 Subject: [PATCH 1/5] Tooltips on bullet.js and bulletChart.js: positioning tooltips related to each bulletChart, not to the 'div#chart'. Resolves Issue #202 --- src/models/bullet.js | 10 ++++++---- src/models/bulletChart.js | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/models/bullet.js b/src/models/bullet.js index a51e3a1..d20af8e 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), @@ -87,7 +89,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 +119,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 +150,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..c4cf3ea 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,7 +107,7 @@ 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 )+ ')'); //------------------------------------------------------------ From b66af7ff5ff842d6bcb10db19b791bd2cd4d44c0 Mon Sep 17 00:00:00 2001 From: Diego Rabatone Oliveira Date: Thu, 20 Sep 2012 01:36:22 -0300 Subject: [PATCH 2/5] Adding nice() method to domains on bullet and bulletChart --- src/models/bullet.js | 4 ++-- src/models/bulletChart.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/models/bullet.js b/src/models/bullet.js index d20af8e..748d9b2 100644 --- a/src/models/bullet.js +++ b/src/models/bullet.js @@ -44,12 +44,12 @@ nv.models.bullet = function() { // Compute the new x-scale. 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, Math.max(rangez[0], markerz[0], measurez[0])]).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. var x0 = this.__chart__ || d3.scale.linear() - .domain([0, Infinity]) + .domain([0, Infinity]).nice() .range(x1.range()); // Stash the new scale. diff --git a/src/models/bulletChart.js b/src/models/bulletChart.js index c4cf3ea..3c2b453 100644 --- a/src/models/bulletChart.js +++ b/src/models/bulletChart.js @@ -114,12 +114,12 @@ nv.models.bulletChart = function() { // Compute the new x-scale. 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, Math.max(rangez[0], markerz[0], measurez[0])]).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. var x0 = this.__chart__ || d3.scale.linear() - .domain([0, Infinity]) + .domain([0, Infinity]).nice() .range(x1.range()); // Stash the new scale. From ed80c7ad8841497e327bf87afad57e261734d120 Mon Sep 17 00:00:00 2001 From: Diego Rabatone Oliveira Date: Thu, 20 Sep 2012 01:39:45 -0300 Subject: [PATCH 3/5] Allowing no Markers on bullet and bulletChart --- src/models/bullet.js | 3 ++- src/models/bulletChart.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/models/bullet.js b/src/models/bullet.js index 748d9b2..daea6ce 100644 --- a/src/models/bullet.js +++ b/src/models/bullet.js @@ -43,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])]).nice() // 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. diff --git a/src/models/bulletChart.js b/src/models/bulletChart.js index 3c2b453..177e516 100644 --- a/src/models/bulletChart.js +++ b/src/models/bulletChart.js @@ -113,8 +113,9 @@ nv.models.bulletChart = function() { // 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])]).nice() // 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. From 959f597c06ae47423c94328fd5e0c5f5ee72918b Mon Sep 17 00:00:00 2001 From: Diego Rabatone Date: Fri, 21 Sep 2012 10:37:50 -0300 Subject: [PATCH 4/5] parentesis mistake corrected on bullet.js --- src/models/bullet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/bullet.js b/src/models/bullet.js index daea6ce..5ddf60b 100644 --- a/src/models/bullet.js +++ b/src/models/bullet.js @@ -45,7 +45,7 @@ nv.models.bullet = function() { // 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, MaxX])]).nice() // 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. From d4811353a6d5550183b440719e23ae1f759424a0 Mon Sep 17 00:00:00 2001 From: Diego Rabatone Date: Fri, 21 Sep 2012 12:08:26 -0300 Subject: [PATCH 5/5] removing nice() from domain with INFINITY parameter, it wouldn't matter --- src/models/bullet.js | 2 +- src/models/bulletChart.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models/bullet.js b/src/models/bullet.js index 5ddf60b..00e0298 100644 --- a/src/models/bullet.js +++ b/src/models/bullet.js @@ -50,7 +50,7 @@ nv.models.bullet = function() { // Retrieve the old x-scale, if this is an update. var x0 = this.__chart__ || d3.scale.linear() - .domain([0, Infinity]).nice() + .domain([0, Infinity]) .range(x1.range()); // Stash the new scale. diff --git a/src/models/bulletChart.js b/src/models/bulletChart.js index 177e516..a2a0f07 100644 --- a/src/models/bulletChart.js +++ b/src/models/bulletChart.js @@ -120,7 +120,7 @@ nv.models.bulletChart = function() { // Retrieve the old x-scale, if this is an update. var x0 = this.__chart__ || d3.scale.linear() - .domain([0, Infinity]).nice() + .domain([0, Infinity]) .range(x1.range()); // Stash the new scale.