Skip to content

Commit

Permalink
Merge pull request #42 from REDDERD/ApiIntegration
Browse files Browse the repository at this point in the history
Api integration
  • Loading branch information
david-2031 authored Sep 28, 2023
2 parents 6032986 + 3eed8e1 commit 2df639c
Show file tree
Hide file tree
Showing 14 changed files with 865 additions and 11,661 deletions.
14 changes: 12 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ import { LoginComponent } from './login/login.component';
import { RouterModule, Routes } from '@angular/router'
import {MatInputModule} from "@angular/material/input";
import {ReactiveFormsModule} from "@angular/forms";
import {HttpClient, HttpClientModule} from "@angular/common/http";
import {HttpClientModule} from "@angular/common/http";
import {MatSnackBarModule} from "@angular/material/snack-bar";
import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
import {MatSelectModule} from "@angular/material/select";
import {MatButtonToggleModule} from "@angular/material/button-toggle";
import {MatExpansionModule} from "@angular/material/expansion";
import {MatSlideToggleModule} from "@angular/material/slide-toggle";

const routes: Routes = [ { path: 'home', component: HomeComponent },
{ path: '', redirectTo: '/home', pathMatch: 'full' },
Expand All @@ -39,7 +44,12 @@ const routes: Routes = [ { path: 'home', component: HomeComponent },
MatInputModule,
ReactiveFormsModule,
HttpClientModule,
MatSnackBarModule
MatSnackBarModule,
MatProgressSpinnerModule,
MatSelectModule,
MatButtonToggleModule,
MatExpansionModule,
MatSlideToggleModule
],
providers: [],
bootstrap: [AppComponent]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<app-chart></app-chart>
<app-chart [apiResponse]="apiResponse"></app-chart>
4 changes: 3 additions & 1 deletion src/app/home/chart-container/chart-container.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Component } from '@angular/core';
import {Component, Input} from '@angular/core';
import {ResponseInterface} from "../../interfaces/response-interface";

@Component({
selector: 'app-chart-container',
templateUrl: './chart-container.component.html',
styleUrls: ['./chart-container.component.css']
})
export class ChartContainerComponent {
@Input() apiResponse: ResponseInterface | undefined;
}
26 changes: 19 additions & 7 deletions src/app/home/chart-container/chart/chart.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {AfterViewInit, Component} from '@angular/core';
import {AfterViewInit, Component, Input, OnChanges, SimpleChanges} from '@angular/core';
import {Chart} from "chart.js/auto";
import {Points, ResponseInterface} from "../../../interfaces/response-interface";
import {CentroidDatesetInterface, ChartDatasetInterface} from "../../../interfaces/chartDataset-interface";
Expand All @@ -9,19 +9,31 @@ import {MockDaten} from "./mock-daten";
templateUrl: './chart.component.html',
styleUrls: ['./chart.component.css']
})
export class ChartComponent implements AfterViewInit{
export class ChartComponent implements AfterViewInit, OnChanges{
public chart: any;
MockData: ResponseInterface = MockDaten
chartData: ResponseInterface = MockDaten
datasets: Array<ChartDatasetInterface> = [];
@Input() apiResponse: ResponseInterface | undefined;

ngAfterViewInit() {
this.renderChart();
}

ngOnChanges(changes: SimpleChanges) {
if (changes['apiResponse'].currentValue != undefined){
if(this.apiResponse){
this.datasets = [];
this.chartData = this.apiResponse;
}
this.chart.destroy()
this.renderChart()
}
}

generateDatasets() {
let centroids: Array<Points> = [];
let clusterArray: Array<ChartDatasetInterface> = [];
this.MockData.cluster.map(cluster => {
this.chartData.cluster.map(cluster => {
let dataset: ChartDatasetInterface = {
label: "Cluster " + (cluster.clusterNr + 1),
data: cluster.points
Expand Down Expand Up @@ -63,20 +75,20 @@ export class ChartComponent implements AfterViewInit{
plugins: {
title: {
display: true,
text: MockDaten.name
text: this.chartData.name
},
},
scales: {
y: {
title: {
display: true,
text: MockDaten.y_label
text: this.chartData.y_label
}
},
x: {
title: {
display: true,
text: MockDaten.x_label
text: this.chartData.x_label
}
}
}
Expand Down
Loading

0 comments on commit 2df639c

Please sign in to comment.