put y axis definition into its own object

This commit is contained in:
2020-02-08 15:39:41 +01:00
parent 6109227508
commit ed7cc9bee5
10 changed files with 96 additions and 72 deletions

View File

@@ -193,13 +193,11 @@ export class PlotRequest {
thumbnailMaxHeight : number = 200; thumbnailMaxHeight : number = 200;
groupBy : Array<string>; groupBy : Array<string>;
limitBy : string; limitBy : string;
axisScale : string;
limit : number; limit : number;
y1:YAxisDefinition;
y2:YAxisDefinition;
dateRange : string; dateRange : string;
aggregates : Array<string>; aggregates : Array<string>;
yRangeMin : number;
yRangeMax : number;
yRangeUnit : string;
keyOutside : boolean = false; keyOutside : boolean = false;
generateThumbnail : boolean; generateThumbnail : boolean;
@@ -208,6 +206,13 @@ export class PlotRequest {
} }
} }
export class YAxisDefinition {
axisScale : string;
yRangeMin : number;
yRangeMax : number;
yRangeUnit : string;
}
export class PlotResponse { export class PlotResponse {
imageUrl : string; imageUrl : string;
stats : PlotResponseStats; stats : PlotResponseStats;

View File

@@ -1,5 +1,5 @@
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import { PlotService, PlotType, PlotRequest, PlotResponse, TagField, FilterDefaults, DataType, AxesTypes } from '../plot.service'; import { PlotService, PlotType, PlotRequest, PlotResponse, TagField, FilterDefaults, DataType, YAxisDefinition, AxesTypes } from '../plot.service';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { FormControl, Validators } from '@angular/forms'; import { FormControl, Validators } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
@@ -139,6 +139,12 @@ export class VisualizationPageComponent implements OnInit {
const aggregates = []; const aggregates = [];
this.selectedPlotType.forEach(a => aggregates.push(a.id)); this.selectedPlotType.forEach(a => aggregates.push(a.id));
const y1 = new YAxisDefinition();
y1.axisScale = this.yAxisDefinitionComponent.yAxisScale;
y1.yRangeMin = this.yAxisDefinitionComponent.minYValue;
y1.yRangeMax = this.yAxisDefinitionComponent.maxYValue;
y1.yRangeUnit = this.yAxisDefinitionComponent.yAxisUnit;
const request = new PlotRequest(); const request = new PlotRequest();
request.query = this.query.query; request.query = this.query.query;
request.height = document.getElementById("results").offsetHeight-1; request.height = document.getElementById("results").offsetHeight-1;
@@ -146,14 +152,11 @@ export class VisualizationPageComponent implements OnInit {
request.groupBy = this.groupBy.map(o => o.name); request.groupBy = this.groupBy.map(o => o.name);
request.limitBy = this.limitbycomponent.limitBy; request.limitBy = this.limitbycomponent.limitBy;
request.limit = this.limitbycomponent.limit; request.limit = this.limitbycomponent.limit;
request.y1 = y1;
request.dateRange = this.dateRangeAsString(); request.dateRange = this.dateRangeAsString();
request.aggregates = aggregates; request.aggregates = aggregates;
request.keyOutside = false; request.keyOutside = false;
request.generateThumbnail = this.enableGallery; request.generateThumbnail = this.enableGallery;
request.axisScale = this.yAxisDefinitionComponent.yAxisScale;
request.yRangeMin = this.yAxisDefinitionComponent.minYValue;
request.yRangeMax = this.yAxisDefinitionComponent.maxYValue;
request.yRangeUnit = this.yAxisDefinitionComponent.yAxisUnit;
return request; return request;
} }

View File

@@ -38,7 +38,7 @@ public class PlotSettings {
private int yRangeMin; private int yRangeMin;
private int yRangeMax; private int yRangeMax;
private TimeRangeUnitInternal yRangeUnit = TimeRangeUnitInternal.AUTOMATIC; private TimeRangeUnit yRangeUnit = TimeRangeUnit.AUTOMATIC;
private boolean keyOutside; private boolean keyOutside;
@@ -186,11 +186,11 @@ public class PlotSettings {
this.yRangeMax = yRangeMax; this.yRangeMax = yRangeMax;
} }
public TimeRangeUnitInternal getYRangeUnit() { public TimeRangeUnit getYRangeUnit() {
return yRangeUnit; return yRangeUnit;
} }
public void setYRangeUnit(final TimeRangeUnitInternal yRangeUnit) { public void setYRangeUnit(final TimeRangeUnit yRangeUnit) {
this.yRangeUnit = yRangeUnit; this.yRangeUnit = yRangeUnit;
} }

View File

@@ -41,9 +41,9 @@ public class ScatterAggregator implements CustomAggregator {
plotAreaHeightInPx = plotSettings.getHeight() - GnuplotSettings.GNUPLOT_TOP_BOTTOM_MARGIN; plotAreaHeightInPx = plotSettings.getHeight() - GnuplotSettings.GNUPLOT_TOP_BOTTOM_MARGIN;
epochMillisPerPixel = Math.max(1, (toEpochMilli - fromEpochMilli) / plotAreaWidthInPx); epochMillisPerPixel = Math.max(1, (toEpochMilli - fromEpochMilli) / plotAreaWidthInPx);
minValue = plotSettings.getYRangeUnit() == TimeRangeUnitInternal.AUTOMATIC ? 0 minValue = plotSettings.getYRangeUnit() == TimeRangeUnit.AUTOMATIC ? 0
: plotSettings.getYRangeUnit().toMilliSeconds(plotSettings.getYRangeMin()); : plotSettings.getYRangeUnit().toMilliSeconds(plotSettings.getYRangeMin());
maxValue = plotSettings.getYRangeUnit() == TimeRangeUnitInternal.AUTOMATIC ? Long.MAX_VALUE maxValue = plotSettings.getYRangeUnit() == TimeRangeUnit.AUTOMATIC ? Long.MAX_VALUE
: plotSettings.getYRangeUnit().toMilliSeconds(plotSettings.getYRangeMax()); : plotSettings.getYRangeUnit().toMilliSeconds(plotSettings.getYRangeMax());
durationMillisPerPixel = plotSettings.getYAxisScale() == AxisScale.LINEAR durationMillisPerPixel = plotSettings.getYAxisScale() == AxisScale.LINEAR
? Math.max(1, (maxValue - minValue) / plotAreaHeightInPx) ? Math.max(1, (maxValue - minValue) / plotAreaHeightInPx)

View File

@@ -1,6 +1,6 @@
package org.lucares.pdb.plot.api; package org.lucares.pdb.plot.api;
public enum TimeRangeUnitInternal { public enum TimeRangeUnit {
AUTOMATIC, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS; AUTOMATIC, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS;
public int toMilliSeconds(final int value) { public int toMilliSeconds(final int value) {

View File

@@ -0,0 +1,41 @@
package org.lucares.pdb.plot.api;
public class YAxisDefinition {
private AxisScale yAxisScale = AxisScale.LINEAR;
private int yRangeMin = 0;
private int yRangeMax = 300;
private TimeRangeUnit yRangeUnit = TimeRangeUnit.AUTOMATIC;
public AxisScale getAxisScale() {
return yAxisScale;
}
public void setAxisScale(final AxisScale yAxis) {
this.yAxisScale = yAxis;
}
public int getyRangeMin() {
return yRangeMin;
}
public void setyRangeMin(final int yRangeMin) {
this.yRangeMin = yRangeMin;
}
public int getyRangeMax() {
return yRangeMax;
}
public void setyRangeMax(final int yRangeMax) {
this.yRangeMax = yRangeMax;
}
public TimeRangeUnit getyRangeUnit() {
return yRangeUnit;
}
public void setyRangeUnit(final TimeRangeUnit yRangeUnit) {
this.yRangeUnit = yRangeUnit;
}
}

View File

@@ -24,7 +24,7 @@ import org.lucares.pdb.api.Tags;
import org.lucares.pdb.plot.api.AggregatorCollection; import org.lucares.pdb.plot.api.AggregatorCollection;
import org.lucares.pdb.plot.api.Limit; import org.lucares.pdb.plot.api.Limit;
import org.lucares.pdb.plot.api.PlotSettings; import org.lucares.pdb.plot.api.PlotSettings;
import org.lucares.pdb.plot.api.TimeRangeUnitInternal; import org.lucares.pdb.plot.api.TimeRangeUnit;
import org.lucares.performance.db.PerformanceDb; import org.lucares.performance.db.PerformanceDb;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -149,9 +149,9 @@ public class Plotter {
} }
private void defineYRange(final GnuplotSettings gnuplotSettings, final int yRangeMin, final int yRangeMax, private void defineYRange(final GnuplotSettings gnuplotSettings, final int yRangeMin, final int yRangeMax,
final TimeRangeUnitInternal yRangeUnit) { final TimeRangeUnit yRangeUnit) {
if (yRangeUnit != TimeRangeUnitInternal.AUTOMATIC) { if (yRangeUnit != TimeRangeUnit.AUTOMATIC) {
final int min = yRangeUnit.toMilliSeconds(yRangeMin); final int min = yRangeUnit.toMilliSeconds(yRangeMin);
final int max = yRangeUnit.toMilliSeconds(yRangeMax); final int max = yRangeUnit.toMilliSeconds(yRangeMax);
gnuplotSettings.setYRange(min, max); gnuplotSettings.setYRange(min, max);
@@ -169,9 +169,9 @@ public class Plotter {
final long toEpochMilli = dateTo.toInstant().toEpochMilli(); final long toEpochMilli = dateTo.toInstant().toEpochMilli();
final boolean useMillis = (toEpochMilli - fromEpochMilli) < TimeUnit.MINUTES.toMillis(5); final boolean useMillis = (toEpochMilli - fromEpochMilli) < TimeUnit.MINUTES.toMillis(5);
final long minValue = plotSettings.getYRangeUnit() == TimeRangeUnitInternal.AUTOMATIC ? 0 final long minValue = plotSettings.getYRangeUnit() == TimeRangeUnit.AUTOMATIC ? 0
: plotSettings.getYRangeUnit().toMilliSeconds(plotSettings.getYRangeMin()); : plotSettings.getYRangeUnit().toMilliSeconds(plotSettings.getYRangeMin());
final long maxValue = plotSettings.getYRangeUnit() == TimeRangeUnitInternal.AUTOMATIC ? Long.MAX_VALUE final long maxValue = plotSettings.getYRangeUnit() == TimeRangeUnit.AUTOMATIC ? Long.MAX_VALUE
: plotSettings.getYRangeUnit().toMilliSeconds(plotSettings.getYRangeMax()); : plotSettings.getYRangeUnit().toMilliSeconds(plotSettings.getYRangeMax());
final AggregatorCollection aggregator = plotSettings.getAggregates().createCustomAggregator(tmpDir, final AggregatorCollection aggregator = plotSettings.getAggregates().createCustomAggregator(tmpDir,

View File

@@ -9,9 +9,8 @@ import org.lucares.pdb.plot.api.HistogramHandler;
import org.lucares.pdb.plot.api.ParallelRequestsAggregate; import org.lucares.pdb.plot.api.ParallelRequestsAggregate;
import org.lucares.pdb.plot.api.PlotSettings; import org.lucares.pdb.plot.api.PlotSettings;
import org.lucares.pdb.plot.api.ScatterAggregateHandler; import org.lucares.pdb.plot.api.ScatterAggregateHandler;
import org.lucares.pdb.plot.api.TimeRangeUnitInternal; import org.lucares.pdb.plot.api.TimeRangeUnit;
import org.lucares.pdbui.domain.PlotRequest; import org.lucares.pdbui.domain.PlotRequest;
import org.lucares.pdbui.domain.TimeRangeUnit;
class PlotSettingsTransformer { class PlotSettingsTransformer {
static PlotSettings toSettings(final PlotRequest request) { static PlotSettings toSettings(final PlotRequest request) {
@@ -25,40 +24,40 @@ class PlotSettingsTransformer {
result.setLimit(request.getLimit()); result.setLimit(request.getLimit());
result.setLimitBy(request.getLimitBy()); result.setLimitBy(request.getLimitBy());
result.setDateRange(request.getDateRange()); result.setDateRange(request.getDateRange());
result.setYAxisScale(request.getAxisScale()); result.setYAxisScale(request.getY1().getAxisScale());
result.setKeyOutside(request.isKeyOutside()); result.setKeyOutside(request.isKeyOutside());
result.setThumbnailMaxWidth(request.getThumbnailMaxWidth()); result.setThumbnailMaxWidth(request.getThumbnailMaxWidth());
result.setThumbnailMaxHeight(request.getThumbnailMaxHeight()); result.setThumbnailMaxHeight(request.getThumbnailMaxHeight());
result.setGenerateThumbnail(request.isGenerateThumbnail()); result.setGenerateThumbnail(request.isGenerateThumbnail());
result.setYRangeMin(request.getyRangeMin()); result.setYRangeMin(request.getY1().getyRangeMin());
result.setYRangeMax(request.getyRangeMax()); result.setYRangeMax(request.getY1().getyRangeMax());
result.setYRangeUnit(toTimeRangeUnitInternal(request.getyRangeUnit())); result.setYRangeUnit(toTimeRangeUnitInternal(request.getY1().getyRangeUnit()));
result.setAggregates( result.setAggregates(
toAggregateInternal(result.getYRangeUnit(), result.getYAxisScale(), request.getAggregates())); toAggregateInternal(result.getYRangeUnit(), result.getYAxisScale(), request.getAggregates()));
return result; return result;
} }
private static TimeRangeUnitInternal toTimeRangeUnitInternal(final TimeRangeUnit yRangeUnit) { private static TimeRangeUnit toTimeRangeUnitInternal(final TimeRangeUnit yRangeUnit) {
switch (yRangeUnit) { switch (yRangeUnit) {
case AUTOMATIC: case AUTOMATIC:
return TimeRangeUnitInternal.AUTOMATIC; return TimeRangeUnit.AUTOMATIC;
case MILLISECONDS: case MILLISECONDS:
return TimeRangeUnitInternal.MILLISECONDS; return TimeRangeUnit.MILLISECONDS;
case SECONDS: case SECONDS:
return TimeRangeUnitInternal.SECONDS; return TimeRangeUnit.SECONDS;
case MINUTES: case MINUTES:
return TimeRangeUnitInternal.MINUTES; return TimeRangeUnit.MINUTES;
case HOURS: case HOURS:
return TimeRangeUnitInternal.HOURS; return TimeRangeUnit.HOURS;
case DAYS: case DAYS:
return TimeRangeUnitInternal.DAYS; return TimeRangeUnit.DAYS;
} }
throw new IllegalStateException("unhandled enum value: " + yRangeUnit); throw new IllegalStateException("unhandled enum value: " + yRangeUnit);
} }
static AggregateHandlerCollection toAggregateInternal(final TimeRangeUnitInternal yRangeUnit, static AggregateHandlerCollection toAggregateInternal(final TimeRangeUnit yRangeUnit, final AxisScale yAxisScale,
final AxisScale yAxisScale, final Iterable<Aggregate> aggregates) { final Iterable<Aggregate> aggregates) {
final AggregateHandlerCollection aggregateHandlerCollection = new AggregateHandlerCollection(); final AggregateHandlerCollection aggregateHandlerCollection = new AggregateHandlerCollection();
for (final Aggregate aggregate : aggregates) { for (final Aggregate aggregate : aggregates) {
@@ -71,7 +70,7 @@ class PlotSettingsTransformer {
aggregateHandlerCollection.addAggregateHandler(new ParallelRequestsAggregate()); aggregateHandlerCollection.addAggregateHandler(new ParallelRequestsAggregate());
break; break;
case SCATTER: case SCATTER:
if (yRangeUnit == TimeRangeUnitInternal.AUTOMATIC && yAxisScale == AxisScale.LINEAR) { if (yRangeUnit == TimeRangeUnit.AUTOMATIC && yAxisScale == AxisScale.LINEAR) {
// TODO need a second ScatterAggregateHandler for YRangeUnit() == // TODO need a second ScatterAggregateHandler for YRangeUnit() ==
// TimeRangeUnitInternal.AUTOMATIC // TimeRangeUnitInternal.AUTOMATIC
throw new UnsupportedOperationException( throw new UnsupportedOperationException(

View File

@@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.lucares.pdb.plot.api.Aggregate; import org.lucares.pdb.plot.api.Aggregate;
import org.lucares.pdb.plot.api.AxisScale;
import org.lucares.pdb.plot.api.Limit; import org.lucares.pdb.plot.api.Limit;
import org.lucares.pdb.plot.api.YAxisDefinition;
public class PlotRequest { public class PlotRequest {
private String query; private String query;
@@ -22,18 +22,15 @@ public class PlotRequest {
private Limit limitBy = Limit.NO_LIMIT; private Limit limitBy = Limit.NO_LIMIT;
private AxisScale yAxisScale = AxisScale.LINEAR;
private int limit = Integer.MAX_VALUE; private int limit = Integer.MAX_VALUE;
private YAxisDefinition y1 = new YAxisDefinition();
private YAxisDefinition y2 = new YAxisDefinition();
private String dateRange; private String dateRange;
private List<Aggregate> aggregates = new ArrayList<>(); private List<Aggregate> aggregates = new ArrayList<>();
private int yRangeMin;
private int yRangeMax;
private TimeRangeUnit yRangeUnit = TimeRangeUnit.AUTOMATIC;
private boolean keyOutside; private boolean keyOutside;
private boolean generateThumbnail; private boolean generateThumbnail;
@@ -115,14 +112,6 @@ public class PlotRequest {
this.dateRange = dateRange; this.dateRange = dateRange;
} }
public AxisScale getAxisScale() {
return yAxisScale;
}
public void setAxisScale(final AxisScale yAxis) {
this.yAxisScale = yAxis;
}
public void setAggregate(final List<Aggregate> aggregates) { public void setAggregate(final List<Aggregate> aggregates) {
this.aggregates = aggregates; this.aggregates = aggregates;
} }
@@ -147,27 +136,19 @@ public class PlotRequest {
this.generateThumbnail = generateThumbnail; this.generateThumbnail = generateThumbnail;
} }
public int getyRangeMin() { public YAxisDefinition getY1() {
return yRangeMin; return y1;
} }
public void setyRangeMin(final int yRangeMin) { public void setY1(final YAxisDefinition y1) {
this.yRangeMin = yRangeMin; this.y1 = y1;
} }
public int getyRangeMax() { public YAxisDefinition getY2() {
return yRangeMax; return y2;
} }
public void setyRangeMax(final int yRangeMax) { public void setY2(final YAxisDefinition y2) {
this.yRangeMax = yRangeMax; this.y2 = y2;
}
public TimeRangeUnit getyRangeUnit() {
return yRangeUnit;
}
public void setyRangeUnit(final TimeRangeUnit yRangeUnit) {
this.yRangeUnit = yRangeUnit;
} }
} }

View File

@@ -1,5 +0,0 @@
package org.lucares.pdbui.domain;
public enum TimeRangeUnit {
AUTOMATIC, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS
}