Skip to content

Commit

Permalink
feat: Format time axis on end of run graph
Browse files Browse the repository at this point in the history
  • Loading branch information
benjl committed Jan 19, 2024
1 parent 022293f commit a4a1006
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion scripts/components/graphs/line-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,27 @@ class LineGraph {
const offset = 'position: ' + (isX ? `${dist}px 0px 0px;` : `0px ${dist}px 0px;`);

// Linear interpolate to determine marker text, backwards for Y. Then round to precision and cast back to Number.
const markerValue = +(isX ? lineMin + j : lineMax + lineMin - j).toFixed(precision);
let markerValue = +(isX ? lineMin + j : lineMax + lineMin - j).toFixed(precision);
if (!isX && axis.name === $.Localize('#Run_Stat_Name_Time')) {
const extreme = Math.max(Math.abs(axis.min), Math.abs(axis.max));
const time = Math.abs(markerValue);

let sign = Math.sign(markerValue) >= 0 ? '+' : '-';
if (markerValue === 0) sign = '';

const hours = Math.floor(time / 3600);
let minutes = Math.floor((time % 3600) / 60);
let seconds = (time % 3600) % 60;

if (time < 10 && extreme < 10) seconds = seconds.toFixed(precision);

markerValue = `${sign}${seconds}`;
if (extreme >= 60) {
if (extreme >= 3600 && minutes < 10) minutes = '0' + minutes;
if (seconds < 10) seconds = '0' + seconds;
markerValue = extreme >= 3600 ? `${sign}${hours}:${minutes}` : `${sign}${minutes}:${seconds}`;
}
}

// Create the marker label
$.CreatePanel('Label', markers, axisName + j, {
Expand Down
2 changes: 1 addition & 1 deletion styles/components/graphs/linegraph.scss
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
height: 16px;
transform: translateY(-6px) translateX(-6px);
text-align: right;
max-width: 20px;
max-width: 40px;
}
}
}
2 changes: 1 addition & 1 deletion styles/config.scss
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ $popup-button-font-size: 24px !default;
// LINEGRAPH
// ================

$linegraph-axis-width: 24px;
$linegraph-axis-width: 40px;

// ================
// TOAST
Expand Down

0 comments on commit a4a1006

Please sign in to comment.