Graph bars for type=Meter
This commit is contained in:
parent
4827fe32fb
commit
e7e2953d00
@ -7,21 +7,25 @@ import java.time.temporal.*;
|
|||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
|
|
||||||
public enum Alignment {
|
public enum Alignment {
|
||||||
FIVE(t -> t.truncatedTo(ChronoUnit.MINUTES).minusMinutes(t.getMinute() % 5), (t, a) -> t.plusMinutes(5 * a)),
|
FIVE(Duration.ofMinutes(5), t -> t.truncatedTo(ChronoUnit.MINUTES).minusMinutes(t.getMinute() % 5), (t, a) -> t.plusMinutes(5 * a)),
|
||||||
HOUR(t -> t.truncatedTo(ChronoUnit.HOURS), ZonedDateTime::plusHours),
|
HOUR(Duration.ofHours(1), t -> t.truncatedTo(ChronoUnit.HOURS), ZonedDateTime::plusHours),
|
||||||
DAY(t -> t.truncatedTo(ChronoUnit.DAYS), ZonedDateTime::plusDays),
|
DAY(Duration.ofDays(1), t -> t.truncatedTo(ChronoUnit.DAYS), ZonedDateTime::plusDays),
|
||||||
WEEK(t -> t.truncatedTo(ChronoUnit.DAYS).minusDays(t.getDayOfWeek().getValue() - 1), ZonedDateTime::plusWeeks),
|
WEEK(Duration.ofDays(7), t -> t.truncatedTo(ChronoUnit.DAYS).minusDays(t.getDayOfWeek().getValue() - 1), ZonedDateTime::plusWeeks),
|
||||||
MONTH(t -> t.truncatedTo(ChronoUnit.DAYS).minusDays(t.getDayOfMonth() - 1), ZonedDateTime::plusMonths),
|
MONTH(Duration.ofDays(31), t -> t.truncatedTo(ChronoUnit.DAYS).minusDays(t.getDayOfMonth() - 1), ZonedDateTime::plusMonths),
|
||||||
YEAR(t -> t.truncatedTo(ChronoUnit.DAYS).minusDays(t.getDayOfYear() - 1), ZonedDateTime::plusYears),
|
YEAR(Duration.ofDays(366), t -> t.truncatedTo(ChronoUnit.DAYS).minusDays(t.getDayOfYear() - 1), ZonedDateTime::plusYears),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public final Duration maxDuration;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public final Function<ZonedDateTime, ZonedDateTime> align;
|
public final Function<ZonedDateTime, ZonedDateTime> align;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public final BiFunction<ZonedDateTime, Long, ZonedDateTime> plus;
|
public final BiFunction<ZonedDateTime, Long, ZonedDateTime> plus;
|
||||||
|
|
||||||
Alignment(@NonNull final Function<ZonedDateTime, ZonedDateTime> align, @NonNull final BiFunction<ZonedDateTime, Long, ZonedDateTime> plus) {
|
Alignment(final @NonNull Duration maxDuration, @NonNull final Function<ZonedDateTime, ZonedDateTime> align, @NonNull final BiFunction<ZonedDateTime, Long, ZonedDateTime> plus) {
|
||||||
|
this.maxDuration = maxDuration;
|
||||||
this.align = align;
|
this.align = align;
|
||||||
this.plus = plus;
|
this.plus = plus;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -100,7 +100,7 @@ public class Graph {
|
|||||||
minuteMin = begin.date.toEpochSecond() / 60;
|
minuteMin = begin.date.toEpochSecond() / 60;
|
||||||
minuteMax = end.date.toEpochSecond() / 60;
|
minuteMax = end.date.toEpochSecond() / 60;
|
||||||
minuteRange = minuteMax - minuteMin;
|
minuteRange = minuteMax - minuteMin;
|
||||||
minuteScale = (double) widthInner / minuteRange;
|
minuteScale = (double) widthInner / (minuteRange + begin.alignment.maxDuration.toMinutes());
|
||||||
|
|
||||||
valueMin = vMin;
|
valueMin = vMin;
|
||||||
valueMax = vMax;
|
valueMax = vMax;
|
||||||
@ -133,14 +133,23 @@ public class Graph {
|
|||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawLine(widthInner, 0, widthInner, heightInner); // y-axis
|
g.drawLine(widthInner, 0, widthInner, heightInner); // y-axis
|
||||||
|
|
||||||
Point last = null;
|
if (series.type == SeriesType.METER) {
|
||||||
|
g.setColor(Color.PINK);
|
||||||
|
final int space = (int) (minuteScale * begin.alignment.maxDuration.toMinutes());
|
||||||
|
final int width = (int) (space * 0.95);
|
||||||
|
for (final Point point : points) {
|
||||||
|
g.fillRect(point.x + (space - width), 0, width, point.y);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
g.setColor(Color.RED);
|
g.setColor(Color.RED);
|
||||||
|
Point last = null;
|
||||||
for (final Point current : points) {
|
for (final Point current : points) {
|
||||||
if (last != null) {
|
if (last != null) {
|
||||||
g.drawLine(last.x, last.y, current.x, current.y);
|
g.drawLine(last.x, last.y, current.x, current.y);
|
||||||
}
|
}
|
||||||
last = current;
|
last = current;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public class GraphController {
|
|||||||
public void graph(@PathVariable final long seriesId, final HttpServletResponse response, @PathVariable final int width, @PathVariable final int height, @PathVariable final String alignmentName, @PathVariable final long offset, @PathVariable final long duration) throws IOException {
|
public void graph(@PathVariable final long seriesId, final HttpServletResponse response, @PathVariable final int width, @PathVariable final int height, @PathVariable final String alignmentName, @PathVariable final long offset, @PathVariable final long duration) throws IOException {
|
||||||
final Alignment alignment = Alignment.valueOf(alignmentName);
|
final Alignment alignment = Alignment.valueOf(alignmentName);
|
||||||
final Aligned end = alignment.align(ZonedDateTime.now()).minus(offset);
|
final Aligned end = alignment.align(ZonedDateTime.now()).minus(offset);
|
||||||
final Aligned begin = end.minus(duration);
|
final Aligned begin = end.minus(duration - 1);
|
||||||
final Graph graph = graphService.getGraph(seriesId, begin, end, width, height, 10);
|
final Graph graph = graphService.getGraph(seriesId, begin, end, width, height, 10);
|
||||||
final BufferedImage image = graph.draw();
|
final BufferedImage image = graph.draw();
|
||||||
response.setContentType("image/png");
|
response.setContentType("image/png");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user