mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-21 03:39:00 +00:00
74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
![]() |
<?php
|
||
|
/*
|
||
|
* ChartData.php
|
||
|
* Copyright (c) 2024 james@firefly-iii.org.
|
||
|
*
|
||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
||
|
*/
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace FireflyIII\Support\Chart;
|
||
|
|
||
|
use FireflyIII\Exceptions\FireflyException;
|
||
|
|
||
|
class ChartData
|
||
|
{
|
||
|
private array $series;
|
||
|
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->series = [];
|
||
|
}
|
||
|
|
||
|
public function render(): array
|
||
|
{
|
||
|
if (0 === count($this->series)) {
|
||
|
throw new FireflyException('No series added to chart');
|
||
|
}
|
||
|
|
||
|
return $this->series;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param array $data
|
||
|
*
|
||
|
* @return void
|
||
|
* @throws FireflyException
|
||
|
*/
|
||
|
public function add(array $data): void
|
||
|
{
|
||
|
if (array_key_exists('currency_id', $data)) {
|
||
|
$data['currency_id'] = (string) $data['currency_id'];
|
||
|
}
|
||
|
if (array_key_exists('native_currency_id', $data)) {
|
||
|
$data['native_currency_id'] = (string) $data['native_currency_id'];
|
||
|
}
|
||
|
if (!array_key_exists('start', $data)) {
|
||
|
throw new FireflyException('Data-set is missing the "start"-variable.');
|
||
|
}
|
||
|
if (!array_key_exists('end', $data)) {
|
||
|
throw new FireflyException('Data-set is missing the "end"-variable.');
|
||
|
}
|
||
|
if (!array_key_exists('period', $data)) {
|
||
|
throw new FireflyException('Data-set is missing the "period"-variable.');
|
||
|
}
|
||
|
|
||
|
$this->series[] = $data;
|
||
|
}
|
||
|
|
||
|
}
|