Skip to content

[Feature Request] use CSS variables for plot attributes #4915

Closed
@nicholasdgoodman

Description

@nicholasdgoodman

I want to be able to manage color theming for charts and graphs the same way I would the remainder of the page, via CSS. A full-scale solution seems like it would be a significant effort, since components like the dcc.Graph take various 'layout' declarations e.g. 'plot_bgcolor' which are converted to inline style attributes on the DOM.

Workarounds / Alternatives

The two workarounds that I have been able to use so far are to declare colors transparent, and then via reverse-engineered CSS selectors, I can get the desired behaviors:

dcc.Graph argument

'layout': {
    'title': 'Dash Data Visualization',
    'paper_bgcolor': 'transparent'
    'plot_bgcolor': 'transparent'
}

CSS

body {
    background-color: #000;
    color: #FFF;
}

.dash-graph text {
    fill: #FFF!important;
}

(Note the required !important to override the inline style declaration.)

Feature Request

Modern browsers support CSS variables which can be used both in for declared and inline styles. However, the dcc.Graph library does not accept these values because it unnecessarily attempts to parse the provided color string and convert it to rgba(...) format.

I would like to be able to:

'layout': {
    'title': 'Dash Data Visualization',
    'paper_bgcolor': 'var(--chart-area-color)`,
    'plot_bgcolor': 'var(--main-background-color)'
}

and without any processing / parsing, simply pass the supplied string straight to the rendered HTML inline style:

<svg class="main-svg" ... style="background: var(--main-background-color);">

Doing so means we can manage coloring of charts and graphs from CSS only without having to modify the dash code.

(Similarly, I see no compelling reasons that named colors or colors supplied in #FFF format should be forcibly converted to rgba(...) format either).

Get more by doing less!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions