draw points and percentile lines with the same color

This commit is contained in:
2018-01-21 14:09:34 +01:00
parent bb7701e7c4
commit b4a0514267
11 changed files with 485 additions and 327 deletions

View File

@@ -28,9 +28,18 @@ public class PercentileAggregate implements AggregateHandler{
for (DataSeries dataSerie : dataSeries) {
final AggregatedData aggregatedData = dataSerie.getAggregatedData();
if (aggregatedData != null){
appendfln(result, "'%s' using 1:2 title '%s' with lines lw 1 axes x2y1, \\", //
aggregatedData.getDataFile().getAbsolutePath(),//
dataSerie.getTitle()+" " +aggregatedData.getLabel());
appendfln(
result,
"'%s' using 1:2 notitle with lines axes x2y1 lw 2 %s, \\", //
aggregatedData.getDataFile().getAbsolutePath(),//
dataSerie.getStyle()//
);
// appendfln(result, "'%s' using 1:2 title '%s' with lines axes x2y1 %s, \\", //
// aggregatedData.getDataFile().getAbsolutePath(),//
// dataSerie.getTitle()+" " +aggregatedData.getLabel(), // title
// dataSerie.getStyle()//
// );
}
}
}

View File

@@ -0,0 +1,19 @@
package org.lucares.recommind.logs;
import java.util.Arrays;
import java.util.List;
public class DashTypes {
public static final List<String> DEFAULT = Arrays.asList(
"1",//
"2",//
"3",//
"4",//
"6",//
"\".\"",//
"\"-\"",//
"\"._\"",//
"\"..- \"",//
"\"(50,6,2,6)\""//
);
}

View File

@@ -19,11 +19,16 @@ public interface DataSeries {
return result < 0 ? -1 : (result > 0 ? 1 : 0);
};
public String getId();
public String getIdAsString();
public int getId();
public String getTitle();
public int getValues();
public long getMaxValue();
public void setStyle(String style);
public String getStyle();
public AggregatedData getAggregatedData();
@@ -74,5 +79,28 @@ public interface DataSeries {
case NO_LIMIT:
}
}
static void setColors(List<DataSeries> dataSeries){
int i = 0;
for (DataSeries dataSerie : dataSeries) {
final int numColors = GnuplotColorPalettes.DEFAULT.size();
final int numDashTypes = DashTypes.DEFAULT.size();
final String color = GnuplotColorPalettes.DEFAULT.get(i % numColors).getColor();
final String dashType = DashTypes.DEFAULT.get((i/numColors) % numDashTypes);
String style = String.format("lt %s dt %s ",//
color,//
dashType//
);
dataSerie.setStyle(style);
i++;
}
}
}

View File

