Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make charts 'theme-able' and add a 'dark' theme. #826

Merged
merged 2 commits into from
May 25, 2020

Conversation

mikelehen
Copy link
Collaborator

This makes the charts minimally "theme-able" and adds a dark set of colors for them.

To see how this gets used in the chart sharing, see here

And preview: https://covid-projections-git-mikelehen-share-charts.covidactnow.now.sh/internal/share-image/states/wa/chart/0

@mikelehen mikelehen requested a review from pnavarrc May 24, 2020 22:59
@vercel
Copy link

vercel bot commented May 24, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/covidactnow/covid-projections/rfhgk9twn
✅ Preview: https://covid-projections-git-mikelehen-chart-themes.covidactnow.now.sh

<Switch>
<Route exact path="/" component={HomePage} />
<MuiThemeProvider theme={theme}>
<ScThemeProvider theme={theme}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the recommended way to use a theme with both material-ui and styled-components. 😬
mui/material-ui#10098 (comment)

(note: the rest of this file is unchanged; turn on "Hide whitespace changes" to make the diff much better)

/** Gets the chart palette based on the current theme. */
function palette(props: any) {
return props.theme.palette.chart;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the core change. Instead of accessing palette directly, we always access it via props.theme.palette so that it picks up the current theme. The rest of the changes are just changing to use this helper function.

See here for how I override the theme for the share charts.


// TODO(michael): Not loving this complexity. Perhaps we could just always use regionColor?
regionAnnotationStroke: (isActive: boolean, regionColor: string) =>
isActive ? regionColor : lightGray,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UX mocks for the dark-mode chart always outline (stroke) the region labels with the region color, but the current light-mode charts only use the region color if the region is active, so I had to make this into a function so I could have different logic for the dark charts. 😦

@vercel vercel bot temporarily deployed to Preview May 25, 2020 00:03 Inactive
@vercel vercel bot temporarily deployed to Preview May 25, 2020 00:04 Inactive
Copy link
Contributor

@pnavarrc pnavarrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

src/components/Charts/Charts.style.ts Outdated Show resolved Hide resolved
@mikelehen mikelehen merged commit 1e43f8f into develop May 25, 2020
@mikelehen mikelehen deleted the mikelehen/chart-themes branch May 25, 2020 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants