Skip to content

Commit 05aba46

Browse files
committed
update Plot and Splot docs for YARD
1 parent 53db728 commit 05aba46

File tree

3 files changed

+93
-50
lines changed

3 files changed

+93
-50
lines changed

lib/gnuplotrb/multiplot.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def initialize(*plots, **options)
2828
@plots = plots[0].is_a?(Hamster::Vector) ? plots[0] : Hamster::Vector.new(plots)
2929
@options = Hamster.hash(options)
3030
OptionHandling.validate_terminal_options(@options)
31+
yield(self) if block_given?
3132
end
3233

3334
##

lib/gnuplotrb/plot.rb

Lines changed: 89 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
module GnuplotRB
22
##
3-
# === Overview
43
# Class corresponding to simple 2D visualisation.
54
#
6-
# === Notebooks
5+
# == Notebooks
76
#
87
# * {Heatmaps}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/heatmaps.ipynb]
98
# * {Vector field}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/vector_field.ipynb]
109
# * {Math equations}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/math_plots.ipynb]
1110
# * {Histogram}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/histogram.ipynb]
1211
# * {Updating plots with new data}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/updating_data.ipynb]
1312
#
14-
# === Options
13+
# == Options
1514
# All possible options are exaplained in
16-
# {gnuplot docs}[http://www.gnuplot.info/docs_5.0/gnuplot.pdf](pp. 105-190).
15+
# {gnuplot docs}[http://www.gnuplot.info/docs_5.0/gnuplot.pdf] (pp. 105-190).
16+
#
1717
# Several common ones:
18+
#
1819
# * xrange(yrange, zrange, urange, vrange) - set range for a variable. Takes
1920
# Range (xrange: 0..100), or String (yrange: '[0:100]').
2021
# * title - plot's title. Takes String (title: 'Some new plot').
@@ -28,21 +29,22 @@ module GnuplotRB
2829
# due to existance of #to_<term_name> methods. One should use #to_png('file.png') instead of
2930
# passing { term: 'png', output: 'file.png' }.
3031
# Every option may be passed to constructor in order to create plot with it.
32+
#
3133
# Methods #options(several: options, ...) and bunch of #option_name(only_an: option) such as
3234
# #xrange, #using, #polar etc create new Plot object based on existing but with a new options.
33-
# See notebooks for examples.
35+
#
36+
# Methods with the same names ending with '!' or '=' ('plot.xrange!(1..3)',
37+
# 'plot.title = "New title"') are destructive and modify state of existing object just as
38+
# "Array#sort!" do with Array object. See notebooks for examples.
3439
class Plot
3540
include Plottable
3641
##
3742
# Array of datasets which are plotted by this object.
3843
attr_reader :datasets
3944
##
40-
# ====== Arguments
41-
# * *datasets* are either instances of Dataset class or
42-
# [data, **dataset_options] arrays from which Dataset may be created
43-
# * *options* will be considered as 'settable' options of gnuplot
44-
# ('set xrange [1:10]' for { xrange: 1..10 },
45-
# "set title 'plot'" for { title: 'plot' } etc).
45+
# @param *datasets [Sequence of Dataset or Array] either instances of Dataset class or
46+
# "[data, **dataset_options]"" arrays
47+
# @param options [Hash] see Plot top level doc for options examples
4648
def initialize(*datasets)
4749
# had to relace **options arg with this because in some cases
4850
# Daru::DataFrame was mentioned as hash and added to options
@@ -59,14 +61,13 @@ def initialize(*datasets)
5961
end
6062

6163
##
62-
# ====== Overview
63-
# This outputs plot to term (if given) or to this plot's own terminal.
64-
# ====== Arguments
65-
# * *term* - Terminal object to plot to
66-
# * *multiplot_part* - part of a multiplot. Option for inner usage
67-
# * *options* - will be considered as 'settable' options of gnuplot
68-
# ('set xrange [1:10]', 'set title 'plot'' etc)
69-
# Options passed here have priority over already existing.
64+
# Output plot to term (if given) or to this plot's own terminal.
65+
#
66+
# @param term [Terminal] Terminal object to plot to
67+
# @param :multiplot_part [Boolean] true if this plot is part of a multiplot. For inner use!
68+
# @param options [Hash] see options in Plot top level doc.
69+
# Options passed here have priority over already existing.
70+
# @return [Plot] self
7071
def plot(term = nil, multiplot_part: false, **options)
7172
fail ArgumentError, 'Empty plots are not supported!' if @datasets.empty?
7273
inner_opts = if multiplot_part
@@ -91,44 +92,68 @@ def plot(term = nil, multiplot_part: false, **options)
9192
alias_method :replot, :plot
9293

