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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116import Highcharts from 'highcharts'import Exporting from 'highcharts/modules/exporting'Exporting(Highcharts)
const defaults = require('deep-defaults')
import {logoYellow, logoBlue, logoGreen} from '../colors.js'
const buildSegmentChart = function(runs, options) { if (document.getElementById('segment-chart') === null) { return }
const run = runs[0] const timing = new URLSearchParams(window.location.search).get('timing') || run.default_timing const duration = `${timing}time_duration_ms` const shortest = `${timing}time_shortest_duration_ms`
const pbData = [] const meanData = [] let resetCounter = run.attempts const resetData = []
run.segments.forEach((segment, i) => { // Start PB info collection let time = (segment[duration] - segment[shortest]) / 1000 if (time < 0) { time = 0 } pbData.push([segment.display_name || segment.name, time])
// Start mean info collection time = 0 let counter = 0 if ((segment.filteredHistories || segment.histories).length !== 0) { (segment.filteredHistories || segment.histories).forEach((attempt) => { time += attempt[duration] counter++ })
time = ((time / counter) - segment[shortest]) / 1000 } meanData.push([segment.display_name, time])
// Start reset info collection if (resetCounter - segment.histories.length > 0) { resetData.push([segment.display_name, (1 - (segment.histories.length / resetCounter)) * 100]) resetCounter = segment.histories.length } else { resetData.push([segment.display_name, 0]) } })
Highcharts.chart('segment-chart', defaults(_.clone(options), { chart: { type: 'column', scrollablePlotArea: {minWidth: 75 * run.segments.length}, zoomType: 'x' }, title: {text: 'Individual Segment Stats'}, subtitle: {text: 'Lower is Better'}, tooltip: { shared: true }, legend: {enabled: false}, series: [{ name: 'Difference of PB and Gold', data: pbData, dataLabels: { format: '{y:.1f}' }, color: logoYellow, tooltip: { pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.y:.1f}s</b><br/>' } }, { name: 'Difference of Average and Gold', data: meanData, dataLabels: { format: '{y:.1f}' }, color: logoBlue, tooltip: { pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.y:.1f}s</b><br/>' } }, { name: 'Reset Rate', data: resetData, dataLabels: { format: '{y:.1f}%' }, color: logoGreen, tooltip: { pointFormat: '<span style="color:{point.color}">\u25CF</span> {series.name}: <b>{point.y:.1f}%</b><br/>' }, yAxis: 1 }], xAxis: { categories: pbData.map(function(seg) { return seg[0] }), crosshair: true }, yAxis: [{ title: {text: 'Possible Time Save (s)'}, gridLineColor: 'rgba(255, 255, 255, 0.2)', tickColor: 'rgba(255, 255, 255, 0.2)' }, { title: {text: 'Reset Attempts Per Split (%)'}, opposite: true, gridLineColor: 'rgba(255, 255, 255, 0.2)', tickColor: 'rgba(255, 255, 255, 0.2)' }] }))}
export {buildSegmentChart}