changeset 1453:a6dd0e5c4451

fix RT-21141 XYChart changes categories order spontaneously on Remove DataItem
author Paru Somashekar <paru.somashekar@oracle.com>
date Mon, 16 Jul 2012 10:34:22 -0700
parents 7e06dda995b5
children 264470ba524e
files javafx-ui-controls/src/javafx/scene/chart/CategoryAxis.java
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/javafx/scene/chart/CategoryAxis.java	Mon Jul 16 18:57:33 2012 +0200
+++ b/javafx-ui-controls/src/javafx/scene/chart/CategoryAxis.java	Mon Jul 16 10:34:22 2012 -0700
@@ -269,6 +269,7 @@
     @Override protected void setRange(Object range, boolean animate) {
         Object[] rangeArray = (Object[]) range;
         @SuppressWarnings({"unchecked"}) List<String> categories = (List<String>)rangeArray[0];
+//        if (categories.isEmpty()) new java.lang.Throwable().printStackTrace();
         double newCategorySpacing = (Double)rangeArray[1];
         double newFirstCategoryPos = (Double)rangeArray[2];
         double tickLabelRotation = (Double)rangeArray[3];
@@ -383,9 +384,19 @@
      */
     @Override public void invalidateRange(List<String> data) {
         super.invalidateRange(data);
-        // Create unique set of category names
+        // Create unique set of category names        
         LinkedHashSet<String> categoryNames = new LinkedHashSet<String>();
-        categoryNames.addAll(data);
+        categoryNames.addAll(allDataCategories);
+        //RT-21141 allDataCategories needs to be updated based on data -
+        // and should maintain the order it originally had for the categories already present.
+        // and remove categories not present in data
+        for(String cat : allDataCategories) {
+            if (!data.contains(cat)) categoryNames.remove(cat); 
+        }
+        // add any new category found in data
+        for(String cat : data) {
+            if (!categoryNames.contains(cat)) categoryNames.add(cat);
+        }
         allDataCategories.clear();
         allDataCategories.addAll(categoryNames);
     }