HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
TbHighCharts.php
Go to the documentation of this file.
1 <?php
39 class TbHighCharts extends CWidget
40 {
44  public $options = array();
45 
49  public $htmlOptions = array();
50 
54  public function run()
55  {
56  $id = $this->getId();
57 
58  // if there is no renderTo id, build the layer with current id and initialize renderTo option
59  if (!isset($this->options['chart']) || !isset($this->options['chart']['renderTo'])) {
60  $this->htmlOptions['id'] = $id;
61  echo '<div ' . CHtml::renderAttributes($this->htmlOptions) . ' ></div>';
62 
63  if (isset($this->options['chart']) && is_array($this->options['chart'])) {
64  $this->options['chart']['renderTo'] = $id;
65  } else {
66  $this->options['chart'] = array('renderTo' => $id);
67  }
68  }
69  $this->registerClientScript();
70  }
71 
75  protected function registerClientScript()
76  {
77  $assets = Booster::getBooster()->cs;
78 
79  $assets->registerPackage('highcharts');
80 
81  $baseUrl = $assets->packages['highcharts']['baseUrl'];
82 
83  $this->options = CMap::mergeArray(array('exporting' => array('enabled' => true)), $this->options);
84 
85  if (isset($this->options['exporting']) && @$this->options['exporting']['enabled']) {
86  $assets->registerScriptFile($baseUrl . '/modules/exporting.js');
87  }
88  if (isset($this->options['theme'])) {
89  $assets->registerScriptFile($baseUrl . '/themes/' . $this->options['theme'] . '.js');
90  }
91 
92  $options = CJavaScript::encode($this->options);
93 
94  $assets->registerScript(
95  __CLASS__ . '#' . $this->getId(),
96  "var highchart{$this->getId()} = new Highcharts.Chart({$options});"
97  );
98  }
99 }