Skip to content

Commit c9e8c71

Browse files
committed
Add barplot document
1 parent 54bc743 commit c9e8c71

1 file changed

Lines changed: 67 additions & 2 deletions

File tree

lib/unicode_plot/barplot.rb

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,57 @@ def print_row(out, row_index)
6969
end
7070
end
7171

72+
# @overload barplot(text, heights, xscale: nil, title: nil, xlabel: nil, ylabel: nil, labels: true, border: :barplot, margin: Plot::DEFAULT_MARGIN, padding: Plot::DEFAULT_PADDING, color: Barplot::DEFAULT_COLOR, width: Plot::DEFAULT_WIDTH, symbol: Barplot::DEFAULT_SYMBOL)
73+
#
74+
# Draws a horizontal barplot.
75+
#
76+
# @param text [Array<String>] The lables / captions of the bars.
77+
# @param heights [Array<Numeric>] The values / heights of the bars.
78+
# @param xscale [nil,:log,:ln,:log10,:lg,:log2,:lb,callable]
79+
# A function name symbol or callable object to transform the bar
80+
# length before plotting. This effectively scales the x-axis
81+
# without influencing the captions of the individual bars.
82+
# e.g. use `xscale: :log10` for logscale.
83+
# @param title
84+
# @param xlabel
85+
# @param ylabel
86+
# @param labels
87+
# @param border
88+
# @param margin
89+
# @param padding
90+
# @param color
91+
# @param width
92+
# @param symbol [String] Specifies the character that should be used
93+
# to render the bars.
94+
#
95+
# @return [Barplot] A plot object.
96+
#
97+
# @example Example usage of barplot on IRB:
98+
#
99+
# >> UnicodePlot.barplot(["Paris", "New York", "Moskau", "Madrid"],
100+
# [2.244, 8.406, 11.92, 3.165],
101+
# xlabel: "population [in mil]").render
102+
# ┌ ┐
103+
# Paris ┤■■■■■■ 2.244
104+
# New York ┤■■■■■■■■■■■■■■■■■■■■■■■ 8.406
105+
# Moskau ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11.92
106+
# Madrid ┤■■■■■■■■■ 3.165
107+
# └ ┘
108+
# population [in mil]
109+
# => nil
110+
#
111+
# @see Plot
112+
# @see histogram
113+
# @see Barplot
114+
#
115+
# @overload barplot(data, **kwargs)
116+
#
117+
# The different variation of barplot described above.
118+
#
119+
# @param data [Hash] A hash in which the keys will be used as `text` and
120+
# the values will be utilized as `heights`.
121+
# @param kwargs Optional keyword arguments same as ones described above.
122+
# @return [Barplot] A plot object.
72123
module_function def barplot(*args,
73124
width: Plot::DEFAULT_WIDTH,
74125
color: Barplot::DEFAULT_COLOR,
@@ -108,10 +159,24 @@ def print_row(out, row_index)
108159
plot
109160
end
110161

162+
# @overload barplot!(plot, text, heights)
163+
#
164+
# Draw additional bars on the given existing plot.
165+
#
166+
# @param plot [Barplot] the existing plot.
167+
# @return [Barplot] A plot object.
168+
#
169+
# @see barplot
170+
#
171+
# @overload barplot!(plot, data)
172+
#
173+
# The different variation of `barplot!` that takes the plotting data in a hash.
174+
#
175+
# @param plot [Barplot] the existing plot.
176+
# @return [Barplot] A plot object.
111177
module_function def barplot!(plot,
112178
*args,
113-
data: nil,
114-
**kw)
179+
data: nil)
115180
case args.length
116181
when 0
117182
data = Hash(data)

0 commit comments

Comments
 (0)