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.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/middleman-gnuplot/extension.rb', line 20

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

Parameters:

  • data (Array)

    see format above

  • series (Array<Hash>) (defaults to: nil)

    function definition hash

  • filename (String) (defaults to: nil)

    base filename for output file

  • title (String) (defaults to: nil)

    plot title

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



79
80
81
# File 'lib/middleman-gnuplot/extension.rb', line 79

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

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 color definition in hex format

  • title (String)

    name of trace



54
55
56
# File 'lib/middleman-gnuplot/extension.rb', line 54

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)



63
64
65
# File 'lib/middleman-gnuplot/extension.rb', line 63

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

#random_filename_if_nil(filename = nil, length = 6) ⇒ Object

Parameters:

  • length (Int) (defaults to: 6)

    length of random filename



87
88
89
# File 'lib/middleman-gnuplot/extension.rb', line 87

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