2018-07-12 11:50:47 +02:00
|
|
|
import Chartkick from 'chartkick';
|
2020-02-20 19:01:23 +01:00
|
|
|
import Highcharts from 'highcharts';
|
2022-04-15 12:12:18 +02:00
|
|
|
import { toggle, delegate } from '@utils';
|
2018-07-12 11:50:47 +02:00
|
|
|
|
2020-04-30 15:42:29 +02:00
|
|
|
export default function () {
|
2020-02-20 19:01:23 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleChart(event) {
|
2018-10-09 11:44:02 +02:00
|
|
|
const nextSelectorItem = event.target,
|
2020-02-20 19:01:23 +01:00
|
|
|
chartClass = event.target.dataset.toggleChart,
|
2018-10-09 11:44:02 +02:00
|
|
|
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)'
|
|
|
|
);
|
2018-07-12 11:50:47 +02:00
|
|
|
|
|
|
|
// Change the current selector and the next selector states
|
2018-10-09 11:44:02 +02:00
|
|
|
currentSelectorItem.classList.toggle('segmented-control-item-active');
|
|
|
|
nextSelectorItem.classList.toggle('segmented-control-item-active');
|
2018-07-12 11:50:47 +02:00
|
|
|
|
|
|
|
// Hide the currently shown chart and show the new one
|
2018-10-09 11:44:02 +02:00
|
|
|
toggle(currentChart);
|
|
|
|
toggle(nextChart);
|
2018-07-12 11:50:47 +02:00
|
|
|
|
|
|
|
// Reflow needed, see https://github.com/highcharts/highcharts/issues/1979
|
|
|
|
Chartkick.charts[nextChartId].getChartObject().reflow();
|
|
|
|
}
|
2020-02-20 19:01:23 +01:00
|
|
|
|
|
|
|
delegate('click', '[data-toggle-chart]', toggleChart);
|
|
|
|
|
|
|
|
Chartkick.use(Highcharts);
|