Beispiel #1
0
 public function _StrokeLegend($aImg, $x, $y, $scaling = 1, $aReturnWidth = false)
 {
     if (!$this->legend->iShow) {
         return 0;
     }
     $nlc = count($this->iLegColors);
     $nlw = count($this->iLegweights);
     // Setup font for ranges
     $value = new Text\Text();
     $value->SetAlign('center', 'bottom');
     $value->SetFont($this->legend->iLblFontFamily, $this->legend->iLblFontStyle, $this->legend->iLblFontSize * $scaling);
     $value->SetColor($this->legend->iLblFontColor);
     // Remember x-center
     $xcenter = $x;
     // Construct format string
     $fmt = $this->legend->iFormatString . '-' . $this->legend->iFormatString;
     // Make sure that the length of each range is enough to cover the
     // size of the labels
     $tst = sprintf($fmt, $this->iRanges[0], $this->iRanges[1]);
     $value->Set($tst);
     $w = $value->GetWidth($aImg);
     $l = round(max($this->legend->iLength * $scaling, $w * 1.5));
     $r = $this->legend->iCircleRadius * $scaling;
     $len = 2 * $r + $this->scale->iMaxNum * $l;
     // We are called just to find out the width
     if ($aReturnWidth) {
         return $len;
     }
     $x -= round($len / 2);
     $x += $r;
     // 4 pixels extra vertical margin since the circle sometimes is +/- 1 pixel of the
     // theorethical radius due to imperfection in the GD library
     //$y -= round(max($r,$scaling*$this->iLegweights[($this->scale->iMaxNum-1) % $nlw])+4*$scaling);
     $y -= ($this->legend->iCircleRadius + 2) * $scaling + $this->legend->iBottomMargin * $scaling;
     // Adjust for bottom text
     if ($this->legend->iTxt != '') {
         // Setup font for text
         $value->Set($this->legend->iTxt);
         $y -= $value->GetHeight($aImg);
     }
     // Stroke 0-circle
     $this->_ThickCircle($aImg, $x, $y, $r, $this->legend->iCircleWeight, $this->legend->iCircleColor);
     // Remember the center of the circe
     $xc = $x;
     $yc = $y;
     $value->SetAlign('center', 'bottom');
     $x += $r + 1;
     // Stroke all used ranges
     $txty = $y - round($this->iLegweights[($this->scale->iMaxNum - 1) % $nlw] * $scaling) - 4 * $scaling;
     if ($this->scale->iMaxNum >= count($this->iRanges)) {
         Util\JpGraphError::RaiseL(22007);
         //('To few values for the range legend.');
     }
     $i = 0;
     $idx = 0;
     while ($i < $this->scale->iMaxNum) {
         $y1 = $y - round($this->iLegweights[$i % $nlw] * $scaling);
         $y2 = $y + round($this->iLegweights[$i % $nlw] * $scaling);
         $x2 = $x + $l;
         $aImg->SetColor($this->iLegColors[$i % $nlc]);
         $aImg->FilledRectangle($x, $y1, $x2, $y2);
         if ($this->iRangeStyle == RANGE_OVERLAPPING) {
             $lbl = sprintf($fmt, $this->iRanges[$idx], $this->iRanges[$idx + 1]);
         } else {
             $lbl = sprintf($fmt, $this->iRanges[$idx], $this->iRanges[$idx + 1]);
             ++$idx;
         }
         $value->Set($lbl);
         $value->Stroke($aImg, $x + $l / 2, $txty);
         $x = $x2;
         ++$i;
         ++$idx;
     }
     // Setup circle font
     $value->SetFont($this->legend->iCircleFontFamily, $this->legend->iCircleFontStyle, $this->legend->iCircleFontSize * $scaling);
     $value->SetColor($this->legend->iCircleFontColor);
     // Stroke 0-circle text
     $value->Set($this->legend->iZCircleTxt);
     $value->SetAlign('center', 'center');
     $value->ParagraphAlign('center');
     $value->Stroke($aImg, $xc, $yc);
     // Setup circle font
     $value->SetFont($this->legend->iTxtFontFamily, $this->legend->iTxtFontStyle, $this->legend->iTxtFontSize * $scaling);
     $value->SetColor($this->legend->iTxtFontColor);
     // Draw the text under the legend
     $value->Set($this->legend->iTxt);
     $value->SetAlign('center', 'top');
     $value->SetParagraphAlign('center');
     $value->Stroke($aImg, $xcenter, $y2 + $this->legend->iTxtMargin * $scaling);
 }