From 72ee9ec227651150f5f4529dcf5d91fce0af7416 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 24 Jan 2024 02:25:56 +0200 Subject: [PATCH] add height calculation modes, month by default --- src/Calendar/Month.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Calendar/Month.php b/src/Calendar/Month.php index fa19207..2ae837e 100644 --- a/src/Calendar/Month.php +++ b/src/Calendar/Month.php @@ -33,21 +33,24 @@ class Month ]; } - public function getNodes() : object + public function getNodes(string $height = 'month') : object { - // Calculate month totals - $total = []; + // Calculate totals + $hours = []; + $month = 0; foreach ($this->_node as $i => $day) { foreach ($day as $l => $layer) { - $total[$i][$l] = 0; + $hours[$i][$l] = 0; foreach ($layer as $data) { - $total[$i][$l] += $data['value']; + $hours[$i][$l] += $data['value']; } + + $month = $month + $hours[$i][$l]; } } @@ -66,8 +69,16 @@ class Month // Calculate column width, height, offset foreach ($layer as $j => $data) { + switch ($height) + { + case 'day': + $this->_node[$i][$l][$j]['height'] = $hours[$i][$l] ? ceil($data['value'] / $hours[$i][$l] * 100) : 0; + break; + default: + $this->_node[$i][$l][$j]['height'] = $month ? round($data['value'] * ($month / 100)) : 0; + } + $this->_node[$i][$l][$j]['width'] = $width; - $this->_node[$i][$l][$j]['height'] = $total[$i][$l] ? ceil($data['value'] / $total[$i][$l] * 100) : 0; $this->_node[$i][$l][$j]['offset'] = $width * $j; } }