Skip to content

Commit bec4c21

Browse files
committed
update multiplot docs for YARD
1 parent c39f507 commit bec4c21

File tree

1 file changed

+83
-47
lines changed

1 file changed

+83
-47
lines changed

lib/gnuplotrb/multiplot.rb

Lines changed: 83 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,43 @@
11
module GnuplotRB
22
##
3-
# === Overview
43
# Multiplot allows to place several plots on one layout.
54
# It's usage is covered in
65
# {multiplot notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/multiplot_layout.ipynb].
76
#
8-
# === Options
9-
# Most of Multiplot options are the same as in Plot.
7+
# == Options
8+
# Most of Multiplot options are the same as in Plot so one can also set any options related
9+
# to Plot and they will be considered by all nested plots
10+
# (if they does not override it with their own values).
11+
#
1012
# There are only 2 specific options:
1113
# * title - set title for the whole layout (above all the plots)
1214
# * layout - set layout size, examples:
13-
# { layout : [1, 3] } - 3 plots, 1 row, 3 columns
14-
# { layout : [2, 2] } - 4 plots, 2 rows, 2 columns
15+
# { layout : [1, 3] } # 3 plots, 1 row, 3 columns
16+
# { layout : [2, 2] } # 4 plots, 2 rows, 2 columns
1517
class Multiplot
1618
include Plottable
1719
##
18-
# Array of plots contained by this object.
20+
# @return [Array] Array of plots contained by this object
1921
attr_reader :plots
2022

2123
##
22-
# ====== Arguments
23-
# * *plots* are Plot or Splot objects which should be placed
24-
# on this multiplot layout
25-
# * *options* will be considered as 'settable' options of gnuplot
26-
# ('set xrange [1:10]' for { xrange: 1..10 } etc) just as in Plot.
27-
# Special options of Multiplot are :layout and :title.
24+
# @param plots [Plot, Splot, Hamster::Vector] Hamster vector (or just sequence) with Plot
25+
# or Splot objects which should be placed on this multiplot layout
26+
# @param options [Hash] see options in top class docs
2827
def initialize(*plots, **options)
2928
@plots = plots[0].is_a?(Hamster::Vector) ? plots[0] : Hamster::Vector.new(plots)
3029
@options = Hamster.hash(options)
3130
OptionHandling.validate_terminal_options(@options)
3231
end
3332

3433
##
35-
# ====== Overview
36-
# This outputs all the plots to term (if given) or to this
37-
# Multiplot's own terminal.
38-
# ====== Arguments
39-
# * *term* - Terminal to plot to
40-
# * *options* - will be considered as 'settable' options of gnuplot
41-
# ('set xrange [1:10]', 'set title 'plot'' etc)
42-
# Options passed here have priority over already existing.
43-
# Inner options of Plots have the highest priority (except
44-
# :term and :output which are ignored in this case).
34+
# Output all the plots to term (if given) or to this Multiplot's own terminal.
35+
#
36+
# @param term [Terminal] Terminal to plot to
37+
# @param multiplot_part [Boolean] placeholder, does not really needed and should not be used
38+
# @param options [Hash] see options in top class docs.
39+
# Options passed here have priority over already set.
40+
# @return [Multiplot] self
4541
def plot(term = nil, multiplot_part: false, **options)
4642
plot_options = mix_options(options) do |plot_opts, mp_opts|
4743
plot_opts.merge(multiplot: mp_opts.to_h)
@@ -59,21 +55,25 @@ def plot(term = nil, multiplot_part: false, **options)
5955
end
6056

6157
##
62-
# ====== Overview
63-
# Create new Multiplot object where plot (Plot or Splot object)
64-
# at *position* will
58+
# Create new updated Multiplot object
59+
# where plot (Plot or Splot object) at *position* will
6560
# be replaced with the new one created from it by updating.
6661
# To update a plot you can pass some options for it or a
6762
# block, that should take existing plot (with new options if
6863
# you gave them) and return a plot too.
69-
# ====== Arguments
70-
# * *position* - position of plot which you need to update
64+
#
65+
# Method yields new created Plot or Splot to allow you update it manually.
66+
#
67+
# @param position [Integer] position of plot which you need to update
7168
# (by default first plot is updated)
72-
# * *options* - options to update plot with
73-
# * *&block* - method also may take a block which returns a plot
74-
# ====== Example
69+
# @param options [Hash] options to set into updated plot
70+
# @return [Multiplot] - self
71+
# @yieldparam plot [Plot, Splot] a new plot
72+
# @yieldreturn [Plot, Splot] changed plot
73+
# @example
7574
# mp = Multiplot.new(Plot.new('sin(x)'), Plot.new('cos(x)'), layout: [2,1])
76-
# updated_mp = mp.update_plot(title: 'Sin(x) and Exp(x)') { |sinx| sinx.add('exp(x)') }
75+
# updated_mp = mp.update_plot(title: 'Sin(x) and Exp(x)') { |sinx| sinx.add!('exp(x)') }
76+
# # mp IS NOT affected
7777
def update_plot(position = 0, **options)
7878
return self unless block_given? if options.empty?
7979
replacement = @plots[position].options(options)
@@ -83,6 +83,14 @@ def update_plot(position = 0, **options)
8383

8484
alias_method :update, :update_plot
8585

