Skip to content

Support wide-gamut colour spaces #1140

Description

@benjaminleonard

uPlot creates its drawing context with no attributes:

const ctx = self.ctx = can.getContext("2d")

which means the canvas is always sRGB. Colours that exceed the sRGB gamut get clamped when drawn to the canvas, so on wide-gamut (P3) displays a uPlot chart looks visibly washed out next to the exact same colour rendered by CSS/SVG elsewhere on the page.

// example attrs
{ ctxAttrs: { colorSpace: 'display-p3' } 

const ctx = self.ctx = can.getContext("2d", opts.ctxAttrs);

I think browsers that don't support colorSpace ignore it, so no feature detection is needed in uPlot itself. desynchronized and alpha (in the context attrs) are likely not useful, so an alternative is passing colorSpace as a bespoke option.

Happy to submit a PR if you're open to it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions