Status Chart: chart.js 3.0.0-beta.13, legend click handler #1721
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.
showandhidetoyandnfor shorter URLs.get_hidden(), which determines the initialhiddenstate of each dataset (depending on theURLSearchParamsand the STL's default preference, which is to show everything except for the average lines). Now it emits additional properties:stl_default_hidden(that default preference) andstl_key(which is the name, likecxx20orvso, that each dataset is referred to in the tables and the URL params). These properties are prefixed withstl_as a reminder that they're for our own use, not chart.js's....get_hidden('cxx20')and...get_hidden('avg_age', true)which avoids repeating this info.legend_click_handler()replaces the default handler. In addition to the default behavior of modifying the line's visibility (which is thech.hide(index)/ch.show(index)call andlegend_item.hidden = becoming_hidden;assignment), it updates the URL in-place.becoming_hidden === stl_default_hidden, we can simplydeletethe key from the URL. (Note that if we inspectedch.data.datasets[index].hidden, that's the initial state of the line, which may have been controlled by the initial URL - this is why we need to record the STL's default preference separately.)seta key-value pair. (This handles all cases of having 0/1/more keys in the URL.) We additionallysortthe keys to make the URL nice - otherwise, the order in which lines are hidden and shown can result in different URLs with the same effects.update_url()useswindow.history.replaceState()to modify the address bar, without interfering with back/forward or refreshing. This contains a bit of extra logic to suppress the?when returning to the true default.main. This is very inconvenient (as a bunch of files have to be deleted or recreated, and a lot more activity happens onmainthangh-pages), so I quickly switched to maintaining the chart in a separate clone. The modern instructions in the README depict only a separate clone, with the additional options needed to track just thegh-pagesbranches (making the clone extremely lightweight)..gitignore. We can discard all of the lines for build/test artifacts, and for submodules. It seems reasonable to keep the.vs/and.vscode/ignores..vscode/settings.json, we don't need to exclude the submodules that don't exist for the Status Chart. However, we should exclude what's gitignored:node_modulesisn't interesting to see in the Explorer tree, and.envcontains a secret that we don't want to accidentally display (e.g. when demoing how the Status Chart works, as I'm going to do soon).📉 Live preview: stephantlavavej.github.io/STL/