Class: TChart::TeXBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/tchart/process/tex_builder.rb

Overview

Responsible for generating TikZ/TeX code for the various chart elements, including labels, bars, (grid)lines, etc. Also responsible for escaping TeX special characters, such as {, }, , etc., and for accumulating the generated code.

Instance Method Summary collapse

Constructor Details

#initializeTeXBuilder

Returns a new instance of TeXBuilder.



13
14
15
# File 'lib/tchart/process/tex_builder.rb', line 13

def initialize
  @output = StringIO.new
end

Instance Method Details

#bar(from, to, style) ⇒ Object



37
38
39
40
# File 'lib/tchart/process/tex_builder.rb', line 37

def bar(from, to, style)
  x_mid, width = to_tikz_coords(from.x, to.x)
  @output << "\\node [#{style}] at (#{f x_mid}mm, #{f from.y}mm) [minimum width = #{f width}mm] {};\n"
end

#begin_chartObject



17
18
19
# File 'lib/tchart/process/tex_builder.rb', line 17

def begin_chart
  @output << "\\tikzpicture\n"
end

#comment(text) ⇒ Object



25
26
27
# File 'lib/tchart/process/tex_builder.rb', line 25

def comment(text)
  @output << "% #{escape_tex_special_chars text.to_s}\n"
end

#end_chartObject



21
22
23
# File 'lib/tchart/process/tex_builder.rb', line 21

def end_chart
  @output << "\\endtikzpicture\n"
end

#gridline(from, to, style) ⇒ Object



29
30
31
# File 'lib/tchart/process/tex_builder.rb', line 29

def gridline(from, to, style)
  @output << "\\draw [#{style}] (#{f from.x}mm, #{f from.y}mm) -- (#{f to.x}mm, #{f to.y}mm);\n"
end

#label(coord, width, style, text) ⇒ Object



33
34
35
# File 'lib/tchart/process/tex_builder.rb', line 33

def label(coord, width, style, text)
  @output << "\\node [#{style}, text width = #{f width}mm] at (#{f coord.x}mm, #{f coord.y}mm) {#{escape_tex_special_chars text.to_s}};\n"
end

#to_sObject

> String



42
43
44
# File 'lib/tchart/process/tex_builder.rb', line 42

def to_s # => String
  @output.string
end