range definitions for the y-axis
Sometimes it is useful to specify the certain y-axis range. For example when you are only interested in the values that take longer than a threshold. Or when you want to exclude some outliers. When you want to compare plots in a gallery, it is very handy when all plots have the same data-area.
This commit is contained in:
@@ -38,6 +38,10 @@ public class PlotSettings {
|
||||
|
||||
private AggregateHandler aggregate;
|
||||
|
||||
private int yRangeMin;
|
||||
private int yRangeMax;
|
||||
private TimeRangeUnitInternal yRangeUnit = TimeRangeUnitInternal.AUTOMATIC;
|
||||
|
||||
private boolean keyOutside;
|
||||
|
||||
private boolean generateThumbnail;
|
||||
@@ -183,7 +187,9 @@ public class PlotSettings {
|
||||
return "PlotSettings [query=" + query + ", height=" + height + ", width=" + width + ", thumbnailMaxWidth="
|
||||
+ thumbnailMaxWidth + ", thumbnailMaxHeight=" + thumbnailMaxHeight + ", groupBy=" + groupBy
|
||||
+ ", limitBy=" + limitBy + ", limit=" + limit + ", dateFrom=" + dateFrom + ", dateRange=" + dateRange
|
||||
+ ", yAxisScale=" + yAxisScale + ", aggregate=" + aggregate + ", keyOutside=" + keyOutside + "]";
|
||||
+ ", yAxisScale=" + yAxisScale + ", aggregate=" + aggregate + ", yRangeMin=" + yRangeMin
|
||||
+ ", yRangeMax=" + yRangeMax + ", yRangeUnit=" + yRangeUnit + ", keyOutside=" + keyOutside
|
||||
+ ", generateThumbnail=" + generateThumbnail + "]";
|
||||
}
|
||||
|
||||
public void setAggregate(final AggregateHandler aggregate) {
|
||||
@@ -209,4 +215,29 @@ public class PlotSettings {
|
||||
public boolean isGenerateThumbnail() {
|
||||
return generateThumbnail;
|
||||
}
|
||||
|
||||
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 TimeRangeUnitInternal getYRangeUnit() {
|
||||
return yRangeUnit;
|
||||
}
|
||||
|
||||
public void setYRangeUnit(final TimeRangeUnitInternal yRangeUnit) {
|
||||
this.yRangeUnit = yRangeUnit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.lucares.pdb.plot.api;
|
||||
|
||||
public enum TimeRangeUnitInternal {
|
||||
AUTOMATIC, MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS;
|
||||
|
||||
public int toMilliSeconds(final int value) {
|
||||
|
||||
switch (this) {
|
||||
case MILLISECONDS:
|
||||
return value;
|
||||
case SECONDS:
|
||||
return value * 1000;
|
||||
case MINUTES:
|
||||
return value * 60 * 1000;
|
||||
case HOURS:
|
||||
return value * 60 * 60 * 1000;
|
||||
case DAYS:
|
||||
return value * 24 * 60 * 60 * 1000;
|
||||
case AUTOMATIC:
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,14 @@ public class GnuplotFileGenerator {
|
||||
appendfln(result, "set xlabel \"%s\"", xAxis.getXlabel());
|
||||
appendfln(result, "set xrange [\"%s\":\"%s\"]", xAxis.getFrom(), xAxis.getTo());
|
||||
|
||||
final long graphOffset = settings.getYAxisScale() == AxisScale.LINEAR ? 0 : 1;
|
||||
appendfln(result, "set yrange [\"" + graphOffset + "\":]");
|
||||
final int graphOffset = settings.getYAxisScale() == AxisScale.LINEAR ? 0 : 1;
|
||||
if (settings.hasYRange()) {
|
||||
final int min = Math.max(settings.getYRangeMin(), graphOffset);
|
||||
final int max = settings.getYRangeMax();
|
||||
appendfln(result, String.format("set yrange [\"%d\":\"%d\"]", min, max));
|
||||
} else {
|
||||
appendfln(result, "set yrange [\"" + graphOffset + "\":]");
|
||||
}
|
||||
|
||||
appendfln(result, "set ylabel \"%s\"", settings.getYlabel());
|
||||
switch (settings.getYAxisScale()) {
|
||||
|
||||
@@ -26,6 +26,8 @@ public class GnuplotSettings {
|
||||
|
||||
private XAxisSettings xAxisSettings = new XAxisSettings();
|
||||
private boolean renderLabels = true;
|
||||
private int yRangeMin = -1;
|
||||
private int yRangeMax = -1;
|
||||
|
||||
public GnuplotSettings(final Path output) {
|
||||
this.output = output;
|
||||
@@ -123,6 +125,23 @@ public class GnuplotSettings {
|
||||
return renderLabels;
|
||||
}
|
||||
|
||||
public boolean hasYRange() {
|
||||
return yRangeMin >= 0 && yRangeMax >= 0 && yRangeMin < yRangeMax;
|
||||
}
|
||||
|
||||
public void setYRange(final int yRangeMin, final int yRangeMax) {
|
||||
this.yRangeMin = yRangeMin;
|
||||
this.yRangeMax = yRangeMax;
|
||||
}
|
||||
|
||||
public int getYRangeMin() {
|
||||
return yRangeMin;
|
||||
}
|
||||
|
||||
public int getYRangeMax() {
|
||||
return yRangeMax;
|
||||
}
|
||||
|
||||
// plot 'sample.txt' using 1:2 title 'Bytes' with linespoints 2
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.plot.api.CustomAggregator;
|
||||
import org.lucares.pdb.plot.api.Limit;
|
||||
import org.lucares.pdb.plot.api.PlotSettings;
|
||||
import org.lucares.pdb.plot.api.TimeRangeUnitInternal;
|
||||
import org.lucares.performance.db.PerformanceDb;
|
||||
import org.lucares.utils.file.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -120,6 +121,8 @@ public class ScatterPlot {
|
||||
|
||||
gnuplotSettings.setYAxisScale(plotSettings.getYAxisScale());
|
||||
gnuplotSettings.setAggregate(plotSettings.getAggregate());
|
||||
defineYRange(gnuplotSettings, plotSettings.getYRangeMin(), plotSettings.getYRangeMax(),
|
||||
plotSettings.getYRangeUnit());
|
||||
gnuplotSettings.setKeyOutside(plotSettings.isKeyOutside());
|
||||
gnuplot.plot(gnuplotSettings, dataSeries);
|
||||
}
|
||||
@@ -135,6 +138,8 @@ public class ScatterPlot {
|
||||
|
||||
gnuplotSettings.setYAxisScale(plotSettings.getYAxisScale());
|
||||
gnuplotSettings.setAggregate(plotSettings.getAggregate());
|
||||
defineYRange(gnuplotSettings, plotSettings.getYRangeMin(), plotSettings.getYRangeMax(),
|
||||
plotSettings.getYRangeUnit());
|
||||
gnuplotSettings.setKeyOutside(false);
|
||||
gnuplotSettings.renderLabels(false);
|
||||
gnuplot.plot(gnuplotSettings, dataSeries);
|
||||
@@ -154,6 +159,16 @@ public class ScatterPlot {
|
||||
}
|
||||
}
|
||||
|
||||
private void defineYRange(final GnuplotSettings gnuplotSettings, final int yRangeMin, final int yRangeMax,
|
||||
final TimeRangeUnitInternal yRangeUnit) {
|
||||
|
||||
if (yRangeUnit != TimeRangeUnitInternal.AUTOMATIC) {
|
||||
final int min = yRangeUnit.toMilliSeconds(yRangeMin);
|
||||
final int max = yRangeUnit.toMilliSeconds(yRangeMax);
|
||||
gnuplotSettings.setYRange(min, max);
|
||||
}
|
||||
}
|
||||
|
||||
private void defineXAxis(final GnuplotSettings gnuplotSettings, final OffsetDateTime minDate,
|
||||
final OffsetDateTime maxDate) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user