Skip to content

Commit 10c3ae0

Browse files
authored
Merge pull request #1906 from plotly/colorbar-loops
Colorbar loops
2 parents c6b4cdd + 7decb53 commit 10c3ae0

File tree

7 files changed

+42
-10
lines changed

7 files changed

+42
-10
lines changed

src/components/colorbar/draw.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,33 @@ module.exports = function draw(gd, id) {
6565
return;
6666
}
6767
var zrange = d3.extent(((typeof opts.fillcolor === 'function') ?
68-
opts.fillcolor : opts.line.color).domain()),
69-
linelevels = [],
70-
filllevels = [],
71-
l,
72-
linecolormap = typeof opts.line.color === 'function' ?
73-
opts.line.color : function() { return opts.line.color; },
74-
fillcolormap = typeof opts.fillcolor === 'function' ?
75-
opts.fillcolor : function() { return opts.fillcolor; };
68+
opts.fillcolor : opts.line.color).domain());
69+
var linelevels = [];
70+
var filllevels = [];
71+
var linecolormap = typeof opts.line.color === 'function' ?
72+
opts.line.color : function() { return opts.line.color; };
73+
var fillcolormap = typeof opts.fillcolor === 'function' ?
74+
opts.fillcolor : function() { return opts.fillcolor; };
75+
var l;
76+
var i;
7677

7778
var l0 = opts.levels.end + opts.levels.size / 100,
7879
ls = opts.levels.size,
7980
zr0 = (1.001 * zrange[0] - 0.001 * zrange[1]),
8081
zr1 = (1.001 * zrange[1] - 0.001 * zrange[0]);
81-
for(l = opts.levels.start; (l - l0) * ls < 0; l += ls) {
82+
for(i = 0; i < 1e5; i++) {
83+
l = opts.levels.start + i * ls;
84+
if(ls > 0 ? (l >= l0) : (l <= l0)) break;
8285
if(l > zr0 && l < zr1) linelevels.push(l);
8386
}
8487

8588
if(typeof opts.fillcolor === 'function') {
8689
if(opts.filllevels) {
8790
l0 = opts.filllevels.end + opts.filllevels.size / 100;
8891
ls = opts.filllevels.size;
89-
for(l = opts.filllevels.start; (l - l0) * ls < 0; l += ls) {
92+
for(i = 0; i < 1e5; i++) {
93+
l = opts.filllevels.start + i * ls;
94+
if(ls > 0 ? (l >= l0) : (l <= l0)) break;
9095
if(l > zrange[0] && l < zrange[1]) filllevels.push(l);
9196
}
9297
}

test/image/baselines/21.png

-3 Bytes
Loading
-9 Bytes
Loading

test/image/baselines/geo_first.png

8 Bytes
Loading
5 Bytes
Loading
-1 Bytes
Loading

test/jasmine/tests/colorbar_test.js

+27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
var Plotly = require('@lib/index');
12
var Colorbar = require('@src/components/colorbar');
3+
var createGraphDiv = require('../assets/create_graph_div');
4+
var destroyGraphDiv = require('../assets/destroy_graph_div');
25

36

47
describe('Test colorbar:', function() {
@@ -29,4 +32,28 @@ describe('Test colorbar:', function() {
2932
expect(hasColorbar(trace.marker.line)).toBe(false);
3033
});
3134
});
35+
36+
describe('floating point limits', function() {
37+
var gd;
38+
39+
beforeEach(function() {
40+
gd = createGraphDiv();
41+
});
42+
43+
afterEach(destroyGraphDiv);
44+
45+
it('does not lock up on tiny fractional ranges', function(done) {
46+
var z = [
47+
[9607345622458638.0, 9607345622458652.0, 9607345622458652.0, 9607345622458646.0, 9607345622458652.0, 9607345622458650.0, 9607345622458650.0, 9607345622458646.0],
48+
[9607345622458654.0, 9607345622458640.0, 9607345622458650.0, 9607345622458652.0, 9607345622458652.0, 9607345622458654.0, 9607345622458650.0, 9607345622458652.0],
49+
[9607345622458654.0, 9607345622458652.0, 9607345622458638.0, 9607345622458652.0, 9607345622458650.0, 9607345622458652.0, 9607345622458654.0, 9607345622458650.0],
50+
[9607345622458650.0, 9607345622458652.0, 9607345622458650.0, 9607345622458632.0, 9607345622458644.0, 9607345622458646.0, 9607345622458646.0, 9607345622458650.0],
51+
[9607345622458654.0, 9607345622458652.0, 9607345622458650.0, 9607345622458650.0, 9607345622458638.0, 9607345622458654.0, 9607345622458654.0, 9607345622458650.0],
52+
[9607345622458650.0, 9607345622458654.0, 9607345622458650.0, 9607345622458646.0, 9607345622458652.0, 9607345622458638.0, 9607345622458646.0, 9607345622458652.0],
53+
[9607345622458654.0, 9607345622458652.0, 9607345622458654.0, 9607345622458650.0, 9607345622458654.0, 9607345622458652.0, 9607345622458640.0, 9607345622458654.0],
54+
[9607345622458650.0, 9607345622458652.0, 9607345622458650.0, 9607345622458652.0, 9607345622458650.0, 9607345622458654.0, 9607345622458654.0, 9607345622458638.0]
55+
];
56+
Plotly.newPlot(gd, [{type: 'heatmap', z: z}]).then(done);
57+
});
58+
});
3259
});

0 commit comments

Comments
 (0)