9394
##
94-
# ====== Overview
9595
# Create new Plot object where dataset at *position* will
9696
# be replaced with the new one created from it by updating.
97-
# ====== Arguments
98-
# * *position* - position of dataset which you need to update
97+
#
98+
# @param position [Integer] position of dataset which you need to update
9999
# (by default first dataset is updated)
100-
# * *data* - data to update dataset with
101-
# * *options* - options to update dataset with
102-
# ====== Example
100+
# @param data [#to_gnuplot_points] data to update dataset with
101+
# @param options [Hash] options to update dataset with, see Dataset top level doc
102+
#
103+
# @example
103104
# updated_plot = plot.update_dataset(data: [x1,y1], title: 'After update')
105+
# # plot IS NOT affected (if dataset did not store data in a file)
104106
def update_dataset(position = 0, data: nil, **options)
105107
old_ds = @datasets[position]
106108
new_ds = old_ds.update(data, options)
107109
new_ds.equal?(old_ds) ? self : replace_dataset(position, new_ds)
108110
end
109111

112+
##
113+
# Updates existing Plot object by replacing dataset at *position*
114+
# with the new one created from it by updating.
115+
#
116+
# @param position [Integer] position of dataset which you need to update
117+
# (by default first dataset is updated)
118+
# @param data [#to_gnuplot_points] data to update dataset with
119+
# @param options [Hash] options to update dataset with, see Dataset top level doc
120+
#
121+
# @example
122+
# plot.update_dataset!(data: [x1,y1], title: 'After update')
123+
# # plot IS affected anyway
110124
def update_dataset!(position = 0, data: nil, **options)
111125
@datasets[position].update!(data, options)
112126
self
113127
end
114128

115129
##
116-
# ====== Overview
117130
# Create new Plot object where dataset at *position* will
118131
# be replaced with the given one.
119-
# ====== Arguments
120-
# * *position* - position of dataset which you need to update
132+
#
133+
# @param position [Integer] position of dataset which you need to replace
121134
# (by default first dataset is replaced)
122-
# * *dataset* - dataset to replace the old one. You can also
123-
# give here [data, **dataset_options] array from
124-
# which Dataset may be created.
125-
# ====== Example
135+
# @param dataset [Dataset, Array] dataset to replace the old one. You can also
136+
# give here "[data, **dataset_options]"" array from which Dataset may be created.
137+
# @example
126138
# sinx = Plot.new('sin(x)')
127139
# cosx = sinx.replace_dataset(['cos(x)'])
140+
# # sinx IS NOT affected
128141
def replace_dataset(position = 0, dataset)
129142
self.class.new(@datasets.set(position, dataset_from_any(dataset)), @options)
130143
end
131144

145+
##
146+
# Updates existing Plot object by replacing dataset at *position*
147+
# with the given one.
148+
#
149+
# @param position [Integer] position of dataset which you need to replace
150+
# (by default first dataset is replaced)
151+
# @param dataset [Dataset, Array] dataset to replace the old one. You can also
152+
# give here "[data, **dataset_options]"" array from which Dataset may be created.
153+
# @example
154+
# sinx = Plot.new('sin(x)')
155+
# sinx.replace_dataset!(['cos(x)'])
156+
# # sinx IS affected
132157
def replace_dataset!(position = 0, dataset)
133158
@datasets = @datasets.set(position, dataset_from_any(dataset))
134159
self
@@ -137,18 +162,19 @@ def replace_dataset!(position = 0, dataset)
137162
alias_method :[]=, :replace_dataset!
138163

