projectdeviation.html.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * The project deviation view file of pivot module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  5. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  6. * @author Gang Liu <liugang@easycorp.ltd>
  7. * @package pivot
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. $getDeviationHtml = function(float $deviation): string
  12. {
  13. if($deviation > 0) return "<span class='up'>&uarr;</span>" . $deviation;
  14. if($deviation < 0) return "<span class='down'>&darr;</span>" . abs($deviation);
  15. return "<span class='zero'>0</span>";
  16. };
  17. $getDeviationRateHtml = function($deviationRate): string
  18. {
  19. if($deviationRate == 'n/a') return "<span class='zero'>" . $deviationRate . '</span>';
  20. if($deviationRate == 0) return "<span class='zero'>" . $deviationRate . '%</span>';
  21. if($deviationRate >= 50) return "<span class='u50'>" . $deviationRate . '%</span>';
  22. if($deviationRate >= 30) return "<span class='u30'>" . $deviationRate . '%</span>';
  23. if($deviationRate >= 10) return "<span class='u10'>" . $deviationRate . '%</span>';
  24. if($deviationRate > 0) return "<span class='u0'>" . $deviationRate . '%</span>';
  25. if($deviationRate <= -20) return "<span class='d20'>" . abs($deviationRate) . '%</span>';
  26. return "<span class='d0'>" . abs($deviationRate) . '%</span>';
  27. };
  28. $canView = hasPriv('execution', 'view');
  29. $chartData = array();
  30. foreach($executions as $execution)
  31. {
  32. $chartData['labels'][] = $execution->executionName;
  33. $chartData['data'][] = $execution->deviation;
  34. if($execution->multiple)
  35. {
  36. if($canView) $execution->executionName = html::a(helper::createLink('execution', 'view', "executionID={$execution->executionID}"), $execution->executionName);
  37. }
  38. else
  39. {
  40. $execution->executionName = $this->lang->null;
  41. }
  42. $execution->deviation = $getDeviationHtml($execution->deviation);
  43. $execution->deviationRate = $getDeviationRateHtml($execution->deviationRate);
  44. }
  45. $cols = $config->pivot->dtable->projectDeviation->fieldList;
  46. $data = new stdclass();
  47. $data->cols = $this->pivot->processDTableCols($cols);
  48. $data->array = $this->pivot->processDTableData(array_keys($cols), $executions);
  49. $generateData = function() use ($lang, $title, $cols, $data, $executions, $chartData, $begin, $end)
  50. {
  51. return array
  52. (
  53. div
  54. (
  55. setID('conditions'),
  56. setClass('flex gap-4 bg-canvas p-2'),
  57. on::change('loadProjectDeviation'),
  58. inputGroup
  59. (
  60. setClass('w-1/4'),
  61. $lang->pivot->execution . $lang->pivot->begin,
  62. datePicker(set(array('name' => 'begin', 'value' => $begin)))
  63. ),
  64. inputGroup
  65. (
  66. setClass('w-1/4'),
  67. $lang->pivot->execution . $lang->pivot->end,
  68. datePicker(set(array('name' => 'end', 'value' => $end)))
  69. )
  70. ),
  71. panel
  72. (
  73. setID('pivotPanel'),
  74. set::title($title),
  75. set::shadow(false),
  76. set::headingClass('h-14'),
  77. set::bodyClass('pt-0'),
  78. to::titleSuffix(
  79. icon
  80. (
  81. setClass('cursor-pointer'),
  82. setData(array('toggle' => 'tooltip', 'title' => $lang->pivot->deviationDesc, 'placement' => 'right', 'className' => 'text-gray border border-light', 'type' => 'white')),
  83. 'help'
  84. )
  85. ),
  86. dtable(set::striped(true), set::bordered(true), set::cols($cols), set::data($executions), set::emptyTip($lang->error->noData)),
  87. div
  88. (
  89. setID('exportData'),
  90. setClass('hidden'),
  91. rawContent(),
  92. html($this->pivot->buildPivotTable($data, array()))
  93. )
  94. ),
  95. panel
  96. (
  97. setID('pivotChart'),
  98. set::title($lang->pivot->deviationChart),
  99. set::shadow(false),
  100. $chartData ? null : setClass('hidden'),
  101. $chartData ? echarts
  102. (
  103. set::width('100%'),
  104. set::height(300),
  105. set::xAxis
  106. (
  107. array
  108. (
  109. 'type' => 'category',
  110. 'boundaryGap' => false,
  111. 'axisLine' => array('onZero' => false),
  112. 'axisLabel' => array('interval' => 0),
  113. 'splitLine' => array('show' => true, 'interval' => 0),
  114. 'data' => $chartData['labels']
  115. )
  116. ),
  117. set::yAxis
  118. (
  119. array
  120. (
  121. 'type' => 'value',
  122. 'axisLine' => array('show' => true)
  123. )
  124. ),
  125. set::tooltip
  126. (
  127. array
  128. (
  129. 'trigger' => 'axis',
  130. 'formatter' => '{b}: {c}h'
  131. )
  132. ),
  133. set::series
  134. (
  135. array
  136. (
  137. array
  138. (
  139. 'data' => $chartData['data'],
  140. 'type' => 'line',
  141. 'lineStyle' => array('color' => '#0033CC')
  142. )
  143. )
  144. )
  145. ) : null
  146. )
  147. );
  148. };