-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add donut graphs to deployments, replica sets, daemon sets and stateful
sets
- Loading branch information
Showing
6 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
/* Icinga Kubernetes Web | (c) 2023 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Icinga\Module\Kubernetes; | ||
|
||
use ipl\Html\BaseHtmlElement; | ||
use ipl\Html\Html; | ||
use ipl\Html\HtmlString; | ||
use ipl\Html\Table; | ||
|
||
class Donut extends BaseHtmlElement | ||
{ | ||
protected $tag = 'section'; | ||
|
||
protected $defaultAttributes = ['class' => 'donut']; | ||
|
||
/** | ||
* The donut data | ||
* | ||
* @var iterable | ||
*/ | ||
protected $data = []; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $heading; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected $headingLevel = 2; | ||
|
||
/** | ||
* @var callable | ||
*/ | ||
protected $labelCallback; | ||
|
||
/** | ||
* Set the data to display | ||
* | ||
* @param iterable $data | ||
* | ||
* @return $this | ||
*/ | ||
public function setData(iterable $data) | ||
{ | ||
$this->data = $data; | ||
|
||
return $this; | ||
} | ||
|
||
public function setHeading(string $heading, int $level) | ||
{ | ||
$this->heading = $heading; | ||
$this->headingLevel = $level; | ||
|
||
return $this; | ||
} | ||
|
||
public function setLabelCallback(callable $callback) | ||
{ | ||
$this->labelCallback = $callback; | ||
|
||
return $this; | ||
} | ||
|
||
public function assemble() | ||
{ | ||
$donut = new \Icinga\Chart\Donut(); | ||
$legend = new Table(); | ||
|
||
foreach ($this->data as $index => $value) { | ||
$donut->addSlice((int) $value, ['class' => 'segment-' . $index]); | ||
$legend->add( | ||
[ | ||
Html::tag('span', ['class' => 'badge badge-' . $index]), | ||
call_user_func($this->labelCallback, $index), | ||
$value | ||
] | ||
); | ||
} | ||
|
||
if ($this->heading === null) { | ||
$this->addHtml(Html::tag("h{$this->headingLevel}", $this->heading), new HtmlString($donut->render()), $legend); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters