1<?php 2namespace Amenadiel\JpGraph\Plot; 3 4//=================================================== 5// CLASS FieldPlot 6// Description: Render a field plot 7//=================================================== 8class FieldPlot extends Plot 9{ 10 public $arrow = ''; 11 private $iAngles = array(); 12 private $iCallback = ''; 13 14 public function __construct($datay, $datax, $angles) 15 { 16 if ((count($datax) != count($datay))) { 17 Util\JpGraphError::RaiseL(20001); 18 } 19 //("Fieldplots must have equal number of X and Y points."); 20 if ((count($datax) != count($angles))) { 21 Util\JpGraphError::RaiseL(20002); 22 } 23 //("Fieldplots must have an angle specified for each X and Y points."); 24 25 $this->iAngles = $angles; 26 27 parent::__construct($datay, $datax); 28 $this->value->SetAlign('center', 'center'); 29 $this->value->SetMargin(15); 30 31 $this->arrow = new FieldArrow(); 32 } 33 34 public function SetCallback($aFunc) 35 { 36 $this->iCallback = $aFunc; 37 } 38 39 public function Stroke($img, $xscale, $yscale) 40 { 41 42 // Remeber base color and size 43 $bc = $this->arrow->iColor; 44 $bs = $this->arrow->iSize; 45 $bas = $this->arrow->iArrowSize; 46 47 for ($i = 0; $i < $this->numpoints; ++$i) { 48 // Skip null values 49 if ($this->coords[0][$i] === "") { 50 continue; 51 } 52 53 $f = $this->iCallback; 54 if ($f != "") { 55 list($cc, $cs, $cas) = call_user_func($f, $this->coords[1][$i], $this->coords[0][$i], $this->iAngles[$i]); 56 // Fall back on global data if the callback isn't set 57 if ($cc == "") { 58 $cc = $bc; 59 } 60 61 if ($cs == "") { 62 $cs = $bs; 63 } 64 65 if ($cas == "") { 66 $cas = $bas; 67 } 68 69 $this->arrow->SetColor($cc); 70 $this->arrow->SetSize($cs, $cas); 71 } 72 73 $xt = $xscale->Translate($this->coords[1][$i]); 74 $yt = $yscale->Translate($this->coords[0][$i]); 75 76 $this->arrow->Stroke($img, $xt, $yt, $this->iAngles[$i]); 77 $this->value->Stroke($img, $this->coords[0][$i], $xt, $yt); 78 } 79 } 80 81 // Framework function 82 public function Legend($aGraph) 83 { 84 if ($this->legend != "") { 85 $aGraph->legend->Add($this->legend, $this->mark->fill_color, $this->mark, 0, 86 $this->legendcsimtarget, $this->legendcsimalt, $this->legendcsimwintarget); 87 } 88 } 89} 90