# # acts_as_treemap.rb - Acts as treemap rails plugin # # Copyright (c) 2006 by Andrew Bruno # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # module TM module Acts module Treemap def self.included(base) base.extend(ClassMethods) end module ClassMethods def acts_as_treemap(opts={}) include TM::Acts::Treemap::InstanceMethods extend TM::Acts::Treemap::SingletonMethods methods = "" if(!opts[:label].nil?) methods += "def label\n" methods += " self.#{opts[:label]}\n" methods += "end\n" end if(!opts[:size].nil?) methods += "def size\n" methods += " self.#{opts[:size]}\n" methods += "end\n" end if(!opts[:color].nil?) methods += "def color\n" methods += " self.#{opts[:color]}\n" methods += "end\n" end if(methods.length > 0) class_eval methods end end end module SingletonMethods end module InstanceMethods def depth return 0 if self.parent.nil? 1 + self.parent.depth end def leaf? return true if self.children.nil? !(self.children.size > 0) end def bounds @bounds end def bounds=(bounds) @bounds = bounds end end end end end