150 lines
3.7 KiB
PHP
150 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace view\history\details;
|
|
|
|
use \generic\core\i_view;
|
|
use \api\core\Request;
|
|
use \error\core\Err;
|
|
|
|
|
|
class main extends i_view{
|
|
|
|
public $id_history;
|
|
private $timeline = [];
|
|
|
|
|
|
/* (1) Constructor
|
|
*
|
|
* @id_history<id> UID of the history entry
|
|
*
|
|
---------------------------------------------------------*/
|
|
public function __construct($id_history){
|
|
/* (1) Set attributes
|
|
---------------------------------------------------------*/
|
|
$this->id_history = $id_history;
|
|
|
|
/* (2) Get machine timeline
|
|
---------------------------------------------------------*/
|
|
/* (1) Request */
|
|
$mac_req = new Request('historyDefault/get_timeline', [ 'id_entry' => $this->id_history ]);
|
|
|
|
/* (2) Get response */
|
|
$mac_res = $mac_req->dispatch();
|
|
|
|
/* (3) On success, store timeline data */
|
|
if( $mac_res->error->get() == Err::Success )
|
|
$this->timeline = $mac_res->get('timeline');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (2) Format timeline data to svg render
|
|
*
|
|
* @timeline<array> Timeline data
|
|
*
|
|
* @return svg<String> SVG raw render
|
|
*
|
|
---------------------------------------------------------*/
|
|
public function svg(){
|
|
|
|
/* (1) Initialize variables
|
|
---------------------------------------------------------*/
|
|
/* (1) Set date() timezone */
|
|
date_default_timezone_set('Europe/Paris');
|
|
|
|
/* (2) Init. result raw svg */
|
|
$RAW = '';
|
|
|
|
/* (3) Set global range */
|
|
$c = 0;
|
|
$cl = count($this->timeline);
|
|
|
|
/* (4) Create ranges of size 15 */
|
|
$r_size = 10;
|
|
$rl = round( $cl / $r_size );
|
|
$y_range_diff = 100;
|
|
$total_height = $y_range_diff*$rl;
|
|
|
|
|
|
/* (1) Svg tag */
|
|
$RAW .= "<svg width='1000' height='$total_height' viewBox='0 0 1000 $total_height'>";
|
|
|
|
/* (2) Start CIRCLE */
|
|
$RAW .= "<circle cx='50' cy='50' r='6' fill='#edf0f5'/>";
|
|
$RAW .= "<circle cx='50' cy='50' r='4' fill='#555'/>";
|
|
|
|
|
|
for( $r = 0 ; $r < $rl ; $r++ ){
|
|
|
|
$y = $y_range_diff*$r + 50;
|
|
|
|
/* (2) Build barebone
|
|
---------------------------------------------------------*/
|
|
/* (1) Timeline LINE */
|
|
$RAW .= "<path d='m50 $y L900 $y' style='stroke-dasharray: 3px;' stroke='#444'/>";
|
|
|
|
|
|
/* (3) Build each action
|
|
---------------------------------------------------------*/
|
|
for( $c = 0 ; $c < $r_size ; $c++ ){
|
|
|
|
// exit if no more entry
|
|
if( !isset($this->timeline[$r*$r_size+$c]) )
|
|
break;
|
|
|
|
$entry = $this->timeline[$r*$r_size+$c];
|
|
|
|
$action_class = strtolower($entry['action_name']);
|
|
$icon_uri = '/src/static/timeline/'.$action_class.'@'.$this->get_action_color($action_class).'.svg';
|
|
$x_offset = 100 + $c*800/$r_size;
|
|
$x_img_offset = $x_offset - 5.5;
|
|
|
|
// circle
|
|
$RAW .= "<circle cx='$x_offset' cy='$y' r='15' class='svg_$action_class op_svg'/>";
|
|
$RAW .= "<circle cx='$x_offset' cy='$y' r='12' class='svg_$action_class'/>";
|
|
|
|
// inside icon
|
|
$y_decal = $y - 5.5;
|
|
$RAW .= "<image x='$x_img_offset' y='$y_decal' width='12' height='12' xlink:href='$icon_uri'/>";
|
|
|
|
}
|
|
|
|
// exit if no more entry
|
|
if( !isset($this->timeline[$r*$r_size]) )
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
/* (4) Stop CIRCLE */
|
|
$x_offset = 100 + $c*800/$r_size;
|
|
$RAW .= "<circle cx='$x_offset' cy='$y' r='6' fill='#edf0f5'/>";
|
|
$RAW .= "<circle cx='$x_offset' cy='$y' r='4' fill='#555'/>";
|
|
|
|
/* (5) Close SVG tag */
|
|
$RAW .= "</svg>";
|
|
|
|
|
|
return $RAW;
|
|
}
|
|
|
|
|
|
|
|
private function get_action_color($action_name){
|
|
|
|
return 'ffffff';
|
|
|
|
switch($action_name){
|
|
case 'start': return '2cde8b'; break;
|
|
case 'stop': return '3a3a3a'; break;
|
|
case 'lock': return 'e04343'; break;
|
|
case 'unlock': return 'af1c1c'; break;
|
|
case 'signal': return '3258d8'; break;
|
|
case 'unsignal': return '2041ab'; break;
|
|
}
|
|
|
|
return '000000';
|
|
}
|
|
|
|
} |