import Highcharts from 'highcharts' import Exporting from 'highcharts/modules/exporting' Exporting(Highcharts) const build_segment_graph = function(timing, segment, chartOptions) { if (document.getElementById(`segment-graph-holder-${segment.id}`) === null) { return } const duration = `${timing}time_duration_ms` let graph_data = [] const non_zero_values = segment.histories.filter((attempt) => attempt[duration] > 0) graph_data.push({ name: segment.name, data: non_zero_values.map(function(attempt) { return ['Attempt #' + attempt.attempt_number, attempt[duration]] }), pointStart: 1 }) Highcharts.chart('segment-graph-holder-' + segment.id, { exporting: { chartOptions: Object.assign(chartOptions, { plotOptions: { series: { dataLabels: {enabled: true} } } }), fallbackToExportServer: false }, chart: { borderRadius: 0, borderWidth: 0, plotBorderWidth: 0, zoomType: 'xy' }, colors: ['#fff'], legend: { enabled: false }, title: { text: 'Segment Duration over Time' }, plotOptions: { series: { connectNulls: true } }, tooltip: { shared: true, crosshairs: true, pointFormatter: function() { let time = moment.duration(this.y).format('H:mm:ss') return `\u25CF ${this.series.name}: ${time}
` } }, xAxis: { allowDecimals: false, lineColor: '#fff', title: { text: 'Attempt Number' } }, yAxis: { gridLineColor: 'rgba(1, 1, 1, 0.3)', min: 0, tickColor: 'rgba(1, 1, 1, 0.3)', title: { text: 'Duration of Segment' }, labels: { formatter: function() { return moment.duration(this.value).format('H:mm:ss') } } }, series: graph_data }) } export {build_segment_graph}