[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qsos-commits] qsos/apps/phpviewer SVGRadar.php
From: |
Raphaël Semeteys |
Subject: |
[Qsos-commits] qsos/apps/phpviewer SVGRadar.php |
Date: |
Tue, 14 Nov 2006 00:21:04 +0000 |
CVSROOT: /sources/qsos
Module name: qsos
Changes by: Raphaël Semeteys <rsemeteys> 06/11/14 00:21:04
Modified files:
apps/phpviewer : SVGRadar.php
Log message:
QSOS file is now a GET parameter
drawTitle() and drawPath() functions added
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/phpviewer/SVGRadar.php?cvsroot=qsos&r1=1.1&r2=1.2
Patches:
Index: SVGRadar.php
===================================================================
RCS file: /sources/qsos/qsos/apps/phpviewer/SVGRadar.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- SVGRadar.php 13 Nov 2006 17:54:01 -0000 1.1
+++ SVGRadar.php 14 Nov 2006 00:21:03 -0000 1.2
@@ -2,27 +2,36 @@
header("Content-type: image/svg+xml");
include('QSOSDocument.php');
-$criterion = $_GET['c'];
+$file = $_GET['f'];
+$name = $_GET['c'];
+
+if (!(isset($file))) {
+ die("No QSOS file provided !");
+}
$SCALE = 100; //1 QSOS unit in pixels
$FONT_SIZE = 14; //$SCALE/10;
-$myDoc = new QSOSDocument('mysql-5.0.qsos');
+$myDoc = new QSOSDocument($file);
$doc = new DOMDocument('1.0');
-//draw "n" equidistant axis
+//draw $n equidistant axis
function drawAxis($n) {
global $SCALE;
drawCircle(0.5*$SCALE);
+ drawMark(0.5*$SCALE-25, 15, "0.5");
drawCircle($SCALE);
+ drawMark($SCALE-15, 15, "1");
drawCircle(1.5*$SCALE);
+ drawMark(1.5*$SCALE-25, 15, "1.5");
drawCircle(2*$SCALE);
+ drawMark(2*$SCALE-15, 15, "2");
for ($i=1; $i < $n+1; $i++) {
drawSingleAxis(2*$i*pi()/$n);
}
}
-//draw a single axis at "angle" (in radians) from angle 0
+//draw a single axis at $angle (in radians) from angle 0
function drawSingleAxis($angle) {
global $SCALE;
$x2 = 2*$SCALE*cos($angle);
@@ -30,7 +39,7 @@
drawLine(0, 0, $x2, $y2);
}
-//draw a circle of "r" radius
+//draw a circle of $r radius
function drawCircle($r) {
global $doc;
global $g;
@@ -58,10 +67,29 @@
$g->appendChild($line);
}
+//draw scale mark on the radar
+//$x, $y: coordinates
+//$mark : text to be displayed
+function drawMark($x, $y, $mark) {
+ global $doc;
+ global $g;
+ global $FONT_SIZE;
+ $text = $doc->createElement("text");
+ $text->setAttribute("x", $x);
+ $text->setAttribute("y", $y);
+ $text->setAttribute("font-family", "Verdana");
+ $text->setAttribute("font-size", $FONT_SIZE);
+
+ $text->setAttribute("fill", "blue");
+ $text->appendChild($doc->createTextNode($mark));
+ $g->appendChild($text);
+}
+
//draw an axis legend
-//x, y: coordinates
-//element : element which title is to be displayed
+//$x, $y: coordinates
+//$element : element which title is to be displayed
function drawText($x, $y, $element) {
+ global $file;
global $doc;
global $g;
global $FONT_SIZE;
@@ -70,14 +98,12 @@
$text->setAttribute("y", $y);
$text->setAttribute("font-family", "Verdana");
$text->setAttribute("font-size", $FONT_SIZE);
-
- $text->setAttribute("fill", "green");
$text->appendChild($doc->createTextNode($element->title));
if ($element->children) {
$text->setAttribute("fill", "green");
$a = $doc->createElement("a");
- $a->setAttribute("xlink:href",
'SVGRadar.php?c='.$element->name);
+ $a->setAttribute("xlink:href",
"SVGRadar.php?f=$file&c=".$element->name);
$a->appendChild($text);
$g->appendChild($a);
} else {
@@ -94,42 +120,75 @@
$text->setAttribute("y", $myY);
}
-//Text
-$svg = $doc->createElement('svg');
-$svg->setAttribute('xmlns', 'http://www.w3.org/2000/svg');
-$svg->setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
-$svg->setAttribute('width', '100%');
-$svg->setAttribute('height', '100%');
+function drawTitle($myDoc, $name) {
+ global $doc;
+ global $file;
+ global $FONT_SIZE;
+ $title = $myDoc->getkeytitle($name);
+ $node = $name;
-//Graph element
-$g = $doc->createElement('g');
-$g->setAttribute('transform', 'translate(500,300)');
+ while ($myDoc->getParent($node)) {
+ $title = $myDoc->getParent($node)->getAttribute("title") . " >
". $title;
+ $node = $myDoc->getParent($node)->getAttribute("name");
+ }
+ $title = $myDoc->getkey("appname")." ".$myDoc->getkey("release").
$title;
+ $text = $doc->createElement("text");
+ $text->setAttribute("font-family", "Verdana");
+ $text->setAttribute("font-weight", "bold");
+ $text->setAttribute("font-size", $FONT_SIZE);
+ $text->setAttribute("x", -475);
+ $text->setAttribute("y", -275);
+ $text->appendChild($doc->createTextNode($title));
+
+ return $text;
+}
//draw path between points on each axis
-$path = $doc->createElement("path");
-$myD = "";
+//$myDoc : QSOSDocument concerned
+//$name : name of the criteria regrouping subcriteria to be displayed
+//if $name is not set, gobal sectiosn are displayed
+function drawPath($myDoc, $name) {
+ global $doc;
+ global $SCALE;
+ $path = $doc->createElement("path");
+ $myD = "";
-if (isset($criterion)) {
- $tree = $myDoc->getSubTree($criterion);
-} else {
+ if (isset($name)) {
+ $tree = $myDoc->getSubTree($name);
+ } else {
$tree = $myDoc->getTree();
-}
+ }
-drawAxis(count($tree));
-for ($i=0; $i < count($tree); $i++) {
+ drawAxis(count($tree));
+ for ($i=0; $i < count($tree); $i++) {
$myD .= ($i==0)?"M":"L";
$angle = ($i+1)*2*pi()/(count($tree));
$myD .= " " . ($tree[$i]->score)*$SCALE*cos($angle) . " " .
($tree[$i]->score)*$SCALE*sin($angle) . " ";
//2.1 = 2 + 0.1 of padding before actual text display
drawText(2.1*$SCALE*cos($angle), 2.1*$SCALE*sin($angle), $tree[$i]);
+ }
+ $myD .= "z";
+ $path->setAttribute("d", $myD);
+ $path->setAttribute("fill", "red");
+ $path->setAttribute("opacity", "0.4");
+ $path->setAttribute("stroke", "red");
+ $path->setAttribute("stroke-width", "2");
+
+ return $path;
}
-$myD .= "z";
-$path->setAttribute("d", $myD);
-$path->setAttribute("fill", "none");
-$path->setAttribute("stroke", "red");
-$path->setAttribute("stroke-width", "2");
-$g->appendChild($path);
+//svg element
+$svg = $doc->createElement('svg');
+$svg->setAttribute('xmlns', 'http://www.w3.org/2000/svg');
+$svg->setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
+$svg->setAttribute('width', '100%');
+$svg->setAttribute('height', '100%');
+
+//Graph element
+$g = $doc->createElement('g');
+$g->setAttribute('transform', 'translate(500,300)');
+$g->appendChild(drawTitle($myDoc, $name));
+$g->appendChild(drawPath($myDoc, $name));
$svg->appendChild($g);
$doc->appendChild($svg);