plot tooltip

This commit is contained in:
Patrick Haßel 2025-11-04 11:57:09 +01:00
parent 04be7692c1
commit bec1ee0c28
5 changed files with 57 additions and 30 deletions

View File

@ -2,6 +2,8 @@ export class EnergyPoint {
readonly epochSeconds: number; readonly epochSeconds: number;
readonly date: Date;
private _purchase: number | null = null; private _purchase: number | null = null;
private _produce: number | null = null; private _produce: number | null = null;
@ -51,6 +53,7 @@ export class EnergyPoint {
point: number[], point: number[],
) { ) {
this.epochSeconds = point[0]; this.epochSeconds = point[0];
this.date = new Date(this.epochSeconds * 1000);
} }
set deliver(value: number | null) { set deliver(value: number | null) {

View File

@ -1,33 +1,42 @@
<svg [attr.viewBox]="`0 0 ${widthPx} ${heightPx}`" [style.background-color]="'#eee'"> <svg [attr.viewBox]="`0 0 ${widthPx} ${heightPx+1}`" [style.background-color]="'#eee'">
@for (point of points; track point.epochSeconds) { @for (point of points; track point.epochSeconds) {
<rect <g>
[attr.x]="(point.epochSeconds - xMin) * xFactor" <title>
[attr.y]="heightPx - 1 + yMinPx - point.getPurchaseY(yFactor)" Bezug: {{ location.energyPurchase?.toValue(point.purchase, point.date)?.toValueString(null) }}
[attr.width]="xWidthPx" Solar: {{ location.energyProduce?.toValue(point.produce, point.date)?.toValueString(null) }}
[attr.height]="point.getPurchaseH(yFactor)" Selbst: {{ location.energyPurchase?.toValue(point.self, point.date)?.toValueString(null) }}
class="COLOR_BACK_PURCHASE" Einsp.: {{ location.energyDeliver?.toValue(point.deliver, point.date)?.toValueString(null) }}
></rect> Verbrauch: {{ location.energyPurchase?.toValue(point.consume, point.date)?.toValueString(null) }}
<rect </title>
[attr.x]="(point.epochSeconds - xMin) * xFactor" <rect
[attr.y]="heightPx - 1 + yMinPx - point.getSelfY(yFactor)" [attr.x]="(point.epochSeconds - xMin) * xFactor"
[attr.width]="xWidthPx" [attr.y]="heightPx + yMinPx - point.getPurchaseY(yFactor)"
[attr.height]="point.getSelfH(yFactor)" [attr.width]="xWidthPx"
class="COLOR_BACK_SELF" [attr.height]="point.getPurchaseH(yFactor)"
></rect> class="COLOR_BACK_PURCHASE"
<rect ></rect>
[attr.x]="(point.epochSeconds - xMin) * xFactor" <rect
[attr.y]="heightPx + yMinPx" [attr.x]="(point.epochSeconds - xMin) * xFactor"
[attr.width]="xWidthPx" [attr.y]="heightPx + yMinPx - point.getSelfY(yFactor)"
[attr.height]="point.getDeliverH(yFactor)" [attr.width]="xWidthPx"
class="COLOR_BACK_DELIVER" [attr.height]="point.getSelfH(yFactor)"
></rect> class="COLOR_BACK_SELF"
<line ></rect>
x1="0" <rect
[attr.y1]="heightPx - 1 + yMinPx" [attr.x]="(point.epochSeconds - xMin) * xFactor"
[attr.x2]="widthPx" [attr.y]="heightPx+1 + yMinPx"
[attr.y2]="heightPx - 1 + yMinPx" [attr.width]="xWidthPx"
stroke="#aaaaaa" [attr.height]="point.getDeliverH(yFactor)"
stroke-width="1" class="COLOR_BACK_DELIVER"
></line> ></rect>
</g>
} }
<line
x1="0"
[attr.y1]="heightPx +0.5 + yMinPx"
[attr.x2]="widthPx"
[attr.y2]="heightPx +0.5 + yMinPx"
stroke="#aaaaaa"
stroke-width="1"
></line>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1 +1,5 @@
@import "../../../../colors"; @import "../../../../colors";
g:hover {
stroke: black;
}

View File

@ -126,6 +126,10 @@ export class EnergyPlot implements OnInit, OnDestroy, AfterViewInit {
this.ngAfterViewInit(); this.ngAfterViewInit();
} }
get location(): Location {
return this._location;
}
@Input() @Input()
set interval(value: Interval) { set interval(value: Interval) {
this._interval = value; this._interval = value;

View File

@ -37,4 +37,11 @@ export class Series {
return this.id === other?.id; return this.id === other?.id;
} }
toValue(value: number | null | undefined, date: Date | null | undefined): Value {
if (value === null || value === undefined || date === null || date === undefined) {
return Value.NULL;
}
return Value.of(this, value, date);
}
} }