@@ -10,21 +10,39 @@ public class FileBackedDataSeries implements DataSeries {
private CsvSummary csvSummary;
private String id;
private int id;
private GnuplotLineType linetype;
public FileBackedDataSeries(String id, String title, CsvSummary csvSummary, GnuplotLineType linetype) {
private String style;
public FileBackedDataSeries(int id, String title, CsvSummary csvSummary,
GnuplotLineType linetype) {
this.id = id;
this.title = title;
this.csvSummary = csvSummary;
this.linetype = linetype;
}
public String getId() {
public String getIdAsString() {
return "id" + id;
}
@Override
public int getId() {
return id;
}
@Override
public void setStyle(String style) {
this.style = style;
}
@Override
public String getStyle() {
return style;
}
public File getDataFile() {
return csvSummary.getDataFile();
}
@@ -40,13 +58,18 @@ public class FileBackedDataSeries implements DataSeries {
public long getMaxValue() {
return csvSummary.getMaxValue();
}
public AggregatedData getAggregatedData() {
return csvSummary.getAggregatedData();
}
@Override
public String getGnuplotPlotDefinition() {
return String.format("'%s' using 1:2 title '%s' with %s, \\", getDataFile(),
getTitle(), linetype);
return String.format("'%s' using 1:2 title '%s' with %s %s, \\", //
getDataFile(),//
getTitle(),//
linetype, // line or points
style//
);
}
}

View File

@@ -1,296 +1,26 @@
package org.lucares.recommind.logs;
public enum GnuplotColor {
ALICEBLUE("aliceblue"),
ANTIQUEWHITE("antiquewhite"),
AQUA("aqua"),
AQUAMARINE("aquamarine"),
AZURE("azure"),
BEIGE("beige"),
BISQUE("bisque"),
BLACK("black"),
BLANCHEDALMOND("blanchedalmond"),
BLUE("blue"),
BLUEVIOLET("blueviolet"),
BROWN("brown"),
BURLYWOOD("burlywood"),
CADETBLUE("cadetblue"),
CHARTREUSE("chartreuse"),
CHOCOLATE("chocolate"),
CORAL("coral"),
CORNFLOWERBLUE("cornflowerblue"),
CORNSILK("cornsilk"),
CRIMSON("crimson"),
CYAN("cyan"),
DARKBLUE("darkblue"),
DARKCYAN("darkcyan"),
DARKGOLDENROD("darkgoldenrod"),
DARKGRAY("darkgray"),
DARKGREEN("darkgreen"),
DARKKHAKI("darkkhaki"),
DARKMAGENTA("darkmagenta"),
DARKOLIVEGREEN("darkolivegreen"),
DARKORANGE("darkorange"),
DARKORCHID("darkorchid"),
DARKRED("darkred"),
DARKSALMON("darksalmon"),
DARKSEAGREEN("darkseagreen"),
DARKSLATEBLUE("darkslateblue"),
DARKSLATEGRAY("darkslategray"),
DARKTURQUOISE("darkturquoise"),
DARKVIOLET("darkviolet"),
DEEPPINK("deeppink"),
DEEPSKYBLUE("deepskyblue"),
DIMGRAY("dimgray"),
DODGERBLUE("dodgerblue"),
FIREBRICK("firebrick"),
FLORALWHITE("floralwhite"),
FORESTGREEN("forestgreen"),
FUCHSIA("fuchsia"),
GAINSBORO("gainsboro"),
GHOSTWHITE("ghostwhite"),
GOLD("gold"),
GOLDENROD("goldenrod"),
GRAY("gray"),
GREEN("green"),
GREENYELLOW("greenyellow"),
HONEYDEW("honeydew"),
HOTPINK("hotpink"),
INDIANRED("indianred"),
INDIGO("indigo"),
IVORY("ivory"),
KHAKI("khaki"),
LAVENDER("lavender"),
LAVENDERBLUSH("lavenderblush"),
LAWNGREEN("lawngreen"),
LEMONCHIFFON("lemonchiffon"),
LIGHTBLUE("lightblue"),
LIGHTCORAL("lightcoral"),
LIGHTCYAN("lightcyan"),
LIGHTGOLDENRODYE("lightgoldenrodye"),
LIGHTGREEN("lightgreen"),
LIGHTGREY("lightgrey"),
LIGHTPINK("lightpink"),
LIGHTSALMON("lightsalmon"),
LIGHTSEAGREEN("lightseagreen"),
LIGHTSKYBLUE("lightskyblue"),
LIGHTSLATEGRAY("lightslategray"),
LIGHTSTEELBLUE("lightsteelblue"),
LIGHTYELLOW("lightyellow"),
LIME("lime"),
LIMEGREEN("limegreen"),
LINEN("linen"),
MAGENTA("magenta"),
MAROON("maroon"),
MEDIUMAQUAMARINE("mediumaquamarine"),
MEDIUMBLUE("mediumblue"),
MEDIUMORCHID("mediumorchid"),
MEDIUMPURPLE("mediumpurple"),
MEDIUMSEAGREEN("mediumseagreen"),
MEDIUMSLATEBLUE("mediumslateblue"),
MEDIUMSPRINGGREE("mediumspringgree"),
MEDIUMTURQUOISE("mediumturquoise"),
MEDIUMVIOLETRED("mediumvioletred"),
MIDNIGHTBLUE("midnightblue"),
MINTCREAM("mintcream"),
MISTYROSE("mistyrose"),
MOCCASIN("moccasin"),
NAVAJOWHITE("navajowhite"),
NAVY("navy"),
NAVYBLUE("navyblue"),
OLDLACE("oldlace"),
OLIVE("olive"),
OLIVEDRAB("olivedrab"),
ORANGE("orange"),
ORANGERED("orangered"),
ORCHID("orchid"),
PALEGOLDENROD("palegoldenrod"),
PALEGREEN("palegreen"),
PALETURQUOISE("paleturquoise"),
PALEVIOLETRED("palevioletred"),
PAPAYAWHIP("papayawhip"),
PEACHPUFF("peachpuff"),
PERU("peru"),
PINK("pink"),
PLUM("plum"),
POWDERBLUE("powderblue"),
PURPLE("purple"),
RED("red"),
ROSYBROWN("rosybrown"),
ROYALBLUE("royalblue"),
SADDLEBROWN("saddlebrown"),
SALMON("salmon"),
SANDYBROWN("sandybrown"),
SEAGREEN("seagreen"),
SEASHELL("seashell"),
SIENNA("sienna"),
SILVER("silver"),
SKYBLUE("skyblue"),
SLATEBLUE("slateblue"),
SLATEGRAY("slategray"),
SNOW("snow"),
SPRINGGREEN("springgreen"),
STEELBLUE("steelblue"),
TAN("tan"),
TEAL("teal"),
THISTLE("thistle"),
TOMATO("tomato"),
TURQUOISE("turquoise"),
VIOLET("violet"),
WHEAT("wheat"),
WHITE("white"),
WHITESMOKE("whitesmoke"),
YELLOW("yellow"),
YELLOWGREEN("yellowgreen");
private final String color;
private GnuplotColor(final String color) {
this.color = color;
}
public String getColor() {
return color;
}
}
package org.lucares.recommind.logs;
public class GnuplotColor {
private final String color; // either a name ('darkorchid') or hex ('#00efcc')
private GnuplotColor(String color) {
this.color = color;
}
public static GnuplotColor byHex(String aHex){
return new GnuplotColor("rgb \"" + aHex+"\"");
}
public static GnuplotColor byName(GnuplotColorNames aName){
return new GnuplotColor(aName.getColor());
}
public String getColor() {
return color;
}
@Override
public String toString() {
return color;
}
}

View File

@@ -0,0 +1,300 @@
package org.lucares.recommind.logs;
public enum GnuplotColorNames {
ALICEBLUE("aliceblue"),
ANTIQUEWHITE("antiquewhite"),
AQUA("aqua"),
AQUAMARINE("aquamarine"),
AZURE("azure"),
BEIGE("beige"),
BISQUE("bisque"),
BLACK("black"),
BLANCHEDALMOND("blanchedalmond"),
BLUE("blue"),
BLUEVIOLET("blueviolet"),
BROWN("brown"),
BURLYWOOD("burlywood"),
CADETBLUE("cadetblue"),
CHARTREUSE("chartreuse"),
CHOCOLATE("chocolate"),
CORAL("coral"),
CORNFLOWERBLUE("cornflowerblue"),
CORNSILK("cornsilk"),
CRIMSON("crimson"),
CYAN("cyan"),
DARKBLUE("darkblue"),
DARKCYAN("darkcyan"),
DARKGOLDENROD("darkgoldenrod"),
DARKGRAY("darkgray"),
DARKGREEN("darkgreen"),
DARKKHAKI("darkkhaki"),
DARKMAGENTA("darkmagenta"),
DARKOLIVEGREEN("darkolivegreen"),
DARKORANGE("darkorange"),
DARKORCHID("darkorchid"),
DARKRED("darkred"),
DARKSALMON("darksalmon"),
DARKSEAGREEN("darkseagreen"),
DARKSLATEBLUE("darkslateblue"),
DARKSLATEGRAY("darkslategray"),
DARKTURQUOISE("darkturquoise"),
DARKVIOLET("darkviolet"),
DEEPPINK("deeppink"),
DEEPSKYBLUE("deepskyblue"),
DIMGRAY("dimgray"),
DODGERBLUE("dodgerblue"),
FIREBRICK("firebrick"),
FLORALWHITE("floralwhite"),
FORESTGREEN("forestgreen"),
FUCHSIA("fuchsia"),
GAINSBORO("gainsboro"),
GHOSTWHITE("ghostwhite"),
GOLD("gold"),
GOLDENROD("goldenrod"),
GRAY("gray"),
GREEN("green"),
GREENYELLOW("greenyellow"),
HONEYDEW("honeydew"),
HOTPINK("hotpink"),
INDIANRED("indianred"),
INDIGO("indigo"),
IVORY("ivory"),
KHAKI("khaki"),
LAVENDER("lavender"),
LAVENDERBLUSH("lavenderblush"),
LAWNGREEN("lawngreen"),
LEMONCHIFFON("lemonchiffon"),
LIGHTBLUE("lightblue"),
LIGHTCORAL("lightcoral"),
LIGHTCYAN("lightcyan"),
LIGHTGOLDENRODYE("lightgoldenrodye"),
LIGHTGREEN("lightgreen"),
LIGHTGREY("lightgrey"),
LIGHTPINK("lightpink"),
LIGHTSALMON("lightsalmon"),
LIGHTSEAGREEN("lightseagreen"),
LIGHTSKYBLUE("lightskyblue"),
LIGHTSLATEGRAY("lightslategray"),
LIGHTSTEELBLUE("lightsteelblue"),
LIGHTYELLOW("lightyellow"),
LIME("lime"),
LIMEGREEN("limegreen"),
LINEN("linen"),
MAGENTA("magenta"),
MAROON("maroon"),
MEDIUMAQUAMARINE("mediumaquamarine"),
MEDIUMBLUE("mediumblue"),
MEDIUMORCHID("mediumorchid"),
MEDIUMPURPLE("mediumpurple"),
MEDIUMSEAGREEN("mediumseagreen"),
MEDIUMSLATEBLUE("mediumslateblue"),
MEDIUMSPRINGGREE("mediumspringgree"),
MEDIUMTURQUOISE("mediumturquoise"),
MEDIUMVIOLETRED("mediumvioletred"),
MIDNIGHTBLUE("midnightblue"),
MINTCREAM("mintcream"),
MISTYROSE("mistyrose"),
MOCCASIN("moccasin"),
NAVAJOWHITE("navajowhite"),
NAVY("navy"),
NAVYBLUE("navyblue"),
OLDLACE("oldlace"),
OLIVE("olive"),
OLIVEDRAB("olivedrab"),
ORANGE("orange"),
ORANGERED("orangered"),
ORCHID("orchid"),
PALEGOLDENROD("palegoldenrod"),
PALEGREEN("palegreen"),
PALETURQUOISE("paleturquoise"),
PALEVIOLETRED("palevioletred"),
PAPAYAWHIP("papayawhip"),
PEACHPUFF("peachpuff"),
PERU("peru"),
PINK("pink"),
PLUM("plum"),
POWDERBLUE("powderblue"),
PURPLE("purple"),
RED("red"),
ROSYBROWN("rosybrown"),
ROYALBLUE("royalblue"),
SADDLEBROWN("saddlebrown"),
SALMON("salmon"),
SANDYBROWN("sandybrown"),
SEAGREEN("seagreen"),
SEASHELL("seashell"),
SIENNA("sienna"),
SILVER("silver"),
SKYBLUE("skyblue"),
SLATEBLUE("slateblue"),
SLATEGRAY("slategray"),
SNOW("snow"),
SPRINGGREEN("springgreen"),
STEELBLUE("steelblue"),
TAN("tan"),
TEAL("teal"),
THISTLE("thistle"),
TOMATO("tomato"),
TURQUOISE("turquoise"),
VIOLET("violet"),
WHEAT("wheat"),
WHITE("white"),
WHITESMOKE("whitesmoke"),
YELLOW("yellow"),
YELLOWGREEN("yellowgreen");
private final String color;
private GnuplotColorNames(final String color) {
this.color = color;
}
public String getColor() {
return color;
}
public GnuplotColor toColor(){
return GnuplotColor.byName(this);
}
}

View File

@@ -0,0 +1,36 @@
package org.lucares.recommind.logs;
import java.util.Arrays;
import java.util.List;
public interface GnuplotColorPalettes {
/**
*
<div style="background-color: #9400D3; display:inline;">#9400D3</div>
<div style="background-color: #009e73; display:inline;">#009e73</div>
<div style="background-color: #56b4e9; display:inline;">#56b4e9</div>
<div style="background-color: #e69f00; display:inline;">#e69f00</div>
<div style="background-color: #f0e442; display:inline;">#f0e442</div>
<div style="background-color: #0072b2; display:inline;">#0072b2</div>
<div style="background-color: #e51e10; display:inline;">#e51e10</div>
<div style="background-color: blue; display:inline;">blue</div>
<div style="background-color: #FF69B4; display:inline;">#FF69B4</div>
<div style="background-color: #00BFFF; display:inline;">#00BFFF</div>
<div style="background-color: black; display:inline;">black</div>
*/
List<GnuplotColor> DEFAULT = Arrays.asList(
GnuplotColor.byHex("#9400D3"),//
GnuplotColor.byHex("#009e73"),//
GnuplotColor.byHex("#56b4e9"),//
GnuplotColor.byHex("#e69f00"),//
GnuplotColor.byHex("#f0e442"),//
GnuplotColor.byHex("#0072b2"),//
GnuplotColor.byHex("#e51e10"),//
GnuplotColor.byHex("#0000FF"),//
GnuplotColor.byHex("#FF69B4"),//
GnuplotColor.byHex("#00BFFF"),//
GnuplotColorNames.BLACK.toColor()//
);
}

View File

@@ -30,16 +30,9 @@ public class GnuplotFileGenerator {
appendfln(result, "set xtics rotate by %d", xAxis.getRotateXAxisLabel());
appendfln(result, "set xrange [\"%s\":\"%s\"]", xAxis.getFrom(), xAxis.getTo());
/*
* set yrange ["0":"100"]
set ytics nomirror # don't show the tics of the left y-axis on the right side
set y2label "CPU load"
set y2tics
set autoscale y2
*/
appendfln(result, "set x2label \"percent\"");
appendfln(result, "set y2tics");
appendfln(result, "set x2label \"percentile\"");
appendln(result, "set format x2 \"%.0f%%\"");
appendfln(result, "set x2tics");
appendfln(result, "set x2range [\"0\":\"100\"]");
final long graphOffset = settings.getYAxisScale() == AxisScale.LINEAR ? 0 : 1;
@@ -84,6 +77,11 @@ public class GnuplotFileGenerator {
private void appendfln(final StringBuilder builder, final String format, final Object... args) {
builder.append(String.format(format + "\n", args));
}
private void appendln(final StringBuilder builder, final String string) {
builder.append(string+"\n");
}
private void appendf(final StringBuilder builder, final String format, final Object... args) {
builder.append(String.format(format, args));

View File

@@ -7,12 +7,12 @@ public class InlineDataSeries implements DataSeries{
private long maxValue;
private int numValues;
private String title;
private String id;
private int id;
private String inlineData;
private String style;
public InlineDataSeries(long maxValue, int numValues, String title,
String id, String inlineData) {
super();
int id, String inlineData) {
this.maxValue = maxValue;
this.numValues = numValues;
this.title = title;
@@ -21,10 +21,25 @@ public class InlineDataSeries implements DataSeries{
}
@Override
public String getId() {
public String getIdAsString() {
return "id"+id;
}
@Override
public int getId() {
return id;
}
@Override
public void setStyle(String style) {
this.style = style;
}
@Override
public String getStyle() {
return style;
}
@Override
public String getTitle() {

View File

@@ -74,8 +74,7 @@ public class PercentilePlot implements ConcretePlotter {
.forEach(
groupResult -> {
try {
final String id = "id"
+ idCounter.getAndIncrement();
final int id = idCounter.getAndIncrement();
final FileBackedDataSeries dataSerie = toCsv(
id, groupResult, tmpDir, dateFrom,
@@ -127,7 +126,7 @@ public class PercentilePlot implements ConcretePlotter {
}
}
private FileBackedDataSeries toCsv(String id, GroupResult groupResult,
private FileBackedDataSeries toCsv(int id, GroupResult groupResult,
Path tmpDir, OffsetDateTime dateFrom, OffsetDateTime dateTo,
PlotSettings plotSettings) throws IOException {

View File

@@ -86,9 +86,9 @@ public class ScatterPlot implements ConcretePlotter {
try{
final CsvSummary csvSummary = toCsv(groupResult, tmpDir, dateFrom, dateTo, plotSettings);
final int id = idCounter.getAndIncrement();
final int id = idCounter.incrementAndGet();
final String title = ConcretePlotter.title(groupResult.getGroupedBy(), csvSummary.getValues());
final DataSeries dataSerie = new FileBackedDataSeries("id"+id, title, csvSummary, GnuplotLineType.Points);
final DataSeries dataSerie = new FileBackedDataSeries(id, title, csvSummary, GnuplotLineType.Points);
if (dataSerie.getValues() > 0) {
dataSeries.add(dataSerie);
}
@@ -106,6 +106,7 @@ public class ScatterPlot implements ConcretePlotter {
final Limit limitBy = plotSettings.getLimitBy();
int limit = plotSettings.getLimit();
DataSeries.sortAndLimit(dataSeries, limitBy, limit);
DataSeries.setColors(dataSeries);
final Path outputFile = Files.createTempFile(outputDir, "out", ".png");
final Gnuplot gnuplot = new Gnuplot(tmpBaseDir);