class GnuplotRB::Animation

Animation allows to create gif animation with given plots as frames. Possible frames: Plot, Splot, Multiplot. More about its usage in animation notebook.

Options

Animations has several specific options:

Animation ignores :term option and does not have methods like to_png or to_svg. One can also set animation any options related to Plot and they will be considered by all nested plots (if they does not override it with their own values).

Animation inherits all plot array handling methods from Multiplot and adds aliases for them (plots -> frames; update_frame! -> update_plot!; etc).

Public Instance Methods

plot(path = nil, **options) click to toggle source

This method creates a gif animation where frames are plots already contained by Animation object.

Options passed in plot have priority over those which were set before.

Inner options of Plots have the highest priority (except :term and :output which are ignored).

@param path [String] path to new gif file that will be created as a result @param options [Hash] see note about available options in top class documentation @return [nil] if path to output file given @return [String] gif file contents if no path to output file given

# File lib/gnuplotrb/animation.rb, line 55
def plot(path = nil, **options)
  options[:output] ||= path
  plot_options = mix_options(options) do |plot_opts, anim_opts|
    plot_opts.merge(term: ['gif', anim_opts])
  end.to_h
  need_output = plot_options[:output].nil?
  plot_options[:output] = Dir.gnuplot_tmpname('anim') if need_output
  terminal = Terminal.new
  multiplot(terminal, plot_options)
  # guaranteed wait for plotting to finish
  terminal.close
  if need_output
    result = File.binread(plot_options[:output])
    File.delete(plot_options[:output])
  else
    result = nil
  end
  result
end
to_iruby() click to toggle source

This method is used to embed gif animations into iRuby notebooks.

# File lib/gnuplotrb/animation.rb, line 84
def to_iruby
  gif_base64 = Base64.encode64(plot)
  ['text/html', "<img src=\"data:image/gif;base64, #{gif_base64}\">"]
end
to_specific_term(*_) click to toggle source

to_|term_name| methods are not supported by animation

# File lib/gnuplotrb/animation.rb, line 77
def to_specific_term(*_)
  fail 'Specific terminals are not supported by Animation'
end

Private Instance Methods

default_options() click to toggle source

Dafault options to be used for that plot

# File lib/gnuplotrb/animation.rb, line 93
def default_options
  {
    animate: {
      delay: 10,
      loop: 0,
      optimize: true
    }
  }
end
specific_keys() click to toggle source

This plot have some specific options which should be handled different way than others. Here are keys of this options.

# File lib/gnuplotrb/animation.rb, line 107
def specific_keys
  %w(
    animate
    size
    background
    transparent
    enhanced
    rounded
    butt
    linewidth
    dashlength
    tiny
    small
    medium
    large
    giant
    font
    fontscale
    crop
  )
end