Blame view

datalets/treemap-datalet/treemap-datalet.html 5.7 KB
a508f993   isisadmin   added datalet doc...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  <!--

  The MIT License (MIT)

  

  Copyright (c) 2015 ROUTE-TO-PA CONSORTIUM

  

  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.

  -->

  

73bcce88   luigser   COMPONENTS
25
26
27
28
29
  <link rel="import" href="../../bower_components/polymer/polymer.html">

  <link rel="import" href="../base-datalet/base-datalet.html">

  

  <dom-module id="treemap-datalet">

      <template>

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

73bcce88   luigser   COMPONENTS
31
  

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

73bcce88   luigser   COMPONENTS
33
34
35
                  color: red;

              }

  

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

73bcce88   luigser   COMPONENTS
37
38
                  width: 100%;

                  height: 70%;

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

73bcce88   luigser   COMPONENTS
40
41
42
                  background: #ddd;

              }

  

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

73bcce88   luigser   COMPONENTS
44
45
46
                  pointer-events: none;

              }

  

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

73bcce88   luigser   COMPONENTS
48
49
50
                  font-weight: bold;

              }

  

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

73bcce88   luigser   COMPONENTS
52
53
54
55
                  fill: none;

                  stroke: #fff;

              }

  

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

73bcce88   luigser   COMPONENTS
57
58
59
60
              .grandparent rect {

                  stroke-width: 2px;

              }

  

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

73bcce88   luigser   COMPONENTS
62
63
64
                  fill: orange;

              }

  

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

73bcce88   luigser   COMPONENTS
66
67
68
                  fill: #ee9700;

              }

  

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

73bcce88   luigser   COMPONENTS
70
71
72
73
              .grandparent rect {

                  cursor: pointer;

              }

  

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

73bcce88   luigser   COMPONENTS
75
76
77
78
                  fill: #bbb;

                  fill-opacity: .5;

              }

  

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

73bcce88   luigser   COMPONENTS
80
81
82
83
                  fill: #bbb;

              }

          </style>

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

f974e824   Luigi Serra   Bugs fix
84
          <base-datalet data-url="{{dataUrl}}" query="{{query}}"></base-datalet>

73bcce88   luigser   COMPONENTS
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
      </template>

  

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

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

      <script>

          var TreemapBehavior = {

              map : {

                  name : "Expenses",

                  children : []

              },

              selectData: function(e){

                  var queries =  this._component.query.split("###");

  

                  if(queries.length > 1) {

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

                          var propName = this.getPropertyName(queries[i]);

  

                          temp = jsonPath(this.properties.json_results.value, queries[i]);

                          for (j = 0; j < temp.length; j++) {

                              if (i == 0) this.properties.data.value[j] = {};

                              currObj = {};

                              currObj[propName] = temp[j];

                              jQuery.extend(this.properties.data.value[j], currObj);

                          }

                      }

                  }else{

                      this.properties.data.value = jsonPath(this.properties.json_results.value, queries[0]);

                  }

  

                  this.map.children = [];

  

73bcce88   luigser   COMPONENTS
116
                  for(var i = 0; i < this.properties.data.value.length; i++){

74249687   Luigi Serra   Cross browser con...
117
                      this.checkAggragationField(this.properties.data.value[i], queries.length , queries.length - 1);

73bcce88   luigser   COMPONENTS
118
                  }

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

73bcce88   luigser   COMPONENTS
120
121
122
123
124
125
126
127
128
129
130
              },

              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;

              },

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

73bcce88   luigser   COMPONENTS
132
133
                  var curchild = this.map;

                  var keys = Object.keys(object);

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

73bcce88   luigser   COMPONENTS
135
  

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

73bcce88   luigser   COMPONENTS
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
                      curchild = child;

                  }

  

                  if (curchild.value === undefined)

                      curchild.value = 0;

  

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

                  curchild.children = null;

                  curchild.value = value;

              },

              transformData: function(){

                  build(this.map, "treemap_placeholder");

              }

          };

  

  

          Polymer({

              is : 'treemap-datalet' ,

              ready: function(){

                  var TreemapComponentBehavior =  $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior,AjaxJsonDataRequestBehavior, TreemapBehavior);

                  TreemapComponentBehavior.init(this);

              }

  

          });

      </script>

  </dom-module>