plot exactly the selected time frame

Before gnuplot would only plot the range with values.
But that is not really helpful, when you navigate with the new
navigation buttons.
This commit is contained in:
2017-04-22 11:23:13 +02:00
parent c783fd2830
commit c2ee632f76
3 changed files with 36 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ public class GnuplotFileGenerator {
appendfln(result, "set format x \"%s\"", settings.getFormatX());
appendfln(result, "set xlabel \"%s\"", settings.getXlabel());
appendfln(result, "set xtics rotate by %d", settings.getRotateXAxisLabel());
appendfln(result, "set xrange [\"%s\":\"%s\"]", settings.getDateFrom(), settings.getDateTo());
appendfln(result, "set ylabel \"%s\"", settings.getYlabel());
if (settings.getYAxisScale() == AxisScale.LOG10) {

View File

@@ -28,6 +28,8 @@ public class GnuplotSettings {
// set xtics rotate by 10 degree
private int rotateXAxisLabel = -10;
private AxisScale yAxisScale;
private String dateFrom;
private String dateTo;
public GnuplotSettings(final Path output) {
this.output = output;
@@ -117,6 +119,22 @@ public class GnuplotSettings {
return yAxisScale;
}
public void setDateFrom(final String dateFrom) {
this.dateFrom = dateFrom;
}
public String getDateFrom() {
return dateFrom;
}
public void setDateTo(final String dateTo) {
this.dateTo = dateTo;
}
public String getDateTo() {
return dateTo;
}
// plot 'sample.txt' using 1:2 title 'Bytes' with linespoints 2
}

View File

@@ -9,9 +9,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
@@ -78,8 +76,12 @@ public class Plotter {
final Result result = db.get(query, groupBy);
OffsetDateTime maxDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MIN_VALUE), ZoneOffset.UTC);
OffsetDateTime minDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE), ZoneOffset.UTC);
// OffsetDateTime maxDate =
// OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MIN_VALUE),
// ZoneOffset.UTC);
// OffsetDateTime minDate =
// OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.MAX_VALUE),
// ZoneOffset.UTC);
for (final GroupResult groupResult : result.getGroups()) {
@@ -93,8 +95,10 @@ public class Plotter {
if (dataSerie.getValues() > 0) {
dataSeries.add(dataSerie);
maxDate = maxDate.compareTo(csvSummary.getMaxDate()) > 0 ? maxDate : csvSummary.getMaxDate();
minDate = minDate.compareTo(csvSummary.getMinDate()) < 0 ? minDate : csvSummary.getMinDate();
// maxDate = maxDate.compareTo(csvSummary.getMaxDate()) > 0
// ? maxDate : csvSummary.getMaxDate();
// minDate = minDate.compareTo(csvSummary.getMinDate()) < 0
// ? minDate : csvSummary.getMinDate();
}
}
@@ -109,7 +113,7 @@ public class Plotter {
final GnuplotSettings gnuplotSettings = new GnuplotSettings(outputFile);
gnuplotSettings.setHeight(height);
gnuplotSettings.setWidth(width);
defineXAxis(gnuplotSettings, minDate, maxDate);
defineXAxis(gnuplotSettings, plotSettings.dateFrom(), plotSettings.dateTo());
gnuplotSettings.setYAxisScale(plotSettings.getYAxisScale());
gnuplot.plot(gnuplotSettings, dataSeries);
@@ -131,6 +135,8 @@ public class Plotter {
String formatX;
int rotateX;
String formattedMinDate;
String formattedMaxDate;
if (minDate.until(maxDate, ChronoUnit.WEEKS) > 1) {
formatX = "%Y-%m-%d";
rotateX = 0;
@@ -139,9 +145,13 @@ public class Plotter {
formatX = "%Y-%m-%d %H:%M:%S";
rotateX = gnuplotSettings.getRotateXAxisLabel();
}
formattedMinDate = minDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
formattedMaxDate = maxDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"));
gnuplotSettings.setFormatX(formatX);
gnuplotSettings.setRotateXAxisLabel(rotateX);
gnuplotSettings.setDateFrom(formattedMinDate);
gnuplotSettings.setDateTo(formattedMaxDate);
}
private String uniqueDirectoryName() {