Ejemplo n.º 1
0
    protected function _border_dashed($x, $y, $length, $color, $widths, $side, $corner_style = "bevel")
    {
        list($top, $right, $bottom, $left) = $widths;

        $pattern = $this->_get_dash_pattern("dashed", $$side);

        switch ($side) {

            case "top":
                $delta = $top / 2;
            case "bottom":
                $delta = isset($delta) ? $delta : -$bottom / 2;
                $this->_canvas->line($x, $y + $delta, $x + $length, $y + $delta, $color, $$side, $pattern);
                break;

            case "left":
                $delta = $left / 2;
            case "right":
                $delta = isset($delta) ? $delta : -$right / 2;
                $this->_canvas->line($x + $delta, $y, $x + $delta, $y + $length, $color, $$side, $pattern);
                break;

            default:
                return;
        }

    }
Ejemplo n.º 2
0
 protected function _border_line($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $pattern_name, $r11 = 0, $r12 = 0, $r21 = 0, $r22)
 {
     // TODO: What is $corner_style for ?
     list($top, $right, $bottom, $left) = $widths;
     $width = ${$side};
     $pattern = $this->_get_dash_pattern($pattern_name, $width);
     $half_width = $width / 2;
     $r11 -= $half_width;
     $r12 -= $half_width;
     $r21 -= $half_width;
     $r22 -= $half_width;
     $length -= $width;
     $outdraw = 0.5;
     switch ($side) {
         case "top":
             $x += $half_width;
             $y += $half_width;
             if ($r11 and $r12) {
                 $this->_canvas->arc($x + $r12, $y + $r11, $r12, $r11, 90 - $outdraw, 135 + $outdraw, $color, $width, $pattern);
             }
             $this->_canvas->line($x + $r12, $y, $x + $length - $r21, $y, $color, $width, $pattern);
             if ($r21 and $r22) {
                 $this->_canvas->arc($x + $length - $r21, $y + $r22, $r21, $r22, 45 - $outdraw, 90 + $outdraw, $color, $width, $pattern);
             }
             break;
         case "bottom":
             $x += $half_width;
             $y -= $half_width;
             if ($r21 and $r22) {
                 $this->_canvas->arc($x + $r21, $y - $r22, $r21, $r22, 225 - $outdraw, 270 + $outdraw, $color, $width, $pattern);
             }
             $this->_canvas->line($x + $r21, $y, $x + $length - $r12, $y, $color, $width, $pattern);
             if ($r11 and $r12) {
                 $this->_canvas->arc($x + $length - $r12, $y - $r11, $r12, $r11, 270 - $outdraw, 315 + $outdraw, $color, $width, $pattern);
             }
             break;
         case "left":
             $y += $half_width;
             $x += $half_width;
             if ($r11 and $r12) {
                 $this->_canvas->arc($x + $r11, $y + $length - $r12, $r11, $r12, 180 - $outdraw, 225 + $outdraw, $color, $width, $pattern);
             }
             $this->_canvas->line($x, $y + $r21, $x, $y + $length - $r12, $color, $width, $pattern);
             if ($r21 and $r22) {
                 $this->_canvas->arc($x + $r22, $y + $r21, $r22, $r21, 135 - $outdraw, 180 + $outdraw, $color, $width, $pattern);
             }
             break;
         case "right":
             $y += $half_width;
             $x -= $half_width;
             if ($r21 and $r22) {
                 $this->_canvas->arc($x - $r22, $y + $length - $r21, $r22, $r21, 315 - $outdraw, 360 + $outdraw, $color, $width, $pattern);
             }
             $this->_canvas->line($x, $y + $r12, $x, $y + $length - $r21, $color, $width, $pattern);
             if ($r11 and $r12) {
                 $this->_canvas->arc($x - $r11, $y + $r12, $r11, $r12, 0 - $outdraw, 45 + $outdraw, $color, $width, $pattern);
             }
             break;
     }
 }
 protected function _border_line($x, $y, $length, $color, $widths, $side, $corner_style = "bevel", $pattern_name, $r1 = 0, $r2 = 0)
 {
     list($top, $right, $bottom, $left) = $widths;
     $width = ${$side};
     $pattern = $this->_get_dash_pattern($pattern_name, $width);
     $half_width = $width / 2;
     $r1 -= $half_width;
     $r2 -= $half_width;
     $adjust = $r1 / 80;
     $length -= $width;
     switch ($side) {
         case "top":
             $x += $half_width;
             $y += $half_width;
             if ($r1 > 0) {
                 $this->_canvas->arc($x + $r1, $y + $r1, $r1, $r1, 90 - $adjust, 135 + $adjust, $color, $width, $pattern);
             }
             $this->_canvas->line($x + $r1, $y, $x + $length - $r2, $y, $color, $width, $pattern);
             if ($r2 > 0) {
                 $this->_canvas->arc($x + $length - $r2, $y + $r2, $r2, $r2, 45 - $adjust, 90 + $adjust, $color, $width, $pattern);
             }
             break;
         case "bottom":
             $x += $half_width;
             $y -= $half_width;
             if ($r1 > 0) {
                 $this->_canvas->arc($x + $r1, $y - $r1, $r1, $r1, 225 - $adjust, 270 + $adjust, $color, $width, $pattern);
             }
             $this->_canvas->line($x + $r1, $y, $x + $length - $r2, $y, $color, $width, $pattern);
             if ($r2 > 0) {
                 $this->_canvas->arc($x + $length - $r2, $y - $r2, $r2, $r2, 270 - $adjust, 315 + $adjust, $color, $width, $pattern);
             }
             break;
         case "left":
             $y += $half_width;
             $x += $half_width;
             if ($r1 > 0) {
                 $this->_canvas->arc($x + $r1, $y + $r1, $r1, $r1, 135 - $adjust, 180 + $adjust, $color, $width, $pattern);
             }
             $this->_canvas->line($x, $y + $r1, $x, $y + $length - $r2, $color, $width, $pattern);
             if ($r2 > 0) {
                 $this->_canvas->arc($x + $r2, $y + $length - $r2, $r2, $r2, 180 - $adjust, 225 + $adjust, $color, $width, $pattern);
             }
             break;
         case "right":
             $y += $half_width;
             $x -= $half_width;
             if ($r1 > 0) {
                 $this->_canvas->arc($x - $r1, $y + $r1, $r1, $r1, 0 - $adjust, 45 + $adjust, $color, $width, $pattern);
             }
             $this->_canvas->line($x, $y + $r1, $x, $y + $length - $r2, $color, $width, $pattern);
             if ($r2 > 0) {
                 $this->_canvas->arc($x - $r2, $y + $length - $r2, $r2, $r2, 315 - $adjust, 360 + $adjust, $color, $width, $pattern);
             }
             break;
     }
 }
