## #46 PieLabel (draw a label within/outside the sector)

open
nobody
None
5
2014-12-14
2011-10-21
Anonymous
No

I do not know whether this can be considered as a patch, rather it is feature. Not so long ago I had to make a pie chart (with labels) using your library. There is a tcpdf::PieSector function to draw a pie sector. Unfortunately, I wasn't able to find the function that draws a label inside or outside the sector. So I wrote it myself. Perhaps it will be interesting to you and the users of this library. Thank you for your time.

Code of the PieLabel method (see the attached file):
public function PieLabel(\$txt, \$xc, \$yc, \$r, \$a, \$b, \$l, \$h=0) {
\$angle = \$a + \$b / 2;

```if (\$angle >= 270) {
\$angle = (360 - \$angle) * M_PI / 180;
\$x0 = (\$r + \$l) * sin(\$angle);
\$y0 = (\$r + \$l) * cos(\$angle);

\$this->Text(\$xc - \$x0 - strlen(\$txt), \$yc - \$y0 - \$h, \$txt);
}
else if (\$angle >= 180 && \$angle < 270) {
\$angle = (\$angle - 180) * M_PI / 180;
\$x0 = (\$r + \$l) * sin(\$angle);
\$y0 = (\$r + \$l) * cos(\$angle);

\$this->Text(\$xc - \$x0 - strlen(\$txt), \$yc + \$y0 - \$h, \$txt);
}
else if (\$angle >= 90 && \$angle < 180) {
\$angle = (180 - \$angle) * M_PI / 180;
\$x0 = (\$r + \$l) * sin(\$angle);
\$y0 = (\$r + \$l) * cos(\$angle);

\$this->Text(\$xc + \$x0, \$yc + \$y0 - \$h, \$txt);
}
else {
\$angle = \$angle * M_PI / 180;
\$x0 = (\$r + \$l) * sin(\$angle);
\$y0 = (\$r + \$l) * cos(\$angle);

\$this->Text(\$xc + \$x0, \$yc - \$y0 - \$h, \$txt);
}
```

}

• Anonymous
2011-10-21

PieLabel

Attachments