View unanswered posts | View active topics It is currently Thu Mar 28, 2024 11:47 am



Reply to topic  [ 1 post ] 
drawXThresholdArea Area name postion 
Author Message
New pChart user
New pChart user

Joined: Thu Oct 27, 2011 12:28 pm
Posts: 2
Post drawXThresholdArea Area name postion
Hi

I change the Draw class drawXThresholdArea function:
Code:
define("ZONE_NAME_POS_CENTER"      , 691091);
define("ZONE_NAME_POS_TOP"         , 691092);
define("ZONE_NAME_POS_BOTTOM"      , 691093);

function drawXThresholdArea($Value1,$Value2,$Format="")
    {
     $R      = isset($Format["R"]) ? $Format["R"] : 255;
     $G      = isset($Format["G"]) ? $Format["G"] : 0;
     $B      = isset($Format["B"]) ? $Format["B"] : 0;
     $Alpha   = isset($Format["Alpha"]) ? $Format["Alpha"] : 20;
     $Border    = isset($Format["Border"]) ? $Format["Border"] : TRUE;
     $BorderR   = isset($Format["BorderR"]) ? $Format["BorderR"] : $R;
     $BorderG   = isset($Format["BorderG"]) ? $Format["BorderG"] : $G;
     $BorderB   = isset($Format["BorderB"]) ? $Format["BorderB"] : $B;
     $BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : $Alpha + 20;
     $BorderTicks = isset($Format["BorderTicks"]) ? $Format["BorderTicks"] : 2;
     $AreaName    = isset($Format["AreaName"]) ? $Format["AreaName"] : NULL;
     $NamePos    = isset($Format["NamePos"]) ? $Format["NamePos"] : ZONE_NAME_POS_CENTER;
     $NameAngle   = isset($Format["NameAngle"]) ? $Format["NameAngle"] : ZONE_NAME_ANGLE_AUTO;
     $NameR   = isset($Format["NameR"]) ? $Format["NameR"] : 255;
     $NameG   = isset($Format["NameG"]) ? $Format["NameG"] : 255;
     $NameB   = isset($Format["NameB"]) ? $Format["NameB"] : 255;
     $NameAlpha   = isset($Format["NameAlpha"]) ? $Format["NameAlpha"] : 100;
     $DisableShadowOnArea = isset($Format["DisableShadowOnArea"]) ? $Format["DisableShadowOnArea"] : TRUE;

     $RestoreShadow = $this->Shadow;
     if ( $DisableShadowOnArea && $this->Shadow ) { $this->Shadow = FALSE; }

     if ($BorderAlpha >100) { $BorderAlpha = 100;}

     $Data           = $this->DataSet->getData();
     $XScale         = $this->scaleGetXSettings();
     $AbscissaMargin = $this->getAbscissaMargin($Data);

     if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
      {
       $XStep = (($this->GraphAreaX2 - $this->GraphAreaX1) - $XScale[0] *2 ) / $XScale[1];
       $XPos1 = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value1;
       $XPos2 = $this->GraphAreaX1 + $XScale[0] + $XStep * $Value2;
       $YPos1 = $this->GraphAreaY1 + $Data["YMargin"];
       $YPos2 = $this->GraphAreaY2 - $Data["YMargin"];

       if ( $XPos1 < $this->GraphAreaX1 + $XScale[0] ) { $XPos1 = $this->GraphAreaX1 + $XScale[0]; }
       if ( $XPos1 > $this->GraphAreaX2 - $XScale[0] ) { $XPos1 = $this->GraphAreaX2 - $XScale[0]; }
       if ( $XPos2 < $this->GraphAreaX1 + $XScale[0] ) { $XPos2 = $this->GraphAreaX1 + $XScale[0]; }
       if ( $XPos2 > $this->GraphAreaX2 - $XScale[0] ) { $XPos2 = $this->GraphAreaX2 - $XScale[0]; }

       $this->drawFilledRectangle($XPos1,$YPos1,$XPos2,$YPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));

       if ( $Border )
        {
         $this->drawLine($XPos1,$YPos1,$XPos1,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
         $this->drawLine($XPos2,$YPos1,$XPos2,$YPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
        }

       if ( $AreaName != NULL )
        {
       switch ($NamePos) {
          default: case ZONE_NAME_POS_CENTER:
                $XPos = ($XPos2-$XPos1)/2 + $XPos1;
                $YPos = ($YPos2-$YPos1)/2 + $YPos1;
             break;
          case ZONE_NAME_POS_TOP:
                $XPos = ($XPos2-$XPos1)/2 + $XPos1;
               
                $TxtPos   = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$AreaName);
                $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
                $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
               
                $YPos = $YPos1+ceil($TxtHeight/2)+5;         
                $YPos_Over=$YPos1+ceil($TxtWidth/2)+5;
             break;
          case ZONE_NAME_POS_BOTTOM:
                $XPos = ($XPos2-$XPos1)/2 + $XPos1;
                $YPos = ($YPos2-$YPos1)/2 + $YPos1;
               
                $XPos = ($XPos2-$XPos1)/2 + $XPos1;
               
                $TxtPos   = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$AreaName);
                $TxtHeight = abs($TxtPos[2]["Y"] - $TxtPos[0]["Y"]);
                $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
               
                $YPos = $YPos2-ceil($TxtHeight/2)-5;         
                $YPos_Over=$YPos2+ceil($TxtWidth/2)-5;
             break;
       }

         if ( $NameAngle == ZONE_NAME_ANGLE_AUTO ) {
            $TxtPos   = $this->getTextBox($XPos,$YPos,$this->FontName,$this->FontSize,0,$AreaName);
            $TxtWidth = $TxtPos[1]["X"] - $TxtPos[0]["X"];
                           
            if ( abs($XPos2 - $XPos1) > $TxtWidth ) { $NameAngle = 0; } else { $NameAngle = 90; $YPos=$YPos_Over; }
        }
         $this->Shadow = $RestoreShadow;
         $this->drawText($XPos,$YPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>$NameAngle,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
         if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
        }

       $this->Shadow = $RestoreShadow;
       return(array("X1"=>$XPos1,"X2"=>$XPos2));
      }
     elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
      {
       $XStep = (($this->GraphAreaY2 - $this->GraphAreaY1) - $XScale[0] *2 ) / $XScale[1];
       $XPos1 = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value1;
       $XPos2 = $this->GraphAreaY1 + $XScale[0] + $XStep * $Value2;
       $YPos1 = $this->GraphAreaX1 + $Data["YMargin"];
       $YPos2 = $this->GraphAreaX2 - $Data["YMargin"];

       if ( $XPos1 < $this->GraphAreaY1 + $XScale[0] ) { $XPos1 = $this->GraphAreaY1 + $XScale[0]; }
       if ( $XPos1 > $this->GraphAreaY2 - $XScale[0] ) { $XPos1 = $this->GraphAreaY2 - $XScale[0]; }
       if ( $XPos2 < $this->GraphAreaY1 + $XScale[0] ) { $XPos2 = $this->GraphAreaY1 + $XScale[0]; }
       if ( $XPos2 > $this->GraphAreaY2 - $XScale[0] ) { $XPos2 = $this->GraphAreaY2 - $XScale[0]; }

       $this->drawFilledRectangle($YPos1,$XPos1,$YPos2,$XPos2,array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha));

       if ( $Border )
        {
         $this->drawLine($YPos1,$XPos1,$YPos2,$XPos1,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
         $this->drawLine($YPos1,$XPos2,$YPos2,$XPos2,array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha,"Ticks"=>$BorderTicks));
        }

       if ( $AreaName != NULL )
        {
         $XPos = ($XPos2-$XPos1)/2 + $XPos1;
         $YPos = ($YPos2-$YPos1)/2 + $YPos1;

         $this->Shadow = $RestoreShadow;
         $this->drawText($YPos,$XPos,$AreaName,array("R"=>$NameR,"G"=>$NameG,"B"=>$NameB,"Alpha"=>$NameAlpha,"Angle"=>0,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE));
         if ( $DisableShadowOnArea ) { $this->Shadow = FALSE; }
        }

       $this->Shadow = $RestoreShadow;
       return(array("X1"=>$XPos1,"X2"=>$XPos2));
      }
    }


This small change can only do so much that can be positioned the AreaName.


Thu Oct 27, 2011 12:40 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron