vendor/amenadiel/jpgraph/src/plot/PlotMark.php line 220

  1. <?php
  2. /**
  3.  * JPGraph v4.0.3
  4.  */
  5. namespace Amenadiel\JpGraph\Plot;
  6. use Amenadiel\JpGraph\Graph;
  7. use Amenadiel\JpGraph\Image;
  8. use Amenadiel\JpGraph\Text;
  9. use Amenadiel\JpGraph\Util;
  10. /**
  11.  * File:        JPGRAPH_PLOTMARK.PHP
  12.  * // Description: Class file. Handles plotmarks
  13.  * // Created:     2003-03-21
  14.  * // Ver:         $Id: jpgraph_plotmark.inc.php 1106 2009-02-22 20:16:35Z ljp $
  15.  * //
  16.  * // Copyright (c) Asial Corporation. All rights reserved.
  17.  */
  18. /**
  19.  * @class PlotMark
  20.  * // Description: Handles the plot marks in graphs
  21.  */
  22. class PlotMark
  23. {
  24.     public $title;
  25.     public $show true;
  26.     public $type;
  27.     public $weight           1;
  28.     public $iFormatCallback  '';
  29.     public $iFormatCallback2 '';
  30.     public $fill_color       'blue';
  31.     public $color            'black';
  32.     public $width            4;
  33.     private $yvalue;
  34.     private $xvalue '';
  35.     private $csimtarget;
  36.     private $csimwintarget '';
  37.     private $csimalt;
  38.     private $csimareas;
  39.     private $markimg     '';
  40.     private $iScale      1.0;
  41.     private $oldfilename '';
  42.     private $iFileName   '';
  43.     private $imgdata_balls;
  44.     private $imgdata_diamonds;
  45.     private $imgdata_squares;
  46.     private $imgdata_bevels;
  47.     private $imgdata_stars;
  48.     private $imgdata_pushpins;
  49.     /**
  50.      * CONSTRUCTOR.
  51.      */
  52.     public function __construct()
  53.     {
  54.         $this->title = new Text\Text();
  55.         $this->title->Hide();
  56.         $this->csimareas '';
  57.         $this->type      = -1;
  58.     }
  59.     /**
  60.      * PUBLIC METHODS.
  61.      *
  62.      * @param mixed $aType
  63.      * @param mixed $aFileName
  64.      * @param mixed $aScale
  65.      */
  66.     public function SetType($aType$aFileName ''$aScale 1.0)
  67.     {
  68.         $this->type $aType;
  69.         if ($aType == MARK_IMG && $aFileName == '') {
  70.             Util\JpGraphError::RaiseL(23003); //('A filename must be specified if you set the mark type to MARK_IMG.');
  71.         }
  72.         $this->iFileName $aFileName;
  73.         $this->iScale    $aScale;
  74.     }
  75.     public function SetCallback($aFunc)
  76.     {
  77.         $this->iFormatCallback $aFunc;
  78.     }
  79.     public function SetCallbackYX($aFunc)
  80.     {
  81.         $this->iFormatCallback2 $aFunc;
  82.     }
  83.     public function GetType()
  84.     {
  85.         return $this->type;
  86.     }
  87.     public function SetColor($aColor)
  88.     {
  89.         $this->color $aColor;
  90.     }
  91.     public function SetFillColor($aFillColor)
  92.     {
  93.         $this->fill_color $aFillColor;
  94.     }
  95.     public function SetWeight($aWeight)
  96.     {
  97.         $this->weight $aWeight;
  98.     }
  99.     // Synonym for SetWidth()
  100.     public function SetSize($aWidth)
  101.     {
  102.         $this->width $aWidth;
  103.     }
  104.     public function SetWidth($aWidth)
  105.     {
  106.         $this->width $aWidth;
  107.     }
  108.     public function SetDefaultWidth()
  109.     {
  110.         switch ($this->type) {
  111.             case MARK_CIRCLE:
  112.             case MARK_FILLEDCIRCLE:
  113.                 $this->width 4;
  114.                 break;
  115.             default:
  116.                 $this->width 7;
  117.         }
  118.     }
  119.     public function GetWidth()
  120.     {
  121.         return $this->width;
  122.     }
  123.     public function Hide($aHide true)
  124.     {
  125.         $this->show = !$aHide;
  126.     }
  127.     public function Show($aShow true)
  128.     {
  129.         $this->show $aShow;
  130.     }
  131.     public function SetCSIMAltVal($aY$aX '')
  132.     {
  133.         $this->yvalue $aY;
  134.         $this->xvalue $aX;
  135.     }
  136.     public function SetCSIMTarget($aTarget$aWinTarget '')
  137.     {
  138.         $this->csimtarget    $aTarget;
  139.         $this->csimwintarget $aWinTarget;
  140.     }
  141.     public function SetCSIMAlt($aAlt)
  142.     {
  143.         $this->csimalt $aAlt;
  144.     }
  145.     public function GetCSIMAreas()
  146.     {
  147.         return $this->csimareas;
  148.     }
  149.     public function AddCSIMPoly($aPts)
  150.     {
  151.         $coords round($aPts[0]) . ', ' round($aPts[1]);
  152.         $n      safe_count($aPts) / 2;
  153.         for ($i 1$i $n; ++$i) {
  154.             $coords .= ', ' round($aPts[$i]) . ', ' round($aPts[$i 1]);
  155.         }
  156.         $this->csimareas '';
  157.         if (!empty($this->csimtarget)) {
  158.             $this->csimareas .= "<area shape=\"poly\" coords=\"${coords}\" ";
  159.             $this->csimareas .= 'href="' htmlentities($this->csimtarget) . '"';
  160.             if (!empty($this->csimwintarget)) {
  161.                 $this->csimareas .= ' target="' $this->csimwintarget '" ';
  162.             }
  163.             if (!empty($this->csimalt)) {
  164.                 $tmp sprintf($this->csimalt$this->yvalue$this->xvalue);
  165.                 $this->csimareas .= " title=\"${tmp}\" alt=\"${tmp}\"";
  166.             }
  167.             $this->csimareas .= " />\n";
  168.         }
  169.     }
  170.     public function AddCSIMCircle($x$y$r)
  171.     {
  172.         $x               round($x);
  173.         $y               round($y);
  174.         $r               round($r);
  175.         $this->csimareas '';
  176.         if (!empty($this->csimtarget)) {
  177.             $this->csimareas .= "<area shape=\"circle\" coords=\"${x},${y},${r}\" ";
  178.             $this->csimareas .= 'href="' htmlentities($this->csimtarget) . '"';
  179.             if (!empty($this->csimwintarget)) {
  180.                 $this->csimareas .= ' target="' $this->csimwintarget '" ';
  181.             }
  182.             if (!empty($this->csimalt)) {
  183.                 $tmp sprintf($this->csimalt$this->yvalue$this->xvalue);
  184.                 $this->csimareas .= " title=\"${tmp}\" alt=\"${tmp}\" ";
  185.             }
  186.             $this->csimareas .= " />\n";
  187.         }
  188.     }
  189.     public function Stroke($img$x$y)
  190.     {
  191.         if (!$this->show) {
  192.             return;
  193.         }
  194.         if ($this->iFormatCallback != '' || $this->iFormatCallback2 != '') {
  195.             if ($this->iFormatCallback != '') {
  196.                 $f                            $this->iFormatCallback;
  197.                 list($width$color$fcolor) = call_user_func($f$this->yvalue);
  198.                 $filename                     $this->iFileName;
  199.                 $imgscale                     $this->iScale;
  200.             } else {
  201.                 $f                                                  $this->iFormatCallback2;
  202.                 list($width$color$fcolor$filename$imgscale) = call_user_func($f$this->yvalue$this->xvalue);
  203.                 if ($filename == '') {
  204.                     $filename $this->iFileName;
  205.                 }
  206.                 if ($imgscale == '') {
  207.                     $imgscale $this->iScale;
  208.                 }
  209.             }
  210.             if ($width == '') {
  211.                 $width $this->width;
  212.             }
  213.             if ($color == '') {
  214.                 $color $this->color;
  215.             }
  216.             if ($fcolor == '') {
  217.                 $fcolor $this->fill_color;
  218.             }
  219.         } else {
  220.             $fcolor   $this->fill_color;
  221.             $color    $this->color;
  222.             $width    $this->width;
  223.             $filename $this->iFileName;
  224.             $imgscale $this->iScale;
  225.         }
  226.         if ($this->type == MARK_IMG ||
  227.             ($this->type >= MARK_FLAG1 && $this->type <= MARK_FLAG4) ||
  228.             $this->type >= MARK_IMG_PUSHPIN) {
  229.             // Note: For the builtin images we use the "filename" parameter
  230.             // to denote the color
  231.             $anchor_x 0.5;
  232.             $anchor_y 0.5;
  233.             switch ($this->type) {
  234.                 case MARK_FLAG1:
  235.                 case MARK_FLAG2:
  236.                 case MARK_FLAG3:
  237.                 case MARK_FLAG4:
  238.                     $this->markimg Util\FlagCache::GetFlagImgByName($this->type MARK_FLAG1 1$filename);
  239.                     break;
  240.                 case MARK_IMG:
  241.                     // Load an image and use that as a marker
  242.                     // Small optimization, if we have already read an image don't
  243.                     // waste time reading it again.
  244.                     if ($this->markimg == '' || !($this->oldfilename === $filename)) {
  245.                         $this->markimg     Graph\Graph::LoadBkgImage(''$filename);
  246.                         $this->oldfilename $filename;
  247.                     }
  248.                     break;
  249.                 case MARK_IMG_PUSHPIN:
  250.                 case MARK_IMG_SPUSHPIN:
  251.                 case MARK_IMG_LPUSHPIN:
  252.                     if ($this->imgdata_pushpins == null) {
  253.                         $this->imgdata_pushpins = new Image\ImgData_PushPins();
  254.                     }
  255.                     $this->markimg             $this->imgdata_pushpins->GetImg($this->type$filename);
  256.                     list($anchor_x$anchor_y) = $this->imgdata_pushpins->GetAnchor();
  257.                     break;
  258.                 case MARK_IMG_SQUARE:
  259.                     if ($this->imgdata_squares == null) {
  260.                         $this->imgdata_squares = new Image\ImgData_Squares();
  261.                     }
  262.                     $this->markimg             $this->imgdata_squares->GetImg($this->type$filename);
  263.                     list($anchor_x$anchor_y) = $this->imgdata_squares->GetAnchor();
  264.                     break;
  265.                 case MARK_IMG_STAR:
  266.                     if ($this->imgdata_stars == null) {
  267.                         $this->imgdata_stars = new Image\ImgData_Stars();
  268.                     }
  269.                     $this->markimg             $this->imgdata_stars->GetImg($this->type$filename);
  270.                     list($anchor_x$anchor_y) = $this->imgdata_stars->GetAnchor();
  271.                     break;
  272.                 case MARK_IMG_BEVEL:
  273.                     if ($this->imgdata_bevels == null) {
  274.                         $this->imgdata_bevels = new Image\ImgData_Bevels();
  275.                     }
  276.                     $this->markimg             $this->imgdata_bevels->GetImg($this->type$filename);
  277.                     list($anchor_x$anchor_y) = $this->imgdata_bevels->GetAnchor();
  278.                     break;
  279.                 case MARK_IMG_DIAMOND:
  280.                     if ($this->imgdata_diamonds == null) {
  281.                         $this->imgdata_diamonds = new Image\ImgData_Diamonds();
  282.                     }
  283.                     $this->markimg             $this->imgdata_diamonds->GetImg($this->type$filename);
  284.                     list($anchor_x$anchor_y) = $this->imgdata_diamonds->GetAnchor();
  285.                     break;
  286.                 case MARK_IMG_BALL:
  287.                 case MARK_IMG_SBALL:
  288.                 case MARK_IMG_MBALL:
  289.                 case MARK_IMG_LBALL:
  290.                     if ($this->imgdata_balls == null) {
  291.                         $this->imgdata_balls = new Image\ImgData_Balls();
  292.                     }
  293.                     $this->markimg             $this->imgdata_balls->GetImg($this->type$filename);
  294.                     list($anchor_x$anchor_y) = $this->imgdata_balls->GetAnchor();
  295.                     break;
  296.             }
  297.             $w $img->GetWidth($this->markimg);
  298.             $h $img->GetHeight($this->markimg);
  299.             $dw round($imgscale $w);
  300.             $dh round($imgscale $h);
  301.             // Do potential rotation
  302.             list($x$y) = $img->Rotate($x$y);
  303.             $dx round($x $dw $anchor_x);
  304.             $dy round($y $dh $anchor_y);
  305.             $this->width max($dx$dy);
  306.             $img->Copy($this->markimg$dx$dy00$dw$dh$w$h);
  307.             if (!empty($this->csimtarget)) {
  308.                 $this->csimareas '<area shape="rect" coords="' .
  309.                 $dx ',' $dy ',' round($dx $dw) . ',' round($dy $dh) . '" ' .
  310.                 'href="' htmlentities($this->csimtarget) . '"';
  311.                 if (!empty($this->csimwintarget)) {
  312.                     $this->csimareas .= ' target="' $this->csimwintarget '" ';
  313.                 }
  314.                 if (!empty($this->csimalt)) {
  315.                     $tmp sprintf($this->csimalt$this->yvalue$this->xvalue);
  316.                     $this->csimareas .= " title=\"${tmp}\" alt=\"${tmp}\" ";
  317.                 }
  318.                 $this->csimareas .= " />\n";
  319.             }
  320.             // Stroke title
  321.             $this->title->Align('center''top');
  322.             $this->title->Stroke($img$x$y round($dh 2));
  323.             return;
  324.         }
  325.         $weight $this->weight;
  326.         $dx     round($width 20);
  327.         $dy     round($width 20);
  328.         $pts    0;
  329.         switch ($this->type) {
  330.             case MARK_SQUARE:
  331.                 $c[] = $x $dx;
  332.                 $c[] = $y $dy;
  333.                 $c[] = $x $dx;
  334.                 $c[] = $y $dy;
  335.                 $c[] = $x $dx;
  336.                 $c[] = $y $dy;
  337.                 $c[] = $x $dx;
  338.                 $c[] = $y $dy;
  339.                 $c[] = $x $dx;
  340.                 $c[] = $y $dy;
  341.                 $pts 5;
  342.                 break;
  343.             case MARK_UTRIANGLE:
  344.                 ++$dx; ++$dy;
  345.                 $c[] = $x $dx;
  346.                 $c[] = $y 0.87 $dy// tan(60)/2*$dx
  347.                 $c[] = $x;
  348.                 $c[] = $y 0.87 $dy;
  349.                 $c[] = $x $dx;
  350.                 $c[] = $y 0.87 $dy;
  351.                 $c[] = $x $dx;
  352.                 $c[] = $y 0.87 $dy// tan(60)/2*$dx
  353.                 $pts 4;
  354.                 break;
  355.             case MARK_DTRIANGLE:
  356.                 ++$dx; ++$dy;
  357.                 $c[] = $x;
  358.                 $c[] = $y 0.87 $dy// tan(60)/2*$dx
  359.                 $c[] = $x $dx;
  360.                 $c[] = $y 0.87 $dy;
  361.                 $c[] = $x $dx;
  362.                 $c[] = $y 0.87 $dy;
  363.                 $c[] = $x;
  364.                 $c[] = $y 0.87 $dy// tan(60)/2*$dx
  365.                 $pts 4;
  366.                 break;
  367.             case MARK_DIAMOND:
  368.                 $c[] = $x;
  369.                 $c[] = $y $dy;
  370.                 $c[] = $x $dx;
  371.                 $c[] = $y;
  372.                 $c[] = $x;
  373.                 $c[] = $y $dy;
  374.                 $c[] = $x $dx;
  375.                 $c[] = $y;
  376.                 $c[] = $x;
  377.                 $c[] = $y $dy;
  378.                 $pts 5;
  379.                 break;
  380.             case MARK_LEFTTRIANGLE:
  381.                 $c[] = $x;
  382.                 $c[] = $y;
  383.                 $c[] = $x;
  384.                 $c[] = $y $dy;
  385.                 $c[] = $x $dx 2;
  386.                 $c[] = $y;
  387.                 $c[] = $x;
  388.                 $c[] = $y;
  389.                 $pts 4;
  390.                 break;
  391.             case MARK_RIGHTTRIANGLE:
  392.                 $c[] = $x $dx 2;
  393.                 $c[] = $y;
  394.                 $c[] = $x;
  395.                 $c[] = $y $dy;
  396.                 $c[] = $x;
  397.                 $c[] = $y;
  398.                 $c[] = $x $dx 2;
  399.                 $c[] = $y;
  400.                 $pts 4;
  401.                 break;
  402.             case MARK_FLASH:
  403.                 $dy *= 2;
  404.                 $c[] = $x $dx 2;
  405.                 $c[] = $y $dy;
  406.                 $c[] = $x $dx $dx 2;
  407.                 $c[] = $y $dy 0.7 $dy;
  408.                 $c[] = $x $dx 2;
  409.                 $c[] = $y $dy 1.3 $dy;
  410.                 $c[] = $x $dx $dx 2;
  411.                 $c[] = $y $dy $dy;
  412.                 $img->SetLineWeight($weight);
  413.                 $img->SetColor($color);
  414.                 $img->Polygon($c);
  415.                 $img->SetLineWeight(1);
  416.                 $this->AddCSIMPoly($c);
  417.                 break;
  418.         }
  419.         if ($pts 0) {
  420.             $this->AddCSIMPoly($c);
  421.             $img->SetLineWeight($weight);
  422.             $img->SetColor($fcolor);
  423.             $img->FilledPolygon($c);
  424.             $img->SetColor($color);
  425.             $img->Polygon($c);
  426.             $img->SetLineWeight(1);
  427.         } elseif ($this->type == MARK_CIRCLE) {
  428.             $img->SetColor($color);
  429.             $img->Circle($x$y$width);
  430.             $this->AddCSIMCircle($x$y$width);
  431.         } elseif ($this->type == MARK_FILLEDCIRCLE) {
  432.             $img->SetColor($fcolor);
  433.             $img->FilledCircle($x$y$width);
  434.             $img->SetColor($color);
  435.             $img->Circle($x$y$width);
  436.             $this->AddCSIMCircle($x$y$width);
  437.         } elseif ($this->type == MARK_CROSS) {
  438.             // Oversize by a pixel to match the X
  439.             $img->SetColor($color);
  440.             $img->SetLineWeight($weight);
  441.             $img->Line($x$y $dy 1$x$y $dy 1);
  442.             $img->Line($x $dx 1$y$x $dx 1$y);
  443.             $this->AddCSIMCircle($x$y$dx);
  444.         } elseif ($this->type == MARK_X) {
  445.             $img->SetColor($color);
  446.             $img->SetLineWeight($weight);
  447.             $img->Line($x $dx$y $dy$x $dx$y $dy);
  448.             $img->Line($x $dx$y $dy$x $dx$y $dy);
  449.             $this->AddCSIMCircle($x$y$dx $dy);
  450.         } elseif ($this->type == MARK_STAR) {
  451.             $img->SetColor($color);
  452.             $img->SetLineWeight($weight);
  453.             $img->Line($x $dx$y $dy$x $dx$y $dy);
  454.             $img->Line($x $dx$y $dy$x $dx$y $dy);
  455.             // Oversize by a pixel to match the X
  456.             $img->Line($x$y $dy 1$x$y $dy 1);
  457.             $img->Line($x $dx 1$y$x $dx 1$y);
  458.             $this->AddCSIMCircle($x$y$dx $dy);
  459.         }
  460.         // Stroke title
  461.         $this->title->Align('center''center');
  462.         $this->title->Stroke($img$x$y);
  463.     }
  464. // @class