Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const RangeSelector = ({ enabled = true, children, ...restProps }) => {
const props = { enabled, ...restProps };
const [rendered, setRendered] = useState(false);
const Highcharts = useHighcharts();
const chart = useChart();
const axis = useAxis('xAxis');
useEffect(() => {
if (!axis) return;
// Workaround inferred from http://jsfiddle.net/x40me94t/2/
const chartObj = chart.object;
chartObj.options.rangeSelector.enabled = true;
// Initialise RangeSelector (see https://github.com/highcharts/highcharts/blob/dd730ab/js/parts/RangeSelector.js#L1464-L1468)
Highcharts.fireEvent(chartObj, 'afterGetContainer');
const opts = getRangeSelectorConfig(props, Highcharts);
updateRangeSelector(opts, chart);
const renderRangeSelector = createRenderRangeSelector(chart, axis);
const RangeSelectorInner = ({ enabled = true, axisId, children, ...restProps }) => {
const props = { enabled, ...restProps };
const [rendered, setRendered] = useState(false);
const Highcharts = useHighcharts();
const chart = useChart();
const axis = useAxis(axisId);
useEffect(() => {
if (!axis) return;
// Workaround inferred from http://jsfiddle.net/x40me94t/2/
const chartObj = chart.object;
chartObj.options.rangeSelector.enabled = true;
Highcharts.fireEvent(chartObj, 'init'); // Pre Highcharts 6.1
Highcharts.fireEvent(chartObj, 'afterGetContainer'); // Highcharts 6.1+
const opts = getRangeSelectorConfig(props, Highcharts);
updateRangeSelector(opts, chart);
const MapNavigation = ({ children, enabled = true, ...restProps }) => {
const [rendered, setRendered] = useState(false);
const chart = useChart();
const Highcharts = useHighcharts();
useEffect(() => {
// Workaround inferred from http://jsfiddle.net/x40me94t/2/
const chartObj = chart.object;
chartObj.options.mapNavigation.enabled = true;
// Initialise MapNavigation https://github.com/highcharts/highcharts/blob/dd730ab/js/parts-map/MapNavigation.js#L288-L294
Highcharts.fireEvent(chartObj, 'beforeRender');
const opts = getMapNavigationConfig({ enabled, ...restProps }, Highcharts);
updateMapNavigation(opts, chart);
setRendered(true);
return () => {
attempt(updateMapNavigation, { enabled: false }, chart);
};
const Navigator = ({ enabled = true, ...restProps }) => {
const props = { enabled, ...restProps };
const [rendered, setRendered] = useState(false);
const chart = useChart();
const Highcharts = useHighcharts();
useEffect(() => {
const { children, ...rest } = props;
// Workaround from http://jsfiddle.net/x40me94t/2/
const chartObj = chart.object;
chartObj.options.navigator.enabled = true;
// Initialise Navigator https://github.com/highcharts/highcharts/blob/dd730ab/js/parts/Navigator.js#L1837-L1844
Highcharts.fireEvent(chartObj, 'beforeRender');
updateNavigator(rest, chart);
setRendered(true);
return () => {
attempt(updateNavigator, { enabled: false }, chart);
};
const MapNavigationButton = props => {
const Highcharts = useHighcharts();
const chart = useChart();
useEffect(() => {
const { type, ...rest } = props;
const opts = getMapNavigationButtonConfig(rest, Highcharts);
updateMapNavigationButton(type, opts, chart);
return () => {
// TODO removeButton was missing in original class?
//const { type } = props;
//attempt(this.removeButton, type, {});
};
}, []);
return null;
};
const HighchartsStockChart = props => {
const Highcharts = useHighcharts();
return (
);
};
const HighchartsMapChart = ({ map, chart, callback, ...restProps }) => {
const Highcharts = useHighcharts();
const geojson = useMemo(() => {
return createGeoJSON(map, Highcharts);
}, [map]);
const chartConfig = useMemo(() => ({ ...chart, map: geojson }), [
geojson,
chart
]);
const chartCallback = useCallback(
cbChart => {
if (geojson) {
const format = Highcharts.format;
const { mapText, mapTextFull } = cbChart.options.credits;
cbChart.mapCredits = format(mapText, { geojson });
cbChart.mapCreditsFull = format(mapTextFull, { geojson });
}
const DateRangePickers = () => {
const Highcharts = useHighcharts();
const axis = useAxis('xAxis');
const [from, setFrom] = useState(null);
const [to, setTo] = useState(null);
const handleFromDateChange = fromDate => {
const newMin = startOfDay(fromDate).valueOf();
const newMax = (newMin >= to) ? newMin + ONE_DAY : to.valueOf();
axis.setExtremes(newMin, newMax);
};
const handleToDateChange = toDate => {
const newMax = startOfDay(toDate).valueOf();
const newMin = (newMax <= from) ? newMax - ONE_DAY : from.valueOf();