Fixed bug in nv.interactiveBisect, for situations where the xAccessor is

function(d,i) { return i}
master
Robin Hu 11 years ago
parent fa89918faf
commit 65edf27199

@ -246,17 +246,17 @@ Has the following known issues:
*/
nv.interactiveBisect = function (values, searchVal, xAccessor) {
if (! values instanceof Array) return null;
if (typeof xAccessor !== 'function') xAccessor = function(d) { return d.x;}
if (typeof xAccessor !== 'function') xAccessor = function(d,i) { return d.x;}
var bisect = d3.bisector(xAccessor).left;
var index = d3.max([0, bisect(values,searchVal) - 1]);
var currentValue = xAccessor(values[index]);
var currentValue = xAccessor(values[index], index);
if (typeof currentValue === 'undefined') currentValue = index;
if (currentValue === searchVal) return index; //found exact match
var nextIndex = d3.min([index+1, values.length - 1]);
var nextValue = xAccessor(values[nextIndex]);
var nextValue = xAccessor(values[nextIndex], index);
if (typeof nextValue === 'undefined') nextValue = nextIndex;
if (Math.abs(nextValue - searchVal) >= Math.abs(currentValue - searchVal))
@ -2381,10 +2381,10 @@ nv.models.cumulativeLineChart = function() {
var point = series.values[pointIndex];
if (typeof point === 'undefined') return;
if (typeof singlePoint === 'undefined') singlePoint = point;
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point));
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex));
allData.push({
key: series.key,
value: chart.y()(point, e.pointIndex),
value: chart.y()(point, pointIndex),
color: color(series,series.seriesIndex)
});
});
@ -5258,10 +5258,10 @@ nv.models.lineChart = function() {
var point = series.values[pointIndex];
if (typeof point === 'undefined') return;
if (typeof singlePoint === 'undefined') singlePoint = point;
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point));
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex));
allData.push({
key: series.key,
value: chart.y()(point, e.pointIndex),
value: chart.y()(point, pointIndex),
color: color(series,series.seriesIndex)
});
});
@ -13612,10 +13612,10 @@ nv.models.stackedAreaChart = function() {
var point = series.values[pointIndex];
if (typeof point === 'undefined') return;
if (typeof singlePoint === 'undefined') singlePoint = point;
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point));
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex));
allData.push({
key: series.key,
value: chart.y()(point, e.pointIndex),
value: chart.y()(point, pointIndex),
color: color(series,series.seriesIndex)
});
});

12
nv.d3.min.js vendored

File diff suppressed because one or more lines are too long

@ -127,17 +127,17 @@ Has the following known issues:
*/
nv.interactiveBisect = function (values, searchVal, xAccessor) {
if (! values instanceof Array) return null;
if (typeof xAccessor !== 'function') xAccessor = function(d) { return d.x;}
if (typeof xAccessor !== 'function') xAccessor = function(d,i) { return d.x;}
var bisect = d3.bisector(xAccessor).left;
var index = d3.max([0, bisect(values,searchVal) - 1]);
var currentValue = xAccessor(values[index]);
var currentValue = xAccessor(values[index], index);
if (typeof currentValue === 'undefined') currentValue = index;
if (currentValue === searchVal) return index; //found exact match
var nextIndex = d3.min([index+1, values.length - 1]);
var nextValue = xAccessor(values[nextIndex]);
var nextValue = xAccessor(values[nextIndex], nextIndex);
if (typeof nextValue === 'undefined') nextValue = nextIndex;
if (Math.abs(nextValue - searchVal) >= Math.abs(currentValue - searchVal))

@ -518,10 +518,10 @@ nv.models.cumulativeLineChart = function() {
var point = series.values[pointIndex];
if (typeof point === 'undefined') return;
if (typeof singlePoint === 'undefined') singlePoint = point;
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point));
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex));
allData.push({
key: series.key,
value: chart.y()(point, e.pointIndex),
value: chart.y()(point, pointIndex),
color: color(series,series.seriesIndex)
});
});

@ -268,10 +268,10 @@ nv.models.lineChart = function() {
var point = series.values[pointIndex];
if (typeof point === 'undefined') return;
if (typeof singlePoint === 'undefined') singlePoint = point;
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point));
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex));
allData.push({
key: series.key,
value: chart.y()(point, e.pointIndex),
value: chart.y()(point, pointIndex),
color: color(series,series.seriesIndex)
});
});

@ -354,10 +354,10 @@ nv.models.stackedAreaChart = function() {
var point = series.values[pointIndex];
if (typeof point === 'undefined') return;
if (typeof singlePoint === 'undefined') singlePoint = point;
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point));
if (typeof pointXLocation === 'undefined') pointXLocation = chart.xScale()(chart.x()(point,pointIndex));
allData.push({
key: series.key,
value: chart.y()(point, e.pointIndex),
value: chart.y()(point, pointIndex),
color: color(series,series.seriesIndex)
});
});

Loading…
Cancel
Save