View unanswered posts | View active topics It is currently Fri Mar 01, 2024 2:10 pm



Reply to topic  [ 1 post ] 
pDraw additional func writeArrowLabel 
Author Message
pChart user
pChart user

Joined: Sat Dec 24, 2011 2:41 pm
Posts: 4
Post pDraw additional func writeArrowLabel
The func allows to put arrow like labels to charts (see attachment)
Code:
   /* Write arrow labels */
   function writeArrowLabel($SeriesName,$Indexes,$Format="")
    {
     $OverrideTitle   = isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
     $ForceLabels   = isset($Format["ForceLabels"]) ? $Format["ForceLabels"] : NULL;
     $DrawPoint      = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
     $DrawVerticalLine   = isset($Format["DrawVerticalLine"]) ? $Format["DrawVerticalLine"] : FALSE;
     $VerticalLineR   = isset($Format["VerticalLineR"]) ? $Format["VerticalLineR"] : 0;
     $VerticalLineG   = isset($Format["VerticalLineG"]) ? $Format["VerticalLineG"] : 0;
     $VerticalLineB   = isset($Format["VerticalLineB"]) ? $Format["VerticalLineB"] : 0;
     $VerticalLineAlpha   = isset($Format["VerticalLineAlpha"]) ? $Format["VerticalLineAlpha"] : 40;
     $VerticalLineTicks   = isset($Format["VerticalLineTicks"]) ? $Format["VerticalLineTicks"] : 2;

     $Data = $this->DataSet->getData();
     list($XMargin,$XDivs) = $this->scaleGetXSettings();

     if ( !is_array($Indexes) )    { $Index = $Indexes; $Indexes = ""; $Indexes[] = $Index; }
     if ( !is_array($SeriesName) ) { $SerieName = $SeriesName; $SeriesName = ""; $SeriesName[] = $SerieName; }
     if ( $ForceLabels != NULL && !is_array($ForceLabels) ) { $ForceLabel = $ForceLabels; $ForceLabels = ""; $ForceLabels[] = $ForceLabel; }

     foreach ($Indexes as $Key => $Index)
      {
       $Series = "";

       if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
        {
         if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
         $X = $this->GraphAreaX1 + $XMargin + $Index * $XStep;

         if ( $DrawVerticalLine ) { $this->drawLine($X,$this->GraphAreaY1+$Data["YMargin"],$X,$this->GraphAreaY2-$Data["YMargin"],array("R"=>$VerticalLineR,"G"=>$VerticalLineG,"B"=>$VerticalLineB,"Alpha"=>$VerticalLineAlpha,"Ticks"=>$VerticalLineTicks)); }

         $MinY = $this->GraphAreaY2;
         foreach ($SeriesName as $iKey => $SerieName)
          {
           if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
            {
             $AxisID      = $Data["Series"][$SerieName]["Axis"];

             if ( $OverrideTitle != NULL)
              $Description = $OverrideTitle;
             elseif ( count($SeriesName) == 1 )
              {
               if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
                $Description = $Data["Series"][$SerieName]["Description"]." - ".$Data["Series"][$Data["Abscissa"]]["Data"][$Index];
               else
                $Description = $Data["Series"][$SerieName]["Description"];
              }
             elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
              $Description = $Data["Series"][$Data["Abscissa"]]["Data"][$Index];

             $AxisMode     = $Data["Axis"][$AxisID]["Display"];
             $AxisFormat   = $Data["Axis"][$AxisID]["Format"];
             $AxisUnit     = $Data["Axis"][$AxisID]["Unit"];

             $Serie = "";
             $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
             $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
             $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
             $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];

             if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
              $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
             else
              $SerieOffset = 0;

             $Value = $Data["Series"][$SerieName]["Data"][$Index];
             if ( $Value == VOID ) { $Value = "NaN"; }

             if ( $ForceLabels != NULL )
              $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
             else
              $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);

             if ( $this->LastChartLayout == CHART_LAST_LAYOUT_STACKED )
              {
               if ( $Value >=0 ) { $LookFor = "+"; } else { $LookFor = "-"; }

               $Value = 0; $Done = FALSE;
               foreach($Data["Series"] as $Name => $SerieLookup)
                {
                 if ( $SerieLookup["isDrawable"] == TRUE && $Name != $Data["Abscissa"] && !$Done )
                  {
                   if ( isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID )
                    {
                     if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+" ) { $Value = $Value + $Data["Series"][$Name]["Data"][$Index]; }
                     if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-" )  { $Value = $Value - $Data["Series"][$Name]["Data"][$Index]; }
                     if ($Name == $SerieName ) { $Done = TRUE; }
                    }
                  }
                }
              }

             $X = floor($this->GraphAreaX1 + $XMargin + $Index * $XStep + $SerieOffset);
             $Y = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));

             if ($Y < $MinY) { $MinY = $Y; }

             if ( $DrawPoint == LABEL_POINT_CIRCLE )
              $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
             elseif ( $DrawPoint == LABEL_POINT_BOX )
              $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));

             $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
            }
          }
