class GerbilCharts::Surfaces::GraphElement

Graph - base for everything you place on the graph (all rectangular)

Constants

EXP_FILL
EXP_FIXED

constants

ORIENT_EAST
ORIENT_NORTH

orientations

ORIENT_NORTHEAST
ORIENT_NORTHWEST
ORIENT_OVERLAY
ORIENT_SOUTH
ORIENT_SOUTHEAST
ORIENT_SOUTHWEST
ORIENT_WEST

Attributes

bounds[R]
class[R]

public ro attributes

group[R]
lay_dimension[R]
lay_expand[R]
lay_orient[R]
parent[R]

Public Class Methods

new( opt={} ) click to toggle source
# File lib/gerbilcharts/surfaces/graph_element.rb, line 32
def initialize( opt={} )
    @lay_orient= opt[:orient] if defined? opt[:orient]
    @lay_expand= opt[:expand] if defined? opt[:expand]
    @lay_dimension= opt[:dim] if defined? opt[:dim]
    @bounds = Rect.new
    if opt[:width] and opt[:height]
      @bounds.from_wh(opt[:width],opt[:height]) 
    end
    if opt[:class]
      @class=opt[:class]
    end
    @group="default"
        @global_chart_options=opt
end

Public Instance Methods

align_to_anchor(anc) click to toggle source
# File lib/gerbilcharts/surfaces/graph_element.rb, line 126
def align_to_anchor(anc)
    case @lay_orient
    when ORIENT_SOUTH
          @bounds.left= anc.bounds.left
          @bounds.right=anc.bounds.right
    when ORIENT_NORTH
          @bounds.left= anc.bounds.left
          @bounds.right=anc.bounds.right
    when ORIENT_EAST
          @bounds.top= anc.bounds.top
          @bounds.bottom=anc.bounds.bottom
    when ORIENT_WEST
          @bounds.top= anc.bounds.top
          @bounds.bottom=anc.bounds.bottom
    when ORIENT_OVERLAY
          @bounds.initfrom anc.bounds
  end
end
get_global_option(optsym, defval) click to toggle source

query a global option, return the defval if option is not set

# File lib/gerbilcharts/surfaces/graph_element.rb, line 146
def get_global_option(optsym, defval)
              @global_chart_options.has_key?(optsym)? @global_chart_options[optsym]: defval 
end
isoverlay?() click to toggle source
# File lib/gerbilcharts/surfaces/graph_element.rb, line 59
def isoverlay?
  if defined? @lay_orient and @lay_orient == ORIENT_OVERLAY
    return true
  else
      return false
  end
end
munch(layrect) click to toggle source
# File lib/gerbilcharts/surfaces/graph_element.rb, line 93
def munch(layrect)
  raise "Element does not need to be laid out" if not needslayout?
  
  @bounds.initfrom(layrect)
  case @lay_orient
    when ORIENT_SOUTH
          @bounds.clip_b @lay_dimension
          layrect.crop_b @lay_dimension
    when ORIENT_NORTH
          @bounds.clip_t @lay_dimension
          layrect.crop_t @lay_dimension
    when ORIENT_EAST
          @bounds.clip_r @lay_dimension
          layrect.crop_r @lay_dimension
    when ORIENT_WEST
          @bounds.clip_l @lay_dimension
          layrect.crop_l @lay_dimension
    when ORIENT_SOUTHEAST
          @bounds.clip_b @lay_dimension
          @bounds.clip_r @lay_dimension
    when ORIENT_NORTHEAST
          @bounds.clip_t @lay_dimension
          @bounds.clip_r @lay_dimension
    when ORIENT_SOUTHWEST
          @bounds.clip_b @lay_dimension
          @bounds.clip_l @lay_dimension
    when ORIENT_NORTHWEST
          @bounds.clip_t @lay_dimension
          @bounds.clip_l @lay_dimension
  end
  return layrect
end
needslayout?() click to toggle source
# File lib/gerbilcharts/surfaces/graph_element.rb, line 47
def needslayout?
  if @lay_orient 
    return true
  else
    return false
  end
end
render(sdc) click to toggle source

setup SVG group element and call int_render

# File lib/gerbilcharts/surfaces/graph_element.rb, line 82
def render(sdc)
    sdc.newwin(@group, { :class => @class } ) do |sdc|
                        int_render(sdc)
        end
end
render_direct(sdc) click to toggle source

render direct - directly render SVG using builder for complex elements

# File lib/gerbilcharts/surfaces/graph_element.rb, line 89
def render_direct(sdc)
    raise "This Graph Element cannot render directly, incorrect usage"
end
scale_x(val,range) click to toggle source
# File lib/gerbilcharts/surfaces/graph_element.rb, line 67
def scale_x val,range
  return @bounds.left + @bounds.width * range.scale_factor(val)
end
scale_y(val,range) click to toggle source
# File lib/gerbilcharts/surfaces/graph_element.rb, line 71
def scale_y val,range
      return 0 if range.invalid?
  return @bounds.bottom - @bounds.height * range.scale_factor(val)
end
setbounds(rcbounds) click to toggle source
# File lib/gerbilcharts/surfaces/graph_element.rb, line 77
def setbounds rcbounds
  @bounds.initfrom rcbounds
end
setparent(par) click to toggle source
# File lib/gerbilcharts/surfaces/graph_element.rb, line 55
def setparent(par)
    @parent=par
end

Protected Instance Methods

color_for_id(id) click to toggle source

random but consistent color for ID depends on a lazily generated map of 100 colors

# File lib/gerbilcharts/surfaces/graph_element.rb, line 163
def color_for_id(id)
              @@mcolors ||= Array.new(100){ |t| "#%06x" % (rand * 0xffffff) }
              return @@mcolors[id]
end
max(a,b) click to toggle source

utility methods to derived classes

# File lib/gerbilcharts/surfaces/graph_element.rb, line 153
def max(a,b)
  return (a>b)?a:b
end
min(a,b) click to toggle source
# File lib/gerbilcharts/surfaces/graph_element.rb, line 157
def min(a,b)
  return (a<b)?a:b
end