Beispiel #1
0
 function Stroke(&$img, &$xscale, &$yscale)
 {
     $numpoints = count($this->coords[0]);
     if (isset($this->coords[1])) {
         if (count($this->coords[1]) != $numpoints) {
             JpGraphError::Raise("Number of X and Y points are not equal. Number of X-points:" . count($this->coords[1]) . " Number of Y-points:{$numpoints}");
         } else {
             $exist_x = true;
         }
     } else {
         $exist_x = false;
     }
     if ($this->barcenter) {
         $textadj = 0.5 - $xscale->text_scale_off;
     } else {
         $textadj = 0;
     }
     // Find the first numeric data point
     $startpoint = 0;
     while ($startpoint < $numpoints && !is_numeric($this->coords[0][$startpoint])) {
         ++$startpoint;
     }
     // Bail out if no data points
     if ($startpoint == $numpoints) {
         return;
     }
     if ($exist_x) {
         $xs = $this->coords[1][$startpoint];
     } else {
         $xs = $textadj + $startpoint;
     }
     $img->SetStartPoint($xscale->Translate($xs), $yscale->Translate($this->coords[0][$startpoint]));
     if ($this->filled) {
         $cord[] = $xscale->Translate($xs);
         $min = $yscale->GetMinVal();
         if ($min > 0 || $this->fillFromMin) {
             $cord[] = $yscale->Translate($min);
         } else {
             $cord[] = $yscale->Translate(0);
         }
     }
     $xt = $xscale->Translate($xs);
     $yt = $yscale->Translate($this->coords[0][$startpoint]);
     $cord[] = $xt;
     $cord[] = $yt;
     $yt_old = $yt;
     $this->value->Stroke($img, $this->coords[0][$startpoint], $xt, $yt);
     $img->SetColor($this->color);
     $img->SetLineWeight($this->weight);
     $img->SetLineStyle($this->line_style);
     for ($pnts = $startpoint + 1; $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]);
         $y = $this->coords[0][$pnts];
         if ($this->step_style && is_numeric($y)) {
             $img->StyleLineTo($xt, $yt_old);
             $img->StyleLineTo($xt, $yt);
             $cord[] = $xt;
             $cord[] = $yt_old;
             $cord[] = $xt;
             $cord[] = $yt;
         } else {
             if (is_numeric($y) || is_string($y) && $y != "-") {
                 $tmp1 = $this->coords[0][$pnts];
                 $tmp2 = $this->coords[0][$pnts - 1];
                 if (is_numeric($tmp1) && (is_numeric($tmp2) || $tmp2 == "-")) {
                     $img->StyleLineTo($xt, $yt);
                 } else {
                     $img->SetStartPoint($xt, $yt);
                 }
                 if (is_numeric($tmp1) && (is_numeric($tmp2) || $tmp2 == "-" || $this->filled && $tmp2 == '')) {
                     $cord[] = $xt;
                     $cord[] = $yt;
                 }
             }
         }
         $yt_old = $yt;
         $this->StrokeDataValue($img, $this->coords[0][$pnts], $xt, $yt);
     }
     if ($this->filled) {
         $cord[] = $xt;
         if ($min > 0 || $this->fillFromMin) {
             $cord[] = $yscale->Translate($min);
         } else {
             $cord[] = $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);
         }
     }
 }
