treemap21 0.1.3 → 0.2.0
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 +117 -47
- metadata +7 -7
- metadata.gz.sig +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0feb0e59218a979c0f561cd12288096efc6cdd74a680ab173cfbce70f39961aa
|
4
|
+
data.tar.gz: 39a9c8fc56f9306bc1c2ffc4ad5291955f3583669e756a8b3d6c39b2cd7090a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24939905ba6150e83555f03a0c94196b7e33614d793415beab733457d6ff79f364348323ebdb39a45b61e72b209c46adcc46bf4014e29e24ac3ac24c933ec66a
|
7
|
+
data.tar.gz: a0151fae774ca54fa7ad1af8a612f7e8954b3d75a67d6f53e06bfa1ae1da999a12172e87e5698d01b5b3dac9d35fc9de094368a770fb403ab33242f1bd0e3ab3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/treemap21.rb
CHANGED
@@ -3,15 +3,51 @@
|
|
3
3
|
# file: treemap21.rb
|
4
4
|
|
5
5
|
require 'rexle'
|
6
|
+
require 'polyrex'
|
6
7
|
|
7
8
|
|
8
9
|
class Treemap21
|
9
10
|
|
10
11
|
attr_reader :to_html
|
11
12
|
|
12
|
-
def initialize(
|
13
|
+
def initialize(obj, orientation: :landscape, debug: false)
|
14
|
+
|
15
|
+
@orientation, @debug = orientation, debug
|
16
|
+
|
17
|
+
@a = case obj
|
18
|
+
when Array
|
19
|
+
a
|
20
|
+
when String
|
21
|
+
|
22
|
+
if obj.lstrip =~ /<?polyrex / then
|
23
|
+
|
24
|
+
px = Polyrex.new obj
|
25
|
+
doc = Rexle.new(px.to_tree)
|
26
|
+
scan_xml(doc.root)
|
27
|
+
|
28
|
+
elsif obj.lstrip =~ /</ then
|
29
|
+
|
30
|
+
doc = Rexle.new(obj)
|
31
|
+
scan_xml(doc.root)
|
32
|
+
|
33
|
+
else
|
34
|
+
|
35
|
+
# most likely a raw polyrex document without the processing
|
36
|
+
# instruction or header
|
37
|
+
|
38
|
+
head = "<?polyrex schema='items[title, description]/item[title," +
|
39
|
+
" pct, url]' delimiter=' # '?>\ntitle: Unititled\ndescription: " +
|
40
|
+
"Treemap record data"
|
41
|
+
|
42
|
+
s = head + "\n\n" + obj.lstrip
|
43
|
+
px = Polyrex.new s
|
44
|
+
doc = Rexle.new(px.to_tree)
|
45
|
+
scan_xml(doc.root)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
13
50
|
|
14
|
-
@a, @orientation, @debug = a, orientation, debug
|
15
51
|
@to_html = build_html()
|
16
52
|
|
17
53
|
end
|
@@ -67,7 +103,7 @@ class Treemap21
|
|
67
103
|
background-color: #111;
|
68
104
|
width: 100%;
|
69
105
|
height: 30px;
|
70
|
-
color: #fff; font-size: 1.
|
106
|
+
color: #fff; font-size: 1.6vw;
|
71
107
|
position: absolute;
|
72
108
|
z-index: 1
|
73
109
|
}
|
@@ -82,17 +118,17 @@ class Treemap21
|
|
82
118
|
|
83
119
|
.group { border: 0px solid black;}
|
84
120
|
|
85
|
-
.c10 {font-size:
|
86
|
-
.c9 {font-size: 7.
|
87
|
-
.c8 {font-size:
|
88
|
-
.c7 {font-size: 5.
|
89
|
-
.c6 {font-size: 4.
|
90
|
-
.c5 {font-size: 4.
|
91
|
-
.c4 {font-size: 3.
|
92
|
-
.c3 {font-size: 2.
|
93
|
-
.c2 {font-size: 2.
|
94
|
-
.c1 {font-size: 1.
|
95
|
-
.c0 {font-size: 1.
|
121
|
+
.c10 {font-size: 8vw}
|
122
|
+
.c9 {font-size: 7.5vw}
|
123
|
+
.c8 {font-size: 6vw}
|
124
|
+
.c7 {font-size: 5.0vw}
|
125
|
+
.c6 {font-size: 4.9vw}
|
126
|
+
.c5 {font-size: 4.5vw}
|
127
|
+
.c4 {font-size: 3.6vw}
|
128
|
+
.c3 {font-size: 2.6vw}
|
129
|
+
.c2 {font-size: 2.4vw}
|
130
|
+
.c1 {font-size: 1.6vw}
|
131
|
+
.c0 {font-size: 1.1vw}
|
96
132
|
|
97
133
|
#{cbox_css.join("\n")}
|
98
134
|
|
@@ -100,7 +136,6 @@ class Treemap21
|
|
100
136
|
</head>
|
101
137
|
<body>
|
102
138
|
|
103
|
-
|
104
139
|
#{boxes}
|
105
140
|
|
106
141
|
</body>
|
@@ -116,8 +151,7 @@ EOF
|
|
116
151
|
|
117
152
|
h = {
|
118
153
|
id: 'cbox' + @count.to_s,
|
119
|
-
class: 'cbox1 ' + cfont
|
120
|
-
#style: a.join('; ')
|
154
|
+
class: 'cbox1 ' + cfont
|
121
155
|
}
|
122
156
|
@count = @count + 1
|
123
157
|
|
@@ -153,10 +187,28 @@ EOF
|
|
153
187
|
'cbox'
|
154
188
|
end
|
155
189
|
|
190
|
+
a.map! do |x|
|
191
|
+
x[1] = x[1].nil? ? 1 : x[1].to_f
|
192
|
+
x
|
193
|
+
end
|
194
|
+
|
156
195
|
# find the largest box
|
157
|
-
a2 = a.sort_by {|_,
|
158
|
-
|
159
|
-
|
196
|
+
a2 = a.sort_by {|_, val, _| val}
|
197
|
+
|
198
|
+
# get the total value
|
199
|
+
total = a2.sum {|x| x[1]}
|
200
|
+
puts 'total ; ' + total.inspect if @debug
|
201
|
+
|
202
|
+
|
203
|
+
# calculate the percentages
|
204
|
+
a3 = a2.map do |title, val, url, list|
|
205
|
+
apct = 100 / (total / val.to_f)
|
206
|
+
[title, val, url, list, apct]
|
207
|
+
end
|
208
|
+
puts 'a3: ' + a3.inspect if @debug
|
209
|
+
|
210
|
+
puts 'a3.first: ' + a3.first.inspect if @debug
|
211
|
+
item = a3.pop
|
160
212
|
|
161
213
|
percent = item[1]
|
162
214
|
remainder = total - percent
|
@@ -186,62 +238,80 @@ EOF
|
|
186
238
|
if item[3].is_a? Array then
|
187
239
|
|
188
240
|
# it's a group item
|
189
|
-
group_name = item
|
241
|
+
group_name, url = item.values_at(0, 2)
|
190
242
|
#<div class='glabel'> <span>Group A</span> </div>
|
191
|
-
group = Rexle::Element.new('div', attributes: {class: 'glabel'})
|
243
|
+
group = Rexle::Element.new('div', attributes: {class: 'glabel'})
|
192
244
|
span = Rexle::Element.new('span', value: group_name)
|
193
|
-
|
245
|
+
|
246
|
+
if url then
|
247
|
+
|
248
|
+
anchor = Rexle::Element.new('a', attributes: {href: url})
|
249
|
+
anchor.root.add span
|
250
|
+
group.add anchor.root
|
251
|
+
|
252
|
+
else
|
253
|
+
|
254
|
+
group.add span
|
255
|
+
|
256
|
+
end
|
257
|
+
|
194
258
|
div.add group
|
195
259
|
|
196
260
|
doc4 = Rexle.new("<div id='box%s' class='%s' style='%s: %s%%'/>" % \
|
197
|
-
[@counter, klass, dimension, rem_pct.round.to_s])
|
198
|
-
|
261
|
+
[@counter, klass, dimension, rem_pct.round.to_s])
|
262
|
+
|
263
|
+
mapper(div, item[3], orientation: orientation, scale: scale)
|
199
264
|
|
200
265
|
group_foot = Rexle::Element.new('div', attributes: {class: 'gfoot'})
|
201
266
|
div.add group_foot
|
202
267
|
|
203
268
|
else
|
204
269
|
|
205
|
-
title,
|
206
|
-
|
270
|
+
title, value, url, list, percent = item
|
207
271
|
|
208
272
|
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
273
|
|
274
|
+
if @debug then
|
275
|
+
puts 'scale: ' + scale.inspect
|
276
|
+
puts 'percent: ' + percent.inspect
|
277
|
+
puts 'factor: ' + factor.inspect
|
278
|
+
end
|
215
279
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
if group_name then
|
221
|
-
|
222
|
-
|
223
|
-
#div.add diva
|
224
|
-
|
225
|
-
end
|
280
|
+
e = add_box(title, url, {}, ("c%02d" % factor).to_s[0..-2])
|
281
|
+
puts 'e: ' + e.inspect if @debug
|
282
|
+
|
283
|
+
end
|
226
284
|
|
227
285
|
div.add e
|
228
286
|
doc.root.add div
|
229
287
|
|
230
|
-
if
|
288
|
+
if a3.any? then
|
231
289
|
|
232
290
|
doc3 = Rexle.new("<div id='box%s' class='%s' style='%s: %s%%'/>" % \
|
233
291
|
[@counter, klass, dimension, rem_pct.round.to_s])
|
234
292
|
@counter += 1
|
235
293
|
|
236
|
-
doc2 = mapper(doc3,
|
294
|
+
doc2 = mapper(doc3, a3, orientation: new_orientation, total: remainder,
|
295
|
+
scale: rem_pct.round)
|
237
296
|
doc.root.add doc2.root
|
238
297
|
|
239
|
-
end
|
240
|
-
|
241
|
-
#<div class='gfoot'> </div>
|
298
|
+
end
|
242
299
|
|
243
300
|
return doc
|
244
301
|
|
245
302
|
end
|
303
|
+
|
304
|
+
def scan_xml(e)
|
305
|
+
|
306
|
+
e.xpath('item').map do |node|
|
307
|
+
|
308
|
+
title, pct, url = node.attributes.values
|
309
|
+
|
310
|
+
r = [title, pct, url]
|
311
|
+
r << scan_xml(node) if node.children.any?
|
312
|
+
r
|
313
|
+
end
|
314
|
+
|
315
|
+
end
|
246
316
|
|
247
317
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: treemap21
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,28 +35,28 @@ cert_chain:
|
|
35
35
|
12lnvOZUZbofT7ctIMQL18INESoDYcmiH9r34KV6UCK9H/Ifm5CPKEYee8nilRM+
|
36
36
|
yIv4TcA8Psh7eTn7IAvLK4C0
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2021-05-
|
38
|
+
date: 2021-05-12 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
41
|
+
name: polyrex
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '1.
|
46
|
+
version: '1.3'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 1.
|
49
|
+
version: 1.3.1
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '1.
|
56
|
+
version: '1.3'
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.
|
59
|
+
version: 1.3.1
|
60
60
|
description:
|
61
61
|
email: digital.robertson@gmail.com
|
62
62
|
executables: []
|
metadata.gz.sig
CHANGED
@@ -1 +1,3 @@
|
|
1
|
-
|
1
|
+
�t��GZ�e���p0g!�,������L���L�R���(8=�&PEр;��]d_,�zi$��L7߅��,J�c&�^�b�F5�qm;I���X�����>u�i该�7iֻ`�+間p*#���P�����ߐE��ha��f������'7�i#T=j��Jș�in�$��N
|
2
|
+
���uLZ\�lg~gډa�*<*�r�=�e��7�0�c��95�n��C�ZE�}"�${��d���
|
3
|
+
|