Blame view

datalets/highcharts-datalet/highcharts-datalet.html 8.06 KB
5e6ba8af   isisadmin   datalet doc update
1
2
3
4
  <!--

  @license

      The MIT License (MIT)

  

b4accc86   Renato De Donato   datalet improved
5
      Copyright (c) 2015 Dipartimento di Informatica - Universit� di Salerno - Italy

5e6ba8af   isisadmin   datalet doc update
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  

      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.

  -->

  

ae17a8dc   Luigi Serra   Controllet and da...
26
  <!--

950d181d   Luigi Serra   license updates
27
28
  * Developed by :

  * ROUTE-TO-PA Project - grant No 645860. - www.routetopa.eu

ae17a8dc   Luigi Serra   Controllet and da...
29
30
31
  *

  -->

  

98d9d8a5   Renato De Donato   filters+groupby
32
  <link rel="import" href="../base-ajax-json-alasql-datalet/base-ajax-json-alasql-datalet.html">

73bcce88   luigser   COMPONENTS
33
  

5e6ba8af   isisadmin   datalet doc update
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  <!--

  The `highcharts-datalet` uses the base-ajax-json-jsonpath-datalet as data retriving and selection mechanism. It defines the common properties

  for all the highchart datalets : categories, series and series_type. Overmore override the transformData method

  to create and populate categories and series array. Every specific highchart chart implementation (eg linechart, barchart, columnchart ...)

  will use highcharts-datalet properties to create the appropriate chart.

  

  Example :

  

      <dom-module id="highcarts-chart-datalet">

          <template>

              ...

              <highcharts-datalet id="charts" data-url="{{dataUrl}}" fields="{{fields}}"></highcharts-datalet>

              ...

          </template>

      </dom-module>

  

  @element highcharts-datalet

  @status v0.1

  @homepage

  @group datalets

  -->

  

73bcce88   luigser   COMPONENTS
56
  <dom-module id="highcharts-datalet">

a1f0799c   isisadmin   datalet global re...
57
  

73bcce88   luigser   COMPONENTS
58
59
      <template>

          <div id="container" style="width:auto; height:auto;"></div>

98d9d8a5   Renato De Donato   filters+groupby
60
          <base-ajax-json-alasql-datalet data-url="{{dataUrl}}" fields="{{fields}}" data="{{data}}" title="{{title}}" description="{{description}}"></base-ajax-json-alasql-datalet>

73bcce88   luigser   COMPONENTS
61
      </template>

a1f0799c   isisadmin   datalet global re...
62
  

5e6ba8af   isisadmin   datalet doc update
63
64
      <script src="static/js/highcharts.js"></script>

      <script src="static/js/exporting.js"></script>

9819a403   Renato De Donato   bubble scatter tr...
65
      <script src="static/js/highcharts-more.js"></script>

fb05b400   Renato De Donato   controllet 2.0, n...
66
      <script src="static/themes/themes.js"></script>

a1f0799c   isisadmin   datalet global re...
67
  

