Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
21d2450
improved the show function for both backends and frontend
alishdipani Jul 13, 2019
0644a78
correction in testing of plot function
alishdipani Jul 14, 2019
64cbdf4
added error handling of large figures for Magick
alishdipani Jul 16, 2019
af190f4
improved frontend for plot function
alishdipani Jul 16, 2019
a0c27ce
Merge pull request #45 from alishdipani/master
alishdipani Jul 17, 2019
cc71ad0
implemented the fmt argument
alishdipani Jul 19, 2019
1b38f34
minor improvements in the plot function frontend
alishdipani Jul 19, 2019
5947c91
added bubble opacity as input for the bubble plot
alishdipani Jul 24, 2019
ca2aa73
added new method print_on_device to avoid repetition in write and show
Aug 7, 2019
a5a91cb
Added iruby integration to magick backend
Aug 15, 2019
92d4da0
Added iruby integration to show function frontend
Aug 15, 2019
640b3d7
Added inline and stop_inline functions to start and stop iruby inline
Aug 15, 2019
442a675
Corrected bug for to changing properties of canvas after declaring
Aug 15, 2019
2edeaef
stop printing output device in stop_output_device function
Aug 15, 2019
bdf5bbc
Added tutorial for Magick backend
Aug 16, 2019
bd321be
Improved the tutorial
Aug 17, 2019
7abeae6
Implemented major ticks
Aug 18, 2019
954f83f
Improved the tutorial
Aug 18, 2019
4f0dab1
Implemented minor ticks
Aug 19, 2019
d11ee83
Corrected bug - only first subplot had axes drawn in case of multiple
Aug 19, 2019
b0b21a2
Improved tick labels
Aug 20, 2019
0e8aa83
added data method for taking in x values as input for consistency
Aug 20, 2019
f101e63
Made x coordinate values compulsory for Line plot
Aug 20, 2019
e89fd2f
Made x values compulsory, added stacked option
Aug 20, 2019
9d693a2
added line_opacity to Line plot and corrected line_color attribute
Aug 21, 2019
2e34714
removed line_opacity option from line plot and plot function
Aug 21, 2019
7780962
improved the tutorial
Aug 21, 2019
3ffd94c
Added comment for point
Aug 25, 2019
8efa9d6
added blog links to the tutorial
Aug 26, 2019
3624962
added final blog link to the tutorial
Aug 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 115 additions & 23 deletions lib/rubyplot/artist/plot/basic_plot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,129 @@ module Rubyplot
module Artist
module Plot
class BasicPlot < Artist::Plot::Base
attr_accessor :marker
attr_accessor :marker_type
attr_accessor :marker_size

attr_accessor :marker_border_color
attr_accessor :marker_fill_color
attr_accessor :line_color
attr_accessor :line_type
attr_accessor :line_width
attr_accessor :line_opacity

COLOR_TYPES_FMT = {
'b' => :blue,
'g' => :green,
'r' => :red,
'c' => :cyan,
'm' => :magenta,
'y' => :yellow,
'k' => :black,
'w' => :white
}.freeze

MARKER_TYPES_FMT = {
'.' => :dot,
',' => :omark,
'o' => :circle,
'v' => :traingle_down,
'^' => :traingle_up,
'<' => :solid_tri_left,
'>' => :solid_tri_right,
'1' => :solid_triangle_down,
'2' => :solid_triangle_up,
'3' => :solid_tri_left,
'4' => :solid_tri_right,
's' => :square,
'p' => :pentagon,
'*' => :star,
'h' => :hexagon,
'H' => :heptagon,
'+' => :plus,
'x' => :diagonal_cross,
'D' => :solid_diamond,
'd' => :diamond,
'|' => :vline,
'_' => :hline
}.freeze

LINE_TYPES_FMT ={
'--' => :dashed,
'-.' => :dashed_dotted,
'-' => :solid,
':' => :dotted
}.freeze

def initialize(*)
super
@marker = :dot
@marker_type = nil
@marker_size = 1.0
@marker_border_color = :default
# set fill to nil for the benefit of hollow markers so that legend
# color defaults to :black in case user does not specify.
@marker_fill_color = nil
@line_color = :default
@line_type = nil
@line_width = 1.0
@line_opacity = 1.0
end

