Merge pull request #208 from ClusterCockpit/hotfix

fix plot timestamp format in systems/node view
This commit is contained in:
Christoph Kluge 2023-08-31 12:08:16 +02:00 committed by GitHub
commit c401e195f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -166,7 +166,7 @@
} }
} }
const plotSeries = [{label: 'Runtime', value: (u, ts, sidx, didx) => didx == null ? null : formatTime(ts)}] const plotSeries = [{label: 'Runtime', value: (u, ts, sidx, didx) => didx == null ? null : formatTime(ts, forNode)}]
const plotData = [new Array(longestSeries)] const plotData = [new Array(longestSeries)]
if (forNode === true) { if (forNode === true) {
@ -227,7 +227,7 @@
scale: 'x', scale: 'x',
space: 35, space: 35,
incrs: timeIncrs(timestep, maxX, forNode), incrs: timeIncrs(timestep, maxX, forNode),
values: (_, vals) => vals.map(v => formatTime(v)) values: (_, vals) => vals.map(v => formatTime(v, forNode))
}, },
{ {
scale: 'y', scale: 'y',
@ -349,19 +349,21 @@
} }
</script> </script>
<script context="module"> <script context="module">
export function formatTime(t) { export function formatTime(t, forNode = false) {
if (t !== null) { if (t !== null) {
if (isNaN(t)) { if (isNaN(t)) {
return t return t
} else { } else {
let h = Math.floor(t / 3600) const tAbs = Math.abs(t)
let m = Math.floor((t % 3600) / 60) const h = Math.floor(tAbs / 3600)
const m = Math.floor((tAbs % 3600) / 60)
// Re-Add "negativity" to time ticks only as string, so that if-cases work as intended
if (h == 0) if (h == 0)
return `${m}m` return `${forNode && m != 0 ? '-' : ''}${m}m`
else if (m == 0) else if (m == 0)
return `${h}h` return `${forNode?'-':''}${h}h`
else else
return `${h}:${m}h` return `${forNode?'-':''}${h}:${m}h`
} }
} }
} }