Status Chart: Dark mode with Primer CSS#2835
Merged
StephanTLavavej merged 17 commits intomicrosoft:gh-pagesfrom Jul 1, 2022
Merged
Status Chart: Dark mode with Primer CSS#2835StephanTLavavej merged 17 commits intomicrosoft:gh-pagesfrom
StephanTLavavej merged 17 commits intomicrosoft:gh-pagesfrom
Conversation
CaseyCarter
approved these changes
Jul 1, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements dark mode for the Status Chart and significantly improves its styling by using Primer CSS, which is what GitHub itself uses. This achieves much better results than a naive invert + hue-rotate, and (with special logic) also updates dynamically - most common on mobile, but you can easily test this on desktop by pressing F12, selecting the Elements > Styles tabs, then clicking the paintbrush to change
prefers-color-scheme.In general, I tried to keep most of the color choices I originally made, but I changed a few to look better, especially in dark mode.
As this is a major change, I've structured it into a series of commits.
htmlelement control dark mode.body,container-xlallows the chart to get quite wide, but with a limit (most relevant on desktop). This helps it stay readable - the chart was hard to read on a fully maximized window.markdown-bodymakes list items, horizontal rules, etc. look nice.pt-2 px-3 pb-3controls padding - without this, content goes all the way to the edge of the window. Padding level 3 looks reasonable, except that the Status Chart itself has a bit of blank space at the top, so I'm using padding level 2 there.btnclass to be styled like GitHub buttons, and the docs strongly advisetype="button"too (which I was previously unaware of).currentValuebolding withCounterbubbles.make_yAxis().HiddenInfotoDatasetInfo.wreckgeneralize it!get_label_and_hidden()toget_dataset_properties().yAxisIDintoDatasetInfo.DatasetInfoMapsand the options below).type AxisID = `${string}Axis`;is a template literal type, providing a little defense against passing arguments in the wrong order.DatasetInfo.merge_bardidn't have abackgroundColorand used a default translucent gray. Now it will have a flat solid color.borderWidth: 1onmerge_bar.make_common_options().common_options,common_plugins,common_titleintomake_common_options().title_text, we can make it clearer what options we're building up.--color-MEOWthat appears in Primer CSS. These can be looked up to get actual hex colors.--color-scale-red-7which looks reasonably good in both light and dark mode.get_css_property()calls will retrieve the correct color for the mode that's active during initial page load. By itself, this will not update dynamically (Primer CSS will automatically update the non-chart HTML elements, but the chart is custom drawn).scale.titledoes not exist when alegendonClickhandler is specified chartjs/Chart.js#10442 here. By usingLegendElement<'bar' | 'line'>(as our charts are either purely line, or bar + line combinations), we can more easily accessscale.titlebelow.npm updatenpm install [dependencies]@latestbuilt/status_chart.mjs.📉 🌃 Live preview: stephantlavavej.github.io/STL/
Screenshots:
Status Chart
Old
New (Light)
New (Dark)
Age Chart
Old
New (Light)
New (Dark)
Merge Chart
Old
New (Light)
New (Dark)