Beispiel #2
0
 function Stroke($img, $xscale, $yscale)
 {
     $idx = 0;
     $numpoints = count($this->coords[0]);
     if (isset($this->coords[1])) {
         if (count($this->coords[1]) != $numpoints) {
             JpGraphError::RaiseL(2003, count($this->coords[1]), $numpoints);
         } else {
             $exist_x = true;
         }
     } else {
         $exist_x = false;
     }
     if ($this->barcenter) {
         $textadj = 0.5 - $xscale->text_scale_off;
     } else {
         $textadj = 0;
     }
     // Find the first numeric data point
     $startpoint = 0;
     while ($startpoint < $numpoints && !is_numeric($this->coords[0][$startpoint])) {
         ++$startpoint;
     }
     // Bail out if no data points
     if ($startpoint == $numpoints) {
         return;
     }
     if ($this->iFastStroke) {
         $this->FastStroke($img, $xscale, $yscale, $startpoint, $exist_x);
         return;
     }
     if ($exist_x) {
         $xs = $this->coords[1][$startpoint];
     } else {
         $xs = $textadj + $startpoint;
     }
     $img->SetStartPoint($xscale->Translate($xs), $yscale->Translate($this->coords[0][$startpoint]));
     if ($this->filled) {
         $min = $yscale->GetMinVal();
         if ($min > 0 || $this->fillFromMin) {
             $fillmin = $yscale->scale_abs[0];
         } else {
             $fillmin = $yscale->Translate(0);
         }
         $cord[$idx++] = $xscale->Translate($xs);
         $cord[$idx++] = $fillmin;
     }
     $xt = $xscale->Translate($xs);
     $yt = $yscale->Translate($this->coords[0][$startpoint]);
     $cord[$idx++] = $xt;
     $cord[$idx++] = $yt;
     $yt_old = $yt;
     $xt_old = $xt;
     $y_old = $this->coords[0][$startpoint];
     $this->value->Stroke($img, $this->coords[0][$startpoint], $xt, $yt);
     $img->SetColor($this->color);
     $img->SetLineWeight($this->weight);
     $img->SetLineStyle($this->line_style);
     $pnts = $startpoint + 1;
     $firstnonumeric = false;
     while ($pnts < $numpoints) {
         if ($exist_x) {
             $x = $this->coords[1][$pnts];
         } else {
             $x = $pnts + $textadj;
         }
         $xt = $xscale->Translate($x);
         $yt = $yscale->Translate($this->coords[0][$pnts]);
         $y = $this->coords[0][$pnts];
         if ($this->step_style) {
             // To handle null values within step style we need to record the
             // first non numeric value so we know from where to start if the
             // non value is '-'.
             if (is_numeric($y)) {
                 $firstnonumeric = false;
                 if (is_numeric($y_old)) {
                     $img->StyleLine($xt_old, $yt_old, $xt, $yt_old);
                     $img->StyleLine($xt, $yt_old, $xt, $yt);
                 } elseif ($y_old == '-') {
                     $img->StyleLine($xt_first, $yt_first, $xt, $yt_first);
                     $img->StyleLine($xt, $yt_first, $xt, $yt);
                 } else {
                     $yt_old = $yt;
                     $xt_old = $xt;
                 }
                 $cord[$idx++] = $xt;
                 $cord[$idx++] = $yt_old;
                 $cord[$idx++] = $xt;
                 $cord[$idx++] = $yt;
             } elseif ($firstnonumeric == false) {
                 $firstnonumeric = true;
                 $yt_first = $yt_old;
                 $xt_first = $xt_old;
             }
         } else {
             $tmp1 = $y;
             $prev = $this->coords[0][$pnts - 1];
             if ($tmp1 === '' || $tmp1 === NULL || $tmp1 === 'X') {
                 $tmp1 = 'x';
             }
             if ($prev === '' || $prev === null || $prev === 'X') {
                 $prev = 'x';
             }
             if (is_numeric($y) || is_string($y) && $y != '-') {
                 if (is_numeric($y) && (is_numeric($prev) || $prev === '-')) {
                     $img->StyleLineTo($xt, $yt);
                 } else {
                     $img->SetStartPoint($xt, $yt);
                 }
             }
             if ($this->filled && $tmp1 !== '-') {
                 if ($tmp1 === 'x') {
                     $cord[$idx++] = $cord[$idx - 3];
                     $cord[$idx++] = $fillmin;
                 } elseif ($prev === 'x') {
                     $cord[$idx++] = $xt;
                     $cord[$idx++] = $fillmin;
                     $cord[$idx++] = $xt;
                     $cord[$idx++] = $yt;
                 } else {
                     $cord[$idx++] = $xt;
                     $cord[$idx++] = $yt;
                 }
             } else {
                 if (is_numeric($tmp1) && (is_numeric($prev) || $prev === '-')) {
                     $cord[$idx++] = $xt;
                     $cord[$idx++] = $yt;
                 }
             }
         }
         $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])) {
                 if (!empty($this->csimwintargets[$pnts])) {
                     $this->mark->SetCSIMTarget($this->csimtargets[$pnts], $this->csimwintargets[$pnts]);
                 } else {
                     $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();
         }
     }
 }
