From ed7cc9bee53973a9edec2f2cef57be2f32968271 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sat, 8 Feb 2020 15:39:41 +0100 Subject: [PATCH] put y axis definition into its own object --- pdb-js/src/app/plot.service.ts | 13 ++++-- .../visualization-page.component.ts | 13 +++--- .../lucares/pdb/plot/api/PlotSettings.java | 6 +-- .../pdb/plot/api/ScatterAggregator.java | 4 +- ...geUnitInternal.java => TimeRangeUnit.java} | 2 +- .../lucares/pdb/plot/api/YAxisDefinition.java | 41 ++++++++++++++++++ .../org/lucares/recommind/logs/Plotter.java | 10 ++--- .../pdbui/PlotSettingsTransformer.java | 31 +++++++------ .../org/lucares/pdbui/domain/PlotRequest.java | 43 ++++++------------- .../lucares/pdbui/domain/TimeRangeUnit.java | 5 --- 10 files changed, 96 insertions(+), 72 deletions(-) rename pdb-plotting/src/main/java/org/lucares/pdb/plot/api/{TimeRangeUnitInternal.java => TimeRangeUnit.java} (94%) create mode 100644 pdb-plotting/src/main/java/org/lucares/pdb/plot/api/YAxisDefinition.java delete mode 100644 pdb-ui/src/main/java/org/lucares/pdbui/domain/TimeRangeUnit.java diff --git a/pdb-js/src/app/plot.service.ts b/pdb-js/src/app/plot.service.ts index bd7cb03..2816fc2 100644 --- a/pdb-js/src/app/plot.service.ts +++ b/pdb-js/src/app/plot.service.ts @@ -193,13 +193,11 @@ export class PlotRequest { thumbnailMaxHeight : number = 200; groupBy : Array; limitBy : string; - axisScale : string; limit : number; + y1:YAxisDefinition; + y2:YAxisDefinition; dateRange : string; aggregates : Array; - yRangeMin : number; - yRangeMax : number; - yRangeUnit : string; keyOutside : boolean = false; generateThumbnail : boolean; @@ -208,6 +206,13 @@ export class PlotRequest { } } +export class YAxisDefinition { + axisScale : string; + yRangeMin : number; + yRangeMax : number; + yRangeUnit : string; +} + export class PlotResponse { imageUrl : string; stats : PlotResponseStats; diff --git a/pdb-js/src/app/visualization-page/visualization-page.component.ts b/pdb-js/src/app/visualization-page/visualization-page.component.ts index 5e2d635..bf158b0 100644 --- a/pdb-js/src/app/visualization-page/visualization-page.component.ts +++ b/pdb-js/src/app/visualization-page/visualization-page.component.ts @@ -1,5 +1,5 @@ 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 { FormControl, Validators } from '@angular/forms'; import { MatSnackBar } from '@angular/material/snack-bar'; @@ -139,6 +139,12 @@ export class VisualizationPageComponent implements OnInit { const aggregates = []; 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(); request.query = this.query.query; 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.limitBy = this.limitbycomponent.limitBy; request.limit = this.limitbycomponent.limit; + request.y1 = y1; request.dateRange = this.dateRangeAsString(); request.aggregates = aggregates; request.keyOutside = false; 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; } diff --git a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java index 764ce52..f8625fe 100644 --- a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java +++ b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/PlotSettings.java @@ -38,7 +38,7 @@ public class PlotSettings { private int yRangeMin; private int yRangeMax; - private TimeRangeUnitInternal yRangeUnit = TimeRangeUnitInternal.AUTOMATIC; + private TimeRangeUnit yRangeUnit = TimeRangeUnit.AUTOMATIC; private boolean keyOutside; @@ -186,11 +186,11 @@ public class PlotSettings { this.yRangeMax = yRangeMax; } - public TimeRangeUnitInternal getYRangeUnit() { + public TimeRangeUnit getYRangeUnit() { return yRangeUnit; } - public void setYRangeUnit(final TimeRangeUnitInternal yRangeUnit) { + public void setYRangeUnit(final TimeRangeUnit yRangeUnit) { this.yRangeUnit = yRangeUnit; } diff --git a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/ScatterAggregator.java b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/ScatterAggregator.java index aa5434d..a7fa227 100644 --- a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/ScatterAggregator.java +++ b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/ScatterAggregator.java @@ -41,9 +41,9 @@ public class ScatterAggregator implements CustomAggregator { plotAreaHeightInPx = plotSettings.getHeight() - GnuplotSettings.GNUPLOT_TOP_BOTTOM_MARGIN; epochMillisPerPixel = Math.max(1, (toEpochMilli - fromEpochMilli) / plotAreaWidthInPx); - minValue = plotSettings.getYRangeUnit() == TimeRangeUnitInternal.AUTOMATIC ? 0 + minValue = plotSettings.getYRangeUnit() == TimeRangeUnit.AUTOMATIC ? 0 : 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()); durationMillisPerPixel = plotSettings.getYAxisScale() == AxisScale.LINEAR ? Math.max(1, (maxValue - minValue) / plotAreaHeightInPx) diff --git a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/TimeRangeUnitInternal.java b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/TimeRangeUnit.java similarity index 94% rename from pdb-plotting/src/main/java/org/lucares/pdb/plot/api/TimeRangeUnitInternal.java rename to pdb-plotting/src/main/java/org/lucares/pdb/plot/api/TimeRangeUnit.java index 3f4ba61..7c4e6c2 100644 --- a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/TimeRangeUnitInternal.java +++ b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/TimeRangeUnit.java @@ -1,6 +1,6 @@ package org.lucares.pdb.plot.api; -public enum TimeRangeUnitInternal { +public enum TimeRangeUnit { AUTOMATIC, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS; public int toMilliSeconds(final int value) { diff --git a/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/YAxisDefinition.java b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/YAxisDefinition.java new file mode 100644 index 0000000..041a756 --- /dev/null +++ b/pdb-plotting/src/main/java/org/lucares/pdb/plot/api/YAxisDefinition.java @@ -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; + } +} diff --git a/pdb-plotting/src/main/java/org/lucares/recommind/logs/Plotter.java b/pdb-plotting/src/main/java/org/lucares/recommind/logs/Plotter.java index 78843d1..09e1dce 100644 --- a/pdb-plotting/src/main/java/org/lucares/recommind/logs/Plotter.java +++ b/pdb-plotting/src/main/java/org/lucares/recommind/logs/Plotter.java @@ -24,7 +24,7 @@ import org.lucares.pdb.api.Tags; import org.lucares.pdb.plot.api.AggregatorCollection; import org.lucares.pdb.plot.api.Limit; 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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -149,9 +149,9 @@ public class Plotter { } 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 max = yRangeUnit.toMilliSeconds(yRangeMax); gnuplotSettings.setYRange(min, max); @@ -169,9 +169,9 @@ public class Plotter { final long toEpochMilli = dateTo.toInstant().toEpochMilli(); 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()); - 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()); final AggregatorCollection aggregator = plotSettings.getAggregates().createCustomAggregator(tmpDir, diff --git a/pdb-ui/src/main/java/org/lucares/pdbui/PlotSettingsTransformer.java b/pdb-ui/src/main/java/org/lucares/pdbui/PlotSettingsTransformer.java index 7f94640..a95cfd2 100644 --- a/pdb-ui/src/main/java/org/lucares/pdbui/PlotSettingsTransformer.java +++ b/pdb-ui/src/main/java/org/lucares/pdbui/PlotSettingsTransformer.java @@ -9,9 +9,8 @@ import org.lucares.pdb.plot.api.HistogramHandler; import org.lucares.pdb.plot.api.ParallelRequestsAggregate; import org.lucares.pdb.plot.api.PlotSettings; 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.TimeRangeUnit; class PlotSettingsTransformer { static PlotSettings toSettings(final PlotRequest request) { @@ -25,40 +24,40 @@ class PlotSettingsTransformer { result.setLimit(request.getLimit()); result.setLimitBy(request.getLimitBy()); result.setDateRange(request.getDateRange()); - result.setYAxisScale(request.getAxisScale()); + result.setYAxisScale(request.getY1().getAxisScale()); result.setKeyOutside(request.isKeyOutside()); result.setThumbnailMaxWidth(request.getThumbnailMaxWidth()); result.setThumbnailMaxHeight(request.getThumbnailMaxHeight()); result.setGenerateThumbnail(request.isGenerateThumbnail()); - result.setYRangeMin(request.getyRangeMin()); - result.setYRangeMax(request.getyRangeMax()); - result.setYRangeUnit(toTimeRangeUnitInternal(request.getyRangeUnit())); + result.setYRangeMin(request.getY1().getyRangeMin()); + result.setYRangeMax(request.getY1().getyRangeMax()); + result.setYRangeUnit(toTimeRangeUnitInternal(request.getY1().getyRangeUnit())); result.setAggregates( toAggregateInternal(result.getYRangeUnit(), result.getYAxisScale(), request.getAggregates())); return result; } - private static TimeRangeUnitInternal toTimeRangeUnitInternal(final TimeRangeUnit yRangeUnit) { + private static TimeRangeUnit toTimeRangeUnitInternal(final TimeRangeUnit yRangeUnit) { switch (yRangeUnit) { case AUTOMATIC: - return TimeRangeUnitInternal.AUTOMATIC; + return TimeRangeUnit.AUTOMATIC; case MILLISECONDS: - return TimeRangeUnitInternal.MILLISECONDS; + return TimeRangeUnit.MILLISECONDS; case SECONDS: - return TimeRangeUnitInternal.SECONDS; + return TimeRangeUnit.SECONDS; case MINUTES: - return TimeRangeUnitInternal.MINUTES; + return TimeRangeUnit.MINUTES; case HOURS: - return TimeRangeUnitInternal.HOURS; + return TimeRangeUnit.HOURS; case DAYS: - return TimeRangeUnitInternal.DAYS; + return TimeRangeUnit.DAYS; } throw new IllegalStateException("unhandled enum value: " + yRangeUnit); } - static AggregateHandlerCollection toAggregateInternal(final TimeRangeUnitInternal yRangeUnit, - final AxisScale yAxisScale, final Iterable aggregates) { + static AggregateHandlerCollection toAggregateInternal(final TimeRangeUnit yRangeUnit, final AxisScale yAxisScale, + final Iterable aggregates) { final AggregateHandlerCollection aggregateHandlerCollection = new AggregateHandlerCollection(); for (final Aggregate aggregate : aggregates) { @@ -71,7 +70,7 @@ class PlotSettingsTransformer { aggregateHandlerCollection.addAggregateHandler(new ParallelRequestsAggregate()); break; case SCATTER: - if (yRangeUnit == TimeRangeUnitInternal.AUTOMATIC && yAxisScale == AxisScale.LINEAR) { + if (yRangeUnit == TimeRangeUnit.AUTOMATIC && yAxisScale == AxisScale.LINEAR) { // TODO need a second ScatterAggregateHandler for YRangeUnit() == // TimeRangeUnitInternal.AUTOMATIC throw new UnsupportedOperationException( diff --git a/pdb-ui/src/main/java/org/lucares/pdbui/domain/PlotRequest.java b/pdb-ui/src/main/java/org/lucares/pdbui/domain/PlotRequest.java index 7ee1bb6..f2eca45 100644 --- a/pdb-ui/src/main/java/org/lucares/pdbui/domain/PlotRequest.java +++ b/pdb-ui/src/main/java/org/lucares/pdbui/domain/PlotRequest.java @@ -4,8 +4,8 @@ import java.util.ArrayList; import java.util.List; 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.YAxisDefinition; public class PlotRequest { private String query; @@ -22,18 +22,15 @@ public class PlotRequest { private Limit limitBy = Limit.NO_LIMIT; - private AxisScale yAxisScale = AxisScale.LINEAR; - private int limit = Integer.MAX_VALUE; + private YAxisDefinition y1 = new YAxisDefinition(); + private YAxisDefinition y2 = new YAxisDefinition(); + private String dateRange; private List aggregates = new ArrayList<>(); - private int yRangeMin; - private int yRangeMax; - private TimeRangeUnit yRangeUnit = TimeRangeUnit.AUTOMATIC; - private boolean keyOutside; private boolean generateThumbnail; @@ -115,14 +112,6 @@ public class PlotRequest { this.dateRange = dateRange; } - public AxisScale getAxisScale() { - return yAxisScale; - } - - public void setAxisScale(final AxisScale yAxis) { - this.yAxisScale = yAxis; - } - public void setAggregate(final List aggregates) { this.aggregates = aggregates; } @@ -147,27 +136,19 @@ public class PlotRequest { this.generateThumbnail = generateThumbnail; } - public int getyRangeMin() { - return yRangeMin; + public YAxisDefinition getY1() { + return y1; } - public void setyRangeMin(final int yRangeMin) { - this.yRangeMin = yRangeMin; + public void setY1(final YAxisDefinition y1) { + this.y1 = y1; } - public int getyRangeMax() { - return yRangeMax; + public YAxisDefinition getY2() { + return y2; } - public void setyRangeMax(final int yRangeMax) { - this.yRangeMax = yRangeMax; - } - - public TimeRangeUnit getyRangeUnit() { - return yRangeUnit; - } - - public void setyRangeUnit(final TimeRangeUnit yRangeUnit) { - this.yRangeUnit = yRangeUnit; + public void setY2(final YAxisDefinition y2) { + this.y2 = y2; } } diff --git a/pdb-ui/src/main/java/org/lucares/pdbui/domain/TimeRangeUnit.java b/pdb-ui/src/main/java/org/lucares/pdbui/domain/TimeRangeUnit.java deleted file mode 100644 index e9785ec..0000000 --- a/pdb-ui/src/main/java/org/lucares/pdbui/domain/TimeRangeUnit.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.lucares.pdbui.domain; - -public enum TimeRangeUnit { - AUTOMATIC, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS -}