treemap21 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/treemap21.rb +143 -0
- metadata +91 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f562d64f657a93585417e8bb8c374d0ccc2b6c7236c27084a9de461428038a28
|
4
|
+
data.tar.gz: 6b51234302c3c93ac22907af27909bd6a9ef117153b523ae123fc42500191b63
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '08fc8fb6bd4e647760d2534e137d0af8d3e4fd176b08e8dff20955a9c916cec0c4813141b58b7d73c03fd777c2f87ff6733905f5ea2c0a9d549e61396013a81e'
|
7
|
+
data.tar.gz: 316f46ef980904be39d77cdfd87e6ba244d345a5e153be7c7b86c004f82574c64d4b2be4122fb3ecaf08548fc743ee45d16ef1fac867c71a56d2d023e8128698
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/lib/treemap21.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: treemap21.rb
|
4
|
+
|
5
|
+
|
6
|
+
require 'rexle'
|
7
|
+
|
8
|
+
|
9
|
+
class Treemap21
|
10
|
+
|
11
|
+
def initialize(a, orientation: :landscape, debug: false)
|
12
|
+
|
13
|
+
@a, @orientation, @debug = a, orientation, debug
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_html()
|
18
|
+
|
19
|
+
doc3 = Rexle.new("<div class='cbox'/>")
|
20
|
+
doc = mapper(doc3, @a, orientation: @orientation)
|
21
|
+
boxes = doc.root.xml pretty: true
|
22
|
+
|
23
|
+
<<EOF
|
24
|
+
<html>
|
25
|
+
<head>
|
26
|
+
<style>
|
27
|
+
|
28
|
+
.cbox, .long, .cbox1 {
|
29
|
+
width: 100%;
|
30
|
+
height: 100%;
|
31
|
+
}
|
32
|
+
.cbox1 ~.long, .cbox1 {
|
33
|
+
float: left;
|
34
|
+
}
|
35
|
+
.cbox1 {
|
36
|
+
display: flex;
|
37
|
+
justify-content: center;
|
38
|
+
align-items: center;
|
39
|
+
}
|
40
|
+
|
41
|
+
.cbox1 span { background-color: transparent;}
|
42
|
+
|
43
|
+
.c10 {font-size: 8em}
|
44
|
+
.c9 {font-size: 7.5em}
|
45
|
+
.c8 {font-size: 6em}
|
46
|
+
.c7 {font-size: 5.0em}
|
47
|
+
.c6 {font-size: 4.9em}
|
48
|
+
.c5 {font-size: 4.5em}
|
49
|
+
.c4 {font-size: 3.2em}
|
50
|
+
.c3 {font-size: 2.1em}
|
51
|
+
.c2 {font-size: 1.9em}
|
52
|
+
.c1 {font-size: 1.6em}
|
53
|
+
.c0 {font-size: 1.1em}
|
54
|
+
|
55
|
+
</style>
|
56
|
+
</head>
|
57
|
+
<body>
|
58
|
+
|
59
|
+
|
60
|
+
#{boxes}
|
61
|
+
|
62
|
+
</body>
|
63
|
+
</html>
|
64
|
+
EOF
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def add_box(text, attr={}, cfont)
|
70
|
+
|
71
|
+
a = attr.map {|key, value| "%s: %s" % [key, value]}
|
72
|
+
h = {class: 'cbox1 ' + cfont, style: a.join('; ')}
|
73
|
+
span = Rexle::Element.new('span', value: text)
|
74
|
+
doc = Rexle::Element.new('div', attributes: h)
|
75
|
+
doc.root.add span
|
76
|
+
doc.root
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def mapper(doc, a, orientation: :landscape, total: 100)
|
81
|
+
|
82
|
+
if @debug then
|
83
|
+
puts 'orientation: ' + orientation.inspect
|
84
|
+
puts 'total: ' + total.inspect
|
85
|
+
end
|
86
|
+
|
87
|
+
klass = if orientation == :landscape then
|
88
|
+
@canvas_width = 100; @canvas_height = @canvas_width / 2
|
89
|
+
'long'
|
90
|
+
else
|
91
|
+
@canvas_height = 100; @canvas_width = @canvas_height / 2
|
92
|
+
'cbox'
|
93
|
+
end
|
94
|
+
|
95
|
+
bgcolor = 3.times.map { rand(60..250).to_s(16) }.join
|
96
|
+
|
97
|
+
# find the largest box
|
98
|
+
a2 = a.sort_by(&:last).reverse
|
99
|
+
puts 'a2.first: ' + a2.first.inspect if @debug
|
100
|
+
title, percent = a2.first
|
101
|
+
|
102
|
+
remainder = total - percent
|
103
|
+
# how much space does the largest box take?
|
104
|
+
rem = 100 / (total / percent.to_f)
|
105
|
+
rem2 = 100 - rem
|
106
|
+
|
107
|
+
new_orientation = if rem <= 30 then
|
108
|
+
orientation
|
109
|
+
else
|
110
|
+
orientation == :landscape ? :portrait : :landscape
|
111
|
+
end
|
112
|
+
|
113
|
+
puts 'new_orientation: ' + new_orientation.inspect if @debug
|
114
|
+
|
115
|
+
dimension = orientation == :landscape ? :width : :height
|
116
|
+
|
117
|
+
style = {
|
118
|
+
:"background-color" => '#' + bgcolor,
|
119
|
+
dimension => rem.round.to_s + '%'
|
120
|
+
}
|
121
|
+
|
122
|
+
e = add_box(title, style, ("c%02d" % percent).to_s[0..-2])
|
123
|
+
puts 'e: ' + e.inspect if @debug
|
124
|
+
|
125
|
+
doc.root.add e
|
126
|
+
|
127
|
+
if a2.length > 1 then
|
128
|
+
|
129
|
+
dim2 = orientation == :landscape ? 'width' : 'height'
|
130
|
+
doc3 = Rexle.new("<div class='%s' style='%s: %s%%'/>" % [klass, dim2,
|
131
|
+
rem2.round.to_s])
|
132
|
+
|
133
|
+
doc2 = mapper(doc3, a2[1..-1], orientation: new_orientation, total: remainder)
|
134
|
+
|
135
|
+
doc.root.add doc2.root
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
return doc
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: treemap21
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjEwNTEwMTc0NTE1WhcN
|
15
|
+
MjIwNTEwMTc0NTE1WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
|
16
|
+
cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDGOBco
|
17
|
+
ram3U5eg4zTR4iFC9QwY8TgNNLRpl0ssfA3XozP4UmapyM88GeEDJaSgQEI05xQk
|
18
|
+
LxgnamMAgsIwAP+xfm0psIk+7yLetNjah6ezcfIQuOWv1d4p/YjPGqF4qOlAvIEp
|
19
|
+
EyrCuOcBjZ+JXH3AWa2YrQJPa35tjRPRZOsRHTVzY+7x2r7RxgqH8QAA9JkYv2NG
|
20
|
+
ixc4a9VAt80yTiR7EwHsGl4b2iKU1uFjN3dSojWCXDXxhoqLy9+O5Wn/clO2Ncaq
|
21
|
+
Mm+WORLRxE05xS5yqj3GtvQ44owpUc3Pc9J+LZebE4l7Y1LAejQJ//4QOyFOpruP
|
22
|
+
e3wrUb9RuvHdGhSACURPXChdUz3HcPjTMCiJoawdubl8sLsEdW+eoxbJyZ0RwJby
|
23
|
+
2zCbVzQ2cMFUAQVUd6fPqR7ZRbch3FpjIYpH3+iEe/GVdixAFbZzAlck7uz+o8e5
|
24
|
+
6qSWyZYAh2QtSekz2inu9Nzc9WpTpFgVi0noxwcY23akiXgjgCnyoD7/OlMCAwEA
|
25
|
+
AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUyDIewoet
|
26
|
+
k2Qk0vk3V7cnk6+zJHEwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
|
27
|
+
c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEAZk/bkmGvUBUKY6pk7ZwA+wtqDTlqIcviTP2+TtD9
|
29
|
+
UIBc4nnIp0sA6I/Degdos1tGG1z7Y4v5ZQztiGqnRcxlpUL8wwih6W9z9nF8NCcC
|
30
|
+
K3gkZUiOyUzacIk/JO/PGgzFFsPcQGlVzijHs7f+lO+5iFiXp7MJNjIU8/7tAJ8T
|
31
|
+
6fauBUNAoVeBlhOB+KSuMUrC9AFEqvy2nJN3APth95KH1MpOj+CmN+u/aH7/Nlym
|
32
|
+
bDqoRNsNM8EQv2g0LZfe45RYE9kFQRmld3Db+pe8+x182MvKgvDVWW4Qe5EN3cAi
|
33
|
+
siom9fsGTtX4bVVUYhCZu3N4hm3wPVjmoZMu9jVJCckANqWp3BCa3IljD1GBD+ck
|
34
|
+
HgBk7ZMTwNws9B6yry5wWaONcBFFmV4rRKvkd7RFgSXnjCW3hm0JCjd6oSNQngb/
|
35
|
+
12lnvOZUZbofT7ctIMQL18INESoDYcmiH9r34KV6UCK9H/Ifm5CPKEYee8nilRM+
|
36
|
+
yIv4TcA8Psh7eTn7IAvLK4C0
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date: 2021-05-10 00:00:00.000000000 Z
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rexle
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.5'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.5.11
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.5'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.5.11
|
60
|
+
description:
|
61
|
+
email: digital.robertson@gmail.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- lib/treemap21.rb
|
67
|
+
homepage: https://github.com/jrobertson/treemap21
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.7.10
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Experimental treemapping gem which generates an HTML document.
|
91
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|