Blame view

datalets/google_piechart-datalet/google_piechart-datalet.html 5.6 KB
331a2265   Renato De Donato   google-chart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  <!--
  @license
      The MIT License (MIT)
  
      Copyright (c) 2015 Dipartimento di Informatica - Universit� di Salerno - Italy
  
      Permission is hereby granted, free of charge, to any person obtaining a copy
      of this software and associated documentation files (the "Software"), to deal
      in the Software without restriction, including without limitation the rights
      to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      copies of the Software, and to permit persons to whom the Software is
      furnished to do so, subject to the following conditions:
  
      The above copyright notice and this permission notice shall be included in
      all copies or substantial portions of the Software.
  
      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      THE SOFTWARE.
  -->
  
  <!--
  * Developed by :
  * ROUTE-TO-PA Project - grant No 645860. - www.routetopa.eu
  *
  -->
  <link rel="import" href="../../bower_components/polymer/polymer.html">
  
  <link rel="import" href="../base-ajax-json-jsonpath-datalet/base-ajax-json-jsonpath-datalet.html">
  
  <link rel="import" href="../../bower_components/google-chart/google-chart.html"/>
  
  <dom-module id="google_piechart-datalet">
  
      <template>
  
          <style is="custom-style">
              #google_piechart{
                  height: 100%;
                  width: 100%;
              }
          </style>
  
          <google-chart
                  id='google_piechart'
                  type='pie'
                  cols={{cols}}
                  rows={{rows}}
                  options={{options}}>
          </google-chart>
  
498cdf34   Andrea Petta   leafletjs
56
          <base-ajax-json-jsonpath-datalet data-url="{{dataUrl}}" fields="{{fields}}" data="{{data}}"  export_menu="{{export_menu}}"></base-ajax-json-jsonpath-datalet>
331a2265   Renato De Donato   google-chart
57
58
59
60
61
62
63
64
  
      </template>
  
      <script>
  
          var GooglePiechartBehavior = {
  
              presentData : function(){
97e0b0f8   Renato De Donato   google chart & lo...
65
66
                  if(!this._dataIsValid())
                      return;
331a2265   Renato De Donato   google-chart
67
  
97e0b0f8   Renato De Donato   google chart & lo...
68
                  var cols = [{"label": this.data[0].name, "type": typeof this.data[0].data[0]}, {"label": this.data[1].name, "type": typeof this.data[1].data[0]}];
331a2265   Renato De Donato   google-chart
69
70
71
72
73
74
75
                  var rows = [];
                  for(var i=0; i<this.data[0].data.length; i++)
                  {
                      var row = [this.data[0].data[i], this.data[1].data[i]];
                      rows.push(row);
                  }
  
97e0b0f8   Renato De Donato   google chart & lo...
76
                  this._updateOptions();
331a2265   Renato De Donato   google-chart
77
78
79
  
                  this._component.cols = cols;
                  this._component.rows = rows;
331a2265   Renato De Donato   google-chart
80
81
82
              },
  
              _updateOptions : function(){
97e0b0f8   Renato De Donato   google chart & lo...
83
84
85
86
87
88
89
90
91
                  if(!this._dataIsValid())
                      return;
  
                  var options = this._component.options;
  
                  options["title"] = this._component._title;
                  options["pieHole"] = this._component.pieHole;
                  options["is3D"] = this._component.is3D;
  
331a2265   Renato De Donato   google-chart
92
93
                  this._component.options = options;
                  this._component.$.google_piechart.drawChart();
97e0b0f8   Renato De Donato   google chart & lo...
94
95
96
97
98
99
              },
  
              _dataIsValid : function(){
                  if(!this.data[0] || !this.data[1] || typeof this.data[1].data[0] != "number")
                      return false;
                  return true;
331a2265   Renato De Donato   google-chart
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
              }
  
          };
  
  
          PiechartDatalet = Polymer({
              is: 'google_piechart-datalet',
  
              properties: {
  
                  behavior : {
                      type : Object,
                      value : undefined
                  },
  
                  //inputs
  
                  cols: {
                      type: Array,
                      value:undefined
                  },
  
                  rows: {
                      type: Array,
                      value: undefined
                  },
  
                  //options
  
                  options: {
                      type: Object,
97e0b0f8   Renato De Donato   google chart & lo...
131
                      value: {"sliceVisibilityThreshold": .03}
331a2265   Renato De Donato   google-chart
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
                  },
  
                  _title: {//_?
                      type: String,
                      value: ""
                  },
  
                  is3D: {
                      type: Boolean,
                      value: false
                  },
  
                  pieHole: {
                      type: Number,
                      value: 0
498cdf34   Andrea Petta   leafletjs
147
148
149
150
151
152
153
154
155
156
157
158
                  },
                  /**
                   * Control the export menu
                   * xxxx BITMASK. FROM RIGHT : HTML, PNG, RTF, MY SPACE (eg. 1111 show all, 0000 hide all)
                   *
                   * @attribute export_menu
                   * @type Number
                   * @default 15
                   */
                  export_menu : {
                      type  : Number,
                      value : 15 // xxxx BITMASK. FROM RIGHT : HTML, PNG, RTF, MY SPACE (eg. 1111 show all, 0000 hide all)
331a2265   Renato De Donato   google-chart
159
                  }
97e0b0f8   Renato De Donato   google chart & lo...
160
  
331a2265   Renato De Donato   google-chart
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
              },
  
              observers: [
                  '_updateOptions(_title, is3D, pieHole)'
              ],
  
              ready : function(){
                  this.behavior =  $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, GooglePiechartBehavior);
                  this.async(function(){this.behavior.init(this)}, 0);
              },
  
              _updateOptions : function(){
  //                this.async(function(){this.behavior._updateOptions()}, 1000);
                  if(this.behavior)//false on ready
                      this.behavior._updateOptions();
              }
  
          });
  
      </script>
  
  </dom-module>