Class: Flotr::Plot
- Inherits:
-
Object
- Object
- Flotr::Plot
- Defined in:
- lib/flotr.rb
Overview
The Plot object. Serves as a container for the data series (Data objects)
and for the plot options. Call the plot/show methods to generate the
plot file Flotr::OUTPUT_FILE.
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#height ⇒ Object
Returns the value of attribute height.
-
#label ⇒ Object
Returns the value of attribute label.
-
#options ⇒ Object
Returns the value of attribute options.
-
#output_file ⇒ Object
Returns the value of attribute output_file.
-
#series ⇒ Object
Returns the value of attribute series.
-
#template ⇒ Object
Returns the value of attribute template.
-
#title ⇒ Object
Returns the value of attribute title.
-
#width ⇒ Object
Returns the value of attribute width.
-
#xlim ⇒ Object
Returns the value of attribute xlim.
-
#ylim ⇒ Object
Returns the value of attribute ylim.
Instance Method Summary collapse
-
#<<(serie) ⇒ Object
Adds a Data serie to the Plot.
-
#initialize(title = "Flotr Plot") ⇒ Plot
constructor
Creates a new plot.
-
#inspect ⇒ Object
Provides a JavaScript-formatted description of the all the series.
-
#save ⇒ Object
(also: #plot)
Generates the html file containing the plot and fires up a preferred browser window with the plot loaded.
- #show ⇒ Object
-
#std_template ⇒ Object
Returns the currently selected standard template, or nil if the active template is a custom one.
-
#std_template=(template) ⇒ Object
Selects the active template.
-
#std_templates ⇒ Object
Lists the available standard templates.
Constructor Details
#initialize(title = "Flotr Plot") ⇒ Plot
Creates a new plot. You only have to provide a title for the plot, that
will (probably) be used as a page title by the active template.
88 89 90 91 92 93 94 95 96 |
# File 'lib/flotr.rb', line 88 def initialize(title = "Flotr Plot") @title = title @template = "#{BASENAME}/#{STD_TEMPLATE}" @series = [] @options = {} @width, @height = 600, 300 @label = @xlim = @ylim = {} @output_file = OUTPUT_FILE end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
80 81 82 |
# File 'lib/flotr.rb', line 80 def comment @comment end |
#height ⇒ Object
Returns the value of attribute height.
81 82 83 |
# File 'lib/flotr.rb', line 81 def height @height end |
#label ⇒ Object
Returns the value of attribute label.
82 83 84 |
# File 'lib/flotr.rb', line 82 def label @label end |
#options ⇒ Object
Returns the value of attribute options.
80 81 82 |
# File 'lib/flotr.rb', line 80 def @options end |
#output_file ⇒ Object
Returns the value of attribute output_file.
80 81 82 |
# File 'lib/flotr.rb', line 80 def output_file @output_file end |
#series ⇒ Object
Returns the value of attribute series.
80 81 82 |
# File 'lib/flotr.rb', line 80 def series @series end |
#template ⇒ Object
Returns the value of attribute template.
80 81 82 |
# File 'lib/flotr.rb', line 80 def template @template end |
#title ⇒ Object
Returns the value of attribute title.
80 81 82 |
# File 'lib/flotr.rb', line 80 def title @title end |
#width ⇒ Object
Returns the value of attribute width.
81 82 83 |
# File 'lib/flotr.rb', line 81 def width @width end |
#xlim ⇒ Object
Returns the value of attribute xlim.
82 83 84 |
# File 'lib/flotr.rb', line 82 def xlim @xlim end |
#ylim ⇒ Object
Returns the value of attribute ylim.
82 83 84 |
# File 'lib/flotr.rb', line 82 def ylim @ylim end |
Instance Method Details
#<<(serie) ⇒ Object
Adds a Data serie to the Plot. It also returns self, so multiple calls
can be concatenated as in plot << series1 << series2 << series3.
157 158 159 160 161 162 163 |
# File 'lib/flotr.rb', line 157 def <<(serie) if serie.instance_of? Data @series << serie else raise ArgumentError end end |
#inspect ⇒ Object
Provides a JavaScript-formatted description of the all the series.
168 169 170 171 |
# File 'lib/flotr.rb', line 168 def inspect data = @series.map {|s| s.inspect} "[ #{data*', '} ]" end |
#save ⇒ Object Also known as: plot
Generates the html file containing the plot and fires up a preferred
browser window with the plot loaded.
132 133 134 135 136 137 |
# File 'lib/flotr.rb', line 132 def save eruby = Erubis::Eruby.new(File.read(@template)) File.open(@output_file, 'w') do |f| f.print eruby.result(binding()) end end |
#show ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/flotr.rb', line 141 def show self.save case RUBY_PLATFORM when /darwin/ system "open \"#{@output_file}\"" when /mswin/ system "start #{@output_file}" else puts "open #{@output_file} in your preferred browser" end end |
#std_template ⇒ Object
Returns the currently selected standard template, or nil if the active
template is a custom one. Use Plot#template=(full/path/to/template.rhtml)
to set a custom template.
120 121 122 123 124 125 126 |
# File 'lib/flotr.rb', line 120 def std_template if File.dirname(@template) == BASENAME File.basename(@template, ".rhtml") else nil end end |
#std_template=(template) ⇒ Object
Selects the active template. It has to be one of those included in the
result of the std_templates method.
110 111 112 113 |
# File 'lib/flotr.rb', line 110 def std_template=(template) raise "Template #{template} does not exist!" unless self.std_templates.include?(template) @template = "#{BASENAME}/#{template}.rhtml" end |
#std_templates ⇒ Object
Lists the available standard templates. These are .rhtml files located in
the lib floder inside the gem. The extension .rhtml is dropped.
102 103 104 |
# File 'lib/flotr.rb', line 102 def std_templates Dir.glob("#{BASENAME}/*.rhtml").map {|f| File.basename(f, ".rhtml")} end |