You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
2.7 KiB
118 lines
2.7 KiB
<?php
|
|
|
|
namespace App\Admin\Actions\Metrics;
|
|
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Widgets\Metrics\Donut;
|
|
|
|
class Market extends Donut
|
|
{
|
|
protected $labels = ['东沟岭市场', '铜鼓岭市场', '华园菜市', '平西市场'];
|
|
protected $market;
|
|
|
|
public function __construct($market)
|
|
{
|
|
|
|
$this->market = $market;
|
|
parent::__construct($title = null, $icon = null);
|
|
}
|
|
|
|
public function init()
|
|
{
|
|
parent::init(); // TODO: Change the autogenerated stub
|
|
$color = Admin::color();
|
|
$colors = [$color->primary(), $color->alpha('blue2', 0.5),$color->warning(),'rebeccapurple'];
|
|
//$this->title('<small>配送数据</small>');
|
|
$this->height = 153;
|
|
$this->chartLabels($this->labels);
|
|
// 设置图表颜色
|
|
$this->chartColors($colors);
|
|
}
|
|
|
|
/**
|
|
* 渲染模板
|
|
*
|
|
* @return string
|
|
*/
|
|
public function render()
|
|
{
|
|
$this->fill();
|
|
return parent::render(); // TODO: Change the autogenerated stub
|
|
}
|
|
|
|
/**
|
|
* 写入数据.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function fill()
|
|
{
|
|
$total = array_sum($this->market);
|
|
|
|
// 图表数据
|
|
|
|
$this->withChart($this->market);
|
|
|
|
$this->withContent($this->market[0], $this->market[1], $this->market[2], $this->market[3]);
|
|
}
|
|
|
|
/**
|
|
* 设置图表数据.
|
|
*
|
|
* @param array $data
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function withChart(array $data)
|
|
{
|
|
return $this->chart([
|
|
'series' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 设置卡片头部内容.
|
|
*
|
|
* @param mixed $desktop
|
|
* @param mixed $mobile
|
|
*
|
|
* @return $this
|
|
*/
|
|
protected function withContent($s1, $s2, $s3, $s4)
|
|
{
|
|
$blue = Admin::color()->alpha('blue2', 0.5);
|
|
|
|
$style = 'margin-bottom: 8px';
|
|
$labelWidth = 120;
|
|
|
|
return $this->content(
|
|
<<<HTML
|
|
<div class="d-flex pl-1 pr-1 " style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle text-primary"></i> {$this->labels[0]}
|
|
</div>
|
|
<div>{$s1}</div>
|
|
</div>
|
|
<div class="d-flex pl-1 pr-1" style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle" style="color: $blue"></i> {$this->labels[1]}
|
|
</div>
|
|
<div>{$s2}</div>
|
|
</div>
|
|
|
|
<div class="d-flex pl-1 pr-1 " style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle text-warning"></i> {$this->labels[2]}
|
|
</div>
|
|
<div>{$s3}</div>
|
|
</div>
|
|
<div class="d-flex pl-1 pr-1" style="{$style}">
|
|
<div style="width: {$labelWidth}px">
|
|
<i class="fa fa-circle" style="color: rebeccapurple"></i> {$this->labels[3]}
|
|
</div>
|
|
<div>{$s4}</div>
|
|
</div>
|
|
HTML
|
|
);
|
|
}
|
|
}
|