TreeMap.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. namespace UCore\DcatAdmin\Metrics\Examples;
  3. use Dcat\Admin\Admin;
  4. use Dcat\Admin\Support\JavaScript;
  5. use Dcat\Admin\Widgets\Metrics\RadialBar;
  6. /**
  7. * 环形图卡片
  8. *
  9. */
  10. class TreeMap extends \Dcat\Admin\Widgets\Metrics\RadialBar
  11. {
  12. /**
  13. * @var array
  14. */
  15. protected $options = [
  16. 'icon' => null,
  17. 'title' => null,
  18. 'header' => null,
  19. 'content' => null,
  20. 'footer' => null,
  21. 'dropdown' => [],
  22. ];
  23. /**
  24. * 卡片高度.
  25. *
  26. * @var int
  27. */
  28. protected $height = 250;
  29. /**
  30. * 图表高度.
  31. *
  32. * @var int
  33. */
  34. protected $chartHeight = 210;
  35. /**
  36. * 内容宽度.
  37. *
  38. * @var array
  39. */
  40. protected $contentWidth = [ 5, 7 ];
  41. /**
  42. * 图表上间距.
  43. *
  44. * @var int
  45. */
  46. protected $chartMarginTop = -10;
  47. /**
  48. * 图表下间距.
  49. *
  50. * @var int
  51. */
  52. protected $chartMarginBottom = -20;
  53. /**
  54. * 图表默认配置.
  55. *
  56. * @return array
  57. */
  58. protected function defaultChartOptions()
  59. {
  60. return [
  61. 'chart' => [
  62. 'height' => 200,
  63. 'type' => 'treemap',
  64. ],
  65. 'legend' => [
  66. 'show' => false,
  67. ],
  68. 'plotOptions' => [
  69. 'treemap' => [
  70. 'distributed' => true,
  71. 'enableShades' => false
  72. ]
  73. ],
  74. ];
  75. }
  76. /**
  77. * 设置圆圈宽度.
  78. *
  79. * @param int $size
  80. * @return $this
  81. */
  82. public function chartRadialBarSize(int $size)
  83. {
  84. return $this->chartOption('plotOptions.radialBar.size', $size);
  85. }
  86. /**
  87. * 设置圆圈间距.
  88. *
  89. * @param int $margin
  90. * @return $this
  91. */
  92. public function chartRadialBarMargin(int $margin)
  93. {
  94. return $this->chartOption('plotOptions.radialBar.track.margin', $margin);
  95. }
  96. /**
  97. * 设置图表统计总数信息.
  98. *
  99. * @param string $label
  100. * @param int $number
  101. * @return $this
  102. */
  103. public function chartTotal(string $label, int $number)
  104. {
  105. return $this->chartOption('plotOptions.radialBar.dataLabels.total', [
  106. 'show' => true,
  107. 'label' => $label,
  108. 'formatter' => JavaScript::make("function () { return {$number}; }"),
  109. ]);
  110. }
  111. /**
  112. * 设置图表数据.
  113. *
  114. * @param array $data 键值对
  115. *
  116. * @return $this
  117. */
  118. public function withChart(array $data)
  119. {
  120. $data2=[];
  121. foreach ($data as $k=>$v){
  122. $data2[]=[
  123. 'y'=>$v,
  124. 'x'=>$k,
  125. ];
  126. }
  127. return $this->chart([
  128. 'series' => [
  129. 'data'=>$data2
  130. ],
  131. ]);
  132. }
  133. /**
  134. * 卡片内容.
  135. *
  136. * @param int $finished
  137. * @param int $pending
  138. * @param int $rejected
  139. *
  140. * @return $this
  141. */
  142. public function withContent($count, $in,$out)
  143. {
  144. return $this->content(
  145. <<<HTML
  146. <div class="col-12 d-flex flex-column flex-wrap text-center" style="max-width: 220px">
  147. <div class="chart-info d-flex justify-content-between mb-1 mt-2" >
  148. <div class="series-info d-flex align-items-center">
  149. <i class="fa fa-circle-o text-bold-700 text-primary"></i>
  150. <span class="text-bold-600 ml-50">总</span>
  151. </div>
  152. <div class="product-result">
  153. <span>{$count}</span>
  154. </div>
  155. </div>
  156. <div class="chart-info d-flex justify-content-between mb-1">
  157. <div class="series-info d-flex align-items-center">
  158. <i class="fa fa-circle-o text-bold-700 text-warning"></i>
  159. <span class="text-bold-600 ml-50">总转入</span>
  160. </div>
  161. <div class="product-result">
  162. <span>{$in}</span>
  163. </div>
  164. </div>
  165. <div class="chart-info d-flex justify-content-between mb-1">
  166. <div class="series-info d-flex align-items-center">
  167. <i class="fa fa-circle-o text-bold-700 text-danger"></i>
  168. <span class="text-bold-600 ml-50">总转出</span>
  169. </div>
  170. <div class="product-result">
  171. <span>{$out}</span>
  172. </div>
  173. </div>
  174. </div>
  175. HTML
  176. );
  177. }
  178. }