Skip to content

Commit

Permalink
patch: allow ints in chart min/max values
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail committed Sep 28, 2024
1 parent fae19be commit fae1ec8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/Chart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,15 @@
{/if}
{#if minShown}
<div class="flex flex-row gap-2">
<span style:color={line.color}>min: {formatFloat(min)}{unit}</span>
<span style:color={line.color}>min: {formatFloat(min, true)}{unit}</span>
</div>
{/if}
{#if maxShown && minShown}
<span class="text-slate-500">-</span>
{/if}
{#if maxShown}
<div class="flex flex-row gap-2">
<span style:color={line.color}>max: {formatFloat(max)}{unit}</span>
<span style:color={line.color}>max: {formatFloat(max, true)}{unit}</span>
</div>
{/if}
{/if}
Expand Down
6 changes: 5 additions & 1 deletion src/lib/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ export const speedMapper = (inUnit: Units, outUnit: Units): ((input: number) =>
return miToKm;
};

export const formatFloat = (n: number) => (Number.isNaN(n) ? '??' : n.toFixed(1));
export const formatFloat = (n: number, allowInt = false) => {
if (Number.isNaN(n)) return '??';
if (allowInt && Number.isInteger(n)) return n.toString();
return n.toFixed(1);
};

0 comments on commit fae1ec8

Please sign in to comment.