Class yii\debug\models\timeline\Svg
Inheritance | yii\debug\models\timeline\Svg » yii\base\BaseObject |
---|---|
Available since extension's version | 2.0.8 |
Source Code | https://github.com/yiisoft/yii2-debug/blob/master/src/models/timeline/Svg.php |
Svg is used to draw a graph using SVG
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$gradient | array | Color indicators svg graph. | yii\debug\models\timeline\Svg |
$listenMessages | array | Listen messages panels | yii\debug\models\timeline\Svg |
$panel | yii\debug\panels\TimelinePanel | yii\debug\models\timeline\Svg | |
$points | array | Each point is define by a X and a Y coordinate. | yii\debug\models\timeline\Svg |
$stroke | string | Stroke color | yii\debug\models\timeline\Svg |
$template | string | Svg template | yii\debug\models\timeline\Svg |
$x | integer | Max X coordinate | yii\debug\models\timeline\Svg |
$y | integer | Max Y coordinate | yii\debug\models\timeline\Svg |
Public Methods
Method | Description | Defined By |
---|---|---|
__construct() | yii\debug\models\timeline\Svg | |
__toString() | yii\debug\models\timeline\Svg | |
hasPoints() | yii\debug\models\timeline\Svg |
Protected Methods
Method | Description | Defined By |
---|---|---|
addPoints() | yii\debug\models\timeline\Svg | |
linearGradient() | yii\debug\models\timeline\Svg | |
polygon() | yii\debug\models\timeline\Svg | |
polyline() | yii\debug\models\timeline\Svg |
Property Details
Color indicators svg graph.
Listen messages panels
Each point is define by a X and a Y coordinate.
Svg template
public string $template = '<svg xmlns="http://www.w3.org/2000/svg" width="{x}" height="{y}" viewBox="0 0 {x} {y}" preserveAspectRatio="none"><defs>{linearGradient}</defs><g><polygon points="{polygon}" fill="url(#gradient)"/><polyline points="{polyline}" fill="none" stroke="{stroke}" stroke-width="1"/></g></svg>'
Method Details
public void __construct ( yii\debug\panels\TimelinePanel $panel, $config = [] ) | ||
$panel | ||
$config |
public function __construct(TimelinePanel $panel, $config = [])
{
parent::__construct($config);
$this->panel = $panel;
foreach ($this->listenMessages as $panel) {
if (isset($this->panel->module->panels[$panel]->data['messages'])) {
$this->addPoints($this->panel->module->panels[$panel]->data['messages']);
}
}
}
public string __toString ( ) |
public function __toString()
{
if ($this->points === []) {
return '';
}
return strtr($this->template, [
'{x}' => StringHelper::normalizeNumber($this->x),
'{y}' => StringHelper::normalizeNumber($this->y),
'{stroke}' => $this->stroke,
'{polygon}' => $this->polygon(),
'{polyline}' => $this->polyline(),
'{linearGradient}' => $this->linearGradient()
]);
}
protected integer addPoints ( $messages ) | ||
$messages | array |
Log messages. See Logger::messages for the structure |
return | integer |
Added points |
---|
protected function addPoints($messages)
{
$hasPoints = $this->hasPoints();
$memory = $this->panel->memory / 100; // 1 percent memory
$yOne = $this->y / 100; // 1 percent Y coordinate
$xOne = $this->panel->duration / $this->x; // 1 percent X coordinate
$i = 0;
foreach ($messages as $message) {
if (empty($message[5])) {
break;
}
++$i;
$this->points[] = [
($message[3] * 1000 - $this->panel->start) / $xOne,
$this->y - ($message[5] / $memory * $yOne),
];
}
if ($hasPoints && $i) {
usort($this->points, function ($a, $b) {
return ($a[0] < $b[0]) ? -1 : 1;
});
}
return $i;
}
public boolean hasPoints ( ) | ||
return | boolean |
Has points |
---|
public function hasPoints()
{
return ($this->points !== []);
}
protected string linearGradient ( ) |
protected function linearGradient()
{
$gradient = '<linearGradient id="gradient" x1="0" x2="0" y1="1" y2="0">';
foreach ($this->gradient as $percent => $color) {
$gradient .= '<stop offset="' . StringHelper::normalizeNumber($percent) . '%" stop-color="' . $color . '"></stop>';
}
return $gradient . '</linearGradient>';
}
protected string polygon ( ) | ||
return | string |
Points attribute for polygon path |
---|
protected function polygon()
{
$str = "0 $this->y ";
foreach ($this->points as $point) {
list($x, $y) = $point;
$str .= "{$x} {$y} ";
}
$str .= $this->x - 0.001 . " {$y} {$this->x} {$this->y}";
return StringHelper::normalizeNumber($str);
}