Skip to content

Commit a3d50cf

Browse files
committed
line plots work
1 parent 6fff607 commit a3d50cf

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

lib/rubyplot/artist/plot/line.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@ def draw_single_point
3333

3434
def draw_lines
3535
prev_x = prev_y = nil
36+
y_axis_length = (@axes.y_axis.abs_y2 - @axes.y_axis.abs_y1).abs
3637
@normalized_data[:x_values].each_with_index do |ix, idx_ix|
3738
iy = @normalized_data[:y_values][idx_ix]
38-
new_x = ix * @axes.graph_width + @axes.graph_left
39-
new_y = @axes.graph_top + (@axes.graph_height - iy * @axes.graph_height)
39+
next if ix.nil? || iy.nil?
40+
new_x = ix * (@axes.x_axis.abs_x2 - @axes.x_axis.abs_x1).abs + @axes.abs_x +
41+
@axes.y_axis_margin
42+
new_y = (y_axis_length - iy * y_axis_length) + @axes.abs_y
43+
4044
if !(prev_x.nil? && prev_y.nil?)
4145
Rubyplot::Artist::Line2D.new(
4246
self,
43-
x1: prev_x,
44-
y1: prev_y,
45-
x2: new_x,
46-
y2: new_y,
47+
abs_x1: prev_x,
48+
abs_y1: prev_y,
49+
abs_x2: new_x,
50+
abs_y2: new_y,
4751
stroke_opacity: @stroke_opacity,
4852
stroke_width: @stroke_width
4953
).draw

lib/rubyplot/artist/plot/scatter.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ def initialize(*)
1010
end
1111

1212
def draw
13-
puts "data: #{@data}"
14-
puts "norm: #{@normalized_data}"
1513
y_axis_length = (@axes.y_axis.abs_y2 - @axes.y_axis.abs_y1).abs
1614
@normalized_data[:y_values].each_with_index do |iy, idx_y|
1715
ix = @normalized_data[:x_values][idx_y]

spec/axes_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@
275275

276276
end
277277

278-
it "makes a simple line plot" do
278+
it "makes a simple line plot", focus: true do
279279
fig = Rubyplot::Figure.new
280280
axes = fig.add_subplot 0,0
281281
axes.line! do |p|
282-
p.data [5, 8, 13, 15]
282+
p.data [2, 4, 7, 9], [1,2,3,4]
283283
p.label = "Marco"
284284
p.color = :blue
285285
end

0 commit comments

Comments
 (0)