-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.php
133 lines (119 loc) · 4.86 KB
/
graph.php
1
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
require_once './include/init.php';
$dimensions = @$_GET['dimensions'];
extract($_SESSION['rns']);
if(empty($dimensions)
|| empty($detectors) || empty($space) || empty($self) || empty($tests)
|| (count($dimensions) != 2 && count($dimensions) != 3))
die('Invalid data');
$w = 600;
$h = 600;
if(count($dimensions) == 2) {
$wSpace = abs($space[$dimensions[0]]['max'] - $space[$dimensions[0]]['min']);
$hSpace = abs($space[$dimensions[1]]['max'] - $space[$dimensions[1]]['min']);
$wRatio = $w / $wSpace;
$hRatio = $h / $hSpace;
$ratio = min($wRatio, $hRatio);
$im = imagecreatetruecolor($w, $h);
$bg = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, $w, $h, $bg);
$colorBlack = imagecolorallocate($im, 0, 0, 0);
$colorRed = imagecolorallocate($im, 255, 0, 0);
$colorGreen = imagecolorallocate($im, 0, 255, 0);
$colorBlue = imagecolorallocate($im, 224, 224, 255);
$colorDarkBlue = imagecolorallocate($im, 0, 0, 255);
$colorGray = imagecolorallocate($im, 224, 224, 224);
$colorYellow = imagecolorallocate($im, 255, 255, 0);
foreach($detectors as $d) {
imagefilledellipse($im,
$ratio * $d->centre->coords[$dimensions[0]], $ratio * $d->centre->coords[$dimensions[1]],
$ratio * $d->radius, $ratio * $d->radius, $colorBlue);
/* imagesetpixel($im,
$ratio * $d->centre->coords[$dimensions[0]], $ratio * $d->centre->coords[$dimensions[1]],
$colorDarkBlue); */
imagefilledellipse($im,
$ratio * $d->centre->coords[$dimensions[0]], $ratio * $d->centre->coords[$dimensions[1]],
6, 6, $colorDarkBlue);
imageellipse($im,
$ratio * $d->centre->coords[$dimensions[0]], $ratio * $d->centre->coords[$dimensions[1]],
$ratio * $d->radius, $ratio * $d->radius, $colorDarkBlue);
}
foreach($self as $s) {
/* imagesetpixel($im,
$ratio * $s->coords[$dimensions[0]], $ratio * $s->coords[$dimensions[1]],
$colorGreen); */
imagefilledellipse($im,
$ratio * $s->coords[$dimensions[0]], $ratio * $s->coords[$dimensions[1]],
10, 10, $colorGreen);
}
foreach($tests as $t) {
/* if($t['result'] == false) {
imagefilledellipse($im,
$ratio * $t['antigen']->coords[$dimensions[0]], $ratio * $t['antigen']->coords[$dimensions[1]],
16, 16, $colorGreen);
} */
/* imagesetpixel($im,
$ratio * $t['antigen']->coords[$dimensions[0]], $ratio * $t['antigen']->coords[$dimensions[1]],
$colorRed); */
imagefilledellipse($im,
$ratio * $t['antigen']->coords[$dimensions[0]], $ratio * $t['antigen']->coords[$dimensions[1]],
8, 8, $t['result'] ? $colorRed : $colorYellow);
}
// grey out limits
if($wRatio < $hRatio) { // x axis is full, draw limit on y
imagefilledrectangle($im, 0, $hSpace * $ratio, $w - 1, $h - 1, $colorGray);
} else { // y axis is full, draw limit on x
imagefilledrectangle($im, $wSpace * $ratio, 0, $w - 1, $h - 1, $colorGray);
}
// axis
for($pixelsPerUnit = 15; $pixelsPerUnit <= 40; $pixelsPerUnit++) {
$tmp = floor($wSpace * $ratio / $pixelsPerUnit);
if($tmp == 0)
$tmp = 1;
$wUnitsPerUnit = $wSpace / $tmp;
$tmp = floor($hSpace * $ratio / $pixelsPerUnit);
if($tmp == 0)
$tmp = 1;
$hUnitsPerUnit = $hSpace / $tmp;
if(floor($wUnitsPerUnit * 10) % 50 == 0
&& floor($hUnitsPerUnit * 10) % 50 == 0)
break;
}
$wUnitsPerUnit = floor($wUnitsPerUnit);
$hUnitsPerUnit = floor($hUnitsPerUnit);
$yAxisX = $xAxisY = 0;
if($space[$dimensions[0]]['min'] < 0) { // y
$yAxisX = $space[$dimensions[0]]['min'] * $ratio * -1;
imageline($im, $yAxisX, 0, $yAxisX, $h - 1, $colorBlack);
}
if($space[$dimensions[1]]['min'] < 0) { // x
$xAxisY = $space[$dimensions[1]]['min'] * $ratio * -1;
imageline($im, 0, $xAxisY, $w - 1, $xAxisY, $colorBlack);
}
for($x = $yAxisX, $i = 0; $x < $w; $x += $pixelsPerUnit, $i++) {
imageline($im, $x, $xAxisY - 3, $x, $xAxisY + 3, $colorBlack);
imagestring($im, 1, $x, $xAxisY >= 13 ? $xAxisY - 13 : $xAxisY + 6,
($i * $wUnitsPerUnit), $colorBlack);
}
for($x = $yAxisX, $i = 0; $x > 0; $x -= $pixelsPerUnit, $i--) {
imageline($im, $x, $xAxisY - 3, $x, $xAxisY + 3, $colorBlack);
imagestring($im, 1, $x, $xAxisY >= 13 ? $xAxisY - 13 : $xAxisY + 6,
($i * $wUnitsPerUnit), $colorBlack);
}
for($y = $xAxisY, $i = 0; $y < $h; $y += $pixelsPerUnit, $i++) {
imageline($im, $yAxisX - 3, $y, $yAxisX + 3, $y, $colorBlack);
if($i > 0)
imagestring($im, 1, $yAxisX <= $w - 16 ? $yAxisX + 6 : $yAxisX - 16, $y - 4,
($i * $hUnitsPerUnit), $colorBlack);
}
for($y = $xAxisY, $i = 0; $y > 0; $y -= $pixelsPerUnit, $i--) {
imageline($im, $yAxisX - 3, $y, $yAxisX + 3, $y, $colorBlack);
if($i < 0)
imagestring($im, 1, $yAxisX <= $w - 16 ? $yAxisX + 6 : $yAxisX - 16, $y - 4,
($i * $hUnitsPerUnit), $colorBlack);
}
// border
imagerectangle($im, 0, 0, $w - 1, $h - 1, $colorBlack);
header('Content-type: image/png');
imagepng($im);
}