1 | <?php |
---|
2 | /*======================================================================= |
---|
3 | // File: JPGRAPH_SCATTER.PHP |
---|
4 | // Description: Scatter (and impuls) plot extension for JpGraph |
---|
5 | // Created: 2001-02-11 |
---|
6 | // Author: Johan Persson (johanp@aditus.nu) |
---|
7 | // Ver: $Id: jpgraph_scatter.php 18250 2005-05-07 14:13:43Z ralfbecker $ |
---|
8 | // |
---|
9 | // License: This code is released under GPL 2.0 |
---|
10 | // Copyright (C) 2001 Johan Persson |
---|
11 | //======================================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | //=================================================== |
---|
15 | // CLASS ScatterPlot |
---|
16 | // Description: Render X and Y plots |
---|
17 | //=================================================== |
---|
18 | class ScatterPlot extends Plot { |
---|
19 | var $impuls = false; |
---|
20 | var $linkpoints = false, $linkpointweight=1, $linkpointcolor="black"; |
---|
21 | //--------------- |
---|
22 | // CONSTRUCTOR |
---|
23 | function ScatterPlot(&$datay,$datax=false) { |
---|
24 | if( (count($datax) != count($datay)) && is_array($datax)) |
---|
25 | JpGraphError::Raise("JpGraph: Scatterplot must have equal number of X and Y points."); |
---|
26 | $this->Plot($datay,$datax); |
---|
27 | $this->mark = new PlotMark(); |
---|
28 | $this->mark->SetType(MARK_CIRCLE); |
---|
29 | $this->mark->SetColor($this->color); |
---|
30 | } |
---|
31 | |
---|
32 | //--------------- |
---|
33 | // PUBLIC METHODS |
---|
34 | function SetImpuls($f=true) { |
---|
35 | $this->impuls = $f; |
---|
36 | } |
---|
37 | |
---|
38 | // Combine the scatter plot points with a line |
---|
39 | function SetLinkPoints($f=true,$lpc="black",$weight=1) { |
---|
40 | $this->linkpoints=$f; |
---|
41 | $this->linkpointcolor=$lpc; |
---|
42 | $this->linkpointweight=$weight; |
---|
43 | } |
---|
44 | |
---|
45 | function Stroke(&$img,&$xscale,&$yscale) { |
---|
46 | $ymin=$yscale->scale_abs[0]; |
---|
47 | if( $yscale->scale[0] < 0 ) |
---|
48 | $yzero=$yscale->Translate(0); |
---|
49 | else |
---|
50 | $yzero=$yscale->scale_abs[0]; |
---|
51 | for( $i=0; $i<$this->numpoints; ++$i ) { |
---|
52 | if( isset($this->coords[1]) ) |
---|
53 | $xt = $xscale->Translate($this->coords[1][$i]); |
---|
54 | else |
---|
55 | $xt = $xscale->Translate($i); |
---|
56 | $yt = $yscale->Translate($this->coords[0][$i]); |
---|
57 | if( $this->linkpoints && isset($yt_old) ) { |
---|
58 | $img->SetColor($this->linkpointcolor); |
---|
59 | $img->SetLineWeight($this->linkpointweight); |
---|
60 | $img->Line($xt_old,$yt_old,$xt,$yt); |
---|
61 | } |
---|
62 | if( $this->impuls ) { |
---|
63 | $img->SetColor($this->color); |
---|
64 | $img->SetLineWeight($this->weight); |
---|
65 | $img->Line($xt,$yzero,$xt,$yt); |
---|
66 | } |
---|
67 | $this->mark->Stroke($img,$xt,$yt); |
---|
68 | $xt_old = $xt; |
---|
69 | $yt_old = $yt; |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | // Framework function |
---|
74 | function Legend(&$aGraph) { |
---|
75 | if( $this->legend != "" ) { |
---|
76 | $aGraph->legend->Add($this->legend,$this->mark->fill_color); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | } // Class |
---|
81 | /* EOF */ |
---|
82 | ?> |
---|