/** * Overridden to prevent drawing on other bars */ public function DataLabelPosition($dataset, $index, &$item, $x, $y, $w, $h, $label_w, $label_h) { if (!is_numeric($dataset)) { // doing this supports stacked grouped bar graph totals too list($d) = explode('-', $dataset); if ($d === 'totalpos') { if (isset($this->last_position_pos[$index])) { list($lpos, $l_h) = $this->last_position_pos[$index]; list($hpos, $vpos) = Graph::TranslatePosition($lpos); if ($vpos == 'ot') { return "above 0 -{$l_h}"; } } return 'above'; } if ($d === 'totalneg') { if (isset($this->last_position_neg[$index])) { list($lpos, $l_h) = $this->last_position_neg[$index]; list($hpos, $vpos) = Graph::TranslatePosition($lpos); if ($vpos == 'ob') { return "below 0 {$l_h}"; } } return 'below'; } } $pos = parent::DataLabelPosition($dataset, $index, $item, $x, $y, $w, $h, $label_w, $label_h); if ($label_h > $h && Graph::IsPositionInside($pos)) { $pos = str_replace(array('top', 'bottom', 'above', 'below'), 'middle', $pos); } if ($item->value > 0) { $this->last_position_pos[$index] = array($pos, $label_h); } else { $this->last_position_neg[$index] = array($pos, $label_h); } return $pos; }
/** * Overridden to prevent drawing on other bars */ public function DataLabelPosition($dataset, $index, &$item, $x, $y, $w, $h, $label_w, $label_h) { if (!is_numeric($dataset)) { if ($dataset === 'totalpos') { if (isset($this->last_position_pos[$index])) { list($lpos, $l_w) = $this->last_position_pos[$index]; list($hpos, $vpos) = Graph::TranslatePosition($lpos); if ($hpos == 'or') { return "middle outside right {$l_w} 0"; } } return 'outside right'; } if ($dataset === 'totalneg') { if (isset($this->last_position_neg[$index])) { list($lpos, $l_w) = $this->last_position_neg[$index]; list($hpos, $vpos) = Graph::TranslatePosition($lpos); if ($hpos == 'ol') { return "middle outside left -{$l_w} 0"; } } return 'outside left'; } } if ($dataset === 'totalpos') { return 'outside right'; } if ($dataset === 'totalneg') { return 'outside left'; } $pos = parent::DataLabelPosition($dataset, $index, $item, $x, $y, $w, $h, $label_w, $label_h); if ($label_w > $w && Graph::IsPositionInside($pos)) { $pos = str_replace(array('outside left', 'outside right'), 'centre', $pos); } if ($item->value > 0) { $this->last_position_pos[$index] = array($pos, $label_w); } else { $this->last_position_neg[$index] = array($pos, $label_w); } return $pos; }
/** * Returns TRUE if the position is inside the item */ public static function IsPositionInside($pos) { list($hpos, $vpos) = Graph::TranslatePosition($pos); return strpos($hpos . $vpos, 'o') === FALSE; }