1: <?php
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22: 23: 24: 25: 26: 27: 28:
29:
30: 31:
32:
33: 34: 35: 36: 37: 38: 39:
40: function F_getSVGGraphCode($p, $w = '', $h = '')
41: {
42:
43:
44: $points = explode('x', $p);
45:
46:
47: $numpoints = count($points);
48:
49: $label_space = 35;
50:
51: $width = ($label_space + ($numpoints * 2));
52: if (!empty($w)) {
53: $width = max($width, intval($w));
54: }
55:
56: $height = 200 + $label_space;
57: if (!empty($h)) {
58: $height = max($height, intval($h));
59: }
60:
61: $color = array('ff0000', '0000ff');
62:
63:
64: $fontsize = sprintf('%.3F', ($label_space / 3));
65:
66:
67: $svg = '<'.'?'.'xml version="1.0" standalone="no"'.'?'.'>'."\n";
68: $svg .= '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'."\n";
69: $svg .= '<svg width="'.$width.'" height="'.$height.'" version="1.1" xmlns="http://www.w3.org/2000/svg">'."\n";
70:
71:
72: $vstep = floor(($height - $label_space) / 11);
73: $pstep = ($vstep / 10);
74: $hw = ($width - 4);
75: $textpos = ($label_space * 0.8);
76: $svg .= '<g stroke="#cccccc" fill="#666666" stroke-width="1" text-anchor="end" font-family="Arial,Verdana" font-size="'.$fontsize.'">'."\n";
77: for ($i = 0; $i <= 10; ++$i) {
78: $y = (($i + 1) * $vstep);
79:
80: $svg .= "\t".'<text x="'.$textpos.'" y="'.$y.'" stroke-width="0">'.(100 - ($i * 10)).'%</text>'."\n";
81:
82: $svg .= "\t".'<line x1="'.$label_space.'" y1="'.$y.'" x2="'.$hw.'" y2="'.$y.'" />'."\n";
83: }
84: $svg .= '</g>'."\n";
85:
86:
87: $hstep = floor(($hw - $label_space) / ($numpoints - 1));
88: $vh = ($height - $label_space);
89: $textpos = $vh + ($label_space * 0.5);
90: $svg .= '<g stroke="#cccccc" fill="#666666" stroke-width="1" text-anchor="end" font-family="Arial,Verdana" font-size="'.$fontsize.'">'."\n";
91: $graph = array('', '');
92: $step = 1;
93: if ($numpoints > 30) {
94: $step = 5;
95: } elseif ($numpoints > 100) {
96: $step = 10;
97: }
98:
99: for ($i = 0; $i < $numpoints; ++$i) {
100: $point = explode('v', $points[$i]);
101: $x = (($i * $hstep) + $label_space);
102:
103: $svg .= "\t".'<line x1="'.$x.'" y1="'.$vstep.'" x2="'.$x.'" y2="'.$vh.'" />'."\n";
104: $xi = ($i + 1);
105: if (($xi == 1) or (($xi % $step) == 0)) {
106:
107: $svg .= "\t".'<text x="'.$x.'" y="'.$textpos.'" stroke-width="0">'.($xi).'</text>'."\n";
108: }
109: for ($k = 0; $k <= 1; ++$k) {
110:
111: $y = sprintf('%.3F', (11 * $vstep) - (intval($point[$k]) * $pstep));
112: $graph[$k] .= ' '.$x.','.$y;
113:
114: $svg .= "\t".'<circle cx="'.$x.'" cy="'.$y.'" r="4" stroke-width="0" fill="#'.$color[$k].'" />'."\n";
115: }
116: }
117: $svg .= '</g>'."\n";
118:
119:
120: for ($k = 0; $k <= 1; ++$k) {
121: $svg .= '<path fill-opacity="0.2" fill="#'.$color[$k].'" stroke-width="0" d="M '.$label_space.' '.(11 * $vstep).' L '.$graph[$k].' '.((($numpoints - 1) * $hstep) + $label_space).' '.(11 * $vstep).' Z" />'."\n";
122: $svg .= '<polyline fill="none" stroke="#'.$color[$k].'" stroke-width="2" points="'.$graph[$k].'" />'."\n";
123: }
124:
125:
126: $svg .= '</svg>'."\n";
127:
128: return $svg;
129: }
130:
131: 132: 133: 134: 135: 136: 137:
138: function F_getSVGGraph($p, $w = '', $h = '')
139: {
140:
141: header('Content-Description: SVG Data');
142: header('Cache-Control: public, must-revalidate, max-age=0');
143: header('Pragma: public');
144: header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
145: header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
146: header('Content-Type: image/svg+xml');
147: header('Content-Disposition: inline; filename="tce_svg_graph_'.md5($p.$w.$h).'.svg";');
148:
149:
150:
151: echo F_getSVGGraphCode($p, $w, $h);
152: }
153:
154:
155:
156:
157: