Skip to content

Commit

Permalink
feat: fix crypto prices
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaZhem committed Aug 28, 2024
1 parent 3a7d85b commit 6f289b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
[horizontalLines]="4"
[verticalLines]="4"
>
<tui-line-chart
class="chart"
[height]="maxPrice() * (maxPrice() > 10 ? 1 : 100) - minPrice() * (maxPrice() > 10 ? 1 : 100)"
[value]="chart()"
[width]="chart().length"
[x]="0"
[xStringify]="xStringify"
[y]="minPrice() * (maxPrice() > 10 ? 1 : 100)"
[yStringify]="yStringify"
/>
@if (checkInfinity(maxPrice()) && checkInfinity(minPrice())) {
<tui-line-chart
class="chart"
[height]="maxPrice() * (maxPrice() > 10 ? 1 : 100) - minPrice() * (maxPrice() > 10 ? 1 : 100)"
[value]="chart()"
[width]="chart().length"
[x]="0"
[xStringify]="xStringify"
[y]="minPrice() * (maxPrice() > 10 ? 1 : 100)"
[yStringify]="yStringify"
/>
}
</tui-axes>
<div class="buttons">
@for (btn of filterButtons; track $index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export class PriceChartComponent {

protected chart = computed(() => this.processData(this.history()));

protected minPrice = computed(() =>
Math.min(...(this.history() ?? []).map((val) => Number(val.priceUsd))),
protected minPrice = computed(
() => Math.min(...(this.history() ?? []).map((val) => Number(val.priceUsd))) || 0,
);

protected maxPrice = computed(() =>
Math.max(...(this.history() ?? []).map((val) => Number(val.priceUsd))),
protected maxPrice = computed(
() => Math.max(...(this.history() ?? []).map((val) => Number(val.priceUsd))) || 0,
);

protected filterButtons = ['D', 'W', 'M', 'M6', 'Y'];
Expand All @@ -94,6 +94,10 @@ export class PriceChartComponent {
return fullSize.filter((_, i) => i % this.step() === 0);
}

protected checkInfinity(value: number): boolean {
return Number.isFinite(value);
}

protected readonly yStringify: TuiStringHandler<number> = (y) =>
`${(this.maxPrice() > 10 ? y : y / 100).toLocaleString('en-US', {maximumFractionDigits: this.maxPrice() > 10 ? 0 : 2})} $`;

Expand Down

0 comments on commit 6f289b2

Please sign in to comment.