-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from computas/SP24-787-stats
Sp24 787 stats
- Loading branch information
Showing
24 changed files
with
750 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,4 @@ export class ErrorLogDialogComponent { | |
|
||
logs = this.data | ||
|
||
closeDialog(): void { | ||
this.dialogRef.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="chart-container"> | ||
@if (render) { | ||
<canvasjs-chart [options]="chartOptions" [ngStyle]="{'width': '100%', 'height': '400px'}"></canvasjs-chart> | ||
} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.chart-container { | ||
justify-content: center; /* Center horizontally */ | ||
align-items: center; /* Center vertically */ | ||
margin: 20px 0; /* Add some vertical margin */ | ||
width: 100%; /* Full width */ | ||
display: flex; | ||
height: 500px; | ||
} | ||
|
||
.canvasjs-chart { | ||
width: 90%; /* Default to 60% width */ | ||
height: 100px; /* Set height */ | ||
position: relative; | ||
} | ||
|
||
@media (max-width: 768px) { | ||
.canvasjs-chart { | ||
width: 90%; /* Increase width on smaller screens */ | ||
} | ||
} | ||
|
||
.canvasjs-chart>canvas:first-of-type { position: relative !important; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { AfterViewInit, Component, ElementRef, Input, OnChanges, OnDestroy, Renderer2 } from '@angular/core'; | ||
import { CanvasJSAngularChartsModule } from '@canvasjs/angular-charts'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
import { endpoints } from '@/app/shared/models/endpoints'; | ||
import { RouterOutlet } from '@angular/router'; | ||
import { CommonModule } from '@angular/common'; | ||
|
||
interface DataPoint { | ||
x: Date; | ||
y: number; | ||
} | ||
|
||
type ScoresPerMonthResponse = Record<string, number>; | ||
|
||
@Component({ | ||
selector: 'app-graph-component', | ||
standalone: true, | ||
imports: [RouterOutlet, CommonModule, CanvasJSAngularChartsModule], | ||
templateUrl: './graph.component.html', | ||
styleUrls: ['./graph.component.scss'], | ||
}) | ||
export class GraphComponent implements OnChanges, OnDestroy, AfterViewInit { | ||
@Input() year = ''; | ||
dataList: Record<string, number> = {}; | ||
render = false; | ||
chartOptions = { | ||
animationEnabled: true, | ||
theme: "light2", | ||
title: { | ||
text: "Statistikk for året " | ||
}, | ||
axisX: { | ||
valueFormatString: "MMM", | ||
intervalType: "month", | ||
interval: 1 | ||
}, | ||
axisY: { | ||
title: "Antall spilte spill", | ||
suffix: "" | ||
}, | ||
toolTip: { | ||
shared: true | ||
}, | ||
legend: { | ||
cursor: "pointer", | ||
itemclick: function (e: { dataSeries: { visible: boolean; }; }) { | ||
e.dataSeries.visible = typeof e.dataSeries.visible === "undefined" || e.dataSeries.visible ? false : true; | ||
} | ||
}, | ||
data: [{ | ||
type: "line", | ||
name: "Antall spill", | ||
showInLegend: true, | ||
dataPoints: [] as DataPoint[] | ||
}] | ||
}; | ||
|
||
constructor(private http: HttpClient, private el: ElementRef, private renderer: Renderer2) {} | ||
|
||
ngOnChanges() { | ||
if (this.year) { | ||
this.getDataList().subscribe({ | ||
next: (res) => { | ||
this.dataList = res; | ||
this.updateChartData(); | ||
this.render = true; | ||
}, | ||
error: (err) => { | ||
console.error('Failed to get data from backend', err); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
updateChartData() { | ||
const dataPoints: DataPoint[] = Object.entries(this.dataList).map(([month, scoreCount]) => ({ | ||
x: new Date(+this.year, Number(month) - 1, 1), | ||
y: Number(scoreCount) | ||
})); | ||
|
||
this.chartOptions.data[0].dataPoints = dataPoints; | ||
this.chartOptions.title.text += this.year; | ||
|
||
|
||
} | ||
|
||
getDataList(): Observable<ScoresPerMonthResponse> { | ||
return this.http.get<ScoresPerMonthResponse>( | ||
`${endpoints.TEKNISKBACKEND}/${endpoints.ADMIN}/${endpoints.GETSCORESPERMONTH}?year=${this.year}`, | ||
{ | ||
withCredentials: true, | ||
} | ||
); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
this.render = false; | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
const canvasChart = this.el.nativeElement.querySelector('canvasjs-chart'); | ||
if (canvasChart) { | ||
this.renderer.setStyle(canvasChart, 'width', '100%'); | ||
this.renderer.setStyle(canvasChart, 'height', '400px'); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,3 +112,4 @@ br { | |
p + p { | ||
margin-top: 0.5rem; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- Month/Year Selection Section --> | ||
<div class="year-selection-container"> | ||
<h2>Velg måned og år</h2> | ||
<mat-form-field> | ||
<mat-label>Måned og år</mat-label> | ||
<input matInput [matDatepicker]="dp" [formControl]="date"> | ||
<mat-hint>MM/YYYY</mat-hint> | ||
<mat-datepicker-toggle matIconSuffix [for]="dp"></mat-datepicker-toggle> | ||
<mat-datepicker #dp startView="multi-year" (monthSelected)="setMonthAndYear($event, dp)" | ||
panelClass="month-picker"> | ||
</mat-datepicker> | ||
</mat-form-field> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.example-picker .mat-calendar-period-button { | ||
pointer-events: none; | ||
} | ||
|
||
.example-picker .mat-calendar-arrow { | ||
display: none; | ||
} | ||
|
||
mat-form-field { | ||
width: 100%; | ||
max-width: 300px; | ||
margin: 0 auto; | ||
} | ||
|
||
.form-section { | ||
width: 100%; | ||
margin-bottom: 20px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} |
Oops, something went wrong.