/**
  * Calculates the bar width, gap to first bar, gap between bars
  * returns an array containing all three
  */
 static function BarPosition($bar_width, $bar_width_min, $unit_width, $group_size, $bar_space, $group_space)
 {
     if (is_numeric($bar_width) && $bar_width >= 1) {
         return GroupedBarGraph::BarPositionFixed($bar_width, $unit_width, $group_size, $group_space);
     } else {
         // bar width dependent on space
         $gap_count = $group_size - 1;
         $gap = $gap_count > 0 ? $group_space : 0;
         $bar_width = $bar_space >= $unit_width ? '1' : $unit_width - $bar_space;
         if ($gap_count > 0 && $gap * $gap_count > $bar_width - $group_size) {
             $gap = ($bar_width - $group_size) / $gap_count;
         }
         $bar_width = ($bar_width - $gap * ($group_size - 1)) / $group_size;
         if ($bar_width < $bar_width_min) {
             return GroupedBarGraph::BarPositionFixed($bar_width_min, $unit_width, $group_size, $group_space);
         }
         $spacing = $bar_width + $gap;
         $offset = $bar_space / 2;
     }
     return array($bar_width, $offset, $spacing);
 }