73bcce88   luigser   COMPONENTS
68
69
      <script>

          var HighchartsBehavior = {

a1f0799c   isisadmin   datalet global re...
70
  

73bcce88   luigser   COMPONENTS
71
              properties: {

a1f0799c   isisadmin   datalet global re...
72
  

73bcce88   luigser   COMPONENTS
73
74
75
76
                  categories: {

                      type: Array,

                      value: []

                  },

a1f0799c   isisadmin   datalet global re...
77
  

73bcce88   luigser   COMPONENTS
78
79
80
81
                  series: {

                      type: Array,

                      value: []

                  },

a1f0799c   isisadmin   datalet global re...
82
  

fb05b400   Renato De Donato   controllet 2.0, n...
83
84
85
86
  //                series_type:{

  //                    type: String,

  //                    value: "line"//spline,time

  //                }

8afca675   Renato De Donato   title-description
87
  

73bcce88   luigser   COMPONENTS
88
              },

584d6ecd   Luigi Serra   Update components...
89
90
91
              /**

               * Normalizes a number in agreement with javascript's conventions. Delete all NaN characters. Exception: number representing lat & long remain unchanged.

               */

fb05b400   Renato De Donato   controllet 2.0, n...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  //            jNumConverter: function(num) {

  //                //lat-long

  //                if(num.charAt(num.length-7) == "." && (num.match(/[\.,]/g) || []).length == 1)

  //                    return num;

  //

  //                num = num.replace(/[^0-9\.]/, '');

  //

  //                var jNum = "";

  //                for (var i = 0; i < num.length; i++) {

  //                    if(num[i].match(/[\.,]/g))

  //                        if (i == num.length - 3)

  //                            jNum += ".";

  //                        else

  //                            ;

  //                    else if (!isNaN(num[i]))

  //                        jNum += num[i];

  //                }

  //

  //                return jNum;

  //            },

5e6ba8af   isisadmin   datalet doc update
112
113
114
115
116
117
118
              /**

               * Populate the categories and the series array.

               *

               * @method transformData

               *

               * @param {Event} e

               */

fb05b400   Renato De Donato   controllet 2.0, n...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  //            transformData: function () {

  //

  //                if(this.data.length == 0) return;

  //

  //                this.properties.categories.value = this.data[0].data;

  //

  //                for (var i = 1; i < this.data.length; i++)

  //                {

  //                    this.data[i].data.every(function (element, index, array) {

  //                        try {

  //                            var e = HighchartsBehavior.jNumConverter(element);

  //                            (isNaN(element)) ? array[index] = parseFloat(HighchartsBehavior.jNumConverter(element)) :

  //                                    array[index] = parseFloat(element);

  //                        }catch(e){

  //                            //console.log("Parsing data error. Highchart-datalet.selectData");

  //                        }

  //                        return true;

  //                    });

  //

  //                    this.properties.series.value.push(this.data[i]);

  //                }

  //            },

a1f0799c   isisadmin   datalet global re...
141
  

fb05b400   Renato De Donato   controllet 2.0, n...
142
143
144
              transformData: function () {

                  if(this.data.length == 0)

                      return;

a1f0799c   isisadmin   datalet global re...
145
  

fb05b400   Renato De Donato   controllet 2.0, n...
146
147
148
                  if(this.data.length == 2){

                      this.properties.categories.value = this.data[0].data;

                      this.properties.series.value = [this.data[1]];

73bcce88   luigser   COMPONENTS
149
                  }

0b7cbd33   Renato De Donato   title-desciption
150
  

fb05b400   Renato De Donato   controllet 2.0, n...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
                  if(this.data.length == 3){//multi series

                      var x = this.data[0]["data"];

                      var gb = this.data[1]["data"];

                      var y = this.data[2]["data"];

  

                      var categories = x.filter(function(item, pos) {

                          return x.indexOf(item) == pos;

                      })

  

                      var s = gb.filter(function(item, pos) {

                          return gb.indexOf(item) == pos;

                      })

  

                      var series = [];

                      for(var i = 0; i < s.length; i++) {

                          series.push({name: s[i], data: new Array(categories.length+1).join('0').split('').map(parseFloat)});

                      }

  

                      for (var i = 0; i < y.length; i++){

                          var index = categories.indexOf(x[i]);

                          var s = series.filter(function( obj ) {

                              return obj.name == gb[i];

                          });

                         s[0]["data"][index] = y[i];

                      }

  

                      this.properties.categories.value = categories;

                      this.properties.series.value = series;

b4accc86   Renato De Donato   datalet improved
179
                  }

fb05b400   Renato De Donato   controllet 2.0, n...
180
              },

b4accc86   Renato De Donato   datalet improved
181
  

fb05b400   Renato De Donato   controllet 2.0, n...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
  //            setParameters: function(params)

  //            {

  //                this._component.title = params['title'];

  //                this._component.description = params['description'];

  //

  //                var chart = $(this._component.$.charts.$.container).highcharts();

  //

  //                chart.setTitle({text: params['title']});

  //                chart.xAxis[0].setTitle({text: params['x-axis-label']});

  //                chart.yAxis[0].setTitle({text: params['y-axis-label']});

  //

  //                chart.tooltip.options.formatter = function() {

  //                    return this.x + '<br/><br/><span style="fill:#7cb5ec" x="8" dy="15"></span> ' + this.series.name + ': <b>' + this.y + ' ' + params['suffix'] + '</b>';

  //                }

  //

  //                //theme default

  //                Highcharts.setOptions(Highcharts[params['theme']]);

  //

  //                this._component.stack = params['stack'];

  //            }

8afca675   Renato De Donato   title-description
202
  

73bcce88   luigser   COMPONENTS
203
204
          };

  

98d9d8a5   Renato De Donato   filters+groupby
205
          var HighchartsComponentBehavior = $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonAlasqlBehavior, HighchartsBehavior);

73bcce88   luigser   COMPONENTS
206
207
208
209
210
211
212
  

          HighchartsDatalet = Polymer({

              is : 'highcharts-datalet'

          });

      </script>

  

  </dom-module>