Blame view

datalets/treemap-datalet/treemap-datalet.html 4.6 KB
73bcce88   luigser   COMPONENTS
1
2
3
4
5
  <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...
6
          <style is="custom-style">

73bcce88   luigser   COMPONENTS
7
  

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

73bcce88   luigser   COMPONENTS
9
10
11
                  color: red;

              }

  

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

73bcce88   luigser   COMPONENTS
13
14
                  width: 100%;

                  height: 70%;

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

73bcce88   luigser   COMPONENTS
16
17
18
                  background: #ddd;

              }

  

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

73bcce88   luigser   COMPONENTS
20
21
22
                  pointer-events: none;

              }

  

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

73bcce88   luigser   COMPONENTS
24
25
26
                  font-weight: bold;

              }

  

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

73bcce88   luigser   COMPONENTS
28
29
30
31
                  fill: none;

                  stroke: #fff;

              }

  

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

73bcce88   luigser   COMPONENTS
33
34
35
36
              .grandparent rect {

                  stroke-width: 2px;

              }

  

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

73bcce88   luigser   COMPONENTS
38
39
40
                  fill: orange;

              }

  

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

73bcce88   luigser   COMPONENTS
42
43
44
                  fill: #ee9700;

              }

  

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

73bcce88   luigser   COMPONENTS
46
47
48
49
              .grandparent rect {

                  cursor: pointer;

              }

  

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

73bcce88   luigser   COMPONENTS
51
52
53
54
                  fill: #bbb;

                  fill-opacity: .5;

              }

  

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

73bcce88   luigser   COMPONENTS
56
57
58
59
                  fill: #bbb;

              }

          </style>

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

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

73bcce88   luigser   COMPONENTS
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
      </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
92
                  for(var i = 0; i < this.properties.data.value.length; i++){

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

73bcce88   luigser   COMPONENTS
94
                  }

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

73bcce88   luigser   COMPONENTS
96
97
98
99
100
101
102
103
104
105
106
              },

              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
107
              checkAggragationField: function(object, levels, value_index){

73bcce88   luigser   COMPONENTS
108
109
                  var curchild = this.map;

                  var keys = Object.keys(object);

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

73bcce88   luigser   COMPONENTS
111
  

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

73bcce88   luigser   COMPONENTS
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
                      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>