From 7d791fd5d7a24bf9dc547e0f33196dacf01362ee Mon Sep 17 00:00:00 2001 From: Mykola Karaman Date: Thu, 21 Sep 2017 15:40:18 +0200 Subject: [PATCH 1/2] NPE fix for Donut PiePlot in pointRenderers --- .../src/main/java/de/erichseifert/gral/plots/PiePlot.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gral-core/src/main/java/de/erichseifert/gral/plots/PiePlot.java b/gral-core/src/main/java/de/erichseifert/gral/plots/PiePlot.java index bcc829f7..2edbff7c 100644 --- a/gral-core/src/main/java/de/erichseifert/gral/plots/PiePlot.java +++ b/gral-core/src/main/java/de/erichseifert/gral/plots/PiePlot.java @@ -915,9 +915,11 @@ public void add(int index, DataSource source, boolean visible) { throw new IllegalArgumentException( "This plot type only supports a single data source."); //$NON-NLS-1$ } - super.add(index, source, visible); + PointRenderer pointRendererDefault = new PieSliceRenderer(this); setPointRenderer(source, pointRendererDefault); + + super.add(index, source, visible); setMapping(source, AXIS_TANGENTIAL); } From cfaa2ddac3b4a63df601d2110ec7c7d52807a04d Mon Sep 17 00:00:00 2001 From: nkaraman Date: Mon, 9 Oct 2017 01:15:07 +0200 Subject: [PATCH 2/2] Fix for break in scaling for some charts --- .../src/main/java/de/erichseifert/gral/plots/PiePlot.java | 4 +--- .../erichseifert/gral/plots/axes/LogarithmicRenderer2D.java | 6 ++++-- .../gral/plots/axes/LogarithmicRenderer2DTest.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gral-core/src/main/java/de/erichseifert/gral/plots/PiePlot.java b/gral-core/src/main/java/de/erichseifert/gral/plots/PiePlot.java index 2edbff7c..bcc829f7 100644 --- a/gral-core/src/main/java/de/erichseifert/gral/plots/PiePlot.java +++ b/gral-core/src/main/java/de/erichseifert/gral/plots/PiePlot.java @@ -915,11 +915,9 @@ public void add(int index, DataSource source, boolean visible) { throw new IllegalArgumentException( "This plot type only supports a single data source."); //$NON-NLS-1$ } - + super.add(index, source, visible); PointRenderer pointRendererDefault = new PieSliceRenderer(this); setPointRenderer(source, pointRendererDefault); - - super.add(index, source, visible); setMapping(source, AXIS_TANGENTIAL); } diff --git a/gral-core/src/main/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2D.java b/gral-core/src/main/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2D.java index 075a7176..edd7d7c0 100644 --- a/gral-core/src/main/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2D.java +++ b/gral-core/src/main/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2D.java @@ -65,8 +65,9 @@ public double worldToView(Axis axis, Number value, boolean extrapolate) { } double minLog = (min > 0.0) ? Math.log10(min) : 0.0; double maxLog = (max > 0.0) ? Math.log10(max) : 1.0; - return (Math.log10(val) - minLog)*getShapeLength() / + double result = (Math.log10(val) - minLog)*getShapeLength() / (maxLog - minLog); + return Double.isFinite(result) ? result : 0; } /** @@ -92,8 +93,9 @@ public Number viewToWorld(Axis axis, double value, boolean extrapolate) { } double minLog = (min > 0.0) ? Math.log10(min) : 0.0; double maxLog = (max > 0.0) ? Math.log10(max) : 1.0; - return Math.pow(10.0, + double result = Math.pow(10.0, value*(maxLog - minLog)/getShapeLength() + minLog); + return Double.isFinite(result) ? result : 0; } @Override diff --git a/gral-core/src/test/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2DTest.java b/gral-core/src/test/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2DTest.java index 5a92ffef..a963010d 100644 --- a/gral-core/src/test/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2DTest.java +++ b/gral-core/src/test/java/de/erichseifert/gral/plots/axes/LogarithmicRenderer2DTest.java @@ -63,7 +63,7 @@ public void testDraw() { @Test public void testWorldToView() { - assertEquals(Double.NEGATIVE_INFINITY, renderer.worldToView(axis, 0.0, true), DELTA); + assertEquals(0, renderer.worldToView(axis, 0.0, true), DELTA); assertEquals(Math.log10( 0.1), renderer.worldToView(axis, 0.1, true), DELTA); assertEquals(Math.log10( 1.0), renderer.worldToView(axis, 1.0, true), DELTA); assertEquals(Math.log10( 5.0), renderer.worldToView(axis, 5.0, true), DELTA);