treemap21 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/treemap21.rb +92 -17
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eab8d9c1cea48b4a87cae180ee9833edb73228b2b030f79b8147bbe182c759f3
|
4
|
+
data.tar.gz: 61de221e10bf7313e9ce20dabdf6c02348a5a252b286f7b8b1726faf931100c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdd8d262424837797d71b637bc37bb1b2bd3902d6f55a74957768c2029abd1c4abfce774bccc3037b47c58fa5d489ee63c1653f89dd42de5ddddac826a1a09de
|
7
|
+
data.tar.gz: 06d08c9ddcc9a542c8dca4460490bb1564077ab5b2012e9febbfd2cdc7bb3009981a78e1409ea3bc0af3ec8b2fae4ae949a2e6b34f832bfe7afce749601f441a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/treemap21.rb
CHANGED
@@ -25,12 +25,14 @@ class Treemap21
|
|
25
25
|
|
26
26
|
doc3 = Rexle.new("<div id='box1' class='cbox'/>")
|
27
27
|
doc = mapper(doc3, @a, orientation: @orientation)
|
28
|
+
|
29
|
+
cbox_css = doc.root.xpath('//div[@class="cbox1"]').map do |e|
|
30
|
+
hex = 3.times.map { rand(60..250).to_s(16) }.join
|
31
|
+
"#%s { background-color: #%s}" % [e.attributes[:id], hex]
|
32
|
+
end
|
33
|
+
|
28
34
|
boxes = doc.root.xml pretty: true
|
29
35
|
|
30
|
-
cbox_css = @a.length.times.with_index.map do |i|
|
31
|
-
hex = 3.times.map { rand(60..250).to_s(16) }.join
|
32
|
-
"#cbox%s {background-color: #%s}" % [i+1, hex]
|
33
|
-
end
|
34
36
|
|
35
37
|
<<EOF
|
36
38
|
<html>
|
@@ -40,7 +42,7 @@ class Treemap21
|
|
40
42
|
width: 100%;
|
41
43
|
height: 100%;
|
42
44
|
}
|
43
|
-
.
|
45
|
+
.long, .cbox1 {
|
44
46
|
float: left;
|
45
47
|
}
|
46
48
|
.cbox1, .cbox1 a {
|
@@ -58,6 +60,27 @@ class Treemap21
|
|
58
60
|
|
59
61
|
.cbox1 a:hover { background-color: rgba(255,255,255,0.2); color: #902}
|
60
62
|
.cbox1 span { background-color: transparent; color2: #300 }
|
63
|
+
|
64
|
+
.cbox {position: relative}
|
65
|
+
|
66
|
+
.glabel {
|
67
|
+
background-color: #111;
|
68
|
+
width: 100%;
|
69
|
+
height: 30px;
|
70
|
+
color: #fff; font-size: 1.6em;
|
71
|
+
position: absolute;
|
72
|
+
z-index: 1
|
73
|
+
}
|
74
|
+
|
75
|
+
.gfoot {
|
76
|
+
background-color: #111;
|
77
|
+
width: 100%;
|
78
|
+
height: 20px;
|
79
|
+
position: absolute;
|
80
|
+
bottom: 0;
|
81
|
+
}
|
82
|
+
|
83
|
+
.group { border: 0px solid black;}
|
61
84
|
|
62
85
|
.c10 {font-size: 8em}
|
63
86
|
.c9 {font-size: 7.5em}
|
@@ -89,12 +112,12 @@ EOF
|
|
89
112
|
|
90
113
|
span = Rexle::Element.new('span', value: text)
|
91
114
|
|
92
|
-
a = attr.map {|key, value| "%s: %s" % [key, value]}
|
115
|
+
#a = attr.map {|key, value| "%s: %s" % [key, value]}
|
93
116
|
|
94
117
|
h = {
|
95
118
|
id: 'cbox' + @count.to_s,
|
96
|
-
class: 'cbox1 ' + cfont
|
97
|
-
style: a.join('; ')
|
119
|
+
class: 'cbox1 ' + cfont#,
|
120
|
+
#style: a.join('; ')
|
98
121
|
}
|
99
122
|
@count = @count + 1
|
100
123
|
|
@@ -113,11 +136,13 @@ EOF
|
|
113
136
|
|
114
137
|
end
|
115
138
|
|
116
|
-
def mapper(doc, a, orientation: :landscape, total: 100)
|
139
|
+
def mapper(doc, a, orientation: :landscape, total: 100, scale: 100)
|
117
140
|
|
118
141
|
if @debug then
|
142
|
+
puts 'a: ' + a.inspect
|
119
143
|
puts 'orientation: ' + orientation.inspect
|
120
144
|
puts 'total: ' + total.inspect
|
145
|
+
puts 'scale: ' + scale.inspect
|
121
146
|
end
|
122
147
|
|
123
148
|
klass = if orientation == :landscape then
|
@@ -131,8 +156,9 @@ EOF
|
|
131
156
|
# find the largest box
|
132
157
|
a2 = a.sort_by {|_, percent, _| percent}
|
133
158
|
puts 'a2.first: ' + a2.first.inspect if @debug
|
134
|
-
|
135
|
-
|
159
|
+
item = a2.pop
|
160
|
+
|
161
|
+
percent = item[1]
|
136
162
|
remainder = total - percent
|
137
163
|
# how much space does the largest box take?
|
138
164
|
rpct = 100 / (total / percent.to_f)
|
@@ -145,14 +171,61 @@ EOF
|
|
145
171
|
end
|
146
172
|
|
147
173
|
puts 'new_orientation: ' + new_orientation.inspect if @debug
|
148
|
-
|
174
|
+
|
149
175
|
dimension = orientation == :landscape ? :width : :height
|
150
176
|
style = { dimension => rpct.round.to_s + '%' }
|
151
177
|
|
152
|
-
|
153
|
-
|
178
|
+
h = {
|
179
|
+
class: klass,
|
180
|
+
style: style.map {|key, value| "%s: %s" % [key, value]}.join(';')
|
181
|
+
}
|
182
|
+
|
183
|
+
div = Rexle::Element.new('div', attributes: h)
|
184
|
+
|
185
|
+
|
186
|
+
if item[3].is_a? Array then
|
187
|
+
|
188
|
+
# it's a group item
|
189
|
+
group_name = item[0]
|
190
|
+
#<div class='glabel'> <span>Group A</span> </div>
|
191
|
+
group = Rexle::Element.new('div', attributes: {class: 'glabel'})
|
192
|
+
span = Rexle::Element.new('span', value: group_name)
|
193
|
+
group.add span
|
194
|
+
div.add group
|
195
|
+
|
196
|
+
doc4 = Rexle.new("<div id='box%s' class='%s' style='%s: %s%%'/>" % \
|
197
|
+
[@counter, klass, dimension, rem_pct.round.to_s])
|
198
|
+
mapper(div, item[3], scale: scale)
|
199
|
+
|
200
|
+
group_foot = Rexle::Element.new('div', attributes: {class: 'gfoot'})
|
201
|
+
div.add group_foot
|
202
|
+
|
203
|
+
else
|
204
|
+
|
205
|
+
title, percent, url = item
|
206
|
+
|
207
|
+
|
208
|
+
factor = scale / (100 / percent.to_f)
|
209
|
+
puts 'scale: ' + scale.inspect
|
210
|
+
puts 'percent: ' + percent.inspect
|
211
|
+
puts 'factor: ' + factor.inspect
|
212
|
+
e = add_box(title, url, {}, ("c%02d" % factor).to_s[0..-2])
|
213
|
+
puts 'e: ' + e.inspect if @debug
|
214
|
+
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
# add the group if there is any
|
220
|
+
if group_name then
|
221
|
+
|
154
222
|
|
155
|
-
|
223
|
+
#div.add diva
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
div.add e
|
228
|
+
doc.root.add div
|
156
229
|
|
157
230
|
if a2.any? then
|
158
231
|
|
@@ -160,11 +233,13 @@ EOF
|
|
160
233
|
[@counter, klass, dimension, rem_pct.round.to_s])
|
161
234
|
@counter += 1
|
162
235
|
|
163
|
-
doc2 = mapper(doc3, a2, orientation: new_orientation, total: remainder)
|
236
|
+
doc2 = mapper(doc3, a2, orientation: new_orientation, total: remainder, scale: rem_pct.round)
|
164
237
|
doc.root.add doc2.root
|
165
238
|
|
166
239
|
end
|
167
|
-
|
240
|
+
|
241
|
+
#<div class='gfoot'> </div>
|
242
|
+
|
168
243
|
return doc
|
169
244
|
|
170
245
|
end
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|