Class: TChart::Label

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

Overview

An x or y axis label on the chart. X axis labels will be years, e.g. “2014”, “2015”, etc., and y axis labels will be descriptions of the items being plotted, e.g. “Ruby”, “C”, “C++”, etc. Responsible for generating TikZ code to render the label.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(coord, width, style, text) ⇒ Label

Returns a new instance of Label.



31
32
33
34
35
36
# File 'lib/tchart/model/label.rb', line 31

def initialize(coord, width, style, text)
  @coord = coord
  @width = width
  @style = style
  @text = text
end

Instance Attribute Details

#coordObject (readonly)

Horizontal and vertical mid-point of label location.



11
12
13
# File 'lib/tchart/model/label.rb', line 11

def coord
  @coord
end

#styleObject (readonly)

TikZ style, must be defined in encompasing TeX document.



13
14
15
# File 'lib/tchart/model/label.rb', line 13

def style
  @style
end

#textObject (readonly)

Returns the value of attribute text.



14
15
16
# File 'lib/tchart/model/label.rb', line 14

def text
  @text
end

#widthObject (readonly)

Required for text justification.



12
13
14
# File 'lib/tchart/model/label.rb', line 12

def width
  @width
end

Class Method Details

.build_xlabel(coord, width, text) ⇒ Object

The difference between an x axis label and a y axis label is the TikZ style; x axis labels are generated with the style “xlabel”, y axis labels use “ylabel”. In the TeX document that embeds the chart, the x axis labels will usually be styled with centered text, whereas y axis labels will be left justified.



23
24
25
# File 'lib/tchart/model/label.rb', line 23

def self.build_xlabel(coord, width, text) # => Label
  Label.new(coord, width, "xlabel", text)
end

.build_ylabel(coord, width, text) ⇒ Object

> Label



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

def self.build_ylabel(coord, width, text) # => Label
  Label.new(coord, width, "ylabel", text)
end

Instance Method Details

#render(tex) ⇒ Object



38
39
40
# File 'lib/tchart/model/label.rb', line 38

def render(tex)
  tex.label @coord, @width, @style, @text
end