Skip to content

Commit d104a32

Browse files
arzoo14v0dro
authored andcommitted
Integrated rubocop to rubyplot and fixed some rubocop offences (#18)
* rubocopping * Update rubyplot.rb * setup_tavis_ci * Update rubyplot.rb * setup_travis_CI * color_related * Update color.rb * rubocop_offenses * fixed_rubocop_errors
1 parent 98c9e00 commit d104a32

38 files changed

+578
-351
lines changed

.rubocop.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
AllCops:
2+
Include:
3+
- 'lib/**/*'
4+
Exclude:
5+
- 'Rakefile'
6+
- 'Guardfile'
7+
- '**/*.erb'
8+
- 'spec/*'
9+
- 'spec/**/*'
10+
- 'vendor/**/*'
11+
- 'benchmarks/*'
12+
- 'profile/*'
13+
- 'tmp/*'
14+
DisplayCopNames: true
15+
TargetRubyVersion: 2.2
16+
17+
# Preferred codebase style ---------------------------------------------
18+
Layout/ExtraSpacing:
19+
AllowForAlignment: true
20+
21+
Style/FormatString:
22+
EnforcedStyle: percent
23+
24+
Style/AndOr:
25+
EnforcedStyle: conditionals
26+
27+
Layout/SpaceAroundEqualsInParameterDefault:
28+
EnforcedStyle: no_space
29+
30+
Layout/SpaceInsideBlockBraces:
31+
EnforcedStyle: space
32+
33+
Layout/SpaceInsideHashLiteralBraces:
34+
EnforcedStyle: no_space
35+
36+
Layout/AlignParameters:
37+
EnforcedStyle: with_fixed_indentation
38+
39+
Style/EmptyElse:
40+
EnforcedStyle: empty
41+
42+
Metrics/LineLength:
43+
Max: 120
44+
45+
Metrics/ModuleLength:
46+
Max: 200
47+
48+
Metrics/ClassLength:
49+
Max: 200
50+
51+
Style/ParallelAssignment:
52+
Enabled: false
53+
54+
Style/DoubleNegation:
55+
Enabled: false
56+
57+
Style/SingleLineBlockParams:
58+
Enabled: false
59+
60+
Style/PerlBackrefs:
61+
Enabled: false
62+
63+
Layout/SpaceAfterComma:
64+
Enabled: false
65+
66+
Layout/SpaceAroundOperators:
67+
Enabled: false
68+
69+
Style/EmptyCaseCondition:
70+
Enabled: false
71+
72+
Style/MultilineBlockChain:
73+
Enabled: false
74+
75+
# See https://github.com/bbatsov/rubocop/issues/4429
76+
Style/YodaCondition:
77+
Enabled: false
78+
79+
Style/PercentLiteralDelimiters:
80+
PreferredDelimiters:
81+
'%i': '[]'
82+
'%w': '[]'
83+
84+
# Neither of prefered styles are good enough :(
85+
Style/BlockDelimiters:
86+
Enabled: false
87+
88+
# Current preferred metrics --------------------------------------------
89+
# Better values are encouraged, but not required.
90+
Metrics/AbcSize:
91+
Max: 20
92+
93+
Metrics/MethodLength:
94+
Max: 15
95+
96+
Metrics/CyclomaticComplexity:
97+
Max: 7
98+
99+
# TODO -----------------------------------------------------------------
100+
101+
Style/Documentation:
102+
Enabled: false
103+
104+
# To discuss and decide ------------------------------------------------
105+
106+
# FIXME: in fact, rescue modifier is rarely a good choice.
107+
# But currently I can't fully grasp the three places they are used.
108+
# So, leaving them intact. - zverok, 2016-05-07
109+
110+
111+
# FIXME: once we should enable and fix it - zverok, 2016-05-07
112+
Style/Alias:
113+
Enabled: false
114+
115+
# FIXME: should decide about this.
116+
# Personally I prefer (as most of Ruby community) to use parens, but
117+
# we also can enforce style to NOT using them. Yet it definitely should
118+
# be only one style. Current codebase uses ~400 method defs without and
119+
# ~ 100 method defs with them. - zverok, 2016-05-07
120+
Style/MethodDefParentheses:
121+
Enabled: false
122+
123+
# Should be fixed, but require change of public API --------------------
124+
125+
# Bans methods like `has_missing_data?`, `is_number?` and so on - started
126+
# with unnecessary has_ or is_.
127+
128+
129+

lib/rubyplot.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
module Rubyplot
1919
def self.backend
2020
b = ENV['RUBYPLOT_BACKEND']
21-
return b.to_sym if b == "magick" || b == "gr"
21+
return b.to_sym if %w[magick gr].include?(b)
22+
2223
:magick
2324
end
2425
end

lib/rubyplot/artist/axes.rb

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,24 @@ class Axes < Base
77
LEGEND_MARGIN = TITLE_MARGIN = 20.0
88
LABEL_MARGIN = 10.0
99
DEFAULT_MARGIN = 20.0
10-
1110
THOUSAND_SEPARATOR = ','.freeze
12-
1311
# FIXME: most of the below accessors should just be name= methods which
1412
# will access the required Artist and set the variable in there directly.
1513
# Range of X axis.
1614
attr_accessor :x_range
1715
# Range of Y axis.
18-
attr_accessor :y_range,
19-
:text_font, :grid,
20-
:bounding_box, :origin,
21-
:title_shift, :title_margin
16+
17+
attr_accessor :y_range, :text_font, :grid, :bounding_box, :origin, :title_shift, :title_margin
18+
2219
# Main title for this Axes.
2320
attr_accessor :title
2421
# Rubyplot::Figure object to which this Axes belongs.
2522
attr_reader :figure
2623
# Array of plots contained in this Axes.
2724
attr_reader :plots
28-
2925
attr_reader :font, :marker_font_size, :legend_font_size,
3026
:title_font_size, :scale, :font_color, :marker_color, :axes,
31-
:legend_margin, :backend, :marker_caps_height, :marker_font_size
32-
27+
:legend_margin, :backend, :marker_caps_height
3328
attr_reader :label_stagger_height
3429
# FIXME: possibly disposable attrs
3530
attr_reader :title_caps_height
@@ -51,30 +46,27 @@ class Axes < Base
5146
attr_accessor :num_x_ticks
5247

5348
# @param figure [Rubyplot::Figure] Figure object to which this Axes belongs.
54-
def initialize figure
49+
def initialize(figure)
5550
@figure = figure
56-
51+
5752
@x_title = ''
5853
@y_title = ''
5954
@x_axis_margin = 40.0
6055
@y_axis_margin = 40.0
6156
@x_range = [nil, nil]
6257
@y_range = [nil, nil]
63-
64-
@title = ""
58+
@title = ''
6559
@title_shift = 0
6660
@title_margin = TITLE_MARGIN
6761
@text_font = :default
6862
@grid = true
6963
@bounding_box = true
7064
@plots = []
71-
7265
@raw_rows = width * (height/width)
73-
7466
@theme = Rubyplot::Themes::CLASSIC_WHITE
7567
vera_font_path = File.expand_path('Vera.ttf', ENV['MAGICK_FONT_PATH'])
7668
@font = File.exist?(vera_font_path) ? vera_font_path : nil
77-
@font_color = "#000000"
69+
@font_color = '#000000'
7870
@marker_font_size = 15.0
7971
@legend_font_size = 20.0
8072
@legend_margin = LEGEND_MARGIN
@@ -90,7 +82,6 @@ def initialize figure
9082
@y_axis = Rubyplot::Artist::YAxis.new(self)
9183
@x_ticks = nil
9284
@num_x_ticks = 5
93-
9485
@legend_box_position = :top
9586
end
9687

@@ -109,7 +100,7 @@ def legend_box_iy
109100
abs_x + @x_axis_margin + @legend_margin
110101
end
111102
end
112-
103+
113104
# Write an image to a file by communicating with the backend.
114105
# FIXME: (refactor) Currently draw first assigns default colors and then
115106
# performs consolidation etc of the data and then assigns the default X ticks.
@@ -128,60 +119,60 @@ def draw
128119
actually_draw
129120
end
130121

131-
def scatter! *args, &block
122+
def scatter!(*_args)
132123
plot = Rubyplot::Artist::Plot::Scatter.new self
133124
yield(plot) if block_given?
134125
@plots << plot
135126
end
136127

137-
def bar! *args, &block
128+
def bar!(*_args)
138129
plot = Rubyplot::Artist::Plot::Bar.new self
139130
yield(plot) if block_given?
140131
@plots << plot
141132
end
142133

143-
def line! *args, &block
134+
def line!(*_args)
144135
plot = Rubyplot::Artist::Plot::Line.new self
145136
yield(plot) if block_given?
146137
@plots << plot
147138
end
148139

149-
def area! *args, &block
140+
def area!(*_args)
150141
plot = Rubyplot::Artist::Plot::Area.new self
151142
yield(plot) if block_given?
152143
@plots << plot
153144
end
154145

155-
def bubble! *args, &block
146+
def bubble!(*_args)
156147
plot = Rubyplot::Artist::Plot::Bubble.new self
157148
yield(plot) if block_given?
158149
@plots << plot
159150
end
160151

161-
def dot! *args, &block
162-
add_plot "Dot", *args, &block
152+
def dot!(*args, &block)
153+
add_plot 'Dot', *args, &block
163154
end
164155

165-
def stacked_bar! *args, &block
156+
def stacked_bar!(*_args)
166157
plot = Rubyplot::Artist::Plot::StackedBar.new self
167158
yield(plot) if block_given?
168159
@plots << plot
169160
end
170161

171-
def write file_name
162+
def write(file_name)
172163
@plots[0].write file_name
173164
end
174-
165+
175166
# Absolute X co-ordinate of the Axes. Top left corner.
176167
def abs_x
177168
@figure.top_spacing * @figure.height + @figure.abs_x
178169
end
179-
170+
180171
# Absolute Y co-ordinate of the Axes. Top left corner.
181172
def abs_y
182173
@figure.top_spacing * @figure.height + @figure.abs_y
183174
end
184-
175+
185176
# Absolute width of the Axes in pixels.
186177
def width
187178
(1 - (@figure.left_spacing + @figure.right_spacing)) * @figure.width
@@ -204,7 +195,7 @@ def x_title= x_title
204195
def y_title= y_title
205196
@y_axis.title = y_title
206197
end
207-
198+
208199
private
209200

210201
def assign_default_label_colors
@@ -242,29 +233,22 @@ def add_plot plot_type, *args, &block
242233
@plots << plot
243234
end
244235

245-
def with_backend plot_type, *args
236+
def with_backend(plot_type, *args)
246237
plot =
247238
case Rubyplot.backend
248239
when :magick
249240
Kernel.const_get("Rubyplot::MagickWrapper::Plot::#{plot_type}").new self, *args
250241
when :gr
251242
Kernel.const_get("Rubyplot::GRWrapper::Plot::#{plot_type}").new self, *args
252243
end
253-
254244
plot
255245
end
256246

257247
# Figure out the co-ordinates of the title text w.r.t Axes.
258248
def configure_title
259249
@title = Rubyplot::Artist::Text.new(
260-
@title,
261-
self,
262-
abs_x: abs_x + width / 2,
263-
abs_y: abs_y + @title_margin,
264-
font: @font,
265-
color: @font_color,
266-
pointsize: @title_font_size,
267-
internal_label: "axes title."
250+
@title, self, abs_x: abs_x + width / 2, abs_y: abs_y + @title_margin, font: @font, color: @font_color,
251+
pointsize: @title_font_size, internal_label: 'axes title.'
268252
)
269253
end
270254

@@ -276,7 +260,8 @@ def calculate_xy_axes_origin
276260
# Figure out co-ordinates of the legends
277261
def configure_legends
278262
@legend_box = Rubyplot::Artist::LegendBox.new(
279-
self, abs_x: legend_box_ix, abs_y: legend_box_iy)
263+
self, abs_x: legend_box_ix, abs_y: legend_box_iy
264+
)
280265
end
281266

