Skip to content

Commit

Permalink
properly fix legend/dataset element visiblity sync
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Apr 19, 2023
1 parent e8af420 commit 22925c7
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/assets/javascripts/visibility.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
$(document).ready(function() {
function updateChart(elemId, checked) {
const chart = Chartkick.charts['chart-1'].chart;
const dataset = chart.data.datasets.find(
x => x.label.replaceAll('&', '').replace(/\s/g, '').toLowerCase() === elemId.replaceAll('_', '')
const lookupId = elemId.replaceAll('_', '');
const legendItem = chart.legend.legendItems.find(
x => x.text.replaceAll('&', '').replace(/\s/g, '').toLowerCase() === lookupId
);
if (dataset) {
dataset.hidden = !checked;
chart.update();
if (legendItem) {
legendItem.hidden = !checked;

if (checked) {
chart.show(legendItem.datasetIndex);
} else {
chart.hide(legendItem.datasetIndex);
}
}
}

Expand Down

0 comments on commit 22925c7

Please sign in to comment.