Skip to content

Commit 225937c

Browse files
authored
Merge pull request #45 from red-data-tools/yard
Use YARD
2 parents ef94340 + d893ead commit 225937c

7 files changed

Lines changed: 94 additions & 49 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ jobs:
5252

5353
- run: bundle install --jobs 4 --retry 3
5454

55-
- run: rake
55+
- run: bundle exec rake
5656

57-
- run: rake build
57+
- run: bundle exec rake build
5858

5959
- run: gem install pkg/*.gem

.yardopts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--output-dir doc/reference
2+
--markup markdown
3+
--no-private
4+
lib/**/*.rb
5+
-
6+
doc/text/*

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
source "https://rubygems.org/"
22

33
gemspec
4+
5+
# Temporary use this for module_function decorator support
6+
gem "yard", github: "mrkn/yard", branch: "module_function_decorator"

Rakefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
require "bundler/gem_helper"
2+
require "yard"
23

34
base_dir = File.expand_path("..", __FILE__)
45
helper = Bundler::GemHelper.new(base_dir)
56
helper.install
6-
spec = helper.gemspec
77

88
desc "Run test"
99
task :test do
1010
ruby("test/run-test.rb")
1111
end
1212

1313
task default: :test
14+
15+
YARD::Rake::YardocTask.new do |task|
16+
end

lib/unicode_plot/lineplot.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@ module UnicodePlot
44
class Lineplot < GridPlot
55
end
66

7+
# @overload lineplot([x], y, name: "", canvas: :braille, title: "", xlabel: "", ylabel: "", labels: true, border: :solid, margin: Plot::DEFAULT_MARGIN, padding: Plot::DEFAULT_PADDING, color: :auto, width: Plot::DEFAULT_WIDTH, height: GridPlot::DEFAULT_HEIGHT, xlim: [0, 0], ylim: [0, 0], canvas: :braille, grid: true)
8+
#
9+
# Draws a path through the given points on a new canvas.
10+
#
11+
# The first (optional) array `x` should contain the horizontal positions for all the points along the path.
12+
# The second array `y` should then contain the corresponding vertical positions respectively.
13+
# This means that the two vectors must be of the same length and ordering.
14+
#
15+
# @param x [Array<Numeric>] Optional. The horizontal position for each point. If omitted, the axes of `y` will be used as `x`.
16+
# @param y [Array<Numeric>] The vertical position for each point.
17+
# @param name [String] Annotation of the current drawing to be displayed on the right.
18+
# @param title
19+
# @param xlabel
20+
# @param ylabel
21+
# @param labels
22+
# @param border
23+
# @param margin
24+
# @param padding
25+
# @param color
26+
# @param width
27+
# @param height
28+
# @param xlim
29+
# @param ylim
30+
# @param canvas [Symbol] The type of canvas that should be used for drawing.
31+
# @param grid [true,false] If `true`, draws grid-lines at the origin.
32+
# @return [Lineplot] A plot object.
733
module_function def lineplot(*args,
834
canvas: :braille,
935
color: :auto,
@@ -41,6 +67,16 @@ class Lineplot < GridPlot
4167
end
4268
end
4369

70+
# @overload lineplot!(plot, [x], y, name: "", color: :auto)
71+
#
72+
# Draws a path through the given points on the given canvas.
73+
#
74+
# @param plot [Lineplot] The plot object.
75+
# @param x [Array<Numeric>] Optional. The horizontal position for each point. If omitted, the axes of `y` will be used as `x`.
76+
# @param y [Array<Numeric>] The vertical position for each point.
77+
# @param name [String] Annotation of the current drawing to be displayed on the right.
78+
# @param color
79+
# @return [Lineplot] The plot object same as the `plot` parameter.
4480
module_function def lineplot!(plot,
4581
*args,
4682
color: :auto,

lib/unicode_plot/stairs.rb

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,54 @@
11
# coding: utf-8
22
module UnicodePlot
3-
# == Description
3+
# @overload stairs(x, y, style: :post, name: "", title: "", xlabel: "", ylabel: "", labels: true, border: :solid, margin: 3, padding: 1, color: :auto, width: 40, height: 15, xlim: [0, 0], ylim: [0, 0], canvas: :braille, grid: true)
44
#
5-
# Draws a staircase plot on a new canvas.
5+
# Draws a staircase plot on a new canvas.
66
#
7-
# The first vector `x` should contain the horizontal
8-
# positions for all the points. The second vector `y` should then
9-
# contain the corresponding vertical positions respectively. This
10-
# means that the two vectors must be of the same length and
11-
# ordering.
7+
# The first vector `x` should contain the horizontal
8+
# positions for all the points. The second vector `y` should then
9+
# contain the corresponding vertical positions respectively. This
10+
# means that the two vectors must be of the same length and
11+
# ordering.
1212
#
13-
# == Usage
13+
# @param x [Array<Numeric>] The horizontal position for each point.
14+
# @param y [Array<Numeric>] The vertical position for each point.
15+
# @param style [Symbol] Specifies where the transition of the stair takes place. Can be either `:pre` or `:post`.
16+
# @param name [String] Annotation of the current drawing to be displayed on the right.
17+
# @param height [Integer] Number of character rows that should be used for plotting.
18+
# @param xlim [Array<Numeric>] Plotting range for the x axis. `[0, 0]` stands for automatic.
19+
# @param ylim [Array<Numeric>] Plotting range for the y axis. `[0, 0]` stands for automatic.
20+
# @param canvas [Symbol] The type of canvas that should be used for drawing.
21+
# @param grid [Boolean] If `true`, draws grid-lines at the origin.
1422
#
15-
# UnicodePlot.stairs(x, y, style: :post, name: "", title: "", xlabel: "", ylabel: "", labels: true, border: :solid, margin: 3, padding: 1, color: :auto, width: 40, height: 15, xlim: [0, 0], ylim: [0, 0], canvas: :braille, grid: true)
23+
# @return [Plot] A plot object.
1624
#
17-
# @param x [Array<Numeric>] The horizontal position for each point.
18-
# @param y [Array<Numeric>] The vertical position for each point.
19-
# @param style [Symbol] Specifies where the transition of the stair takes place. Can be either `:pre` or `:post`.
20-
# @param name [String] Annotation of the current drawing to be displayed on the right.
21-
# @param height [Integer] Number of character rows that should be used for plotting.
22-
# @param xlim [Array<Numeric>] Plotting range for the x axis. `[0, 0]` stands for automatic.
23-
# @param ylim [Array<Numeric>] Plotting range for the y axis. `[0, 0]` stands for automatic.
24-
# @param canvas [Symbol] The type of canvas that should be used for drawing.
25-
# @param grid [Boolean] If `true`, draws grid-lines at the origin.
25+
# @example Example usage of stairs on IRB:
2626
#
27-
# @return [Plot] A plot object
28-
#
29-
# @example
30-
# UnicodePlot.stairs([1, 2, 4, 7, 8], [1, 3, 4, 2, 7], style: :post, title: "My Staircase Plot")
31-
#
32-
#
33-
# ┌────────────────────────────────────────┐
34-
# 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
35-
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
36-
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
37-
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
38-
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
39-
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
40-
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
41-
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡄⠀⠀⠀⠀⢸│
42-
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│
43-
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│
44-
# │⠀⠀⠀⠀⠀⢸⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│
45-
# │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│
46-
# │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠤⠤⠤⠤⠼│
47-
# │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
48-
# 1 │⣀⣀⣀⣀⣀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
49-
# └────────────────────────────────────────┘
50-
# 1 8
51-
#
52-
# @see Plot
53-
# @see scatterplot
54-
# @see lineplot
27+
# >> UnicodePlot.stairs([1, 2, 4, 7, 8], [1, 3, 4, 2, 7], style: :post, title: "My Staircase Plot").render
28+
# My Staircase Plot
29+
# ┌────────────────────────────────────────┐
30+
# 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
31+
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
32+
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
33+
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
34+
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
35+
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
36+
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
37+
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡄⠀⠀⠀⠀⢸│
38+
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│
39+
# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│
40+
# │⠀⠀⠀⠀⠀⢸⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│
41+
# │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│
42+
# │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠤⠤⠤⠤⠼│
43+
# │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
44+
# 1 │⣀⣀⣀⣀⣀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
45+
# └────────────────────────────────────────┘
46+
# 1 8
47+
# => nil
5548
#
49+
# @see Plot
50+
# @see scatterplot
51+
# @see lineplot
5652
module_function def stairs(xvec, yvec, style: :post, **kw)
5753
x_vex, y_vex = compute_stair_lines(xvec, yvec, style: style)
5854
lineplot(x_vex, y_vex, **kw)

unicode_plot.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
3434
spec.add_development_dependency "bundler", ">= 1.17"
3535
spec.add_development_dependency "rake"
3636
spec.add_development_dependency "test-unit"
37+
spec.add_development_dependency "yard"
3738
end

0 commit comments

Comments
 (0)