Added timeline iterator for automatic splitting of nested events.
This commit is contained in:
1 parent
bee765071b
commit
a9484ed4ee
4 files changed
+49
-19
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Rarst\Laps\Events;
|
||||
|
||||
class Recursive_Event_Iterator extends \RecursiveArrayIterator {
|
||||
class Recursive_Event_Iterator extends \ArrayIterator implements \RecursiveIterator {
|
||||
|
||||
protected $children = [];
|
||||
|
||||
|
||||
+8
-16
@@ -143,22 +143,10 @@ class Laps extends Container {
|
||||
$start = $timestart * 1000;
|
||||
$end = microtime( true ) * 1000;
|
||||
$total = $end - $start;
|
||||
$event_data = [];
|
||||
|
||||
foreach ( $events as $event ) {
|
||||
|
||||
$event['offset'] = round( ( $event['origin'] - $start ) / $total * 100, 2 );
|
||||
$event['width'] = round( $event['duration'] / $total * 100, 2 );
|
||||
$event_data[] = $event;
|
||||
}
|
||||
|
||||
$iterator = new Recursive_Event_Iterator( $event_data );
|
||||
$timelines = [ [ 'events' => $iterator ] ];
|
||||
|
||||
while ( $iterator->hasChildren() ) {
|
||||
$children = $iterator->getChildren();
|
||||
$timelines[] = [ 'events' => $children ];
|
||||
$iterator = $children;
|
||||
foreach ( $events as $key => $event ) {
|
||||
$events[ $key ]['offset'] = round( ( $event['origin'] - $start ) / $total * 100, 2 );
|
||||
$events[ $key ]['width'] = round( $event['duration'] / $total * 100, 2 );
|
||||
}
|
||||
|
||||
$wp_admin_bar->add_node( [
|
||||
@@ -169,7 +157,11 @@ class Laps extends Container {
|
||||
$wp_admin_bar->add_node( [
|
||||
'id' => 'laps_output',
|
||||
'parent' => 'laps',
|
||||
'meta' => [ 'html' => $this['mustache']->render( 'laps', [ 'timelines' => $timelines ] ) ],
|
||||
'meta' => [
|
||||
'html' => $this['mustache']->render( 'laps', [
|
||||
'timelines' => new Timeline_Iterator( new Recursive_Event_Iterator( $events ) ),
|
||||
] ),
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Rarst\Laps;
|
||||
|
||||
use Rarst\Laps\Events\Recursive_Event_Iterator;
|
||||
|
||||
class Timeline_Iterator implements \Iterator {
|
||||
|
||||
/** @var Recursive_Event_Iterator */
|
||||
protected $iterator;
|
||||
|
||||
/** @var Recursive_Event_Iterator */
|
||||
protected $current;
|
||||
|
||||
public function __construct( Recursive_Event_Iterator $iterator ) {
|
||||
$this->iterator = $iterator;
|
||||
}
|
||||
|
||||
public function current() {
|
||||
return $this->current;
|
||||
}
|
||||
|
||||
public function next() {
|
||||
$this->current = $this->current->getChildren();
|
||||
}
|
||||
|
||||
public function key() {
|
||||
|
||||
}
|
||||
|
||||
public function valid() {
|
||||
return (bool) count( $this->current );
|
||||
}
|
||||
|
||||
public function rewind() {
|
||||
$this->current = $this->iterator;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
{{#timelines}}
|
||||
<div class="laps-timeline">
|
||||
{{#events}}
|
||||
{{#.}}
|
||||
<div class="event event-{{category}}" data-toggle="tooltip" title="{{description}}" style="width:{{width}}%; left:{{offset}}%;">
|
||||
<span class="sr-only">{{description}}</span>
|
||||
</div>
|
||||
{{/events}}
|
||||
{{/.}}
|
||||
</div>
|
||||
{{/timelines}}
|
||||
Reference in new issue
Block a user