ruby-treemap 0.0.1 → 0.0.2
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.
- data/ChangeLog +7 -0
- data/lib/treemap.rb +1 -1
- data/lib/treemap/html_output.rb +7 -3
- data/lib/treemap/node.rb +9 -2
- metadata +7 -7
data/ChangeLog
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
RubyTreemap - ChangeLog
|
3
3
|
===============================================================================
|
4
4
|
|
5
|
+
2007-08-14
|
6
|
+
* Applied patch from Adrian Schoenig
|
7
|
+
- added an object attribute to the Treemap::Node class in order to
|
8
|
+
provide easy access to the object, which is represented by the node
|
9
|
+
- made the font size of every box dependant on its size for
|
10
|
+
html output
|
11
|
+
|
5
12
|
2006-07-16
|
6
13
|
* First release 0.0.1
|
7
14
|
* Created RubyForge project
|
data/lib/treemap.rb
CHANGED
@@ -25,7 +25,7 @@ require File.dirname(__FILE__) + '/treemap/gradient_color'
|
|
25
25
|
# require File.dirname(__FILE__) + '/treemap/svg_output'
|
26
26
|
|
27
27
|
module Treemap
|
28
|
-
VERSION = "0.0.
|
28
|
+
VERSION = "0.0.2"
|
29
29
|
|
30
30
|
def Treemap::dump_tree(node)
|
31
31
|
puts "#{node.label}: #{node.bounds.to_s}"
|
data/lib/treemap/html_output.rb
CHANGED
@@ -15,7 +15,7 @@ require File.dirname(__FILE__) + "/output_base"
|
|
15
15
|
require File.dirname(__FILE__) + "/slice_layout"
|
16
16
|
|
17
17
|
class Treemap::HtmlOutput < Treemap::OutputBase
|
18
|
-
attr_accessor(:full_html, :center_labels_at_depth, :stylesheets, :javascripts)
|
18
|
+
attr_accessor(:full_html, :base_font_size, :center_labels_at_depth, :center_labels_at_z, :stylesheets, :javascripts)
|
19
19
|
|
20
20
|
def initialize
|
21
21
|
super
|
@@ -23,8 +23,10 @@ class Treemap::HtmlOutput < Treemap::OutputBase
|
|
23
23
|
# default options for HtmlOutput
|
24
24
|
@full_html = true
|
25
25
|
@center_labels_at_depth = nil
|
26
|
+
@center_labels_at_z = 100
|
26
27
|
@stylesheets = ""
|
27
28
|
@javascripts = ""
|
29
|
+
@base_font_size = 14
|
28
30
|
|
29
31
|
yield self if block_given?
|
30
32
|
|
@@ -107,7 +109,7 @@ CSS
|
|
107
109
|
|
108
110
|
label += " style=\""
|
109
111
|
label += "overflow: hidden; position: absolute;"
|
110
|
-
label += "margin-top: " + (node.bounds.height/2).to_s + "px;"
|
112
|
+
label += "margin-top: " + (node.bounds.height/2 - node.font_size(@base_font_size)/2).to_s + "px;"
|
111
113
|
|
112
114
|
left_margin = 0
|
113
115
|
if(label_size < node.bounds.width)
|
@@ -116,11 +118,13 @@ CSS
|
|
116
118
|
label += "margin-left: " + left_margin.to_s + "px;"
|
117
119
|
#label += "left: #{node.bounds.x1}px; top: #{node.bounds.y1}px;"
|
118
120
|
label += "left: 0px; top: 0px;"
|
119
|
-
label += "z-index:
|
121
|
+
label += "z-index: #{@center_labels_at_z};"
|
122
|
+
label += "font-size:#{node.font_size(@base_font_size)}px;"
|
120
123
|
label += "\""
|
121
124
|
label += " class=\"label-heading\""
|
122
125
|
else
|
123
126
|
label += " class=\"label\""
|
127
|
+
label += " style=\"font-size:#{node.font_size(@base_font_size)}px\""
|
124
128
|
end
|
125
129
|
label += ">"
|
126
130
|
label += node_label(node)
|
data/lib/treemap/node.rb
CHANGED
@@ -37,7 +37,7 @@ module Treemap
|
|
37
37
|
#
|
38
38
|
#
|
39
39
|
class Treemap::Node
|
40
|
-
attr_accessor :id, :label, :color, :size, :bounds, :parent
|
40
|
+
attr_accessor :id, :label, :color, :size, :bounds, :parent, :object
|
41
41
|
attr_reader :children
|
42
42
|
|
43
43
|
#
|
@@ -51,8 +51,9 @@ module Treemap
|
|
51
51
|
# * :color - The background fill color in hex to render when drawing the
|
52
52
|
# square. If the value is a number a color will be calculated. An example
|
53
53
|
# string color would be: ##FFFFFF (white)
|
54
|
-
# * :id -
|
54
|
+
# * :id - A unique id to assign to this node. Default id will be generated if
|
55
55
|
# one is not provided.
|
56
|
+
# * :object - An object, that this node might contain.
|
56
57
|
#
|
57
58
|
#
|
58
59
|
def initialize(opts = {})
|
@@ -60,6 +61,7 @@ module Treemap
|
|
60
61
|
@label = opts[:label]
|
61
62
|
@color = opts[:color]
|
62
63
|
@id = opts[:id]
|
64
|
+
@object = opts[:object]
|
63
65
|
@children = []
|
64
66
|
|
65
67
|
if(@id.nil?)
|
@@ -114,6 +116,11 @@ module Treemap
|
|
114
116
|
|
115
117
|
sum
|
116
118
|
end
|
119
|
+
|
120
|
+
# Unscientific formula to calculate the font size depending on the node's area
|
121
|
+
def font_size(base_size)
|
122
|
+
(base_size * Math.sqrt(self.bounds.width * self.bounds.height) / 125).to_i
|
123
|
+
end
|
117
124
|
|
118
125
|
def label
|
119
126
|
return @label if !@label.nil?
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-treemap
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date:
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2007-08-17 00:00:00 -04:00
|
8
8
|
summary: Treemap visualization in ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -36,8 +36,6 @@ files:
|
|
36
36
|
- ChangeLog
|
37
37
|
- COPYING
|
38
38
|
- lib/treemap
|
39
|
-
- lib/treemap.rb
|
40
|
-
- lib/treemap/squarified_layout.rb
|
41
39
|
- lib/treemap/svg_output.rb
|
42
40
|
- lib/treemap/image_output.rb
|
43
41
|
- lib/treemap/html_output.rb
|
@@ -45,11 +43,13 @@ files:
|
|
45
43
|
- lib/treemap/node.rb
|
46
44
|
- lib/treemap/layout_base.rb
|
47
45
|
- lib/treemap/color_base.rb
|
48
|
-
- lib/treemap/
|
46
|
+
- lib/treemap/squarified_layout.rb
|
49
47
|
- lib/treemap/output_base.rb
|
48
|
+
- lib/treemap/gradient_color.rb
|
50
49
|
- lib/treemap/slice_layout.rb
|
51
|
-
-
|
50
|
+
- lib/treemap.rb
|
52
51
|
- test/tc_simple.rb
|
52
|
+
- test/tc_squarified.rb
|
53
53
|
- test/tc_color.rb
|
54
54
|
- test/tc_slice.rb
|
55
55
|
- test/tc_svg.rb
|