Class: GerbilCharts::Surfaces::GraphElement
- Inherits:
-
Object
- Object
- GerbilCharts::Surfaces::GraphElement
- Defined in:
- lib/gerbilcharts/surfaces/graph_element.rb
Overview
Graph - base for everything you place on the graph (all rectangular)
Direct Known Subclasses
Axis, Chart, DetailedLegend, Grid, Legend, LinkPivots, MarkBand, Panel, Surface, Tracker
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
-
#bounds ⇒ Object
readonly
Returns the value of attribute bounds.
-
#class ⇒ Object
readonly
public ro attributes.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#lay_dimension ⇒ Object
readonly
Returns the value of attribute lay_dimension.
-
#lay_expand ⇒ Object
readonly
Returns the value of attribute lay_expand.
-
#lay_orient ⇒ Object
readonly
Returns the value of attribute lay_orient.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #align_to_anchor(anc) ⇒ Object
-
#get_global_option(optsym, defval) ⇒ Object
query a global option, return the defval if option is not set.
-
#initialize(opt = {}) ⇒ GraphElement
constructor
A new instance of GraphElement.
- #isoverlay? ⇒ Boolean
- #munch(layrect) ⇒ Object
- #needslayout? ⇒ Boolean
-
#render(sdc) ⇒ Object
setup SVG group element and call int_render.
-
#render_direct(sdc) ⇒ Object
render direct - directly render SVG using builder for complex elements.
- #scale_x(val, range) ⇒ Object
- #scale_y(val, range) ⇒ Object
- #setbounds(rcbounds) ⇒ Object
- #setparent(par) ⇒ Object
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] = 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" =opt end |
Instance Attribute Details
#bounds ⇒ Object (readonly)
Returns the value of attribute bounds.
26 27 28 |
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 26 def bounds @bounds end |
#class ⇒ Object (readonly)
public ro attributes
24 25 26 |
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 24 def class @class end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
25 26 27 |
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 25 def group @group end |
#lay_dimension ⇒ Object (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_expand ⇒ Object (readonly)
Returns the value of attribute lay_expand.
28 29 30 |
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 28 def end |
#lay_orient ⇒ Object (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 |
#parent ⇒ Object (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) .has_key?(optsym)? [optsym]: defval end |
#isoverlay? ⇒ Boolean
59 60 61 62 63 64 65 |
# File 'lib/gerbilcharts/surfaces/graph_element.rb', line 59 def 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
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 |