changeset 7079:7a1db976a80b

RT-37167 [StackedAreaChart,Ensemble8] Stacked Area Chart fill paints above line Reviewed by: dgrieve
author Martin Sladecek <martin.sladecek@oracle.com>
date Tue, 20 May 2014 11:20:45 +0200
parents 701abcfabf03
children 1000cd96bf56
files modules/controls/src/main/java/javafx/scene/chart/Axis.java modules/controls/src/main/java/javafx/scene/chart/CategoryAxis.java modules/controls/src/main/java/javafx/scene/chart/StackedBarChart.java modules/controls/src/main/java/javafx/scene/chart/ValueAxis.java modules/controls/src/test/java/javafx/scene/chart/CategoryAxisTest.java modules/controls/src/test/java/javafx/scene/chart/ValueAxisTest.java
diffstat 6 files changed, 56 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/chart/Axis.java	Tue May 20 11:30:59 2014 +0300
+++ b/modules/controls/src/main/java/javafx/scene/chart/Axis.java	Tue May 20 11:20:45 2014 +0200
@@ -496,10 +496,15 @@
     public abstract double getZeroPosition();
 
     /**
-     * Get the display position along this axis for a given value
+     * Get the display position along this axis for a given value.
+     * If the value is not in the current range, the returned value will be an extrapolation of the display
+     * position.
+     *
+     * If the value is not valid for this Axis and the axis cannot display such value in any range,
+     * Double.NaN is returned
      *
      * @param value The data value to work out display position for
-     * @return display position or Double.NaN if zero is not in current range;
+     * @return display position or Double.NaN if value not valid
      */
     public abstract double getDisplayPosition(T value);
 
--- a/modules/controls/src/main/java/javafx/scene/chart/CategoryAxis.java	Tue May 20 11:30:59 2014 +0300
+++ b/modules/controls/src/main/java/javafx/scene/chart/CategoryAxis.java	Tue May 20 11:20:45 2014 +0200
@@ -455,10 +455,12 @@
     }
 
     /**
-     * Get the display position along this axis for a given value
+     * Get the display position along this axis for a given value.
+     *
+     * If the value is not equal to any of the categories, Double.NaN is returned
      *
      * @param value The data value to work out display position for
-     * @return display position or Double.NaN if zero is not in current range;
+     * @return display position or Double.NaN if value not one of the categories
      */
     @Override public double getDisplayPosition(String value) {
         // find index of value
--- a/modules/controls/src/main/java/javafx/scene/chart/StackedBarChart.java	Tue May 20 11:30:59 2014 +0300
+++ b/modules/controls/src/main/java/javafx/scene/chart/StackedBarChart.java	Tue May 20 11:20:45 2014 +0200
@@ -451,38 +451,21 @@
                         boolean isNegative = bar.getStyleClass().contains("negative");
                         if (!isNegative) {
                             bottom = valueAxis.getDisplayPosition(currentPositiveValue);
-                            if (Double.isNaN(bottom) && currentPositiveValue < lowerBoundValue) {
-                                bottom = valueAxis.getDisplayPosition(lowerBoundValue);
-                            }
                             top = valueAxis.getDisplayPosition(currentPositiveValue + valNumber);
-                            if (Double.isNaN(top) && currentPositiveValue + valNumber > upperBoundValue) {
-                                top = valueAxis.getDisplayPosition(upperBoundValue);
-                            }
                             currentPositiveValue += valNumber;
                         } else {
                             bottom = valueAxis.getDisplayPosition(currentNegativeValue + valNumber);
-                            if (Double.isNaN(bottom) && currentNegativeValue + valNumber < lowerBoundValue) {
-                                bottom = valueAxis.getDisplayPosition(lowerBoundValue);
-                            }
                             top = valueAxis.getDisplayPosition(currentNegativeValue);
-                            if (Double.isNaN(top) && currentNegativeValue > upperBoundValue) {
-                                top = valueAxis.getDisplayPosition(upperBoundValue);
-                            }
                             currentNegativeValue += valNumber;
                         }
 
-                        if (!Double.isNaN(bottom) && !Double.isNaN(top)) {
-                            bar.setVisible(true);
-                            if (orientation == Orientation.VERTICAL) {
-                                bar.resizeRelocate(categoryPos + barOffset,
-                                        top, barWidth, bottom - top);
-                            } else {
-                                bar.resizeRelocate(bottom,
-                                        categoryPos + barOffset,
-                                        top - bottom, barWidth);
-                            }
+                        if (orientation == Orientation.VERTICAL) {
+                            bar.resizeRelocate(categoryPos + barOffset,
+                                    top, barWidth, bottom - top);
                         } else {
-                            bar.setVisible(false);
+                            bar.resizeRelocate(bottom,
+                                    categoryPos + barOffset,
+                                    top - bottom, barWidth);
                         }
                     }
                 }
