Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/splits-io. a speedrunning data store and analysis engine splits.io
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263const Highcharts = require('highcharts')require('highcharts/modules/exporting')(Highcharts)
const defaults = require('deep-defaults')const moment = require('moment')
import {logoColors} from '../colors.js'
const buildSegmentDurationChart = function(timing, runs, segments, options = {}) { if (document.getElementById(`segment-duration-chart-${segments[0].id}`) === null) { return }
const duration = `${timing}time_duration_ms`
Highcharts.chart(`segment-duration-chart-${segments[0].id}`, defaults(_.clone(options), { exporting: {enabled: false}, chart: { borderRadius: 0, borderWidth: 0, plotBorderWidth: 0, type: 'spline', zoomType: 'xy' }, colors: logoColors, plotOptions: { series: {connectNulls: true}, spline: { marker: {enabled: false} } }, series: segments.filter(Boolean).map((segment, i) => ({ name: `${(runs[i].runners[0] || {name: '???'}).name}'s ${segment.display_name}`, data: (segment.filteredHistories || segment.histories).map(attempt => { return [`Attempt #${attempt.attempt_number}`, attempt[duration]] }), pointStart: 1 })), title: {text: undefined}, tooltip: { shared: true, crosshairs: true, pointFormatter: function() { let time = moment.duration(this.y).format('H:mm:ss') return `<span style="color: #fff">\u25CF</span> ${this.series.name}: <b>${time}</b><br/>` } }, xAxis: { allowDecimals: false, lineColor: '#fff', title: {text: 'Attempt Number'} }, yAxis: { gridLineColor: 'rgba(255, 255, 255, 0.2)', labels: {formatter: function() { return moment.duration(this.value).format('H:mm:ss') }}, tickColor: 'rgba(255, 255, 255, 0.2)', title: {text: 'Duration of Segment'} } }))}
export {buildSegmentDurationChart}