Skip to content

Commit

Permalink
add height calculation modes, month by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost committed Jan 24, 2024
1 parent cdc2217 commit 72ee9ec
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Calendar/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ public function addNode(int $day, int $value, string $label = null, string $clas
];
}

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];
}
}

Expand All @@ -66,8 +69,16 @@ public function getNodes() : object
// 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;
}
}
Expand Down

0 comments on commit 72ee9ec

Please sign in to comment.