Refactor toggle chart helpers
This commit is contained in:
parent
9d5ffba068
commit
08d5e7d328
1 changed files with 14 additions and 18 deletions
|
@ -1,28 +1,24 @@
|
||||||
import $ from 'jquery';
|
|
||||||
import Chartkick from 'chartkick';
|
import Chartkick from 'chartkick';
|
||||||
|
import { toggle } from '@utils';
|
||||||
|
|
||||||
export function toggleChart(event, chartClass) {
|
export function toggleChart(event, chartClass) {
|
||||||
const nextSelectorItem = $(event.target),
|
const nextSelectorItem = event.target,
|
||||||
nextChart = $(chartClass),
|
nextChart = document.querySelector(chartClass),
|
||||||
nextChartId = nextChart
|
nextChartId = nextChart.children[0].id,
|
||||||
.children()
|
currentSelectorItem = nextSelectorItem.parentElement.querySelector(
|
||||||
.first()
|
'.segmented-control-item-active'
|
||||||
.attr('id'),
|
),
|
||||||
currentSelectorItem = nextSelectorItem
|
currentChart = nextSelectorItem.parentElement.parentElement.querySelector(
|
||||||
.parent()
|
'.chart:not(.hidden)'
|
||||||
.find('.segmented-control-item-active'),
|
);
|
||||||
currentChart = nextSelectorItem
|
|
||||||
.parent()
|
|
||||||
.parent()
|
|
||||||
.find('.chart:not(.hidden)');
|
|
||||||
|
|
||||||
// Change the current selector and the next selector states
|
// Change the current selector and the next selector states
|
||||||
currentSelectorItem.toggleClass('segmented-control-item-active');
|
currentSelectorItem.classList.toggle('segmented-control-item-active');
|
||||||
nextSelectorItem.toggleClass('segmented-control-item-active');
|
nextSelectorItem.classList.toggle('segmented-control-item-active');
|
||||||
|
|
||||||
// Hide the currently shown chart and show the new one
|
// Hide the currently shown chart and show the new one
|
||||||
currentChart.toggleClass('hidden');
|
toggle(currentChart);
|
||||||
nextChart.toggleClass('hidden');
|
toggle(nextChart);
|
||||||
|
|
||||||
// Reflow needed, see https://github.com/highcharts/highcharts/issues/1979
|
// Reflow needed, see https://github.com/highcharts/highcharts/issues/1979
|
||||||
Chartkick.charts[nextChartId].getChartObject().reflow();
|
Chartkick.charts[nextChartId].getChartObject().reflow();
|
||||||
|
|
Loading…
Add table
Reference in a new issue