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:
2018-05-01 10:18:06 +02:00
parent 54ee23459d
commit 6d85c56cb0
10 changed files with 180 additions and 28 deletions

View File

@@ -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()) {

View File

@@ -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
}

View File

@@ -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) {