86+
##
87+
# Destructive version of #update_plot.
88+
#
89+
# @return [Multiplot] - self
90+
# @example
91+
# Multiplot.new(Plot.new('sin(x)'), Plot.new('cos(x)'), layout: [2,1])
92+
# mp.update_plot!(title: 'Sin(x) and Exp(x)') { |sinx| sinx.add!('exp(x)') }
93+
# # mp IS affected
8694
def update_plot!(position = 0, **options)
8795
return self unless block_given? if options.empty?
8896
replacement = @plots[position].options!(options)
@@ -93,22 +101,31 @@ def update_plot!(position = 0, **options)
93101
alias_method :update!, :update_plot!
94102

95103
##
96-
# ====== Overview
97104
# Create new Multiplot object where plot (Plot or Splot object)
98105
# at *position* will be replaced with the given one.
99-
# ====== Arguments
100-
# * *position* - position of plot which you need to update
101-
# (by default first plot is updated)
102-
# * *plot* - replacement for existing plot
103-
# ====== Example
106+
#
107+
# @param position [Integer] position of plot which you need to replace
108+
# (by default first plot is replace)
109+
# @param plot [Plot, Splot] replacement
110+
# @return [Multiplot] - self
111+
# @example
104112
# mp = Multiplot.new(Plot.new('sin(x)'), Plot.new('cos(x)'), layout: [2,1])
105113
# mp_with_replaced_plot = mp.replace_plot(Plot.new('exp(x)', title: 'exp instead of sin'))
114+
# # mp IS NOT affected
106115
def replace_plot(position = 0, plot)
107116
self.class.new(@plots.set(position, plot), @options)
108117
end
109118

110119
alias_method :replace, :replace_plot
111120

121+
##
122+
# Destructive version of #replace_plot.
123+
#
124+
# @return [Multiplot] - self
125+
# @example
126+
# mp = Multiplot.new(Plot.new('sin(x)'), Plot.new('cos(x)'), layout: [2,1])
127+
# mp.replace_plot!(Plot.new('exp(x)', title: 'exp instead of sin'))
128+
# # mp IS affected
112129
def replace_plot!(position = 0, plot)
113130
@plots = @plots.set(position, plot)
114131
self
@@ -118,15 +135,17 @@ def replace_plot!(position = 0, plot)
118135
alias_method :[]=, :replace_plot!
119136

120137
##
121-
# ====== Overview
122138
# Create new Multiplot with given *plots* added before plot at given *position*.
123139
# (by default it adds plot at the front).
124-
# ====== Arguments
125-
# * *position* - position before which you want to add a plot
126-
# * *plots* - sequence of plots you want to add
127-
# ====== Example
140+
#
141+
# @param position [Integer] position of plot which you need to replace
142+
# (by default first plot is replace)
143+
# @param plots [Sequence of Plot or Splot] plots you want to add
144+
# @return [Multiplot] - self
145+
# @example
128146
# mp = Multiplot.new(Plot.new('sin(x)'), Plot.new('cos(x)'), layout: [2,1])
129147
# enlarged_mp = mp.add_plots(Plot.new('exp(x)')).layout([3,1])
148+
# # mp IS NOT affected
130149
def add_plots(*plots)
131150
plots.unshift(0) unless plots[0].is_a?(Numeric)
132151
self.class.new(@plots.insert(*plots), @options)
@@ -136,6 +155,14 @@ def add_plots(*plots)
136155
alias_method :<<, :add_plots
137156
alias_method :add, :add_plots
138157

158+
##
159+
# Destructive version of #add_plots.
160+
#
161+
# @return [Multiplot] - self
162+
# @example
163+
# mp = Multiplot.new(Plot.new('sin(x)'), Plot.new('cos(x)'), layout: [2,1])
164+
# mp.add_plots!(Plot.new('exp(x)')).layout([3,1])
165+
# # mp IS affected
139166
def add_plots!(*plots)
140167
plots.unshift(0) unless plots[0].is_a?(Numeric)
141168
@plots = @plots.insert(*plots)
@@ -146,20 +173,30 @@ def add_plots!(*plots)
146173
alias_method :add!, :add_plots!
147174

148175
##
149-
# ====== Overview
150176
# Create new Multiplot without plot at given position
151177
# (by default last plot is removed).
152-
# ====== Arguments
153-
# * *position* - position of plot you want to remove
154-
# ====== Example
178+
#
179+
# @param position [Integer] position of plot which you need to remove
180+
# (by default last plot is removed)
181+
# @return [Multiplot] - self
182+
# @example
155183
# mp = Multiplot.new(Plot.new('sin(x)'), Plot.new('cos(x)'), layout: [2,1])
156184
# mp_with_only_cos = mp.remove_plot(0)
185+
# # mp IS NOT affected
157186
def remove_plot(position = -1)
158187
self.class.new(@plots.delete_at(position), @options)
159188
end
160189

161190
alias_method :remove, :remove_plot
162191

192+
##
193+
# Destructive version of #remove_plot.
194+
#
195+
# @return [Multiplot] - self
196+
# @example
197+
# mp = Multiplot.new(Plot.new('sin(x)'), Plot.new('cos(x)'), layout: [2,1])
198+
# mp.remove_plot!(0)
199+
# # mp IS affected
163200
def remove_plot!(position = -1)
164201
@plots = @plots.delete_at(position)
165202
self
@@ -168,7 +205,6 @@ def remove_plot!(position = -1)
168205
alias_method :remove!, :remove_plot!
169206

170207
##
171-
# ====== Overview
172208
# Equal to #plots[*args]
173209
def [](*args)
174210
@plots[*args]

0 commit comments

Comments
 (0)