Class: RubyPost::BaseLabel

Inherits:
Object
  • Object
show all
Defined in:
lib/label.rb

Overview

Base class for labels in rubypost

Direct Known Subclasses

DotLabel, GraphLabel, Label

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Object

#compile

Constructor Details

#initialize(t = nil, p = nil) ⇒ BaseLabel

You can set the text in the constructor. At the moment you must use etex/btex for the string to display correct. This can be achieve using latex(“string”).



12
13
14
15
16
17
18
# File 'lib/label.rb', line 12

def initialize(t=nil, p=nil)
  @options = Array.new
  @text = t
  @position = p
  top
  self
end

Instance Attribute Details

#position=(value) ⇒ Object (writeonly)

Sets the attribute position

Parameters:

  • value

    the value to set the attribute position to.



6
7
8
# File 'lib/label.rb', line 6

def position=(value)
  @position = value
end

#text=(value) ⇒ Object (writeonly)

Sets the attribute text

Parameters:

  • value

    the value to set the attribute text to.



6
7
8
# File 'lib/label.rb', line 6

def text=(value)
  @text = value
end

Instance Method Details

#add_option(o) ⇒ Object



20
21
22
23
# File 'lib/label.rb', line 20

def add_option(o)
  @options.push(o)
  self
end

#botObject



83
84
85
# File 'lib/label.rb', line 83

def bot
  bottom
end

#bottomObject

place the text bellow the position. Wraps the metapost bot command for labels



79
80
81
82
# File 'lib/label.rb', line 79

def bottom
  @place = "bot"
  self
end

#bottom_leftObject

place the text to the bottom left the position. Wraps the metapost bot command for labels



126
127
128
129
# File 'lib/label.rb', line 126

def bottom_left
  @place = "llft"
  self
end

#bottom_rightObject

place the text to the bottom right the position. Wraps the metapost bot command for labels



146
147
148
149
# File 'lib/label.rb', line 146

def bottom_right
  @place = "lrt"
  self
end

#color(r, g, b) ⇒ Object

macro for setting the colour of the draw command. Spelt incorrectly.



52
53
54
# File 'lib/label.rb', line 52

def color(r,g,b)
  colour(r,g,b)
end

#colour(r, g, b) ⇒ Object

macro for setting the colour of the draw command



45
46
47
48
# File 'lib/label.rb', line 45

def colour(r,g,b)
  add_option(Colour.new(r,g,b))
  self
end

#compile_optionsObject

utility function to compile all the options



38
39
40
41
42
# File 'lib/label.rb', line 38

def compile_options
  str = String.new
  @options.each { |o| str = str + ' ' + o.compile }
  return str
end

#leftObject

place the text to the left the position. Wraps the metapost bot command for labels



106
107
108
109
# File 'lib/label.rb', line 106

def left
  @place = "lft"
  self
end

#lftObject



110
111
112
# File 'lib/label.rb', line 110

def lft
  left
end

#llftObject



130
131
132
# File 'lib/label.rb', line 130

def llft
  bottom_left
end

#lrtObject



150
151
152
# File 'lib/label.rb', line 150

def lrt
  bottom_right
end

#rightObject

place the text to the right of the position. Wraps the metapost bot command for labels



96
97
98
99
# File 'lib/label.rb', line 96

def right
  @place = "rt"
  self
end

#rotate(a) ⇒ Object

macro for rotating the label. This is the same as using add_option(Rotate.new(a))



72
73
74
75
# File 'lib/label.rb', line 72

def rotate(a)
  add_option(Rotate.new(a))
  self
end

#rtObject



100
101
102
# File 'lib/label.rb', line 100

def rt
  right
end

#scale(s) ⇒ Object

macro for scaling the draw command. This is the same as using add_option(Scale.new(s))



58
59
60
61
# File 'lib/label.rb', line 58

def scale(s)
  add_option(Scale.new(s))
  self
end

#set_position(d) ⇒ Object

set the text for this label. You can also use BaseLabel.position=



32
33
34
35
# File 'lib/label.rb', line 32

def set_position(d)
  @position = d
  self
end

#set_text(d) ⇒ Object

set the text for this label. You can also use BaseLabel.text=



26
27
28
29
# File 'lib/label.rb', line 26

def set_text(d)
  @text = d
  self
end

#topObject

place the text above the position. Wraps the metapost bot command for labels



89
90
91
92
# File 'lib/label.rb', line 89

def top
  @place = "top"
  self
end

#top_leftObject

place the text to the upper left of the position. Wraps the metapost bot command for labels



116
117
118
119
# File 'lib/label.rb', line 116

def top_left
  @place = "ulft"
  self
end

#top_rightObject

place the text to the upper right the position. Wraps the metapost bot command for labels



136
137
138
139
# File 'lib/label.rb', line 136

def top_right
  @place = "urt"
  self
end

#translate(x, y) ⇒ Object

macro for translating the label. This is the same as using add_option(Translate.new(x,y))



65
66
67
68
# File 'lib/label.rb', line 65

def translate(x,y)
  add_option(Translate.new(Pair.new(x,y)))
  self
end

#ulftObject



120
121
122
# File 'lib/label.rb', line 120

def ulft
  top_left
end

#urtObject



140
141
142
# File 'lib/label.rb', line 140

def urt
  top_right
end