Load chartkick and highcharts only on stat pages

This commit is contained in:
Paul Chavard 2020-02-20 19:01:23 +01:00
parent 655e8bc849
commit d8eb3ebb94
8 changed files with 29 additions and 18 deletions

View file

@ -1,25 +0,0 @@
import Chartkick from 'chartkick';
import { toggle } from '@utils';
export function toggleChart(event, chartClass) {
const nextSelectorItem = event.target,
nextChart = document.querySelector(chartClass),
nextChartId = nextChart.children[0].id,
currentSelectorItem = nextSelectorItem.parentElement.querySelector(
'.segmented-control-item-active'
),
currentChart = nextSelectorItem.parentElement.parentElement.querySelector(
'.chart:not(.hidden)'
);
// Change the current selector and the next selector states
currentSelectorItem.classList.toggle('segmented-control-item-active');
nextSelectorItem.classList.toggle('segmented-control-item-active');
// Hide the currently shown chart and show the new one
toggle(currentChart);
toggle(nextChart);
// Reflow needed, see https://github.com/highcharts/highcharts/issues/1979
Chartkick.charts[nextChartId].getChartObject().reflow();
}