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_data(data, series = nil, filename = nil, title = nil) ⇒ Object

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]]

Options Hash (series):

  • x (Int)

    Index of x-column in array (1, 2, …)

  • y (Int)

    Index of y-column in array (1, 2, …)

  • style (String)

    lines or points

  • color (String)

    RGB color definition in hex format

  • title (String)

    name of trace



75
76
77
# 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

#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:

Options Hash (functions):

  • expression (String)

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

  • style (String)

    lines or points

  • color (String)

    RGB color 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:



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)



82
83
84
# File 'lib/middleman-gnuplot/extension.rb', line 82

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