139164
##
140-
# ====== Overview
141165
# Create new Plot object where given datasets will
142166
# be inserted into dataset list before given position
143167
# (position = 0 by default).
144-
# ====== Arguments
145-
# * *position* - position where to insert given datasets
146-
# * *datasets* - sequence of datasets to add
147-
# ====== Example
168+
#
169+
# @param position [Integer] position of dataset BEFORE which datasets will be placed.
170+
# 0 by default.
171+
# @param *datasets [ Sequence of Dataset or Array] datasets to insert
172+
# @example
148173
# sinx = Plot.new('sin(x)')
149174
# sinx_and_cosx_with_expx = sinx.add(['cos(x)'], ['exp(x)'])
150175
#
151176
# cosx_and_sinx = sinx << ['cos(x)']
177+
# # sinx IS NOT affected in both cases
152178
def add_datasets(*datasets)
153179
datasets.map! { |ds| ds.is_a?(Numeric) ? ds : dataset_from_any(ds) }
154180
# first element is position where to add datasets
@@ -159,6 +185,17 @@ def add_datasets(*datasets)
159185
alias_method :add_dataset, :add_datasets
160186
alias_method :<<, :add_datasets
161187

188+
##
189+
# Updates existing Plot object by inserting given datasets
190+
# into dataset list before given position (position = 0 by default).
191+
#
192+
# @param position [Integer] position of dataset BEFORE which datasets will be placed.
193+
# 0 by default.
194+
# @param *datasets [ Sequence of Dataset or Array] datasets to insert
195+
# @example
196+
# sinx = Plot.new('sin(x)')
197+
# sinx.add!(['cos(x)'], ['exp(x)'])
198+
# # sinx IS affected
162199
def add_datasets!(*datasets)
163200
datasets.map! { |ds| ds.is_a?(Numeric) ? ds : dataset_from_any(ds) }
164201
# first element is position where to add datasets
@@ -170,28 +207,37 @@ def add_datasets!(*datasets)
170207
alias_method :add_dataset!, :add_datasets!
171208

172209
##
173-
# ====== Overview
174210
# Create new Plot object where dataset at given position
175211
# will be removed from dataset list.
176-
# ====== Arguments
177-
# * *position* - position of dataset that should be
212+
#
213+
# @param position [Integer] position of dataset that should be
178214
# removed (by default last dataset is removed)
179-
# ====== Example
215+
# @example
180216
# sinx_and_cosx = Plot.new('sin(x)', 'cos(x)')
181217
# sinx = sinx_and_cosx.remove_dataset
182218
# cosx = sinx_and_cosx.remove_dataset(0)
219+
# # sinx_and_cosx IS NOT affected in both cases
183220
def remove_dataset(position = -1)
184221
self.class.new(@datasets.delete_at(position), @options)
185222
end
186223

224+
##
225+
# Updates existing Plot object by removing dataset at given position.
226+
#
227+
# @param position [Integer] position of dataset that should be
228+
# removed (by default last dataset is removed)
229+
# @example
230+
# sinx_and_cosx = Plot.new('sin(x)', 'cos(x)')
231+
# sinx_and_cosx!.remove_dataset
232+
# sinx_and_cosx!.remove_dataset
233+
# # sinx_and_cosx IS affected and now is empty
187234
def remove_dataset!(position = -1)
188235
@datasets = @datasets.delete_at(position)
189236
self
190237
end
191238

192239
##
193-
# ====== Overview
194-
# The same as Plot#datasets[args]
240+
# The same as #datasets[*args]
195241
def [](*args)
196242
@datasets[*args]
197243
end

lib/gnuplotrb/splot.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
module GnuplotRB
22
##
3-
# === Overview
43
# Splot class correspond to simple 3D visualisation.
54
# Most of Plot's docs are right for Splot too.
65
#
76
# Examples of usage are in
87
# {a notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/3d_plot.ipynb]
98
class Splot < Plot
109
##
11-
# ==== Arguments
12-
# * *datasets* are either instances of Dataset class or
13-
# [data, **dataset_options] arrays
14-
# * *options* will be considered as 'settable' options of gnuplot
15-
# ('set xrange [1:10]' for { xrange: 1..10 }, "set title 'plot'"
16-
# for { title: 'plot' } etc)
10+
# @param *datasets [Sequence of Dataset or Array] either instances of Dataset class or
11+
# "[data, **dataset_options]"" arrays
12+
# @param options [Hash] see Plot top level doc for options examples
1713
def initialize(*datasets, **options)
1814
super
1915
@cmd = 'splot '

0 commit comments

Comments
 (0)