Introduce units.js, centralizes value normalizing

This commit is contained in:
Christoph Kluge
2023-06-16 12:44:34 +02:00
parent dbd2b491ed
commit ece57bf65e
7 changed files with 56 additions and 37 deletions

View File

@@ -196,7 +196,7 @@
</style>
<script context="module">
import { formatNumber } from '../utils.js'
import { formatNumber } from '../units.js'
export function binsFromFootprint(weights, values, numBins) {
let min = 0, max = 0

View File

@@ -22,7 +22,7 @@
-->
<script>
import uPlot from 'uplot'
import { formatNumber } from '../utils.js'
import { formatNumber } from '../units.js'
import { getContext, onMount, onDestroy } from 'svelte'
export let width
@@ -312,7 +312,9 @@
</script>
<!--Add empty series warning card-->
<div bind:this={plotWrapper} class="cc-plot"></div>
<style>
.cc-plot {
border-radius: 5px;

View File

@@ -46,16 +46,6 @@
}
}
const power = [1, 1e3, 1e6, 1e9, 1e12]
const suffix = ['', 'k', 'm', 'g']
function formatNumber(x) {
for (let i = 0; i < suffix.length; i++)
if (power[i] <= x && x < power[i+1])
return `${x / power[i]}${suffix[i]}`
return Math.abs(x) >= 1000 ? x.toExponential() : x.toString()
}
function axisStepFactor(i, size) {
if (size && size < 500)
return 10
@@ -307,6 +297,7 @@
<script>
import { onMount, tick } from 'svelte'
import { formatNumber } from '../units.js'
export let flopsAny = null
export let memBw = null

View File

@@ -3,7 +3,7 @@
</div>
<script context="module">
import { formatNumber } from '../utils.js'
import { formatNumber } from '../units.js'
const axesColor = '#aaaaaa'
const fontSize = 12