Description
Expected behavior: contours with < 100% opacity render correctly
Observed behavior: This json:
{
type: 'contour',
z: [[1, 2], [3, 4]],
colorscale: [
[0, 'rgba(0, 0, 0, 0.5)'],
[1, 'rgba(0, 0, 0, 0.5)']
]
}
produces the following plot.
The colorscale has no variation, so I'd expect a flat region with 50% black. See: http://codepen.io/rsreusser/pen/PWBjZG
Analysis: The reason is that contours are drawn on top of one another vs. the region between successive levels. That is, the colors are assumed fully-opaque so that it makes no difference.
For carpet plots inequality ranges, I had to do some magic on the extracted paths to flip paths and render the area between contours levels. That would maybe work here. The downside of this approach for regular contour plots is that the SVG paths will not rasterize and antialias nicely without a small gap between them. Of course if there's any line between them, it makes no difference.
A potential workaround:
- Remove any opacity and draw the overlapping contours, as we do now
- Draw the overlapping contours once more, rendering the alpha as black-white
- Use (2) as a
mask
of (1) (as opposed to aclip-path
)
Since masks are opacity-aware, I believe this would produce the expected result without unpleasant artifacts. The downside is that the SVG has to internally rasterize and composite multiple layers, which seems to be significantly slower. It would need some testing to ensure this is viable.
ping @alexcjohnson for any details I may have missed based on previous discussion