def draw
line_style = @marker.to_s.match /(.*)_line\z/
if line_style
Rubyplot::Artist::Line2D.new(
self,
x: @data[:x_values],
y: @data[:y_values],
type: line_style[1].to_sym,
color: @data[:color]
).draw
else
# FIXME: this should probably be inside a 'Collections' class that will
# allow the user to customise individual parameters.
Rubyplot.backend.draw_markers(
x: @data[:x_values],
y: @data[:y_values],
type: @marker,
fill_color: @data[:color],
size: [@marker_size] * @data[:x_values].size
)
def color
@line_color || @marker_fill_color || @marker_border_color || :default
end

def fmt=(fmt)
unless fmt.is_a? String
raise TypeError, 'fmt argument takes a String input'
end

COLOR_TYPES_FMT.each do |symbol, color|
if fmt.include? symbol
@marker_fill_color = color
@marker_border_color = color
@line_color = color
break
end
end

MARKER_TYPES_FMT.each do |symbol, marker_type|
if fmt.include? symbol
@marker_type = marker_type
break
end
end

LINE_TYPES_FMT.each do |symbol, line_type|
if fmt.include? symbol
@line_type = line_type
break
end
end
end

def draw
# Default marker fill color
@marker_fill_color = :default if @marker_fill_color.nil?
# defualt type of plot is solid line
@line_type = :solid if @line_type.nil? && @marker_type.nil?
Rubyplot::Artist::Line2D.new(
self,
x: @data[:x_values],
y: @data[:y_values],
type: @line_type,
# type: line_style[1].to_sym,
color: @line_color,
opacity: @line_opacity,
width: @line_width
).draw if @line_type
Rubyplot.backend.draw_markers(
x: @data[:x_values],
y: @data[:y_values],
type: @marker_type,
fill_color: @marker_fill_color,
border_color: @marker_border_color,
size: [@marker_size] * @data[:x_values].size
) if @marker_type
end
end # class BasicPlot
end # module Plot
end # module Artist
Expand Down
8 changes: 6 additions & 2 deletions lib/rubyplot/artist/plot/bubble.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ class Bubble < Artist::Plot::Base
# Width in pixels of the border of each bubble.
attr_reader :border_width
attr_reader :z_max, :z_min
# Opacity of the circles
attr_accessor :fill_opacity

def initialize(*)
super
@bubbles = []
@border_width = 1.0
@fill_opacity = 0.5
end

def data x_values, y_values, z_values
Expand All @@ -23,9 +27,9 @@ def draw
x: @data[:x_values][idx],
y: @data[:y_values][idx],
radius: @data[:z_values][idx],
fill_opacity: 0.5,
fill_opacity: @fill_opacity,
color: @data[:color],
border_width: 1,
border_width: @border_width,
abs: false
).draw
end
Expand Down
9 changes: 9 additions & 0 deletions lib/rubyplot/backend/magick_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ def stop_output_device

# Function to convert figure size to pixels
def scale_figure(width, height)
case @figure.figsize_unit
when :pixel
raise RangeError, 'Figure with a dimension greater than 11500 pixels can not be plotted' if height>11500 || width>11500
when :cm
raise RangeError, 'Figure with a dimension greater than 290 cms can not be plotted' if height>290 || width>290
when :inch
raise RangeError, 'Figure with a dimension greater than 115 inches can not be plotted' if height>115 || width>115
end

[width * PIXEL_MULTIPLIERS[@figure.figsize_unit], height * PIXEL_MULTIPLIERS[@figure.figsize_unit]]
end

Expand Down
3 changes: 3 additions & 0 deletions spec/axes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
p.marker = :solid_line
d = (0..360).step(30).to_a
p.data d, d.map { |a| Math.sin(a) }
p.data d, d.map { |a| Math.sin(a * Math::PI / 180) }
end
axes.title = "Simple sine wave plot."
end
Expand All @@ -93,6 +94,7 @@
p.marker = :dashed_dotted_line
d = (0..360).step(30).to_a
p.data d, d.map { |a| Math.sin(a) }
p.data d, d.map { |a| Math.sin(a * Math::PI / 180) }
p.color = :green
end
end
Expand All @@ -107,6 +109,7 @@
p.marker = :plus
d = (0..360).step(30).to_a
p.data d, d.map { |a| Math.cos(a) }
p.data d, d.map { |a| Math.cos(a * Math::PI / 180) }
p.color = :green
end
end
Expand Down