Browse Source

Feature Admin Summary: added logic so we can have an inset legend sometimes ;).

Lacey Sanderson 10 years ago
parent
commit
66c54da5f4

+ 2 - 2
tripal_feature/includes/tripal_feature.admin.inc

@@ -100,10 +100,10 @@ function tripal_feature_admin_feature_view() {
     );
 
     // We also need to keep track of the total number of features for a single bar (Type).
-    $chart[$row->cvterm_id]['total_features'] = $chart[$row->cvterm_id]['y1'];
+    $chart[$row->cvterm_id]['total_features'] = (int) $chart[$row->cvterm_id]['y1'];
     // And the maximum "height" for all bars.
     if ($max_bar_height < $chart[$row->cvterm_id]['total_features']) {
-      $max_bar_height = $chart[$row->cvterm_id]['total_features'];
+      $max_bar_height = (int) $chart[$row->cvterm_id]['total_features'];
     }
   }
 

+ 12 - 0
tripal_feature/theme/js/tripalFeature.adminChart.js

@@ -65,6 +65,18 @@ Drupal.behaviors.tripalFeature_adminSummaryChart = {
         width = numBars * (maxTotalLength * 9);
       }
 
+      // Determine the best place for the legend. Default to top since that
+      // will for sure not cause conflict... even though it looks better
+      // on the right ;).
+      // Logic: If the difference between the max & min bar heights is greater
+      // than 1/2 the chart height (max bar height) then there "should"
+      // be room for the chart nested on the right.
+      minBarHeight = d3.min(Drupal.settings.tripalFeature.admin.summary, function(d,i) { return d.total_features; });
+      barHeightDifference = Drupal.settings.tripalFeature.admin.maxBarHeight - minBarHeight;
+      if (barHeightDifference >= Drupal.settings.tripalFeature.admin.maxBarHeight/2) {
+        Drupal.settings.tripalFeature.admin.legendPosition = 'right';
+      }
+
       // Also if we need to put the legend along the top we need to
       // increase the top margin.
       if (Drupal.settings.tripalFeature.admin.legendPosition == 'top') {