Skip to content

Commit ffc8cad

Browse files
committed
revert some rubocopping and antialias text
1 parent d104a32 commit ffc8cad

File tree

11 files changed

+60
-74
lines changed

11 files changed

+60
-74
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ AllCops:
1111
- 'benchmarks/*'
1212
- 'profile/*'
1313
- 'tmp/*'
14+
- '*.so'
1415
DisplayCopNames: true
1516
TargetRubyVersion: 2.2
1617

lib/rubyplot/artist/axes.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ def with_backend(plot_type, *args)
246246

247247
# Figure out the co-ordinates of the title text w.r.t Axes.
248248
def configure_title
249-
@title = Rubyplot::Artist::Text.new(
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.'
249+
@texts << Rubyplot::Artist::Text.new(
250+
@title, self, abs_x: abs_x + width / 2, abs_y: abs_y + @title_margin,
251+
font: @font, color: @font_color,
252+
pointsize: @title_font_size, internal_label: 'axes title.'
252253
)
253254
end
254255

@@ -277,7 +278,7 @@ def actually_draw
277278
@x_axis.draw
278279
@x_ticks.each(&:draw)
279280
@y_axis.draw
280-
@title.draw
281+
@texts.each(&:draw)
281282
@legend_box.draw
282283
@plots.each(&:draw)
283284
end

lib/rubyplot/artist/axis/base.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ def initialize axes
1919
@backend = @axes.backend
2020
@major_ticks_count = 5
2121
@x_ticks = nil
22+
@texts = []
23+
@lines = []
24+
end
25+
26+
def draw
27+
configure_title
28+
@lines.each(&:draw)
29+
@texts.each(&:draw)
2230
end
2331
end
2432
# class Base

lib/rubyplot/artist/axis/x_axis.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,18 @@ def initialize axes
1111
@length = (@abs_x2 - @abs_x1).abs
1212
configure_axis_line
1313
end
14-
15-
def draw
16-
configure_title
17-
@line.draw
18-
@title.draw
19-
end
20-
14+
2115
private
2216

2317
def configure_axis_line
24-
@line = Rubyplot::Artist::Line2D.new(
18+
@lines << Rubyplot::Artist::Line2D.new(
2519
self, abs_x1: @abs_x1, abs_y1: @axes.origin[1], abs_x2: @abs_x2, abs_y2: @axes.origin[1],
2620
stroke_width: @stroke_width
2721
)
2822
end
2923

3024
def configure_title
31-
@title = Rubyplot::Artist::Text.new(
25+
@texts << Rubyplot::Artist::Text.new(
3226
@title,
3327
self,
3428
pointsize: @axes.marker_font_size,

lib/rubyplot/artist/axis/y_axis.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@ def initialize(*)
1010
@y_ticks = []
1111
@length = (@abs_y1 - @abs_y2).abs
1212
configure_axis_line
13-
configure_title
14-
end
15-
16-
def draw
17-
@title.draw
18-
@line.draw
1913
end
2014

2115
private
2216

2317
def configure_axis_line
24-
@line = Rubyplot::Artist::Line2D.new(
18+
@lines << Rubyplot::Artist::Line2D.new(
2519
self,
2620
abs_x1: @abs_x1,
2721
abs_y1: @abs_y1,
@@ -32,7 +26,7 @@ def configure_axis_line
3226
end
3327

3428
def configure_title
35-
@title = Rubyplot::Artist::Text.new(
29+
@texts << Rubyplot::Artist::Text.new(
3630
@title,
3731
self,
3832
rotation: -90.0,

lib/rubyplot/artist/figure.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,17 @@ class Figure < Artist::Base
3333
# @param height [Integer] nil Height in pixels of the complete Figure.
3434
# @param width [Integer] nil Width in pixels of the complete Figure.
3535
def initialize(height: nil, width: nil)
36+
super(Rubyplot::Backend::MagickWrapper.new, 0, 0)
3637
@title = ''
3738
@nrows = 1
3839
@ncols = 1
39-
@backend = Rubyplot::Backend::MagickWrapper.new
4040
@width = width || DEFAULT_TARGET_WIDTH
4141
@height = height || @width * 0.75
42-
@abs_x = 0
43-
@abs_y = 0
4442
@top_spacing = 0.05
4543
@bottom_spacing = 0.05
4644
@left_spacing = 0.05
4745
@right_spacing = 0.05
46+
@subplots = nil
4847
setup_default_theme
4948
add_subplots @nrows, @ncols
5049
end

lib/rubyplot/artist/text.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ class Text < Artist::Base
77

88
# rubocop:disable Metrics/ParameterLists
99
def initialize(text, owner, abs_x:, abs_y:,font: nil,
10-
color: '#000000',pointsize:,stroke: 'transparent', internal_label: '', rotation: nil)
11-
# weight: nil, gravity: nil is removed as they are unused method argument.
10+
color: '#000000',pointsize:,stroke: 'transparent',
11+
internal_label: '', rotation: nil,
12+
weight: nil, gravity: nil
13+
)
14+
super(owner.backend, abs_x, abs_y)
1215
@text = text
1316
@owner = owner
14-
@abs_x = abs_x
15-
@abs_y = abs_y
1617
@font = font
1718
@color = color
1819
@pointsize = pointsize
1920
@stroke = stroke
2021
@internal_label = internal_label
21-
@backend = @owner.backend
2222
@rotation = rotation
2323
end
2424
# rubocop:enable Metrics/ParameterLists

lib/rubyplot/backend/magick_wrapper.rb

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,6 @@ def initialize
1616
@draw = Magick::Draw.new
1717
end
1818

19-
# Returns the height of the capital letter 'X' for the current font and
20-
# size.
21-
#
22-
# Not scaled since it deals with dimensions that the regular scaling will
23-
# handle.
24-
def caps_height(font, font_size)
25-
@draw.pointsize = font_size
26-
@draw.font = font if font
27-
@draw.get_type_metrics(@base_image, 'X').height
28-
end
29-
30-
# Returns the width of a string at this pointsize.
31-
#
32-
# Not scaled since it deals with dimensions that the regular
33-
# scaling will handle.
34-
# FIXME: duplicate with get_text_width_height
35-
def string_width(font, font_size, text)
36-
@draw.pointsize = font_size
37-
@draw.font = font if font
38-
@draw.get_type_metrics(@base_image, text.to_s).height
39-
end
40-
4119
# Height in pixels of particular text.
4220
# @param text [String] Text to be measured.
4321
def text_height(text, font, font_size)
@@ -73,41 +51,43 @@ def get_text_width_height(text)
7351
# Unused method argument - stroke
7452
def draw_text(text,font_color:,font: nil,pointsize:,
7553
font_weight: Magick::NormalWeight, gravity: nil,
76-
x_pos:,y_pos:,rotation: nil)
54+
x:,y:,rotation: nil, stroke: 'transparent')
7755
@draw.fill = font_color
7856
@draw.font = font if font
7957
@draw.pointsize = pointsize
8058
@draw.font_weight = font_weight
8159
@draw.gravity = GRAVITY_MEASURE[gravity] || Magick::ForgetGravity
60+
@draw.stroke stroke
61+
@draw.stroke_antialias true
8262
@draw.rotation = rotation if rotation
83-
@draw.annotate(@base_image, 0,0,x_pos.to_i,y_pos.to_i, text.gsub('%', '%%'))
63+
@draw.annotate(@base_image, 0,0,x.to_i,y.to_i, text.gsub('%', '%%'))
8464
@draw.rotation = 90.0 if rotation
8565
end
8666

8767
# Draw a rectangle.
88-
def draw_rectangle(x01:,y01:,x02:,y02:,border_color: '#000000',stroke: 'transparent',
68+
def draw_rectangle(x1:,y1:,x2:,y2:,border_color: '#000000',stroke: 'transparent',
8969
fill_color: nil, stroke_width: 1.0)
9070
if fill_color # solid rectangle
9171
@draw.stroke stroke
9272
@draw.fill fill_color
9373
@draw.stroke_width stroke_width
94-
@draw.rectangle x01, y01, x02, y02
74+
@draw.rectangle x1, y1, x2, y2
9575
else # just edges
9676
@draw.stroke_width stroke_width
9777
@draw.fill border_color
98-
@draw.line x01, y01, x01 + (x02-x01), y01 # top line
99-
@draw.line x01 + (x02-x01), y01, x02, y02 # right line
100-
@draw.line x02, y02, x01, y01 + (y02-y01) # bottom line
101-
@draw.line x01, y01, x01, y01 + (y02-y01) # left line
78+
@draw.line x1, y1, x1 + (x2-x1), y1 # top line
79+
@draw.line x1 + (x2-x1), y1, x2, y2 # right line
80+
@draw.line x2, y2, x1, y1 + (y2-y1) # bottom line
81+
@draw.line x1, y1, x1, y1 + (y2-y1) # left line
10282
end
10383
end
10484

105-
def draw_line(x01:,y01:,x02:,y02:,color: '#000000', stroke: 'transparent',
85+
def draw_line(x1:,y1:,x2:,y2:,color: '#000000', stroke: 'transparent',
10686
stroke_opacity: 0.0, stroke_width: 2.0)
10787
@draw.stroke_opacity stroke_opacity
10888
@draw.stroke_width stroke_width
10989
@draw.fill color
110-
@draw.line x01, y01, x02, y02
90+
@draw.line x1, y1, x2, y2
11191
end
11292

11393
def draw_circle(x_pos:,y_pos:,radius:,stroke_opacity:,stroke_width:,color:)

rubyplot.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
2828
spec.add_development_dependency 'rake-compiler'
2929
spec.add_development_dependency 'rspec'
3030
spec.add_development_dependency 'pry'
31+
spec.add_development_dependency 'rubocop'
3132

3233
spec.add_runtime_dependency 'rmagick', '>= 2.13.4'
3334
end

spec/figure_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@
99
expect(axes).to be_a(Rubyplot::Axes)
1010
end
1111
end
12+
13+
context "#reset!" do
14+
it "resets all values to defaults" do
15+
fig = Rubyplot::Figure.new
16+
axes = fig.add_subplot 0,0
17+
axes.title = "reset test"
18+
fig.reset!
19+
20+
expect(axes.title).to eq("")
21+
end
22+
end
1223
end

0 commit comments

Comments
 (0)