Skip to content

Contours not rendered correctly with semi-transparent colorscale #1356

Closed
@rreusser

Description

@rreusser

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.

screen shot 2017-02-06 at 16 45 17

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:

  1. Remove any opacity and draw the overlapping contours, as we do now
  2. Draw the overlapping contours once more, rendering the alpha as black-white
  3. Use (2) as a mask of (1) (as opposed to a clip-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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions