summaryrefslogtreecommitdiffstats
path: root/src/element/text.php
blob: a72ee3eb5c8c801481dd7e36cc07c7855ad3e53c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
 * File containing the abstract ezcGraphChartElementText class
 *
 * @package Graph
 * @version //autogentag//
 * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
 * @license http://ez.no/licenses/new_bsd New BSD License
 */
/**
 * Class to represent a legend as a chart element
 *
 * @package Graph
 */
class ezcGraphChartElementText extends ezcGraphChartElement
{

    /**
     * Maximum percent of bounding used to display the text
     * 
     * @var float
     */
    protected $maxHeight = .1;

    /**
     * Render a legend
     * 
     * @param ezcGraphRenderer $renderer 
     * @access public
     * @return void
     */
    public function render( ezcGraphRenderer $renderer, ezcGraphBoundings $boundings )
    {
        if ( empty( $this->title ) )
        {
            return $boundings;
        }

        $this->renderBorder( $renderer );
        $this->renderBackground( $renderer );

        $height = (int) min( 
            round( $this->maxHeight * ( $boundings->y1 - $boundings->y0 ) ),
            $this->font->maxFontSize + $this->padding * 2
        );

        switch ( $this->position )
        {
            case ezcGraph::TOP:
                $renderer->drawTextBox(
                    new ezcGraphCoordinate(
                        $boundings->x0 + $this->padding,
                        $boundings->y0 + $this->padding
                    ),
                    $this->title,
                    $boundings->x1 - $boundings->x0 - $this->padding * 2,
                    $height - $this->padding * 2,
                    ezcGraph::CENTER | ezcGraph::MIDDLE
                );
                $boundings->y0 += $height + $this->margin;
                break;
            case ezcGraph::BOTTOM:
                $renderer->drawTextBox(
                    new ezcGraphCoordinate(
                        $boundings->x0 + $this->padding,
                        $boundings->y1 - $height + $this->padding
                    ),
                    $this->title,
                    $boundings->x1 - $boundings->x0 - $this->padding * 2,
                    $height - $this->padding * 2,
                    ezcGraph::CENTER | ezcGraph::MIDDLE
                );
                $boundings->y1 -= $height + $this->margin;
                break;
        }
        return $boundings;
    }
}

?>
OpenPOWER on IntegriCloud