Skip to content

Commit b2b55f5

Browse files
author
alishdipani
committed
Added support for Numo arrays to plots
1 parent d859e04 commit b2b55f5

File tree

11 files changed

+61
-18
lines changed

11 files changed

+61
-18
lines changed

lib/rubyplot/artist/plot/area.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def stacked(bool)
1515
end
1616

1717
def data x_values, y_values
18-
x_values, y_values = x_values.zip(y_values).sort.transpose if @sort_data
18+
x_values, y_values = x_values.to_a.zip(y_values.to_a).sort.transpose if @sort_data
1919
super(x_values, y_values)
2020
end
2121

lib/rubyplot/artist/plot/bar.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def spacing_ratio=(s_r)
3434

3535
# Set Bar plot data.
3636
def data y_values
37-
super(Array.new(y_values.size) { |i| i }, y_values)
37+
super(Array.new(y_values.to_a.size) { |i| i }, y_values.to_a)
3838
end
3939

4040
# Number of bars in this Bar plot

lib/rubyplot/artist/plot/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def color=(color)
3939
end
4040

4141
def data(x_values, y_values)
42-
@data[:x_values] = x_values
43-
@data[:y_values] = y_values
42+
@data[:x_values] = x_values.to_a
43+
@data[:y_values] = y_values.to_a
4444
end
4545

4646
def process_data

lib/rubyplot/artist/plot/box_plot.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ def process_data
3939
end
4040

4141
def data vectors
42-
@vectors = vectors
42+
# @vectors = vectors.to_a unless vectors.is_a? Array
43+
if vectors.is_a? Array
44+
vectors.each_with_index { |_, idx| vectors[idx] = vectors[idx].to_a}
45+
@vectors = vectors
46+
else
47+
@vectors = vectors.to_a
48+
end
4349
end
4450

4551
def draw

lib/rubyplot/artist/plot/bubble.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def initialize(*)
1616
end
1717

1818
def data x_values, y_values, z_values
19-
super(x_values, y_values)
20-
@data[:z_values] = z_values
19+
super(x_values.to_a, y_values.to_a)
20+
@data[:z_values] = z_values.to_a
2121
end
2222

2323
def draw

lib/rubyplot/artist/plot/candle_stick.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ module Rubyplot
22
module Artist
33
module Plot
44
class CandleStick < Artist::Plot::Base
5-
attr_accessor :lows
6-
attr_accessor :highs
7-
attr_accessor :opens
8-
attr_accessor :closes
5+
attr_reader :lows
6+
attr_reader :highs
7+
attr_reader :opens
8+
attr_reader :closes
99
attr_accessor :bar_width
1010
attr_accessor :x_left_candle
1111
attr_accessor :x_low_stick
@@ -24,6 +24,22 @@ def initialize(*)
2424
@border_color = :black
2525
end
2626

27+
def lows=(lows_arr)
28+
@lows = lows_arr.to_a
29+
end
30+
31+
def highs=(highs_arr)
32+
@highs = highs_arr.to_a
33+
end
34+
35+
def opens=(opens_arr)
36+
@opens = opens_arr.to_a
37+
end
38+
39+
def closes=(closes_arr)
40+
@closes = closes_arr.to_a
41+
end
42+
2743
def process_data
2844
if @lows.size != @highs.size || @opens.size != @closes.size
2945
raise Rubyplot::SizeError, "all given parameters must be of equal size."

lib/rubyplot/artist/plot/error_bar.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module Rubyplot
22
module Artist
33
module Plot
44
class ErrorBar < Artist::Plot::Base
5-
attr_accessor :xerr, :yerr, :xuplims, :xlolims, :yuplims, :ylolims, :line_width, :xerr_width, :yerr_width, :xerr_color, :yerr_color
5+
attr_accessor :xuplims, :xlolims, :yuplims, :ylolims, :line_width, :xerr_width, :yerr_width, :xerr_color, :yerr_color
6+
attr_reader :xerr, :yerr
67

78
def initialize(*)
89
super
@@ -13,6 +14,22 @@ def initialize(*)
1314
@yerr_color = nil
1415
end
1516

17+
def xerr=(xerror)
18+
if (xerror.is_a?(Float) || xerror.is_a?(Integer))
19+
@xerr = xerror
20+
else
21+
@xerr = xerror.to_a
22+
end
23+
end
24+
25+
def yerr=(yerror)
26+
if (yerror.is_a?(Float) || yerror.is_a?(Integer))
27+
@yerr = yerror
28+
else
29+
@yerr = yerror.to_a
30+
end
31+
end
32+
1633
def process_data
1734
super
1835
preprocess_err_values!

lib/rubyplot/artist/plot/histogram.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Artist
33
module Plot
44
class Histogram < Artist::Plot::Base
55
# Values that need to be shown as a histogram.
6-
attr_accessor :x
6+
attr_reader :x
77
# Array of bins into which the data should be subdivided.
88
attr_accessor :bins
99
# Width of each bar.
@@ -13,8 +13,12 @@ def initialize(*)
1313
super
1414
end
1515

16+
def x=(xvals)
17+
@x = xvals.to_a
18+
end
19+
1620
def data x_values
17-
@x = x_values
21+
@x = x_values.to_a
1822
end
1923

2024
def process_data

lib/rubyplot/artist/plot/line.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(*)
2020
end
2121

2222
def data(x_values, y_values)
23-
super x_values, y_values
23+
super x_values.to_a, y_values.to_a
2424
end
2525

2626
def draw

lib/rubyplot/artist/plot/scatter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ class Scatter < Artist::Plot::Base
77
# Rubyplot::MARKER_TYPES.
88
attr_accessor :marker_type
99
# Set a color from Rubyplot::Color::COLOR_INDEX as the color of the
10-
# fill of the marker.
10+
# fill of the marker.
1111
attr_accessor :marker_fill_color
1212
# Set a color from Rubyplot::Color::COLOR_INDEX as the color of the
1313
# border of the marker.
1414
attr_accessor :marker_border_color
15-
15+
1616
def initialize(*)
1717
super
1818
@marker_size = 1.0

lib/rubyplot/artist/plot/stacked_bar.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def initialize(*)
2121
end
2222

2323
def data y_values
24-
super(Array(0...(y_values.size)), y_values)
24+
super(Array(0...(y_values.to_a.size)), y_values.to_a)
2525
end
2626

2727
def y_values

0 commit comments

Comments
 (0)