📄 jpgraph_line.php
字号:
} } $yt_old = $yt; $xt_old = $xt; $y_old = $y; $this->StrokeDataValue($img,$this->coords[0][$pnts],$xt,$yt); ++$pnts; } if( $this->filled ) { $cord[$idx++] = $xt; if( $min > 0 || $this->fillFromMin ) $cord[$idx++] = $yscale->Translate($min); else $cord[$idx++] = $yscale->Translate(0); if( $this->fillgrad ) { $img->SetLineWeight(1); $grad = new Gradient($img); $grad->SetNumColors($this->fillgrad_numcolors); $grad->FilledFlatPolygon($cord,$this->fillgrad_fromcolor,$this->fillgrad_tocolor); $img->SetLineWeight($this->weight); } else { $img->SetColor($this->fill_color); $img->FilledPolygon($cord); } if( $this->line_weight > 0 ) { $img->SetColor($this->color); $img->Polygon($cord); } } if(!empty($this->filledAreas)) { $minY = $yscale->Translate($yscale->GetMinVal()); $factor = ($this->step_style ? 4 : 2); for($i = 0; $i < sizeof($this->filledAreas); ++$i) { // go through all filled area elements ordered by insertion // fill polygon array $areaCoords[] = $cord[$this->filledAreas[$i][0] * $factor]; $areaCoords[] = $minY; $areaCoords = array_merge($areaCoords, array_slice($cord, $this->filledAreas[$i][0] * $factor, ($this->filledAreas[$i][1] - $this->filledAreas[$i][0] + ($this->step_style ? 0 : 1)) * $factor)); $areaCoords[] = $areaCoords[sizeof($areaCoords)-2]; // last x $areaCoords[] = $minY; // last y if($this->filledAreas[$i][3]) { $img->SetColor($this->filledAreas[$i][2]); $img->FilledPolygon($areaCoords); $img->SetColor($this->color); } // Check if we should draw the frame. // If not we still re-draw the line since it might have been // partially overwritten by the filled area and it doesn't look // very good. // TODO: The behaviour is undefined if the line does not have // any line at the position of the area. if( $this->filledAreas[$i][4] ) $img->Polygon($areaCoords); else $img->Polygon($cord); $areaCoords = array(); } } if( $this->mark->type == -1 || $this->mark->show == false ) return; for( $pnts=0; $pnts<$numpoints; ++$pnts) { if( $exist_x ) $x=$this->coords[1][$pnts]; else $x=$pnts+$textadj; $xt = $xscale->Translate($x); $yt = $yscale->Translate($this->coords[0][$pnts]); if( is_numeric($this->coords[0][$pnts]) ) { if( !empty($this->csimtargets[$pnts]) ) { $this->mark->SetCSIMTarget($this->csimtargets[$pnts]); $this->mark->SetCSIMAlt($this->csimalts[$pnts]); } if( $exist_x ) $x=$this->coords[1][$pnts]; else $x=$pnts; $this->mark->SetCSIMAltVal($this->coords[0][$pnts],$x); $this->mark->Stroke($img,$xt,$yt); $this->csimareas .= $this->mark->GetCSIMAreas(); $this->StrokeDataValue($img,$this->coords[0][$pnts],$xt,$yt); } } }} // Class//===================================================// CLASS AccLinePlot// Description: //===================================================class AccLinePlot extends Plot { var $plots=null,$nbrplots=0,$numpoints=0; var $iStartEndZero=true;//---------------// CONSTRUCTOR function AccLinePlot($plots) { $this->plots = $plots; $this->nbrplots = count($plots); $this->numpoints = $plots[0]->numpoints; for($i=0; $i < $this->nbrplots; ++$i ) { $this->LineInterpolate($this->plots[$i]->coords[0]); } }//---------------// PUBLIC METHODS function Legend(&$graph) { $n=count($this->plots); for($i=0; $i < $n; ++$i ) $this->plots[$i]->DoLegend($graph); } function Max() { list($xmax) = $this->plots[0]->Max(); $nmax=0; $n = count($this->plots); for($i=0; $i < $n; ++$i) { $nc = count($this->plots[$i]->coords[0]); $nmax = max($nmax,$nc); list($x) = $this->plots[$i]->Max(); $xmax = Max($xmax,$x); } for( $i = 0; $i < $nmax; $i++ ) { // Get y-value for line $i by adding the // individual bars from all the plots added. // It would be wrong to just add the // individual plots max y-value since that // would in most cases give to large y-value. $y=$this->plots[0]->coords[0][$i]; for( $j = 1; $j < $this->nbrplots; $j++ ) { $y += $this->plots[ $j ]->coords[0][$i]; } $ymax[$i] = $y; } $ymax = max($ymax); return array($xmax,$ymax); } function Min() { $nmax=0; list($xmin,$ysetmin) = $this->plots[0]->Min(); $n = count($this->plots); for($i=0; $i < $n; ++$i) { $nc = count($this->plots[$i]->coords[0]); $nmax = max($nmax,$nc); list($x,$y) = $this->plots[$i]->Min(); $xmin = Min($xmin,$x); $ysetmin = Min($y,$ysetmin); } for( $i = 0; $i < $nmax; $i++ ) { // Get y-value for line $i by adding the // individual bars from all the plots added. // It would be wrong to just add the // individual plots min y-value since that // would in most cases give to small y-value. $y=$this->plots[0]->coords[0][$i]; for( $j = 1; $j < $this->nbrplots; $j++ ) { $y += $this->plots[ $j ]->coords[0][$i]; } $ymin[$i] = $y; } $ymin = Min($ysetmin,Min($ymin)); return array($xmin,$ymin); } // Gets called before any axis are stroked function PreStrokeAdjust(&$graph) { // If another plot type have already adjusted the // offset we don't touch it. // (We check for empty in case the scale is a log scale // and hence doesn't contain any xlabel_offset) if( empty($graph->xaxis->scale->ticks->xlabel_offset) || $graph->xaxis->scale->ticks->xlabel_offset == 0 ) { if( $this->center ) { ++$this->numpoints; $a=0.5; $b=0.5; } else { $a=0; $b=0; } $graph->xaxis->scale->ticks->SetXLabelOffset($a); $graph->SetTextScaleOff($b); $graph->xaxis->scale->ticks->SupressMinorTickMarks(); } } function SetInterpolateMode($aIntMode) { $this->iStartEndZero=$aIntMode; } // Replace all '-' with an interpolated value. We use straightforward // linear interpolation. If the data starts with one or several '-' they // will be replaced by the the first valid data point function LineInterpolate(&$aData) { $n=count($aData); $i=0; // If first point is undefined we will set it to the same as the first // valid data if( $aData[$i]==='-' ) { // Find the first valid data while( $i < $n && $aData[$i]==='-' ) { ++$i; } if( $i < $n ) { for($j=0; $j < $i; ++$j ) { if( $this->iStartEndZero ) $aData[$i] = 0; else $aData[$j] = $aData[$i]; } } else { // All '-' => Error return false; } } while($i < $n) { while( $i < $n && $aData[$i] !== '-' ) { ++$i; } if( $i < $n ) { $pstart=$i-1; // Now see how long this segment of '-' are while( $i < $n && $aData[$i] === '-' ) ++$i; if( $i < $n ) { $pend=$i; $size=$pend-$pstart; $k=($aData[$pend]-$aData[$pstart])/$size; // Replace the segment of '-' with a linear interpolated value. for($j=1; $j < $size; ++$j ) { $aData[$pstart+$j] = $aData[$pstart] + $j*$k ; } } else { // There are no valid end point. The '-' goes all the way to the end // In that case we just set all the remaining values the the same as the // last valid data point. for( $j=$pstart+1; $j < $n; ++$j ) if( $this->iStartEndZero ) $aData[$j] = 0; else $aData[$j] = $aData[$pstart] ; } } } return true; } // To avoid duplicate of line drawing code here we just // change the y-values for each plot and then restore it // after we have made the stroke. We must do this copy since // it wouldn't be possible to create an acc line plot // with the same graphs, i.e AccLinePlot(array($pl,$pl,$pl)); // since this method would have a side effect. function Stroke(&$img,&$xscale,&$yscale) { $img->SetLineWeight($this->weight); $this->numpoints = count($this->plots[0]->coords[0]); // Allocate array $coords[$this->nbrplots][$this->numpoints]=0; for($i=0; $i<$this->numpoints; $i++) { $coords[0][$i]=$this->plots[0]->coords[0][$i]; $accy=$coords[0][$i]; for($j=1; $j<$this->nbrplots; ++$j ) { $coords[$j][$i] = $this->plots[$j]->coords[0][$i]+$accy; $accy = $coords[$j][$i]; } } for($j=$this->nbrplots-1; $j>=0; --$j) { $p=$this->plots[$j]; for( $i=0; $i<$this->numpoints; ++$i) { $tmp[$i]=$p->coords[0][$i]; $p->coords[0][$i]=$coords[$j][$i]; } $p->Stroke($img,$xscale,$yscale); for( $i=0; $i<$this->numpoints; ++$i) $p->coords[0][$i]=$tmp[$i]; $p->coords[0][]=$tmp; } }} // Class/* EOF */?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -