/** * 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; }
/** * Creates a single marker element and its link version */ private function CreateMarker($type, $size, $fill, $stroke_width, $stroke_colour) { $m_key = "{$type}:{$size}:{$fill}:{$stroke_width}:{$stroke_colour}"; if (isset($this->marker_types[$m_key])) { return $this->marker_types[$m_key]; } $id = $this->NewID(); $marker = array('id' => $id, 'cursor' => 'crosshair', 'fill' => $fill); if (!empty($stroke_colour) && $stroke_colour != 'none') { $marker['stroke'] = $stroke_colour; if (!empty($stroke_width)) { $marker['stroke-width'] = $stroke_width; } } // check for image marker if (strncmp($type, 'image:', 6) == 0) { $image_path = SVGGraphSubstr($type, 6, NULL, $this->encoding); $type = 'image'; } $a = $size; // will be repeated a lot, and 'a' is smaller $element = 'path'; switch ($type) { case 'triangle': $o = $a * tan(M_PI / 6); $h = $a / cos(M_PI / 6); $marker['d'] = "M{$a},{$o} L0,-{$h} L-{$a},{$o} z"; break; case 'diamond': $marker['d'] = "M0 -{$a}L{$a} 0 0 {$a} -{$a} 0z"; break; case 'square': $element = 'rect'; $marker['x'] = $marker['y'] = -$a; $marker['width'] = $marker['height'] = $a * 2; break; case 'x': $marker['transform'] = 'rotate(45)'; // no break - 'x' is a cross rotated by 45 degrees // no break - 'x' is a cross rotated by 45 degrees case 'cross': $t = $a / 4; $marker['d'] = "M-{$a},-{$t} L-{$a},{$t} -{$t},{$t} -{$t},{$a} " . "{$t},{$a} {$t},{$t} {$a},{$t} " . "{$a},-{$t} {$t},-{$t} {$t},-{$a} " . "-{$t},-{$a} -{$t},-{$t} z"; break; case 'octagon': $t = $a * sin(M_PI / 8); $marker['d'] = "M{$t} -{$a}L{$a} -{$t} {$a} {$t} {$t} {$a} -{$t} {$a} " . "-{$a} {$t} -{$a} -{$t} -{$t} -{$a}z"; break; case 'star': $t = $a * 0.382; $x1 = $t * sin(M_PI * 0.8); $y1 = $t * cos(M_PI * 0.8); $x2 = $a * sin(M_PI * 0.6); $y2 = $a * cos(M_PI * 0.6); $x3 = $t * sin(M_PI * 0.4); $y3 = $t * cos(M_PI * 0.4); $x4 = $a * sin(M_PI * 0.2); $y4 = $a * cos(M_PI * 0.2); $marker['d'] = "M0 -{$a}L{$x1} {$y1} {$x2} {$y2} {$x3} {$y3} {$x4} {$y4} 0 {$t} " . "-{$x4} {$y4} -{$x3} {$y3} -{$x2} {$y2} -{$x1} {$y1} z"; break; case 'threestar': $t = $a / 4; $t1 = $t * cos(M_PI / 6); $t2 = $t * sin(M_PI / 6); $a1 = $a * cos(M_PI / 6); $a2 = $a * sin(M_PI / 6); $marker['d'] = "M0 -{$a}L{$t1} -{$t2} {$a1} {$a2} 0 {$t} -{$a1} {$a2} -{$t1} -{$t2}z"; break; case 'fourstar': $t = $a / 4; $marker['d'] = "M0 -{$a}L{$t} -{$t} {$a} 0 {$t} {$t} " . "0 {$a} -{$t} {$t} -{$a} 0 -{$t} -{$t}z"; break; case 'eightstar': $t = $a * sin(M_PI / 8); $marker['d'] = "M0 -{$t}L{$t} -{$a} {$t} -{$t} {$a} -{$t} {$t} 0 " . "{$a} {$t} {$t} {$t} {$t} {$a} 0 {$t} -{$t} {$a} -{$t} {$t} -{$a} {$t} -{$t} 0 " . "-{$a} -{$t} -{$t} -{$t} -{$t} -{$a}z"; break; case 'asterisk': $t = $a / 3; $x1 = $a * sin(M_PI * 0.9); $y1 = $a * cos(M_PI * 0.9); $x2 = $t * sin(M_PI * 0.8); $y2 = $t * cos(M_PI * 0.8); $x3 = $a * sin(M_PI * 0.7); $y3 = $a * cos(M_PI * 0.7); $x4 = $a * sin(M_PI * 0.5); $y4 = $a * cos(M_PI * 0.5); $x5 = $t * sin(M_PI * 0.4); $y5 = $t * cos(M_PI * 0.4); $x6 = $a * sin(M_PI * 0.3); $y6 = $a * cos(M_PI * 0.3); $x7 = $a * sin(M_PI * 0.1); $y7 = $a * cos(M_PI * 0.1); $marker['d'] = "M{$x1} {$y1}L{$x2} {$y2} {$x3} {$y3} {$x4} {$y4} {$x5} {$y5} " . "{$x6} {$y6} {$x7} {$y7} 0 {$t} -{$x7} {$y7} -{$x6} {$y6} -{$x5} {$y5} -{$x4} {$y4} " . "-{$x3} {$y3} -{$x2} {$y2} -{$x1} {$y1}z"; break; case 'pentagon': $x1 = $a * sin(M_PI * 0.4); $y1 = $a * cos(M_PI * 0.4); $x2 = $a * sin(M_PI * 0.2); $y2 = $a * cos(M_PI * 0.2); $marker['d'] = "M0 -{$a}L{$x1} -{$y1} {$x2} {$y2} -{$x2} {$y2} -{$x1} -{$y1}z"; break; case 'hexagon': $x = $a * sin(M_PI / 3); $y = $a * cos(M_PI / 3); $marker['d'] = "M0 -{$a}L{$x} -{$y} {$x} {$y} 0 {$a} -{$x} {$y} -{$x} -{$y}z"; break; case 'image': $element = 'image'; $marker['xlink:href'] = $image_path; $marker['x'] = $marker['y'] = -$size; $marker['width'] = $size * 2; $marker['height'] = $size * 2; break; case 'circle': default: $element = 'circle'; $marker['r'] = $size; } $this->marker_elements[$marker['id']] = $this->Element('symbol', NULL, NULL, $this->Element($element, $marker, NULL)); // add link version unset($marker['cursor']); $this->marker_link_ids[$marker['id']] = $this->NewID(); $marker['id'] = $this->marker_link_ids[$marker['id']]; $this->marker_elements[$marker['id']] = $this->Element('symbol', NULL, NULL, $this->Element($element, $marker, NULL)); // save this marker style for reuse $this->marker_types[$m_key] = $id; return $id; }