Class yii\debug\models\timeline\DataProvider
Inheritance | yii\debug\models\timeline\DataProvider » yii\data\ArrayDataProvider |
---|---|
Available since extension's version | 2.0.8 |
Source Code | https://github.com/yiisoft/yii2-debug/blob/master/src/models/timeline/DataProvider.php |
DataProvider implements a data provider based on a data array.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$panel | yii\debug\panels\TimelinePanel | yii\debug\models\timeline\DataProvider | |
$rulers | array | This property is read-only. | yii\debug\models\timeline\DataProvider |
Public Methods
Method | Description | Defined By |
---|---|---|
__construct() | DataProvider constructor. | yii\debug\models\timeline\DataProvider |
getColor() | Getting HEX color based on model duration | yii\debug\models\timeline\DataProvider |
getCssClass() | Returns item, css class | yii\debug\models\timeline\DataProvider |
getLeft() | Returns the offset left item, percentage of the total width | yii\debug\models\timeline\DataProvider |
getMemory() | ` php
[
0 => string, memory usage (MB)
1 => float, Y position (percent)
] |
yii\debug\models\timeline\DataProvider |
getRulers() | Ruler items, key milliseconds, value offset left | yii\debug\models\timeline\DataProvider |
getTime() | Returns item duration, milliseconds | yii\debug\models\timeline\DataProvider |
getWidth() | Returns item width percent of the total width | yii\debug\models\timeline\DataProvider |
Protected Methods
Method | Description | Defined By |
---|---|---|
prepareModels() | yii\debug\models\timeline\DataProvider |
Property Details
Method Details
DataProvider constructor.
public void __construct ( yii\debug\panels\TimelinePanel $panel, $config = [] ) | ||
$panel | yii\debug\panels\TimelinePanel | |
$config | array |
public function __construct(TimelinePanel $panel, $config = [])
{
$this->panel = $panel;
parent::__construct($config);
}
Getting HEX color based on model duration
public string getColor ( $model ) | ||
$model | array |
public function getColor($model)
{
$width = isset($model['css']['width']) ? $model['css']['width'] : $this->getWidth($model);
foreach ($this->panel->colors as $percent => $color) {
if ($width >= $percent) {
return $color;
}
}
return '#d6e685';
}
Returns item, css class
public string getCssClass ( $model ) | ||
$model | array |
public function getCssClass($model)
{
$class = 'time';
$class .= (($model['css']['left'] > 15) && ($model['css']['left'] + $model['css']['width'] > 50)) ? ' right' : ' left';
return $class;
}
Returns the offset left item, percentage of the total width
public float getLeft ( $model ) | ||
$model | array |
public function getLeft($model)
{
return $this->getTime($model) / ($this->panel->duration / 100);
}
`
php
[
0 => string, memory usage (MB)
1 => float, Y position (percent)
]
public array|null getMemory ( $model ) | ||
$model | array |
public function getMemory($model)
{
if (empty($model['memory'])) {
return null;
}
return [
sprintf('%.2f MB', $model['memory'] / 1048576),
$model['memory'] / ($this->panel->memory / 100)
];
}
Ruler items, key milliseconds, value offset left
public array getRulers ( $line = 10 ) | ||
$line | integer |
Number of columns |
public function getRulers($line = 10)
{
if ($line == 0) {
return [];
}
$data = [0];
$percent = ($this->panel->duration / 100);
$row = $this->panel->duration / $line;
$precision = $row > 100 ? -2 : -1;
for ($i = 1; $i < $line; $i++) {
$ms = round($i * $row, $precision);
$data[$ms] = $ms / $percent;
}
return $data;
}
Returns item duration, milliseconds
public float getTime ( $model ) | ||
$model | array |
public function getTime($model)
{
return $model['timestamp'] - $this->panel->start;
}
Returns item width percent of the total width
public float getWidth ( $model ) | ||
$model | array |
public function getWidth($model)
{
return $model['duration'] / ($this->panel->duration / 100);
}
protected void prepareModels ( ) |
protected function prepareModels()
{
if (($models = $this->allModels) === null) {
return [];
}
$child = [];
foreach ($models as $key => &$model) {
$model['timestamp'] *= 1000;
$model['duration'] *= 1000;
$model['child'] = 0;
$model['css']['width'] = $this->getWidth($model);
$model['css']['left'] = $this->getLeft($model);
$model['css']['color'] = $this->getColor($model);
foreach ($child as $id => $timestamp) {
if ($timestamp > $model['timestamp']) {
++$models[$id]['child'];
} else {
unset($child[$id]);
}
}
$child[$key] = $model['timestamp'] + $model['duration'];
}
return $models;
}