[42] | 1 | <?php |
---|
| 2 | /*======================================================================= |
---|
| 3 | // File: JPGRAPH_PLOTLINE.PHP |
---|
| 4 | // Description: PlotLine extension for JpGraph |
---|
| 5 | // Created: 2009-03-24 |
---|
| 6 | // Ver: $Id: jpgraph_plotline.php 1931 2010-03-22 15:05:48Z ljp $ |
---|
| 7 | // |
---|
| 8 | // CLASS PlotLine |
---|
| 9 | // Data container class to hold properties for a static |
---|
| 10 | // line that is drawn directly in the plot area. |
---|
| 11 | // Useful to add static borders inside a plot to show for example set-values |
---|
| 12 | // |
---|
| 13 | // Copyright (c) Asial Corporation. All rights reserved. |
---|
| 14 | //======================================================================== |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | class PlotLine { |
---|
| 18 | public $scaleposition, $direction=-1; |
---|
| 19 | protected $weight=1; |
---|
| 20 | protected $color = 'black'; |
---|
| 21 | private $legend='',$hidelegend=false, $legendcsimtarget='', $legendcsimalt='',$legendcsimwintarget=''; |
---|
| 22 | private $iLineStyle='solid'; |
---|
| 23 | public $numpoints=0; // Needed since the framework expects this property |
---|
| 24 | |
---|
| 25 | function __construct($aDir=HORIZONTAL,$aPos=0,$aColor='black',$aWeight=1) { |
---|
| 26 | $this->direction = $aDir; |
---|
| 27 | $this->color=$aColor; |
---|
| 28 | $this->weight=$aWeight; |
---|
| 29 | $this->scaleposition=$aPos; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | function SetLegend($aLegend,$aCSIM='',$aCSIMAlt='',$aCSIMWinTarget='') { |
---|
| 33 | $this->legend = $aLegend; |
---|
| 34 | $this->legendcsimtarget = $aCSIM; |
---|
| 35 | $this->legendcsimwintarget = $aCSIMWinTarget; |
---|
| 36 | $this->legendcsimalt = $aCSIMAlt; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | function HideLegend($f=true) { |
---|
| 40 | $this->hidelegend = $f; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | function SetPosition($aScalePosition) { |
---|
| 44 | $this->scaleposition=$aScalePosition; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | function SetDirection($aDir) { |
---|
| 48 | $this->direction = $aDir; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | function SetColor($aColor) { |
---|
| 52 | $this->color=$aColor; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | function SetWeight($aWeight) { |
---|
| 56 | $this->weight=$aWeight; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | function SetLineStyle($aStyle) { |
---|
| 60 | $this->iLineStyle = $aStyle; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | function GetCSIMAreas() { |
---|
| 64 | return ''; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | //--------------- |
---|
| 68 | // PRIVATE METHODS |
---|
| 69 | |
---|
| 70 | function DoLegend($graph) { |
---|
| 71 | if( !$this->hidelegend ) $this->Legend($graph); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | // Framework function the chance for each plot class to set a legend |
---|
| 75 | function Legend($aGraph) { |
---|
| 76 | if( $this->legend != '' ) { |
---|
| 77 | $dummyPlotMark = new PlotMark(); |
---|
| 78 | $lineStyle = 1; |
---|
| 79 | $aGraph->legend->Add($this->legend,$this->color,$dummyPlotMark,$lineStyle, |
---|
| 80 | $this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget); |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | function PreStrokeAdjust($aGraph) { |
---|
| 85 | // Nothing to do |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | // Called by framework to allow the object to draw |
---|
| 89 | // optional information in the margin area |
---|
| 90 | function StrokeMargin($aImg) { |
---|
| 91 | // Nothing to do |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | // Framework function to allow the object to adjust the scale |
---|
| 95 | function PrescaleSetup($aGraph) { |
---|
| 96 | // Nothing to do |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | function Min() { |
---|
| 100 | return array(null,null); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | function Max() { |
---|
| 104 | return array(null,null); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | function _Stroke($aImg,$aMinX,$aMinY,$aMaxX,$aMaxY,$aXPos,$aYPos) { |
---|
| 108 | $aImg->SetColor($this->color); |
---|
| 109 | $aImg->SetLineWeight($this->weight); |
---|
| 110 | $oldStyle = $aImg->SetLineStyle($this->iLineStyle); |
---|
| 111 | if( $this->direction == VERTICAL ) { |
---|
| 112 | $ymin_abs = $aMinY; |
---|
| 113 | $ymax_abs = $aMaxY; |
---|
| 114 | $xpos_abs = $aXPos; |
---|
| 115 | $aImg->StyleLine($xpos_abs, $ymin_abs, $xpos_abs, $ymax_abs); |
---|
| 116 | } |
---|
| 117 | elseif( $this->direction == HORIZONTAL ) { |
---|
| 118 | $xmin_abs = $aMinX; |
---|
| 119 | $xmax_abs = $aMaxX; |
---|
| 120 | $ypos_abs = $aYPos; |
---|
| 121 | $aImg->StyleLine($xmin_abs, $ypos_abs, $xmax_abs, $ypos_abs); |
---|
| 122 | } |
---|
| 123 | else { |
---|
| 124 | JpGraphError::RaiseL(25125);//(" Illegal direction for static line"); |
---|
| 125 | } |
---|
| 126 | $aImg->SetLineStyle($oldStyle); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | function Stroke($aImg,$aXScale,$aYScale) { |
---|
| 130 | $this->_Stroke($aImg, |
---|
| 131 | $aImg->left_margin, |
---|
| 132 | $aYScale->Translate($aYScale->GetMinVal()), |
---|
| 133 | $aImg->width-$aImg->right_margin, |
---|
| 134 | $aYScale->Translate($aYScale->GetMaxVal()), |
---|
| 135 | $aXScale->Translate($this->scaleposition), |
---|
| 136 | $aYScale->Translate($this->scaleposition) |
---|
| 137 | ); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | ?> |
---|