Class: Middleman::GnuplotExtension

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-gnuplot/extension.rb

Constant Summary collapse

@@base_dir =
""
@@plot_names =
[]

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ GnuplotExtension

Initializes the middleman-gnuplot extension.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

Instance Method Details

#plot_functions(functions = [], filename = nil, title = nil) ⇒ Object

Generates a plot via gnuplot using a given expression. The function must be provided as hash using the following fields:

Parameters:

  • functions (Array<Hash>) (defaults to: [])

    function definition hash

  • filename (String) (defaults to: nil)

    base filename for output file

  • title (String) (defaults to: nil)

    plot title

Options Hash (functions):

  • expression (String)

    expression hat can be processed by gnuplot (e.g. sin(x))

  • style (String)

    lines or points

  • color (String)

    RGB colro definition in hex format

  • title (String)

    name of trace



50
51
52
# File 'lib/middleman-gnuplot/extension.rb', line 50

def plot_functions (functions=[], filename=nil, title=nil)
    # stub method to enable documentation in yard
end

#plot_script(script, filename = nil, title = nil) ⇒ Object

Generates a plot directly from an existing gnuplot script Params:

Parameters:

  • script (String)

    path to the gnuplot script

  • filename (String) (defaults to: nil)

    for output file (can be overridden in script)

  • title (String) (defaults to: nil)

    plot title (can be overridden in script)



59
60
61
# File 'lib/middleman-gnuplot/extension.rb', line 59

def plot_script (script, filename=nil, title=nil)
    # stub method to enable documentation in yard
end

#random_filename_if_nil(filename = nil) ⇒ Object

Generates a random filename, if the given paramter is nil or empty Returns filename (given or random) Params.

filename

input filename



67
68
69
# File 'lib/middleman-gnuplot/extension.rb', line 67

def random_filename_if_nil (filename=nil)
    # stub method to enable documentation in yard
end