282267
# Make adjustments to the data that will be plotted. Maps the data
@@ -299,16 +284,15 @@ def actually_draw
299284

300285
def consolidate_plots
301286
bars = @plots.grep(Rubyplot::Artist::Plot::Bar)
302-
if !bars.empty?
287+
unless bars.empty?
303288
@plots.delete_if { |p| p.is_a?(Rubyplot::Artist::Plot::Bar) }
304289
@plots << Rubyplot::Artist::Plot::MultiBars.new(self, bar_plots: bars)
305290
end
306291

307292
stacked_bars = @plots.grep(Rubyplot::Artist::Plot::StackedBar)
308-
if !stacked_bars.empty?
293+
unless stacked_bars.empty?
309294
@plots.delete_if { |p| p.is_a?(Rubyplot::Artist::Plot::StackedBar) }
310-
@plots << Rubyplot::Artist::Plot::MultiStackedBar.new(
311-
self, stacked_bars: stacked_bars)
295+
@plots << Rubyplot::Artist::Plot::MultiStackedBar.new(self, stacked_bars: stacked_bars)
312296
end
313297
end
314298

@@ -335,6 +319,9 @@ def set_yrange
335319
@y_axis.min_val = @y_range[0]
336320
@y_axis.max_val = @y_range[1]
337321
end
338-
end # class Axes
339-
end # moudle Artist
340-
end # module Rubyplot
322+
end
323+
# class Axes
324+
end
325+
# moudle Artist
326+
end
327+
# module Rubyplot

0 commit comments

Comments
 (0)