예제 #1
0
 /**
  * Returns the positions of the Y-axis text
  */
 protected function YAxisTextPositions(&$points, $xoff, $yoff, $angle, $inside, $axis_no)
 {
     $positions = array();
     $labels = '';
     $font_size = $this->GetFirst($this->ArrayOption($this->axis_font_size_v, $axis_no), $this->axis_font_size);
     $font_adjust = $this->GetFirst($this->ArrayOption($this->axis_font_adjust_v, $axis_no), $this->axis_font_adjust);
     $text_space = $this->GetFirst($this->ArrayOption($this->axis_text_space_v, $axis_no), $this->axis_text_space);
     $c = cos($this->arad);
     $s = sin($this->arad);
     $a = $this->arad + ($s * $c > 0 ? -M_PI_2 : M_PI_2);
     $x2 = ($xoff + $text_space) * sin($a);
     $y2 = ($xoff + $text_space) * cos($a);
     $x3 = 0;
     $y3 = $c > 0 ? $font_size : 0;
     $position = array('text-anchor' => $s < 0 ? 'start' : 'end');
     foreach ($points as $grid_point) {
         $key = $grid_point->text;
         $y = $grid_point->position;
         if (SVGGraphStrlen($key, $this->encoding) > 0) {
             $x1 = $y * $s;
             $y1 = $y * $c;
             $position['x'] = $this->xc + $x1 + $x2 + $x3;
             $position['y'] = $this->yc + $y1 + $y2 + $y3;
             if ($angle != 0) {
                 $rcx = $position['x'];
                 $rcy = $position['y'];
                 $position['transform'] = "rotate({$angle},{$rcx},{$rcy})";
             }
             $size = $this->TextSize((string) $key, $font_size, $font_adjust, $this->encoding, $angle, $font_size);
             $position['text'] = $key;
             $position['w'] = $size[0];
             $position['h'] = $size[1];
             $positions[] = $position;
         }
     }
     return $positions;
 }
예제 #2
0
 /**
  * Returns [width,height] of text 
  * $text = string OR text length
  */
 public static function TextSize($text, $font_size, $font_adjust, $encoding, $angle = 0, $line_spacing = 0)
 {
     $height = $font_size;
     if (is_int($text)) {
         $len = $text;
     } else {
         // replace all entities with an underscore
         $text = preg_replace('/&[^;]+;/', '_', $text);
         if ($line_spacing > 0) {
             $len = 0;
             $lines = explode("\n", $text);
             foreach ($lines as $l) {
                 if (SVGGraphStrlen($l, $encoding) > $len) {
                     $len = SVGGraphStrlen($l, $encoding);
                 }
             }
             $height += $line_spacing * (count($lines) - 1);
         } else {
             $len = SVGGraphStrlen($text, $encoding);
         }
     }
     $width = $len * $font_size * $font_adjust;
     if ($angle % 180 != 0) {
         if ($angle % 90 == 0) {
             $w = $height;
             $height = $width;
             $width = $w;
         } else {
             $a = deg2rad($angle);
             $sa = abs(sin($a));
             $ca = abs(cos($a));
             $w = $ca * $width + $sa * $height;
             $h = $sa * $width + $ca * $height;
             $width = $w;
             $height = $h;
         }
     }
     return array($width, $height);
 }
 /**
  * Strips units from before and after label
  */
 protected function StripLabel($label)
 {
     $before = $this->before_label;
     $after = $this->after_label;
     $enc = $this->encoding;
     $llen = SVGGraphStrlen($label, $enc);
     $blen = SVGGraphStrlen($before, $enc);
     $alen = SVGGraphStrlen($after, $enc);
     if ($alen > 0 && SVGGraphSubstr($label, $llen - $alen, $alen, $enc) == $after) {
         $label = SVGGraphSubstr($label, 0, $llen - $alen, $enc);
     }
     if ($blen > 0 && SVGGraphSubstr($label, 0, $blen, $enc) == $before) {
         $label = SVGGraphSubstr($label, $blen, NULL, $enc);
     }
     return $label;
 }
예제 #4
0
 /**
  * Returns the Y-axis text positions
  */
 protected function YAxisTextPositions(&$points, $xoff, $yoff, $angle, $inside, $axis_no)
 {
     $y_prev = $this->height;
     $min_space = $this->GetFirst($this->ArrayOption($this->minimum_grid_spacing_v, $axis_no), $this->minimum_grid_spacing);
     $font_size = $this->GetFirst($this->ArrayOption($this->axis_font_size_v, $axis_no), $this->axis_font_size);
     $font_adjust = $this->GetFirst($this->ArrayOption($this->axis_font_adjust_v, $axis_no), $this->axis_font_adjust);
     $text_space = $this->GetFirst($this->ArrayOption($this->axis_text_space_v, $axis_no), $this->axis_text_space);
     $text_centre = $font_size * 0.3;
     $label_centre_y = $this->label_centre && $this->flip_axes;
     $x_rotate_offset = $inside ? $text_centre : -$text_centre;
     $y_rotate_offset = -$text_centre;
     $x = $xoff + $text_space;
     if (!$inside) {
         $x = -$x;
     }
     $position = array('x' => $x);
     $position['text-anchor'] = $inside ? 'start' : 'end';
     $positions = array();
     $count = count($points);
     $p = 0;
     foreach ($points as $grid_point) {
         $key = $grid_point->text;
         $y = $grid_point->position;
         if ($this->flip_axes) {
             // if the key is different to value, use it
             $k = $this->GetKey($grid_point->value);
             if ($k !== $grid_point->value) {
                 $key = $k;
             }
         }
         // don't draw 0 over the axis line
         if ($inside && !$label_centre_y && !$axis_no && $key == '0') {
             $key = '';
         }
         if (SVGGraphStrlen($key, $this->encoding) && $y_prev - $y >= $min_space && (++$p < $count || !$label_centre_y)) {
             $position['y'] = $y + $text_centre + $yoff;
             if ($angle != 0) {
                 $rcx = $position['x'] + $x_rotate_offset;
                 $rcy = $position['y'] + $y_rotate_offset;
                 $position['transform'] = compact('angle', 'rcx', 'rcy');
             }
             $size = $this->TextSize((string) $key, $font_size, $font_adjust, $this->encoding, $angle, $font_size);
             $position['text'] = $key;
             $position['w'] = $size[0];
             $position['h'] = $size[1];
             $positions[] = $position;
         }
         $y_prev = $y;
     }
     return $positions;
 }