Browse Source

fixed binarySearchGeneric from infinite loop (added protection), fixed issue where all points have the same Y value. #222

v3_develop
Alex de Mulder 10 years ago
parent
commit
d7e5aad410
3 changed files with 9392 additions and 9358 deletions
  1. +9371
    -9354
      dist/vis.js
  2. +5
    -0
      lib/timeline/DataStep.js
  3. +16
    -4
      lib/util.js

+ 9371
- 9354
dist/vis.js
File diff suppressed because it is too large
View File


+ 5
- 0
lib/timeline/DataStep.js View File

@ -58,6 +58,11 @@ DataStep.prototype.setRange = function(start, end, minimumStep, containerHeight,
this._start = start;
this._end = end;
if (start == end) {
this._start = start - 0.75;
this._end = end + 1;
}
if (this.autoScale) {
this.setMinimumStep(minimumStep, containerHeight, forcedStepSize);
}

+ 16
- 4
lib/util.js View File

@ -1140,6 +1140,8 @@ exports.mergeOptions = function (mergeTarget, options, option) {
exports.binarySearch = function(orderedItems, range, field, field2) {
var array = orderedItems;
var maxIterations = 10000;
var iteration = 0;
var found = false;
var low = 0;
var high = array.length;
@ -1162,7 +1164,7 @@ exports.binarySearch = function(orderedItems, range, field, field2) {
else {
high -= 1;
while (found == false) {
while (found == false && iteration < maxIterations) {
value = field2 === undefined ? array[guess][field] : array[guess][field][field2];
if (array[guess].isVisible(range)) {
@ -1185,6 +1187,10 @@ exports.binarySearch = function(orderedItems, range, field, field2) {
guess = Math.floor(0.5*(high+low));
}
}
iteration++;
}
if (iteration >= maxIterations) {
console.log("BinarySearch too many iterations. Aborting.");
}
}
return guess;
@ -1208,6 +1214,8 @@ exports.binarySearch = function(orderedItems, range, field, field2) {
* @private
*/
exports.binarySearchGeneric = function(orderedItems, target, field, sidePreference) {
var maxIterations = 10000;
var iteration = 0;
var array = orderedItems;
var found = false;
var low = 0;
@ -1230,7 +1238,7 @@ exports.binarySearchGeneric = function(orderedItems, target, field, sidePreferen
}
else {
high -= 1;
while (found == false) {
while (found == false && iteration < maxIterations) {
prevValue = array[Math.max(0,guess - 1)][field];
value = array[guess][field];
nextValue = array[Math.min(array.length-1,guess + 1)][field];
@ -1252,10 +1260,10 @@ exports.binarySearchGeneric = function(orderedItems, target, field, sidePreferen
}
else {
if (value < target) { // it is too small --> increase low
low = Math.floor(0.5*(high+low));
newLow = Math.floor(0.5*(high+low));
}
else { // it is too big --> decrease high
high = Math.floor(0.5*(high+low));
newHigh = Math.floor(0.5*(high+low));
}
newGuess = Math.floor(0.5*(high+low));
// not in list;
@ -1268,6 +1276,10 @@ exports.binarySearchGeneric = function(orderedItems, target, field, sidePreferen
guess = Math.floor(0.5*(high+low));
}
}
iteration++;
}
if (iteration >= maxIterations) {
console.log("BinarySearch too many iterations. Aborting.");
}
}
return guess;

Loading…
Cancel
Save