mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Adding charts to reports
This commit is contained in:
parent
339c7f920b
commit
5066a95da0
@ -1342,6 +1342,28 @@ class Utils
|
||||
}
|
||||
|
||||
public static function brewerColor($number) {
|
||||
$colors = [
|
||||
'#337AB7',
|
||||
'#3cb44b',
|
||||
'#e6194b',
|
||||
'#f58231',
|
||||
'#911eb4',
|
||||
'#46f0f0',
|
||||
'#f032e6',
|
||||
'#d2f53c',
|
||||
'#fabebe',
|
||||
'#008080',
|
||||
'#e6beff',
|
||||
'#aa6e28',
|
||||
'#fffac8',
|
||||
'#800000',
|
||||
'#aaffc3',
|
||||
'#808000',
|
||||
'#000080',
|
||||
'#808080',
|
||||
];
|
||||
|
||||
/*
|
||||
$colors = [
|
||||
'#1c9f77',
|
||||
'#d95d02',
|
||||
@ -1352,11 +1374,18 @@ class Utils
|
||||
'#a87821',
|
||||
'#676767',
|
||||
];
|
||||
*/
|
||||
$number = ($number-1) % count($colors);
|
||||
|
||||
return $colors[$number];
|
||||
}
|
||||
|
||||
public static function brewerColorRGB($number) {
|
||||
$color = static::brewerColor($number);
|
||||
list($r, $g, $b) = sscanf($color, "#%02x%02x%02x");
|
||||
return "{$r},{$g},{$b}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace language-specific characters by ASCII-equivalents.
|
||||
* @param string $s
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Ninja\Reports;
|
||||
|
||||
use Utils;
|
||||
use Auth;
|
||||
use DateInterval;
|
||||
use DatePeriod;
|
||||
@ -233,26 +234,16 @@ class AbstractReport
|
||||
$records[] = isset($data[$date]) ? $data[$date] : 0;
|
||||
}
|
||||
|
||||
$color = '51,122,183';
|
||||
|
||||
/*
|
||||
if ($entityType == ENTITY_INVOICE) {
|
||||
$color = '51,122,183';
|
||||
} elseif ($entityType == ENTITY_PAYMENT) {
|
||||
$color = '54,193,87';
|
||||
} elseif ($entityType == ENTITY_EXPENSE) {
|
||||
$color = '128,128,128';
|
||||
}
|
||||
*/
|
||||
|
||||
$record = new stdClass();
|
||||
$datasets[] = $record;
|
||||
$color = Utils::brewerColorRGB(count($datasets));
|
||||
|
||||
$record->data = $records;
|
||||
$record->label = trans("texts.{$dimension}");
|
||||
$record->lineTension = 0;
|
||||
$record->borderWidth = 3;
|
||||
$record->borderColor = "rgba({$color}, 1)";
|
||||
$record->backgroundColor = "rgba({$color}, 0.1)";
|
||||
$datasets[] = $record;
|
||||
}
|
||||
|
||||
$data = new stdClass();
|
||||
@ -282,8 +273,6 @@ class AbstractReport
|
||||
$labels = [];
|
||||
$totals = [];
|
||||
|
||||
$color = '51,122,183';
|
||||
|
||||
foreach ($this->chartData as $dimension => $data) {
|
||||
foreach ($data as $date => $value) {
|
||||
if (! isset($totals[$dimension])) {
|
||||
@ -306,8 +295,10 @@ class AbstractReport
|
||||
$datasets->data[] = $value;
|
||||
$datasets->lineTension = 0;
|
||||
$datasets->borderWidth = 3;
|
||||
$datasets->borderColor = "rgba({$color}, 1)";
|
||||
$datasets->backgroundColor = "rgba({$color}, 0.1)";
|
||||
|
||||
$color = count($totals) ? Utils::brewerColorRGB(count($response->labels)) : '51,122,183';
|
||||
$datasets->borderColor[] = "rgba({$color}, 1)";
|
||||
$datasets->backgroundColor[] = "rgba({$color}, 0.1)";
|
||||
}
|
||||
|
||||
$response->datasets = [$datasets];
|
||||
|
Loading…
x
Reference in New Issue
Block a user