* Bug #8990 fixed - A zoom_auto feature was missing on the plot toolbar. 74/16674/4
Clément DAVID [Thu, 11 Jun 2015 13:08:56 +0000 (15:08 +0200)]
This commit implement a zoom_auto (similar to zoom_rect) that handle
both zoom_box and data_bounds to try to make visible all the objects on
the current figure.

Change-Id: I28e69850be1d57b2d20d7bb759299ad84eec62d2

scilab/CHANGES_5.5.X
scilab/modules/graphics/help/en_US/axes_operations/zoom_auto.xml [new file with mode: 0644]
scilab/modules/graphics/macros/zoom_auto.sci [new file with mode: 0644]
scilab/modules/gui/etc/graphics_menubar.xml
scilab/modules/gui/etc/graphics_toolbar.xml

index fc04a02..93dedf0 100644 (file)
@@ -4,6 +4,8 @@
 Scilab Bug Fixes
 ================
 
+* Bug #8990 fixed - zoom_auto feature was missing on the plot toolbar.
+
 * Bug #13807 fixed - Invalid margins were computed when figure was not visible.
 
 * Bug #13829 fixed - mean and sum functions returned wrong results for hypermatrices.
diff --git a/scilab/modules/graphics/help/en_US/axes_operations/zoom_auto.xml b/scilab/modules/graphics/help/en_US/axes_operations/zoom_auto.xml
new file mode 100644 (file)
index 0000000..f9cf916
--- /dev/null
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * This help file was generated from zoom_auto.sci using help_from_sci().
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="zoom_auto" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns3="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:scilab="http://www.scilab.org"
+          xmlns:db="http://docbook.org/ns/docbook">
+    
+    <refnamediv>
+        <refname>zoom_auto</refname>
+        <refpurpose>Zoom automatically to the visible values of all axes of the figure</refpurpose>
+    </refnamediv>
+    
+    
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>
+            zoom_auto()
+            zoom_auto(h)
+            
+        </synopsis>
+    </refsynopsisdiv>
+    
+    <refsection>
+        <title>Parameters</title>
+        <variablelist>
+            <varlistentry>
+                <term>h:</term>
+                <listitem>
+                    <para> A Figure or Axes handle to zoom automatically</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    
+    <refsection>
+        <title>Description</title>
+        <para>
+            This function update the zoom_box of all axes of the figure when there is
+            some zoom applied to it or update the data bounds otherwise. After the call
+            the user will be able to view all visible data even if mis-configured
+            something.
+        </para>
+        <para>
+        </para>
+    </refsection>
+    
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+plot3d();
+a=gca();
+// hide some data to the user
+a.data_bounds = [-1 -1 -0.5 ; 1 1 0.5]
+sleep(1000)
+// let the user view the whole dataset
+zoom_auto()
+
+   ]]></programlisting>
+    </refsection>
+    
+    <refsection>
+        <title>See also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="zoom_rect">zoom_rect</link>
+            </member>
+            <member>
+                <link linkend="unzoom">unzoom</link>
+            </member>
+            <member>
+                <link linkend="axes_properties">axes_properties</link>
+            </member>
+        </simplelist>
+    </refsection>
+    
+    <refsection>
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.5.3</revnumber>
+                <revremark>
+                    Function <function>zoom_auto</function> introduced.
+                </revremark>
+            </revision>
+        </revhistory>
+    </refsection>
+</refentry>
diff --git a/scilab/modules/graphics/macros/zoom_auto.sci b/scilab/modules/graphics/macros/zoom_auto.sci
new file mode 100644 (file)
index 0000000..432e27f
--- /dev/null
@@ -0,0 +1,211 @@
+function zoom_auto(h)
+    // Zoom automatically to the visible values of all axes of the figure
+    //
+    // Calling Sequence
+    //   zoom_auto()
+    //   zoom_auto(h)
+    //
+    // Parameters
+    // h: A Figure or Axes handle to zoom automatically
+    //
+    // Description
+    // This function update the zoom_box of all axes of the figure when there is
+    // some zoom applied to it or update the data bounds otherwise. After the call
+    // the user will be able to view all visible data even if mis-configured
+    // something.
+    //
+    // Examples
+    // plot3d();
+    // a=gca();
+    // // hide some data to the user
+    // a.data_bounds = [-1 -1 -0.5 ; 1 1 0.5]
+    // sleep(1000)
+    // // let the user view the whole dataset
+    // zoom_auto()
+    //
+    // See also
+    //  zoom_rect
+    //  unzoom
+    //  axes_properties
+    //
+    // Authors
+    //  Clement DAVID - Scilab Enterprises
+
+    rhs=argn(2);
+    if rhs>1 then
+        error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"), "zoom_auto", 0, 1));
+    end
+
+    if (rhs == 0) then
+        h=gcf();
+    end
+    if typeof(h)<>"handle" then
+        error(sprintf(gettext("%s: Wrong type for argument %d: a handle expected.\n"), "zoom_auto", 1));
+    end
+    if size(h, "*")<>1 then
+        error(sprintf(gettext("%s: Wrong size for input argument #%d: a handle expected.\n"), "zoom_auto" , 1));
+    end
+
+    visit(h, [0 0 0 ; 0 0 0])
+endfunction
+
+function [bounds]=visit(e, bounds)
+    if isempty(e) then
+        pause,
+    end
+    execstr("bounds=visit"+e.Type+"(e, bounds);");
+endfunction
+
+function [bounds]=visitFigure(e, bounds)
+    for i=1:length(e.children)
+        a=e.children(i);
+        bounds = visit(a, bounds);
+
+        if (a.zoom_state == "off") then
+            a.data_bounds=bounds;
+        else
+            // the weird definition of zoom_box enforce us to perfom a projection
+            M=[1 0 0 0 0 0 ;..
+            0 0 1 0 0 0 ;..
+            0 1 0 0 0 0 ;..
+            0 0 0 1 0 0 ;..
+            0 0 0 0 1 0 ;..
+            0 0 0 0 0 1 ];
+            a.zoom_box= M * bounds(:);
+        end
+    end
+endfunction
+
+function [bounds]=visitAxes(e, bounds)
+    children = e.children;
+    for i=1:length(children)
+        bounds = visit(children(i), bounds);
+    end
+endfunction
+
+function [bounds]=visitCompound(e, bounds)
+    children = e.children;
+    for i=1:length(children)
+        bounds = visit(children(i), bounds);
+    end
+endfunction
+
+function [bounds]=visitAxis(e, bounds)
+    bounds(1,1)=min([a1.xtics_coord , bounds(1,1)]);
+    bounds(2,1)=max([a1.xtics_coord , bounds(2,1)]);
+    bounds(1,2)=min([a1.ytics_coord , bounds(1,2)]);
+    bounds(2,2)=max([a1.ytics_coord , bounds(2,2)]);
+endfunction
+
+function [bounds]=visitPolyline(e, bounds)
+    data = e.data;
+
+    bounds(1,1)=min([data(:,1) ; bounds(1,1)]);
+    bounds(2,1)=max([data(:,1) ; bounds(2,1)]);
+    bounds(1,2)=min([data(:,2) ; bounds(1,2)]);
+    bounds(2,2)=max([data(:,2) ; bounds(2,2)]);
+    if (size(data,"c") > 2) then
+        bounds(1,3)=min([data(:,3) ; bounds(1,3)]);
+        bounds(2,3)=max([data(:,3) ; bounds(2,3)]);
+    end
+endfunction
+
+function [bounds]=visitArc(e, bounds)
+    data = e.data;
+
+    bounds(1,1)=min([data(1) ; bounds(1,1)]);
+    bounds(2,1)=max([data(1)+data(3) ; bounds(2,1)]);
+    bounds(1,2)=min([data(2)-data(4) ; bounds(1,2)]);
+    bounds(2,2)=max([data(2) ; bounds(2,2)]);
+endfunction
+
+function [bounds]=visitRectangle(e, bounds)
+    data = e.data;
+
+    bounds(1,1)=min([data(1) ; bounds(1,1)]);
+    bounds(2,1)=max([data(1)+data(3) ; bounds(2,1)]);
+    bounds(1,2)=min([data(2)-data(4) ; bounds(1,2)]);
+    bounds(2,2)=max([data(2) ; bounds(2,2)]);
+endfunction
+
+function [bounds]=visitSurface(e, bounds)
+    data = e.data;
+
+    bounds(1,1)=min([min(data.x) ; bounds(1,1)]);
+    bounds(2,1)=max([max(data.x) ; bounds(2,1)]);
+    bounds(1,2)=min([min(data.y) ; bounds(1,2)]);
+    bounds(2,2)=max([max(data.y) ; bounds(2,2)]);
+    bounds(1,3)=min([min(data.z) ; bounds(1,3)]);
+    bounds(2,3)=max([max(data.z) ; bounds(2,3)]);
+endfunction
+
+function [bounds]=visitFac3d(e, bounds)
+    [bounds]=visitSurface(e, bounds)
+endfunction
+
+function [bounds]=visitPlot3d(e, bounds)
+    [bounds]=visitSurface(e, bounds)
+endfunction
+
+function [bounds]=visitFec(e, bounds)
+    data = e.data;
+
+    // TODO: Fec zoom behavior is not clear to me, should be reviewed carefully
+    bounds(1,1)=min([data(:,2) ; bounds(1,1)]);
+    bounds(2,1)=max([data(:,2) ; bounds(2,1)]);
+    bounds(1,2)=min([data(:,1) ; bounds(1,2)]);
+    bounds(2,2)=max([data(:,1) ; bounds(2,2)]);
+endfunction
+
+function [bounds]=visitGrayplot(e, bounds)
+    [bounds]=visitSurface(e, bounds)
+endfunction
+
+function [bounds]=visitMatplot(e, bounds)
+    data = e.rect;
+
+    bounds(1,1)=min([data(1) ; bounds(1,1)]);
+    bounds(2,1)=max([data(3) ; bounds(2,1)]);
+    bounds(1,2)=min([data(2) ; bounds(1,2)]);
+    bounds(2,2)=max([data(4) ; bounds(2,2)]);
+endfunction
+
+function [bounds]=visitSegs(e, bounds)
+    data = e.data;
+
+    bounds(1,1)=min([data(:,1) ; bounds(1,1)]);
+    bounds(2,1)=max([data(:,1) ; bounds(2,1)]);
+    bounds(1,2)=min([data(:,2) ; bounds(1,2)]);
+    bounds(2,2)=max([data(:,2) ; bounds(2,2)]);
+    if (size(data,"c") > 2) then
+        bounds(1,3)=min([data(:,3) ; bounds(1,3)]);
+        bounds(2,3)=max([data(:,3) ; bounds(2,3)]);
+    end
+endfunction
+
+function [bounds]=visitChamp(e, bounds)
+    data = e.data;
+
+    bounds(1,1)=min([data.x ; bounds(1,1)]);
+    bounds(2,1)=max([data.x ; bounds(2,1)]);
+    bounds(1,2)=min([data.y ; bounds(1,2)]);
+    bounds(2,2)=max([data.y ; bounds(2,2)]);
+endfunction
+
+function [bounds]=visitText(e, bounds)
+    data = e.data;
+
+    bounds(1,1)=min([data(1) ; bounds(1,1)]);
+    bounds(1,2)=min([data(2) ; bounds(1,2)]);
+    if (size(data,"c") > 2) then
+        bounds(1,3)=min([data(3) ; bounds(1,3)]);
+    end
+endfunction
+
+function [bounds]=visitLegend(e, bounds)
+    // TODO: implement something ; it might not be possible at all
+endfunction
+
+function [bounds]=visitLight(e, bounds)
+    // nothing to do, a light is always visible
+endfunction
index 71cff58..4c52969 100644 (file)
@@ -77,6 +77,9 @@
         <submenu label="&amp;Original View" icon="zoom-original">
             <callback instruction='unzoom(get_figure_handle([SCILAB_FIGURE_ID]))' type="0"/>
         </submenu>
+        <submenu label="Fit zoom to data" icon="zoom-fit-drawing">
+            <callback instruction='zoom_auto(get_figure_handle([SCILAB_FIGURE_ID]))' type="0"/>
+        </submenu>
         <separator/>
         <submenu label="2D/3D &amp;Rotation" icon="transform-rotate">
             <callback instruction="set(get_figure_handle([SCILAB_FIGURE_ID]), 'info_message', 'Right click and drag to rotate.')" type="-2"/>
index 7057be3..e2e72f6 100644 (file)
     <button icon="zoom-original" tooltiptext="Original View">
         <callback instruction="unzoom(get_figure_handle([SCILAB_FIGURE_ID]))" type="-2"/>
     </button>
+    <!-- Fit to the data -->
+    <button icon="zoom-fit-drawing" tooltiptext="Fit zoom to data">
+        <callback instruction="zoom_auto(get_figure_handle([SCILAB_FIGURE_ID]))" type="-2"/>
+    </button>
     <separator/>
     <!-- Datatips -->
     <button icon="datatips" tooltiptext="Toggle datatip mode" toggle="true">