Skip to content

Commit

Permalink
Merge pull request #47 from harald78/develop
Browse files Browse the repository at this point in the history
Corrected chart service
  • Loading branch information
harald78 authored Jun 24, 2024
2 parents 85838d5 + 1d94ba5 commit d6dc6f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/app/features/dashboard/service/chart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {SensorMeasurementHistory} from "../model/measurementHistory.model";
import {UnitPipe} from "../../../shared/pipes/unit.pipe";
import { DateTimeUtil } from '../../../shared/util/date.util';
import { ReferenceLine } from '../model/chart.models';
import {parse} from "@angular-eslint/template-parser";

@Injectable({
providedIn: 'root'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import {
inject,
input,
InputSignal,
OnInit,
signal,
WritableSignal
Signal,
computed
} from '@angular/core';
import {Color, colorSets, LegendPosition, NgxChartsModule, ScaleType} from '@swimlane/ngx-charts';
import {Color, colorSets, LegendPosition, NgxChartsModule} from '@swimlane/ngx-charts';
import {SensorMeasurementHistory} from '../../../model/measurementHistory.model';
import {ChartService} from '../../../service/chart.service';
import {UnitPipe} from "../../../../../shared/pipes/unit.pipe";
Expand All @@ -23,7 +22,7 @@ import {ReferenceLine} from '../../../model/chart.models';
styleUrl: './chart.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ChartComponent implements OnInit {
export class ChartComponent {

private readonly chartService: ChartService = inject(ChartService);
public formatYAxisTickFn = this.formatYAxisTick.bind(this);
Expand All @@ -37,28 +36,16 @@ export class ChartComponent implements OnInit {
showLegend = true;
showXAxisLabel = false;
showYAxisLabel = false;
yScaleMin: WritableSignal<number> = signal(0);
yScaleMax: WritableSignal<number> = signal(40);
yScaleMin: Signal<number> = computed(() => this.chartService.calculateYScaleMin(this.chartData()));
yScaleMax: Signal<number> = computed(() => this.chartService.calculateYScaleMax(this.chartData()));
roundDomains = true;
autoScale = false;
legendPosition: LegendPosition = LegendPosition.Below;
colorScheme: Color = colorSets.find(s => s.name === 'forest')!;
referenceLines: WritableSignal<ReferenceLine[]> = signal([]);
referenceLines: Signal<ReferenceLine[]> = computed(() => this.chartService.calculateReferenceLines(this.chartData()));

dataToggle = input(false);

ngOnInit() {
this.prepareChartData();
}

prepareChartData() {
if (this.chartData()) {
this.yScaleMax.set(this.chartService.calculateYScaleMax(this.chartData()));
this.yScaleMin.set(this.chartService.calculateYScaleMin(this.chartData()));
this.referenceLines.set(this.chartService.calculateReferenceLines(this.chartData()));
}
}

formatYAxisTick(value: number): string {
return this.chartService.formatYAxisTick(value, this.chartData()[0].type, this.dataToggle());
}
Expand Down

0 comments on commit d6dc6f5

Please sign in to comment.