Beispiel #3
0
 function Stroke(&$img, &$xscale, &$yscale)
 {
     $idx = 0;
     $numpoints = count($this->coords[0]);
     if (isset($this->coords[1])) {
         if (count($this->coords[1]) != $numpoints) {
             JpGraphError::RaiseL(2003, count($this->coords[1]), $numpoints);
         } else {
             $exist_x = true;
         }
     } else {
         $exist_x = false;
     }
     if ($this->barcenter) {
         $textadj = 0.5 - $xscale->text_scale_off;
     } else {
         $textadj = 0;
     }
     $startpoint = 0;
     while ($startpoint < $numpoints && !is_numeric($this->coords[0][$startpoint])) {
         ++$startpoint;
     }
     if ($startpoint == $numpoints) {
         return;
     }
     if ($this->iFastStroke) {
         $this->FastStroke($img, $xscale, $yscale, $startpoint, $exist_x);
         return;
     }
     if ($exist_x) {
         $xs = $this->coords[1][$startpoint];
     } else {
         $xs = $textadj + $startpoint;
     }
     $img->SetStartPoint($xscale->Translate($xs), $yscale->Translate($this->coords[0][$startpoint]));
     if ($this->filled) {
         $min = $yscale->GetMinVal();
         if ($min > 0 || $this->fillFromMin) {
             $fillmin = $yscale->scale_abs[0];
         } else {
             $fillmin = $yscale->Translate(0);
         }
         $cord[$idx++] = $xscale->Translate($xs);
         $cord[$idx++] = $fillmin;
     }
     $xt = $xscale->Translate($xs);
     $yt = $yscale->Translate($this->coords[0][$startpoint]);
     $cord[$idx++] = $xt;
     $cord[$idx++] = $yt;
     $yt_old = $yt;
     $xt_old = $xt;
     $y_old = $this->coords[0][$startpoint];
     $this->value->Stroke($img, $this->coords[0][$startpoint], $xt, $yt);
     $img->SetColor($this->color);
     $img->SetLineWeight($this->weight);
     $img->SetLineStyle($this->line_style);
     $pnts = $startpoint + 1;
     $firstnonumeric = false;
     while ($pnts < $numpoints) {
         if ($exist_x) {
             $x = $this->coords[1][$pnts];
         } else {
             $x = $pnts + $textadj;
         }
         $xt = $xscale->Translate($x);
         $yt = $yscale->Translate($this->coords[0][$pnts]);
         $y = $this->coords[0][$pnts];
         if ($this->step_style) {
             if (is_numeric($y)) {
                 $firstnonumeric = false;
                 if (is_numeric($y_old)) {
                     $img->StyleLine($xt_old, $yt_old, $xt, $yt_old);
                     $img->StyleLine($xt, $yt_old, $xt, $yt);
                 } elseif ($y_old == '-') {
                     $img->StyleLine($xt_first, $yt_first, $xt, $yt_first);
                     $img->StyleLine($xt, $yt_first, $xt, $yt);
                 } else {
                     $yt_old = $yt;
                     $xt_old = $xt;
                 }
                 $cord[$idx++] = $xt;
                 $cord[$idx++] = $yt_old;
                 $cord[$idx++] = $xt;
                 $cord[$idx++] = $yt;
             } elseif ($firstnonumeric == false) {
                 $firstnonumeric = true;
                 $yt_first = $yt_old;
                 $xt_first = $xt_old;
             }
         } else {
             $tmp1 = $y;
             $prev = $this->coords[0][$pnts - 1];
             if ($tmp1 === '' || $tmp1 === NULL || $tmp1 === 'X') {
                 $tmp1 = 'x';
             }
             if ($prev === '' || $prev === null || $prev === 'X') {
                 $prev = 'x';
             }
             if (is_numeric($y) || is_string($y) && $y != '-') {
                 if (is_numeric($y) && (is_numeric($prev) || $prev === '-')) {
                     $img->StyleLineTo($xt, $yt);
                 } else {
                     $img->SetStartPoint($xt, $yt);
                 }
             }
             if ($this->filled && $tmp1 !== '-') {
                 if ($tmp1 === 'x') {
                     $cord[$idx++] = $cord[$idx - 3];
                     $cord[$idx++] = $fillmin;
                 } elseif ($prev === 'x') {
                     $cord[$idx++] = $xt;
                     $cord[$idx++] = $fillmin;
                     $cord[$idx++] = $xt;
                     $cord[$idx++] = $yt;
                 } else {
                     $cord[$idx++] = $xt;
                     $cord[$idx++] = $yt;
                 }
             } else {
                 if (is_numeric($tmp1) && (is_numeric($prev) || $prev === '-')) {
                     $cord[$idx++] = $xt;
                     $cord[$idx++] = $yt;
                 }
             }
         }
         $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) {
             $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];
             $areaCoords[] = $minY;
             if ($this->filledAreas[$i][3]) {
                 $img->SetColor($this->filledAreas[$i][2]);
                 $img->FilledPolygon($areaCoords);
                 $img->SetColor($this->color);
             }
             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])) {
                 if (!empty($this->csimwintargets[$pnts])) {
                     $this->mark->SetCSIMTarget($this->csimtargets[$pnts], $this->csimwintargets[$pnts]);
                 } else {
                     $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();
         }
     }
 }