Merge remote-tracking branch 'diraol/bulletChart'

This commit is contained in:
Bob Monteverde 2012-09-21 17:10:57 -04:00
commit bd5ca282ec
2 changed files with 14 additions and 10 deletions

View File

@ -29,7 +29,9 @@ nv.models.bullet = function() {
selection.each(function(d, i) { selection.each(function(d, i) {
var availableWidth = width - margin.left - margin.right, var availableWidth = width - margin.left - margin.right,
availableHeight = height - margin.top - margin.bottom, 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), var rangez = ranges.call(this, d, i).slice().sort(d3.descending),
markerz = markers.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 // Setup Scales
// Compute the new x-scale. // 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() 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]); .range(reverse ? [availableWidth, 0] : [0, availableWidth]);
// Retrieve the old x-scale, if this is an update. // Retrieve the old x-scale, if this is an update.
@ -87,7 +90,7 @@ nv.models.bullet = function() {
dispatch.elementMouseover({ dispatch.elementMouseover({
value: d, value: d,
label: (i <= 0) ? 'Maximum' : (i > 1) ? 'Minimum' : 'Mean', //TODO: make these labels a variable 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) { .on('mouseout', function(d,i) {
@ -117,7 +120,7 @@ nv.models.bullet = function() {
dispatch.elementMouseover({ dispatch.elementMouseover({
value: d, value: d,
label: 'Current', //TODO: make these labels a variable label: 'Current', //TODO: make these labels a variable
pos: [x1(d), availableHeight/2] pos: [x1(d), heightFromTop]
}) })
}) })
.on('mouseout', function(d) { .on('mouseout', function(d) {
@ -148,7 +151,7 @@ nv.models.bullet = function() {
dispatch.elementMouseover({ dispatch.elementMouseover({
value: d, value: d,
label: 'Previous', label: 'Previous',
pos: [x1(d), availableHeight/2] pos: [x1(d), heightFromTop]
}) })
}) })
.on('mouseout', function(d,i) { .on('mouseout', function(d,i) {

View File

@ -36,15 +36,15 @@ nv.models.bulletChart = function() {
// Private Variables // Private Variables
//------------------------------------------------------------ //------------------------------------------------------------
var showTooltip = function(e, offsetElement) { var showTooltip = function(e, parentElement) {
var offsetElement = document.getElementById("chart"), var offsetElement = parentElement.parentNode.parentNode,
left = e.pos[0] + offsetElement.offsetLeft + margin.left, left = e.pos[0] + offsetElement.offsetLeft + margin.left,
top = e.pos[1] + offsetElement.offsetTop + margin.top; top = e.pos[1] + offsetElement.offsetTop + margin.top;
var content = '<h3>' + e.label + '</h3>' + var content = '<h3>' + e.label + '</h3>' +
'<p>' + e.value + '</p>'; '<p>' + e.value + '</p>';
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-bulletWrap');
gEnter.append('g').attr('class', 'nv-titles'); 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. // 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() 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]); .range(reverse ? [availableWidth, 0] : [0, availableWidth]);
// Retrieve the old x-scale, if this is an update. // Retrieve the old x-scale, if this is an update.