mirror of
https://github.com/YGGverse/graph-php.git
synced 2026-04-01 18:15:30 +00:00
Compare commits
No commits in common. "main" and "0.1.1" have entirely different histories.
3 changed files with 10 additions and 12 deletions
|
|
@ -7,12 +7,11 @@ Build calendar graphs with unlimited chart layers
|
||||||
|
|
||||||
#### [Month](https://github.com/YGGverse/graph-php/blob/main/src/Calendar/Month.php)
|
#### [Month](https://github.com/YGGverse/graph-php/blob/main/src/Calendar/Month.php)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
##### Examples
|
##### Live examples
|
||||||
|
|
||||||
* [YGGstate](https://github.com/YGGverse/YGGstate) - Yggdrasil Network Explorer
|
* [http://94.140.114.241/yggstate](http://94.140.114.241/yggstate)
|
||||||
* [HLState](https://github.com/YGGverse/HLState) - Web Monitor for Half-Life Servers
|
|
||||||
|
|
||||||
##### Usage
|
##### Usage
|
||||||
|
|
||||||
|
|
@ -59,4 +58,4 @@ To make your own implementation, play with:
|
||||||
var_dump(
|
var_dump(
|
||||||
$calendarMonth->getNodes()
|
$calendarMonth->getNodes()
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
BIN
media/calendar/example-2-layers.png
Normal file
BIN
media/calendar/example-2-layers.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
|
|
@ -35,19 +35,18 @@ class Month
|
||||||
|
|
||||||
public function getNodes() : object
|
public function getNodes() : object
|
||||||
{
|
{
|
||||||
// Calculate max value
|
// Calculate month totals
|
||||||
$max = 0;
|
$total = [];
|
||||||
|
|
||||||
foreach ($this->_node as $i => $day)
|
foreach ($this->_node as $i => $day)
|
||||||
{
|
{
|
||||||
foreach ($day as $l => $layer)
|
foreach ($day as $l => $layer)
|
||||||
{
|
{
|
||||||
|
$total[$i][$l] = 0;
|
||||||
|
|
||||||
foreach ($layer as $data)
|
foreach ($layer as $data)
|
||||||
{
|
{
|
||||||
if ($data['value'] > $max)
|
$total[$i][$l] += $data['value'];
|
||||||
{
|
|
||||||
$max = $data['value'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -67,8 +66,8 @@ class Month
|
||||||
// Calculate column width, height, offset
|
// Calculate column width, height, offset
|
||||||
foreach ($layer as $j => $data)
|
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]['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;
|
$this->_node[$i][$l][$j]['offset'] = $width * $j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue