Class: GnuplotRB::Dataset
- Inherits:
-
Object
- Object
- GnuplotRB::Dataset
- Includes:
- Plottable
- Defined in:
- lib/gnuplotrb/staff/dataset.rb
Overview
Dataset keeps control of Datablock or String (some math functions like this ‘x*sin(x)’ or filename) and options related to original dataset in gnuplot (with, title, using etc).
Options
Dataset options are explained in gnuplot docs (pp. 80-101). Several common options:
-
with - set plot style for dataset (‘lines’, ‘points’, ‘impulses’ etc)
-
using - choose which columns of input data gnuplot should use. Takes String (using: ‘xtic(1):2:3’). If Daru::Dataframe passed one can use column names instead of numbers (using: ‘index:value1:summ’ - value1 and summ here are column names).
-
linewidth (lw) - integer line width
-
dashtype (dt) - takes pattern with dash style. Examples: ‘.. ’, ‘– ’, ‘.- ’.
-
pointtype (pt) - takes integer number of point type (works only when :with option is set to ‘points’). One can call Terminal::test(term_name) or Terminal#test in order to see which point types are supported by terminal.
Constant Summary collapse
- INIT_HANDLERS =
Hash of init handlers for data given in different containers.
Hash.new(:init_default).merge( String => :init_string, Datablock => :init_dblock )
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Data represented by this dataset.
Instance Method Summary collapse
-
#clone ⇒ Object
Own implementation of #clone.
-
#initialize(data, **options) ⇒ Dataset
constructor
Create new dataset out of given string with math function or filename.
-
#plot(*args) ⇒ Plot
Create new Plot object with only one Dataset given - self.
-
#to_s(terminal = nil, without_options: false) ⇒ String
Convert Dataset to string containing gnuplot dataset.
-
#update(data = nil, **options) ⇒ Object
Create new dataset with updated data and merged options.
-
#update!(data = nil, **options) ⇒ Object
Update Dataset with new data and options.
Methods included from Plottable
#method_missing, #option_name, #option_name!, #own_terminal, #respond_to?, #title, #title!, #to_canvas, #to_gif, #to_iruby, #to_png, #to_specific_term, #to_svg, #xrange, #xrange!, #yrange, #yrange!
Methods included from OptionHandling
option_to_string, #options, #options!, ruby_class_to_gnuplot, string_key, valid_terminal?, validate_terminal_options
Constructor Details
#initialize(data, **options) ⇒ Dataset
Create new dataset out of given string with math function or filename. If data isn’t a string it will create datablock to store data.
65 66 67 68 |
# File 'lib/gnuplotrb/staff/dataset.rb', line 65 def initialize(data, **) # run method by name send(INIT_HANDLERS[data.class], data, ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class GnuplotRB::Plottable
Instance Attribute Details
#data ⇒ Object (readonly)
Data represented by this dataset
24 25 26 |
# File 'lib/gnuplotrb/staff/dataset.rb', line 24 def data @data end |
Instance Method Details
#clone ⇒ Object
Own implementation of #clone. Creates new Dataset if data stored in datablock and calls super otherwise.
172 173 174 175 176 177 178 |
# File 'lib/gnuplotrb/staff/dataset.rb', line 172 def clone if @type == :datablock (@options) else super end end |
#plot(*args) ⇒ Plot
Create new Plot object with only one Dataset given - self. Calls #plot on created Plot. All arguments given to this #plot will be sent to Plot#plot instead.
193 194 195 |
# File 'lib/gnuplotrb/staff/dataset.rb', line 193 def plot(*args) Plot.new(self).plot(*args) end |
#to_s(terminal = nil, without_options: false) ⇒ String
Convert Dataset to string containing gnuplot dataset.
84 85 86 87 88 |
# File 'lib/gnuplotrb/staff/dataset.rb', line 84 def to_s(terminal = nil, without_options: false) result = "#{@type == :datablock ? @data.name(terminal) : @data} " result += unless result end |
#update(data = nil, **options) ⇒ Object
Create new dataset with updated data and merged options.
Given data is appended to existing. Data is updated only if Dataset stores it in Datablock. Method does nothing if no options given and data isn’t stored in in-memory Datablock.
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/gnuplotrb/staff/dataset.rb', line 119 def update(data = nil, **) if data && @type == :datablock new_datablock = @data.update(data) if new_datablock == @data () else self.class.new(new_datablock, ) end else () end end |
#update!(data = nil, **options) ⇒ Object
Update Dataset with new data and options.
Given data is appended to existing. Data is updated only if Dataset stores it in Datablock. Method does nothing if no options given and data isn’t stored in in-memory Datablock.
163 164 165 166 167 |
# File 'lib/gnuplotrb/staff/dataset.rb', line 163 def update!(data = nil, **) @data.update!(data) if data () self end |