From 110d93e4fa0762a0969b41804e2bd81b147f1a8a Mon Sep 17 00:00:00 2001 From: grzesiul Date: Tue, 28 Jun 2016 11:42:41 +0200 Subject: [PATCH 1/3] Discover properly maximal value in data series --- .../sparklines/client/ui/SparklinesGWT.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java b/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java index 29e9e57..7582824 100644 --- a/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java +++ b/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java @@ -41,7 +41,7 @@ public class SparklinesGWT extends Composite { protected String pathColor = "#ccc"; protected int pathWidth = 1; - protected double max = Double.MIN_VALUE; + protected double max = -Double.MAX_VALUE;//Double.MIN_VALUE; protected double maxidx = 0; protected double minidx = 0; protected double min = Double.MAX_VALUE; @@ -71,7 +71,7 @@ public class SparklinesGWT extends Composite { protected String valueColor = "#00f"; public SparklinesGWT(String caption, int graphWidth, int graphHeight, - int displayRangeMin, int displayRangeMax) { + int displayRangeMin, int displayRangeMax) { this.graphHeight = graphHeight; this.graphWidth = graphWidth; this.displayHigh = displayRangeMax; @@ -284,7 +284,7 @@ public void setValueDotVisible(boolean valueDotVisible) { } private void redraw() { - max = Double.MIN_VALUE; + max = Integer.MIN_VALUE;//Double.MIN_VALUE; maxidx = 0; minidx = 0; min = Integer.MAX_VALUE; @@ -324,9 +324,8 @@ private void redraw() { } value.setText(String.valueOf(data[data.length - 1])); - double effectiveMin = (displayLow < Double.MAX_VALUE ? displayLow : min); - double effectiveMax = (displayHigh > Double.MIN_VALUE ? displayHigh - : max); + double effectiveMin = effectiveMin(); + double effectiveMax = effectiveMax(); if (graphHeight < 1) { // canvas.setHeight(effectiveMax - effectiveMin + PAD); @@ -342,8 +341,7 @@ private void redraw() { canvas.setWidth(graphWidth); } - vscale = (double) (canvas.getHeight() - PAD) - / (effectiveMax - effectiveMin); + vscale = (double) (canvas.getHeight() - PAD) / (effectiveMax - effectiveMin); hscale = (double) (canvas.getWidth() - PAD) / (data.length - 1); // average @@ -392,9 +390,16 @@ private void redraw() { } + private double effectiveMin() { + return displayLow < Integer.MAX_VALUE ? displayLow : min; + } + + private double effectiveMax() { + return displayHigh > Integer.MIN_VALUE ? displayHigh : max; + } + private int translateY(double y) { - double effectiveMin = (displayLow < Integer.MAX_VALUE ? displayLow - : min); + double effectiveMin = effectiveMin(); int newY = (int) ((y - effectiveMin) * vscale); int res = (canvas.getHeight() - newY) - OFFSET; return res; From b88d832b414be24e3688046c02916aa037509f5b Mon Sep 17 00:00:00 2001 From: grzesiul Date: Tue, 28 Jun 2016 11:48:44 +0200 Subject: [PATCH 2/3] clean up --- .../src/org/vaadin/sparklines/client/ui/SparklinesGWT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java b/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java index 7582824..46fa573 100644 --- a/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java +++ b/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java @@ -41,7 +41,7 @@ public class SparklinesGWT extends Composite { protected String pathColor = "#ccc"; protected int pathWidth = 1; - protected double max = -Double.MAX_VALUE;//Double.MIN_VALUE; + protected double max = -(Double.MAX_VALUE - 1); protected double maxidx = 0; protected double minidx = 0; protected double min = Double.MAX_VALUE; @@ -284,7 +284,7 @@ public void setValueDotVisible(boolean valueDotVisible) { } private void redraw() { - max = Integer.MIN_VALUE;//Double.MIN_VALUE; + max = Integer.MIN_VALUE; maxidx = 0; minidx = 0; min = Integer.MAX_VALUE; From c4aadd6c6cc842e5ad616989b34588169c794230 Mon Sep 17 00:00:00 2001 From: grzesiul Date: Tue, 28 Jun 2016 12:24:35 +0200 Subject: [PATCH 3/3] effective maximum revert --- .../sparklines/client/ui/SparklinesGWT.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java b/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java index 46fa573..6186312 100644 --- a/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java +++ b/Sparklines/src/org/vaadin/sparklines/client/ui/SparklinesGWT.java @@ -18,7 +18,8 @@ // TODO setDotSize // TODO ? set public class SparklinesGWT extends Composite { - + private static final double MAXIMAL_VALUE = Double.MAX_VALUE; + private static final double MINIMAL_VALUE = -(Double.MAX_VALUE - 1); public static String CLASSNAME = "v-sparkline"; private static int PAD = 4; @@ -41,10 +42,10 @@ public class SparklinesGWT extends Composite { protected String pathColor = "#ccc"; protected int pathWidth = 1; - protected double max = -(Double.MAX_VALUE - 1); + protected double max = MINIMAL_VALUE; protected double maxidx = 0; protected double minidx = 0; - protected double min = Double.MAX_VALUE; + protected double min = MAXIMAL_VALUE; protected int avg = 0; @@ -284,10 +285,10 @@ public void setValueDotVisible(boolean valueDotVisible) { } private void redraw() { - max = Integer.MIN_VALUE; + max = MINIMAL_VALUE; maxidx = 0; minidx = 0; - min = Integer.MAX_VALUE; + min = MAXIMAL_VALUE; avg = 0; @@ -391,11 +392,11 @@ private void redraw() { } private double effectiveMin() { - return displayLow < Integer.MAX_VALUE ? displayLow : min; + return displayLow < MAXIMAL_VALUE ? displayLow : min; } private double effectiveMax() { - return displayHigh > Integer.MIN_VALUE ? displayHigh : max; + return displayHigh > MINIMAL_VALUE ? displayHigh : max; } private int translateY(double y) {