Skip to content

Commit cb2324d

Browse files
committed
Merge branch 'refactoring'
2 parents e64c525 + 420851c commit cb2324d

4 files changed

Lines changed: 23 additions & 30 deletions

File tree

lib/unicode_plot/barplot.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ class Barplot < Plot
33
include ValueTransformer
44

55
MIN_WIDTH = 10
6-
DEFAULT_WIDTH = 40
76
DEFAULT_COLOR = :green
87
DEFAULT_SYMBOL = "■"
98

@@ -68,16 +67,10 @@ def print_row(out, row_index)
6867
end
6968
[max, i]
7069
end
71-
72-
private def check_row_index(row_index)
73-
unless 0 <= row_index && row_index < n_rows
74-
raise ArgumentError, "row_index is out of range"
75-
end
76-
end
7770
end
7871

7972
module_function def barplot(*args,
80-
width: Barplot::DEFAULT_WIDTH,
73+
width: Plot::DEFAULT_WIDTH,
8174
color: Barplot::DEFAULT_COLOR,
8275
symbol: Barplot::DEFAULT_SYMBOL,
8376
border: :barplot,

lib/unicode_plot/boxplot.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module UnicodePlot
44
class Boxplot < Plot
55
MIN_WIDTH = 10
66
DEFAULT_COLOR = :green
7-
DEFAULT_WIDTH = 40
87

98
def initialize(data, width, color, min_x, max_x, **kw)
109
if min_x == max_x
@@ -20,7 +19,8 @@ def initialize(data, width, color, min_x, max_x, **kw)
2019
super(**kw)
2120
end
2221

23-
attr_reader :min_x, :max_x
22+
attr_reader :min_x
23+
attr_reader :max_x
2424

2525
def n_data
2626
@data.length
@@ -89,19 +89,13 @@ def print_row(out, row_index)
8989
val.round(half: :even).clamp(1, @width).to_i
9090
end
9191
end
92-
93-
private def check_row_index(row_index)
94-
unless 0 <= row_index && row_index < n_rows
95-
raise ArgumentError, "row_index out of bounds"
96-
end
97-
end
9892
end
9993

10094
module_function def boxplot(*args,
10195
data: nil,
10296
border: :corners,
10397
color: Boxplot::DEFAULT_COLOR,
104-
width: Boxplot::DEFAULT_WIDTH,
98+
width: Plot::DEFAULT_WIDTH,
10599
xlim: [0, 0],
106100
**kw)
107101
case args.length

lib/unicode_plot/grid_plot.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module UnicodePlot
22
class GridPlot < Plot
33
MIN_WIDTH = 5
4-
DEFAULT_WIDTH = 40
54
MIN_HEIGHT = 2
65
DEFAULT_HEIGHT = 15
76

lib/unicode_plot/plot.rb

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module UnicodePlot
22
class Plot
33
include StyledPrinter
44

5+
DEFAULT_WIDTH = 40
56
DEFAULT_BORDER = :solid
67
DEFAULT_MARGIN = 3
78
DEFAULT_PADDING = 1
@@ -29,18 +30,18 @@ def initialize(title: nil,
2930
@auto_color = 0
3031
end
3132

32-
attr_reader :title,
33-
:xlabel,
34-
:ylabel,
35-
:border,
36-
:margin,
37-
:padding,
38-
:labels_left,
39-
:colors_left,
40-
:labels_right,
41-
:colors_right,
42-
:decorations,
43-
:colors_deco
33+
attr_reader :title
34+
attr_reader :xlabel
35+
attr_reader :ylabel
36+
attr_reader :border
37+
attr_reader :margin
38+
attr_reader :padding
39+
attr_reader :labels_left
40+
attr_reader :colors_left
41+
attr_reader :labels_right
42+
attr_reader :colors_right
43+
attr_reader :decorations
44+
attr_reader :colors_deco
4445

4546
def title_given?
4647
title && title != ""
@@ -135,5 +136,11 @@ def to_s
135136
end
136137
margin
137138
end
139+
140+
private def check_row_index(row_index)
141+
unless 0 <= row_index && row_index < n_rows
142+
raise ArgumentError, "row_index out of bounds"
143+
end
144+
end
138145
end
139146
end

0 commit comments

Comments
 (0)