treemap21 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/treemap21.rb +51 -36
- metadata +2 -2
- 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: c6d4cea411a212554b648adda8cc3ef97caeb9bc777930fae4812d6cfff3531a
|
4
|
+
data.tar.gz: d53d6fae22338a229522fa0e3ff80797708fea28e856456f705a3bc4a0cd81d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e97f1cf05c2c1c55147c4f010459e40ab4d8ceded089d14fb081d6d91ab773af3be2bb0922dee7bfcb4f5f9d0c4bde257273e033c23c23da0d2aa05110a0572
|
7
|
+
data.tar.gz: d597f34903c1c95d0d403dc3c93028d27e06284c0037b880e4bb18a18032ab9fcf512f32073a22011a2b13f3c7aa640e7b32b1f5fb456e866265dbda44272388
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/treemap21.rb
CHANGED
@@ -2,29 +2,40 @@
|
|
2
2
|
|
3
3
|
# file: treemap21.rb
|
4
4
|
|
5
|
-
|
6
5
|
require 'rexle'
|
7
6
|
|
8
7
|
|
9
8
|
class Treemap21
|
9
|
+
|
10
|
+
attr_reader :to_html
|
10
11
|
|
11
12
|
def initialize(a, orientation: :landscape, debug: false)
|
12
13
|
|
13
14
|
@a, @orientation, @debug = a, orientation, debug
|
14
|
-
|
15
|
+
@to_html = build_html()
|
16
|
+
|
15
17
|
end
|
18
|
+
|
19
|
+
private
|
16
20
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
21
|
+
def build_html()
|
22
|
+
|
23
|
+
# used for the box id
|
24
|
+
@counter, @count = 2, 1
|
25
|
+
|
26
|
+
doc3 = Rexle.new("<div id='box1' class='cbox'/>")
|
20
27
|
doc = mapper(doc3, @a, orientation: @orientation)
|
21
28
|
boxes = doc.root.xml pretty: true
|
29
|
+
|
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
|
22
34
|
|
23
35
|
<<EOF
|
24
36
|
<html>
|
25
37
|
<head>
|
26
38
|
<style>
|
27
|
-
|
28
39
|
.cbox, .long, .cbox1, .cbox1 a {
|
29
40
|
width: 100%;
|
30
41
|
height: 100%;
|
@@ -38,10 +49,15 @@ class Treemap21
|
|
38
49
|
align-items: center;
|
39
50
|
}
|
40
51
|
|
41
|
-
.cbox1 a {
|
52
|
+
.cbox1 a {
|
53
|
+
text-decoration: none;
|
54
|
+
color: #010;
|
55
|
+
font-family: helvetica, arial;
|
56
|
+
color: #115;
|
57
|
+
}
|
58
|
+
|
42
59
|
.cbox1 a:hover { background-color: rgba(255,255,255,0.2); color: #902}
|
43
|
-
|
44
|
-
.cbox1 span { background-color: transparent; }
|
60
|
+
.cbox1 span { background-color: transparent; color2: #300 }
|
45
61
|
|
46
62
|
.c10 {font-size: 8em}
|
47
63
|
.c9 {font-size: 7.5em}
|
@@ -54,6 +70,8 @@ class Treemap21
|
|
54
70
|
.c2 {font-size: 2.4em}
|
55
71
|
.c1 {font-size: 1.6em}
|
56
72
|
.c0 {font-size: 1.1em}
|
73
|
+
|
74
|
+
#{cbox_css.join("\n")}
|
57
75
|
|
58
76
|
</style>
|
59
77
|
</head>
|
@@ -67,15 +85,20 @@ class Treemap21
|
|
67
85
|
EOF
|
68
86
|
end
|
69
87
|
|
70
|
-
private
|
71
|
-
|
72
88
|
def add_box(text, url=nil, attr={}, cfont)
|
73
|
-
|
74
|
-
a = attr.map {|key, value| "%s: %s" % [key, value]}
|
75
|
-
h = {class: 'cbox1 ' + cfont, style: a.join('; ')}
|
89
|
+
|
76
90
|
span = Rexle::Element.new('span', value: text)
|
91
|
+
|
92
|
+
a = attr.map {|key, value| "%s: %s" % [key, value]}
|
93
|
+
|
94
|
+
h = {
|
95
|
+
id: 'cbox' + @count.to_s,
|
96
|
+
class: 'cbox1 ' + cfont,
|
97
|
+
style: a.join('; ')
|
98
|
+
}
|
99
|
+
@count = @count + 1
|
100
|
+
|
77
101
|
doc = Rexle::Element.new('div', attributes: h)
|
78
|
-
|
79
102
|
|
80
103
|
if url then
|
81
104
|
anchor = Rexle::Element.new('a', attributes: {href: url})
|
@@ -91,7 +114,7 @@ EOF
|
|
91
114
|
end
|
92
115
|
|
93
116
|
def mapper(doc, a, orientation: :landscape, total: 100)
|
94
|
-
|
117
|
+
|
95
118
|
if @debug then
|
96
119
|
puts 'orientation: ' + orientation.inspect
|
97
120
|
puts 'total: ' + total.inspect
|
@@ -104,20 +127,18 @@ EOF
|
|
104
127
|
@canvas_height = 100; @canvas_width = @canvas_height / 2
|
105
128
|
'cbox'
|
106
129
|
end
|
107
|
-
|
108
|
-
bgcolor = 3.times.map { rand(60..250).to_s(16) }.join
|
109
130
|
|
110
131
|
# find the largest box
|
111
|
-
a2 = a.sort_by {|_, percent, _| percent}
|
132
|
+
a2 = a.sort_by {|_, percent, _| percent}
|
112
133
|
puts 'a2.first: ' + a2.first.inspect if @debug
|
113
|
-
title, percent, url = a2.
|
134
|
+
title, percent, url = a2.pop
|
114
135
|
|
115
136
|
remainder = total - percent
|
116
137
|
# how much space does the largest box take?
|
117
|
-
|
118
|
-
|
138
|
+
rpct = 100 / (total / percent.to_f)
|
139
|
+
rem_pct = 100 - rpct
|
119
140
|
|
120
|
-
new_orientation = if
|
141
|
+
new_orientation = if rpct.round <= 33 and rpct.round >= 3 then
|
121
142
|
orientation
|
122
143
|
else
|
123
144
|
orientation == :landscape ? :portrait : :landscape
|
@@ -125,27 +146,21 @@ EOF
|
|
125
146
|
|
126
147
|
puts 'new_orientation: ' + new_orientation.inspect if @debug
|
127
148
|
|
128
|
-
dimension = orientation == :landscape ? :width : :height
|
129
|
-
|
130
|
-
style = {
|
131
|
-
:"background-color" => '#' + bgcolor,
|
132
|
-
dimension => rem.round.to_s + '%'
|
133
|
-
}
|
149
|
+
dimension = orientation == :landscape ? :width : :height
|
150
|
+
style = { dimension => rpct.round.to_s + '%' }
|
134
151
|
|
135
152
|
e = add_box(title, url, style, ("c%02d" % percent).to_s[0..-2])
|
136
153
|
puts 'e: ' + e.inspect if @debug
|
137
154
|
|
138
155
|
doc.root.add e
|
139
156
|
|
140
|
-
if a2.
|
141
|
-
|
142
|
-
dim2 = orientation == :landscape ? 'width' : 'height'
|
143
|
-
doc3 = Rexle.new("<div class='%s' style='%s: %s%%'/>" % [klass, dim2,
|
144
|
-
rem2.round.to_s])
|
157
|
+
if a2.any? then
|
145
158
|
|
146
|
-
|
147
|
-
|
159
|
+
doc3 = Rexle.new("<div id='box%s' class='%s' style='%s: %s%%'/>" % \
|
160
|
+
[@counter, klass, dimension, rem_pct.round.to_s])
|
161
|
+
@counter += 1
|
148
162
|
|
163
|
+
doc2 = mapper(doc3, a2, orientation: new_orientation, total: remainder)
|
149
164
|
doc.root.add doc2.root
|
150
165
|
|
151
166
|
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.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
12lnvOZUZbofT7ctIMQL18INESoDYcmiH9r34KV6UCK9H/Ifm5CPKEYee8nilRM+
|
36
36
|
yIv4TcA8Psh7eTn7IAvLK4C0
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2021-05-
|
38
|
+
date: 2021-05-11 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rexle
|
metadata.gz.sig
CHANGED
Binary file
|