don't render labels in gallery preview
This commit is contained in:
@@ -4,7 +4,7 @@ import org.lucares.recommind.logs.GnuplotAxis;
|
||||
|
||||
public interface BarChart extends IndexedAggregator {
|
||||
|
||||
String asCsv();
|
||||
String asCsv(boolean renderLabels);
|
||||
|
||||
String getDataName();
|
||||
|
||||
|
||||
@@ -1,30 +1,21 @@
|
||||
package org.lucares.pdb.plot.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.lucares.pdb.api.RuntimeIOException;
|
||||
import org.lucares.recommind.logs.GnuplotAxis;
|
||||
|
||||
public class BarChartAggregator implements CustomAggregator, IndexedAggregator, BarChart {
|
||||
|
||||
long count = 0;
|
||||
|
||||
private final Path tmpDir;
|
||||
|
||||
private Long index = null;
|
||||
private Long numberOfDataSeries;
|
||||
|
||||
private final String dataName = "$data" + UUID.randomUUID().toString().replace("-", "");
|
||||
|
||||
public BarChartAggregator(final Path tmpDir) {
|
||||
public BarChartAggregator() {
|
||||
super();
|
||||
this.tmpDir = tmpDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,7 +51,7 @@ public class BarChartAggregator implements CustomAggregator, IndexedAggregator,
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asCsv() {
|
||||
public String asCsv(final boolean renderLabels) {
|
||||
final StringBuilder csv = new StringBuilder();
|
||||
|
||||
csv.append(getIndex() + 0.5);
|
||||
@@ -73,17 +64,9 @@ public class BarChartAggregator implements CustomAggregator, IndexedAggregator,
|
||||
|
||||
@Override
|
||||
public AggregatedData getAggregatedData() {
|
||||
try {
|
||||
final File dataFile = File.createTempFile("bar", ".dat", tmpDir.toFile());
|
||||
|
||||
final String csv = asCsv();
|
||||
|
||||
Files.writeString(dataFile.toPath(), csv, StandardCharsets.UTF_8);
|
||||
final AggregatedData result = new AggregatedData("label", dataFile);
|
||||
return result;
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeIOException(e);
|
||||
}
|
||||
// not needed - usually this method is used to write the data to file, but bar
|
||||
// charts use inline data
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package org.lucares.pdb.plot.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
@@ -12,15 +7,12 @@ import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.lucares.pdb.api.RuntimeIOException;
|
||||
import org.lucares.recommind.logs.GnuplotAxis;
|
||||
|
||||
public class BarChartAggregatorForIntervals implements CustomAggregator, IndexedAggregator, BarChart {
|
||||
|
||||
private static final double SPACE_BETWEEN_BARS = 0.6;
|
||||
|
||||
private final Path tmpDir;
|
||||
|
||||
private Long index = null;
|
||||
private Long numberOfDataSeries;
|
||||
|
||||
@@ -32,8 +24,7 @@ public class BarChartAggregatorForIntervals implements CustomAggregator, Indexed
|
||||
|
||||
private int count;
|
||||
|
||||
public BarChartAggregatorForIntervals(final Path tmpDir, final Interval interval) {
|
||||
this.tmpDir = tmpDir;
|
||||
public BarChartAggregatorForIntervals(final Interval interval) {
|
||||
this.interval = interval;
|
||||
buckets = interval.getBuckets();
|
||||
}
|
||||
@@ -77,7 +68,7 @@ public class BarChartAggregatorForIntervals implements CustomAggregator, Indexed
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asCsv() {
|
||||
public String asCsv(final boolean renderLabels) {
|
||||
final StringBuilder csv = new StringBuilder();
|
||||
final boolean isMiddleSeries = getIndex() == numberOfDataSeries / 2;
|
||||
|
||||
@@ -86,7 +77,7 @@ public class BarChartAggregatorForIntervals implements CustomAggregator, Indexed
|
||||
final long count = buckets.get(bucketId).get();
|
||||
csv.append(offset + getIndex() * SPACE_BETWEEN_BARS + 0.5);
|
||||
csv.append(",");
|
||||
csv.append(isMiddleSeries ? bucketId : "");
|
||||
csv.append(renderLabels && isMiddleSeries ? bucketId : "");
|
||||
csv.append(",");
|
||||
csv.append(count);
|
||||
csv.append("\n");
|
||||
@@ -102,17 +93,9 @@ public class BarChartAggregatorForIntervals implements CustomAggregator, Indexed
|
||||
|
||||
@Override
|
||||
public AggregatedData getAggregatedData() {
|
||||
try {
|
||||
final File dataFile = File.createTempFile("bar", ".dat", tmpDir.toFile());
|
||||
|
||||
final String csv = asCsv();
|
||||
|
||||
Files.writeString(dataFile.toPath(), csv, StandardCharsets.UTF_8);
|
||||
final AggregatedData result = new AggregatedData("label", dataFile);
|
||||
return result;
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeIOException(e);
|
||||
}
|
||||
// not needed - usually this method is used to write the data to file, but bar
|
||||
// charts use inline data
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -62,7 +62,7 @@ public class BarChartHandler extends AggregateHandler {
|
||||
final BarChart barAggregator = (BarChart) aggregator;
|
||||
|
||||
appendfln(result, "%s <<EOD", barAggregator.getDataName());
|
||||
appendln(result, barAggregator.asCsv());
|
||||
appendln(result, barAggregator.asCsv(settings.isRenderLabels()));
|
||||
appendln(result, "EOD");
|
||||
|
||||
if (settings.isRenderLabels()) {
|
||||
@@ -91,9 +91,9 @@ public class BarChartHandler extends AggregateHandler {
|
||||
CustomAggregator createCustomAggregator(final Path tmpDir, final PlotSettings plotSettings,
|
||||
final long fromEpochMilli, final long toEpochMilli) {
|
||||
if (plotSettings.getInterval().isPresent()) {
|
||||
return new BarChartAggregatorForIntervals(tmpDir, plotSettings.getInterval().get());
|
||||
return new BarChartAggregatorForIntervals(plotSettings.getInterval().get());
|
||||
} else {
|
||||
return new BarChartAggregator(tmpDir);
|
||||
return new BarChartAggregator();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user