Blame view

datalets/treemap-datalet/treemap-datalet.html 6.8 KB
a508f993   isisadmin   added datalet doc...
1
  <!--

5e6ba8af   isisadmin   datalet doc update
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  @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.

a508f993   isisadmin   added datalet doc...
24
25
  -->

  

ae17a8dc   Luigi Serra   Controllet and da...
26
27
28
29
30
31
32
33
34
35
  <!--

  * Created by :

  * Luigi Serra - luigser@gmail.com

  * Andrea Petta - andrpet@gmail.com

  * Donato Pirozzi - donatopirozzi@gmail.com

  *

  * Copyright (c) 2015 Dipartimento di Informatica - Università di Salerno - Italy

  *

  -->

  

a1f0799c   isisadmin   datalet global re...
36
  <link rel="import" href="../base-ajax-json-jsonpath-datalet/base-ajax-json-jsonpath-datalet.html">

73bcce88   luigser   COMPONENTS
37
  

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

  

  `treemap-datalet` is a treemap datalet based on d3js treemap project http://bl.ocks.org/mbostock/4063582

  A treemap recursively subdivides area into rectangles; the area of any node in the tree corresponds to its value.

  

  Example:

  

      <treemap-datalet

          data-url="http://ckan.routetopa.eu/api/action/datastore_search?resource_id=#"

          fields='["field1","field2"]'>

      </treemap-datalet>

  

  @element barchart-datalet

  @status v0.1

  @demo demo/index.html

  @group datalets

  -->

  

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

      <template>

74249687   Luigi Serra   Cross browser con...
58
          <style is="custom-style">

73bcce88   luigser   COMPONENTS
59
  

74249687   Luigi Serra   Cross browser con...
60
              :host ::content h6 {

73bcce88   luigser   COMPONENTS
61
62
63
                  color: red;

              }

  

74249687   Luigi Serra   Cross browser con...
64
              :host ::content #treemap_placeholder {

73bcce88   luigser   COMPONENTS
65
66
                  width: 100%;

                  height: 70%;

f974e824   Luigi Serra   Bugs fix
67
                  min-height: 500px;

73bcce88   luigser   COMPONENTS
68
69
70
                  background: #ddd;

              }

  

74249687   Luigi Serra   Cross browser con...
71
              :host ::content text {

73bcce88   luigser   COMPONENTS
72
73
74
                  pointer-events: none;

              }

  

74249687   Luigi Serra   Cross browser con...
75
              :host ::content .grandparent text {

73bcce88   luigser   COMPONENTS
76
77
78
                  font-weight: bold;

              }

  

74249687   Luigi Serra   Cross browser con...
79
              :host ::content rect {

73bcce88   luigser   COMPONENTS
80
81
82
83
                  fill: none;

                  stroke: #fff;

              }

  

74249687   Luigi Serra   Cross browser con...
84
              :host ::content rect.parent,

73bcce88   luigser   COMPONENTS
85
86
87
88
              .grandparent rect {

                  stroke-width: 2px;

              }

  

74249687   Luigi Serra   Cross browser con...
89
              :host ::content .grandparent rect {

73bcce88   luigser   COMPONENTS
90
91
92
                  fill: orange;

              }

  

74249687   Luigi Serra   Cross browser con...
93
              :host ::content .grandparent:hover rect {

73bcce88   luigser   COMPONENTS
94
95
96
                  fill: #ee9700;

              }

  

74249687   Luigi Serra   Cross browser con...
97
              :host ::content .children rect.parent,

73bcce88   luigser   COMPONENTS
98
99
100
101
              .grandparent rect {

                  cursor: pointer;

              }

  

74249687   Luigi Serra   Cross browser con...
102
              :host ::content .children rect.parent {

73bcce88   luigser   COMPONENTS
103
104
105
106
                  fill: #bbb;

                  fill-opacity: .5;

              }

  

74249687   Luigi Serra   Cross browser con...
107
              :host ::content .children:hover rect.child {

73bcce88   luigser   COMPONENTS
108
109
110
111
                  fill: #bbb;

              }

          </style>

          <div id="treemap_placeholder"></div>

a1f0799c   isisadmin   datalet global re...
112
          <base-ajax-json-jsonpath-datalet data-url="{{dataUrl}}" fields="{{fields}}"></base-ajax-json-jsonpath-datalet>

73bcce88   luigser   COMPONENTS
113
114
115
116
117
      </template>

  

      <script src="../shared_js/d3.js"></script>

      <script src="js/buildtreemap.js"></script>

      <script>

a1f0799c   isisadmin   datalet global re...
118
  

