Use jsx extension
This commit is contained in:
parent
98be7e2076
commit
1c164c4376
28 changed files with 2 additions and 1 deletions
37
app/javascript/components/Chartkick.jsx
Normal file
37
app/javascript/components/Chartkick.jsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import Chartkick from 'chartkick';
|
||||
import Highcharts from 'highcharts';
|
||||
import { toggle, delegate, fire } from '@utils';
|
||||
|
||||
export default function () {
|
||||
return null;
|
||||
}
|
||||
|
||||
function toggleChart(event) {
|
||||
const nextSelectorItem = event.target,
|
||||
chartClass = event.target.dataset.toggleChart,
|
||||
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();
|
||||
}
|
||||
|
||||
delegate('click', '[data-toggle-chart]', toggleChart);
|
||||
|
||||
Chartkick.use(Highcharts);
|
||||
window.Chartkick = Chartkick;
|
||||
fire(window, 'chartkick:ready');
|
Loading…
Add table
Add a link
Reference in a new issue