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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eab8d9c1cea48b4a87cae180ee9833edb73228b2b030f79b8147bbe182c759f3
4
- data.tar.gz: 61de221e10bf7313e9ce20dabdf6c02348a5a252b286f7b8b1726faf931100c1
3
+ metadata.gz: 0feb0e59218a979c0f561cd12288096efc6cdd74a680ab173cfbce70f39961aa
4
+ data.tar.gz: 39a9c8fc56f9306bc1c2ffc4ad5291955f3583669e756a8b3d6c39b2cd7090a7
5
5
  SHA512:
6
- metadata.gz: bdd8d262424837797d71b637bc37bb1b2bd3902d6f55a74957768c2029abd1c4abfce774bccc3037b47c58fa5d489ee63c1653f89dd42de5ddddac826a1a09de
7
- data.tar.gz: 06d08c9ddcc9a542c8dca4460490bb1564077ab5b2012e9febbfd2cdc7bb3009981a78e1409ea3bc0af3ec8b2fae4ae949a2e6b34f832bfe7afce749601f441a
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(a, orientation: :landscape, debug: false)
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.6em;
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: 8em}
86
- .c9 {font-size: 7.5em}
87
- .c8 {font-size: 6em}
88
- .c7 {font-size: 5.0em}
89
- .c6 {font-size: 4.9em}
90
- .c5 {font-size: 4.5em}
91
- .c4 {font-size: 3.6em}
92
- .c3 {font-size: 2.6em}
93
- .c2 {font-size: 2.4em}
94
- .c1 {font-size: 1.6em}
95
- .c0 {font-size: 1.1em}
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 {|_, percent, _| percent}
158
- puts 'a2.first: ' + a2.first.inspect if @debug
159
- item = a2.pop
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[0]
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
- group.add span
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
- mapper(div, item[3], scale: scale)
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, percent, url = item
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
- end
217
-
218
-
219
- # add the group if there is any
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 a2.any? then
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, a2, orientation: new_orientation, total: remainder, scale: rem_pct.round)
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.1.3
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-11 00:00:00.000000000 Z
38
+ date: 2021-05-12 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
- name: rexle
41
+ name: polyrex
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '1.5'
46
+ version: '1.3'
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.5.11
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.5'
56
+ version: '1.3'
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: 1.5.11
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
- %�/lo��k��a �,xdb���J�w3dkZH�6�&�b0�S*�Pe͟�)���ݤ#+}�8�Sa�n~2z���T�ڥx41&�?��S_���?S����n���6>g�;�xϕ�3O�W�_ �jKo�%��g��JܚX�i� Y��2Ya�%�s� ~��Y�嶕��kV�����)����O���ES>���3鰡 ����L!��b�0@���kK�!T�#�L'S��Ůݷ �c\���*�H�b�h9z#�DRg#��"����z�q[, ��,ڴ��+�1��C�=?�� Pgq���P�4A+���w_�$��m��/�� OM�?@�Q��$�Y�_6R�E��i(������J; =5_Ev �dy��P ��%^
1
+ t��GZe���p0g!�,������L���LR���(8=޺�&PEр;��]d_,�zi$��L7߅��,J�c&�^�b�F5qm;I���X�����>u�i该�7iֻ`�+間p*#���P�����ߐE��ha��f������'7i#T=j��Jș�in�$��N
2
+ ���uLZ\�lg~gډa�*<*�r�=�e��7�0�c��95�n��C�ZE�}"�${��d���
3
+