From 22b35bac79242229463cf6ebec62f2f6eaa3d880 Mon Sep 17 00:00:00 2001
From: Ivica Ico Bukvic <ico@vt.edu>
Date: Sat, 23 Aug 2014 09:46:34 -0400
Subject: [PATCH] *fixed remaining problems (hopefully) with 2 arrays drawn in
 the same gop (need to test with more than 2 arrays?) *bug for Jonathan--bar
 graph draws from top down, as opposed from bottom up when opening array gop

---
 pd/src/g_array.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/pd/src/g_array.c b/pd/src/g_array.c
index ebf6f7c35..1bd4516b3 100644
--- a/pd/src/g_array.c
+++ b/pd/src/g_array.c
@@ -279,12 +279,25 @@ static int garray_get_largest_array(t_garray *x)
 {
     t_gobj *g;
     t_array *a;
+    t_garray *tmp;
     int an = 0;
+
+    // checks if there is a PLOTSTYLE_POLY vs others
+    // longest array uses has_*, total_* gives total number
+    // n_array gives you the number of arrays
+    int has_poly = 0;
+    int total_poly = 0;
+    int has_other = 0;
+    int total_other = 0;
+    int n_array = 0;
+
     int length = 0;
+
     for (g = x->x_glist->gl_list; g; g = g->g_next)
     {
         if (pd_class(&g->g_pd) == garray_class)
         {
+            n_array++;
             a = garray_getarray((t_garray *)g);
             //if ((t_garray *)g != x)
             //{
@@ -297,11 +310,55 @@ static int garray_get_largest_array(t_garray *x)
             //else
             //{
                 a = garray_getarray((t_garray *)g);
+                tmp = (t_garray *)g;
+
+                // if we have new longest plot reset the
+                // count for the longest plot style
                 if (a->a_n > length)
+                {
+                    has_poly = 0;
+                    has_other = 0;
+                }
+
+                // get the longest (or matching) plots style
+                if (a->a_n >= length)
+                {
+                    if (tmp->x_style == PLOTSTYLE_POLY)
+                    {
+                        has_poly++;                      
+                    }
+                    else
+                    {
+                        has_other++;
+                    }
                     length = a->a_n;
+                }
+
+                // adjust total number of plot styles
+                if (tmp->x_style == PLOTSTYLE_POLY)
+                {
+                    total_poly++;                        
+                }
+                else
+                {
+                    total_other++;
+                }
             //}
         }
     }
+    //fprintf(stderr, "has_poly=%d has_other=%d | total_poly=%d total_other=%d | n_array=%d | pre-length=%d ",
+    //        has_poly, has_other, total_poly, total_other, n_array, length);
+    if (has_poly && !has_other)
+    {
+        if (total_other)
+            length--;
+    }
+    if (!has_poly && has_other)
+    {
+        if (total_poly)
+            length++;
+    }
+    //fprintf(stderr, "post-lenght=%d\n", length);
     return(length);
 }
 
@@ -316,7 +373,7 @@ static int garray_get_largest_array(t_garray *x)
 void garray_fittograph(t_garray *x, int n, int flag)
 {
     int max_length = garray_get_largest_array(x);
-    fprintf(stderr,"garray_fittograph n=%d flag=%d | max_length=%d\n", n, flag, max_length);
+    //fprintf(stderr,"garray_fittograph n=%d flag=%d | max_length=%d\n", n, flag, max_length);
     // here we check for x->x_glist validity because when creating
     // a new array from the menu gl is null at the first garray_vis call
     if (!x->x_glist)
-- 
GitLab