Skip to content

Commit 0fe718d

Browse files
committed
Fix colorbar to work using alpha colors but still display opaque colors
1 parent e645b1c commit 0fe718d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/components/colorbar/draw.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
var d3 = require('d3');
13+
var tc = require('tinycolor2');
1314

1415
var Plotly = require('../../plotly');
1516
var Plots = require('../../plots/plots');
@@ -356,13 +357,22 @@ module.exports = function draw(gd, id) {
356357
if(i!==filllevels.length-1) {
357358
z[1] += (z[1]>z[0]) ? 1 : -1;
358359
}
360+
361+
362+
// Tinycolor can't handle exponents and
363+
// at this scale, removing it makes no difference.
364+
var colorString = fillcolormap(d).replace('e-', ''),
365+
opaqueColor = tc(colorString).toHexString();
366+
367+
// Colorbar cannot currently support opacities so we
368+
// use an opaque fill even when alpha channels present
359369
d3.select(this).attr({
360370
x: xLeft,
361371
width: Math.max(thickPx,2),
362372
y: d3.min(z),
363-
height: Math.max(d3.max(z)-d3.min(z),2)
364-
})
365-
.style('fill',fillcolormap(d));
373+
height: Math.max(d3.max(z)-d3.min(z),2),
374+
fill: opaqueColor
375+
});
366376
});
367377

368378
var lines = container.select('.cblines')

0 commit comments

Comments
 (0)