changeset 29452:a0eb1ae33192

maint: merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 20 Mar 2021 11:40:07 +0100
parents 3a680307d4aa (current diff) 75ba68c686ab (diff)
children 27cb1672b249
files doc/interpreter/plot.txi libgui/src/main-window.cc libgui/src/main-window.h
diffstat 5 files changed, 94 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/images	Sat Mar 20 10:42:06 2021 +0900
+++ b/doc/interpreter/images	Sat Mar 20 11:40:07 2021 +0100
@@ -1,5 +1,5 @@
 geometryimages.m voronoi triplot griddata convhull delaunay inpolygon
 interpimages.m interpft interpn interpderiv1 interpderiv2
-plotimages.m plot hist errorbar polar mesh plot3 extended
+plotimages.m plot hist errorbar polar mesh plot3 extended precisiondate
 sparseimages.m gplot grid spmatrix spchol spcholperm
 splineimages.m splinefit1 splinefit2 splinefit3 splinefit4 splinefit6
--- a/doc/interpreter/plot.txi	Sat Mar 20 10:42:06 2021 +0900
+++ b/doc/interpreter/plot.txi	Sat Mar 20 11:40:07 2021 +0100
@@ -2690,6 +2690,7 @@
 @menu
 * Customizing Toolkit Behavior::
 * Hardware vs. Software Rendering::
+* Precision issues::
 @end menu
 
 @node Customizing Toolkit Behavior
@@ -2733,3 +2734,60 @@
 @file{@var{octave-home}\bin\opengl32.dll}
 @*where @var{octave-home} is the directory in which Octave is installed (the
 default is @file{C:\Octave\Octave-@var{version}}).
+
+@node Precision issues
+@subsubsection Precision issues
+@cindex opengl single precision date time
+
+The OpenGL graphics toolkits (@qcode{"qt"} and @qcode{"fltk"}) use single
+precision for rendering.  This limitation in particular applies to plots of
+timeseries against serial dates as used by the @code{datenum}, @code{datestr},
+@code{datestruct}, and @code{datetick} functions.
+
+Serial dates encode timestamps as days elapsed since the year zero with hours,
+minutes, seconds as the fractional part. On December 31st 1999, the serial date
+representation was 730485.  A double precision variable with this integer part
+allows for a resolution in its fractional part of 1.2e-10, representing about 5
+microseconds.  But with single precision, the resolution is reduced to about
+0.06, representing 45 minutes.  Any attempt to plot timestamped data with finer
+granularity will result in a distorted graph.
+
+As a workaround, it is possible to use the @qcode{"gnuplot"} graphics toolkit
+or subtract 2000 years---i.e. datenum(2000,0,0) or 730485---from the time
+values.  Due to the fact that the calendar structure repeats every 2000 years,
+the relation between year, month, day of month and day of week will stay
+unchanged and the ticks and ticklabels produced by the @code{datetick} function
+will still be correct.  Only years will lack the millennium digit.  Thus,
+"2020" will be printed as "20".  For example:
+
+@example
+@group
+# timestamps of 24 hours in one minute steps
+t = datenum (2020, 1, 1):(1/1440):datenum (2020, 1, 2);
+
+# some example timeseries data
+x = -cos (2*pi*t) + rand (size (t)) / 10;
+
+subplot (1, 2, 1);
+plot (t, x);
+datetick ("x");
+xlabel ("serial date");
+title ("problem");
+
+subplot (1, 2, 2);
+plot (t - 730485, x);
+datetick ("x");
+xlabel ("2000 years off");
+title ("workaround");
+@end group
+@end example
+
+@ifnotinfo
+@noindent
+The result of which can be seen in @ref{fig:precisiondate}.
+
+@float Figure,fig:precisiondate
+@center @image{precisiondate,4in}
+@caption{Single precision issues with OpenGL graphics toolkits}
+@end float
+@end ifnotinfo
--- a/doc/interpreter/plotimages.m	Sat Mar 20 10:42:06 2021 +0900
+++ b/doc/interpreter/plotimages.m	Sat Mar 20 11:40:07 2021 +0100
@@ -121,6 +121,26 @@
             '\int_{\fontsize{8}0}^{\fontsize{8}x}} e^{-t^2} dt} = 0.6175']);
       print (outfile, d_typ);
     endif
+  elseif (strcmp (nm, "precisiondate"))
+    rand ("state", 1);
+    t = datenum (2020, 1, 1):(1/1440):datenum (2020, 1, 2);
+    x = -cos (2*pi*t) + rand (size (t)) / 10;
+    subplot (1, 2, 1);
+    plot (t, x);
+    datetick ("x");
+    xlabel ("serial date");
+    title ("problem");
+    subplot (1, 2, 2);
+    plot (t - 730485, x);
+    datetick ("x");
+    xlabel ("2000 years off");
+    title ("workaround");
+    # set wider aspect ratio
+    image_size = [8.25, 3.5]; # in inches, 5:2 format
+    border = 0;              # For postscript use 50/72
+    set (gcf, "papersize", image_size + 2*border);
+    set (gcf, "paperposition", [border, border, image_size]);
+    print (outfile, d_typ);
   else
     error ("unrecognized plot requested");
   endif
--- a/libgui/src/main-window.cc	Sat Mar 20 10:42:06 2021 +0900
+++ b/libgui/src/main-window.cc	Sat Mar 20 11:40:07 2021 +0100
@@ -1509,6 +1509,10 @@
 
   void main_window::set_window_layout (gui_settings *settings)
   {
+    // For resetting from some inconsistent state, first reset layout
+    // without saving or showing it
+    do_reset_windows (true, false);
+
     // Restore main window state and geometry from settings file or, in case
     // of an error (no pref values yet), from the default layout.
     if (! restoreGeometry (settings->value (mw_geometry).toByteArray ()))
@@ -2907,7 +2911,7 @@
   // Create the default layout of the main window. Do not use
   // restoreState () and restoreGeometry () with default values since
   // this might lead to problems when the Qt version changes
-  void main_window::do_reset_windows (bool show_it)
+  void main_window::do_reset_windows (bool show, bool save)
   {
     // Set main window default geometry and store its width for
     // later resizing the command window
@@ -2949,7 +2953,7 @@
 
     // Show main wibdow, save state and geometry of main window and
     // all dock widgets
-    if (show_it)
+    if (show)
       {
         // Show all dock widgets
         for (auto *widget : dock_widget_list ())
@@ -2958,11 +2962,14 @@
         // Show main window and store size and state
         showNormal ();
 
-        resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
-        gui_settings *settings = rmgr.get_settings ();
-
-        settings->setValue (mw_geometry.key, saveGeometry ());
-        settings->setValue (mw_state.key, saveState ());
+        if (save)
+          {
+            resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
+            gui_settings *settings = rmgr.get_settings ();
+
+            settings->setValue (mw_geometry.key, saveGeometry ());
+            settings->setValue (mw_state.key, saveState ());
+          }
 
         focus_command_window ();
       }
--- a/libgui/src/main-window.h	Sat Mar 20 10:42:06 2021 +0900
+++ b/libgui/src/main-window.h	Sat Mar 20 11:40:07 2021 +0100
@@ -163,7 +163,7 @@
     void prepare_to_exit (void);
     void go_to_previous_widget (void);
     void reset_windows (void);
-    void do_reset_windows (bool show_it = true);
+    void do_reset_windows (bool show = true, bool save = true);
 
     void update_octave_directory (const QString& dir);
     void browse_for_directory (void);