66 |
aurelien |
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 1881 2009-10-01 10:28:12Z 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) Aditus Consulting. 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 |
//---------------
|
|
|
64 |
// PRIVATE METHODS
|
|
|
65 |
|
|
|
66 |
function DoLegend($graph) {
|
|
|
67 |
if( !$this->hidelegend ) $this->Legend($graph);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
// Framework function the chance for each plot class to set a legend
|
|
|
71 |
function Legend($aGraph) {
|
|
|
72 |
if( $this->legend != '' ) {
|
|
|
73 |
$dummyPlotMark = new PlotMark();
|
|
|
74 |
$lineStyle = 1;
|
|
|
75 |
$aGraph->legend->Add($this->legend,$this->color,$dummyPlotMark,$lineStyle,
|
|
|
76 |
$this->legendcsimtarget,$this->legendcsimalt,$this->legendcsimwintarget);
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
function PreStrokeAdjust($aGraph) {
|
|
|
81 |
// Nothing to do
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
// Called by framework to allow the object to draw
|
|
|
85 |
// optional information in the margin area
|
|
|
86 |
function StrokeMargin($aImg) {
|
|
|
87 |
// Nothing to do
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
// Framework function to allow the object to adjust the scale
|
|
|
91 |
function PrescaleSetup($aGraph) {
|
|
|
92 |
// Nothing to do
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
function Min() {
|
|
|
96 |
return array(null,null);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
function Max() {
|
|
|
100 |
return array(null,null);
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
function _Stroke($aImg,$aMinX,$aMinY,$aMaxX,$aMaxY,$aXPos,$aYPos) {
|
|
|
104 |
$aImg->SetColor($this->color);
|
|
|
105 |
$aImg->SetLineWeight($this->weight);
|
|
|
106 |
$oldStyle = $aImg->SetLineStyle($this->iLineStyle);
|
|
|
107 |
if( $this->direction == VERTICAL ) {
|
|
|
108 |
$ymin_abs = $aMinY;
|
|
|
109 |
$ymax_abs = $aMaxY;
|
|
|
110 |
$xpos_abs = $aXPos;
|
|
|
111 |
$aImg->StyleLine($xpos_abs, $ymin_abs, $xpos_abs, $ymax_abs);
|
|
|
112 |
}
|
|
|
113 |
elseif( $this->direction == HORIZONTAL ) {
|
|
|
114 |
$xmin_abs = $aMinX;
|
|
|
115 |
$xmax_abs = $aMaxX;
|
|
|
116 |
$ypos_abs = $aYPos;
|
|
|
117 |
$aImg->StyleLine($xmin_abs, $ypos_abs, $xmax_abs, $ypos_abs);
|
|
|
118 |
}
|
|
|
119 |
else {
|
|
|
120 |
JpGraphError::RaiseL(25125);//(" Illegal direction for static line");
|
|
|
121 |
}
|
|
|
122 |
$aImg->SetLineStyle($oldStyle);
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
function Stroke($aImg,$aXScale,$aYScale) {
|
|
|
126 |
$this->_Stroke($aImg,
|
|
|
127 |
$aImg->left_margin,
|
|
|
128 |
$aYScale->Translate($aYScale->GetMinVal()),
|
|
|
129 |
$aImg->width-$aImg->right_margin,
|
|
|
130 |
$aYScale->Translate($aYScale->GetMaxVal()),
|
|
|
131 |
$aXScale->Translate($this->scaleposition),
|
|
|
132 |
$aYScale->Translate($this->scaleposition)
|
|
|
133 |
);
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
?>
|