Beispiel #1
0
function drawPath($path, $form, $models, $objects)
{
    $form->input('select', 'type[' . $path->id . ']', $path->item, ['values' => ['' => 'Выберите', 'continue' => 'Пропустить', 'container' => 'Контейнер', 'object' => ['text' => 'Объект', 'input' => ['name' => 'typeOptions[' . $path->id . ']', 'type' => 'select', 'source' => 'array', 'sourceArray' => $models]]] + $objects, 'value' => $path->type != 'object' ? $path->type : $path->object_id]);
    foreach ($path->childs as $path) {
        echo '<div class="col-xs-offset-1">';
        drawPath($path, $form, $models, $objects);
        echo '</div>';
    }
}
Beispiel #2
0
 function Radar($save, $file = '')
 {
     global $doc, $SCALE, $FONT_SIZE, $dx, $dy, $g, $myDoc, $msg, $lang, $f, $name, $save;
     $FONT_SIZE = 12;
     //$SCALE/10;
     $g;
     $doc = new DOMDocument('1.0');
     $myDoc = $this->docs;
     $lang = $this->lang;
     $f = $this->f;
     $num = count($this->ids);
     $name = $this->criteria;
     $msg = $this->msg;
     if (!$save) {
         header("Content-type: image/svg+xml");
     }
     //draw $n equidistant axis
     if (!function_exists('drawAxis')) {
         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");
             //N: should be commented
             for ($i = 1; $i < $n + 1; $i++) {
                 drawSingleAxis(2 * $i * pi() / $n);
             }
         }
     }
     //draw a single axis at $angle (in radians) from angle 0
     if (!function_exists('drawSingleAxis')) {
         function drawSingleAxis($angle)
         {
             global $SCALE, $dx, $dy;
             $x2 = 2 * $SCALE * cos($angle) + $dx;
             $y2 = 2 * $SCALE * sin($angle) + $dy;
             drawLine($dx, $dy, $x2, $y2);
         }
     }
     //draw a circle of $r radius
     if (!function_exists('drawCircle')) {
         function drawCircle($r)
         {
             global $dx, $dy, $doc, $g;
             $circle = $doc->createElement("circle");
             $circle->setAttribute("cx", $dx);
             $circle->setAttribute("cy", $dy);
             $circle->setAttribute("r", $r);
             $circle->setAttribute("fill", "none");
             $circle->setAttribute("stroke", "lightgrey");
             $circle->setAttribute("stroke-width", "1");
             $g->appendChild($circle);
         }
     }
     //draw a line between two points
     if (!function_exists('drawLine')) {
         function drawLine($x1, $y1, $x2, $y2)
         {
             global $doc, $g;
             $line = $doc->createElement("line");
             $line->setAttribute("x1", $x1);
             $line->setAttribute("y1", $y1);
             $line->setAttribute("x2", $x2);
             $line->setAttribute("y2", $y2);
             $line->setAttribute("stroke", "lightgrey");
             $line->setAttribute("stroke-width", "1");
             $g->appendChild($line);
         }
     }
     //draw scale mark on the radar
     //$x, $y: coordinates
     //$mark : text to be displayed
     if (!function_exists('drawMark')) {
         function drawMark($x, $y, $mark)
         {
             global $FONT_SIZE, $dx, $dy, $doc, $g;
             $text = $doc->createElement("text");
             $text->setAttribute("x", $x + $dx);
             $text->setAttribute("y", $y + $dy);
             $text->setAttribute("font-family", "Verdana");
             $text->setAttribute("font-size", $FONT_SIZE);
             $text->setAttribute("fill", "lightgrey");
             $text->appendChild($doc->createTextNode($mark));
             $g->appendChild($text);
         }
     }
     //draw an axis legend
     //$x, $y: coordinates
     //$element : element which title is to be displayed
     if (!function_exists('drawText')) {
         function drawText($x, $y, $element)
         {
             global $FONT_SIZE, $dx, $dy, $doc, $g, $lang, $f, $save;
             $text = $doc->createElement("text");
             $text->setAttribute("x", $x + $dx);
             $text->setAttribute("y", $y + $dy);
             $text->setAttribute("font-family", "Verdana");
             $text->setAttribute("font-size", $FONT_SIZE);
             $text->appendChild($doc->createTextNode($element->title));
             if ($element->children) {
                 if ($save) {
                     $text->setAttribute("fill", "black");
                 } else {
                     $text->setAttribute("fill", "green");
                 }
                 $a = $doc->createElement("a");
                 $a->setAttribute("xlink:href", $_SERVER['PHP_SELF'] . "?lang={$lang}&" . $f . "c=" . $element->name . "&svg=yes");
                 $a->appendChild($text);
                 $g->appendChild($a);
             } else {
                 $text->setAttribute("fill", "black");
                 $g->appendChild($text);
             }
             //text position is ajusted to be outside the circle shape
             //8 here is empiric data :)
             $textLength = strlen($element->title) * 8;
             $myX = abs($x) == $x ? $x : $x - $textLength;
             $myY = abs($y) == $y ? $y + $FONT_SIZE : $y;
             $text->setAttribute("x", $myX + $dx);
             $text->setAttribute("y", $myY + $dy);
         }
     }
     //draw "Up" and "Back" links under the navigation tree
     //$name : name of the current criterion
     if (!function_exists('drawNavBar')) {
         function drawNavBar($name)
         {
             global $doc, $g, $msg, $myDoc, $lang, $f;
             $a = $doc->createElement("a");
             $a->setAttribute("xlink:href", "show.php?lang={$lang}&" . $f . "svg=yes");
             $text = $doc->createElement("text");
             $text->setAttribute("x", 0);
             $text->setAttribute("y", 25);
             $text->setAttribute("fill", "green");
             $text->appendChild($doc->createTextNode($msg['s5_back']));
             $a->appendChild($text);
             $g->appendChild($a);
             if ($myDoc[0]->getParent($name)) {
                 $a = $doc->createElement("a");
                 $a->setAttribute("xlink:href", $_SERVER['PHP_SELF'] . "?lang={$lang}&" . $f . "c=" . $myDoc[0]->getParent($name)->getAttribute("name") . "&svg=yes");
                 $text = $doc->createElement("text");
                 $text->setAttribute("x", strlen($msg['s5_back']) * 12);
                 $text->setAttribute("y", 25);
                 $text->setAttribute("fill", "green");
                 $text->appendChild($doc->createTextNode($msg['s5_up']));
                 $a->appendChild($text);
                 $g->appendChild($a);
             }
         }
     }
     //draw the graph's title including software name and release and navigation tree
     //$name : name of the current criterion
     if (!function_exists('drawTitle')) {
         function drawTitle($name)
         {
             global $doc, $g, $FONT_SIZE, $myDoc;
             $text = $doc->createElement("text");
             $text->setAttribute("font-family", "Verdana");
             $text->setAttribute("font-weight", "bold");
             $text->setAttribute("font-size", $FONT_SIZE);
             $tspan = $doc->createElement("tspan");
             $tspan->appendChild($doc->createTextNode($title = $myDoc[0]->getkeytitle($name)));
             $text->appendChild($tspan);
             $lasttspan = $tspan;
             $node = $name;
             while ($myDoc[0]->getParent($node)) {
                 $tspan = $doc->createElement("tspan");
                 $tspan->appendChild($doc->createTextNode($myDoc[0]->getParent($node)->getAttribute("title") . " > "));
                 $text->insertBefore($tspan, $lasttspan);
                 $node = $myDoc[0]->getParent($node)->getAttribute("name");
                 $lasttspan = $tspan;
             }
             for ($i = 0; $i < count($myDoc); $i++) {
                 $tspan = $doc->createElement("tspan");
                 $tspan->setAttribute("fill", getcolor($i));
                 $tspan->appendChild($doc->createTextNode($myDoc[$i]->getkey("appname") . " " . $myDoc[$i]->getkey("release") . " "));
                 $text->insertBefore($tspan, $lasttspan);
             }
             return $text;
         }
     }
     //draw path between points on each axis
     //$myDoc : QSOSDocument concerned
     //$name : name of the criteria regrouping subcriteria to be displayed
     //	if $name is not set, gobal sectiosn are displayed
     //$n : position of the software to display in the list (used for coloring)
     //$weights: array of weights for the scores
     if (!function_exists('drawPath')) {
         function drawPath($myDoc, $name, $n, $weights)
         {
             global $doc, $SCALE, $dx, $dy;
             $path = $doc->createElement("path");
             $myD = "";
             if (isset($name) && $name != "") {
                 $tree = $myDoc->getWeightedSubTree($name, $weights);
             } else {
                 $tree = $myDoc->getWeightedTree($weights);
             }
             /*N
                   $totalWeight = 0;
                   for ($i=0; $i < count($tree); $i++) {
             	$totalWeight = $totalWeight + $weights[$tree[$i]->name];
                   }*/
             drawAxis(count($tree));
             $angle = 0;
             for ($i = 0; $i < count($tree); $i++) {
                 /*N $delta = $weights[$tree[$i]->name]*2*pi()/$totalWeight;
                 	$angle_text = $angle + $delta/2;
                 	$angle = $angle + $delta;
                 	drawSingleAxis($angle);*/
                 $myD .= $i == 0 ? "M" : "L";
                 //N: should be commented
                 $angle = ($i + 1) * 2 * pi() / count($tree);
                 $x = $tree[$i]->score * $SCALE * cos($angle);
                 $x = $x + $dx;
                 $y = $tree[$i]->score * $SCALE * sin($angle);
                 $y = $y + $dy;
                 $myD .= " {$x} {$y} ";
                 //2.1 = 2 + 0.1 of padding before actual text display
                 //N: drawText(2.1*$SCALE*cos($angle_text), 2.1*$SCALE*sin($angle_text), $tree[$i]);
                 drawText(2.1 * $SCALE * cos($angle), 2.1 * $SCALE * sin($angle), $tree[$i]);
             }
             $myD .= "z";
             $path->setAttribute("d", $myD);
             $path->setAttribute("fill", getColor($n));
             $path->setAttribute("fill-opacity", "0.2");
             $path->setAttribute("stroke-width", "3");
             $path->setAttribute("stroke", getColor($n));
             return $path;
         }
     }
     //Return drawing color depending on software position in the list
     if (!function_exists('getColor')) {
         function getColor($i)
         {
             $colors = array('red', 'blue', 'green', 'purple');
             if ($i < count($colors)) {
                 return $colors[$i];
             } else {
                 return "black";
             }
         }
     }
     $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', '1000');
     $svg->setAttribute('height', '600');
     //Graph element
     $g = $doc->createElement('g');
     $g->setAttribute('transform', 'translate(50,50)');
     $g->appendChild(drawTitle($name));
     if (!$save) {
         drawNavBar($name);
     }
     //display each software on the graph
     for ($i = 0; $i < $num; $i++) {
         $g->appendChild(drawPath($myDoc[$i], $name, $i, $weights));
     }
     $svg->appendChild($g);
     $doc->appendChild($svg);
     if ($save) {
         $doc->save($file);
     } else {
         echo $doc->saveXML();
     }
 }