--- a/modules/controls/src/main/java/javafx/scene/chart/ValueAxis.java	Tue May 20 11:30:59 2014 +0300
+++ b/modules/controls/src/main/java/javafx/scene/chart/ValueAxis.java	Tue May 20 11:20:45 2014 +0200
@@ -441,13 +441,14 @@
     }
 
     /**
-     * Get the display position along this axis for a given value
+     * Get the display position along this axis for a given value.
+     * If the value is not in the current range, the returned value will be an extrapolation of the display
+     * position.
      *
      * @param value The data value to work out display position for
-     * @return display position or Double.NaN if zero is not in current range;
+     * @return display position
      */
     @Override public double getDisplayPosition(T value) {
-        if (value.doubleValue() < getLowerBound() || value.doubleValue() > getUpperBound()) return Double.NaN;
         return Math.round(offset + ((value.doubleValue() - currentLowerBound.get()) * getScale()));
     }
 
--- a/modules/controls/src/test/java/javafx/scene/chart/CategoryAxisTest.java	Tue May 20 11:30:59 2014 +0300
+++ b/modules/controls/src/test/java/javafx/scene/chart/CategoryAxisTest.java	Tue May 20 11:20:45 2014 +0200
@@ -40,6 +40,8 @@
 import org.junit.Before;
 import org.junit.Test;
 
+import java.util.Arrays;
+
 /**
  * All public members of CatgoryAxis are tested here . 
  * @author srikalyc
@@ -254,5 +256,16 @@
         assertSame(axis.getCategories(), list);
     }
 
+    @Test
+    public void testDisplayPositionOfValue() {
+        axis.setCategories(FXCollections.observableArrayList("A", "B", "C", "D"));
+        assertTrue(Double.isFinite(axis.getDisplayPosition("C")));
+    }
+
+    @Test
+    public void testDisplayPositionOfInvalidValue() {
+        axis.setCategories(FXCollections.observableArrayList("A", "B", "C", "D"));
+        assertTrue(Double.isNaN(axis.getDisplayPosition("E")));
+    }
     
 }
--- a/modules/controls/src/test/java/javafx/scene/chart/ValueAxisTest.java	Tue May 20 11:30:59 2014 +0300
+++ b/modules/controls/src/test/java/javafx/scene/chart/ValueAxisTest.java	Tue May 20 11:20:45 2014 +0200
@@ -25,6 +25,7 @@
 
 package javafx.scene.chart;
 
+import javafx.collections.FXCollections;
 import javafx.css.CssMetaData;
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.DoubleProperty;
@@ -363,5 +364,25 @@
         axis.setTickLabelFormatter(formatter);
         assertSame(axis.getTickLabelFormatter(), formatter);
     }
-    
+
+
+    @Test
+    public void testDisplayPositionOfValueInRange() {
+        axis.setLowerBound(0);
+        axis.setUpperBound(10);
+        axis.setScale(1);
+
+        assertEquals(5, axis.getDisplayPosition(5), 1e-10);
+    }
+
+    @Test
+    public void testDisplayPositionOfValueOutOfRange() {
+        axis.setLowerBound(0);
+        axis.setUpperBound(10);
+        axis.setScale(1);
+
+        assertEquals(-1, axis.getDisplayPosition(-1), 1e-10);
+        assertEquals(11, axis.getDisplayPosition(11), 1e-10);
+    }
+
 }