[goffice] Fix box plots when only outliers lie outside of the box. [#345]



commit f8c3ca1c50ff2ad5bd00f9667e3496943b5266c2
Author: Jean Brefort <jean brefort normalesup org>
Date:   Fri Jul 13 15:48:44 2018 +0200

    Fix box plots when only outliers lie outside of the box. [#345]

 ChangeLog                          |  6 ++++++
 NEWS                               |  3 +++
 plugins/plot_distrib/gog-boxplot.c | 42 +++++++++++++++++++++++---------------
 3 files changed, 35 insertions(+), 16 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7087b82b..1c2aad41 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-07-13  Jean Brefort  <jean brefort normalesup org>
+
+       * plugins/plot_distrib/gog-boxplot.c (gog_box_plot_view_render): do
+       not display whiskers when there are only ouliers outside of the box. Fixes
+       #345.
+
 2018-05-17  Morten Welinder  <terra gnome org>
 
        * goffice/app/go-plugin.c (go_plugins_shutdown): Avoid hash order
diff --git a/NEWS b/NEWS
index 2b5cbc6f..0a9b0004 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 goffice 0.10.42:
 
+Jean:
+       * Fix box plots when only outliers lie outside of the box. [#345]
+
 Morten:
        * Introspection fixes.
        * Improve file saver api.
diff --git a/plugins/plot_distrib/gog-boxplot.c b/plugins/plot_distrib/gog-boxplot.c
index 6105922f..edc52179 100644
--- a/plugins/plot_distrib/gog-boxplot.c
+++ b/plugins/plot_distrib/gog-boxplot.c
@@ -567,14 +567,20 @@ gog_box_plot_view_render (GogView *view, GogViewAllocation const *bbox)
                        go_path_close (path);
                        gog_renderer_draw_shape (view->renderer, path);
                        go_path_clear (path);
-                       go_path_move_to (path, y + hbar, min);
-                       go_path_line_to (path, y - hbar, min);
-                       go_path_move_to (path, y + hbar, max);
-                       go_path_line_to (path, y - hbar, max);
-                       go_path_move_to (path, y, max);
-                       go_path_line_to (path, y, qu3);
-                       go_path_move_to (path, y, min);
-                       go_path_line_to (path, y, qu1);
+                       /* whiskers are displayed only if they are not inside the quartile box
+                        * which might be the case if outliers are taken into account, see #345 */
+                       if ((qu1 - min) * (med - qu1) > 0) { /* we don't compare the real value but the 
canvas coordinates */
+                               go_path_move_to (path, y + hbar, min);
+                               go_path_line_to (path, y - hbar, min);
+                               go_path_move_to (path, y, min);
+                               go_path_line_to (path, y, qu1);
+                       }
+                       if ((max - qu3) * (qu3 - med) > 0) {
+                               go_path_move_to (path, y + hbar, max);
+                               go_path_line_to (path, y - hbar, max);
+                               go_path_move_to (path, y, max);
+                               go_path_line_to (path, y, qu3);
+                       }
                        go_path_move_to (path, y - hrect, med);
                        go_path_line_to (path, y + hrect, med);
                        gog_renderer_stroke_shape (view->renderer, path);
@@ -587,14 +593,18 @@ gog_box_plot_view_render (GogView *view, GogViewAllocation const *bbox)
                        go_path_close (path);
                        gog_renderer_draw_shape (view->renderer, path);
                        go_path_clear (path);
-                       go_path_move_to (path, min, y + hbar);
-                       go_path_line_to (path, min, y - hbar);
-                       go_path_move_to (path, max, y + hbar);
-                       go_path_line_to (path, max, y - hbar);
-                       go_path_move_to (path, max, y);
-                       go_path_line_to (path, qu3, y);
-                       go_path_move_to (path, min, y);
-                       go_path_line_to (path, qu1, y);
+                       if ((qu1 - min) * (med - qu1) > 0) {
+                               go_path_move_to (path, min, y + hbar);
+                               go_path_line_to (path, min, y - hbar);
+                               go_path_move_to (path, min, y);
+                               go_path_line_to (path, qu1, y);
+                       }
+                       if ((max - qu3) * (qu3 - med) > 0) {
+                               go_path_move_to (path, max, y + hbar);
+                               go_path_line_to (path, max, y - hbar);
+                               go_path_move_to (path, max, y);
+                               go_path_line_to (path, qu3, y);
+                       }
                        go_path_move_to (path, med, y - hrect);
                        go_path_line_to (path, med, y + hrect);
                        gog_renderer_stroke_shape (view->renderer, path);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]