Bug 13807 fixed: Invalid margins when the visibility of figure was to off 97/16597/3
Calixte DENIZET [Wed, 3 Jun 2015 14:19:47 +0000 (16:19 +0200)]
Change-Id: I6994d707392321fb9665fc5afded923d2bc4c545

scilab/CHANGES_5.5.X
scilab/modules/graphics/tests/nonreg_tests/bug_13807.dia.ref [new file with mode: 0644]
scilab/modules/graphics/tests/nonreg_tests/bug_13807.tst [new file with mode: 0644]
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/DrawerVisitor.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/AxesDrawer.java

index 0a0e13a..512f174 100644 (file)
@@ -4,6 +4,8 @@
 Scilab Bug Fixes
 ================
 
+* Bug #13807 fixed - Invalid margins were computed when figure was not visible.
+
 * Bug #13829 fixed - mean and sum functions returned wrong results for hypermatrices.
 
 * Bug #13834 fixed - Drawing a high number of strings in a figure generated a Java exceptions.
diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_13807.dia.ref b/scilab/modules/graphics/tests/nonreg_tests/bug_13807.dia.ref
new file mode 100644 (file)
index 0000000..1526812
--- /dev/null
@@ -0,0 +1,49 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Vincent COUVERT
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- TEST WITH GRAPHIC -->
+// <-- Non-regression test for bug 13807 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/13807
+//
+// <-- Short Description -->
+// Invalid margins when the visibility of figure was to off
+fig = figure("figure_name", "TEST MARGINS", ...
+"dockable", "off", ...
+"axes_size", [950,550], ...
+"infobar_visible", "off", ...
+"toolbar", "none", ...
+"menubar_visible", "on", ...
+"menubar", "none", ...
+"default_axes", "off", ...
+"layout", "border", ...
+"visible", "off");
+f = uicontrol(fig, "style", "frame", ...
+"layout", "gridbag");
+f1 = uicontrol(f, "style", "frame", ...
+"layout", "gridbag", ...
+"constraints", createConstraints("gridbag", [1 1 1 1], [1 1], "both", "left"));
+a1 = newaxes(f1);
+//a1.auto_margins="off";
+a1.filled = "off";
+a1.tag = "axe";
+f2 = uicontrol(f, "style", "frame", ...
+"layout", "gridbag", ...
+"constraints", createConstraints("gridbag", [1 2 1 1], [1 1], "horizontal", "left"));
+uicontrol(f2, "style", "text", ...
+"string", "test", ...
+"layout", "gridbag", ...
+"constraints", createConstraints("gridbag", [1 1 1 1], [1 1], "none", "left"));
+sca(a1);
+plot2d(1:10, 1:10);
+a1.tight_limits = "on";
+a1.x_label.text = "Time (s)";
+a1.x_label.font_size = 2;
+a1.x_location = "top";
+legend("text", -1);
+fig.visible="on";
+// Check that the margins ont the top are visually correct.
diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_13807.tst b/scilab/modules/graphics/tests/nonreg_tests/bug_13807.tst
new file mode 100644 (file)
index 0000000..c0fd853
--- /dev/null
@@ -0,0 +1,58 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Vincent COUVERT
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- TEST WITH GRAPHIC -->
+
+// <-- Non-regression test for bug 13807 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/13807
+//
+// <-- Short Description -->
+// Invalid margins when the visibility of figure was to off
+
+fig = figure("figure_name", "TEST MARGINS", ...
+"dockable", "off", ...
+"axes_size", [950,550], ...
+"infobar_visible", "off", ...
+"toolbar", "none", ...
+"menubar_visible", "on", ...
+"menubar", "none", ...
+"default_axes", "off", ...
+"layout", "border", ...
+"visible", "off");
+
+f = uicontrol(fig, "style", "frame", ...
+"layout", "gridbag");
+
+f1 = uicontrol(f, "style", "frame", ...
+"layout", "gridbag", ...
+"constraints", createConstraints("gridbag", [1 1 1 1], [1 1], "both", "left"));
+a1 = newaxes(f1);
+//a1.auto_margins="off";
+a1.filled = "off";
+a1.tag = "axe";
+
+f2 = uicontrol(f, "style", "frame", ...
+"layout", "gridbag", ...
+"constraints", createConstraints("gridbag", [1 2 1 1], [1 1], "horizontal", "left"));
+uicontrol(f2, "style", "text", ...
+"string", "test", ...
+"layout", "gridbag", ...
+"constraints", createConstraints("gridbag", [1 1 1 1], [1 1], "none", "left"));
+
+sca(a1);
+plot2d(1:10, 1:10);
+a1.tight_limits = "on";
+a1.x_label.text = "Time (s)";
+a1.x_label.font_size = 2;
+a1.x_location = "top";
+legend("text", -1);
+fig.visible="on";
+
+// Check that the margins ont the top are visually correct.
+
index 20a1985..486d4ea 100755 (executable)
@@ -1031,7 +1031,7 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
         GraphicObject object = GraphicController.getController().getObjectFromId(id);
         int objectType = (Integer) GraphicController.getController().getProperty(id, GraphicObjectProperties.__GO_TYPE__);
         int objectStyle = (objectType == GraphicObjectProperties.__GO_UICONTROL__ ? (Integer) GraphicController.getController().getProperty(id, GraphicObjectProperties.__GO_STYLE__) : -1);
