Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace PhpOffice\PhpSpreadsheet\Chart;
4
 
5
class Legend
6
{
7
    /** Legend positions */
8
    const XL_LEGEND_POSITION_BOTTOM = -4107; //    Below the chart.
9
    const XL_LEGEND_POSITION_CORNER = 2; //    In the upper right-hand corner of the chart border.
10
    const XL_LEGEND_POSITION_CUSTOM = -4161; //    A custom position.
11
    const XL_LEGEND_POSITION_LEFT = -4131; //    Left of the chart.
12
    const XL_LEGEND_POSITION_RIGHT = -4152; //    Right of the chart.
13
    const XL_LEGEND_POSITION_TOP = -4160; //    Above the chart.
14
 
15
    const POSITION_RIGHT = 'r';
16
    const POSITION_LEFT = 'l';
17
    const POSITION_BOTTOM = 'b';
18
    const POSITION_TOP = 't';
19
    const POSITION_TOPRIGHT = 'tr';
20
 
21
    const POSITION_XLREF = [
22
        self::XL_LEGEND_POSITION_BOTTOM => self::POSITION_BOTTOM,
23
        self::XL_LEGEND_POSITION_CORNER => self::POSITION_TOPRIGHT,
24
        self::XL_LEGEND_POSITION_CUSTOM => '??',
25
        self::XL_LEGEND_POSITION_LEFT => self::POSITION_LEFT,
26
        self::XL_LEGEND_POSITION_RIGHT => self::POSITION_RIGHT,
27
        self::XL_LEGEND_POSITION_TOP => self::POSITION_TOP,
28
    ];
29
 
30
    /**
31
     * Legend position.
32
     */
33
    private string $position = self::POSITION_RIGHT;
34
 
35
    /**
36
     * Allow overlay of other elements?
37
     */
38
    private bool $overlay = true;
39
 
40
    /**
41
     * Legend Layout.
42
     */
43
    private ?Layout $layout;
44
 
45
    private GridLines $borderLines;
46
 
47
    private ChartColor $fillColor;
48
 
49
    private ?AxisText $legendText = null;
50
 
51
    /**
52
     * Create a new Legend.
53
     */
54
    public function __construct(string $position = self::POSITION_RIGHT, ?Layout $layout = null, bool $overlay = false)
55
    {
56
        $this->setPosition($position);
57
        $this->layout = $layout;
58
        $this->setOverlay($overlay);
59
        $this->borderLines = new GridLines();
60
        $this->fillColor = new ChartColor();
61
    }
62
 
63
    public function getFillColor(): ChartColor
64
    {
65
        return $this->fillColor;
66
    }
67
 
68
    /**
69
     * Get legend position as an excel string value.
70
     */
71
    public function getPosition(): string
72
    {
73
        return $this->position;
74
    }
75
 
76
    /**
77
     * Get legend position using an excel string value.
78
     *
79
     * @param string $position see self::POSITION_*
80
     */
81
    public function setPosition(string $position): bool
82
    {
83
        if (!in_array($position, self::POSITION_XLREF)) {
84
            return false;
85
        }
86
 
87
        $this->position = $position;
88
 
89
        return true;
90
    }
91
 
92
    /**
93
     * Get legend position as an Excel internal numeric value.
94
     */
95
    public function getPositionXL(): false|int
96
    {
97
        return array_search($this->position, self::POSITION_XLREF);
98
    }
99
 
100
    /**
101
     * Set legend position using an Excel internal numeric value.
102
     *
103
     * @param int $positionXL see self::XL_LEGEND_POSITION_*
104
     */
105
    public function setPositionXL(int $positionXL): bool
106
    {
107
        if (!isset(self::POSITION_XLREF[$positionXL])) {
108
            return false;
109
        }
110
 
111
        $this->position = self::POSITION_XLREF[$positionXL];
112
 
113
        return true;
114
    }
115
 
116
    /**
117
     * Get allow overlay of other elements?
118
     */
119
    public function getOverlay(): bool
120
    {
121
        return $this->overlay;
122
    }
123
 
124
    /**
125
     * Set allow overlay of other elements?
126
     */
127
    public function setOverlay(bool $overlay): void
128
    {
129
        $this->overlay = $overlay;
130
    }
131
 
132
    /**
133
     * Get Layout.
134
     */
135
    public function getLayout(): ?Layout
136
    {
137
        return $this->layout;
138
    }
139
 
140
    public function getLegendText(): ?AxisText
141
    {
142
        return $this->legendText;
143
    }
144
 
145
    public function setLegendText(?AxisText $legendText): self
146
    {
147
        $this->legendText = $legendText;
148
 
149
        return $this;
150
    }
151
 
152
    public function getBorderLines(): GridLines
153
    {
154
        return $this->borderLines;
155
    }
156
 
157
    public function setBorderLines(GridLines $borderLines): self
158
    {
159
        $this->borderLines = $borderLines;
160
 
161
        return $this;
162
    }
163
 
164
    /**
165
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
166
     */
167
    public function __clone()
168
    {
169
        $this->layout = ($this->layout === null) ? null : clone $this->layout;
170
        $this->legendText = ($this->legendText === null) ? null : clone $this->legendText;
171
        $this->borderLines = clone $this->borderLines;
172
        $this->fillColor = clone $this->fillColor;
173
    }
174
}