add logarithmic scaling for the y-axis
Often we have a few very high values and a lot low values. With a linearly scaled y-axis the plot is mostly useless.
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
package org.lucares.pdb.plot.api;
|
||||||
|
|
||||||
|
public enum AxisScale {
|
||||||
|
LINEAR, LOG10, LOG2
|
||||||
|
}
|
||||||
@@ -30,6 +30,8 @@ public class PlotSettings {
|
|||||||
|
|
||||||
private String dateRange;
|
private String dateRange;
|
||||||
|
|
||||||
|
private AxisScale yAxisScale;
|
||||||
|
|
||||||
public String getQuery() {
|
public String getQuery() {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
@@ -142,11 +144,18 @@ public class PlotSettings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setYAxisScale(final AxisScale axisScale) {
|
||||||
|
this.yAxisScale = axisScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AxisScale getYAxisScale() {
|
||||||
|
return yAxisScale;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PlotSettings [query=" + query + ", height=" + height + ", width=" + width + ", groupBy=" + groupBy
|
return "PlotSettings [query=" + query + ", height=" + height + ", width=" + width + ", groupBy=" + groupBy
|
||||||
+ ", limitBy=" + limitBy + ", limit=" + limit + ", dateFrom=" + dateFrom + ", dateRange=" + dateRange
|
+ ", limitBy=" + limitBy + ", limit=" + limit + ", dateFrom=" + dateFrom + ", dateRange=" + dateRange
|
||||||
+ "]";
|
+ ", axisScale=" + yAxisScale + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package org.lucares.recommind.logs;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.lucares.pdb.plot.api.AxisScale;
|
||||||
|
|
||||||
public class GnuplotFileGenerator {
|
public class GnuplotFileGenerator {
|
||||||
|
|
||||||
public String generate(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
public String generate(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||||
@@ -20,6 +22,11 @@ public class GnuplotFileGenerator {
|
|||||||
appendfln(result, "set xtics rotate by %d", settings.getRotateXAxisLabel());
|
appendfln(result, "set xtics rotate by %d", settings.getRotateXAxisLabel());
|
||||||
|
|
||||||
appendfln(result, "set ylabel \"%s\"", settings.getYlabel());
|
appendfln(result, "set ylabel \"%s\"", settings.getYlabel());
|
||||||
|
if (settings.getYAxisScale() == AxisScale.LOG10) {
|
||||||
|
appendfln(result, "set logscale y");
|
||||||
|
} else if (settings.getYAxisScale() == AxisScale.LOG2) {
|
||||||
|
appendfln(result, "set logscale y 2");
|
||||||
|
}
|
||||||
|
|
||||||
appendfln(result, "set output \"%s\"", settings.getOutput().toAbsolutePath().toString().replace("\\", "/"));
|
appendfln(result, "set output \"%s\"", settings.getOutput().toAbsolutePath().toString().replace("\\", "/"));
|
||||||
appendf(result, "plot ");
|
appendf(result, "plot ");
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package org.lucares.recommind.logs;
|
|||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import org.lucares.pdb.plot.api.AxisScale;
|
||||||
|
|
||||||
public class GnuplotSettings {
|
public class GnuplotSettings {
|
||||||
private String terminal = "png";
|
private String terminal = "png";
|
||||||
private int height = 1200;
|
private int height = 1200;
|
||||||
@@ -25,6 +27,7 @@ public class GnuplotSettings {
|
|||||||
|
|
||||||
// set xtics rotate by 80
|
// set xtics rotate by 80
|
||||||
private int rotateXAxisLabel = -80;
|
private int rotateXAxisLabel = -80;
|
||||||
|
private AxisScale yAxisScale;
|
||||||
|
|
||||||
public GnuplotSettings(final Path output) {
|
public GnuplotSettings(final Path output) {
|
||||||
this.output = output;
|
this.output = output;
|
||||||
@@ -106,6 +109,14 @@ public class GnuplotSettings {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setYAxisScale(final AxisScale yAxisScale) {
|
||||||
|
this.yAxisScale = yAxisScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AxisScale getYAxisScale() {
|
||||||
|
return yAxisScale;
|
||||||
|
}
|
||||||
|
|
||||||
// plot 'sample.txt' using 1:2 title 'Bytes' with linespoints 2
|
// plot 'sample.txt' using 1:2 title 'Bytes' with linespoints 2
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ public class Plotter {
|
|||||||
gnuplotSettings.setHeight(height);
|
gnuplotSettings.setHeight(height);
|
||||||
gnuplotSettings.setWidth(width);
|
gnuplotSettings.setWidth(width);
|
||||||
gnuplotSettings.setFormatX(getFormatX(minDate, maxDate));
|
gnuplotSettings.setFormatX(getFormatX(minDate, maxDate));
|
||||||
|
gnuplotSettings.setYAxisScale(plotSettings.getYAxisScale());
|
||||||
gnuplot.plot(gnuplotSettings, dataSeries);
|
gnuplot.plot(gnuplotSettings, dataSeries);
|
||||||
|
|
||||||
return new PlotResult(outputFile.getFileName(), dataSeries);
|
return new PlotResult(outputFile.getFileName(), dataSeries);
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package org.lucares.pdbui;
|
package org.lucares.pdbui;
|
||||||
|
|
||||||
|
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.PlotSettings;
|
import org.lucares.pdb.plot.api.PlotSettings;
|
||||||
import org.lucares.pdbui.domain.LimitBy;
|
import org.lucares.pdbui.domain.LimitBy;
|
||||||
import org.lucares.pdbui.domain.PlotRequest;
|
import org.lucares.pdbui.domain.PlotRequest;
|
||||||
|
import org.lucares.pdbui.domain.YAxis;
|
||||||
|
|
||||||
class PlotSettingsTransformer {
|
class PlotSettingsTransformer {
|
||||||
static PlotSettings toSettings(final PlotRequest request) {
|
static PlotSettings toSettings(final PlotRequest request) {
|
||||||
@@ -18,10 +20,24 @@ class PlotSettingsTransformer {
|
|||||||
result.setLimitBy(toLimit(request.getLimitBy()));
|
result.setLimitBy(toLimit(request.getLimitBy()));
|
||||||
result.setDateFrom(request.getDateFrom());
|
result.setDateFrom(request.getDateFrom());
|
||||||
result.setDateRange(request.getDateRange());
|
result.setDateRange(request.getDateRange());
|
||||||
|
result.setYAxisScale(toAxisScale(request.getAxisScale()));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static AxisScale toAxisScale(final YAxis yAxis) {
|
||||||
|
switch (yAxis) {
|
||||||
|
case LINEAR:
|
||||||
|
return AxisScale.LINEAR;
|
||||||
|
case LOG10:
|
||||||
|
return AxisScale.LOG10;
|
||||||
|
case LOG2:
|
||||||
|
return AxisScale.LOG2;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("unhandled enum: " + yAxis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Limit toLimit(final LimitBy limitBy) {
|
private static Limit toLimit(final LimitBy limitBy) {
|
||||||
switch (limitBy) {
|
switch (limitBy) {
|
||||||
case NO_LIMIT:
|
case NO_LIMIT:
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public class PlotRequest {
|
|||||||
|
|
||||||
private LimitBy limitBy = LimitBy.NO_LIMIT;
|
private LimitBy limitBy = LimitBy.NO_LIMIT;
|
||||||
|
|
||||||
|
private YAxis yAxis = YAxis.LINEAR;
|
||||||
|
|
||||||
private int limit = Integer.MAX_VALUE;
|
private int limit = Integer.MAX_VALUE;
|
||||||
|
|
||||||
private String dateFrom;
|
private String dateFrom;
|
||||||
@@ -91,4 +93,11 @@ public class PlotRequest {
|
|||||||
this.dateRange = dateRange;
|
this.dateRange = dateRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public YAxis getAxisScale() {
|
||||||
|
return yAxis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAxisScale(final YAxis yAxis) {
|
||||||
|
this.yAxis = yAxis;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
pdb-ui/src/main/java/org/lucares/pdbui/domain/YAxis.java
Normal file
5
pdb-ui/src/main/java/org/lucares/pdbui/domain/YAxis.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package org.lucares.pdbui.domain;
|
||||||
|
|
||||||
|
public enum YAxis {
|
||||||
|
LINEAR, LOG10, LOG2
|
||||||
|
}
|
||||||
@@ -96,6 +96,7 @@ function plot(event){
|
|||||||
request['limit'] = parseInt($('#search-limit-value').val());
|
request['limit'] = parseInt($('#search-limit-value').val());
|
||||||
request['dateFrom'] = $('#search-date-from').val();
|
request['dateFrom'] = $('#search-date-from').val();
|
||||||
request['dateRange'] = $('#search-date-range').val();
|
request['dateRange'] = $('#search-date-range').val();
|
||||||
|
request['axisScale'] = $('#search-y-axis-scale').val();
|
||||||
|
|
||||||
|
|
||||||
var success = function(response){
|
var success = function(response){
|
||||||
|
|||||||
@@ -46,6 +46,13 @@
|
|||||||
<option value="1 month">
|
<option value="1 month">
|
||||||
</datalist>
|
</datalist>
|
||||||
|
|
||||||
|
<label for="search-y-axis-scale">y-axis:</label>
|
||||||
|
<select id="search-y-axis-scale">
|
||||||
|
<option value="LINEAR" selected="selected">linear</option>
|
||||||
|
<option value="LOG10">log 10</option>
|
||||||
|
<option value="LOG2">log 2</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
<button id="search-submit"><i class="fa fa-area-chart"> Plot</i></button>
|
<button id="search-submit"><i class="fa fa-area-chart"> Plot</i></button>
|
||||||
</div>
|
</div>
|
||||||
<div id="result-view">
|
<div id="result-view">
|
||||||
|
|||||||
Reference in New Issue
Block a user