-        if ((object != null) && isFigureChild(id) || (objectType == GraphicObjectProperties.__GO_UICONTROL__ && objectStyle == GraphicObjectProperties.__GO_UI_FRAME__)
+        if ((object != null) && (isFigureChild(id) || isFigureParent(id)) || (objectType == GraphicObjectProperties.__GO_UICONTROL__ && objectStyle == GraphicObjectProperties.__GO_UI_FRAME__)
                 && objectType != GraphicObjectProperties.__GO_UIMENU__ && objectType != GraphicObjectProperties.__GO_UI_FRAME_BORDER__) {
 
             if (GraphicObjectProperties.__GO_VALID__ == property) {
@@ -1078,11 +1078,12 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
                 if (property == GraphicObjectProperties.__GO_SIZE__
                         || property == GraphicObjectProperties.__GO_AXES_SIZE__
                         || property == GraphicObjectProperties.__GO_CHILDREN__
-                        || property == GraphicObjectProperties.__GO_POSITION__) {
-                    Figure fig = (Figure) object;
-                    for (Integer gid : fig.getChildren()) {
+                        || property == GraphicObjectProperties.__GO_POSITION__
+                        || property == GraphicObjectProperties.__GO_VISIBLE__) {
+                    for (Integer gid : figure.getChildren()) {
                         GraphicObject go = GraphicController.getController().getObjectFromId(gid);
                         if (go instanceof Axes) {
+                            axesDrawer.computeMargins((Axes) go);
                             axesDrawer.computeRulers((Axes) go);
                         }
                     }
@@ -1183,6 +1184,28 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
     }
 
     /**
+     * Check if the given id correspond to a parent of the current {@see Figure}.
+     * @param id the given id.
+     * @return true if the given id correspond to a parent of the current {@see Figure}.
+     */
+    private boolean isFigureParent(Integer id) {
+        GraphicObject object = GraphicController.getController().getObjectFromId(id);
+        if (object != null) {
+            Object parentObject = GraphicController.getController().getProperty(figure.getIdentifier(), GraphicObjectProperties.__GO_PARENT__);
+            Integer parentUID = parentObject == null ? 0 : (Integer) parentObject;
+            while (parentUID.intValue() != 0) {
+                if (parentUID.intValue() == id.intValue()) {
+                    return true;
+                }
+                parentObject = GraphicController.getController().getProperty(parentUID, GraphicObjectProperties.__GO_PARENT__);
+                parentUID = parentObject == null ? 0 : (Integer) parentObject;
+            }
+        }
+
+        return false;
+    }
+
+    /**
      * Check if the given id correspond to a child of the current {@see Figure}.
      * @param id the given id.
      * @return true if the given id correspond to a child of the current {@see Figure}.
index 76fa620..2e5a61f 100644 (file)
@@ -193,123 +193,125 @@ public class AxesDrawer {
 
             Dimension[] marginLabels = labelManager.getLabelsSize(colorMap, axes, this);
             Integer[] size = {visitor.getCanvas().getWidth(), visitor.getCanvas().getHeight()};
-            // [x_left, y_up, w, h]
-            Double[] axesBounds = axes.getAxesBounds();
-            // [l, r, t, b]
-            Double[] margins = axes.getMargins();
-            // m is a copy of margins
-            Double[] mt = new Double[] { 0., 0., 0., 0. };
-            Double[] ml = new Double[] { 0., 0., 0., 0. };
-            Double[] ma = new Double[] { 0., 0., 0., 0. };
-            Double[] m = new Double[] { 0., 0., 0., 0. };
-            AxisProperty.AxisLocation xloc = axes.getXAxis().getAxisLocation();
-            AxisProperty.AxisLocation yloc = axes.getYAxis().getAxisLocation();
-            final double DEFAULT_MARGIN = 0.125;
-
-            // We compute the adapted margins for axes titles.
-            if (marginLabels[0].height != 0 || marginLabels[2].height != 0 || marginLabels[1].width != 0) {
-                if (marginLabels[2].height != 0) {
-                    final double th = (marginLabels[2].height + 2 + TitlePositioner.TITLEOFFSET) / (size[1] * axesBounds[3]);
-                    mt[2] = th;
-                }
+            if (size[0] != 0 && size[1] != 0) {
+                // [x_left, y_up, w, h]
+                Double[] axesBounds = axes.getAxesBounds();
+                // [l, r, t, b]
+                Double[] margins = axes.getMargins();
+                // m is a copy of margins
+                Double[] mt = new Double[] { 0., 0., 0., 0. };
+                Double[] ml = new Double[] { 0., 0., 0., 0. };
+                Double[] ma = new Double[] { 0., 0., 0., 0. };
+                Double[] m = new Double[] { 0., 0., 0., 0. };
+                AxisProperty.AxisLocation xloc = axes.getXAxis().getAxisLocation();
+                AxisProperty.AxisLocation yloc = axes.getYAxis().getAxisLocation();
+                final double DEFAULT_MARGIN = 0.125;
+
+                // We compute the adapted margins for axes titles.
+                if (marginLabels[0].height != 0 || marginLabels[2].height != 0 || marginLabels[1].width != 0) {
+                    if (marginLabels[2].height != 0) {
+                        final double th = (marginLabels[2].height + 2 + TitlePositioner.TITLEOFFSET) / (size[1] * axesBounds[3]);
+                        mt[2] = th;
+                    }
 
-                if (marginLabels[0].height != 0 && (xloc == AxisProperty.AxisLocation.BOTTOM || xloc == AxisProperty.AxisLocation.TOP)) {
-                    final double xh = (marginLabels[0].height + 2) / (size[1] * axesBounds[3]);
-                    if (xloc == AxisProperty.AxisLocation.BOTTOM) {
-                        mt[3] = xh;
-                    } else {
-                        mt[2] += xh;
+                    if (marginLabels[0].height != 0 && (xloc == AxisProperty.AxisLocation.BOTTOM || xloc == AxisProperty.AxisLocation.TOP)) {
+                        final double xh = (marginLabels[0].height + 2) / (size[1] * axesBounds[3]);
+                        if (xloc == AxisProperty.AxisLocation.BOTTOM) {
+                            mt[3] = xh;
+                        } else {
+                            mt[2] += xh;
+                        }
                     }
-                }
 
-                if (marginLabels[1].width != 0 && (yloc == AxisProperty.AxisLocation.LEFT || yloc == AxisProperty.AxisLocation.RIGHT)) {
-                    final double yh = (marginLabels[1].width + 2) / (size[0] * axesBounds[2]);
-                    if (yloc == AxisProperty.AxisLocation.LEFT) {
-                        mt[0] = yh;
-                    } else {
-                        mt[1] = yh;
+                    if (marginLabels[1].width != 0 && (yloc == AxisProperty.AxisLocation.LEFT || yloc == AxisProperty.AxisLocation.RIGHT)) {
+                        final double yh = (marginLabels[1].width + 2) / (size[0] * axesBounds[2]);
+                        if (yloc == AxisProperty.AxisLocation.LEFT) {
+                            mt[0] = yh;
+                        } else {
+                            mt[1] = yh;
+                        }
                     }
                 }
-            }
 
-            //computeRulers(axes);
-            final double xratio = rulerDrawer.getRulerDrawer(axes, 0).getDistanceRatio();
-            final double yratio = rulerDrawer.getRulerDrawer(axes, 1).getDistanceRatio();
+                //computeRulers(axes);
+                final double xratio = rulerDrawer.getRulerDrawer(axes, 0).getDistanceRatio();
+                final double yratio = rulerDrawer.getRulerDrawer(axes, 1).getDistanceRatio();
 
-            if (xloc == AxisProperty.AxisLocation.BOTTOM) {
-                ma[3] = (1 - margins[2] - margins[3]) * xratio / 2.;
-            } else if (xloc == AxisProperty.AxisLocation.TOP) {
-                ma[2] = (1 - margins[2] - margins[3]) * xratio / 2.;
-            }
+                if (xloc == AxisProperty.AxisLocation.BOTTOM) {
+                    ma[3] = (1 - margins[2] - margins[3]) * xratio / 2.;
+                } else if (xloc == AxisProperty.AxisLocation.TOP) {
+                    ma[2] = (1 - margins[2] - margins[3]) * xratio / 2.;
+                }
 
-            if (yloc == AxisProperty.AxisLocation.LEFT) {
-                ma[0] = (1 - margins[0] - margins[1]) * yratio / 2.;
-            } else if (yloc == AxisProperty.AxisLocation.RIGHT) {
-                ma[1] = (1 - margins[0] - margins[1]) * yratio / 2.;
-            }
+                if (yloc == AxisProperty.AxisLocation.LEFT) {
+                    ma[0] = (1 - margins[0] - margins[1]) * yratio / 2.;
+                } else if (yloc == AxisProperty.AxisLocation.RIGHT) {
+                    ma[1] = (1 - margins[0] - margins[1]) * yratio / 2.;
+                }
 
-            // Get the legend if any (only one ???)
-            if (axes.getChildren() != null) {
-                for (Integer i : axes.getChildren()) {
-                    GraphicObject child = GraphicController.getController().getObjectFromId(i);
-                    if (child instanceof Legend) {
-                        Legend legend = (Legend) child;
-                        Dimension legDims = visitor.getLegendDrawer().computeDimensions(axes, legend);
-                        if (legDims != null) {
-                            LegendLocation legLoc = legend.getLegendLocationAsEnum();
-                            double C;
-                            /*
-                             * Legends dimension are linearly dependent of margins... so we need to solve an equation
-                             * to find a good value for margins.
-                             * For example:
-                             *  legend.w = texture.w + 3/8 * line.w + line.w
-                             *  where line.w = LINE_WIDTH * ab[2] * (1 - m[0] - m[1]) * size[0];
-                             *  the minimal value for m[1] is the solution of the equation (where unknown is m[1]):
-                             *   legend.w = ab[2] * m[1] * size[0].
-                             */
-                            switch (legLoc) {
-                                case OUT_UPPER_RIGHT:
-                                case OUT_LOWER_RIGHT:
-                                    // 1/8 of LINE_WIDTH is xOffset
-                                    // see legendDims[0] = ... in LegendDrawer::draw
-                                    // we add 2*xoffset to have a little space around the box
-                                    C = legend.getLineWidth() + LegendDrawer.LINE_WIDTH * (3. / 8. + 2. / 8.);
-                                    m[0] = Math.max(ma[0] + mt[0], DEFAULT_MARGIN);
-                                    m[1] = Math.max(((legDims.width + 2) / (axesBounds[2] * size[0]) + C * (1 - m[0])) / (1 + C) + ma[1] + mt[1], DEFAULT_MARGIN);
-                                    break;
-                                case OUT_UPPER_LEFT:
-                                case OUT_LOWER_LEFT:
-                                    C = legend.getLineWidth() + LegendDrawer.LINE_WIDTH * (3. / 8. + 2. / 8.);
-                                    m[1] = Math.max(ma[1] + mt[1], DEFAULT_MARGIN);
-                                    m[0] = Math.max(((legDims.width + 2) / (axesBounds[2] * size[0]) + C * (1 - m[1])) / (1 + C) + ma[0] + mt[0], DEFAULT_MARGIN);
-                                    break;
-                                case UPPER_CAPTION:
-                                    C = LegendDrawer.Y_OFFSET * (3. + 2.);
-                                    m[3] = Math.max(ma[3] + mt[3], DEFAULT_MARGIN);
-                                    m[2] = Math.max(Math.max(((legDims.height + 2) / (axesBounds[3] * size[1]) + C * (1 - m[3])) / (1 + C), mt[2]) + ma[2], DEFAULT_MARGIN);
-                                    break;
-                                case LOWER_CAPTION:
-                                    C = LegendDrawer.Y_OFFSET * (3. + 2.);
-                                    m[2] = Math.max(ma[2] + mt[2], DEFAULT_MARGIN);
-                                    m[3] = Math.max(Math.max(((legDims.height + 2) / (axesBounds[3] * size[1]) + C * (1 - m[2])) / (1 + C), mt[3]) + ma[3], DEFAULT_MARGIN);
-                                    break;
-                                default:
+                // Get the legend if any (only one ???)
+                if (axes.getChildren() != null) {
+                    for (Integer i : axes.getChildren()) {
+                        GraphicObject child = GraphicController.getController().getObjectFromId(i);
+                        if (child instanceof Legend) {
+                            Legend legend = (Legend) child;
+                            Dimension legDims = visitor.getLegendDrawer().computeDimensions(axes, legend);
+                            if (legDims != null) {
+                                LegendLocation legLoc = legend.getLegendLocationAsEnum();
+                                double C;
+                                /*
+                                 * Legends dimension are linearly dependent of margins... so we need to solve an equation
+                                 * to find a good value for margins.
+                                 * For example:
+                                 *  legend.w = texture.w + 3/8 * line.w + line.w
+                                 *  where line.w = LINE_WIDTH * ab[2] * (1 - m[0] - m[1]) * size[0];
+                                 *  the minimal value for m[1] is the solution of the equation (where unknown is m[1]):
+                                 *   legend.w = ab[2] * m[1] * size[0].
+                                 */
+                                switch (legLoc) {
+                                    case OUT_UPPER_RIGHT:
+                                    case OUT_LOWER_RIGHT:
+                                        // 1/8 of LINE_WIDTH is xOffset
+                                        // see legendDims[0] = ... in LegendDrawer::draw
+                                        // we add 2*xoffset to have a little space around the box
+                                        C = legend.getLineWidth() + LegendDrawer.LINE_WIDTH * (3. / 8. + 2. / 8.);
+                                        m[0] = Math.max(ma[0] + mt[0], DEFAULT_MARGIN);
+                                        m[1] = Math.max(((legDims.width + 2) / (axesBounds[2] * size[0]) + C * (1 - m[0])) / (1 + C) + ma[1] + mt[1], DEFAULT_MARGIN);
+                                        break;
+                                    case OUT_UPPER_LEFT:
+                                    case OUT_LOWER_LEFT:
+                                        C = legend.getLineWidth() + LegendDrawer.LINE_WIDTH * (3. / 8. + 2. / 8.);
+                                        m[1] = Math.max(ma[1] + mt[1], DEFAULT_MARGIN);
+                                        m[0] = Math.max(((legDims.width + 2) / (axesBounds[2] * size[0]) + C * (1 - m[1])) / (1 + C) + ma[0] + mt[0], DEFAULT_MARGIN);
+                                        break;
+                                    case UPPER_CAPTION:
+                                        C = LegendDrawer.Y_OFFSET * (3. + 2.);
+                                        m[3] = Math.max(ma[3] + mt[3], DEFAULT_MARGIN);
+                                        m[2] = Math.max(Math.max(((legDims.height + 2) / (axesBounds[3] * size[1]) + C * (1 - m[3])) / (1 + C), mt[2]) + ma[2], DEFAULT_MARGIN);
+                                        break;
+                                    case LOWER_CAPTION:
+                                        C = LegendDrawer.Y_OFFSET * (3. + 2.);
+                                        m[2] = Math.max(ma[2] + mt[2], DEFAULT_MARGIN);
+                                        m[3] = Math.max(Math.max(((legDims.height + 2) / (axesBounds[3] * size[1]) + C * (1 - m[2])) / (1 + C), mt[3]) + ma[3], DEFAULT_MARGIN);
+                                        break;
+                                    default:
+                                }
                             }
+                            break;
                         }
-                        break;
                     }
                 }
-            }
 
-            for (int i = 0; i < m.length; i++) {
-                if (m[i] == 0) {
-                    m[i] = Math.max(ma[i] + mt[i], DEFAULT_MARGIN);
+                for (int i = 0; i < m.length; i++) {
+                    if (m[i] == 0) {
+                        m[i] = Math.max(ma[i] + mt[i], DEFAULT_MARGIN);
+                    }
                 }
-            }
 
-            if (!m[0].equals(margins[0]) || !m[1].equals(margins[1]) || !m[2].equals(margins[2]) || !m[3].equals(margins[3])) {
-                axes.setMargins(m);
-                //computeRulers(axes);
+                if (!m[0].equals(margins[0]) || !m[1].equals(margins[1]) || !m[2].equals(margins[2]) || !m[3].equals(margins[3])) {
+                    axes.setMargins(m);
+                    //computeRulers(axes);
+                }
             }
         }
     }