const showChart = (underlying, underlying_spots) => { if (typeof underlying_spots === 'undefined' || underlying_spots.length <= 0) { console.log('Unexpected error occured in the charts.'); return; } const dec = underlying_spots[0].split('.')[1].length; for (let i = 0; i < underlying_spots.length; i++) { const val = parseFloat(underlying_spots[i]).toFixed(dec); underlying_spots[i] = val.substr(val.length - 1); } const getTitle = () => ( { text: template($('#last_digit_title').html(), [underlying_spots.length, $('#digit_underlying option:selected').text()]) } ); spots = underlying_spots; if (chart && $('#last_digit_histo').html()) { chart.xAxis[0].update({ title: getTitle() }, true); chart.series[0].name = underlying; } else { addContent(underlying); // this creates #last_digit_title chart_config.xAxis.title = getTitle(); chart = new Highcharts.Chart(chart_config); chart.addSeries({ name: underlying, data: [] }); onLatest(); stream_id = null; } update(); };
$.getJSON('./charts/' + chart_fn).then((options) => { extend(true, options, { subtitle: { text: chart_fn } }); const chart = new Highcharts.Chart(id, options); $(chart.container).bind('mousedown.hc touchstart.hc', (eStart) => { eStart = chart.pointer.normalize(eStart); let posX = eStart.pageX, posY = eStart.pageY, alpha = chart.options.chart.options3d.alpha, beta = chart.options.chart.options3d.beta, newAlpha, newBeta, sensitivity = 5; // lower is more sensitive $(document).bind({ 'mousemove.hc touchdrag.hc': (e) => { // Run beta newBeta = beta + (posX - e.pageX) / sensitivity; chart.options.chart.options3d.beta = newBeta; // Run alpha newAlpha = alpha + (e.pageY - posY) / sensitivity; chart.options.chart.options3d.alpha = newAlpha; chart.redraw(false); }, 'mouseup touchend': () => { $(document).unbind('.hc'); } }); }); });
'mousemove.hc touchdrag.hc': (e) => { // Run beta newBeta = beta + (posX - e.pageX) / sensitivity; chart.options.chart.options3d.beta = newBeta; // Run alpha newAlpha = alpha + (e.pageY - posY) / sensitivity; chart.options.chart.options3d.alpha = newAlpha; chart.redraw(false); },
componentWillUnmount () { this.chart.destroy() }