class Middleman::GnuplotExtension
Public Class Methods
Initializes the middleman-gnuplot extension.
# File lib/middleman-gnuplot/extension.rb, line 19 def initialize app, options_hash={}, &block super app.config[:gp_outdir] = options.gp_outdir app.config[:gp_tmpdir] = options.gp_tmpdir app.config[:gp_format] = options.gp_format @@base_dir = "./#{app.config[:gp_tmpdir]}/#{app.config[:images_dir]}/" FileUtils.mkdir_p "#{@@base_dir}/#{app.config[:gp_outdir]}/" term = Middleman::Gnuplot::get_gnuplot_term(options.gp_format) @@gp = Numo::Gnuplot.new @@gp.debug_on @@gp.set term:"#{term}" app.after_build do |builder| # Move generated plots to build dir FileUtils.cp_r @@base_dir, app.config[:build_dir] end end
Public Instance Methods
Prints a colored text message to terminal. Params.
text
-
the message body to be printed
type
-
:warning (yellow) or :error (red)
# File lib/middleman-gnuplot/extension.rb, line 266 def message text, type=:warning colString = '' colReset = "\033[0m" offset = "\033[14C" case type when :warning colString = "\033[1;33m" when :error colString = "\033[1;31m" end message = "#{colString}#{offset}middleman-gnuplot: #{text}#{colReset}" puts message end
Generates a plot via gnuplot using the given data array The data array should be an array of rows that contains arrays of cols. e.g. [[x1, y1, z1], [x2, y2, z2], [x3, y3, z3]] @param [Array] data see format above @param [Array<Hash>] series function definition hash @option series [Int] x Index of x-column in array (1, 2, …) @option series [Int] y Index of y-column in array (1, 2, …) @option series [String] style lines or points @option series [String] color RGB color definition in hex format @option series [String] title name of trace @param [String] filename base filename for output file @param [String] title plot title
# File lib/middleman-gnuplot/extension.rb, line 75 def plot_data data, series=nil, filename=nil, title=nil # stub method to enable documentation in yard end
Generates a plot via gnuplot using a given expression. The function must be provided as hash using the following fields: @param [Array<Hash>] functions function definition hash @option functions [String] expression expression hat can be processed by gnuplot (e.g. sin(x)) @option functions [String] style lines or points @option functions [String] color RGB color definition in hex format @option functions [String] title name of trace @param [String] filename base filename for output file @param [String] title plot title
# File lib/middleman-gnuplot/extension.rb, line 50 def plot_functions functions=[], filename=nil, title=nil # stub method to enable documentation in yard end
Generates a plot directly from an existing gnuplot script Params: @param [String] script path to the gnuplot script @param [String] filename for output file (can be overridden in script) @param [String] title plot title (can be overridden in script)
# File lib/middleman-gnuplot/extension.rb, line 59 def plot_script script, filename=nil, title=nil # stub method to enable documentation in yard end
Generates a random filename, if the given paramter is nil or empty Returns filename (given or random) @param [String] filename input filename @param [Int] length length of random filename
# File lib/middleman-gnuplot/extension.rb, line 83 def random_filename_if_nil filename=nil, length=6 # stub method to enable documentation in yard end
Adds a generated or given filename to the log array to ensure unique plot names, if no filename is given. Note: In case a given filename already exists - e.g. because a user adds the same filename twice - a warning is issued. Params.
filename
-
filename to be added to array
# File lib/middleman-gnuplot/extension.rb, line 254 def register_filename filename if @@plot_names.include?(filename) message "Warning: Filename #{filename} for plot already in use!", :warning end @@plot_names.append(filename) end