Skip to content

Commit

Permalink
item chart settings (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Apr 3, 2021
1 parent 1c90dd0 commit 33d7360
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/app/_services/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { observable, Observable, BehaviorSubject } from 'rxjs';
import { Observable, BehaviorSubject } from 'rxjs';
import { Users } from './users.model';

@Injectable({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

@Component({
selector: 'app-add-metric',
templateUrl: './add-metric.component.html',
styleUrls: ['./add-metric.component.scss']
})
export class AddMetricComponent implements OnInit {
export class AddMetricComponent implements OnInit, OnChanges {

@Input() chartLines;
@Input() preloadedSeries;
@Output() chartUpdate = new EventEmitter<{}>();

overallChartLines;
Expand Down Expand Up @@ -54,12 +55,22 @@ export class AddMetricComponent implements OnInit {
}
}
this.chartUpdate.emit(checked);


this.modalService.dismissAll();

}



ngOnChanges(changes) {
// update checkboxes with pre-loaded settings
if (changes.preloadedSeries) {
const preloadedSeries = changes.preloadedSeries.currentValue;
if (!Array.isArray(preloadedSeries)) {
return;
}
preloadedSeries.forEach(_ => {
if (this.metrics[_.metric]) {
const item = this.metrics[_.metric].find(__ => __.name === _.name);
item.isChecked = true;
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h6 class="card-header bg-transparent">
<span class="float-right">
<div display="dynamic" [placement]="['bottom-right', 'bottom-left']" class="btn-group" ngbDropdown role="group"
aria-label="">
<app-add-metric [chartLines]="chartLines" (chartUpdate)="chartUpdated($event)"></app-add-metric>
<app-add-metric [chartLines]="chartLines" [preloadedSeries]="preloadedSeries" (chartUpdate)="chartUpdated($event)"></app-add-metric>
</div>
</span>
</h6>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
Expand All @@ -16,7 +17,8 @@ describe('AnalyzeChartsComponent', () => {
imports: [
HighchartsChartModule,
NgbModule,
FormsModule
FormsModule,
HttpClientModule
]
})
.compileComponents();
Expand All @@ -26,6 +28,7 @@ describe('AnalyzeChartsComponent', () => {
fixture = TestBed.createComponent(AnalyzeChartsComponent);
component = fixture.componentInstance;
component.chartLines = { labels: new Map([['test', [{ name: 'test', data: []}]]]), overall: new Map() };
component.params = { projectName: 'test', scenarioName: 'test', id: 'id' };
fixture.detectChanges();
});

Expand Down
36 changes: 31 additions & 5 deletions src/app/item-detail/analyze-charts/analyze-charts.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, Input, OnInit } from '@angular/core';
import { customChartSettings } from 'src/app/graphs/item-detail';
import * as Highcharts from 'highcharts';
import { ItemsApiService } from 'src/app/items-api.service';
import { Observable } from 'rxjs';

@Component({
selector: 'app-analyze-charts',
Expand All @@ -9,6 +11,7 @@ import * as Highcharts from 'highcharts';
})
export class AnalyzeChartsComponent implements OnInit {

@Input() params: { projectName: string, scenarioName: string, id: string };
@Input() chartLines: ChartLines;
Highcharts: typeof Highcharts = Highcharts;
customChartsOptions = {
Expand All @@ -23,24 +26,40 @@ export class AnalyzeChartsComponent implements OnInit {
['Error Rate', 3],
['Network', 4]
]);
preloadedSeries;

constructor() {
constructor(
private itemApiService: ItemsApiService
) {
}

ngOnInit() {
this.itemApiService
.fetchItemChartSettings(this.params.projectName, this.params.scenarioName, this.params.id)
.subscribe(_ => {
this.updateChart(_);
this.preloadedSeries = _;
});
}

chartUpdated(event: [{ name: string, metric: string }]) {
const chartSeries: Line[] = [];
this.updateChart(event);
this.saveChartSettings(event);
}

event.forEach(_ => {
private updateChart(series) {
const chartSeries: Line[] = [];
if (!Array.isArray(series)) {
return;
}
series.forEach(_ => {
const { name, metric } = _;
const yAxis = this.yAxisId.get(metric.includes('Response Time') ? 'Response Time' : metric);
if (name === 'overall') {
const metricLine = this.chartLines.overall.get(metric);
const line: Line = {
...metricLine,
id: name,
id: `${metric}: ${name}`,
yAxis
};
chartSeries.push(line);
Expand All @@ -59,6 +78,13 @@ export class AnalyzeChartsComponent implements OnInit {
this.customChartsOptions.series = JSON.parse(JSON.stringify(chartSeries));
this.updateLabelChartFlag = true;
}

private saveChartSettings(event) {
this.itemApiService.upsertItemChartSettings(
this.params.projectName,
this.params.scenarioName,
this.params.id, event).subscribe(_ => _);
}
}

interface Line {
Expand All @@ -70,5 +96,5 @@ interface Line {

interface ChartLines {
labels: Map<string, [{ data: [], name: string }]>;
overall: Map<string, { name: string, data: []}>;
overall: Map<string, { name: string, data: [] }>;
}
2 changes: 1 addition & 1 deletion src/app/item-detail/item-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ <h6 class="card-header bg-transparent">Overall Chart</h6>
<ng-template ngbNavContent>
<div class="row chart-fix charts">
<div class="col">
<app-analyze-charts [chartLines]="chartLines"></app-analyze-charts>
<app-analyze-charts [chartLines]="chartLines" [params]="itemParams"></app-analyze-charts>
</div>
</div>

Expand Down
11 changes: 10 additions & 1 deletion src/app/items-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';
import { Observable, BehaviorSubject } from 'rxjs';
import { ItemDetail, Items } from './items.service.model';
import { ItemDetail, Items, UpsertItemChartSettings } from './items.service.model';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -94,4 +94,13 @@ export class ItemsApiService {
return this.http.delete<{}>(`projects/${projectName}/scenarios/${scenarioName}/items/${itemId}/share-tokens/${id}`,
{ observe: 'response' });
}

upsertItemChartSettings(projectName, scenarioName, itemId, body: UpsertItemChartSettings) {
return this.http.post(`projects/${projectName}/scenarios/${scenarioName}/items/${itemId}/custom-chart-settings`,
body, { observe: 'response' });
}

fetchItemChartSettings(projectName, scenarioName, itemId) {
return this.http.get(`projects/${projectName}/scenarios/${scenarioName}/items/${itemId}/custom-chart-settings`);
}
}
6 changes: 6 additions & 0 deletions src/app/items.service.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,9 @@ export interface ScenarioNotifications {
type: string;
}

export interface UpsertItemChartSettings {
series: [{
name: string;
data: [number, number];
}];
}

0 comments on commit 33d7360

Please sign in to comment.