tao.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. class screenTao extends screenModel
  3. {
  4. /**
  5. * 设置默认的图表配置。
  6. * Set the default chart config.
  7. *
  8. * @param string $type
  9. * @param object $component
  10. * @return bool
  11. */
  12. protected function setChartDefault($type, $component)
  13. {
  14. if(!isset($this->config->screen->chart->default->{$type})) return false;
  15. $chartConfig = $this->config->screen->chart->default->{$type};
  16. foreach(get_object_vars($chartConfig) as $key => $value) $component->{$key} = $value;
  17. return true;
  18. }
  19. /**
  20. * 处理雷达图表的数据。
  21. * Set the chart data.
  22. *
  23. * @param string $sql
  24. * @param object $settings
  25. * @param array $indicator
  26. * @param array $seriesData
  27. * @return void
  28. */
  29. protected function processRadarData($sql, $settings, &$indicator, &$seriesData)
  30. {
  31. $results = $this->dao->query($sql)->fetchAll();
  32. $group = $settings->group[0]->field;
  33. /* 通过配置获取指标。 */
  34. /* Get the metric by the setting. */
  35. $metrics = array();
  36. foreach($settings->metric as $metric) $metrics[$metric->key] = array('field' => $metric->field, 'name' => $metric->name, 'value' => 0);
  37. /* 计算指标的值。 */
  38. /* Calculate the value of the metric. */
  39. foreach($results as $result)
  40. {
  41. if(isset($metrics[$result->$group]))
  42. {
  43. $field = $metrics[$result->$group]['field'];
  44. $metrics[$result->$group]['value'] += $result->$field;
  45. }
  46. }
  47. $max = 0;
  48. foreach($metrics as $data) $max = $data['value'] > $max ? $data['value'] : $max;
  49. /* 设置指标和数据。 */
  50. /* Set the indicator and data. */
  51. $data = array('name' => '', 'value' => array());
  52. $value = array();
  53. foreach($metrics as $metric)
  54. {
  55. $indicator[] = array('name' => $metric['name'], 'max' => $max);
  56. $data['value'][] = $metric['value'];
  57. $value[] = $metric['value'];
  58. }
  59. $seriesData[] = $data;
  60. return $value;
  61. }
  62. }