make defaults for groupBy configurable

We do not know which fields exist at compile time.
But it is a great help to have some pre-selected
fields in groupBy.
Solved by adding a configuration option.
This commit is contained in:
2019-11-10 09:38:16 +01:00
parent c83d0a3e1e
commit 198b51089d
5 changed files with 78 additions and 29 deletions

View File

@@ -9,18 +9,10 @@ import { Observable } from 'rxjs/Observable';
export class PlotService {
plotTypes: Array<PlotType>;
tagFields: Array<TagField>;
constructor(private http: HttpClient) {
this.plotTypes = new Array<PlotType>();
this.plotTypes.push(new PlotType(
"SCATTER",
"Scatter",
"scatter-chart2",
true,
DataType.Time,
DataType.Duration));
this.plotTypes.push(new PlotType("SCATTER","Scatter","scatter-chart2",true,DataType.Time,DataType.Duration));
this.plotTypes.push(new PlotType("HEATMAP", "Heatmap", "heatmap", false, DataType.Other, DataType.Other));
this.plotTypes.push(new PlotType("CONTOUR", "Contour", "contour-chart", false, DataType.Time, DataType.Duration));
this.plotTypes.push(new PlotType("CUM_DISTRIBUTION", "Cumulative Distribution", "cumulative-distribution-chart", true, DataType.Percent, DataType.Duration));
@@ -33,8 +25,6 @@ export class PlotService {
this.plotTypes.push(new PlotType("PIE", "Pie", "pie-chart", false, DataType.Other, DataType.Other));
this.plotTypes.push(new PlotType("BAR", "Bar", "bar-chart", false, DataType.Other, DataType.Other));
this.plotTypes.push(new PlotType("STEP_FIT", "Step Fit", "step-fit", false, DataType.Other, DataType.Other));
this.tagFields = new Array<TagField>();
}
ngOnInit() {
@@ -45,16 +35,8 @@ export class PlotService {
return this.plotTypes.filter(plotType => plotType.active);
}
getTagFields(): Array<TagField> {
const that = this;
this.http.get('//'+window.location.hostname+':8080/fields').subscribe(data => {
if (data instanceof Array){
data.forEach(function(name) {
that.tagFields.push(new TagField(name));
});
}
});
return this.tagFields;
getTagFields(): Observable<Array<string>> {
return this.http.get<Array<string>>('//'+window.location.hostname+':8080/fields');
}
autocomplete(query: string, caretIndex: number): Observable<AutocompleteResult>
@@ -72,6 +54,10 @@ export class PlotService {
console.log("send plot request: "+ JSON.stringify(plotRequest));
return this.http.post<PlotResponse>('//'+window.location.hostname+':8080/plots', plotRequest);
}
getFilterDefaults(): Observable<FilterDefaults>{
return this.http.get<FilterDefaults>('//'+window.location.hostname+':8080/filters/defaults')
}
}
@@ -181,3 +167,7 @@ export class DataSeriesStats {
plottedValues : number;
}
export class FilterDefaults {
groupBy: Array<string>;
fields: Array<string>;
}

View File

@@ -1,11 +1,11 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { PlotService, PlotType, PlotRequest, PlotResponse } from '../plot.service';
import { PlotService, PlotType, PlotRequest, PlotResponse, TagField, FilterDefaults } from '../plot.service';
import { Observable } from 'rxjs/Observable';
import { FormControl, Validators } from '@angular/forms';
import { LimitByComponent } from '../limit-by/limit-by.component';
import { YAxisRangeComponent } from '../y-axis-range/y-axis-range.component';
import { QueryAutocompleteComponent } from '../query-autocomplete/query-autocomplete.component';
import {PlotViewComponent, SelectionRange, DateAnchor } from '../plot-view/plot-view.component'
import {PlotViewComponent, SelectionRange, DateAnchor} from '../plot-view/plot-view.component'
import * as moment from 'moment';
@Component({
@@ -27,9 +27,9 @@ export class VisualizationPageComponent implements OnInit {
selectedCombinePlotType = new FormControl('');
combinePlotTypes: Array<any>;
tagFields: Array<any>;
tagFields: Array<TagField> = new Array<TagField>();
groupBy: Array<any> = [];
groupBy = new Array<TagField>();
@ViewChild(LimitByComponent, {static: false})
private limitbycomponent : LimitByComponent;
@@ -62,7 +62,14 @@ export class VisualizationPageComponent implements OnInit {
this.combinePlotTypes = this.getCombinablePlotTypes(this.selectedPlotType.value);
this.tagFields = this.plotService.getTagFields();
that.plotService.getFilterDefaults().subscribe(function(filterDefaults) {
filterDefaults.fields.forEach(function(name) {
that.tagFields.push(new TagField(name));
});
that.groupBy = that.tagFields.filter(val => filterDefaults.groupBy.includes(val.name));
});
this.yAxisScale = "LOG10";
this.selectedPlotType.valueChanges.subscribe(function(selectedMainPlotType){