handle multi series bar chart better by reducing distance between bars
This commit is contained in:
@@ -17,6 +17,8 @@ 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;
|
||||
@@ -77,13 +79,14 @@ public class BarChartAggregatorForIntervals implements CustomAggregator, Indexed
|
||||
@Override
|
||||
public String asCsv() {
|
||||
final StringBuilder csv = new StringBuilder();
|
||||
final boolean isMiddleSeries = getIndex() == numberOfDataSeries / 2;
|
||||
|
||||
int offset = 0;
|
||||
for (final String bucketId : bucketIds()) {
|
||||
final long count = buckets.get(bucketId).get();
|
||||
csv.append(getIndex() + 0.5 + offset);
|
||||
csv.append(offset + getIndex() * SPACE_BETWEEN_BARS + 0.5);
|
||||
csv.append(",");
|
||||
csv.append(bucketId);
|
||||
csv.append(isMiddleSeries ? bucketId : "");
|
||||
csv.append(",");
|
||||
csv.append(count);
|
||||
csv.append("\n");
|
||||
@@ -131,8 +134,8 @@ public class BarChartAggregatorForIntervals implements CustomAggregator, Indexed
|
||||
final long count = buckets.get(bucketId).get();
|
||||
final String label = String.format("set label at %s %f, %d '%s' center front offset 0,0.3\n", // front
|
||||
xAxis == GnuplotAxis.X1 ? "first" : "second", //
|
||||
getIndex() + 0.5 + offset, //
|
||||
count, //
|
||||
offset + getIndex() * SPACE_BETWEEN_BARS + 0.5, // x-axis position of the label
|
||||
count, // y axis position of the label
|
||||
String.format(Locale.US, "%,d", count));
|
||||
|
||||
result.append(label);
|
||||
|
||||
@@ -42,7 +42,6 @@ public class BarChartHandler extends AggregateHandler {
|
||||
result.setType(Type.Group);
|
||||
result.setAxis(getxAxis());
|
||||
result.setTicsEnabled(false);
|
||||
// TODO revert next two lines
|
||||
result.setFrom("0");
|
||||
// result.setTo(String.valueOf(dataSeries.size()));
|
||||
|
||||
|
||||
@@ -62,15 +62,15 @@ public class Interval {
|
||||
private String toDateFormatForBucketer(final IntervalTimeUnit intervalTimeUnit) {
|
||||
switch (intervalTimeUnit) {
|
||||
case MINUTE:
|
||||
return "yyyyMMddHHmm";
|
||||
return "yyyy-MM-dd HH:mm";
|
||||
case HOUR:
|
||||
return "yyyyMMddHH";
|
||||
return "yyyy-MM-dd HH";
|
||||
case DAY:
|
||||
return "yyyyMMdd";
|
||||
return "yyyy-MM-dd";
|
||||
case WEEK:
|
||||
return "YYYYww"; // use week based year! Otherwise intervals over the year boundary will be wrong
|
||||
return "YYYY-ww"; // use week based year! Otherwise intervals over the year boundary will be wrong
|
||||
case MONTH:
|
||||
return "yyyyMM";
|
||||
return "yyyy-MM";
|
||||
case YEAR:
|
||||
return "yyyy";
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user