diff --git a/README.md b/README.md index c0d7d0b..d554d03 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,11 @@ Build calendar graphs with unlimited chart layers #### [Month](https://github.com/YGGverse/graph-php/blob/main/src/Calendar/Month.php) -![yggverse-graph-php-example](https://github.com/YGGverse/graph-php/assets/108541346/bbac7626-1f0b-476c-b154-f8a6f2933530) +![2 layers example](https://github.com/YGGverse/graph-php/blob/main/media/calendar/example-2-layers.png?raw=true) -##### Examples +##### Live examples - * [YGGstate](https://github.com/YGGverse/YGGstate) - Yggdrasil Network Explorer - * [HLState](https://github.com/YGGverse/HLState) - Web Monitor for Half-Life Servers + * [http://94.140.114.241/yggstate](http://94.140.114.241/yggstate) ##### Usage @@ -59,4 +58,4 @@ To make your own implementation, play with: var_dump( $calendarMonth->getNodes() ); -``` +``` \ No newline at end of file diff --git a/media/calendar/example-2-layers.png b/media/calendar/example-2-layers.png new file mode 100644 index 0000000..9a5491c Binary files /dev/null and b/media/calendar/example-2-layers.png differ diff --git a/src/Calendar/Month.php b/src/Calendar/Month.php index 9a0bacf..fa19207 100644 --- a/src/Calendar/Month.php +++ b/src/Calendar/Month.php @@ -35,19 +35,18 @@ class Month public function getNodes() : object { - // Calculate max value - $max = 0; + // Calculate month totals + $total = []; foreach ($this->_node as $i => $day) { foreach ($day as $l => $layer) { + $total[$i][$l] = 0; + foreach ($layer as $data) { - if ($data['value'] > $max) - { - $max = $data['value']; - } + $total[$i][$l] += $data['value']; } } } @@ -67,8 +66,8 @@ class Month // Calculate column width, height, offset foreach ($layer as $j => $data) { - $this->_node[$i][$l][$j]['height'] = $max ? ceil($data['value'] / $max * 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; } }