YiiWheels
  • Package
  • Class
  • Tree

Packages

  • None
  • yiiwheels
    • behaviors
    • widgets
    • widgets
      • ace
      • box
      • datepicker
      • daterangepicker
      • datetimepicker
      • detail
      • fileupload
      • fileuploader
      • gallery
      • google
      • grid
        • behaviors
        • operations
      • highcharts
      • maskInput
      • maskmoney
      • modal
      • multiselect
      • rangeslider
      • redactor
      • select2
      • sparklines
      • switch
      • timeago
      • timepicker
      • toggle
      • typeahead

Classes

  • WhCountOfTypeOperation
  • WhOperation
  • WhPercentOfTypeEasyPieOperation
  • WhPercentOfTypeGooglePieOperation
  • WhPercentOfTypeOperation
  • WhSumOperation
 1 <?php
 2 /**
 3  *
 4  * WhPercentOfTypeGooglePieOperation class
 5  *
 6  * Displays an chart based on jquery.easy.pie plugin
 7  *
 8  * @author Antonio Ramirez <amigo.cobos@gmail.com>
 9  * @copyright Copyright &copy; 2amigos.us 2013-
10  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
11  * @package YiiWheels.widgets.grid.operations
12  * @uses Yiistrap.widgets.WhPercentOfTypeOperation
13  */
14 Yii::import('yiiwheels.widgets.grid.operations.WhPercentOfTypeOperation');
15 
16 class WhPercentOfTypeGooglePieOperation extends WhPercentOfTypeOperation
17 {
18     /**
19      * @var string $chartCssClass the class name of the layer holding the chart
20      */
21     public $chartCssClass = 'bootstrap-operation-google-pie-chart';
22 
23     /**
24      * The options
25      * @var array $chartOptions
26      * @see https://google-developers.appspot.com/chart/interactive/docs/gallery/piechart
27      */
28     public $chartOptions = array(
29         'title' => 'Google Pie Chart'
30     );
31 
32     /**
33      * @var array $data the configuration data of the chart
34      */
35     protected $data = array();
36 
37     /**
38      * @see TbOperation
39      * @return mixed|void
40      */
41     public function displaySummary()
42     {
43         $this->data[] = array('Label', 'Percent');
44 
45         foreach ($this->types as $type) {
46             if (!isset($type['value'])) {
47                 $type['value'] = 0;
48             }
49 
50             $this->data[] = $this->getTotal() ? array(
51                 $type['label'],
52                 (float)number_format(($type['value'] / $this->getTotal()) * 100, 1)
53             ) : 0;
54         }
55         $data = CJavaScript::jsonEncode($this->data);
56         $options = CJavaScript::jsonEncode($this->chartOptions);
57         echo "<div id='{$this->id}' class='{$this->chartCssClass}' data-data='{$data}' data-options='{$options}'></div>";
58 
59         $this->registerClientScript();
60     }
61 
62     /**
63      * Registers required scripts
64      * @see WhVisualizationChart
65      */
66     public function registerClientScript()
67     {
68         // Run chart
69         $chart = Yii::createComponent(
70             array(
71                 'class' => 'yiiwheels.widgets.google.WhVisualizationChart',
72                 'visualization' => 'PieChart',
73                 'containerId' => $this->getId(),
74                 'data' => $this->data,
75                 'options' => $this->chartOptions
76             )
77         );
78         $chart->init();
79         $chart->run();
80 
81         // create custom chart update by using the global chart variable
82         $this->column->grid->componentsAfterAjaxUpdate[__CLASS__] =
83             'var $el = $("#' . $this->getId() . '");var data = $el.data("data");var opts = $el.data("options");
84             data = google.visualization.arrayToDataTable(data);
85             ' . $chart->getId() . '=new google.visualization.PieChart(document.getElementById("' . $this->getId() . '"));
86             ' . $chart->getId() . '.draw(data,opts);';
87     }
88 
89 }
90 
YiiWheels API documentation generated by ApiGen 2.8.0