From 72d1d3941d5d2a3ad348fe14ddf04d96408231e4 Mon Sep 17 00:00:00 2001 From: MasterZydra Date: Thu, 14 Mar 2024 21:21:11 +0100 Subject: [PATCH] Added component for line chart Fixes #59 --- CHANGELOG.md | 3 + framework/registerFn.php | 9 ++- resources/Views/Components/chart/chartJs.php | 1 + resources/Views/Components/chart/line.php | 54 +++++++++++++++ .../Views/statistics/revenueAndProfit.php | 67 +++---------------- 5 files changed, 75 insertions(+), 59 deletions(-) create mode 100644 resources/Views/Components/chart/chartJs.php create mode 100644 resources/Views/Components/chart/line.php diff --git a/CHANGELOG.md b/CHANGELOG.md index ca9cf08..04ede54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Types of changes: `Added`, `Changed`, `Deprecate`, `Removed`, `Fixed`, `Secruity ## [Unreleased] +### Added +- Added component for line chart #59 + ## v2.4.0 - 11.03.2024 - Added revenue and profit statistic ### Added diff --git a/framework/registerFn.php b/framework/registerFn.php index 5d9f0da..2e54fbb 100644 --- a/framework/registerFn.php +++ b/framework/registerFn.php @@ -34,12 +34,17 @@ function view(string $name, array $data = []): void } /** Render the given component */ -function component(string $name, array $data = []): void +function component(string $name, array $data = [], bool $once = false): void { if (count($data) > 0) { extract($data); } - require Path::join(__DIR__, '..', 'resources', 'Views', 'Components', str_replace('.', '/', $name) . '.php'); + $path = Path::join(__DIR__, '..', 'resources', 'Views', 'Components', str_replace('.', '/', $name) . '.php'); + if ($once) { + require_once $path; + } else { + require $path; + } } /** Translate the given label into user language */ diff --git a/resources/Views/Components/chart/chartJs.php b/resources/Views/Components/chart/chartJs.php new file mode 100644 index 0000000..8670d73 --- /dev/null +++ b/resources/Views/Components/chart/chartJs.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/resources/Views/Components/chart/line.php b/resources/Views/Components/chart/line.php new file mode 100644 index 0000000..078fa1a --- /dev/null +++ b/resources/Views/Components/chart/line.php @@ -0,0 +1,54 @@ + 'string', 'data' => [array]] +?> + + +
+ +
+ + \ No newline at end of file diff --git a/resources/Views/statistics/revenueAndProfit.php b/resources/Views/statistics/revenueAndProfit.php index 1fdd1f7..323405c 100644 --- a/resources/Views/statistics/revenueAndProfit.php +++ b/resources/Views/statistics/revenueAndProfit.php @@ -20,62 +20,15 @@ - -
- -
- - - - + 'revenueAndProfit', + 'xTitle' => __('Year'), + 'yTitle' => __('inX', setting('currencyUnit')), + 'dataSet' => [ + ['label' => __('Revenue'), 'data' => array_map(fn(array $line): float => $line['revenue'], $data)], + ['label' => __('Payouts'), 'data' => array_map(fn(array $line): float => $line['payouts'], $data)], + ['label' => __('Profit'), 'data' => array_map(fn(array $line): float => $line['profit'], $data)], + ] +]) ?> \ No newline at end of file