View unanswered posts | View active topics It is currently Sat Apr 27, 2024 7:42 pm



Reply to topic  [ 2 posts ] 
drawLegend - when Description contains "\n" 
Author Message
Post drawLegend - when Description contains "\n"
Maybe this was never supposed to be allowed, but in Version 1.2x you could use a wordwrap with "\n" to get long Descriptions fit into the legend - so they expand only to y-Axis.
In Version 2.0.4. This will not work.

I have very long descriptions, that will never fit into the Legend if they don't wrap with a "\n".
So I made a small change to the function drawLegend() that will fullfill my requirement, but it is not perfect (see later)

Changes will affect only LEGEND_VERTICAL:
"Align"=>TEXT_ALIGN_TOPLEFT
Coordinates will be dependant from FontSize and number of "\n" in the Description.

Sad, i could not made it work perfect for all fontsizes. The Scalefactor (1.2) is only a dirty-hack
I hope someone else may find a better Solution.


Code:
pChart2.0.4/class $ diff pDraw.class pDraw.class.ori
1301,1302c1301,1302
<          $this->drawFilledRectangle($X+1,$Y+1+$this->FontSize/2,$X+$BoxSize+1,$Y+$BoxSize+1+$this->FontSize/2,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
<          $this->drawFilledRectangle($X,$Y+$this->FontSize/2,$X+$BoxSize,$Y+$BoxSize+$this->FontSize/2,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
---
>          $this->drawFilledRectangle($X+1,$Y+1,$X+$BoxSize+1,$Y+$BoxSize+1,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>20));
>          $this->drawFilledRectangle($X,$Y,$X+$BoxSize,$Y+$BoxSize,array("R"=>$R,"G"=>$G,"B"=>$B,"Surrounding"=>20));
1305,1306c1305,1306
<            $this->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Serie["Description"],array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_TOPLEFT));
<            $Y=$Y+$YStep*(1+preg_match_all("/\n/",$Serie["Description"],$a=array()))*1.2;
---
>            $this->drawText($X+$BoxSize+4,$Y+$BoxSize/2,$Serie["Description"],array("R"=>$FontR,"G"=>$FontG,"B"=>$FontB,"Align"=>TEXT_ALIGN_MIDDLELEFT));
>            $Y=$Y+$YStep;


Tue Dec 07, 2010 4:08 pm
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: drawLegend - when Description contains "\n"
Hi,

This is now fixed in the 2.0.5 sub-release. I've tried to do it in a clean and safe way which is really tricky while working with the TTF PHP functions..

http://wiki.pchart.net/doc.doc.draw.legend.html

Thanks for having reported it !

Kind regards,
JD.


Wed Dec 08, 2010 11:38 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 5 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