add labels to bar chart
This commit is contained in:
@@ -57,7 +57,7 @@ public abstract class AggregateHandler implements Appender {
|
||||
abstract CustomAggregator createCustomAggregator(Path tmpDir, PlotSettings plotSettings, long fromEpochMilli,
|
||||
long toEpochMilli);
|
||||
|
||||
String beforePlot(final CustomAggregator aggregator) {
|
||||
String beforePlot(final CustomAggregator aggregator, final GnuplotSettings settings) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,8 @@ public class AggregateHandlerCollection {
|
||||
return new AggregatorCollection(aggregators);
|
||||
}
|
||||
|
||||
public void addPlots(final StringBuilder result, final Collection<DataSeries> dataSeries) {
|
||||
public void addPlots(final StringBuilder result, final Collection<DataSeries> dataSeries,
|
||||
final GnuplotSettings settings) {
|
||||
|
||||
final StringBuilder plots = new StringBuilder();
|
||||
final StringBuilder beforePlots = new StringBuilder();
|
||||
@@ -116,7 +117,7 @@ public class AggregateHandlerCollection {
|
||||
index++;
|
||||
}
|
||||
|
||||
final String beforePlot = handler.beforePlot(aggregator);
|
||||
final String beforePlot = handler.beforePlot(aggregator, settings);
|
||||
beforePlots.append(beforePlot);
|
||||
|
||||
final String plot = handler.addPlot(aggregator, dataSerie.getStyle(), title);
|
||||
|
||||
@@ -37,6 +37,10 @@ public class BarChartAggregator implements CustomAggregator, IndexedAggregator {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addValue(final boolean valueIsInYRange, final long epochMilli, final long value) {
|
||||
count++;
|
||||
@@ -45,7 +49,7 @@ public class BarChartAggregator implements CustomAggregator, IndexedAggregator {
|
||||
public String asCsv() {
|
||||
final StringBuilder csv = new StringBuilder();
|
||||
|
||||
csv.append(index + 0.5);
|
||||
csv.append(getIndex() + 0.5);
|
||||
csv.append(",");
|
||||
csv.append("");
|
||||
csv.append(",");
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.lucares.recommind.logs.AxisSettings;
|
||||
@@ -68,7 +69,7 @@ public class BarChartHandler extends AggregateHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
String beforePlot(final CustomAggregator aggregator) {
|
||||
String beforePlot(final CustomAggregator aggregator, final GnuplotSettings settings) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
final BarChartAggregator barAggregator = (BarChartAggregator) aggregator;
|
||||
@@ -76,6 +77,14 @@ public class BarChartHandler extends AggregateHandler {
|
||||
appendfln(result, "%s <<EOD", barAggregator.getDataName());
|
||||
appendln(result, barAggregator.asCsv());
|
||||
appendln(result, "EOD");
|
||||
|
||||
if (settings.isRenderLabels()) {
|
||||
appendfln(result, "set label at %f, %d '%s' center front offset 0,0.3", // front
|
||||
barAggregator.getIndex() + 0.5, //
|
||||
barAggregator.getCount(), //
|
||||
String.format(Locale.US, "%,d", barAggregator.getCount()));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public class GnuplotFileGenerator implements Appender {
|
||||
// appendfln(result, "set xrange [-1:1]");
|
||||
appendfln(result, "set boxwidth 0.5");
|
||||
|
||||
settings.getAggregates().addPlots(result, dataSeries);
|
||||
settings.getAggregates().addPlots(result, dataSeries, settings);
|
||||
|
||||
// Add a plot outside of the visible range. Without this gnuplot would not
|
||||
// render images when there are not data points on it.
|
||||
|
||||
Reference in New Issue
Block a user