Class: Treemap::HtmlOutput
- Inherits:
-
OutputBase
- Object
- OutputBase
- Treemap::HtmlOutput
- Defined in:
- lib/treemap/html_output.rb
Instance Attribute Summary collapse
-
#base_font_size ⇒ Object
Returns the value of attribute base_font_size.
-
#center_labels_at_depth ⇒ Object
Returns the value of attribute center_labels_at_depth.
-
#center_labels_at_z ⇒ Object
Returns the value of attribute center_labels_at_z.
-
#full_html ⇒ Object
Returns the value of attribute full_html.
-
#javascripts ⇒ Object
Returns the value of attribute javascripts.
-
#stylesheets ⇒ Object
Returns the value of attribute stylesheets.
Attributes inherited from OutputBase
#color, #height, #layout, #margin_left, #margin_top, #width
Instance Method Summary collapse
- #default_css ⇒ Object
- #draw_label(node) ⇒ Object
- #draw_map(node) ⇒ Object
- #draw_node(node) ⇒ Object
-
#draw_node_body(node) ⇒ Object
Subclass can override to add more html inside <div/> of node.
-
#initialize {|_self| ... } ⇒ HtmlOutput
constructor
A new instance of HtmlOutput.
- #node_color(node) ⇒ Object
- #node_label(node) ⇒ Object
- #to_html(node) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ HtmlOutput
Returns a new instance of HtmlOutput.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/treemap/html_output.rb', line 20 def initialize super # default options for HtmlOutput @full_html = true @center_labels_at_depth = nil @center_labels_at_z = 100 @stylesheets = "" @javascripts = "" @base_font_size = 14 yield self if block_given? @layout.position = :absolute end |
Instance Attribute Details
#base_font_size ⇒ Object
Returns the value of attribute base_font_size.
18 19 20 |
# File 'lib/treemap/html_output.rb', line 18 def base_font_size @base_font_size end |
#center_labels_at_depth ⇒ Object
Returns the value of attribute center_labels_at_depth.
18 19 20 |
# File 'lib/treemap/html_output.rb', line 18 def center_labels_at_depth @center_labels_at_depth end |
#center_labels_at_z ⇒ Object
Returns the value of attribute center_labels_at_z.
18 19 20 |
# File 'lib/treemap/html_output.rb', line 18 def center_labels_at_z @center_labels_at_z end |
#full_html ⇒ Object
Returns the value of attribute full_html.
18 19 20 |
# File 'lib/treemap/html_output.rb', line 18 def full_html @full_html end |
#javascripts ⇒ Object
Returns the value of attribute javascripts.
18 19 20 |
# File 'lib/treemap/html_output.rb', line 18 def javascripts @javascripts end |
#stylesheets ⇒ Object
Returns the value of attribute stylesheets.
18 19 20 |
# File 'lib/treemap/html_output.rb', line 18 def stylesheets @stylesheets end |
Instance Method Details
#default_css ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/treemap/html_output.rb', line 36 def default_css css = <<CSS .node { border: 1px solid black; } .label { color: #FFFFFF; font-size: 11px; } .label-heading { color: #FFFFFF; font-size: 14pt; font-weight: bold; text-decoration: underline; } CSS end |
#draw_label(node) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/treemap/html_output.rb', line 104 def draw_label(node) label= "<span" if(!@center_labels_at_depth.nil? and @center_labels_at_depth == node.depth) px_per_point = 20 label_size = node.label.length * px_per_point label += " style=\"" label += "overflow: hidden; position: absolute;" label += "margin-top: " + (node.bounds.height/2 - node.font_size(@base_font_size)/2).to_s + "px;" left_margin = 0 if(label_size < node.bounds.width) left_margin = (node.bounds.width - label_size) / 2 end label += "margin-left: " + left_margin.to_s + "px;" #label += "left: #{node.bounds.x1}px; top: #{node.bounds.y1}px;" label += "left: 0px; top: 0px;" label += "z-index: #{@center_labels_at_z};" label += "font-size:#{node.font_size(@base_font_size)}px;" label += "\"" label += " class=\"label-heading\"" else label += " class=\"label\"" label += " style=\"font-size:#{node.font_size(@base_font_size)}px\"" end label += ">" label += node_label(node) label += "</span>" label end |
#draw_map(node) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/treemap/html_output.rb', line 80 def draw_map(node) html = "" if(@full_html) html += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " html += "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" html += "<html><head>" html += "<title>Treemap - #{node_label(node)}</title>" html += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />" html += "<style type=\"text/css\">" + default_css + "</style>" html += self.stylesheets html += self.javascripts html += "</head><body>" end html += draw_node(node) if(@full_html) html += "</body></html>" end html end |
#draw_node(node) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/treemap/html_output.rb', line 141 def draw_node(node) return "" if node.bounds.nil? html = "<div id=\"node-#{node.id}\"" html += " style=\"" html += "overflow: hidden; position: absolute; display: inline;" html += "left: #{node.bounds.x1}px; top: #{node.bounds.y1}px;" html += "width: #{node.bounds.width}px; height: #{node.bounds.height}px;" html += "background-color: " + node_color(node) + ";" if(!@center_labels_at_depth.nil? and @center_labels_at_depth == node.depth) html += "border: 1px solid black;" end html += "\" class=\"node\"" html += ">" html += draw_node_body(node) if(!node.children.nil? and node.children.size > 0) node.children.each do |c| html += draw_node(c) end end html += "</div>" end |
#draw_node_body(node) ⇒ Object
Subclass can override to add more html inside <div/> of node
137 138 139 |
# File 'lib/treemap/html_output.rb', line 137 def draw_node_body(node) draw_label(node) end |
#node_color(node) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/treemap/html_output.rb', line 58 def node_color(node) color = "#CCCCCC" if(!node.color.nil?) if(not Numeric === node.color) color = node.color else color = "#" + @color.get_hex_color(node.color) end end color end |
#node_label(node) ⇒ Object
54 55 56 |
# File 'lib/treemap/html_output.rb', line 54 def node_label(node) CGI.escapeHTML(node.label) end |
#to_html(node) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/treemap/html_output.rb', line 72 def to_html(node) @bounds = self.bounds @layout.process(node, @bounds) draw_map(node) end |