centralize generation of y-axis definitions
There is only one y1 and one y2 axis. Therefore it doesn't make sense to have their definition in the AggregateHandlers, because this would produce multiple definitions for these axises.
This commit is contained in:
@@ -5,19 +5,29 @@ package org.lucares.pdb.plot.api;
|
||||
* drawn.
|
||||
*/
|
||||
public enum Aggregate {
|
||||
BAR,
|
||||
BAR("Bar"),
|
||||
|
||||
PARALLEL,
|
||||
PARALLEL("Parallel Requests"),
|
||||
|
||||
SCATTER,
|
||||
SCATTER("Scatter"),
|
||||
|
||||
/**
|
||||
* Empirical cumulative distribution functions
|
||||
*
|
||||
* @see https://serialmentor.com/dataviz/ecdf-qq.html
|
||||
*/
|
||||
CUM_DISTRIBUTION,
|
||||
CUM_DISTRIBUTION("Cumulative Distribution"),
|
||||
|
||||
HISTOGRAM,
|
||||
HISTOGRAM("Histogram");
|
||||
|
||||
private final String axisLabel;
|
||||
|
||||
private Aggregate(final String axisLabel) {
|
||||
this.axisLabel = axisLabel;
|
||||
}
|
||||
|
||||
public String getAxisLabel() {
|
||||
return axisLabel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public abstract class AggregateHandler implements Appender {
|
||||
}
|
||||
}
|
||||
|
||||
public GnuplotAxis getyAxis() {
|
||||
public GnuplotAxis getYAxis() {
|
||||
return yAxis;
|
||||
}
|
||||
|
||||
@@ -50,8 +50,6 @@ public abstract class AggregateHandler implements Appender {
|
||||
|
||||
abstract AxisSettings createXAxisSettings(GnuplotSettings settings, Collection<DataSeries> dataSeries);
|
||||
|
||||
abstract AxisSettings createYAxisSettings(GnuplotSettings settings, Collection<DataSeries> dataSeries);
|
||||
|
||||
abstract String addPlot(CustomAggregator aggregator, LineStyle lineStyle, Optional<String> title);
|
||||
|
||||
abstract CustomAggregator createCustomAggregator(Path tmpDir, PlotSettings plotSettings, long fromEpochMilli,
|
||||
|
||||
@@ -4,11 +4,13 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.lucares.recommind.logs.AxisSettings;
|
||||
import org.lucares.recommind.logs.AxisTime;
|
||||
import org.lucares.recommind.logs.DataSeries;
|
||||
import org.lucares.recommind.logs.GnuplotAxis;
|
||||
import org.lucares.recommind.logs.GnuplotSettings;
|
||||
@@ -32,18 +34,18 @@ public class AggregateHandlerCollection {
|
||||
}
|
||||
|
||||
private void updateAxisForHandlers(final GnuplotAxis axis) {
|
||||
final EnumSet<Type> result = EnumSet.noneOf(Type.class);
|
||||
final Map<Type, GnuplotAxis> result = new HashMap<>();
|
||||
for (final AggregateHandler handler : aggregateHandlers) {
|
||||
final Type type = handler.getAxisType(axis);
|
||||
|
||||
if (result.isEmpty()) {
|
||||
result.add(type);
|
||||
result.put(type, axis);
|
||||
} else {
|
||||
final boolean containsType = result.contains(type);
|
||||
if (containsType) {
|
||||
final GnuplotAxis previouslyUsedAxis = result.get(type);
|
||||
if (previouslyUsedAxis != null) {
|
||||
// already has an axis of this type
|
||||
// TODO merge axis definitions and use the greater values for: range,
|
||||
// ticsIncrement
|
||||
handler.updateAxis(previouslyUsedAxis);
|
||||
result.put(type, previouslyUsedAxis);
|
||||
} else {
|
||||
Preconditions.checkSmaller(result.size(), 2,
|
||||
"At most two different axis are supported. "
|
||||
@@ -51,7 +53,7 @@ public class AggregateHandlerCollection {
|
||||
+ "-axis. Remove one or more plot types.");
|
||||
final GnuplotAxis mirrorAxis = axis.mirrorAxis();
|
||||
handler.updateAxis(mirrorAxis);
|
||||
result.add(type);
|
||||
result.put(type, mirrorAxis);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,10 +72,21 @@ public class AggregateHandlerCollection {
|
||||
public List<AxisSettings> getYAxisDefinitions(final GnuplotSettings settings,
|
||||
final Collection<DataSeries> dataSeries) {
|
||||
final List<AxisSettings> result = new ArrayList<>();
|
||||
|
||||
final Map<GnuplotAxis, String> usedYAxises = new HashMap<>();
|
||||
for (final AggregateHandler handler : aggregateHandlers) {
|
||||
final AxisSettings axis = handler.createYAxisSettings(settings, dataSeries);
|
||||
final String label = handler.getAggregateType().getAxisLabel();
|
||||
final GnuplotAxis yAxis = handler.getYAxis();
|
||||
usedYAxises.compute(yAxis, (k, v) -> v == null ? label : v + "/" + label);
|
||||
}
|
||||
|
||||
for (final GnuplotAxis gnuplotAxis : usedYAxises.keySet()) {
|
||||
final String label = usedYAxises.get(gnuplotAxis);
|
||||
final AxisSettings axis = AxisTime.createYAxis(settings, gnuplotAxis, dataSeries);
|
||||
axis.setLabel(axis.getLabel() + " (" + label + ")");
|
||||
result.add(axis);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.lucares.recommind.logs.AxisSettings;
|
||||
import org.lucares.recommind.logs.AxisTime;
|
||||
import org.lucares.recommind.logs.DataSeries;
|
||||
import org.lucares.recommind.logs.GnuplotAxis;
|
||||
import org.lucares.recommind.logs.GnuplotLineType;
|
||||
@@ -57,13 +56,6 @@ public class BarChartHandler extends AggregateHandler {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
AxisSettings createYAxisSettings(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||
|
||||
final AxisSettings result = AxisTime.createYAxis(settings, getyAxis(), dataSeries);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
String beforePlot(final CustomAggregator aggregator, final GnuplotSettings settings) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.lucares.recommind.logs.AxisSettings;
|
||||
import org.lucares.recommind.logs.AxisTime;
|
||||
import org.lucares.recommind.logs.DataSeries;
|
||||
import org.lucares.recommind.logs.GnuplotAxis;
|
||||
import org.lucares.recommind.logs.GnuplotSettings;
|
||||
@@ -37,13 +36,6 @@ public class CumulativeDistributionHandler extends AggregateHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisSettings createYAxisSettings(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||
final AxisSettings result = AxisTime.createYAxis(settings, getyAxis(), dataSeries);
|
||||
result.setAxis(getyAxis());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisSettings createXAxisSettings(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||
final AxisSettings result = new AxisSettings();
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.lucares.recommind.logs.AxisSettings;
|
||||
import org.lucares.recommind.logs.AxisTime;
|
||||
import org.lucares.recommind.logs.DataSeries;
|
||||
import org.lucares.recommind.logs.GnuplotAxis;
|
||||
import org.lucares.recommind.logs.GnuplotSettings;
|
||||
@@ -43,21 +42,6 @@ public class HistogramHandler extends AggregateHandler {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
AxisSettings createYAxisSettings(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||
final AxisSettings result = AxisTime.createYAxis(settings, getyAxis(), dataSeries);
|
||||
result.setLabel("Histogram - Count");
|
||||
return result;
|
||||
|
||||
// final AxisSettings result = new AxisSettings();
|
||||
// result.setLabel("Histogram - Count");
|
||||
// result.setType(Type.HistogramCount);
|
||||
// result.setAxis(getyAxis());
|
||||
// result.setTicsEnabled(true);
|
||||
// result.setFrom("0");
|
||||
// return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
String addPlot(final CustomAggregator aggregator, final LineStyle lineStyle, final Optional<String> title) {
|
||||
final AggregatedData aggregatedData = aggregator.getAggregatedData();
|
||||
|
||||
@@ -29,13 +29,6 @@ public class ParallelRequestsAggregate extends AggregateHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisSettings createYAxisSettings(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||
|
||||
final AxisSettings result = AxisTime.createYAxis(settings, getyAxis(), dataSeries);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisSettings createXAxisSettings(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||
final AxisSettings result = AxisTime.createXAxis(settings);
|
||||
|
||||
@@ -29,13 +29,6 @@ public class ScatterAggregateHandler extends AggregateHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisSettings createYAxisSettings(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||
final AxisSettings result = AxisTime.createYAxis(settings, getyAxis(), dataSeries);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AxisSettings createXAxisSettings(final GnuplotSettings settings, final Collection<DataSeries> dataSeries) {
|
||||
final AxisSettings result = AxisTime.createXAxis(settings);
|
||||
@@ -60,7 +53,7 @@ public class ScatterAggregateHandler extends AggregateHandler {
|
||||
public CustomAggregator createCustomAggregator(final Path tmpDir, final PlotSettings plotSettings,
|
||||
final long fromEpochMilli, final long toEpochMilli) {
|
||||
|
||||
return new ScatterAggregator(tmpDir, plotSettings, getyAxis(), fromEpochMilli, toEpochMilli);
|
||||
return new ScatterAggregator(tmpDir, plotSettings, getYAxis(), fromEpochMilli, toEpochMilli);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user