From: Caio SOUZA Date: Wed, 29 Jun 2016 16:49:02 +0000 (-0300) Subject: * [Bug #14632] fixed - Zooming moves drawn axis offscreen X-Git-Tag: 6.0.0~526 X-Git-Url: http://gitweb.scilab.org/?p=scilab.git;a=commitdiff_plain;h=2babc1beafb15314035dc45606125ceff8b7d9ea * [Bug #14632] fixed - Zooming moves drawn axis offscreen Change-Id: I6761803542870b223d4579788af4ace7e7e110da --- diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index ab822b2..d947ab5 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -272,6 +272,7 @@ Bug Fixes * [Bug #14590](http://bugzilla.scilab.org/show_bug.cgi?id=14590) fixed - Help pages in pt_BR directories had a wrong xml:lang="en" tag. * [Bug #14593](http://bugzilla.scilab.org/show_bug.cgi?id=14593) fixed - Signs are no more drawn in BIGSOM and PRODUCT components. * [Bug #14602](http://bugzilla.scilab.org/show_bug.cgi?id=14602) fixed - WRITEC_f block didn't work for x86 machines. +* [Bug #14632](http://bugzilla.scilab.org/show_bug.cgi?id=14632) fixed - Zooming moves drawn axis offscreen * [Bug #14640](http://bugzilla.scilab.org/show_bug.cgi?id=14640) fixed - `median(int8([10 60 80 100]))` returned -58 instead of 70 due to overflow when interpolating (60+80)>128 * [Bug #14648](http://bugzilla.scilab.org/show_bug.cgi?id=14648) fixed - `isinf` returned `%F` for complex numbers with both real and imag infinite parts. * [Bug #14649](http://bugzilla.scilab.org/show_bug.cgi?id=14649) fixed - isnan(complex(%inf, %inf)) returned %F while the phase is NaN. diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/AxisDrawer.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/AxisDrawer.java index f66e778..3a4f60d 100644 --- a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/AxisDrawer.java +++ b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/AxisDrawer.java @@ -70,7 +70,7 @@ public class AxisDrawer { Double[] yTicksValues; double[] xMinAndMax; double[] yMinAndMax; - double[][] factors = axes.getScaleTranslateFactors(); + double[][] factors = calcCorrectedFactors(axes, axis); if (axis.getXTicksCoords().length == 1) { xTicksValues = axis.getXTicksCoords(); @@ -119,6 +119,67 @@ public class AxisDrawer { } /** + * Calculates corrected axes factors when zoom is enabled + * @param axes the given axes + * @param axis the given axis + * @return corrected factors + */ + private double[][] calcCorrectedFactors(Axes axes, Axis axis) { + Double [] bounds = axes.getDisplayedBounds(); + + double[][] zoomFactors = new double[2][]; + zoomFactors[0] = new double[] { 2 / (bounds[1] - bounds[0]), + 2 / (bounds[3] - bounds[2]), + 2 / (bounds[5] - bounds[4]) + }; + zoomFactors[1] = new double[] { -(bounds[1] + bounds[0]) / (bounds[1] - bounds[0]), + -(bounds[3] + bounds[2]) / (bounds[3] - bounds[2]), + -(bounds[5] + bounds[4]) / (bounds[5] - bounds[4]) + }; + double[][] factors = axes.getScaleTranslateFactors(); + //Z coordinate + double scale = factors[0][2] / (zoomFactors[0][2] == 0.0 ? 1.0 : zoomFactors[0][2]); + double invScale = zoomFactors[0][2] / (factors[0][2] == 0.0 ? 1.0 : factors[0][2]); + factors[0][2] *= scale; + factors[1][2] = scale * (factors[1][2] + (invScale * factors[1][2] - zoomFactors[1][2])); + + + + if (axis.getYNumberTicks() == 1 || isConst(axis.getYTicksCoords())) { + scale = factors[0][1] / (zoomFactors[0][1] == 0.0 ? 1.0 : zoomFactors[0][1]); + invScale = zoomFactors[0][1] / (factors[0][1] == 0.0 ? 1.0 : factors[0][1]); + factors[0][1] *= scale; + factors[1][1] = scale * (factors[1][1] + (invScale * factors[1][1] - zoomFactors[1][1])); + } + + if (axis.getXNumberTicks() == 1 || isConst(axis.getXTicksCoords())) { + scale = factors[0][0] / (zoomFactors[0][0] == 0.0 ? 1.0 : zoomFactors[0][0]); + invScale = zoomFactors[0][0] / (factors[0][0] == 0.0 ? 1.0 : factors[0][0]); + factors[0][0] *= scale; + factors[1][0] = scale * (factors[1][0] + (invScale * factors[1][0] - zoomFactors[1][0])); + } + + return factors; + } + + /** + * Checks if the given array have all its values equal(constant) + * @param data the given array + * @return true if it is constant, false otherwise + */ + private boolean isConst(Double[] data) { + if (data.length > 0) { + double d = data[0]; + for (int i = 0; i < data.length; i++) { + if (data[i] != d) { + return false; + } + } + } + return true; + } + + /** * Return [min, max] the minimum and maximum of given values. * @param values the given value. * @return [min, max] the minimum and maximum of given values.