< prev index next >

modules/javafx.controls/src/main/java/javafx/scene/chart/ValueAxis.java

Print this page

        

@@ -354,27 +354,24 @@
             // update current lower bound
             currentLowerBound.set(getLowerBound());
         }
         // we have done all auto calcs, let Axis position major tickmarks
         super.layoutChildren();
+        int numMinorTicks = (getTickMarks().size() - 1)*(Math.max(1, getMinorTickCount()) - 1);
+        double neededLength = (getTickMarks().size()+numMinorTicks)*2;
 
         // Update minor tickmarks
         minorTickPath.getElements().clear();
+        // Don't draw minor tick marks if there isn't enough space for them!
 
         double minorTickLength = Math.max(0, getMinorTickLength());
-        // The length must be greater then the space required for tick marks, otherwise, there's no reason to create
-        // minor tick marks
-        if (minorTickLength > 0 && length > 2 * getTickMarks().size()) {
-            // Strip factor is >= 1. When == 1, all minor ticks will fit.
-            // It's computed as number of minor tick marks divided by available length
-            int stripFactor = (int)Math.ceil(2 * minorTickMarkValues.size() / (length - 2 * getTickMarks().size()));
+        if (minorTickLength > 0 && length > neededLength) {
             if (Side.LEFT.equals(side)) {
                 // snap minorTickPath to pixels
                 minorTickPath.setLayoutX(-0.5);
                 minorTickPath.setLayoutY(0.5);
-                for (int i = 0; i < minorTickMarkValues.size(); i += stripFactor) {
-                    T value = minorTickMarkValues.get(i);
+                for (T value : minorTickMarkValues) {
                     double y = getDisplayPosition(value);
                     if (y >= 0 && y <= length) {
                         minorTickPath.getElements().addAll(
                                 new MoveTo(getWidth() - minorTickLength, y),
                                 new LineTo(getWidth() - 1, y));

@@ -382,12 +379,11 @@
                 }
             } else if (Side.RIGHT.equals(side)) {
                 // snap minorTickPath to pixels
                 minorTickPath.setLayoutX(0.5);
                 minorTickPath.setLayoutY(0.5);
-                for (int i = 0; i < minorTickMarkValues.size(); i += stripFactor) {
-                    T value = minorTickMarkValues.get(i);
+                for (T value : minorTickMarkValues) {
                     double y = getDisplayPosition(value);
                     if (y >= 0 && y <= length) {
                         minorTickPath.getElements().addAll(
                                 new MoveTo(1, y),
                                 new LineTo(minorTickLength, y));

@@ -395,12 +391,11 @@
                 }
             } else if (Side.TOP.equals(side)) {
                 // snap minorTickPath to pixels
                 minorTickPath.setLayoutX(0.5);
                 minorTickPath.setLayoutY(-0.5);
-                for (int i = 0; i < minorTickMarkValues.size(); i += stripFactor) {
-                    T value = minorTickMarkValues.get(i);
+                for (T value : minorTickMarkValues) {
                     double x = getDisplayPosition(value);
                     if (x >= 0 && x <= length) {
                         minorTickPath.getElements().addAll(
                                 new MoveTo(x, getHeight() - 1),
                                 new LineTo(x, getHeight() - minorTickLength));

@@ -408,12 +403,11 @@
                 }
             } else { // BOTTOM
                 // snap minorTickPath to pixels
                 minorTickPath.setLayoutX(0.5);
                 minorTickPath.setLayoutY(0.5);
-                for (int i = 0; i < minorTickMarkValues.size(); i += stripFactor) {
-                    T value = minorTickMarkValues.get(i);
+                for (T value : minorTickMarkValues) {
                     double x = getDisplayPosition(value);
                     if (x >= 0 && x <= length) {
                         minorTickPath.getElements().addAll(
                                 new MoveTo(x, 1.0F),
                                 new LineTo(x, minorTickLength));
< prev index next >