73bcce88   luigser   COMPONENTS
119
          var TreemapBehavior = {

5bc002a2   isisadmin   datalet refactoring
120
  

73bcce88   luigser   COMPONENTS
121
              map : {

4e7eacf4   Luigi Serra   Controllets and d...
122
                  name : "",

73bcce88   luigser   COMPONENTS
123
124
                  children : []

              },

5bc002a2   isisadmin   datalet refactoring
125
126
  

              transformData: function(e)

a1f0799c   isisadmin   datalet global re...
127
128
              {

                  var treemapData = [];

4e7eacf4   Luigi Serra   Controllets and d...
129
                  TreemapBehavior.map.name = this._component.name;

73bcce88   luigser   COMPONENTS
130
  

a1f0799c   isisadmin   datalet global re...
131
132
133
                  if(this.data.length > 1) {

                      for (i = 0; i < this.data.length; i++) {

                          var propName = this.data[i].name;

73bcce88   luigser   COMPONENTS
134
  

a1f0799c   isisadmin   datalet global re...
135
136
                          for (var j = 0; j < this.data[i].data.length; j++) {

                              if (i == 0) treemapData[j] = {};

73bcce88   luigser   COMPONENTS
137
                              currObj = {};

a1f0799c   isisadmin   datalet global re...
138
139
                              currObj[propName] = this.data[i].data[j];

                              jQuery.extend(treemapData[j], currObj);

73bcce88   luigser   COMPONENTS
140
141
142
                          }

                      }

                  }else{

a1f0799c   isisadmin   datalet global re...
143
                      treemapData = this.data[0].data;

73bcce88   luigser   COMPONENTS
144
145
146
147
                  }

  

                  this.map.children = [];

  

a1f0799c   isisadmin   datalet global re...
148
149
                  for(var i = 0; i < treemapData.length; i++){

                      this.checkAggragationField(treemapData[i], this._component.fields.length , this._component.fields.length - 1);

73bcce88   luigser   COMPONENTS
150
                  }

5bc002a2   isisadmin   datalet refactoring
151
  

74249687   Luigi Serra   Cross browser con...
152
                  var json = JSON.stringify(this.map);

5bc002a2   isisadmin   datalet refactoring
153
  

73bcce88   luigser   COMPONENTS
154
              },

5bc002a2   isisadmin   datalet refactoring
155
  

73bcce88   luigser   COMPONENTS
156
157
158
159
160
161
162
163
164
165
              findChild: function(child, category){

                  var children = child.children;

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

                      if (children[i].name == category)

                          return children[i];

                  }

                  var nchild = {name : category , children : []};

                  children.push(nchild);

                  return nchild;

              },

5bc002a2   isisadmin   datalet refactoring
166
  

f974e824   Luigi Serra   Bugs fix
167
              checkAggragationField: function(object, levels, value_index){

73bcce88   luigser   COMPONENTS
168
169
                  var curchild = this.map;

                  var keys = Object.keys(object);

f974e824   Luigi Serra   Bugs fix
170
                  for(var level= 0; level < levels; level++){

73bcce88   luigser   COMPONENTS
171
  

f974e824   Luigi Serra   Bugs fix
172
                      var child = this.findChild(curchild, object[keys[level]]);

73bcce88   luigser   COMPONENTS
173
174
175
176
177
178
179
180
181
182
                      curchild = child;

                  }

  

                  if (curchild.value === undefined)

                      curchild.value = 0;

  

                  var value = curchild.value + parseFloat(object[keys[value_index]]);

                  curchild.children = null;

                  curchild.value = value;

              },

5bc002a2   isisadmin   datalet refactoring
183
184
  

              presentData: function(){

73bcce88   luigser   COMPONENTS
185
186
187
188
189
190
191
                  build(this.map, "treemap_placeholder");

              }

          };

  

  

          Polymer({

              is : 'treemap-datalet' ,

a1f0799c   isisadmin   datalet global re...
192
  

035bbee3   Luigi Serra   Datalets and cont...
193
194
195
196
197
198
199
200
201
202
203
204
205
206
              properties: {

                  /**

                   * It's the name for treemap

                   *

                   * @attribute name

                   * @type String

                   * @default ''

                   */

                  name: {

                      type: String,

                      value: ""

                  }

              },

  

73bcce88   luigser   COMPONENTS
207
              ready: function(){

a1f0799c   isisadmin   datalet global re...
208
                  var TreemapComponentBehavior =  $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, TreemapBehavior);

73bcce88   luigser   COMPONENTS
209
210
211
212
213
214
                  TreemapComponentBehavior.init(this);

              }

  

          });

      </script>

  </dom-module>