Class: GerbilCharts::Surfaces::GraphElement

Inherits:
Object
  • Object
show all
Defined in:
lib/gerbilcharts/surfaces/graph_element.rb

Overview

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

Constant Summary collapse

EXP_FIXED =

constants

1
EXP_FILL =
2
ORIENT_NORTH =

orientations

1
ORIENT_SOUTH =
2
ORIENT_EAST =
3
ORIENT_WEST =
4
ORIENT_NORTHEAST =
5
ORIENT_NORTHWEST =
6
ORIENT_SOUTHEAST =
7
ORIENT_SOUTHWEST =
8
ORIENT_OVERLAY =
9

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}) ⇒ GraphElement

Returns a new instance of GraphElement.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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

Instance Attribute Details

#boundsObject (readonly)

Returns the value of attribute bounds.



26
27
28
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 26

def bounds
  @bounds
end

#classObject (readonly)

public ro attributes



24
25
26
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 24

def class
  @class
end

#groupObject (readonly)

Returns the value of attribute group.



25
26
27
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 25

def group
  @group
end

#lay_dimensionObject (readonly)

Returns the value of attribute lay_dimension.



29
30
31
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 29

def lay_dimension
  @lay_dimension
end

#lay_expandObject (readonly)

Returns the value of attribute lay_expand.



28
29
30
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 28

def lay_expand
  @lay_expand
end

#lay_orientObject (readonly)

Returns the value of attribute lay_orient.



27
28
29
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 27

def lay_orient
  @lay_orient
end

#parentObject (readonly)

Returns the value of attribute parent.



30
31
32
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 30

def parent
  @parent
end

Instance Method Details

#align_to_anchor(anc) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# 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) ⇒ Object

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



146
147
148
# 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?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# 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) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 47

def needslayout?
  if @lay_orient 
    return true
  else
    return false
  end
end

#render(sdc) ⇒ Object

setup SVG group element and call int_render



82
83
84
85
86
# 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) ⇒ Object

render direct - directly render SVG using builder for complex elements



89
90
91
# 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) ⇒ Object



67
68
69
# 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) ⇒ Object



71
72
73
74
# 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) ⇒ Object



77
78
79
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 77

def setbounds rcbounds
  @bounds.initfrom rcbounds
end

#setparent(par) ⇒ Object



55
56
57
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 55

def setparent(par)
    @parent=par
end