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
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
6
 
7
class DataSeries
8
{
9
    const TYPE_BARCHART = 'barChart';
10
    const TYPE_BARCHART_3D = 'bar3DChart';
11
    const TYPE_LINECHART = 'lineChart';
12
    const TYPE_LINECHART_3D = 'line3DChart';
13
    const TYPE_AREACHART = 'areaChart';
14
    const TYPE_AREACHART_3D = 'area3DChart';
15
    const TYPE_PIECHART = 'pieChart';
16
    const TYPE_PIECHART_3D = 'pie3DChart';
17
    const TYPE_DOUGHNUTCHART = 'doughnutChart';
18
    const TYPE_DONUTCHART = self::TYPE_DOUGHNUTCHART; // Synonym
19
    const TYPE_SCATTERCHART = 'scatterChart';
20
    const TYPE_SURFACECHART = 'surfaceChart';
21
    const TYPE_SURFACECHART_3D = 'surface3DChart';
22
    const TYPE_RADARCHART = 'radarChart';
23
    const TYPE_BUBBLECHART = 'bubbleChart';
24
    const TYPE_STOCKCHART = 'stockChart';
25
    const TYPE_CANDLECHART = self::TYPE_STOCKCHART; // Synonym
26
 
27
    const GROUPING_CLUSTERED = 'clustered';
28
    const GROUPING_STACKED = 'stacked';
29
    const GROUPING_PERCENT_STACKED = 'percentStacked';
30
    const GROUPING_STANDARD = 'standard';
31
 
32
    const DIRECTION_BAR = 'bar';
33
    const DIRECTION_HORIZONTAL = self::DIRECTION_BAR;
34
    const DIRECTION_COL = 'col';
35
    const DIRECTION_COLUMN = self::DIRECTION_COL;
36
    const DIRECTION_VERTICAL = self::DIRECTION_COL;
37
 
38
    const STYLE_LINEMARKER = 'lineMarker';
39
    const STYLE_SMOOTHMARKER = 'smoothMarker';
40
    const STYLE_MARKER = 'marker';
41
    const STYLE_FILLED = 'filled';
42
 
43
    const EMPTY_AS_GAP = 'gap';
44
    const EMPTY_AS_ZERO = 'zero';
45
    const EMPTY_AS_SPAN = 'span';
46
 
47
    /**
48
     * Series Plot Type.
49
     */
50
    private ?string $plotType;
51
 
52
    /**
53
     * Plot Grouping Type.
54
     */
55
    private ?string $plotGrouping;
56
 
57
    /**
58
     * Plot Direction.
59
     */
60
    private string $plotDirection;
61
 
62
    /**
63
     * Plot Style.
64
     */
65
    private ?string $plotStyle;
66
 
67
    /**
68
     * Order of plots in Series.
69
     *
70
     * @var int[]
71
     */
72
    private array $plotOrder;
73
 
74
    /**
75
     * Plot Label.
76
     *
77
     * @var DataSeriesValues[]
78
     */
79
    private array $plotLabel;
80
 
81
    /**
82
     * Plot Category.
83
     *
84
     * @var DataSeriesValues[]
85
     */
86
    private array $plotCategory;
87
 
88
    /**
89
     * Smooth Line. Must be specified for both DataSeries and DataSeriesValues.
90
     */
91
    private bool $smoothLine;
92
 
93
    /**
94
     * Plot Values.
95
     *
96
     * @var DataSeriesValues[]
97
     */
98
    private array $plotValues;
99
 
100
    /**
101
     * Plot Bubble Sizes.
102
     *
103
     * @var DataSeriesValues[]
104
     */
105
    private array $plotBubbleSizes = [];
106
 
107
    /**
108
     * Create a new DataSeries.
109
     *
110
     * @param int[] $plotOrder
111
     * @param DataSeriesValues[] $plotLabel
112
     * @param DataSeriesValues[] $plotCategory
113
     * @param DataSeriesValues[] $plotValues
114
     */
115
    public function __construct(
116
        null|string $plotType = null,
117
        null|string $plotGrouping = null,
118
        array $plotOrder = [],
119
        array $plotLabel = [],
120
        array $plotCategory = [],
121
        array $plotValues = [],
122
        ?string $plotDirection = null,
123
        bool $smoothLine = false,
124
        ?string $plotStyle = null
125
    ) {
126
        $this->plotType = $plotType;
127
        $this->plotGrouping = $plotGrouping;
128
        $this->plotOrder = $plotOrder;
129
        $keys = array_keys($plotValues);
130
        $this->plotValues = $plotValues;
131
        if (!isset($plotLabel[$keys[0]])) {
132
            $plotLabel[$keys[0]] = new DataSeriesValues();
133
        }
134
        $this->plotLabel = $plotLabel;
135
 
136
        if (!isset($plotCategory[$keys[0]])) {
137
            $plotCategory[$keys[0]] = new DataSeriesValues();
138
        }
139
        $this->plotCategory = $plotCategory;
140
 
141
        $this->smoothLine = (bool) $smoothLine;
142
        $this->plotStyle = $plotStyle;
143
 
144
        if ($plotDirection === null) {
145
            $plotDirection = self::DIRECTION_COL;
146
        }
147
        $this->plotDirection = $plotDirection;
148
    }
149
 
150
    /**
151
     * Get Plot Type.
152
     */
153
    public function getPlotType(): ?string
154
    {
155
        return $this->plotType;
156
    }
157
 
158
    /**
159
     * Set Plot Type.
160
     *
161
     * @return $this
162
     */
163
    public function setPlotType(string $plotType): static
164
    {
165
        $this->plotType = $plotType;
166
 
167
        return $this;
168
    }
169
 
170
    /**
171
     * Get Plot Grouping Type.
172
     */
173
    public function getPlotGrouping(): ?string
174
    {
175
        return $this->plotGrouping;
176
    }
177
 
178
    /**
179
     * Set Plot Grouping Type.
180
     *
181
     * @return $this
182
     */
183
    public function setPlotGrouping(string $groupingType): static
184
    {
185
        $this->plotGrouping = $groupingType;
186
 
187
        return $this;
188
    }
189
 
190
    /**
191
     * Get Plot Direction.
192
     */
193
    public function getPlotDirection(): string
194
    {
195
        return $this->plotDirection;
196
    }
197
 
198
    /**
199
     * Set Plot Direction.
200
     *
201
     * @return $this
202
     */
203
    public function setPlotDirection(string $plotDirection): static
204
    {
205
        $this->plotDirection = $plotDirection;
206
 
207
        return $this;
208
    }
209
 
210
    /**
211
     * Get Plot Order.
212
     *
213
     * @return int[]
214
     */
215
    public function getPlotOrder(): array
216
    {
217
        return $this->plotOrder;
218
    }
219
 
220
    /**
221
     * Get Plot Labels.
222
     *
223
     * @return DataSeriesValues[]
224
     */
225
    public function getPlotLabels(): array
226
    {
227
        return $this->plotLabel;
228
    }
229
 
230
    /**
231
     * Get Plot Label by Index.
232
     *
233
     * @return DataSeriesValues|false
234
     */
235
    public function getPlotLabelByIndex(int $index): bool|DataSeriesValues
236
    {
237
        $keys = array_keys($this->plotLabel);
238
        if (in_array($index, $keys)) {
239
            return $this->plotLabel[$index];
240
        }
241
 
242
        return false;
243
    }
244
 
245
    /**
246
     * Get Plot Categories.
247
     *
248
     * @return DataSeriesValues[]
249
     */
250
    public function getPlotCategories(): array
251
    {
252
        return $this->plotCategory;
253
    }
254
 
255
    /**
256
     * Get Plot Category by Index.
257
     *
258
     * @return DataSeriesValues|false
259
     */
260
    public function getPlotCategoryByIndex(int $index): bool|DataSeriesValues
261
    {
262
        $keys = array_keys($this->plotCategory);
263
        if (in_array($index, $keys)) {
264
            return $this->plotCategory[$index];
265
        } elseif (isset($keys[$index])) {
266
            return $this->plotCategory[$keys[$index]];
267
        }
268
 
269
        return false;
270
    }
271
 
272
    /**
273
     * Get Plot Style.
274
     */
275
    public function getPlotStyle(): ?string
276
    {
277
        return $this->plotStyle;
278
    }
279
 
280
    /**
281
     * Set Plot Style.
282
     *
283
     * @return $this
284
     */
285
    public function setPlotStyle(?string $plotStyle): static
286
    {
287
        $this->plotStyle = $plotStyle;
288
 
289
        return $this;
290
    }
291
 
292
    /**
293
     * Get Plot Values.
294
     *
295
     * @return DataSeriesValues[]
296
     */
297
    public function getPlotValues(): array
298
    {
299
        return $this->plotValues;
300
    }
301
 
302
    /**
303
     * Get Plot Values by Index.
304
     *
305
     * @return DataSeriesValues|false
306
     */
307
    public function getPlotValuesByIndex(int $index): bool|DataSeriesValues
308
    {
309
        $keys = array_keys($this->plotValues);
310
        if (in_array($index, $keys)) {
311
            return $this->plotValues[$index];
312
        }
313
 
314
        return false;
315
    }
316
 
317
    /**
318
     * Get Plot Bubble Sizes.
319
     *
320
     * @return DataSeriesValues[]
321
     */
322
    public function getPlotBubbleSizes(): array
323
    {
324
        return $this->plotBubbleSizes;
325
    }
326
 
327
    /**
328
     * Set Plot Bubble Sizes.
329
     *
330
     * @param DataSeriesValues[] $plotBubbleSizes
331
     */
332
    public function setPlotBubbleSizes(array $plotBubbleSizes): self
333
    {
334
        $this->plotBubbleSizes = $plotBubbleSizes;
335
 
336
        return $this;
337
    }
338
 
339
    /**
340
     * Get Number of Plot Series.
341
     */
342
    public function getPlotSeriesCount(): int
343
    {
344
        return count($this->plotValues);
345
    }
346
 
347
    /**
348
     * Get Smooth Line.
349
     */
350
    public function getSmoothLine(): bool
351
    {
352
        return $this->smoothLine;
353
    }
354
 
355
    /**
356
     * Set Smooth Line.
357
     *
358
     * @return $this
359
     */
360
    public function setSmoothLine(bool $smoothLine): static
361
    {
362
        $this->smoothLine = $smoothLine;
363
 
364
        return $this;
365
    }
366
 
367
    public function refresh(Worksheet $worksheet): void
368
    {
369
        foreach ($this->plotValues as $plotValues) {
370
            $plotValues->refresh($worksheet, true);
371
        }
372
        foreach ($this->plotLabel as $plotValues) {
373
            $plotValues->refresh($worksheet, true);
374
        }
375
        foreach ($this->plotCategory as $plotValues) {
376
            $plotValues->refresh($worksheet, false);
377
        }
378
    }
379
 
380
    /**
381
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
382
     */
383
    public function __clone()
384
    {
385
        $plotLabels = $this->plotLabel;
386
        $this->plotLabel = [];
387
        foreach ($plotLabels as $plotLabel) {
388
            $this->plotLabel[] = $plotLabel;
389
        }
390
        $plotCategories = $this->plotCategory;
391
        $this->plotCategory = [];
392
        foreach ($plotCategories as $plotCategory) {
393
            $this->plotCategory[] = clone $plotCategory;
394
        }
395
        $plotValues = $this->plotValues;
396
        $this->plotValues = [];
397
        foreach ($plotValues as $plotValue) {
398
            $this->plotValues[] = clone $plotValue;
399
        }
400
        $plotBubbleSizes = $this->plotBubbleSizes;
401
        $this->plotBubbleSizes = [];
402
        foreach ($plotBubbleSizes as $plotBubbleSize) {
403
            $this->plotBubbleSizes[] = clone $plotBubbleSize;
404
        }
405
    }
406
}