mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 18:54:58 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			71 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.9 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;
 | |
| 
 | |
| /**
 | |
|  * @deprecated
 | |
|  */
 | |
| class ChartData
 | |
| {
 | |
|     private array $series;
 | |
| 
 | |
|     public function __construct()
 | |
|     {
 | |
|         $this->series = [];
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @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('primary_currency_id', $data)) {
 | |
|             $data['primary_currency_id'] = (string)$data['primary_currency_id'];
 | |
|         }
 | |
|         $required       = ['start', 'date', 'end', 'entries'];
 | |
|         foreach ($required as $field) {
 | |
|             if (!array_key_exists($field, $data)) {
 | |
|                 throw new FireflyException(sprintf('Data-set is missing the "%s"-variable.', $field));
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         $this->series[] = $data;
 | |
|     }
 | |
| 
 | |
|     public function render(): array
 | |
|     {
 | |
|         if (0 === count($this->series)) {
 | |
|             throw new FireflyException('No series added to chart');
 | |
|         }
 | |
| 
 | |
|         return $this->series;
 | |
|     }
 | |
| }
 |