aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_elements/_charts/box-plot
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/app/_elements/_charts/box-plot')
-rw-r--r--frontend/src/app/_elements/_charts/box-plot/box-plot.component.css0
-rw-r--r--frontend/src/app/_elements/_charts/box-plot/box-plot.component.html3
-rw-r--r--frontend/src/app/_elements/_charts/box-plot/box-plot.component.spec.ts25
-rw-r--r--frontend/src/app/_elements/_charts/box-plot/box-plot.component.ts102
4 files changed, 130 insertions, 0 deletions
diff --git a/frontend/src/app/_elements/_charts/box-plot/box-plot.component.css b/frontend/src/app/_elements/_charts/box-plot/box-plot.component.css
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/frontend/src/app/_elements/_charts/box-plot/box-plot.component.css
diff --git a/frontend/src/app/_elements/_charts/box-plot/box-plot.component.html b/frontend/src/app/_elements/_charts/box-plot/box-plot.component.html
new file mode 100644
index 00000000..688eafae
--- /dev/null
+++ b/frontend/src/app/_elements/_charts/box-plot/box-plot.component.html
@@ -0,0 +1,3 @@
+<div class="chart-wrapper">
+ <canvas #boxplot [width]="width" [height]="height"></canvas>
+</div> \ No newline at end of file
diff --git a/frontend/src/app/_elements/_charts/box-plot/box-plot.component.spec.ts b/frontend/src/app/_elements/_charts/box-plot/box-plot.component.spec.ts
new file mode 100644
index 00000000..759e7c5e
--- /dev/null
+++ b/frontend/src/app/_elements/_charts/box-plot/box-plot.component.spec.ts
@@ -0,0 +1,25 @@
+import { ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { BoxPlotComponent } from './box-plot.component';
+
+describe('BoxPlotComponent', () => {
+ let component: BoxPlotComponent;
+ let fixture: ComponentFixture<BoxPlotComponent>;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ declarations: [ BoxPlotComponent ]
+ })
+ .compileComponents();
+ });
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(BoxPlotComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/frontend/src/app/_elements/_charts/box-plot/box-plot.component.ts b/frontend/src/app/_elements/_charts/box-plot/box-plot.component.ts
new file mode 100644
index 00000000..3faa4794
--- /dev/null
+++ b/frontend/src/app/_elements/_charts/box-plot/box-plot.component.ts
@@ -0,0 +1,102 @@
+import { AfterViewInit, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
+import { Chart, LinearScale, CategoryScale } from 'chart.js';
+import { BoxPlotController, BoxAndWiskers } from '@sgratzl/chartjs-chart-boxplot';
+
+function randomValues(count: number, min: number, max: number) {
+ const delta = max - min;
+ return Array.from({ length: count }).map(() => Math.random() * delta + min);
+}
+
+Chart.register(BoxPlotController, BoxAndWiskers, LinearScale, CategoryScale);
+
+@Component({
+ selector: 'app-box-plot',
+ templateUrl: './box-plot.component.html',
+ styleUrls: ['./box-plot.component.css']
+})
+export class BoxPlotComponent implements AfterViewInit {
+
+ @Input()width?: number;
+ @Input()height?: number;
+
+ @ViewChild('boxplot') chartRef!: ElementRef;
+ constructor() { }
+
+ boxplotData = {
+ // define label tree
+ labels: ['January'/*, 'February', 'March', 'April', 'May', 'June', 'July'*/],
+ datasets: [{
+ label: 'Dataset 1',
+ backgroundColor: 'rgba(0, 65, 101, 1.0)',
+ borderColor: '#0063AB',
+ borderWidth: 1,
+ outlierColor: '#999999',
+ scaleFontColor: '#0063AB',
+ padding: 10,
+ itemRadius: 0,
+ data: [
+ randomValues(100, 0, 100),
+ /*randomValues(100, 0, 20),
+ randomValues(100, 20, 70),
+ randomValues(100, 60, 100),
+ randomValues(40, 50, 100),
+ randomValues(100, 60, 120),
+ randomValues(100, 80, 100)*/
+ ]}/*, {
+ label: 'Dataset 2',
+ backgroundColor: 'rgba(0,0,255,0.5)',
+ borderColor: 'blue',
+ borderWidth: 1,
+ outlierColor: '#999999',
+ padding: 10,
+ itemRadius: 0,
+ data: [
+ randomValues(100, 60, 100),
+ randomValues(100, 0, 100),
+ randomValues(100, 0, 20),
+ randomValues(100, 20, 70),
+ randomValues(40, 60, 120),
+ randomValues(100, 20, 100),
+ randomValues(100, 80, 100)
+ ]
+ }*/]
+ };
+ ngAfterViewInit(): void {
+ const myChart = new Chart(this.chartRef.nativeElement, {
+ type: "boxplot",
+ data: this.boxplotData,
+ options: {
+ /*title: {
+ display: true,
+ text: 'Predicted world population (millions) in 2050'
+ }*/
+ plugins:{
+ legend: {
+ display: false
+ },
+ },
+ scales : {
+ x: {
+ ticks: {
+ color: 'rgba(0, 65, 101, 1.0)'
+ },
+ grid: {
+ color: "rgba(0, 99, 171, 0.5)"
+ }
+ },
+ y : {
+ min: -50,
+ max: 200,
+ ticks: {
+ color: 'rgba(0, 65, 101, 1.0)'
+ },
+ grid: {
+ color: "rgba(0, 99, 171, 0.5)"
+ }
+ }
+ }
+ }
+ });
+}
+
+}