aebruno / ruby-treemap

RubyTreemap is a library for generating treemaps in ruby
GNU General Public License v2.0
2 stars 2 forks source link

add using colour to examples #10

Open matkoniecz opened 9 years ago

matkoniecz commented 9 years ago

There are at least three ways to set colour - and I am not sure which one is working as expected and which ones are working only by accident (I would like to fix #8 and I am not sure what should be supported).

# encoding: UTF-8

#using development version
require_relative 'ruby-treemap/lib/treemap'
require_relative 'ruby-treemap/lib/treemap/image_output'

#using released gem
#require 'treemap'
#require 'treemap/image_output'

root = Treemap::Node.new(:label => '')
root.new_child(:label => 'SMR', :size => 1, :color => 'black')
root.new_child(:label => 'SMR', :size => 1, :color => 0)
root.new_child(:label => 'SMR', :size => 1, :color => '#000000')
root.new_child(:label => 'SMR', :size => 1, :color => 'lime')
root.new_child(:label => 'SMR', :size => 1, :color => 100)
root.new_child(:label => 'SMR', :size => 1, :color => '#00FF00')

output = Treemap::HtmlOutput.new do |o|
   o.width = 800
   o.height = 600
   o.center_labels_at_depth = 1
end
open('test.html', 'w') {|html|
   html.puts output.to_html(root)
}
matkoniecz commented 9 years ago

@aebruno - is it expected that specifying color by passing colour name ('lime') works or is it working by an accident?

aebruno commented 9 years ago

@matkoniecz For the HTML output, the color is set via css using the background-color property on the nodes div. So whatever css supports as a background-color will work. When I initially wrote the library I was most interested in HTML output, but if we build more support for other output formats we may want to standardize the api to support colors across all output formats. Perhaps we only allow hex colors as they're likely going to be supported in both SVG and PNG.