diff --git a/src/components/colorbar/draw.js b/src/components/colorbar/draw.js index d817dd84635..9aa7f5be855 100644 --- a/src/components/colorbar/draw.js +++ b/src/components/colorbar/draw.js @@ -65,20 +65,23 @@ module.exports = function draw(gd, id) { return; } var zrange = d3.extent(((typeof opts.fillcolor === 'function') ? - opts.fillcolor : opts.line.color).domain()), - linelevels = [], - filllevels = [], - l, - linecolormap = typeof opts.line.color === 'function' ? - opts.line.color : function() { return opts.line.color; }, - fillcolormap = typeof opts.fillcolor === 'function' ? - opts.fillcolor : function() { return opts.fillcolor; }; + opts.fillcolor : opts.line.color).domain()); + var linelevels = []; + var filllevels = []; + var linecolormap = typeof opts.line.color === 'function' ? + opts.line.color : function() { return opts.line.color; }; + var fillcolormap = typeof opts.fillcolor === 'function' ? + opts.fillcolor : function() { return opts.fillcolor; }; + var l; + var i; var l0 = opts.levels.end + opts.levels.size / 100, ls = opts.levels.size, zr0 = (1.001 * zrange[0] - 0.001 * zrange[1]), zr1 = (1.001 * zrange[1] - 0.001 * zrange[0]); - for(l = opts.levels.start; (l - l0) * ls < 0; l += ls) { + for(i = 0; i < 1e5; i++) { + l = opts.levels.start + i * ls; + if(ls > 0 ? (l >= l0) : (l <= l0)) break; if(l > zr0 && l < zr1) linelevels.push(l); } @@ -86,7 +89,9 @@ module.exports = function draw(gd, id) { if(opts.filllevels) { l0 = opts.filllevels.end + opts.filllevels.size / 100; ls = opts.filllevels.size; - for(l = opts.filllevels.start; (l - l0) * ls < 0; l += ls) { + for(i = 0; i < 1e5; i++) { + l = opts.filllevels.start + i * ls; + if(ls > 0 ? (l >= l0) : (l <= l0)) break; if(l > zrange[0] && l < zrange[1]) filllevels.push(l); } } diff --git a/test/image/baselines/21.png b/test/image/baselines/21.png index 098370c0c47..e17d6d60c2c 100644 Binary files a/test/image/baselines/21.png and b/test/image/baselines/21.png differ diff --git a/test/image/baselines/contour_heatmap_coloring.png b/test/image/baselines/contour_heatmap_coloring.png index 48141cc3b60..dd408d1120a 100644 Binary files a/test/image/baselines/contour_heatmap_coloring.png and b/test/image/baselines/contour_heatmap_coloring.png differ diff --git a/test/image/baselines/geo_first.png b/test/image/baselines/geo_first.png index 7f4be6e3486..3929fca1fad 100644 Binary files a/test/image/baselines/geo_first.png and b/test/image/baselines/geo_first.png differ diff --git a/test/image/baselines/ternary_array_styles.png b/test/image/baselines/ternary_array_styles.png index 521df1ebcd9..ab11c0f648d 100644 Binary files a/test/image/baselines/ternary_array_styles.png and b/test/image/baselines/ternary_array_styles.png differ diff --git a/test/image/baselines/zsmooth_methods.png b/test/image/baselines/zsmooth_methods.png index e310acde0f9..baf8c7e3da8 100644 Binary files a/test/image/baselines/zsmooth_methods.png and b/test/image/baselines/zsmooth_methods.png differ diff --git a/test/jasmine/tests/colorbar_test.js b/test/jasmine/tests/colorbar_test.js index 0b6591f0e5c..0c722327cb1 100644 --- a/test/jasmine/tests/colorbar_test.js +++ b/test/jasmine/tests/colorbar_test.js @@ -1,4 +1,7 @@ +var Plotly = require('@lib/index'); var Colorbar = require('@src/components/colorbar'); +var createGraphDiv = require('../assets/create_graph_div'); +var destroyGraphDiv = require('../assets/destroy_graph_div'); describe('Test colorbar:', function() { @@ -29,4 +32,28 @@ describe('Test colorbar:', function() { expect(hasColorbar(trace.marker.line)).toBe(false); }); }); + + describe('floating point limits', function() { + var gd; + + beforeEach(function() { + gd = createGraphDiv(); + }); + + afterEach(destroyGraphDiv); + + it('does not lock up on tiny fractional ranges', function(done) { + var z = [ + [9607345622458638.0, 9607345622458652.0, 9607345622458652.0, 9607345622458646.0, 9607345622458652.0, 9607345622458650.0, 9607345622458650.0, 9607345622458646.0], + [9607345622458654.0, 9607345622458640.0, 9607345622458650.0, 9607345622458652.0, 9607345622458652.0, 9607345622458654.0, 9607345622458650.0, 9607345622458652.0], + [9607345622458654.0, 9607345622458652.0, 9607345622458638.0, 9607345622458652.0, 9607345622458650.0, 9607345622458652.0, 9607345622458654.0, 9607345622458650.0], + [9607345622458650.0, 9607345622458652.0, 9607345622458650.0, 9607345622458632.0, 9607345622458644.0, 9607345622458646.0, 9607345622458646.0, 9607345622458650.0], + [9607345622458654.0, 9607345622458652.0, 9607345622458650.0, 9607345622458650.0, 9607345622458638.0, 9607345622458654.0, 9607345622458654.0, 9607345622458650.0], + [9607345622458650.0, 9607345622458654.0, 9607345622458650.0, 9607345622458646.0, 9607345622458652.0, 9607345622458638.0, 9607345622458646.0, 9607345622458652.0], + [9607345622458654.0, 9607345622458652.0, 9607345622458654.0, 9607345622458650.0, 9607345622458654.0, 9607345622458652.0, 9607345622458640.0, 9607345622458654.0], + [9607345622458650.0, 9607345622458652.0, 9607345622458650.0, 9607345622458652.0, 9607345622458650.0, 9607345622458654.0, 9607345622458654.0, 9607345622458638.0] + ]; + Plotly.newPlot(gd, [{type: 'heatmap', z: z}]).then(done); + }); + }); });