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
|
-->
|
a1f0799c
isisadmin
datalet global re...
|
26
|
<link rel="import" href="../base-ajax-json-jsonpath-datalet/base-ajax-json-jsonpath-datalet.html">
|
73bcce88
luigser
COMPONENTS
|
27
|
|
5e6ba8af
isisadmin
datalet doc update
|
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<!--
`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
|
46
47
|
<dom-module id="treemap-datalet">
<template>
|
74249687
Luigi Serra
Cross browser con...
|
48
|
<style is="custom-style">
|
73bcce88
luigser
COMPONENTS
|
49
|
|
74249687
Luigi Serra
Cross browser con...
|
50
|
:host ::content h6 {
|
73bcce88
luigser
COMPONENTS
|
51
52
53
|
color: red;
}
|
74249687
Luigi Serra
Cross browser con...
|
54
|
:host ::content #treemap_placeholder {
|
73bcce88
luigser
COMPONENTS
|
55
56
|
width: 100%;
height: 70%;
|
f974e824
Luigi Serra
Bugs fix
|
57
|
min-height: 500px;
|
73bcce88
luigser
COMPONENTS
|
58
59
60
|
background: #ddd;
}
|
74249687
Luigi Serra
Cross browser con...
|
61
|
:host ::content text {
|
73bcce88
luigser
COMPONENTS
|
62
63
64
|
pointer-events: none;
}
|
74249687
Luigi Serra
Cross browser con...
|
65
|
:host ::content .grandparent text {
|
73bcce88
luigser
COMPONENTS
|
66
67
68
|
font-weight: bold;
}
|
74249687
Luigi Serra
Cross browser con...
|
69
|
:host ::content rect {
|
73bcce88
luigser
COMPONENTS
|
70
71
72
73
|
fill: none;
stroke: #fff;
}
|
74249687
Luigi Serra
Cross browser con...
|
74
|
:host ::content rect.parent,
|
73bcce88
luigser
COMPONENTS
|
75
76
77
78
|
.grandparent rect {
stroke-width: 2px;
}
|
74249687
Luigi Serra
Cross browser con...
|
79
|
:host ::content .grandparent rect {
|
73bcce88
luigser
COMPONENTS
|
80
81
82
|
fill: orange;
}
|
74249687
Luigi Serra
Cross browser con...
|
83
|
:host ::content .grandparent:hover rect {
|
73bcce88
luigser
COMPONENTS
|
84
85
86
|
fill: #ee9700;
}
|
74249687
Luigi Serra
Cross browser con...
|
87
|
:host ::content .children rect.parent,
|
73bcce88
luigser
COMPONENTS
|
88
89
90
91
|
.grandparent rect {
cursor: pointer;
}
|
74249687
Luigi Serra
Cross browser con...
|
92
|
:host ::content .children rect.parent {
|
73bcce88
luigser
COMPONENTS
|
93
94
95
96
|
fill: #bbb;
fill-opacity: .5;
}
|
74249687
Luigi Serra
Cross browser con...
|
97
|
:host ::content .children:hover rect.child {
|
73bcce88
luigser
COMPONENTS
|
98
99
100
101
|
fill: #bbb;
}
</style>
<div id="treemap_placeholder"></div>
|
a1f0799c
isisadmin
datalet global re...
|
102
|
<base-ajax-json-jsonpath-datalet data-url="{{dataUrl}}" fields="{{fields}}"></base-ajax-json-jsonpath-datalet>
|
73bcce88
luigser
COMPONENTS
|
103
104
105
106
107
|
</template>
<script src="../shared_js/d3.js"></script>
<script src="js/buildtreemap.js"></script>
<script>
|
a1f0799c
isisadmin
datalet global re...
|
108
|
|
73bcce88
luigser
COMPONENTS
|
109
|
var TreemapBehavior = {
|
5bc002a2
isisadmin
datalet refactoring
|
110
|
|
73bcce88
luigser
COMPONENTS
|
111
|
map : {
|
035bbee3
Luigi Serra
Datalets and cont...
|
112
|
name : this._component.name,
|
73bcce88
luigser
COMPONENTS
|
113
114
|
children : []
},
|
5bc002a2
isisadmin
datalet refactoring
|
115
116
|
transformData: function(e)
|
a1f0799c
isisadmin
datalet global re...
|
117
118
119
|
{
var treemapData = [];
|
73bcce88
luigser
COMPONENTS
|
120
|
|
a1f0799c
isisadmin
datalet global re...
|
121
122
123
|
if(this.data.length > 1) {
for (i = 0; i < this.data.length; i++) {
var propName = this.data[i].name;
|
73bcce88
luigser
COMPONENTS
|
124
|
|
a1f0799c
isisadmin
datalet global re...
|
125
126
|
for (var j = 0; j < this.data[i].data.length; j++) {
if (i == 0) treemapData[j] = {};
|
73bcce88
luigser
COMPONENTS
|
127
|
currObj = {};
|
a1f0799c
isisadmin
datalet global re...
|
128
129
|
currObj[propName] = this.data[i].data[j];
jQuery.extend(treemapData[j], currObj);
|
73bcce88
luigser
COMPONENTS
|
130
131
132
|
}
}
}else{
|
a1f0799c
isisadmin
datalet global re...
|
133
|
treemapData = this.data[0].data;
|
73bcce88
luigser
COMPONENTS
|
134
135
136
137
|
}
this.map.children = [];
|
a1f0799c
isisadmin
datalet global re...
|
138
139
|
for(var i = 0; i < treemapData.length; i++){
this.checkAggragationField(treemapData[i], this._component.fields.length , this._component.fields.length - 1);
|
73bcce88
luigser
COMPONENTS
|
140
|
}
|
5bc002a2
isisadmin
datalet refactoring
|
141
|
|
74249687
Luigi Serra
Cross browser con...
|
142
|
var json = JSON.stringify(this.map);
|
5bc002a2
isisadmin
datalet refactoring
|
143
|
|
73bcce88
luigser
COMPONENTS
|
144
|
},
|
5bc002a2
isisadmin
datalet refactoring
|
145
|
|
73bcce88
luigser
COMPONENTS
|
146
147
148
149
150
151
152
153
154
155
|
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
|
156
|
|
f974e824
Luigi Serra
Bugs fix
|
157
|
checkAggragationField: function(object, levels, value_index){
|
73bcce88
luigser
COMPONENTS
|
158
159
|
var curchild = this.map;
var keys = Object.keys(object);
|
f974e824
Luigi Serra
Bugs fix
|
160
|
for(var level= 0; level < levels; level++){
|
73bcce88
luigser
COMPONENTS
|
161
|
|
f974e824
Luigi Serra
Bugs fix
|
162
|
var child = this.findChild(curchild, object[keys[level]]);
|
73bcce88
luigser
COMPONENTS
|
163
164
165
166
167
168
169
170
171
172
|
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
|
173
174
|
presentData: function(){
|
73bcce88
luigser
COMPONENTS
|
175
176
177
178
179
180
181
|
build(this.map, "treemap_placeholder");
}
};
Polymer({
is : 'treemap-datalet' ,
|
a1f0799c
isisadmin
datalet global re...
|
182
|
|
035bbee3
Luigi Serra
Datalets and cont...
|
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
properties: {
/**
* It's the name for treemap
*
* @attribute name
* @type String
* @default ''
*/
name: {
type: String,
value: ""
}
},
|
73bcce88
luigser
COMPONENTS
|
197
|
ready: function(){
|
a1f0799c
isisadmin
datalet global re...
|
198
|
var TreemapComponentBehavior = $.extend(true, {}, BaseDataletBehavior, WorkcycleBehavior, AjaxJsonJsonPathBehavior, TreemapBehavior);
|
73bcce88
luigser
COMPONENTS
|
199
200
201
202
203
204
|
TreemapComponentBehavior.init(this);
}
});
</script>
</dom-module>
|