2
/*=======================================================================
3
// File: JPGRAPH_STOCK.PHP
4
// Description: Stock plot extension for JpGraph
6
// Ver: $Id: jpgraph_stock.php 907 2007-08-31 22:47:57Z ljp $
8
// Copyright (c) Aditus Consulting. All rights reserved.
9
//========================================================================
12
//===================================================
14
//===================================================
15
class StockPlot extends Plot {
19
var $iStockColor1='white',$iStockColor2='darkred',$iStockColor3='darkred';
22
function StockPlot(&$datay,$datax=false) {
23
if( count($datay) % $this->iTupleSize ) {
24
JpGraphError::RaiseL(21001,$this->iTupleSize);//('Data values for Stock charts must contain an even multiple of '.$this->iTupleSize.' data points.');
26
$this->Plot($datay,$datax);
27
$this->numpoints /= $this->iTupleSize;
32
function SetColor($aColor,$aColor1='white',$aColor2='darkred',$aColor3='darkred') {
33
$this->color = $aColor;
34
$this->iStockColor1 = $aColor1;
35
$this->iStockColor2 = $aColor2;
36
$this->iStockColor3 = $aColor3;
39
function SetWidth($aWidth) {
41
$this->iWidth = 2*floor($aWidth/2)+1;
44
function HideEndLines($aHide=true) {
45
$this->iEndLines = !$aHide;
48
// Gets called before any axis are stroked
49
function PreStrokeAdjust(&$graph) {
56
$graph->xaxis->scale->ticks->SetXLabelOffset($a);
57
$graph->SetTextScaleOff($b);
61
function Stroke(&$img,$xscale,$yscale) {
63
if( $this->center ) $n--;
64
if( isset($this->coords[1]) ) {
65
if( count($this->coords[1])!=$n )
66
JpGraphError::RaiseL(2003,count($this->coords[1]),$numpoints);
67
//("Number of X and Y points are not equal. Number of X-points:".count($this->coords[1])." Number of Y-points:$numpoints");
75
$xs=$this->coords[1][0];
79
$ts = $this->iTupleSize;
80
$this->csimareas = '';
81
for( $i=0; $i<$n; ++$i) {
83
//If value is NULL, then don't draw a bar at all
84
if ($this->coords[0][$i] === null) continue;
86
if( $exist_x ) $x=$this->coords[1][$i];
88
$xt = $xscale->Translate($x);
90
$neg = $this->coords[0][$i*$ts] > $this->coords[0][$i*$ts+1] ;
91
$yopen = $yscale->Translate($this->coords[0][$i*$ts]);
92
$yclose = $yscale->Translate($this->coords[0][$i*$ts+1]);
93
$ymin = $yscale->Translate($this->coords[0][$i*$ts+2]);
94
$ymax = $yscale->Translate($this->coords[0][$i*$ts+3]);
96
$dx = floor($this->iWidth/2);
101
$img->SetColor($this->iStockColor3);
103
$img->SetColor($this->iStockColor1);
104
$img->FilledRectangle($xl,$yopen,$xr,$yclose);
105
$img->SetLineWeight($this->weight);
107
$img->SetColor($this->iStockColor2);
109
$img->SetColor($this->color);
111
$img->Rectangle($xl,$yopen,$xr,$yclose);
113
if( $yopen < $yclose ) {
121
$img->SetColor($this->color);
122
$img->Line($xt,$ytop,$xt,$ymax);
123
$img->Line($xt,$ybottom,$xt,$ymin);
125
if( $this->iEndLines ) {
126
$img->Line($xl,$ymax,$xr,$ymax);
127
$img->Line($xl,$ymin,$xr,$ymin);
130
// A chance for subclasses to add things to the bar
132
$this->ModBox($img,$xscale,$yscale,$i,$xl,$xr,$neg);
135
if( !empty($this->csimtargets[$i]) ) {
136
$this->csimareas.= '<area shape="rect" coords="'.
137
round($xl).','.round($ytop).','.
138
round($xr).','.round($ybottom).'" ';
139
$this->csimareas .= ' href="'.$this->csimtargets[$i].'"';
140
if( !empty($this->csimalts[$i]) ) {
141
$sval=$this->csimalts[$i];
142
$this->csimareas .= " title=\"$sval\" alt=\"$sval\" ";
144
$this->csimareas.= " />\n";
150
// A hook for subclasses to modify the plot
151
function ModBox($img,$xscale,$yscale,$i,$xl,$xr,$neg) {}
155
//===================================================
157
//===================================================
158
class BoxPlot extends StockPlot {
159
var $iPColor='black',$iNColor='white';
160
function BoxPlot($datay,$datax=false) {
162
parent::StockPlot($datay,$datax);
165
function SetMedianColor($aPos,$aNeg) {
166
$this->iPColor = $aPos;
167
$this->iNColor = $aNeg;
170
function ModBox(&$img,$xscale,$yscale,$i,$xl,$xr,$neg) {
172
$img->SetColor($this->iNColor);
174
$img->SetColor($this->iPColor);
176
$y = $yscale->Translate($this->coords[0][$i*5+4]);
177
$img->Line($xl,$y,$xr,$y);
b'\\ No newline at end of file'