Ejemplo n.º 4
0
 protected function drawProfile($profile, $width, $height)
 {
     $margint = 50;
     $marginr = 50;
     $marginb = 50;
     $marginl = 50;
     $last = end($profile);
     $maxdist = $last[0];
     $minalti = array(array(0, INF));
     $maxalti = array(array(0, -INF));
     foreach ($profile as $coords) {
         $alti = $coords[1];
         if ($alti == $minalti[0][1]) {
             $minalti[] = array($coords[0], $alti);
         } else {
             if ($alti < $minalti[0][1]) {
                 $minalti = array(array($coords[0], $alti));
             }
         }
         if ($alti == $maxalti[0][1]) {
             $maxalti[] = array($coords[0], $alti);
         } else {
             if ($alti > $maxalti[0][1]) {
                 $maxalti = array(array($coords[0], $alti));
             }
         }
     }
     $canvas = new Canvas($width, $height, $margint, $marginr, $marginb, $marginl);
     $canvas->setViewBox(0, $minalti[0][1], $maxdist, $maxalti[0][1]);
     $canvas->rect(0, 0, $width, $height, "FFFFFF");
     $slopecolor = function ($slope) {
         if ($slope > 18) {
             return "FF0000";
             // red
         } else {
             if ($slope > 12) {
                 return "FF4000";
             } else {
                 if ($slope > 7) {
                     return "FF8000";
                 } else {
                     if ($slope > 3) {
                         return "FFC000";
                     } else {
                         if ($slope > 0) {
                             return "FFFF00";
                             // yellow
                         } else {
                             if ($slope > -3) {
                                 return "00FFFF";
                             } else {
                                 if ($slope > -7) {
                                     return "00C0FF";
                                 } else {
                                     if ($slope > -12) {
                                         return "0080FF";
                                     } else {
                                         if ($slope > -18) {
                                             return "0040FF";
                                         } else {
                                             return "0000FF";
                                             // blue;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     };
     $canvas->setThickness(2);
     $prev = null;
     foreach ($profile as $coord) {
         if (!is_null($prev)) {
             $dist = $coord[0];
             $alti = $coord[1];
             $prevdist = $prev[0];
             $prevalti = $prev[1];
             $slope = 100 * ($alti - $prevalti) / ($dist - $prevdist);
             $canvas->line($canvas->canvasXPos($prevdist), $canvas->canvasYPos($prevalti), $canvas->canvasXPos($dist), $canvas->canvasYPos($alti), $slopecolor($slope), true);
         }
         $prev = $coord;
     }
     $canvas->setThickness(1);
     $canvas->setFont(APPLICATION_PATH . '/resources/' . 'DejaVuSans.ttf', 10);
     list($minx, $miny, $maxx, $maxy) = $canvas->getViewBox();
     $deltax = pow(10, floor(log10($maxx - $minx)));
     foreach (range($minx, $maxx, $deltax) as $x) {
         $canvas->line($canvas->canvasXPos($x), $height - $marginb + 10, $canvas->canvasXPos($x), $height - $marginb, "000000");
         if ($deltax < 1000) {
             $text = $x . "m";
         } else {
             $text = round($x / 1000) . "km";
         }
         $canvas->text($canvas->canvasXPos($x), $height - $marginb + 10 + 3, $text, "000000", "cb");
     }
     $canvas->line($marginl, $height - $marginb, $width - $marginr, $height - $marginb, "000000");
     $deltay = pow(10, floor(log10($maxy - $miny)));
     foreach (range($miny, $maxy, $deltay) as $y) {
         $canvas->line($marginl - 10, $canvas->canvasYPos($y), $marginl, $canvas->canvasYPos($y), "000000");
         $text = $y . "m";
         $canvas->text($marginl - 10 - 3, $canvas->canvasYPos($y), $text, "000000", "rc");
     }
     $canvas->line($marginl, $height - $marginb, $marginr, $margint, "000000");
     list($minx, $miny, $maxx, $maxy) = $canvas->getViewBox();
     $limits = array($canvas->canvasYPos($maxy) + 3, $canvas->canvasXPos($maxx) - 3, $canvas->canvasYPos($miny) - 3, $canvas->canvasXPos($minx) + 3);
     $prev = null;
     foreach ($minalti as $coords) {
         list($dist, $alti) = $coords;
         if (!is_null($prev)) {
             $xdist = $canvas->canvasXPos($dist) - $canvas->canvasXPos($prev[0]);
             /* second label would be less than 10px from previous one. Do
                not display it */
             if ($xdist < 10) {
                 continue;
             }
         }
         $text = round($alti) . "m";
         $xpos = $canvas->canvasXPos($dist);
         $ypos = $canvas->canvasYPos($alti);
         $canvas->text($xpos, $ypos + 5, $text, "000000", "cb", $limits);
         $canvas->rect($xpos - 1, $ypos - 1, $xpos + 1, $ypos + 1, "000000");
         $prev = $coords;
     }
     $prev = null;
     foreach ($maxalti as $coords) {
         list($dist, $alti) = $coords;
         if (!is_null($prev)) {
             $xdist = $canvas->canvasXPos($dist) - $canvas->canvasXPos($prev[0]);
             /* second label would be less than 10px from previous one. Do
                not display it */
             if ($xdist < 10) {
                 continue;
             }
         }
         $text = round($alti) . "m";
         $xpos = $canvas->canvasXPos($dist);
         $ypos = $canvas->canvasYPos($alti);
         $canvas->text($xpos, $ypos - 5, $text, "000000", "ct", $limits);
         $canvas->rect($xpos - 1, $ypos - 1, $xpos + 1, $ypos + 1, "000000");
         $prev = $coords;
     }
     return $canvas;
 }