//         $this->drawLabelBox($X,$MinY-3,$Description,$Series,$Format);
         $this->drawArrowLabel($X,$MinY,$Caption,$Format);

        }
       else
        {
         if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1)/4; } else { $XStep = ($this->GraphAreaY2-$this->GraphAreaY1-$XMargin*2)/$XDivs; }
         $Y = $this->GraphAreaY1 + $XMargin + $Index * $XStep;

         if ( $DrawVerticalLine ) { $this->drawLine($this->GraphAreaX1+$Data["YMargin"],$Y,$this->GraphAreaX2-$Data["YMargin"],$Y,array("R"=>$VerticalLineR,"G"=>$VerticalLineG,"B"=>$VerticalLineB,"Alpha"=>$VerticalLineAlpha,"Ticks"=>$VerticalLineTicks)); }

         $MinX = $this->GraphAreaX2;
         foreach ($SeriesName as $Key => $SerieName)
          {
           if ( isset($Data["Series"][$SerieName]["Data"][$Index]) )
            {
             $AxisID      = $Data["Series"][$SerieName]["Axis"];

             if ( $OverrideTitle != NULL)
              $Description = $OverrideTitle;
             elseif ( count($SeriesName) == 1 )
              {
               if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
                $Description = $Data["Series"][$SerieName]["Description"]." - ".$Data["Series"][$Data["Abscissa"]]["Data"][$Index];
               else
                $Description = $Data["Series"][$SerieName]["Description"];
              }
             elseif ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Index]) )
              $Description = $Data["Series"][$Data["Abscissa"]]["Data"][$Index];

             $AxisMode     = $Data["Axis"][$AxisID]["Display"];
             $AxisFormat   = $Data["Axis"][$AxisID]["Format"];
             $AxisUnit     = $Data["Axis"][$AxisID]["Unit"];

             $Serie = "";
             if ( isset($Data["Extended"]["Palette"][$Index] ) )
              {
               $Serie["R"] = $Data["Extended"]["Palette"][$Index]["R"];
               $Serie["G"] = $Data["Extended"]["Palette"][$Index]["G"];
               $Serie["B"] = $Data["Extended"]["Palette"][$Index]["B"];
               $Serie["Alpha"] = $Data["Extended"]["Palette"][$Index]["Alpha"];
              }
             else
              {
               $Serie["R"] = $Data["Series"][$SerieName]["Color"]["R"];
               $Serie["G"] = $Data["Series"][$SerieName]["Color"]["G"];
               $Serie["B"] = $Data["Series"][$SerieName]["Color"]["B"];
               $Serie["Alpha"] = $Data["Series"][$SerieName]["Color"]["Alpha"];
              }

             if ( count($SeriesName) == 1 && isset($Data["Series"][$SerieName]["XOffset"]) )
              $SerieOffset = $Data["Series"][$SerieName]["XOffset"];
             else
              $SerieOffset = 0;

             $Value = $Data["Series"][$SerieName]["Data"][$Index];
             if ( $ForceLabels != NULL )
              $Caption = isset($ForceLabels[$Key]) ? $ForceLabels[$Key] : "Not set";
             else
              $Caption = $this->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);
             if ( $Value == VOID ) { $Value = "NaN"; }

             if ( $this->LastChartLayout == CHART_LAST_LAYOUT_STACKED )
              {
               if ( $Value >=0 ) { $LookFor = "+"; } else { $LookFor = "-"; }

               $Value = 0; $Done = FALSE;
               foreach($Data["Series"] as $Name => $SerieLookup)
                {
                 if ( $SerieLookup["isDrawable"] == TRUE && $Name != $Data["Abscissa"] && !$Done )
                  {
                   if ( isset($Data["Series"][$Name]["Data"][$Index]) && $Data["Series"][$Name]["Data"][$Index] != VOID )
                    {
                     if ($Data["Series"][$Name]["Data"][$Index] >= 0 && $LookFor == "+" ) { $Value = $Value + $Data["Series"][$Name]["Data"][$Index]; }
                     if ($Data["Series"][$Name]["Data"][$Index] < 0 && $LookFor == "-" )  { $Value = $Value - $Data["Series"][$Name]["Data"][$Index]; }
                     if ($Name == $SerieName ) { $Done = TRUE; }
                    }
                  }
                }
              }

             $X = floor($this->scaleComputeY($Value,array("AxisID"=>$AxisID)));
             $Y = floor($this->GraphAreaY1 + $XMargin + $Index * $XStep + $SerieOffset);

             if ($X < $MinX) { $MinX = $X; }

             if ( $DrawPoint == LABEL_POINT_CIRCLE )
              $this->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
             elseif ( $DrawPoint == LABEL_POINT_BOX )
              $this->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));

             $Series[] = array("Format"=>$Serie,"Caption"=>$Caption);
            }
          }
//         $this->drawLabelBox($MinX,$Y-3,$Description,$Series,$Format);
         $this->drawArrowLabel($MinX,$Y,$Caption,$Format);

        }
      }
    }   


Attachments:
chart.png
chart.png [ 31.95 KiB | Viewed 7221 times ]
Fri Feb 17, 2012 4:56 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