Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main/http_server/axe-os/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { HashSuffixPipe } from './pipes/hash-suffix.pipe';
import { DiffSuffixPipe } from './pipes/diff-suffix.pipe';
import { AddressPipe } from './pipes/address.pipe';
import { SatsPipe } from './pipes/sats.pipe';
import { HeatmapLightnessPipe } from './pipes/heatmap-lightness.pipe';
import { DialogService, DialogListComponent } from './services/dialog.service';

const components = [
Expand Down Expand Up @@ -96,6 +97,7 @@ const components = [
DiffSuffixPipe,
AddressPipe,
SatsPipe,
HeatmapLightnessPipe,
],
providers: [
{ provide: LocationStrategy, useClass: HashLocationStrategy },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ElementRef, Input, OnChanges, OnDestroy, SimpleChanges, ViewChild } from '@angular/core';
import { Component, ElementRef, Input, NgZone, OnChanges, OnDestroy, SimpleChanges, ViewChild } from '@angular/core';
import { Chart, registerables } from 'chart.js';

Chart.register(...registerables);
Expand All @@ -25,6 +25,8 @@ export class AppChartComponent implements OnChanges, OnDestroy {

public chart: Chart | null = null;

constructor(private ngZone: NgZone) {}

ngOnChanges(changes: SimpleChanges) {
if (changes['data'] || changes['options'] || changes['type']) {
this.updateChart();
Expand All @@ -37,34 +39,40 @@ export class AppChartComponent implements OnChanges, OnDestroy {

private destroyChart() {
if (this.chart) {
this.chart.destroy();
this.chart = null;
this.ngZone.runOutsideAngular(() => {
this.chart?.destroy();
this.chart = null;
});
}
}

private updateChart() {
if (!this.canvas) return;

if (this.chart) {
this.chart.data = this.data;
if (this.options) {
this.chart.options = this.options;
this.ngZone.runOutsideAngular(() => {
if (this.chart) {
this.chart.data = this.data;
if (this.options) {
this.chart.options = this.options;
}
this.chart.update();
} else {
this.initChart();
}
this.chart.update();
} else {
this.initChart();
}
});
}

private initChart() {
this.destroyChart();
const ctx = this.canvas.nativeElement.getContext('2d');
if (!ctx) return;

this.chart = new Chart(ctx, {
type: this.type as any,
data: this.data,
options: this.options
this.ngZone.runOutsideAngular(() => {
this.chart = new Chart(ctx, {
type: this.type as any,
data: this.data,
options: this.options
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ <h6 class="flex justify-between mb-1">
</h6>
@let powerProgress = ((info.power / info.maxPower) * 100);
<div class="w-full bg-progressbar rounded-sm overflow-hidden h-[6px]">
<div class="bg-progressbar-value h-full transition-all duration-300" [style.width.%]="powerProgress"></div>
<div class="bg-progressbar-value h-full transition-[width] duration-300" [style.width.%]="powerProgress"></div>
</div>
</div>

Expand All @@ -244,7 +244,7 @@ <h6 class="flex justify-between mb-1">
<div class="relative">
@let voltageProgress = ((info.voltage / (info.nominalVoltage + .5)) * 100);
<div class="w-full bg-progressbar rounded-sm overflow-hidden h-[6px]">
<div class="bg-progressbar-value h-full transition-all duration-300" [style.width.%]="voltageProgress"></div>
<div class="bg-progressbar-value h-full transition-[width] duration-300" [style.width.%]="voltageProgress"></div>
</div>

<!-- Conditional marker based on nominal voltage-->
Expand All @@ -268,7 +268,7 @@ <h6 class="flex justify-between mb-1">
</h6>
@let freqProgress = ((info.actualFrequency / maxFrequency) * 100);
<div class="w-full bg-progressbar rounded-sm overflow-hidden h-[6px]">
<div class="bg-progressbar-value h-full transition-all duration-300" [style.width.%]="freqProgress"></div>
<div class="bg-progressbar-value h-full transition-[width] duration-300" [style.width.%]="freqProgress"></div>
</div>
</div>

Expand All @@ -278,7 +278,7 @@ <h6 class="flex justify-between mb-1">
</h6>
@let coreVoltProgress = ((info.coreVoltageActual / 1.8) * 100);
<div class="w-full bg-progressbar rounded-sm overflow-hidden h-[6px]">
<div class="bg-progressbar-value h-full transition-all duration-300" [style.width.%]="coreVoltProgress"></div>
<div class="bg-progressbar-value h-full transition-[width] duration-300" [style.width.%]="coreVoltProgress"></div>
</div>
</div>
</div>
Expand Down Expand Up @@ -307,7 +307,7 @@ <h6 class="flex justify-between mb-1">
</h6>
@let tempProgress = ((info.temp / maxTemp) * 100);
<div class="w-full bg-progressbar rounded-sm overflow-hidden h-[6px]">
<div class="bg-progressbar-value h-full transition-all duration-300" [style.width.%]="tempProgress"></div>
<div class="bg-progressbar-value h-full transition-[width] duration-300" [style.width.%]="tempProgress"></div>
</div>

<strong class="text-red-500" *ngIf="info.temp >= 70">
Expand All @@ -324,7 +324,7 @@ <h6 class="flex justify-between mb-1">
</h6>
@let temp2Progress = ((info.temp2 / maxTemp) * 100);
<div class="w-full bg-progressbar rounded-sm overflow-hidden h-[6px]">
<div class="bg-progressbar-value h-full transition-all duration-300" [style.width.%]="temp2Progress"></div>
<div class="bg-progressbar-value h-full transition-[width] duration-300" [style.width.%]="temp2Progress"></div>
</div>

<strong class="text-red-500" *ngIf="info.temp2 >= 70">
Expand All @@ -338,7 +338,7 @@ <h6 class="flex justify-between mb-1">
</h6>
@let vrTempProgress = ((info.vrTemp / 120) * 100);
<div class="w-full bg-progressbar rounded-sm overflow-hidden h-[6px]">
<div class="bg-progressbar-value h-full transition-all duration-300" [style.width.%]="vrTempProgress"></div>
<div class="bg-progressbar-value h-full transition-[width] duration-300" [style.width.%]="vrTempProgress"></div>
</div>

<strong class="text-red-500" *ngIf="info.vrTemp >= 105">
Expand Down Expand Up @@ -370,7 +370,7 @@ <h4 class="text-center font-medium">Fan</h4>
</h6>
@let fanProgress = info.fanspeed;
<div class="w-full bg-progressbar rounded-sm overflow-hidden h-[6px]">
<div class="bg-progressbar-value h-full transition-all duration-300" [style.width.%]="fanProgress"></div>
<div class="bg-progressbar-value h-full transition-[width] duration-300" [style.width.%]="fanProgress"></div>
</div>
</div>
</div>
Expand Down Expand Up @@ -581,7 +581,7 @@ <h4 class="whitespace-nowrap overflow-hidden text-ellipsis font-medium">Hashrate
{{ i + 1 }}
</td>
<td *ngFor="let domain of asic?.domains; trackBy: trackByIndex"
[style.--lightness]="getHeatmapLightness(domain, info.expectedHashrate)"
[style.--lightness]="domain | heatmapLightness: info.expectedHashrate : asicsAmount : asicDomainsAmount"
[style.height]="(asicAmount <= 2 ? '2rem' : null)"
class="heatmap-cell">
<span class="text-xs">{{ domain | hashSuffix }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { DateAgoPipe } from 'src/app/pipes/date-ago.pipe';
import { AddressPipe } from 'src/app/pipes/address.pipe';
import { SatsPipe } from 'src/app/pipes/sats.pipe';
import { ByteSuffixPipe } from 'src/app/pipes/byte-suffix.pipe';
import { HeatmapLightnessPipe } from 'src/app/pipes/heatmap-lightness.pipe';

import { TooltipTextIconComponent } from 'src/app/components/tooltip-text-icon/tooltip-text-icon.component';
import { TooltipIconComponent } from 'src/app/components/tooltip-icon/tooltip-icon.component';
Expand Down Expand Up @@ -166,7 +167,8 @@ describe('HomeComponent', () => {
DateAgoPipe,
AddressPipe,
SatsPipe,
ByteSuffixPipe
ByteSuffixPipe,
HeatmapLightnessPipe
],
providers: [
provideRouter([]),
Expand Down
121 changes: 73 additions & 48 deletions main/http_server/axe-os/src/app/components/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, ViewChild, Input, OnDestroy, ElementRef, HostListener, effect } from '@angular/core';
import { Component, OnInit, ViewChild, Input, OnDestroy, ElementRef, HostListener, effect, NgZone, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { map, Observable, shareReplay, Subscription, switchMap, tap, first, Subject, takeUntil, BehaviorSubject, filter, combineLatest } from 'rxjs';
import { HttpErrorResponse } from '@angular/common/http';
import { getHttpErrorMessage } from 'src/app/utils/error-handler';
Expand Down Expand Up @@ -74,6 +74,7 @@ const WIDGET_DEFAULTS: WidgetDef[] = [
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false
})
export class HomeComponent implements OnInit, OnDestroy {
Expand Down Expand Up @@ -221,7 +222,9 @@ export class HomeComponent implements OnInit, OnDestroy {
private shareRejectReasonsService: ShareRejectionExplanationService,
private storageService: LocalStorageService,
private dashboardEditService: DashboardEditService,
public layoutService: LayoutService
public layoutService: LayoutService,
private ngZone: NgZone,
private cd: ChangeDetectorRef
) {
this.initializeChart();

Expand Down Expand Up @@ -285,7 +288,9 @@ export class HomeComponent implements OnInit, OnDestroy {
this.loadPreviousData();
})

this.staleCheckInterval = setInterval(() => this.checkStaleData(), 1000);
this.ngZone.runOutsideAngular(() => {
this.staleCheckInterval = setInterval(() => this.checkStaleData(), 1000);
});

this.loadPreviousData();
}
Expand Down Expand Up @@ -481,7 +486,9 @@ export class HomeComponent implements OnInit, OnDestroy {
const durationSeconds = Math.floor(elapsedMs / 1000);
const current = this.systemInfoError$.value;
if (current.duration !== durationSeconds) {
this.systemInfoError$.next({ duration: durationSeconds, startTime: this.lastMessageTime });
this.ngZone.run(() => {
this.systemInfoError$.next({ duration: durationSeconds, startTime: this.lastMessageTime });
});
}
}
}
Expand Down Expand Up @@ -926,25 +933,41 @@ export class HomeComponent implements OnInit, OnDestroy {
if (this.lastSharesAcceptedCount !== -1 && currentSharesAccepted > this.lastSharesAcceptedCount) {
this.flashShareAccepted = true;
clearTimeout(this.shareAcceptedTimeout);
this.shareAcceptedTimeout = setTimeout(() => this.flashShareAccepted = false, 500);
this.ngZone.runOutsideAngular(() => {
this.shareAcceptedTimeout = setTimeout(() => {
this.flashShareAccepted = false;
this.cd.markForCheck();
}, 500);
});
}
this.lastSharesAcceptedCount = currentSharesAccepted;

const currentSharesRejected = info.sharesRejected;
if (this.lastSharesRejectedCount !== -1 && currentSharesRejected > this.lastSharesRejectedCount) {
this.flashShareRejected = true;
clearTimeout(this.shareRejectedTimeout);
this.shareRejectedTimeout = setTimeout(() => this.flashShareRejected = false, 500);
this.ngZone.runOutsideAngular(() => {
this.shareRejectedTimeout = setTimeout(() => {
this.flashShareRejected = false;
this.cd.markForCheck();
}, 500);
});
}
this.lastSharesRejectedCount = currentSharesRejected;

const currentWorkReceived = info.workReceived ?? 0;
if (this.lastWorkReceived !== -1 && currentWorkReceived > this.lastWorkReceived) {
this.flashWorkReceived = true;
clearTimeout(this.workReceivedTimeout);
this.workReceivedTimeout = setTimeout(() => this.flashWorkReceived = false, 500);
this.ngZone.runOutsideAngular(() => {
this.workReceivedTimeout = setTimeout(() => {
this.flashWorkReceived = false;
this.cd.markForCheck();
}, 500);
});
}
this.lastWorkReceived = currentWorkReceived;
this.cd.markForCheck();
}),
map(info => {
const formatted = { ...info };
Expand All @@ -967,6 +990,7 @@ export class HomeComponent implements OnInit, OnDestroy {
.subscribe(([info, systemInfoError]) => {
this.handleSystemMessages(info, systemInfoError);
this.setTitle(info, systemInfoError);
this.cd.markForCheck();
});

this.info$.pipe(first(), takeUntil(this.destroy$)).subscribe(() => {
Expand Down Expand Up @@ -1234,54 +1258,55 @@ export class HomeComponent implements OnInit, OnDestroy {
const statsFrequencyMs = (statsFrequency || 30) * 1000;
const windowDurationMs = limit * statsFrequencyMs;

const currentSpan = this.dataLabel[this.dataLabel.length - 1] - this.dataLabel[0];
if (currentSpan >= windowDurationMs) {
const excess = this.dataLabel.length - limit;
if (excess > 0) {
this.dataLabel.splice(0, excess);
this.hashrateData.splice(0, excess);
this.powerData.splice(0, excess);
this.chartY1Data.splice(0, excess);
this.chartY2Data.splice(0, excess);
}
}

while (this.dataLabel.length > limit) {
const currentSpan = this.dataLabel[this.dataLabel.length - 1] - this.dataLabel[0];

if (currentSpan >= windowDurationMs) {
// Option A: Chart is at max capacity in time. Prune oldest to slide the window.
this.dataLabel.shift();
this.hashrateData.shift();
this.powerData.shift();
this.chartY1Data.shift();
this.chartY2Data.shift();
} else {
// Option B: Chart is crowded. Binary search for the densest region.
// We initialize search range from index 1 to length - 2 to protect the oldest point (index 0)
// and newest point (index length - 1) from being deleted, preserving chart boundaries.
let low = 1;
let high = this.dataLabel.length - 2;
while (high - low > 1) {
const midTime = (this.dataLabel[low] + this.dataLabel[high]) / 2;

let split = low;
for (let i = low; i <= high; i++) {
if (this.dataLabel[i] >= midTime) {
split = i;
break;
}
// Option B: Chart is crowded. Binary search for the densest region.
// We initialize search range from index 1 to length - 2 to protect the oldest point (index 0)
// and newest point (index length - 1) from being deleted, preserving chart boundaries.
let low = 1;
let high = this.dataLabel.length - 2;
while (high - low > 1) {
const midTime = (this.dataLabel[low] + this.dataLabel[high]) / 2;

let split = low;
for (let i = low; i <= high; i++) {
if (this.dataLabel[i] >= midTime) {
split = i;
break;
}
}

// Ensure we make progress even if multiple points have the same timestamp
if (split === low) split++;
if (split > high) split = high;
// Ensure we make progress even if multiple points have the same timestamp
if (split === low) split++;
if (split > high) split = high;

const leftCount = split - low;
const rightCount = high - split + 1;
const leftCount = split - low;
const rightCount = high - split + 1;

if (leftCount > rightCount) {
high = split - 1;
} else {
low = split;
}
if (leftCount > rightCount) {
high = split - 1;
} else {
low = split;
}

// Remove point at index 'low'.
this.dataLabel.splice(low, 1);
this.hashrateData.splice(low, 1);
this.powerData.splice(low, 1);
this.chartY1Data.splice(low, 1);
this.chartY2Data.splice(low, 1);
}

// Remove point at index 'low'.
this.dataLabel.splice(low, 1);
this.hashrateData.splice(low, 1);
this.powerData.splice(low, 1);
this.chartY1Data.splice(low, 1);
this.chartY2Data.splice(low, 1);
}

if (this.chartData) {
Expand Down
9 changes: 6 additions & 3 deletions main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ export class DateAgoPipe implements PipeTransform {
}

transform(value: any, args?: any): any {
if (value) {
value = new Date().getTime() - value * 1000;
let seconds = Math.floor((+new Date() - +new Date(value)) / 1000);
if (value !== undefined && value !== null && value !== '') {
let seconds = Math.floor(Number(value));
if (seconds > 1e9) {
seconds = Math.floor((Date.now() - seconds) / 1000);
}
if (isNaN(seconds) || seconds < 0) return value;
if (!args?.strict && seconds < 29) // less than 30 seconds ago will show as 'Just now'
return 'Just now';
const intervals: { [key: string]: number } = {
Expand Down
Loading
Loading