From 0b973b8cfb3c76108b922ce2df2b0ef2ca9786ab Mon Sep 17 00:00:00 2001 From: arzoo14 Date: Fri, 14 Dec 2018 21:41:07 +0530 Subject: [PATCH 1/9] rubocopping --- .rubocop.yml | 131 +++++++++ lib/rubyplot.rb | 3 +- lib/rubyplot/artist/axes.rb | 154 ++++------ lib/rubyplot/artist/axis/base.rb | 18 +- lib/rubyplot/artist/axis/x_axis.rb | 20 +- lib/rubyplot/artist/axis/y_axis.rb | 17 +- lib/rubyplot/artist/base.rb | 12 +- lib/rubyplot/artist/circle.rb | 15 +- lib/rubyplot/artist/figure.rb | 19 +- lib/rubyplot/artist/legend.rb | 11 +- lib/rubyplot/artist/legend_box.rb | 13 +- lib/rubyplot/artist/line2d.rb | 13 +- lib/rubyplot/artist/plot/bar.rb | 22 +- lib/rubyplot/artist/plot/base.rb | 34 ++- lib/rubyplot/artist/plot/line.rb | 32 +-- lib/rubyplot/artist/plot/scatter.rb | 26 +- lib/rubyplot/artist/rectangle.rb | 14 +- lib/rubyplot/artist/text.rb | 19 +- lib/rubyplot/artist/tick/base.rb | 17 +- lib/rubyplot/artist/tick/x_tick.rb | 13 +- lib/rubyplot/artist/tick/y_tick.rb | 9 +- lib/rubyplot/backend/magick_wrapper.rb | 69 +++-- .../gr_wrapper/plot/base_plot/lazy_base.rb | 4 +- .../gr_wrapper/plot/base_plot/robust_base.rb | 38 +-- lib/rubyplot/gr_wrapper/plot/scatter.rb | 30 +- lib/rubyplot/gr_wrapper/tasks.rb | 29 +- lib/rubyplot/magick_wrapper.rb | 2 - lib/rubyplot/magick_wrapper/artist.rb | 267 +++++++++--------- .../magick_wrapper/artist/attributes.rb | 16 +- .../magick_wrapper/artist/geometry.rb | 32 ++- .../magick_wrapper/artist/math_methods.rb | 23 +- lib/rubyplot/magick_wrapper/magick/draw.rb | 13 +- lib/rubyplot/magick_wrapper/plot/area.rb | 6 +- .../magick_wrapper/plot/area/geometry.rb | 15 +- lib/rubyplot/magick_wrapper/plot/bar.rb | 53 ++-- .../magick_wrapper/plot/bar/geometry.rb | 15 +- lib/rubyplot/magick_wrapper/plot/bubble.rb | 80 +++--- .../magick_wrapper/plot/bubble/geometry.rb | 23 +- lib/rubyplot/magick_wrapper/plot/dot.rb | 35 ++- lib/rubyplot/magick_wrapper/plot/line.rb | 60 ++-- .../magick_wrapper/plot/line/geometry.rb | 23 +- lib/rubyplot/magick_wrapper/plot/scatter.rb | 43 +-- .../magick_wrapper/plot/scatter/geometry.rb | 15 +- .../magick_wrapper/plot/stacked_bar.rb | 29 +- .../plot/stacked_bar/geometry.rb | 15 +- lib/rubyplot/magick_wrapper/themes.rb | 2 +- lib/rubyplot/spi.rb | 8 +- lib/rubyplot/subplot.rb | 1 - lib/rubyplot/themes.rb | 2 +- lib/rubyplot/utils.rb | 14 +- lib/rubyplot/version.rb | 2 +- 51 files changed, 909 insertions(+), 667 deletions(-) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..61b0525 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,131 @@ +AllCops: + Include: + - 'lib/**/*' + Exclude: + - 'daru.gemspec' + - 'Rakefile' + - 'Gemfile' + - 'Guardfile' + - '**/*.erb' + - 'spec/*' + - 'spec/**/*' + - 'vendor/**/*' + - 'benchmarks/*' + - 'profile/*' + - 'tmp/*' + DisplayCopNames: true + TargetRubyVersion: 2.2 + +# Preferred codebase style --------------------------------------------- +Layout/ExtraSpacing: + AllowForAlignment: true + +Style/FormatString: + EnforcedStyle: percent + +Style/AndOr: + EnforcedStyle: conditionals + +Layout/SpaceAroundEqualsInParameterDefault: + EnforcedStyle: no_space + +Layout/SpaceInsideBlockBraces: + EnforcedStyle: space + +Layout/SpaceInsideHashLiteralBraces: + EnforcedStyle: no_space + +Layout/AlignParameters: + EnforcedStyle: with_fixed_indentation + +Style/EmptyElse: + EnforcedStyle: empty + +Metrics/LineLength: + Max: 120 + +Metrics/ModuleLength: + Max: 200 + +Metrics/ClassLength: + Max: 200 + +Style/ParallelAssignment: + Enabled: false + +Style/DoubleNegation: + Enabled: false + +Style/SingleLineBlockParams: + Enabled: false + +Style/PerlBackrefs: + Enabled: false + +Layout/SpaceAfterComma: + Enabled: false + +Layout/SpaceAroundOperators: + Enabled: false + +Style/EmptyCaseCondition: + Enabled: false + +Style/MultilineBlockChain: + Enabled: false + +# See https://github.com/bbatsov/rubocop/issues/4429 +Style/YodaCondition: + Enabled: false + +Style/PercentLiteralDelimiters: + PreferredDelimiters: + '%i': '[]' + '%w': '[]' + +# Neither of prefered styles are good enough :( +Style/BlockDelimiters: + Enabled: false + +# Current preferred metrics -------------------------------------------- +# Better values are encouraged, but not required. +Metrics/AbcSize: + Max: 20 + +Metrics/MethodLength: + Max: 15 + +Metrics/CyclomaticComplexity: + Max: 7 + +# TODO ----------------------------------------------------------------- + +Style/Documentation: + Enabled: false + +# To discuss and decide ------------------------------------------------ + +# FIXME: in fact, rescue modifier is rarely a good choice. +# But currently I can't fully grasp the three places they are used. +# So, leaving them intact. - zverok, 2016-05-07 + + +# FIXME: once we should enable and fix it - zverok, 2016-05-07 +Style/Alias: + Enabled: false + +# FIXME: should decide about this. +# Personally I prefer (as most of Ruby community) to use parens, but +# we also can enforce style to NOT using them. Yet it definitely should +# be only one style. Current codebase uses ~400 method defs without and +# ~ 100 method defs with them. - zverok, 2016-05-07 +Style/MethodDefParentheses: + Enabled: false + +# Should be fixed, but require change of public API -------------------- + +# Bans methods like `has_missing_data?`, `is_number?` and so on - started +# with unnecessary has_ or is_. + + + diff --git a/lib/rubyplot.rb b/lib/rubyplot.rb index fc97ff9..5e6bd66 100644 --- a/lib/rubyplot.rb +++ b/lib/rubyplot.rb @@ -19,7 +19,8 @@ module Rubyplot def self.backend b = ENV['RUBYPLOT_BACKEND'] - return b.to_sym if b == "magick" || b == "gr" + return b.to_sym if %w[magick gr].include?(b) + :magick end end diff --git a/lib/rubyplot/artist/axes.rb b/lib/rubyplot/artist/axes.rb index 28cf8fa..b324e35 100644 --- a/lib/rubyplot/artist/axes.rb +++ b/lib/rubyplot/artist/axes.rb @@ -7,9 +7,7 @@ class Axes < Base LEGEND_MARGIN = TITLE_MARGIN = 20.0 LABEL_MARGIN = 10.0 DEFAULT_MARGIN = 20.0 - THOUSAND_SEPARATOR = ','.freeze - # FIXME: most of the below accessors should just be name= methods which # will access the required Artist and set the variable in there directly. # Title of the X axis @@ -19,16 +17,11 @@ class Axes < Base # Range of X axis. attr_accessor :x_range # Range of Y axis. - attr_accessor :y_range, - :x_tick_count, :y_tick_count, :text_font, :grid, - :bounding_box, :x_axis_padding, :y_axis_padding, :origin, - :title_shift, :title_margin - - # A hash of names for the individual columns, where the key is the array - # index for the column this label represents. - # + attr_accessor :y_range, :x_tick_count, :y_tick_count, :text_font, :grid, :bounding_box, :x_axis_padding, + :y_axis_padding, :origin, :title_shift, :title_margin + # A hash of names for the individual columns, where the key is the + # array index for the column this label represents. # Not all columns need to be named. - # # Example: 0 => 2005, 3 => 2006, 5 => 2007, 7 => 2008 attr_accessor :x_ticks attr_accessor :y_ticks @@ -40,11 +33,8 @@ class Axes < Base attr_reader :plots # data variables for something attr_reader :raw_rows - - attr_reader :geometry, :font, :marker_font_size, :legend_font_size, - :title_font_size, :scale, :font_color, :marker_color, :axes, - :legend_margin, :backend, :marker_caps_height, :marker_font_size - + attr_reader :geometry, :font, :legend_font_size, :title_font_size, :scale, :font_color + attr_reader :marker_color, :axes, :legend_margin, :backend, :marker_caps_height, :marker_font_size attr_reader :label_stagger_height # FIXME: possibly disposable attrs attr_reader :title_caps_height @@ -62,47 +52,33 @@ class Axes < Base attr_reader :y_axis # @param figure [Rubyplot::Figure] Figure object to which this Axes belongs. - def initialize figure + def initialize(figure) @figure = figure - - @x_title = '' - @y_title = '' - @x_axis_margin = 40.0 - @y_axis_margin = 40.0 - @x_range = [nil, nil] - @y_range = [nil, nil] - @x_tick_count = :default - @y_tick_count = :default - + @x_title = @y_title = '' + @x_axis_margin = @y_axis_margin = 40.0 + @x_range = @y_range = [nil, nil] + @x_tick_count = @y_tick_count = :default @origin = [nil, nil] - @title = "" + @title = '' @title_shift = 0 @title_margin = TITLE_MARGIN @text_font = :default - @grid = true - @bounding_box = true + @grid = @bounding_box = true @x_ticks = {} @plots = [] - @raw_rows = width * (height/width) - @theme = Rubyplot::Themes::CLASSIC_WHITE @geometry = Rubyplot::MagickWrapper::Plot::Scatter::Geometry.new vera_font_path = File.expand_path('Vera.ttf', ENV['MAGICK_FONT_PATH']) @font = File.exist?(vera_font_path) ? vera_font_path : nil - @font_color = "#000000" + @font_color = '#000000' @marker_font_size = 15.0 @legend_font_size = 20.0 @legend_margin = LEGEND_MARGIN @title_font_size = 25.0 @backend = @figure.backend - @plot_colors = [] - @legends = [] - @lines = [] - @texts = [] - @x_axis = nil - @y_axis = nil - + @plot_colors = @legends = @lines = @texts = [] + @x_axis = @y_axis = nil @legend_box_position = :top end @@ -121,7 +97,7 @@ def legend_box_iy abs_x + @x_axis_margin + @legend_margin end end - + # Write an image to a file by communicating with the backend. def draw configure_title @@ -132,54 +108,54 @@ def draw actually_draw end - def scatter! *args, &block + def scatter!(*_args) plot = Rubyplot::Artist::Plot::Scatter.new self yield(plot) if block_given? @plots << plot end - def bar! *args, &block + def bar!(*_args) plot = Rubyplot::Artist::Plot::Bar.new self yield(plot) if block_given? @plots << plot end - def line! *args, &block + def line!(*_args) plot = Rubyplot::Artist::Plot::Line.new self yield(plot) if block_given? @plots << plot end - def area! *args, &block - add_plot "Area", *args, &block + def area!(*args, &block) + add_plot 'Area', *args, &block end - def bubble! *args, &block - add_plot "Bubble", *args, &block + def bubble!(*args, &block) + add_plot 'Bubble', *args, &block end - def dot! *args, &block - add_plot "Dot", *args, &block + def dot!(*args, &block) + add_plot 'Dot', *args, &block end - def stacked_bar! *args, &block - add_plot "StackedBar", *args, &block + def stacked_bar!(*args, &block) + add_plot 'StackedBar', *args, &block end - def write file_name + def write(file_name) @plots[0].write file_name end - + # Absolute X co-ordinate of the Axes. Top left corner. def abs_x @figure.top_spacing * @figure.height + @figure.abs_x end - + # Absolute Y co-ordinate of the Axes. Top left corner. def abs_y @figure.top_spacing * @figure.height + @figure.abs_y end - + # Absolute width of the Axes in pixels. def width (1 - (@figure.left_spacing + @figure.right_spacing)) * @figure.width @@ -193,13 +169,13 @@ def height private - def add_plot plot_type, *args, &block + def add_plot(plot_type, *args) plot = with_backend plot_type, *args yield(plot) if block_given? @plots << plot end - def with_backend plot_type, *args + def with_backend(plot_type, *args) plot = case Rubyplot.backend when :magick @@ -207,26 +183,19 @@ def with_backend plot_type, *args when :gr Kernel.const_get("Rubyplot::GRWrapper::Plot::#{plot_type}").new self, *args end - plot end def prepare_legend @legends = @plots.map(&:create_legend) - @legends.each { |l| l.draw } + @legends.each(&:draw) end # Figure out the co-ordinates of the title text w.r.t Axes. def configure_title @title = Rubyplot::Artist::Text.new( - @title, - self, - abs_x: abs_x + width / 2, - abs_y: abs_y + @title_margin, - font: @font, - color: @font_color, - pointsize: @title_font_size, - internal_label: "axes title." + @title, self, abs_x: abs_x + width / 2, abs_y: abs_y + @title_margin, font: @font, color: @font_color, + pointsize: @title_font_size, internal_label: 'axes title.' ) end @@ -237,24 +206,20 @@ def calculate_xy_axes_origin # Figure out co-ordinatees of the XAxis and YAxis def configure_xy_axes - @x_axis = Rubyplot::Artist::XAxis.new( - self, @x_title, @x_range[0], @x_range[1]) - @y_axis = Rubyplot::Artist::YAxis.new( - self, @y_title, @y_range[0], @y_range[1]) + @x_axis = Rubyplot::Artist::XAxis.new(self, @x_title, @x_range[0], @x_range[1]) + @y_axis = Rubyplot::Artist::YAxis.new(self, @y_title, @y_range[0], @y_range[1]) end # Figure out co-ordinates of the legends def configure_legends @legend_box = Rubyplot::Artist::LegendBox.new( - self, abs_x: legend_box_ix, abs_y: legend_box_iy) + self, abs_x: legend_box_ix, abs_y: legend_box_iy + ) end - # Make adjustments to the data that will be plotted. Maps the data - # contained in the plot to actual pixel values. + # Make adjustments to the data that will be plotted. Maps the data contained in the plot to actual pixel values. def configure_plotting_data - @plots.each do |plot| - plot.normalize - end + @plots.each(&:normalize) end # Call the respective draw methods on each of the elements of this Axes. @@ -266,33 +231,31 @@ def actually_draw @plots.each(&:draw) end - # Return a formatted string representing a number value that should be - # printed as a label. + # Return a formatted string representing a number value that should be printed as a label. def label_string(value, increment) label = if increment if increment >= 10 || (increment * 1) == (increment * 1).to_i.to_f - format('%0i', value) + '%0i' % value elsif increment >= 1.0 || (increment * 10) == (increment * 10).to_i.to_f - format('%0.1f', value) + '%0.1f' % value elsif increment >= 0.1 || (increment * 100) == (increment * 100).to_i.to_f - format('%0.2f', value) + '%0.2f' % value elsif increment >= 0.01 || (increment * 1000) == (increment * 1000).to_i.to_f - format('%0.3f', value) + '%0.3f' % value elsif increment >= 0.001 || (increment * 10_000) == (increment * 10_000).to_i.to_f - format('%0.4f', value) + '%0.4f' % value else value.to_s end - elsif ((@y_spread.to_f % - (@geometry.marker_count.to_f == 0 ? - 1 : @geometry.marker_count.to_f) == 0) || - !@geometry.y_axis_increment .nil?) + elsif (@y_spread.to_f % + (@geometry.marker_count.to_f.zero ? 1 : @geometry.marker_count.to_f)).zero? || + !@geometry.y_axis_increment .nil? value.to_i.to_s elsif @y_spread > 10.0 - format('%0i', value) + '%0i' % value elsif @y_spread >= 3.0 - format('%0.2f', value) + '%0.2f' % value else value.to_s end @@ -300,6 +263,9 @@ def label_string(value, increment) parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{THOUSAND_SEPARATOR}") parts.join('.') end - end # class Axes - end # moudle Artist -end # module Rubyplot + end + # class Axes + end + # moudle Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/axis/base.rb b/lib/rubyplot/artist/axis/base.rb index 6681cc3..8964ca9 100644 --- a/lib/rubyplot/artist/axis/base.rb +++ b/lib/rubyplot/artist/axis/base.rb @@ -4,12 +4,12 @@ class Axis class Base # Length in pixels of the arrow after the last major tick. FINISH_ARROW_LENGTH = 10.0 - + attr_reader :label, :ticks, :major_ticks_count, :min_val, :max_val, :title attr_reader :abs_x1, :abs_x2, :abs_y1, :abs_y2, :backend attr_reader :stroke_width - - def initialize axes, title, min_val, max_val + + def initialize(axes, title, min_val, max_val) @axes = axes @title = title @min_val = min_val @@ -17,7 +17,11 @@ def initialize axes, title, min_val, max_val @stroke_width = 1.0 @backend = @axes.backend end - end # class Base - end # class Axis - end # class Artist -end # module Rubyplot + end + # class Base + end + # class Axis + end + # class Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/axis/x_axis.rb b/lib/rubyplot/artist/axis/x_axis.rb index 896777f..155b090 100644 --- a/lib/rubyplot/artist/axis/x_axis.rb +++ b/lib/rubyplot/artist/axis/x_axis.rb @@ -27,12 +27,13 @@ def draw def configure_axis_line @line = Rubyplot::Artist::Line2D.new( - self, abs_x1: @abs_x1, abs_y1: @abs_y1, abs_x2: @abs_x2, abs_y2: @abs_y2) - #stroke_width: @stroke_width) + self, abs_x1: @abs_x1, abs_y1: @abs_y1, abs_x2: @abs_x2, abs_y2: @abs_y2 + ) + # stroke_width: @stroke_width) end - + def populate_major_x_ticks - value_distance = (@max_val) / @major_ticks_count.to_f + value_distance = @max_val / @major_ticks_count.to_f @major_ticks_count.times do |count| count += 1 @x_ticks << Rubyplot::Artist::XTick.new( @@ -52,9 +53,12 @@ def configure_title self, pointsize: @axes.marker_font_size, abs_y: @axes.origin[1] + 20, - abs_x: @axes.origin[0] + (@abs_x2 - @abs_x1)/2, + abs_x: @axes.origin[0] + (@abs_x2 - @abs_x1)/2 ) end - end # class XAxis - end # class Artist -end # module Rubyplot + end + # class XAxis + end + # class Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/axis/y_axis.rb b/lib/rubyplot/artist/axis/y_axis.rb index 4ffe680..bb28fcf 100644 --- a/lib/rubyplot/artist/axis/y_axis.rb +++ b/lib/rubyplot/artist/axis/y_axis.rb @@ -16,7 +16,7 @@ def initialize(*) def draw @title.draw @line.draw - #@y_ticks.each(&:draw) + # @y_ticks.each(&:draw) end private @@ -31,7 +31,7 @@ def configure_axis_line stroke_width: @stroke_width ) end - + def configure_title @title = Rubyplot::Artist::Text.new( @title, @@ -43,9 +43,10 @@ def configure_title ) end - def populate_major_y_ticks - - end - end # class YAxis - end # class Artist -end # module Rubyplot + def populate_major_y_ticks; end + end + # class YAxis + end + # class Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/base.rb b/lib/rubyplot/artist/base.rb index b31fe2f..6e2cb66 100644 --- a/lib/rubyplot/artist/base.rb +++ b/lib/rubyplot/artist/base.rb @@ -7,12 +7,14 @@ class Base attr_reader :abs_x # Absolute Y co-ordinate of this Aritist on the canvas. attr_reader :abs_y - - def initialize backend, abs_x, abs_y + def initialize(backend, abs_x, abs_y) @backend = backend @abs_x = abs_x @abs_y = abs_y end - end # class Base - end # module Artist -end # module Rubyplot + end + # class Base + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/circle.rb b/lib/rubyplot/artist/circle.rb index 946d6dc..3386ff9 100644 --- a/lib/rubyplot/artist/circle.rb +++ b/lib/rubyplot/artist/circle.rb @@ -1,8 +1,9 @@ module Rubyplot module Artist class Circle < Base - def initialize(owner, abs_x:, abs_y:, radius: , stroke_opacity: 0.0, - color: '#000000', stroke_width:) + # rubocop:disable Metrics/ParameterLists + def initialize(owner, abs_x:, abs_y:, radius:, stroke_opacity: 0.0, + color: '#000000', stroke_width:) super(owner.backend, abs_x, abs_y) @owner = owner @radius = radius @@ -11,6 +12,7 @@ def initialize(owner, abs_x:, abs_y:, radius: , stroke_opacity: 0.0, @color = color @backend = @owner.backend end + # rubocop:enable Metrics/ParameterLists def draw @backend.draw_circle( @@ -18,6 +20,9 @@ def draw stroke_width: @stroke_width, color: @color ) end - end # class Circle - end # module Artist -end # module Rubyplot + end + # class Circle + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/figure.rb b/lib/rubyplot/artist/figure.rb index 0db7648..0140606 100644 --- a/lib/rubyplot/artist/figure.rb +++ b/lib/rubyplot/artist/figure.rb @@ -1,7 +1,7 @@ module Rubyplot module Artist class Figure < Artist::Base - DEFAULT_TARGET_WIDTH = 800 + DEFAULT_TARGET_WIDTH = 800 # Title on the figure. attr_reader :title @@ -45,16 +45,16 @@ def initialize add_subplots @nrows, @ncols end - def add_subplots nrows, ncols + def add_subplots(nrows, ncols) @subplots = Array.new(nrows) { Array.new(ncols) { nil } } end - def add_subplot nrow, ncol + def add_subplot(nrow, ncol) @subplots[nrow][ncol] = Rubyplot::Artist::Axes.new(self) end - def write file_name - @subplots.each { |i| i.each { |j| j.draw } } + def write(file_name) + @subplots.each { |i| i.each(&:draw) } @backend.write(file_name) end @@ -75,6 +75,9 @@ def setup_default_theme @theme_options[:background_direction] ) end - end # class Figure - end # module Artist -end # module Rubyplot + end + # class Figure + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/legend.rb b/lib/rubyplot/artist/legend.rb index 81108ab..105245d 100644 --- a/lib/rubyplot/artist/legend.rb +++ b/lib/rubyplot/artist/legend.rb @@ -7,6 +7,7 @@ class Legend < Artist::Base BOX_AND_TEXT_SPACE = 5.0 attr_reader :legend_box_size, :font, :font_size, :font_color + # rubocop:disable Metrics/ParameterLists def initialize(legend_box, axes, text:, color:,abs_x:,abs_y:) super(legend_box.backend, abs_x, abs_y) @legend_box = legend_box @@ -21,6 +22,7 @@ def initialize(legend_box, axes, text:, color:,abs_x:,abs_y:) configure_legend_color_box configure_legend_text end + # rubocop:enable Metrics/ParameterLists def draw @legend_color_box.draw @@ -52,6 +54,9 @@ def configure_legend_text pointsize: @font_size ) end - end # class Legend - end # class Artist -end # module Rubyplot + end + # class Legend + end + # class Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/legend_box.rb b/lib/rubyplot/artist/legend_box.rb index d96403c..e7b47c9 100644 --- a/lib/rubyplot/artist/legend_box.rb +++ b/lib/rubyplot/artist/legend_box.rb @@ -11,11 +11,11 @@ class LegendBox < Base RIGHT_SPACING_RATIO = 0.1 attr_accessor :border_color - + def initialize(axes, abs_x:, abs_y:) super(axes.backend, abs_x, abs_y) @axes = axes - @border_color = "#000000" + @border_color = '#000000' @legends = [] configure_dimensions configure_legends @@ -80,6 +80,9 @@ def configure_legends ) end end - end # class LegendBox - end # module Artist -end # module Rubyplot + end + # class LegendBox + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/line2d.rb b/lib/rubyplot/artist/line2d.rb index 886cd12..56cb423 100644 --- a/lib/rubyplot/artist/line2d.rb +++ b/lib/rubyplot/artist/line2d.rb @@ -1,8 +1,9 @@ module Rubyplot module Artist class Line2D < Artist::Base + # rubocop:disable Metrics/ParameterLists def initialize(owner,abs_x1:,abs_y1:,abs_x2:,abs_y2:,color: '#000000', - stroke_opacity: 0.0, stroke_width: 2.0) + stroke_opacity: 0.0, stroke_width: 2.0) @owner = owner @abs_x1 = abs_x1 @abs_y1 = abs_y1 @@ -13,11 +14,15 @@ def initialize(owner,abs_x1:,abs_y1:,abs_x2:,abs_y2:,color: '#000000', @stroke_width = stroke_width @backend = @owner.backend end + # rubocop:enable Metrics/ParameterLists def draw @backend.draw_line(x1: @abs_x1, y1: @abs_y1, x2: @abs_x2, y2: @abs_y2, stroke_width: @stroke_width) end - end # class Line2D - end # class Artist -end # module Rubyplot + end + # class Line2D + end + # class Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/plot/bar.rb b/lib/rubyplot/artist/plot/bar.rb index c9927ab..53a4735 100644 --- a/lib/rubyplot/artist/plot/bar.rb +++ b/lib/rubyplot/artist/plot/bar.rb @@ -14,18 +14,22 @@ def initialize(*) end # Set the spacing factor for this bar plot. - def spacing_factor= sf + def spacing_factor=(s_f) raise ValueError, '@spacing_factor must be between 0.00 and 1.00' unless - (sf >= 0) && (sf <= 1) - @spacing_factor = sf + (s_f >= 0) && (s_f <= 1) + + @spacing_factor = s_f end - + def draw super return unless @axes.geometry.has_data end - end # class Bar - end # module Plot - end # module Artist -end # module Rubyplot - + end + # class Bar + end + # module Plot + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/plot/base.rb b/lib/rubyplot/artist/plot/base.rb index 033cfcd..049121f 100644 --- a/lib/rubyplot/artist/plot/base.rb +++ b/lib/rubyplot/artist/plot/base.rb @@ -4,8 +4,8 @@ module Plot class Base < Artist::Base attr_reader :axes, :data attr_writer :stroke_width, :stroke_opacity - - def initialize axes + + def initialize(axes) @axes = axes @backend = @axes.backend @data = { @@ -13,8 +13,8 @@ def initialize axes color: :default } @normalized_data = { - :y_values => nil, - :x_values => nil + y_values: nil, + x_values: nil } @stroke_width = 4.0 @stroke_opacity = 0.0 @@ -28,20 +28,21 @@ def color @data[:color] end - def label= label + def label=(label) @data[:label] = label end - def color= color + def color=(color) @data[:color] = Rubyplot::Color::COLOR_INDEX[color] end - def data x_values, y_values + def data(x_values, y_values) @data[:x_values] = x_values @data[:y_values] = y_values # Set column count if this is larger than previous column counts - @axes.geometry.column_count = y_values.length > @axes.geometry.column_count ? - y_values.length : @axes.geometry.column_count + @axes.geometry.column_count =if y_values.length > @axes.geometry.column_count then y_values.length + else @axes.geometry.column_count + end if @axes.y_range[0].nil? && @axes.y_range[1].nil? @axes.y_range[0] = y_values.min @axes.y_range[1] = y_values.max @@ -60,14 +61,17 @@ def normalize x_spread = @axes.x_range[1] - x_min y_spread = @axes.y_range[1] - y_min @normalized_data[:x_values] = @data[:x_values].map do |x| - (x.to_f - x_min) / x_spread + (x.to_f - x_min) / x_spread end @normalized_data[:y_values] = @data[:y_values].map do |y| (y.to_f - y_min) / y_spread end end - end # class Base - end # module Plot - end # module Artist -end # module Rubyplot - + end + # class Base + end + # module Plot + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/plot/line.rb b/lib/rubyplot/artist/plot/line.rb index 3255c52..3319236 100644 --- a/lib/rubyplot/artist/plot/line.rb +++ b/lib/rubyplot/artist/plot/line.rb @@ -4,19 +4,20 @@ module Plot class Line < Artist::Plot::Base # Set true if you want to see only the vertices of the line plot. attr_writer :hide_lines - + def initialize(*) super - @hide_lines = false + @hide_lines = false end - def data x_values, y_values=[] + def data(x_values, y_values=[]) y_values = Array.new(x_values.size) { |i| i } if y_values.empty? super x_values, y_values end def draw return unless @axes.geometry.has_data + if @normalized_data[:x_values].size == 1 draw_single_point else @@ -37,23 +38,22 @@ def draw_lines iy = @normalized_data[:y_values][idx_ix] new_x = ix * @axes.graph_width + @axes.graph_left new_y = @axes.graph_top + (@axes.graph_height - iy * @axes.graph_height) - if !(prev_x.nil? && prev_y.nil?) + unless prev_x.nil? && prev_y.nil? Rubyplot::Artist::Line2D.new( - self, - x1: prev_x, - y1: prev_y, - x2: new_x, - y2: new_y, - stroke_opacity: @stroke_opacity, - stroke_width: @stroke_width + self,x1: prev_x,y1: prev_y,x2: new_x,y2: new_y, + stroke_opacity: @stroke_opacity, + stroke_width: @stroke_width ).draw end prev_x = new_x prev_y = new_y end end - end # class Line - end # module Plot - end # module Artist -end # module Rubyplot - + end + # class Line + end + # module Plot + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/plot/scatter.rb b/lib/rubyplot/artist/plot/scatter.rb index d55863d..effd081 100644 --- a/lib/rubyplot/artist/plot/scatter.rb +++ b/lib/rubyplot/artist/plot/scatter.rb @@ -3,7 +3,7 @@ module Artist module Plot class Scatter < Artist::Plot::Base attr_writer :circle_radius - + def initialize(*) super @circle_radius = 4.0 @@ -16,20 +16,20 @@ def draw @normalized_data[:y_values].each_with_index do |iy, idx_y| ix = @normalized_data[:x_values][idx_y] next if iy.nil? || ix.nil? - abs_x = ix * (@axes.x_axis.abs_x2 - @axes.x_axis.abs_x1).abs + @axes.abs_x + - @axes.y_axis_margin + + abs_x = ix * (@axes.x_axis.abs_x2 - @axes.x_axis.abs_x1).abs + @axes.abs_x + @axes.y_axis_margin abs_y = (y_axis_length - iy * y_axis_length) + @axes.abs_y Rubyplot::Artist::Circle.new( - self, - abs_x: abs_x, - abs_y: abs_y, - radius: @circle_radius, - stroke_opacity: @stroke_opacity, - stroke_width: @stroke_width + self, abs_x: abs_x, abs_y: abs_y, radius: @circle_radius, stroke_opacity: @stroke_opacity, + stroke_width: @stroke_width ).draw end end - end # class Scatter - end # module Plot - end # module Artist -end # module Rubyplot + end + # class Scatter + end + # module Plot + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/rectangle.rb b/lib/rubyplot/artist/rectangle.rb index 94fb92a..5233bb3 100644 --- a/lib/rubyplot/artist/rectangle.rb +++ b/lib/rubyplot/artist/rectangle.rb @@ -3,13 +3,16 @@ module Artist class Rectangle < Base attr_reader :width, :height, :border_color, :fill_color - def initialize(owner,abs_x:,abs_y:,width:,height:,border_color:,fill_color: nil) + # rubocop:disable Metrics/ParameterLists + def initialize(owner,abs_x:,abs_y:,width:, + height:,border_color:,fill_color: nil) super(owner.backend, abs_x, abs_y) @height = height @width = width @border_color = border_color @fill_color = fill_color end + # rubocop:enable Metrics/ParameterLists def draw @backend.draw_rectangle( @@ -21,6 +24,9 @@ def draw fill_color: @fill_color ) end - end # class Rectangle - end # class Artist -end # moduel Rubyplot + end + # class Rectangle + end + # class Artist +end +# moduel Rubyplot diff --git a/lib/rubyplot/artist/text.rb b/lib/rubyplot/artist/text.rb index 413a01f..50edf25 100644 --- a/lib/rubyplot/artist/text.rb +++ b/lib/rubyplot/artist/text.rb @@ -3,11 +3,12 @@ module Artist class Text < Artist::Base # (X,Y) of upper left corner of the rectangle. attr_reader :color, :font, :pointsize, - :stroke, :weight, :gravity, :text, :backend - + :stroke, :weight, :gravity, :text, :backend + + # rubocop:disable Metrics/ParameterLists def initialize(text, owner, abs_x:, abs_y:,font: nil, - color: '#000000',pointsize:,stroke: 'transparent', - weight: nil,gravity: nil, internal_label: "", rotation: nil) + color: '#000000',pointsize:,stroke: 'transparent', internal_label: '', rotation: nil) + # weight: nil, gravity: nil is removed as they are unused method argument. @text = text @owner = owner @abs_x = abs_x @@ -20,6 +21,7 @@ def initialize(text, owner, abs_x:, abs_y:,font: nil, @backend = @owner.backend @rotation = rotation end + # rubocop:enable Metrics/ParameterLists # Height in pixels of this text def height @@ -43,6 +45,9 @@ def draw rotation: @rotation ) end - end # class Text - end # class Artist -end # module Rubyplot + end + # class Text + end + # class Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/tick/base.rb b/lib/rubyplot/artist/tick/base.rb index e8ab4aa..27bb1f6 100644 --- a/lib/rubyplot/artist/tick/base.rb +++ b/lib/rubyplot/artist/tick/base.rb @@ -16,8 +16,10 @@ class Base # @param label [String] Label below the tick. # @param label_distance [Integer] Distance between the label and tick. # @param tick_opacity [Float] Number describing the opacity of the tick drawn. 0-1.0. + + # rubocop:disable Metrics/ParameterLists def initialize(owner,abs_x:,abs_y:,length:,label:,label_distance:, - tick_opacity: 0.0,tick_width: 1.0) + tick_opacity: 0.0,tick_width: 1.0) @owner = owner @abs_x = abs_x @abs_y = abs_y @@ -28,7 +30,12 @@ def initialize(owner,abs_x:,abs_y:,length:,label:,label_distance:, @tick_width = tick_width @backend = @owner.backend end - end # class Base - end # class Tick - end # class Artist -end # module Rubyplot + # rubocop:enable Metrics/ParameterLists + end + # class Base + end + # class Tick + end + # class Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/tick/x_tick.rb b/lib/rubyplot/artist/tick/x_tick.rb index b7f6e1d..8ac24e8 100644 --- a/lib/rubyplot/artist/tick/x_tick.rb +++ b/lib/rubyplot/artist/tick/x_tick.rb @@ -8,17 +8,20 @@ def initialize(*) @owner, abs_x: @abs_x - 5, abs_y: @abs_y + @length + @label_distance, - pointsize: @owner.marker_font_size, + pointsize: @owner.marker_font_size ) end - + def draw @backend.draw_line( x1: @abs_x, y1: @abs_y, x2: @abs_x, y2: @abs_y + @length, stroke_opacity: @tick_opacity, - stroke_width: @tick_width) + stroke_width: @tick_width + ) @label.draw end end - end # class Artist -end # module Rubyplot + end + # class Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/tick/y_tick.rb b/lib/rubyplot/artist/tick/y_tick.rb index a31a75e..ed22860 100644 --- a/lib/rubyplot/artist/tick/y_tick.rb +++ b/lib/rubyplot/artist/tick/y_tick.rb @@ -1,6 +1,9 @@ module Rubyplot module Artist class YTick < Tick::Base - end # class YTick - end # module Artist -end # module Rubyplot + end + # class YTick + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/backend/magick_wrapper.rb b/lib/rubyplot/backend/magick_wrapper.rb index e6bbac1..db574fa 100644 --- a/lib/rubyplot/backend/magick_wrapper.rb +++ b/lib/rubyplot/backend/magick_wrapper.rb @@ -1,4 +1,4 @@ -module Rubyplot +module Rubyplot module Backend class MagickWrapper include ::Magick @@ -8,10 +8,10 @@ class MagickWrapper :west => Magick::WestGravity, :east => Magick::EastGravity, :north => Magick::NorthGravity - } + }.freeze attr_reader :draw - + def initialize @draw = Magick::Draw.new end @@ -21,7 +21,7 @@ def initialize # # Not scaled since it deals with dimensions that the regular scaling will # handle. - def caps_height font, font_size + def caps_height(font, font_size) @draw.pointsize = font_size @draw.font = font if font @draw.get_type_metrics(@base_image, 'X').height @@ -32,7 +32,7 @@ def caps_height font, font_size # Not scaled since it deals with dimensions that the regular # scaling will handle. # FIXME: duplicate with get_text_width_height - def string_width font, font_size, text + def string_width(font, font_size, text) @draw.pointsize = font_size @draw.font = font if font @draw.get_type_metrics(@base_image, text.to_s).height @@ -40,7 +40,7 @@ def string_width font, font_size, text # Height in pixels of particular text. # @param text [String] Text to be measured. - def text_height text, font, font_size + def text_height(text, font, font_size) @draw.pointsize = font_size @draw.font = font if font @draw.get_type_metrics(@base_image, text.to_s).height @@ -48,81 +48,85 @@ def text_height text, font, font_size # Width in pixels of particular text. # @param text [String] Text to be measured. - def text_width text, font, font_size + def text_width(text, font, font_size) @draw.pointsize = font_size @draw.font = font if font @draw.get_type_metrics(@base_image, text.to_s).width end # Scale backend canvas to required proportion. - def scale scale + def scale(scale) @draw.scale(scale, scale) end - def set_base_image_gradient top_color, bottom_color, width, height, direct=:top_bottom + def set_base_image_gradient(top_color, bottom_color, width, height, direct=:top_bottom) @base_image = render_gradient top_color, bottom_color, width, height, direct end # Get the width and height of the text in pixels. - def get_text_width_height text + def get_text_width_height(text) metrics = @draw.get_type_metrics(@base_image, text) [metrics.width, metrics.height] end - def draw_text(text,font_color:,font: nil,pointsize:,stroke:, - font_weight: Magick::NormalWeight, gravity: nil, - x:,y:,rotation: nil) + # rubocop:disable Metrics/ParameterLists + # Unused method argument - stroke + def draw_text(text,font_color:,font: nil,pointsize:, + font_weight: Magick::NormalWeight, gravity: nil, + x_pos:,y_pos:,rotation: nil) @draw.fill = font_color @draw.font = font if font @draw.pointsize = pointsize @draw.font_weight = font_weight @draw.gravity = GRAVITY_MEASURE[gravity] || Magick::ForgetGravity @draw.rotation = rotation if rotation - @draw.annotate(@base_image, 0,0,x.to_i,y.to_i, text.gsub('%', '%%')) + @draw.annotate(@base_image, 0,0,x_pos.to_i,y_pos.to_i, text.gsub('%', '%%')) @draw.rotation = 90.0 if rotation end # Draw a rectangle. - def draw_rectangle(x1:,y1:,x2:,y2:,border_color: '#000000',stroke: 'transparent', - fill_color: nil, stroke_width: 1.0) + def draw_rectangle(x01:,y01:,x02:,y02:,border_color: '#000000',stroke: 'transparent', + fill_color: nil, stroke_width: 1.0) if fill_color # solid rectangle @draw.stroke stroke @draw.fill fill_color @draw.stroke_width stroke_width - @draw.rectangle x1, y1, x2, y2 + @draw.rectangle x01, y01, x02, y02 else # just edges @draw.stroke_width stroke_width @draw.fill border_color - @draw.line x1, y1, x1 + (x2-x1), y1 # top line - @draw.line x1 + (x2-x1), y1, x2, y2 # right line - @draw.line x2, y2, x1, y1 + (y2-y1) # bottom line - @draw.line x1, y1, x1, y1 + (y2-y1) # left line + @draw.line x01, y01, x01 + (x02-x01), y01 # top line + @draw.line x01 + (x02-x01), y01, x02, y02 # right line + @draw.line x02, y02, x01, y01 + (y02-y01) # bottom line + @draw.line x01, y01, x01, y01 + (y02-y01) # left line end end - def draw_line(x1:,y1:,x2:,y2:,color: '#000000', stroke: 'transparent', - stroke_opacity: 0.0, stroke_width: 2.0) + def draw_line(x01:,y01:,x02:,y02:,color: '#000000', stroke: 'transparent', + stroke_opacity: 0.0, stroke_width: 2.0) @draw.stroke_opacity stroke_opacity @draw.stroke_width stroke_width @draw.fill color - @draw.line x1, y1, x2, y2 + @draw.line x01, y01, x02, y02 end - def draw_circle(x:,y:,radius:,stroke_opacity:,stroke_width:,color:) + def draw_circle(x_pos:,y_pos:,radius:,stroke_opacity:,stroke_width:,color:) @draw.stroke_opacity stroke_opacity @draw.stroke_width stroke_width @draw.fill color - @draw.circle(x,y,x-radius,y) + @draw.circle(x_pos,y_pos,x-radius,y) end + # rubocop:enable Metrics/ParameterLists - def write file_name + def write(file_name) @draw.draw(@base_image) @base_image.write(file_name) end private + # Render a gradient and return an Image. - def render_gradient top_color, bottom_color, width, height, direct + def render_gradient(top_color, bottom_color, width, height, direct) gradient_fill = case direct when :bottom_top GradientFill.new(0, 0, 100, 0, bottom_color, top_color) @@ -139,6 +143,9 @@ def render_gradient top_color, bottom_color, width, height, direct end Image.new(width, height, gradient_fill) end - end # class MagickWrapper - end # module Backend -end # module Rubyplot + end + # class MagickWrapper + end + # module Backend +end +# module Rubyplot diff --git a/lib/rubyplot/gr_wrapper/plot/base_plot/lazy_base.rb b/lib/rubyplot/gr_wrapper/plot/base_plot/lazy_base.rb index 5849397..a3d2141 100644 --- a/lib/rubyplot/gr_wrapper/plot/base_plot/lazy_base.rb +++ b/lib/rubyplot/gr_wrapper/plot/base_plot/lazy_base.rb @@ -10,9 +10,7 @@ def initialize end def call - @tasks.each do |task| - task.call() - end + @tasks.each(&:call) end end end diff --git a/lib/rubyplot/gr_wrapper/plot/base_plot/robust_base.rb b/lib/rubyplot/gr_wrapper/plot/base_plot/robust_base.rb index 1820db9..68a8c69 100644 --- a/lib/rubyplot/gr_wrapper/plot/base_plot/robust_base.rb +++ b/lib/rubyplot/gr_wrapper/plot/base_plot/robust_base.rb @@ -4,9 +4,9 @@ module Plot module BasePlot class RobustBase include Rubyplot::GRWrapper::Tasks - + attr_reader :plot_type - + def initialize @tasks = [] @plot_type = :robust @@ -14,12 +14,12 @@ def initialize # FIXME: writer to canvas is also part of this class, similar to Magick backend. # In the future both should be abstracted to another rendering class. - def write file_name + def write(file_name) BeginPrint.new(file_name).call - + # FIXME: remove @identity varible. @identity = [@axes.figure.nrows, @axes.figure.ncols, @axes.position+1] - + r = (@identity[2].to_f / @identity[1].to_f).ceil c = (@identity[2] % @identity[1]).zero? ? @identity[1] : @identity[2] % @identity[1] @ymax = 1 - (1.to_f / @identity[0]) * (r - 1) - 0.095 / @identity[0] @@ -37,27 +37,28 @@ def write file_name SetViewPort.new(@xmin, @xmax, @ymin, @ymax).call SetWindow.new(@axes.x_range[0] - @axes.x_axis_padding, - @axes.x_range[1] + @axes.x_axis_padding, - @axes.y_range[0] - @axes.y_axis_padding, - @axes.y_range[1] + @axes.y_axis_padding).call + @axes.x_range[1] + @axes.x_axis_padding, + @axes.y_range[0] - @axes.y_axis_padding, + @axes.y_range[1] + @axes.y_axis_padding).call # Make sure that window is set bigger than range figure out how to manage it SetTextAlign.new(2, 0).call @axes.text_font = :times_roman if @axes.text_font == :default SetTextFontPrecision.new(GR_FONTS[@axes.text_font], - GR_FONT_PRECISION[:text_precision_string]).call + GR_FONT_PRECISION[:text_precision_string]).call SetCharHeight.new(0.012).call @axes.y_tick_count = 10 if @axes.y_tick_count == :default @axes.x_tick_count = 10 if @axes.x_tick_count == :default # 10 ticks by default SetLineColorIndex.new(hex_color_to_gr_color_index( - Rubyplot::Color::COLOR_INDEX[:black])).call + Rubyplot::Color::COLOR_INDEX[:black] + )).call SetLineWidth.new(1).call SetLineType.new(GR_LINE_TYPES[:solid]).call Grid.new((@axes.x_range[1] - @axes.x_range[0]).to_f / @axes.x_tick_count, - (@axes.y_range[1] - @axes.y_range[0]).to_f / @axes.y_tick_count, - 0, 0, 1, 1).call + (@axes.y_range[1] - @axes.y_range[0]).to_f / @axes.y_tick_count, + 0, 0, 1, 1).call Tasks::Axes.new((@axes.x_range[1] - @axes.x_range[0]).to_f / @axes.x_tick_count, - (@axes.y_range[1] - @axes.y_range[0]).to_f / @axes.y_tick_count, - @axes.origin[0], @axes.origin[1], 1, 1, 0.01).call + (@axes.y_range[1] - @axes.y_range[0]).to_f / @axes.y_tick_count, + @axes.origin[0], @axes.origin[1], 1, 1, 0.01).call Tasks::AxesTitles.new(@axes.x_title, @axes.y_title, '').call call @@ -70,6 +71,9 @@ def write file_name end end end - end # module Plot - end # module GRWrapper -end # module Rubyplot + end + # module Plot + end + # module GRWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/gr_wrapper/plot/scatter.rb b/lib/rubyplot/gr_wrapper/plot/scatter.rb index ce45d5d..b3f953b 100644 --- a/lib/rubyplot/gr_wrapper/plot/scatter.rb +++ b/lib/rubyplot/gr_wrapper/plot/scatter.rb @@ -2,7 +2,7 @@ module Rubyplot module GRWrapper module Plot class Scatter < BasePlot::RobustBase - def initialize axes, *args + def initialize(axes, *_args) super() @axes = axes @color = hex_color_to_gr_color_index(Rubyplot::Color::COLOR_INDEX[:black]) @@ -10,7 +10,7 @@ def initialize axes, *args @marker_type = GR_MARKER_SHAPES[:solid_circle] end - def data x_values, y_values + def data(x_values, y_values) @axes.x_range[0] = x_values.min if @axes.x_range[0].nil? @axes.x_range[1] = x_values.max if @axes.x_range[1].nil? @axes.x_range[0] = x_values.min if x_values.min < @axes.x_range[0] @@ -19,24 +19,22 @@ def data x_values, y_values @axes.y_range[1] = y_values.max if @axes.y_range[1].nil? @axes.y_range[0] = y_values.min if y_values.min < @axes.y_range[0] @axes.y_range[1] = y_values.max if y_values.max > @axes.y_range[1] - + @x_values = x_values @y_values = y_values end - def label= label + def label=(label) # TODO : implement labels end - def color= color + def color=(color) @color = hex_color_to_gr_color_index(Rubyplot::Color::COLOR_INDEX[color]) end - def marker_size= marker_size - @marker_size = marker_size - end + attr_writer :marker_size - def marker_type= marker_type + def marker_type=(marker_type) @marker_type = GR_MARKER_SHAPES[marker_type] end @@ -45,10 +43,14 @@ def call @tasks.push(SetMarkerSize.new(@marker_size)) @tasks.push(SetMarkerType.new(@marker_type)) @tasks.push(Polymarker.new(@x_values, @y_values)) - + @tasks.each(&:call) end - end # class Scatter - end # module Plot - end # module GRWrapper -end # module Rubyplot + end + # class Scatter + end + # module Plot + end + # module GRWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/gr_wrapper/tasks.rb b/lib/rubyplot/gr_wrapper/tasks.rb index 99acd1d..c867ee1 100644 --- a/lib/rubyplot/gr_wrapper/tasks.rb +++ b/lib/rubyplot/gr_wrapper/tasks.rb @@ -4,8 +4,8 @@ module Tasks def hex_color_to_gr_color_index(rgbstring) rgb = rgbstring.match /#(..)(..)(..)/ GR.inqcolorfromrgb((rgb[1].hex.to_f/255.0), - (rgb[2].hex.to_f/255.0), - (rgb[3].hex.to_f/255.0)) + (rgb[2].hex.to_f/255.0), + (rgb[3].hex.to_f/255.0)) end class BeginPrint @@ -43,6 +43,7 @@ def initialize(x_coordinates, y_coordinates) @x_coordinates = x_coordinates @y_coordinates = y_coordinates end + def call GR.polymarker(@x_coordinates, @y_coordinates) end @@ -53,6 +54,7 @@ def initialize(x_coordinates, y_coordinates) @x_coordinates = x_coordinates @y_coordinates = y_coordinates end + def call GR.polyline(@x_coordinates, @y_coordinates) end @@ -221,9 +223,10 @@ def call end end + # rubocop:disable Metrics/ParameterLists class Axes def initialize(x_major_tick, y_major_tick, x_origin, y_origin, major_x, - major_y, tick_size) + major_y, tick_size) @x_major_tick = x_major_tick @y_major_tick = y_major_tick @x_origin = x_origin @@ -235,13 +238,13 @@ def initialize(x_major_tick, y_major_tick, x_origin, y_origin, major_x, def call GR.axes(@x_major_tick, @y_major_tick, @x_origin, @y_origin, @major_x, - @major_y, @tick_size) + @major_y, @tick_size) end end class Grid def initialize(x_major_tick, y_major_tick, x_origin, y_origin, major_x, - major_y) + major_y) @x_major_tick = x_major_tick @y_major_tick = y_major_tick @x_origin = x_origin @@ -252,7 +255,7 @@ def initialize(x_major_tick, y_major_tick, x_origin, y_origin, major_x, def call GR.grid(@x_major_tick, @y_major_tick, @x_origin, @y_origin, @major_x, - @major_y) + @major_y) end end @@ -280,7 +283,7 @@ def initialize(x_min, x_max, y_min, y_max, starting_angle, ending_angle) def call GR.drawarc(@x_min, @x_max, @y_min, @y_max, @starting_angle, - @ending_angle) + @ending_angle) end end @@ -296,9 +299,10 @@ def initialize(x_min, x_max, y_min, y_max, starting_angle, ending_angle) def call GR.fillarc(@x_min, @x_max, @y_min, @y_max, @starting_angle, - @ending_angle) + @ending_angle) end end + # rubocop:enable Metrics/ParameterLists GR_FONTS = { times_roman: 101, @@ -402,6 +406,9 @@ def call pattern: 2, hatch: 3 }.freeze - end # module Tasks - end # module GRWrapper -end # module Rubyplot + end + # module Tasks + end + # module GRWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper.rb b/lib/rubyplot/magick_wrapper.rb index 11d0576..5bcd9b1 100644 --- a/lib/rubyplot/magick_wrapper.rb +++ b/lib/rubyplot/magick_wrapper.rb @@ -3,5 +3,3 @@ require_relative 'magick_wrapper/artist' require_relative 'magick_wrapper/themes' require_relative 'magick_wrapper/plot' - - diff --git a/lib/rubyplot/magick_wrapper/artist.rb b/lib/rubyplot/magick_wrapper/artist.rb index 63808a5..59f7b8c 100644 --- a/lib/rubyplot/magick_wrapper/artist.rb +++ b/lib/rubyplot/magick_wrapper/artist.rb @@ -14,7 +14,7 @@ class Artist include Attributes include MathMethods include Magick - + # If one numerical argument is given, the graph is drawn at 4/3 ratio # according to the given width (800 results in 800x600, 400 gives 400x300, # etc.). @@ -23,9 +23,9 @@ class Artist # # Looks for Bitstream Vera as the default font. Expects an environment var # of MAGICK_FONT_PATH to be set. (Uses RMagick's default font otherwise.) - def initialize(axes, target_width = DEFAULT_TARGET_WIDTH) + def initialize(axes, target_width=DEFAULT_TARGET_WIDTH) @axes = axes - if Numeric === target_width + if Numeric == target_width @columns = target_width.to_f @rows = target_width.to_f * 0.75 else @@ -40,11 +40,9 @@ def initialize(axes, target_width = DEFAULT_TARGET_WIDTH) self.theme = Themes::CLASSIC_WHITE end - def marker_size= marker_size - end + def marker_size=(marker_size); end - def marker_type= marker_type - end + def marker_type=(marker_type); end # Set instance variables for this object. # @@ -84,16 +82,18 @@ def initialize_variables @plot_colors = [] end - def data(data_points = [], label: :default, color: :default) - name = (label == :default) ? ' ' : label.to_s + def data(data_points=[], label: :default) + # color: :default is removed as it is unused. + name = label == :default ? ' ' : label.to_s data_points = Array(data_points) # make sure it's an array # TODO: Adding an empty color array which can be developed later # to make graphs super customizable with regards to coloring of # individual data points. @data[:y_values] = data_points # Set column count if this is larger than previous column counts - @geometry.column_count = data_points.length > @geometry.column_count ? - data_points.length : @geometry.column_count + @geometry.column_count =if data_points.length > @geometry.column_count then data_points.length + else @geometry.column_count + end # Pre-normalize => Set the max and min values of the data. data_points.each do |data_point| @@ -103,10 +103,8 @@ def data(data_points = [], label: :default, color: :default) @geometry.maximum_value = @geometry.minimum_value = data_point end - @geometry.maximum_value = data_point > @geometry.maximum_value ? - data_point : @geometry.maximum_value - @geometry.minimum_value = data_point < @geometry.minimum_value ? - data_point : @geometry.minimum_value + @geometry.maximum_value = data_point > @geometry.maximum_value ? data_point : @geometry.maximum_value + @geometry.minimum_value = data_point < @geometry.minimum_value ? data_point : @geometry.minimum_value @geometry.has_data = true end end @@ -136,7 +134,8 @@ def theme=(options) @base_image = render_gradiated_background( @geometry.theme_options[:background_colors][0], @geometry.theme_options[:background_colors][1], - @geometry.theme_options[:background_direction]) + @geometry.theme_options[:background_direction] + ) end # Resets the themes to defaults. @@ -155,29 +154,30 @@ def scale(value) # the colors for data labels if user doesn't specify the colors for data labels. def construct_colors_array return unless @plot_colors.empty? + # 0.upto(@geometry.norm_data.size - 1) do |i| - if (@data[:color] == :default) - @plot_colors.push(@geometry.theme_options[:label_colors][0]) - else - @plot_colors.push(Rubyplot::Color::COLOR_INDEX[@data[:color]]) - end + if @data[:color] == :default + @plot_colors.push(@geometry.theme_options[:label_colors][0]) + else + @plot_colors.push(Rubyplot::Color::COLOR_INDEX[@data[:color]]) + end # end end # Sets the colors for the data labels of the plot. - def set_colors_array(color_array) + def colors_array_set(color_array) @plot_colors = color_array end # Returns the current color array for the labels - def get_colors_array + def colors_array_get @plot_colors end # Writes the plot to a file. Defaults to 'plot.png' # All file writing formats supported by RMagicks are supported by this # function. - def write(filename = 'plot.png') + def write(filename='plot.png') draw @base_image.write(filename) end @@ -194,6 +194,7 @@ def draw # with subclasses used to define different plots. def artist_draw return unless @geometry.has_data + setup_drawing construct_colors_array # ideal scenario should be to just instruct the backend to write @@ -227,8 +228,9 @@ def setup_drawing def setup_graph_measurements @marker_caps_height = calculate_caps_height(@marker_font_size) - @title_caps_height = @geometry.hide_title || @axes.title.nil? ? 0 : - calculate_caps_height(@title_font_size) * @axes.title.lines.to_a.size + @title_caps_height =if @geometry.hide_title || @axes.title.nil? then 0 + else calculate_caps_height(@title_font_size) * @axes.title.lines.to_a.size + end # Initially the title is nil. @legend_caps_height = calculate_caps_height(@legend_font_size) @@ -237,21 +239,24 @@ def setup_graph_measurements # makes sense to only have this as an attribute for this kind of # graph and not for others. # FIXME: move this out of Artist. - if @geometry.has_left_labels - longest_left_label_width = calculate_width( - @marker_font_size, - @axes.y_ticks.values.inject('') { |value, memo| - value.to_s.length > memo.to_s.length ? value : memo - }) * 1.25 - else - longest_left_label_width = calculate_width( - @marker_font_size, - label_string(@geometry.maximum_value.to_f, @geometry.increment)) - end + longest_left_label_width = if @geometry.has_left_labels + calculate_width( + @marker_font_size, + @axes.y_ticks.values.inject('') { |value, memo| + value.to_s.length > memo.to_s.length ? value : memo + } + ) * 1.25 + else + calculate_width( + @marker_font_size, + label_string(@geometry.maximum_value.to_f, @geometry.increment) + ) + end # Shift graph if left line numbers are hidden - line_number_width = @geometry.hide_line_numbers && !@geometry.has_left_labels ? - 0.0 : (longest_left_label_width + LABEL_MARGIN * 2) + line_number_width =if @geometry.hide_line_numbers && !@geometry.has_left_labels then 0.0 + else longest_left_label_width + LABEL_MARGIN * 2 + end # Pixel offset from the left edge of the plot @graph_left = @geometry.left_margin + @@ -260,10 +265,10 @@ def setup_graph_measurements # Make space for half the width of the rightmost column label. last_label = @axes.x_ticks.keys.max.to_i - extra_room_for_long_label = last_label >= (@geometry.column_count - 1) && - @geometry.center_labels_over_point ? - calculate_width(@marker_font_size, - @axes.x_ticks[last_label]) / 2.0 : 0 + extra_room_for_long_label =if last_label >= (@geometry.column_count - 1) && @geometry.center_labels_over_point + calculate_width(@marker_font_size,@axes.x_ticks[last_label]) / 2.0 + else 0 + end # Margins @graph_right_margin = @geometry.right_margin + extra_room_for_long_label @@ -273,16 +278,13 @@ def setup_graph_measurements @graph_width = @geometry.raw_columns - @graph_left - @graph_right_margin # When @hide title, leave a title_margin space for aesthetics. - @graph_top = @geometry.legend_at_bottom ? - @geometry.top_margin : - (@geometry.top_margin + - (@geometry.hide_title ? - @axes.title_margin : - @title_caps_height + @axes.title_margin) + - (@legend_caps_height + legend_margin)) + @graph_top =if @geometry.legend_at_bottom then @geometry.top_margin + else (@geometry.top_margin + if @geometry.hide_title then @axes.title_margin + else @title_caps_height + @axes.title_margin + end + (@legend_caps_height + legend_margin)) + end - x_axis_label_height = @geometry.x_axis_label .nil? ? 0.0 : - @marker_caps_height + LABEL_MARGIN + x_axis_label_height = @geometry.x_axis_label .nil? ? 0.0 : @marker_caps_height + LABEL_MARGIN # The actual height of the graph inside the whole image in pixels. @graph_bottom = @raw_rows - @graph_bottom_margin - x_axis_label_height - @label_stagger_height @@ -303,20 +305,16 @@ def draw_axis_labels! @d.stroke('transparent') @d.pointsize = scale_fontsize(@marker_font_size) @d.gravity = NorthGravity - @d = @d.scale_annotation(@base_image, - @geometry.raw_columns, 1.0, - 0.0, x_axis_label_y_coordinate, - @geometry.x_axis_label, @scale) + @d = @d.scale_annotation(@base_image, @geometry.raw_columns, 1.0, 0.0, x_axis_label_y_coordinate, + @geometry.x_axis_label, @scale) end unless @geometry.y_axis_label .nil? # Y Axis, rotated vertically @d.rotation = -90.0 @d.gravity = CenterGravity - @d = @d.scale_annotation(@base_image, - 1.0, @raw_rows, - @geometry.left_margin + @marker_caps_height / 2.0, 0.0, - @geometry.y_axis_label, @scale) + @d = @d.scale_annotation(@base_image, 1.0, @raw_rows, @geometry.left_margin + @marker_caps_height / 2.0, 0.0, + @geometry.y_axis_label, @scale) @d.rotation = 90.0 end end @@ -332,9 +330,9 @@ def draw_title! @d.font_weight = BoldWeight @d.gravity = NorthGravity @d = @d.scale_annotation(@base_image, - @geometry.raw_columns, 1.0, - 0, @geometry.top_margin, - @axes.title, @scale) + @geometry.raw_columns, 1.0, + 0, @geometry.top_margin, + @axes.title, @scale) end ## @@ -342,7 +340,7 @@ def draw_title! # to the colors used to draw them. def draw_legend! # FIXME: reflect single data behaviour - @legend_labels = [@data[:label]]#@data.collect { |item| item[DATA_LABEL_INDEX] } + @legend_labels = [@data[:label]] # @data.collect { |item| item[DATA_LABEL_INDEX] } legend_square_width = @legend_box_size # small square with color of this item @@ -356,17 +354,16 @@ def draw_legend! label_width = metrics.width + legend_square_width * 2.7 label_widths.last.push label_width - if sum(label_widths.last) > (@geometry.raw_columns * 0.9) - label_widths.push [label_widths.last.pop] - end + label_widths.push [label_widths.last.pop] if sum(label_widths.last) > (@geometry.raw_columns * 0.9) end current_x_offset = center(sum(label_widths.first)) - current_y_offset = @geometry.legend_at_bottom ? @graph_height + @axes.title_margin : ( - @geometry.hide_title ? @geometry.top_margin + @axes.title_margin : - @geometry.top_margin + @axes.title_margin + @title_caps_height) + current_y_offset = if @geometry.legend_at_bottom then @graph_height + @axes.title_margin + elsif @geometry.hide_title then @geometry.top_margin + @axes.title_margin + else @geometry.top_margin + @axes.title_margin + @title_caps_height + end - @legend_labels.each_with_index do |legend_label, _index| + @legend_labels.each_with_index do |legend_label, index| # Draw label @d.fill = @font_color @d.font = @font if @font @@ -375,19 +372,19 @@ def draw_legend! @d.font_weight = NormalWeight @d.gravity = WestGravity @d = @d.scale_annotation(@base_image, - @geometry.raw_columns, 1.0, - current_x_offset + (legend_square_width * 1.7), current_y_offset, - legend_label.to_s, @scale) + @geometry.raw_columns, 1.0, + current_x_offset + (legend_square_width * 1.7), current_y_offset, + legend_label.to_s, @scale) # Now draw box with color of this dataset @d = @d.stroke('transparent') @d = @d.fill('black') - @d = @d.fill(@plot_colors[_index]) if defined? @plot_colors + @d = @d.fill(@plot_colors[index]) if defined? @plot_colors @d = @d.rectangle(current_x_offset, - current_y_offset - legend_square_width / 2.0, - current_x_offset + legend_square_width, - current_y_offset + legend_square_width / 2.0) - # string = 'hello' + _index.to_s + '.png' + current_y_offset - legend_square_width / 2.0, + current_x_offset + legend_square_width, + current_y_offset + legend_square_width / 2.0) + # string = 'hello' + index.to_s + '.png' # @base_image.write(string) @d.pointsize = @legend_font_size @@ -431,8 +428,10 @@ def draw_line_markers! end @geometry.marker_count ||= 4 end - @geometry.increment = @spread > 0 && @geometry.marker_count > 0 ? - significant(@spread / @geometry.marker_count) : 1 + @geometry.increment =if (@spread > 0) && (@geometry.marker_count > 0) + significant(@spread / @geometry.marker_count) + else 1 + end else # TODO: Make this work for negative values @geometry.marker_count = (@spread / @geometry.y_axis_increment).to_i @@ -444,9 +443,9 @@ def draw_line_markers! (0..@geometry.marker_count).each do |index| y = @graph_top + @graph_height - index.to_f * @geometry.increment_scaled y_next = @graph_top + @graph_height - (index.to_f + 1) * @geometry.increment_scaled - @d = @d.fill(@marker_color) + @d = @d.fill(@marker_color) @d = @d.line(@graph_left, y, @graph_right, y) if - !@geometry.hide_line_markers || (index == 0) + !@geometry.hide_line_markers || index.zero? # If the user specified a marker shadow color, draw a shadow just below it unless @marker_shadow_color.nil? @d = @d.fill(@marker_shadow_color) @@ -458,6 +457,7 @@ def draw_line_markers! BigDecimal(@geometry.minimum_value.to_s) next if @geometry.hide_line_numbers + @d.fill = @font_color @d.font = @font if @font @d.stroke('transparent') @@ -466,9 +466,9 @@ def draw_line_markers! # Vertically center with 1.0 for the height @d = @d.scale_annotation(@base_image, - @graph_left - LABEL_MARGIN, 1.0, - 0.0, y, - label_string(marker_label, @geometry.increment), @scale) + @graph_left - LABEL_MARGIN, 1.0, + 0.0, y, + label_string(marker_label, @geometry.increment), @scale) end @d = @d.stroke_antialias true # string = 'hello' + '.png' @@ -477,7 +477,7 @@ def draw_line_markers! end # Use with a theme definition method to draw a gradiated background. - def render_gradiated_background(top_color, bottom_color, direct = :top_bottom) + def render_gradiated_background(top_color, bottom_color, direct=:top_bottom) gradient_fill = case direct when :bottom_top GradientFill.new(0, 0, 100, 0, bottom_color, top_color) @@ -497,43 +497,41 @@ def render_gradiated_background(top_color, bottom_color, direct = :top_bottom) # Draws column labels below graph, centered over x_offset def draw_label(x_offset, index) - if !@axes.x_ticks[index].nil? && @geometry.labels_seen[index].nil? - y_offset = @graph_bottom + LABEL_MARGIN - - # TESTME - # TODO: See if index.odd? is the best stragegy - y_offset += @label_stagger_height if index.odd? - - label_text = @axes.x_ticks[index].to_s - - # TESTME - # FIXME: Consider chart types other than bar - if label_text.size > @label_max_size - if @geometry.label_truncation_style == :trailing_dots - if @label_max_size > 3 - # 4 because '...' takes up 3 chars - label_text = "#{label_text[0..(@label_max_size - 4)]}..." - end - else # @geometry.label_truncation_style is :absolute (default) - label_text = label_text[0..(@label_max_size - 1)] - end + y_offset = @graph_bottom + LABEL_MARGIN if !@axes.x_ticks[index].nil? && @geometry.labels_seen[index].nil? - end + # TESTME + # TODO: See if index.odd? is the best stragegy + y_offset += @label_stagger_height if index.odd? + + label_text = @axes.x_ticks[index].to_s - if x_offset >= @graph_left && x_offset <= @graph_right - @d.fill = @font_color - @d.font = @font if @font - @d.stroke('transparent') - @d.font_weight = NormalWeight - @d.pointsize = scale_fontsize(@marker_font_size) - @d.gravity = NorthGravity - @d = @d.scale_annotation(@base_image, - 1.0, 1.0, - x_offset, y_offset, - label_text, @scale) + # TESTME + # FIXME: Consider chart types other than bar + if label_text.size > @label_max_size + if @geometry.label_truncation_style == :trailing_dots + if @label_max_size > 3 + # 4 because '...' takes up 3 chars + label_text = "#{label_text[0..(@label_max_size - 4)]}..." + end + else # @geometry.label_truncation_style is :absolute (default) + label_text = label_text[0..(@label_max_size - 1)] end - @geometry.labels_seen[index] = 1 + + end + + if x_offset >= @graph_left && x_offset <= @graph_right + @d.fill = @font_color + @d.font = @font if @font + @d.stroke('transparent') + @d.font_weight = NormalWeight + @d.pointsize = scale_fontsize(@marker_font_size) + @d.gravity = NorthGravity + @d = @d.scale_annotation(@base_image, + 1.0, 1.0, + x_offset, y_offset, + label_text, @scale) end + @geometry.labels_seen[index] = 1 end private @@ -544,27 +542,25 @@ def label_string(value, increment) label = if increment if increment >= 10 || (increment * 1) == (increment * 1).to_i.to_f - format('%0i', value) + '%0i' % value elsif increment >= 1.0 || (increment * 10) == (increment * 10).to_i.to_f - format('%0.1f', value) + '%0.1f' % value elsif increment >= 0.1 || (increment * 100) == (increment * 100).to_i.to_f - format('%0.2f', value) + '%0.2f' % value elsif increment >= 0.01 || (increment * 1000) == (increment * 1000).to_i.to_f - format('%0.3f', value) + '%0.3f' % value elsif increment >= 0.001 || (increment * 10_000) == (increment * 10_000).to_i.to_f - format('%0.4f', value) + '%0.4f' % value else value.to_s end - elsif ((@spread.to_f % - (@geometry.marker_count.to_f == 0 ? - 1 : @geometry.marker_count.to_f) == 0) || - !@geometry.y_axis_increment .nil?) + elsif (@spread.to_f % (@geometry.marker_count.to_f.zero? ? 1 : @geometry.marker_count.to_f)).zero? || + !@geometry.y_axis_increment .nil? value.to_i.to_s elsif @spread > 10.0 - format('%0i', value) + '%0i' % value elsif @spread >= 3.0 - format('%0.2f', value) + '%0.2f' % value else value.to_s end @@ -572,6 +568,9 @@ def label_string(value, increment) parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{THOUSAND_SEPARATOR}") parts.join('.') end - end # class Artist - end # module MagickWrapper -end # module Rubyplot + end + # class Artist + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/artist/attributes.rb b/lib/rubyplot/magick_wrapper/artist/attributes.rb index 1907f56..212f860 100644 --- a/lib/rubyplot/magick_wrapper/artist/attributes.rb +++ b/lib/rubyplot/magick_wrapper/artist/attributes.rb @@ -1,10 +1,10 @@ module Rubyplot - module MagickWrapper + module MagickWrapper class Artist module Attributes # Blank space below the legend attr_accessor :legend_margin - + # Used internally for horizontal graph types. attr_accessor :has_left_labels @@ -49,7 +49,11 @@ module Attributes # Axes object to which this plot belongs. attr_reader :axes - end # module Attributes - end # class Artist - end # module MagickWrapper -end # module Rubyplot + end + # module Attributes + end + # class Artist + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/artist/geometry.rb b/lib/rubyplot/magick_wrapper/artist/geometry.rb index 277fa2f..13d9182 100644 --- a/lib/rubyplot/magick_wrapper/artist/geometry.rb +++ b/lib/rubyplot/magick_wrapper/artist/geometry.rb @@ -11,22 +11,22 @@ class Geometry DEFAULT_TARGET_WIDTH = 800 # Blank space above the graph - attr_accessor :top_margin + # attr_accessor :top_margin # Blank space below the graph - attr_accessor :bottom_margin + # attr_accessor :bottom_margin # Blank space to the right of the graph - attr_accessor :right_margin + # attr_accessor :right_margin # Blank space to the left of the graph - attr_accessor :left_margin + # attr_accessor :left_margin # Blank space below the title attr_accessor :title_margin # Blank space below the legend - attr_accessor :legend_margin + # attr_accessor :legend_margin # A hash of names for the individual columns, where the key is the array # index for the column this label represents. @@ -34,10 +34,10 @@ class Geometry # Not all columns need to be named. # # Example: 0 => 2005, 3 => 2006, 5 => 2007, 7 => 2008 - attr_accessor :labels + # attr_accessor :labels # Used internally for horizontal graph types. - attr_accessor :has_left_labels + # attr_accessor :has_left_labels # A label for the bottom of the graph attr_accessor :x_axis_label @@ -56,7 +56,7 @@ class Geometry attr_accessor :font_color # Prevent drawing of line numbers - attr_accessor :hide_line_numbers + # attr_accessor :hide_line_numbers # Optionally set the size of the font. Based on an 800x600px graph. # Default is 20. @@ -65,7 +65,7 @@ class Geometry attr_accessor :legend_font_size # The number of horizontal lines shown for reference - attr_accessor :marker_count + # attr_accessor :marker_count # The color of the auxiliary lines attr_accessor :marker_color @@ -92,7 +92,7 @@ class Geometry # Label values attr_accessor :labels, :labels_seen, :has_left_labels, :label_formatting - attr_accessor :label_truncation_style, :label_max_size, :label_stagger_height + # attr_accessor :label_truncation_style, :label_max_size, :label_stagger_height attr_accessor :label_stagger_height, :label_max_size # Offset @@ -161,7 +161,11 @@ def initialize(*) @right_margin = DEFAULT_MARGIN @labels_seen = {} end - end # class Geometry - end # class Artist - end # module MagickWrapper -end # module Rubyplot + end + # class Geometry + end + # class Artist + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/artist/math_methods.rb b/lib/rubyplot/magick_wrapper/artist/math_methods.rb index 5f459e2..539f5d7 100644 --- a/lib/rubyplot/magick_wrapper/artist/math_methods.rb +++ b/lib/rubyplot/magick_wrapper/artist/math_methods.rb @@ -7,7 +7,7 @@ module MathMethods # FIXME: change this method to reflect arch change. def normalize @geometry.norm_data = [] - #@data.each do |data_row| + # @data.each do |data_row| data_row = @data norm_data_points = [] data_row[:y_values].each do |data_point| @@ -15,7 +15,7 @@ def normalize # Add support for nil values in data etc. end @geometry.norm_data << [data_row[:label], norm_data_points] - #end + # end @geometry.norm_data[0] << @data[:color] if @data[:x_values] norm_data_points = [] @@ -52,9 +52,10 @@ def scale_fontsize(value) value * @scale end - def significant(i) - return 1.0 if i == 0 # Keep from going into infinite loop - inc = BigDecimal(i.to_s) + def significant(var) + return 1.0 if var.zero? # Keep from going into infinite loop + + inc = BigDecimal(var.to_s) factor = BigDecimal('1.0') while inc < 10 inc *= 10 @@ -67,10 +68,7 @@ def significant(i) end res = inc.floor * factor - if res.to_i.to_f == res - res.to_i - else - res + if res.to_i.to_f == res then res.to_i else res end end @@ -79,10 +77,10 @@ def significant(i) def sort_norm_data @geometry.norm_data = @geometry.norm_data.sort_by { |a| - -a[DATA_VALUES_INDEX].inject(0) { |sum, num| - sum + num.to_f + -a[DATA_VALUES_INDEX].inject(0) { |sum, num| + sum + num.to_f + } } - } end # Returns the height of the capital letter 'X' for the current font and @@ -102,6 +100,7 @@ def calculate_caps_height(font_size) # scaling will handle. def calculate_width(font_size, text) return 0 if text.nil? + @d.pointsize = font_size @d.font = @font if @font @d.get_type_metrics(@base_image, text.to_s).width diff --git a/lib/rubyplot/magick_wrapper/magick/draw.rb b/lib/rubyplot/magick_wrapper/magick/draw.rb index ef84d49..6a1ab8c 100644 --- a/lib/rubyplot/magick_wrapper/magick/draw.rb +++ b/lib/rubyplot/magick_wrapper/magick/draw.rb @@ -2,14 +2,17 @@ module Magick class Draw # Method to Scale text annotation in RMagick - def scale_annotation(img, width, height, x, y, text, scale) + + # rubocop:disable Metrics/ParameterLists + def scale_annotation(img, width, height, x_param, y_param, text, scale) scaled_width = (width * scale) >= 1 ? (width * scale) : 1 scaled_height = (height * scale) >= 1 ? (height * scale) : 1 annotate(img, - scaled_width.to_i, - scaled_height.to_i, - (x * scale).to_i, (y * scale).to_i, - text.gsub('%', '%%')) + scaled_width.to_i, + scaled_height.to_i, + (x_param * scale).to_i, (y_param * scale).to_i, + text.gsub('%', '%%')) end + # rubocop:enable Metrics/ParameterLists end end diff --git a/lib/rubyplot/magick_wrapper/plot/area.rb b/lib/rubyplot/magick_wrapper/plot/area.rb index 6548d2a..f13a239 100644 --- a/lib/rubyplot/magick_wrapper/plot/area.rb +++ b/lib/rubyplot/magick_wrapper/plot/area.rb @@ -49,5 +49,7 @@ def draw end end end - end # module MagickWrapper -end # module Rubyplot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/plot/area/geometry.rb b/lib/rubyplot/magick_wrapper/plot/area/geometry.rb index 53ce43f..3dadc00 100644 --- a/lib/rubyplot/magick_wrapper/plot/area/geometry.rb +++ b/lib/rubyplot/magick_wrapper/plot/area/geometry.rb @@ -8,8 +8,13 @@ def initialize(*) super @spacing_factor = 0.9 end - end # class Geometry - end # class Area - end # module Plot - end # module MagickWrapper -end # module Rubyplot + end + # class Geometry + end + # class Area + end + # module Plot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/plot/bar.rb b/lib/rubyplot/magick_wrapper/plot/bar.rb index 3f50386..a64895e 100644 --- a/lib/rubyplot/magick_wrapper/plot/bar.rb +++ b/lib/rubyplot/magick_wrapper/plot/bar.rb @@ -27,6 +27,7 @@ def draw @geometry.center_labels_over_point = (@axes.x_ticks.keys.length > @geometry.column_count) super return unless @geometry.has_data + draw_bars end @@ -39,6 +40,7 @@ def draw def spacing_factor=(space_percent) raise ArgumentError, 'geometry.spacing_factor must be between 0.00 and 1.00' unless (space_percent >= 0) && (space_percent <= 1) + @geometry.spacing_factor = (1 - space_percent) end @@ -60,17 +62,14 @@ def draw_bars if @geometry.minimum_value >= 0 # all bars go from zero to positiv @mode = :positive + elsif @geometry.maximum_value <= 0 # all bars go from 0 to negative + @mode = :negative else - # all bars go from 0 to negativ - if @geometry.maximum_value <= 0 - @mode = :negative - else - # bars either go from zero to negativ or to positive - @mode = :both - @spread = @spread - @minimum_value = @geometry.minimum_value - @zero = -@geometry.minimum_value / @spread - end + # bars either go from zero to negativ or to positive + @mode = :both + @spread = @spread + @minimum_value = @geometry.minimum_value + @zero = -@geometry.minimum_value / @spread end # iterate over all normalised data @@ -98,12 +97,12 @@ def draw_bars # Subtract half a bar width to center left if requested draw_label(label_center - (@geometry.center_labels_over_point ? @bar_width / 2.0 : 0.0), - point_index) - if @geometry.show_labels_for_bar_values - val = (@geometry.label_formatting || '%.2f') % - @geometry.norm_data[row_index][3][point_index] - draw_value_label(left_x + (right_x - left_x) / 2, conv[0] - 30, val.commify, true) - end + point_index) + next unless @geometry.show_labels_for_bar_values + + val = (@geometry.label_formatting || '%.2f') % + @geometry.norm_data[row_index][3][point_index] + draw_value_label(left_x + (right_x - left_x) / 2, conv[0] - 30, val.commify, true) end end @@ -111,7 +110,7 @@ def draw_bars draw_label(@graph_right, @geometry.column_count) if @geometry.center_labels_over_point @d.draw(@base_image) end - + def get_left_y_right_y_scaled(data_point, result) case @mode when :positive then # Case one @@ -125,19 +124,23 @@ def get_left_y_right_y_scaled(data_point, result) when :both then # Case three # positive and negative values -> bars go in both the +ve and -ve direction val = data_point - @geometry.minimum_value / @spread - if data_point >= @zero - result[0] = @graph_top + @graph_height * (1 - (val - @zero)) + 1 - result[1] = @graph_top + @graph_height * (1 - @zero) - 1 - else + if data_point >= @zero || data_points < @zero result[0] = @graph_top + @graph_height * (1 - (val - @zero)) + 1 result[1] = @graph_top + @graph_height * (1 - @zero) - 1 + # else + # result[0] = @graph_top + @graph_height * (1 - (val - @zero)) + 1 + # result[1] = @graph_top + @graph_height * (1 - @zero) - 1 end else result[0] = 0.0 result[1] = 0.0 end end - end # class Bar - end # module Plot - end # module MagickWrapper -end # module Rubyplot + end + # class Bar + end + # module Plot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/plot/bar/geometry.rb b/lib/rubyplot/magick_wrapper/plot/bar/geometry.rb index e8e3a92..b187c3a 100644 --- a/lib/rubyplot/magick_wrapper/plot/bar/geometry.rb +++ b/lib/rubyplot/magick_wrapper/plot/bar/geometry.rb @@ -8,8 +8,13 @@ def initialize(*) super @spacing_factor = 0.9 end - end # class Geometry - end # class Bar - end # module Plot - end # module MagickWrapper -end # module Rubyplot + end + # class Geometry + end + # class Bar + end + # module Plot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/plot/bubble.rb b/lib/rubyplot/magick_wrapper/plot/bubble.rb index 8eb1355..45ad157 100644 --- a/lib/rubyplot/magick_wrapper/plot/bubble.rb +++ b/lib/rubyplot/magick_wrapper/plot/bubble.rb @@ -42,67 +42,65 @@ def initialize(*) # plot.data(:peaches, [20, 30, -6, -3], [-1, 5, -27, -3], [13, 10, 20, 10]) # plot.write('spec/reference_images/bubble_test_1.png') # - def data(x_data_points = [], y_data_points = [], z_data_points = []) -# name = label == :default ? ' ' : label.to_s - # the existing data routine for the y axis data + def data(x_data_points=[], y_data_points=[], z_data_points=[]) + # name = label == :default ? ' ' : label.to_s + # the existing data routine for the y axis data data_y(y_data_points, z_data_points) # append the x data to the last entry that was just added in the @data member # last_elem = @data.length - 1 # @data[last_elem] << x_data_points @data[:x_values] = x_data_points - if @geometry.maximum_x_value.nil? && @geometry.minimum_x_value.nil? - @geometry.maximum_x_value = @geometry.minimum_x_value = x_data_points.first + if @geometry.max_x_value.nil? && @geometry.min_x_value.nil? + @geometry.max_x_value = @geometry.min_x_value = x_data_points.first end @z_data << z_data_points x_z_array_sum = [x_data_points, z_data_points].transpose.map { |x| x.reduce(:+) } - x_z_array_diff = [x_data_points, z_data_points].transpose.map { |x| x.reduce(:-) } + x_z_array_dif = [x_data_points, z_data_points].transpose.map { |x| x.reduce(:-) } - @geometry.maximum_x_value = x_z_array_sum.max > @geometry.maximum_x_value ? - x_z_array_sum.max : @geometry.maximum_x_value - @geometry.minimum_x_value = x_z_array_sum.min < @geometry.minimum_x_value ? - x_z_array_sum.min : @geometry.minimum_x_value - - @geometry.maximum_x_value = x_z_array_diff.max > @geometry.maximum_x_value ? - x_z_array_diff.max : @geometry.maximum_x_value - @geometry.minimum_x_value = x_z_array_diff.min < @geometry.minimum_x_value ? - x_z_array_diff.min : @geometry.minimum_x_value + @geometry.max_x_value = x_z_array_sum.max > @geometry.max_x_value ? x_z_array_sum.max : @geometry.max_x_value + @geometry.min_x_value = x_z_array_sum.min < @geometry.min_x_value ? x_z_array_sum.min : @geometry.min_x_value + @geometry.max_x_value = x_z_array_dif.max > @geometry.max_x_value ? x_z_array_dif.max : @geometry.max_x_value + @geometry.min_x_value = x_z_array_dif.min < @geometry.min_x_value ? x_z_array_dif.min : @geometry.min_x_value end private # Helper function to normalize the data along Y axis. - def data_y(data_points = [], z_data_points) + def data_y(z_data_points, data_points=[]) data_points = Array(data_points) # make sure it's an array - # TODO: Adding an empty color array which can be developed later - # to make graphs super customizable with regards to coloring of - # individual data points. + # TODO: Adding an empty color array which can be developed later to make graphs + # super customizable with regards to coloring of individual data points. @data[:y_values] = data_points # Set column count if this is larger than previous column counts - @geometry.column_count = data_points.length > @geometry.column_count ? - data_points.length : @geometry.column_count + @geometry.column_count = if data_points.length > @geometry.column_count then data_points.length + else @geometry.column_count + end y_z_array_sum = [data_points, z_data_points].transpose.map { |x| x.reduce(:+) } - y_z_array_diff = [data_points, z_data_points].transpose.map { |x| x.reduce(:-) } + y_z_array_dif = [data_points, z_data_points].transpose.map { |x| x.reduce(:-) } if @geometry.maximum_value.nil? && @geometry.maximum_value.nil? @geometry.maximum_value = @geometry.minimum_value = data_points.first end - @geometry.maximum_value = y_z_array_sum.max > @geometry.maximum_value ? - y_z_array_sum.max : @geometry.maximum_value - @geometry.minimum_value = y_z_array_sum.min < @geometry.minimum_value ? - y_z_array_sum.min : @geometry.minimum_value - @geometry.maximum_value = y_z_array_diff.max > @geometry.maximum_value ? - y_z_array_diff.max : @geometry.maximum_value - @geometry.minimum_value = y_z_array_diff.min < @geometry.minimum_value ? - y_z_array_diff.min : @geometry.minimum_value + @geometry.maximum_value = if y_z_array_sum.max > @geometry.maximum_value then y_z_array_sum.max + else @geometry.maximum_value + end + @geometry.minimum_value = if y_z_array_sum.min < @geometry.minimum_value then y_z_array_sum.min + else @geometry.minimum_value + end + @geometry.maximum_value = if y_z_array_dif.max > @geometry.maximum_value then y_z_array_dif.max + else @geometry.maximum_value + end + @geometry.minimum_value = if y_z_array_dif.min < @geometry.minimum_value then y_z_array_dif.min + else @geometry.minimum_value + end @geometry.has_data = true end def draw super # Check to see if more than one datapoint was given. NaN can result otherwise. - @x_increment = @geometry.column_count > 1 ? - (@graph_width / (@geometry.column_count - 1).to_f) : @graph_width + @x_increment = @geometry.column_count > 1 ? (@graph_width / (@geometry.column_count - 1).to_f) : @graph_width @geometry.norm_data.each_with_index do |data_row, data_row_index| data_row[DATA_VALUES_INDEX].each_with_index do |data_point, index| @@ -118,15 +116,19 @@ def draw @d.fill_opacity(0.3) @d.fill_color(@plot_colors[data_row_index]) @d = @d.stroke_width @stroke_width || - clip_value_if_greater_than(@columns / - (@geometry.norm_data.first[1].size * 4), 5.0) + clip_value_if_greater_than(@columns / + (@geometry.norm_data.first[1].size * 4), 5.0) circle_radius = 2 * @z_data[data_row_index][index] @d = @d.circle(new_x, new_y, new_x - circle_radius, new_y) end end @d.draw(@base_image) - end - end # class Bubble - end # module Plot - end # module MagickWrapper -end # module Rubyplot + end + end + # class Bubble + end + # module Plot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/plot/bubble/geometry.rb b/lib/rubyplot/magick_wrapper/plot/bubble/geometry.rb index 148e9d8..c1a9466 100644 --- a/lib/rubyplot/magick_wrapper/plot/bubble/geometry.rb +++ b/lib/rubyplot/magick_wrapper/plot/bubble/geometry.rb @@ -6,19 +6,24 @@ class Geometry < MagickWrapper::Plot::Scatter::Geometry attr_accessor :all_colors_array attr_accessor :z_data attr_accessor :plot_colors - attr_accessor :maximum_x_value - attr_accessor :minimum_x_value + attr_accessor :max_x_value + attr_accessor :min_x_value def initialize super @all_colors_array = Magick.colors @plot_colors = [] @z_data = [] - @maximum_x_value = nil - @minimum_x_value = nil + @max_x_value = nil + @min_x_value = nil end - end # class Geometry - end # class Bar - end # module Plot - end # module MagickWrapper -end # module Rubyplot + end + # class Geometry + end + # class Bar + end + # module Plot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/plot/dot.rb b/lib/rubyplot/magick_wrapper/plot/dot.rb index 6a62cba..ce08132 100644 --- a/lib/rubyplot/magick_wrapper/plot/dot.rb +++ b/lib/rubyplot/magick_wrapper/plot/dot.rb @@ -20,7 +20,7 @@ def draw y_pos = @graph_top + (@items_width * point_index) + padding + (@items_width.to_f / 2.0).round - if row_index == 0 + if row_index.zero? @d = @d.stroke(@marker_color) @d = @d.fill(@marker_color) @d = @d.stroke_width 1.0 @@ -62,8 +62,10 @@ def draw_line_markers @geometry.marker_count ||= 5 end # TODO: Round maximum marker value to a round number like 100, 0.1, 0.5, etc. - @geometry.increment = @spread > 0 && @geometry.marker_count > 0 ? - significant(@spread / @geometry.marker_count) : 1 + @geometry.increment = if @spread > 0 && @geometry.marker_count > 0 + significant(@spread / @geometry.marker_count) + else 1 + end number_of_lines = @geometry.marker_count increment = @geometry.increment @@ -82,10 +84,11 @@ def draw_line_markers @d.gravity = CenterGravity # TODO: Center text over line @d = @d.scale_annotation(@base_image, - 0, 0, # Width of box to draw text in - x, @graph_bottom + (LABEL_MARGIN * 2.0), # Coordinates of text - label(marker_label, increment), @scale) - end # unless + 0, 0, # Width of box to draw text in + x, @graph_bottom + (LABEL_MARGIN * 2.0), # Coordinates of text + label(marker_label, increment), @scale) + end + # unless @d = @d.stroke_antialias true end end @@ -100,13 +103,17 @@ def draw_label(y_offset, index) @d.pointsize = scale_fontsize(@marker_font_size) @d.gravity = EastGravity @d = @d.scale_annotation(@base_image, - 1, 1, - -@graph_left + LABEL_MARGIN * 2.0, y_offset, - @axes.y_ticks[index], @scale) + 1, 1, + -@graph_left + LABEL_MARGIN * 2.0, y_offset, + @axes.y_ticks[index], @scale) @geometry.labels_seen[index] = 1 end end - end # class Dot - end # module Plot - end # module MagickWrapper -end # module Rubyplot + end + # class Dot + end + # module Plot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/plot/line.rb b/lib/rubyplot/magick_wrapper/plot/line.rb index 7d8c3a5..faed1b1 100644 --- a/lib/rubyplot/magick_wrapper/plot/line.rb +++ b/lib/rubyplot/magick_wrapper/plot/line.rb @@ -5,19 +5,19 @@ # FIXME: refactor this module and make it a part of Line. module DotRenderers class Circle - def render(d, new_x, new_y, circle_radius) - d.circle(new_x, new_y, new_x - circle_radius, new_y) + def render(dis, new_x, new_y, circle_radius) + dis.circle(new_x, new_y, new_x - circle_radius, new_y) end end class Square - def render(d, new_x, new_y, circle_radius) + def render(dis, new_x, new_y, circle_radius) offset = (circle_radius * 0.8).to_i - corner_1 = new_x - offset - corner_2 = new_y - offset - corner_3 = new_x + offset - corner_4 = new_y + offset - d.rectangle(corner_1, corner_2, corner_3, corner_4) + corner1 = new_x - offset + corner2 = new_y - offset + corner3 = new_x + offset + corner4 = new_y + offset + dis.rectangle(corner1, corner2, corner3, corner4) end end @@ -46,7 +46,8 @@ class Line < Artist # g = Rubyplot::Line.new(false) # Defaults to 800px wide, no lines def initialize(*args) raise ArgumentError, 'Wrong number of arguments' if args.length > 2 - if args.empty? || (!(Numeric === args.first) && !(String === args.first)) + + if args.empty? || ((Numeric != args.first) && (String != args.first)) super else super args.shift # TODO: Figure out a better alternative here. @@ -81,8 +82,7 @@ def draw return unless @geometry.has_data # Check to see if more than one datapoint was given. NaN can result otherwise. - @x_increment = @geometry.column_count > 1 ? - (@graph_width / (@geometry.column_count - 1).to_f) : @graph_width + @x_increment = @geometry.column_count > 1 ? (@graph_width / (@geometry.column_count - 1).to_f) : @graph_width @geometry.norm_data.each_with_index do |data_row, row_num| # Initially the previous x,y points are nil and then @@ -100,10 +100,10 @@ def draw new_x = get_x_coord(x_data[index], @graph_width, @graph_left) @labels.each do |label_pos, _| draw_label(@graph_left + ((label_pos - - @geometry.minimum_x_value) * + @geometry.min_x_value) * @graph_width) / - (@geometry.maximum_x_value - - @geometry.minimum_x_value), label_pos) + (@geometry.max_x_value - + @geometry.min_x_value), label_pos) end end unless data_point @@ -119,24 +119,28 @@ def draw @d = @d.stroke_width line_width || clip_value_if_greater_than( @columns / ( - @geometry.norm_data.first[DATA_VALUES_INDEX].size * 4), 5.0) + @geometry.norm_data.first[DATA_VALUES_INDEX].size * 4), 5.0 + ) circle_radius = dot_radius || clip_value_if_greater_than( @columns / ( - @geometry.norm_data.first[DATA_VALUES_INDEX].size * 2.5), 5.0) + @geometry.norm_data.first[DATA_VALUES_INDEX].size * 2.5), 5.0 + ) if !@geometry.hide_lines && !prev_x.nil? && !prev_y.nil? @d = @d.line(prev_x, prev_y, new_x, new_y) elsif @one_point # Show a circle if there's just one_point @d = DotRenderers.renderer( - @geometry.dot_style).render(@d, new_x, new_y, circle_radius) + @geometry.dot_style + ).render(@d, new_x, new_y, circle_radius) end unless @geometry.hide_dots @d = DotRenderers.renderer( - @geometry.dot_style).render(@d, new_x, new_y, circle_radius) + @geometry.dot_style + ).render(@d, new_x, new_y, circle_radius) end prev_x = new_x @@ -183,7 +187,7 @@ def get_x_coord(x_data_point, width, offset) # In this example the lables are drawn at x positions 2, 4, and 6: # g.labels = {0 => '2003', 2 => '2004', 4 => '2005', 6 => '2006'} # The 0 => '2003' label will be ignored since it is outside the chart range. - def dataxy(_name, x_data_points = [], y_data_points = [], _color = nil) + def dataxy(_name, x_data_points=[], y_data_points=[], _color=nil) raise ArgumentError, 'x_data_points is nil!' if x_data_points.empty? if x_data_points.all? { |p| p.is_a?(Array) && p.size == 2 } @@ -206,14 +210,12 @@ def dataxy(_name, x_data_points = [], y_data_points = [], _color = nil) next if x_data_point.nil? # Setup max/min so spread starts at the low end of the data points - if @geometry.maximum_x_value.nil? && @geometry.minimum_x_value.nil? - @geometry.maximum_x_value = @geometry.minimum_x_value = x_data_point + if @geometry.max_x_value.nil? && @geometry.min_x_value.nil? + @geometry.max_x_value = @geometry.min_x_value = x_data_point end - @geometry.maximum_x_value = x_data_point > @geometry.maximum_x_value ? - x_data_point : @geometry.maximum_x_value - @geometry.minimum_x_value = x_data_point < @geometry.minimum_x_value ? - x_data_point : @geometry.minimum_x_value + @geometry.max_x_value = x_data_point > @geometry.max_x_value ? x_data_point : @geometry.max_x_value + @geometry.min_x_value = x_data_point < @geometry.min_x_value ? x_data_point : @geometry.min_x_value end end @@ -226,11 +228,12 @@ def normalize @data.each_with_index do |data_row, index| norm_x_data_points = [] next if data_row[DATA_VALUES_X_INDEX].nil? + data_row[DATA_VALUES_X_INDEX].each do |x_data_point| norm_x_data_points << ((x_data_point.to_f - - @geometry.minimum_x_value.to_f) / - (@geometry.maximum_x_value.to_f - - @geometry.minimum_x_value.to_f)) + @geometry.min_x_value.to_f) / + (@geometry.max_x_value.to_f - + @geometry.min_x_value.to_f)) end @geometry.norm_data[index] << norm_x_data_points end @@ -250,6 +253,7 @@ def contains_one_point_only?(data_row) # more than one point, bail return false end + # there is at least one data point one_point = true end diff --git a/lib/rubyplot/magick_wrapper/plot/line/geometry.rb b/lib/rubyplot/magick_wrapper/plot/line/geometry.rb index fed6fc1..75e2ae9 100644 --- a/lib/rubyplot/magick_wrapper/plot/line/geometry.rb +++ b/lib/rubyplot/magick_wrapper/plot/line/geometry.rb @@ -10,8 +10,8 @@ class Geometry < MagickWrapper::Artist::Geometry attr_accessor :hide_lines attr_accessor :show_vertical_markers attr_accessor :dot_style - attr_accessor :maximum_x_value - attr_accessor :minimum_x_value + attr_accessor :max_x_value + attr_accessor :min_x_value def initialize super @@ -22,12 +22,17 @@ def initialize @hide_dots = @hide_lines = false @dot_style = 'circle' # Options present for Circle and Square dot style. - @maximum_x_value = nil - @minimum_x_value = nil + @max_x_value = nil + @min_x_value = nil @hide_line_markers = true end - end # class Geometry - end # class Line - end # module Plot - end # module MagickWrapper -end # module Rubyplot + end + # class Geometry + end + # class Line + end + # module Plot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/plot/scatter.rb b/lib/rubyplot/magick_wrapper/plot/scatter.rb index f25f18e..ee8f54c 100644 --- a/lib/rubyplot/magick_wrapper/plot/scatter.rb +++ b/lib/rubyplot/magick_wrapper/plot/scatter.rb @@ -1,6 +1,6 @@ require_relative 'scatter/geometry' -module Rubyplot +module Rubyplot module MagickWrapper module Plot class Scatter < Artist @@ -33,7 +33,8 @@ class Scatter < Artist attr_accessor :stroke_width # Allow disabling the significant rounding when labeling the X axis - # This is useful when working with a small range of high values (for example, a date range of months, while seconds as units) + # This is useful when working with a small range of high values + # (for example, a date range of months, while seconds as units) attr_accessor :disable_significant_rounding_x_axis # Allow enabling vertical lines. When you have a lot of data, they can work great @@ -96,7 +97,7 @@ def setup_drawing # Error means that the x and y axis point arrays do not match in length # # - def data(x_data_points = [], y_data_points = [], label: :default, color: :default) + def data(x_data_points=[], y_data_points=[], label: :default, color: :default) # Call the existing data routine for the y axis data super(y_data_points, label: label, color: color) @@ -107,10 +108,12 @@ def data(x_data_points = [], y_data_points = [], label: :default, color: :defaul @geometry.maximum_x_value = @geometry.minimum_x_value = x_data_points.first end - @geometry.maximum_x_value = x_data_points.max > @geometry.maximum_x_value ? - x_data_points.max : @geometry.maximum_x_value - @geometry.minimum_x_value = x_data_points.min < @geometry.minimum_x_value ? - x_data_points.min : @geometry.minimum_x_value + @geometry.maximum_x_value = if x_data_points.max > @geometry.maximum_x_value then x_data_points.max + else @geometry.maximum_x_value + end + @geometry.minimum_x_value = if x_data_points.min < @geometry.minimum_x_value then x_data_points.min + else @geometry.minimum_x_value + end end def calculate_spread #:nodoc: @@ -120,7 +123,7 @@ def calculate_spread #:nodoc: end # FIXME: eventually move this normalization to Axes. - def normalize(force = nil) + def normalize(force=nil) if @geometry.norm_data.nil? || force @geometry.norm_data = [] return unless @geometry.has_data @@ -144,8 +147,7 @@ def draw return unless @geometry.has_data # Check to see if more than one datapoint was given. NaN can result otherwise. - @x_increment = @geometry.column_count > 1 ? - (@graph_width / (@geometry.column_count - 1).to_f) : @graph_width + @x_increment = @geometry.column_count > 1 ? (@graph_width / (@geometry.column_count - 1).to_f) : @graph_width @geometry.norm_data.each_with_index do |data_row, row_num| data_row[DATA_VALUES_INDEX].each_with_index do |data_point, index| @@ -161,11 +163,13 @@ def draw @d = @d.stroke_width(@geometry.stroke_width || clip_value_if_greater_than( @columns / ( - @geometry.norm_data.first[1].size * 4), 5.0)) + @geometry.norm_data.first[1].size * 4), 5.0 + )) circle_radius = @geometry.circle_radius || clip_value_if_greater_than( - @columns / (@geometry.norm_data.first[1].size * 2.5), 5.0) + @columns / (@geometry.norm_data.first[1].size * 2.5), 5.0 + ) @d = @d.circle(new_x, new_y, new_x - circle_radius, new_y) end end @@ -179,6 +183,7 @@ def draw_line_markers! # do all of the stuff for the horizontal lines on the y-axis super return if @geometry.hide_line_markers + @d = @d.stroke_antialias false if @geometry.x_axis_increment.nil? @@ -193,9 +198,7 @@ def draw_line_markers! @geometry.marker_x_count ||= 4 end @x_increment = @x_spread > 0 ? (@x_spread / @geometry.marker_x_count) : 1 - unless @geometry.disable_significant_rounding_x_axis - @x_increment = significant(@x_increment) - end + @x_increment = significant(@x_increment) unless @geometry.disable_significant_rounding_x_axis else # TODO: Make this work for negative values @geometry.maximum_x_value = [@geometry.maximum_value.ceil, @geometry.x_axis_increment].max @@ -210,7 +213,8 @@ def draw_line_markers! # Draw vertical line markers and annotate with numbers (0..@geometry.marker_x_count).each do |index| - # TODO: Fix the vertical lines, and enable them by default. Not pretty when they don't match up with top y-axis line + # TODO: Fix the vertical lines, and enable them by default. + # Not pretty when they don't match up with top y-axis line if @geometry.enable_vertical_line_markers x = @graph_left + @graph_width - index.to_f * @geometry.increment_x_scaled @d = @d.stroke(@marker_color) @@ -219,6 +223,7 @@ def draw_line_markers! end next if @geometry.hide_line_numbers + marker_label = index * @x_increment + @geometry.minimum_x_value.to_f y_offset = @graph_bottom + (@geometry.x_label_margin || LABEL_MARGIN) x_offset = get_x_coord(index.to_f, @geometry.increment_x_scaled, @graph_left) @@ -230,9 +235,9 @@ def draw_line_markers! @d.gravity = NorthGravity @d.rotation = -90.0 if @geometry.use_vertical_x_labels @d = @d.scale_annotation(@base_image, - 1.0, 1.0, - x_offset, y_offset, - vertical_label(marker_label, @x_increment), @scale) + 1.0, 1.0, + x_offset, y_offset, + vertical_label(marker_label, @x_increment), @scale) @d.rotation = 90.0 if @geometry.use_vertical_x_labels end diff --git a/lib/rubyplot/magick_wrapper/plot/scatter/geometry.rb b/lib/rubyplot/magick_wrapper/plot/scatter/geometry.rb index d242cd3..bd5427e 100644 --- a/lib/rubyplot/magick_wrapper/plot/scatter/geometry.rb +++ b/lib/rubyplot/magick_wrapper/plot/scatter/geometry.rb @@ -37,8 +37,13 @@ def initialize(*) @x_label_margin = nil @y_axis_label_format = nil end - end # class Geometry - end # class Scatter - end # module Plot - end # module MagickWrapper -end # module Rubyplot + end + # class Geometry + end + # class Scatter + end + # module Plot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/plot/stacked_bar.rb b/lib/rubyplot/magick_wrapper/plot/stacked_bar.rb index b71a8e5..6d9c89e 100644 --- a/lib/rubyplot/magick_wrapper/plot/stacked_bar.rb +++ b/lib/rubyplot/magick_wrapper/plot/stacked_bar.rb @@ -4,7 +4,7 @@ module Rubyplot module MagickWrapper module Plot class StackedBar < Artist - #DATA_VALUES_INDEX = Rubyplot::MagickArtist::DATA_VALUES_INDEX + # DATA_VALUES_INDEX = Rubyplot::MagickArtist::DATA_VALUES_INDEX # # A stacked bar graph (or stacked bar chart) is a chart that uses bars to show # comparisons between categories of data, but with ability to break down and @@ -67,7 +67,8 @@ def draw (@bar_width * @bar_spacing / 2.0) draw_label(label_center, point_index) - next if data_point == 0 + next if data_point.zero? + # Use incremented x and scaled y left_x = @graph_left + (@bar_width * point_index) + @padding left_y = @graph_top + (@graph_height - @@ -90,12 +91,12 @@ def draw def max_stack_height # Get the sum of values in each stack to the get the stack height max_hash = {} - #@data.each do |data_set| - @data[:y_values].each_with_index do |data_point, i| - max_hash[i] = 0.0 unless max_hash[i] - max_hash[i] += data_point.to_f - end - # end + # @data.each do |data_set| + @data[:y_values].each_with_index do |data_point, i| + max_hash[i] = 0.0 unless max_hash[i] + max_hash[i] += data_point.to_f + end + # end @geometry.maximum_value = 0 max_hash.keys.each do |key| @@ -103,7 +104,11 @@ def max_stack_height end @geometry.minimum_value = 0 end - end # class StackedBar - end # module Plot - end # module MagickWrapper -end # module Rubyplot + end + # class StackedBar + end + # module Plot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/plot/stacked_bar/geometry.rb b/lib/rubyplot/magick_wrapper/plot/stacked_bar/geometry.rb index 3150a5e..0b7d3b8 100644 --- a/lib/rubyplot/magick_wrapper/plot/stacked_bar/geometry.rb +++ b/lib/rubyplot/magick_wrapper/plot/stacked_bar/geometry.rb @@ -18,8 +18,13 @@ def initialize @all_colors_array = Magick.colors @plot_colors = [] end - end # class Geometry - end # class StackedBar - end # module Plot - end # module MagickWrapper -end # module Rubyplot + end + # class Geometry + end + # class StackedBar + end + # module Plot + end + # module MagickWrapper +end +# module Rubyplot diff --git a/lib/rubyplot/magick_wrapper/themes.rb b/lib/rubyplot/magick_wrapper/themes.rb index 70a858a..b9fb9a1 100644 --- a/lib/rubyplot/magick_wrapper/themes.rb +++ b/lib/rubyplot/magick_wrapper/themes.rb @@ -8,7 +8,7 @@ module Themes marker_color: 'white', # The color of the marker used to make marker lines on plot. font_color: 'white', # Font Color used to write on the plot. background_colors: %w[black #4a465a], # The Background colors that form the gradient - label_colors: %w[#ffe119 #0082c8 #f58231 #911eb4 #aaffc3 #808000 #ffd8b1 #000080 #808080] + label_colors: %w[#ffe119 #0082c8 #f58231 #911eb4 #aaffc3 #808000 #ffd8b1 #000080 #808080] }.freeze TRACKS = { diff --git a/lib/rubyplot/spi.rb b/lib/rubyplot/spi.rb index 26f1438..9b584c1 100644 --- a/lib/rubyplot/spi.rb +++ b/lib/rubyplot/spi.rb @@ -1,10 +1,8 @@ module Rubyplot # Rubyplot simple plotting interface class SPI - def initialize - end - - def scatter! *args, &block - end + def initialize; end + + def scatter!(*args, &block); end end end diff --git a/lib/rubyplot/subplot.rb b/lib/rubyplot/subplot.rb index facda6b..fc0adfc 100644 --- a/lib/rubyplot/subplot.rb +++ b/lib/rubyplot/subplot.rb @@ -1,5 +1,4 @@ module Rubyplot class Subplot - end end diff --git a/lib/rubyplot/themes.rb b/lib/rubyplot/themes.rb index 606a9e5..98479e4 100644 --- a/lib/rubyplot/themes.rb +++ b/lib/rubyplot/themes.rb @@ -7,7 +7,7 @@ module Themes marker_color: 'white', # The color of the marker used to make marker lines on plot. font_color: 'white', # Font Color used to write on the plot. background_colors: %w[black #4a465a], # The Background colors that form the gradient - label_colors: %w[#ffe119 #0082c8 #f58231 #911eb4 #aaffc3 #808000 #ffd8b1 #000080 #808080] + label_colors: %w[#ffe119 #0082c8 #f58231 #911eb4 #aaffc3 #808000 #ffd8b1 #000080 #808080] }.freeze TRACKS = { diff --git a/lib/rubyplot/utils.rb b/lib/rubyplot/utils.rb index bcebf0a..daad809 100644 --- a/lib/rubyplot/utils.rb +++ b/lib/rubyplot/utils.rb @@ -1,12 +1,12 @@ module Rubyplot module Utils - THOUSAND_SEPARATOR = ',' + THOUSAND_SEPARATOR = ','.freeze class << self - def format_label label - if label.is_a? Float - format('%0.2f', label) - end + def format_label(label) + '%0.2f' % label if label.is_a? Float end end - end # module Utils -end # module Rubyplot + end + # module Utils +end +# module Rubyplot diff --git a/lib/rubyplot/version.rb b/lib/rubyplot/version.rb index 3c4e703..3598147 100644 --- a/lib/rubyplot/version.rb +++ b/lib/rubyplot/version.rb @@ -1,3 +1,3 @@ module Rubyplot - VERSION = "0.0.1" + VERSION = '0.0.1'.freeze end From c713e3afb79c0885962452369a07cf2873ce2352 Mon Sep 17 00:00:00 2001 From: arzoo14 Date: Sat, 15 Dec 2018 15:40:15 +0530 Subject: [PATCH 2/9] Update rubyplot.rb --- lib/rubyplot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rubyplot.rb b/lib/rubyplot.rb index 5e6bd66..8c2a411 100644 --- a/lib/rubyplot.rb +++ b/lib/rubyplot.rb @@ -19,7 +19,7 @@ module Rubyplot def self.backend b = ENV['RUBYPLOT_BACKEND'] - return b.to_sym if %w[magick gr].include?(b) + return b.to_sym if ["magick" , "gr"].include?(b) :magick end From d1610f8245bc8c02045c5986155e2f8239298110 Mon Sep 17 00:00:00 2001 From: arzoo14 Date: Sun, 16 Dec 2018 01:19:30 +0530 Subject: [PATCH 3/9] setup_travis_CI --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..549dfe9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: + ruby + +rvm: + - '2.0' + - '2.1' + - '2.2' + - '2.3.0' + - '2.4.0' + +script: + - bundle exec rubocop From 0925590a2a764bd5314c90288126445884fc69df Mon Sep 17 00:00:00 2001 From: arzoo14 Date: Sat, 15 Dec 2018 20:15:09 +0530 Subject: [PATCH 4/9] setup_tavis_ci --- lib/rubyplot.rb | 2 +- lib/rubyplot/artist/axes.rb | 25 +++++++++++-------------- lib/rubyplot/artist/axis/base.rb | 5 ++--- lib/rubyplot/artist/plot/bar.rb | 5 +++-- lib/rubyplot/artist/plot/base.rb | 17 ++++++++++------- lib/rubyplot/artist/plot/line.rb | 4 ++-- lib/rubyplot/artist/plot/multi_bars.rb | 26 +++++++++++++------------- 7 files changed, 42 insertions(+), 42 deletions(-) diff --git a/lib/rubyplot.rb b/lib/rubyplot.rb index 8c2a411..5e6bd66 100644 --- a/lib/rubyplot.rb +++ b/lib/rubyplot.rb @@ -19,7 +19,7 @@ module Rubyplot def self.backend b = ENV['RUBYPLOT_BACKEND'] - return b.to_sym if ["magick" , "gr"].include?(b) + return b.to_sym if %w[magick gr].include?(b) :magick end diff --git a/lib/rubyplot/artist/axes.rb b/lib/rubyplot/artist/axes.rb index a15add0..04eada4 100644 --- a/lib/rubyplot/artist/axes.rb +++ b/lib/rubyplot/artist/axes.rb @@ -17,11 +17,11 @@ class Axes < Base # Range of X axis. attr_accessor :x_range # Range of Y axis. - + attr_accessor :y_range, - :text_font, :grid, - :bounding_box, :x_axis_padding, :y_axis_padding, :origin, - :title_shift, :title_margin + :text_font, :grid, + :bounding_box, :x_axis_padding, :y_axis_padding, :origin, + :title_shift, :title_margin # Main title for this Axes. attr_accessor :title @@ -52,14 +52,14 @@ class Axes < Base # @param figure [Rubyplot::Figure] Figure object to which this Axes belongs. def initialize(figure) @figure = figure - + @x_title = '' @y_title = '' @x_axis_margin = 40.0 @y_axis_margin = 40.0 @x_range = [nil, nil] @y_range = [nil, nil] - + @origin = [nil, nil] @title = '' @title_shift = 0 @@ -171,9 +171,7 @@ def height (1 - (@figure.top_spacing + @figure.bottom_spacing)) * @figure.height end - def x_ticks= ticks_hash - @x_ticks = ticks_hash - end + attr_writer :x_ticks private @@ -272,15 +270,14 @@ def label_string(value, increment) parts.join('.') end - def consolidate_plots bars = @plots.map { |p| p.is_a?(Rubyplot::Artist::Plot::Bar) } @plots.delete_if { |p| p.is_a?(Rubyplot::Artist::Plot::Bar) } @plots << Rubyplot::Artist::Plot::MultiBars.new(self, bars) end - end + end # class Axes - end + end # moudle Artist -end -# module Rubyplot \ No newline at end of file +end +# module Rubyplot diff --git a/lib/rubyplot/artist/axis/base.rb b/lib/rubyplot/artist/axis/base.rb index bcf304f..66890f2 100644 --- a/lib/rubyplot/artist/axis/base.rb +++ b/lib/rubyplot/artist/axis/base.rb @@ -8,9 +8,8 @@ class Base attr_reader :label, :ticks, :major_ticks_count, :min_val, :max_val, :title attr_reader :abs_x1, :abs_x2, :abs_y1, :abs_y2, :backend - attr_reader :stroke_width, :major_ticks - + def initialize(axes, title, min_val, max_val) @axes = axes @title = title @@ -27,4 +26,4 @@ def initialize(axes, title, min_val, max_val) end # class Artist end -# module Rubyplot \ No newline at end of file +# module Rubyplot diff --git a/lib/rubyplot/artist/plot/bar.rb b/lib/rubyplot/artist/plot/bar.rb index 8c59aeb..4b13ea8 100644 --- a/lib/rubyplot/artist/plot/bar.rb +++ b/lib/rubyplot/artist/plot/bar.rb @@ -37,6 +37,7 @@ def num_bars def draw super return unless @axes.geometry.has_data + configure_bars end @@ -47,9 +48,9 @@ def configure_bars x_axis_length = @axes.x_axis.abs_x2 - @axes.x_axis.abs_x1 @bar_width = coords_width / @data[:y_values].to_f padding = @bar_width * @spacing_ratio / 2 - @normalized_data[:y_values].each_with_index do |iy, index| + @normalized_data[:y_values].each_with_index do |_iy, index| ix = @normalized_data[:x_values][index] - left_x = ix * x_axis_length + ix * x_axis_length end end end diff --git a/lib/rubyplot/artist/plot/base.rb b/lib/rubyplot/artist/plot/base.rb index 064b3e5..9dbb967 100644 --- a/lib/rubyplot/artist/plot/base.rb +++ b/lib/rubyplot/artist/plot/base.rb @@ -54,13 +54,16 @@ def normalize y_min = @axes.y_range[0] < 0 ? @axes.y_range[0] : 0 x_spread = @axes.x_range[1] - x_min y_spread = @axes.y_range[1] - y_min - @normalized_data[:x_values] = @data[:x_values].map do |x| - - (x.to_f - x_min) / x_spread - end if @data[:x_values] - @normalized_data[:y_values] = @data[:y_values].map do |y| - (y.to_f - y_min) / y_spread - end if @data[:y_values] + if @data[:x_values] + @normalized_data[:x_values] = @data[:x_values].map do |x| + (x.to_f - x_min) / x_spread + end + end + if @data[:y_values] + @normalized_data[:y_values] = @data[:y_values].map do |y| + (y.to_f - y_min) / y_spread + end + end end protected diff --git a/lib/rubyplot/artist/plot/line.rb b/lib/rubyplot/artist/plot/line.rb index 8ef9e17..60f4983 100644 --- a/lib/rubyplot/artist/plot/line.rb +++ b/lib/rubyplot/artist/plot/line.rb @@ -38,11 +38,12 @@ def draw_lines @normalized_data[:x_values].each_with_index do |ix, idx_ix| iy = @normalized_data[:y_values][idx_ix] next if ix.nil? || iy.nil? + new_x = ix * (@axes.x_axis.abs_x2 - @axes.x_axis.abs_x1).abs + @axes.abs_x + @axes.y_axis_margin new_y = (y_axis_length - iy * y_axis_length) + @axes.abs_y - if !(prev_x.nil? && prev_y.nil?) + unless prev_x.nil? && prev_y.nil? Rubyplot::Artist::Line2D.new( self, abs_x1: prev_x, @@ -51,7 +52,6 @@ def draw_lines abs_y2: new_y, stroke_opacity: @stroke_opacity, stroke_width: @stroke_width - ).draw end prev_x = new_x diff --git a/lib/rubyplot/artist/plot/multi_bars.rb b/lib/rubyplot/artist/plot/multi_bars.rb index e664b25..621185b 100644 --- a/lib/rubyplot/artist/plot/multi_bars.rb +++ b/lib/rubyplot/artist/plot/multi_bars.rb @@ -5,7 +5,7 @@ module Plot class MultiBars < Artist::Plot::Base # The max. width that each bar can occupy. attr_reader :max_bar_width - + def initialize(*, bar_plots:) super @bar_plots = bar_plots @@ -21,25 +21,25 @@ def draw private def configure_plot_geometry_data - max_bars = @bar_plots.map { |bar| bar.num_bars }.max + @bar_plots.map(&:num_bars).max @max_bar_width = (@axes.x_axis.abs_x2 - @axes.x_axis.abs_x1).abs @bar_plots.each do |bar| set_bar_coords bar end end - + def configure_x_ticks if @axes.x_ticks # user supplied ticks - - else # default ticks - + end end - def set_bar_coords bar_plot - - end - end # class MultiBars - end # module Plot - end # module Artist -end # module Rubyplot + def bar_coords_set bar_plot; end + end + # class MultiBars + end + # module Plot + end + # module Artist +end +# module Rubyplot From d50db16119a60d28d213285111cb57ce79fb9b78 Mon Sep 17 00:00:00 2001 From: arzoo14 Date: Sat, 15 Dec 2018 23:18:24 +0530 Subject: [PATCH 5/9] Update rubyplot.rb --- lib/rubyplot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rubyplot.rb b/lib/rubyplot.rb index 5e6bd66..8c2a411 100644 --- a/lib/rubyplot.rb +++ b/lib/rubyplot.rb @@ -19,7 +19,7 @@ module Rubyplot def self.backend b = ENV['RUBYPLOT_BACKEND'] - return b.to_sym if %w[magick gr].include?(b) + return b.to_sym if ["magick" , "gr"].include?(b) :magick end From e0b23d441bef16989acb6ddca0fc69e837b8e891 Mon Sep 17 00:00:00 2001 From: arzoo14 Date: Tue, 18 Dec 2018 22:30:44 +0530 Subject: [PATCH 6/9] color_related --- lib/rubyplot/color.rb | 2 +- lib/rubyplot/themes.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rubyplot/color.rb b/lib/rubyplot/color.rb index 82a0306..718334e 100644 --- a/lib/rubyplot/color.rb +++ b/lib/rubyplot/color.rb @@ -972,7 +972,7 @@ module Color blue: '#0000FF', green: '#008000', purple: '#7e1e9c', - vivid_orange: '#ff7f0e' + vivid_orange: '#ff7f0e', }.freeze end end diff --git a/lib/rubyplot/themes.rb b/lib/rubyplot/themes.rb index 2adf800..9a3ce9e 100644 --- a/lib/rubyplot/themes.rb +++ b/lib/rubyplot/themes.rb @@ -7,7 +7,7 @@ module Themes marker_color: 'white', # The color of the marker used to make marker lines on plot. font_color: 'white', # Font Color used to write on the plot. background_colors: %w[black #4a465a], # The Background colors that form the gradient - label_colors: %w[#ffe119 #0082c8 #f58231 #911eb4 #aaffc3 #808000 #ffd8b1 #000080 #808080] + label_colors: %w[#ffe119 #0082c8 #f58231 #911eb4 #aaffc3 #808000 #ffd8b1 #000080 #808080] }.freeze TRACKS = { From 38e4ecdc7c8ee56ef3a867fd0118550acefbbdeb Mon Sep 17 00:00:00 2001 From: arzoo14 Date: Tue, 18 Dec 2018 22:54:49 +0530 Subject: [PATCH 7/9] Update color.rb --- lib/rubyplot/color.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rubyplot/color.rb b/lib/rubyplot/color.rb index 718334e..82a0306 100644 --- a/lib/rubyplot/color.rb +++ b/lib/rubyplot/color.rb @@ -972,7 +972,7 @@ module Color blue: '#0000FF', green: '#008000', purple: '#7e1e9c', - vivid_orange: '#ff7f0e', + vivid_orange: '#ff7f0e' }.freeze end end From c250f0eefbd513c9560bc94084e22a93ab187709 Mon Sep 17 00:00:00 2001 From: arzoo14 Date: Wed, 26 Dec 2018 01:30:10 +0530 Subject: [PATCH 8/9] rubocop_offenses --- .rubocop.yml | 2 - .travis.yml | 12 ---- lib/rubyplot.rb | 2 +- lib/rubyplot/artist/axes.rb | 27 +++---- lib/rubyplot/artist/axis/base.rb | 6 +- lib/rubyplot/artist/axis/x_axis.rb | 4 +- lib/rubyplot/artist/axis/y_axis.rb | 1 - lib/rubyplot/artist/circle.rb | 5 +- lib/rubyplot/artist/legend_box.rb | 20 +++--- lib/rubyplot/artist/plot/area.rb | 12 ++-- lib/rubyplot/artist/plot/bar.rb | 5 +- lib/rubyplot/artist/plot/bar_type.rb | 16 +++-- lib/rubyplot/artist/plot/base.rb | 24 ++++--- lib/rubyplot/artist/plot/bubble.rb | 13 ++-- lib/rubyplot/artist/plot/multi_bars.rb | 11 ++- lib/rubyplot/artist/plot/multi_stacked_bar.rb | 22 +++--- lib/rubyplot/artist/plot/stacked_bar.rb | 16 +++-- lib/rubyplot/artist/polygon.rb | 9 ++- lib/rubyplot/artist/rectangle.rb | 1 - lib/rubyplot/artist/tick/base.rb | 4 +- lib/rubyplot/artist/tick/x_tick.rb | 7 +- lib/rubyplot/backend/magick_wrapper.rb | 4 +- lib/rubyplot/color.rb | 72 +++++++++---------- lib/rubyplot/utils.rb | 2 +- 24 files changed, 144 insertions(+), 153 deletions(-) delete mode 100644 .travis.yml diff --git a/.rubocop.yml b/.rubocop.yml index 61b0525..b99a277 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,9 +2,7 @@ AllCops: Include: - 'lib/**/*' Exclude: - - 'daru.gemspec' - 'Rakefile' - - 'Gemfile' - 'Guardfile' - '**/*.erb' - 'spec/*' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 549dfe9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: - ruby - -rvm: - - '2.0' - - '2.1' - - '2.2' - - '2.3.0' - - '2.4.0' - -script: - - bundle exec rubocop diff --git a/lib/rubyplot.rb b/lib/rubyplot.rb index c0303a3..2840aa3 100644 --- a/lib/rubyplot.rb +++ b/lib/rubyplot.rb @@ -18,7 +18,7 @@ module Rubyplot def self.backend b = ENV['RUBYPLOT_BACKEND'] - return b.to_sym if ["magick" , "gr"].include?(b) + return b.to_sym if %w[magick gr].include?(b) :magick end diff --git a/lib/rubyplot/artist/axes.rb b/lib/rubyplot/artist/axes.rb index 3545293..1fc3d51 100644 --- a/lib/rubyplot/artist/axes.rb +++ b/lib/rubyplot/artist/axes.rb @@ -14,10 +14,7 @@ class Axes < Base attr_accessor :x_range # Range of Y axis. - attr_accessor :y_range, - :text_font, :grid, - :bounding_box, :origin, - :title_shift, :title_margin + attr_accessor :y_range, :text_font, :grid, :bounding_box, :origin, :title_shift, :title_margin # Main title for this Axes. attr_accessor :title @@ -27,8 +24,7 @@ class Axes < Base attr_reader :plots attr_reader :font, :marker_font_size, :legend_font_size, :title_font_size, :scale, :font_color, :marker_color, :axes, - :legend_margin, :backend, :marker_caps_height, :marker_font_size - + :legend_margin, :backend, :marker_caps_height attr_reader :label_stagger_height # FIXME: possibly disposable attrs attr_reader :title_caps_height @@ -59,7 +55,7 @@ def initialize(figure) @y_axis_margin = 40.0 @x_range = [nil, nil] @y_range = [nil, nil] - @title = "" + @title = '' @title_shift = 0 @title_margin = TITLE_MARGIN @text_font = :default @@ -141,13 +137,13 @@ def line!(*_args) @plots << plot end - def area! *args, &block + def area!(*_args) plot = Rubyplot::Artist::Plot::Area.new self yield(plot) if block_given? @plots << plot end - def bubble! *args, &block + def bubble!(*_args) plot = Rubyplot::Artist::Plot::Bubble.new self yield(plot) if block_given? @plots << plot @@ -157,7 +153,7 @@ def dot!(*args, &block) add_plot 'Dot', *args, &block end - def stacked_bar! *args, &block + def stacked_bar!(*_args) plot = Rubyplot::Artist::Plot::StackedBar.new self yield(plot) if block_given? @plots << plot @@ -199,7 +195,7 @@ def x_title= x_title def y_title= y_title @y_axis.title = y_title end - + private def assign_default_label_colors @@ -232,7 +228,6 @@ def assign_x_ticks end def add_plot plot_type, *args, &block - plot = with_backend plot_type, *args yield(plot) if block_given? @plots << plot @@ -249,7 +244,6 @@ def with_backend(plot_type, *args) plot end - # Figure out the co-ordinates of the title text w.r.t Axes. def configure_title @title = Rubyplot::Artist::Text.new( @@ -290,16 +284,15 @@ def actually_draw def consolidate_plots bars = @plots.grep(Rubyplot::Artist::Plot::Bar) - if !bars.empty? + unless bars.empty? @plots.delete_if { |p| p.is_a?(Rubyplot::Artist::Plot::Bar) } @plots << Rubyplot::Artist::Plot::MultiBars.new(self, bar_plots: bars) end stacked_bars = @plots.grep(Rubyplot::Artist::Plot::StackedBar) - if !stacked_bars.empty? + unless stacked_bars.empty? @plots.delete_if { |p| p.is_a?(Rubyplot::Artist::Plot::StackedBar) } - @plots << Rubyplot::Artist::Plot::MultiStackedBar.new( - self, stacked_bars: stacked_bars) + @plots << Rubyplot::Artist::Plot::MultiStackedBar.new(self, stacked_bars: stacked_bars) end end diff --git a/lib/rubyplot/artist/axis/base.rb b/lib/rubyplot/artist/axis/base.rb index de46075..f2799b7 100644 --- a/lib/rubyplot/artist/axis/base.rb +++ b/lib/rubyplot/artist/axis/base.rb @@ -4,15 +4,15 @@ class Axis class Base # Length in pixels of the arrow after the last major tick. FINISH_ARROW_LENGTH = 10.0 - + attr_reader :label, :ticks, :major_ticks_count attr_reader :abs_x1, :abs_x2, :abs_y1, :abs_y2, :backend, :length attr_reader :stroke_width, :major_ticks attr_accessor :title, :min_val, :max_val - + def initialize axes @axes = axes - @title = "" + @title = '' @min_val = nil @max_val = nil @stroke_width = 1.0 diff --git a/lib/rubyplot/artist/axis/x_axis.rb b/lib/rubyplot/artist/axis/x_axis.rb index 32d1799..a9e65dd 100644 --- a/lib/rubyplot/artist/axis/x_axis.rb +++ b/lib/rubyplot/artist/axis/x_axis.rb @@ -23,8 +23,8 @@ def draw def configure_axis_line @line = Rubyplot::Artist::Line2D.new( self, abs_x1: @abs_x1, abs_y1: @axes.origin[1], abs_x2: @abs_x2, abs_y2: @axes.origin[1], - stroke_width: @stroke_width) - + stroke_width: @stroke_width + ) end def configure_title diff --git a/lib/rubyplot/artist/axis/y_axis.rb b/lib/rubyplot/artist/axis/y_axis.rb index 6986372..d130b2f 100644 --- a/lib/rubyplot/artist/axis/y_axis.rb +++ b/lib/rubyplot/artist/axis/y_axis.rb @@ -41,7 +41,6 @@ def configure_title pointsize: @axes.marker_font_size ) end - end # class YAxis end diff --git a/lib/rubyplot/artist/circle.rb b/lib/rubyplot/artist/circle.rb index 440fbb6..2710ca7 100644 --- a/lib/rubyplot/artist/circle.rb +++ b/lib/rubyplot/artist/circle.rb @@ -1,10 +1,9 @@ module Rubyplot module Artist class Circle < Base - # rubocop:disable Metrics/ParameterLists - def initialize(owner, abs_x:, abs_y:, radius: , stroke_opacity: 0.0, - color: :default, stroke_width:) + def initialize(owner, abs_x:, abs_y:, radius:, stroke_opacity: 0.0, + color: :default, stroke_width:) super(owner.backend, abs_x, abs_y) @owner = owner @radius = radius diff --git a/lib/rubyplot/artist/legend_box.rb b/lib/rubyplot/artist/legend_box.rb index ab9da8b..d1f4c2b 100644 --- a/lib/rubyplot/artist/legend_box.rb +++ b/lib/rubyplot/artist/legend_box.rb @@ -72,16 +72,16 @@ def configure_dimensions def configure_legends @axes.plots.each_with_index do |plot, count| - if plot.label != "" - @legends << Rubyplot::Artist::Legend.new( - self, - @axes, - text: plot.label, - color: plot.color, - abs_x: @abs_x + left_margin, - abs_y: @abs_y + count * per_legend_height + top_margin - ) - end + next unless plot.label != '' + + @legends << Rubyplot::Artist::Legend.new( + self, + @axes, + text: plot.label, + color: plot.color, + abs_x: @abs_x + left_margin, + abs_y: @abs_y + count * per_legend_height + top_margin + ) end end end diff --git a/lib/rubyplot/artist/plot/area.rb b/lib/rubyplot/artist/plot/area.rb index 4ad444c..67aac0f 100644 --- a/lib/rubyplot/artist/plot/area.rb +++ b/lib/rubyplot/artist/plot/area.rb @@ -31,7 +31,11 @@ def draw fill_opacity: 0.3 ).draw end - end # class Area - end # module Plot - end # module Artist -end # module Rubyplot + end + # class Area + end + # module Plot + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/plot/bar.rb b/lib/rubyplot/artist/plot/bar.rb index 27598ef..f02f2a1 100644 --- a/lib/rubyplot/artist/plot/bar.rb +++ b/lib/rubyplot/artist/plot/bar.rb @@ -15,7 +15,7 @@ class Bar < Artist::Plot::Base attr_accessor :abs_x_left # Y co-ordinates of the lower left corner of the bar. attr_accessor :abs_y_left - + def initialize(*) super @spacing_ratio = 0.1 @@ -34,7 +34,7 @@ def spacing_factor=(s_f) # Set Bar plot data. def data y_values - super(Array.new(y_values.size) { |i| i}, y_values) + super(Array.new(y_values.size) { |i| i }, y_values) end # Number of bars in this Bar plot @@ -49,7 +49,6 @@ def draw private - def setup_bar_rectangles @normalized_data[:y_values].each_with_index do |iy, i| height = iy * @axes.y_axis.length diff --git a/lib/rubyplot/artist/plot/bar_type.rb b/lib/rubyplot/artist/plot/bar_type.rb index d702f6a..48826fc 100644 --- a/lib/rubyplot/artist/plot/bar_type.rb +++ b/lib/rubyplot/artist/plot/bar_type.rb @@ -2,7 +2,6 @@ module Rubyplot module Artist module Plot class BarType < Artist::Plot::Base - def initialize(*) super @spacing_ratio = 0.1 @@ -14,7 +13,7 @@ def initialize(*) def data y_values super(Array(0...(y_values.size)), y_values) end - + def num_bars @data[:y_values].size end @@ -26,8 +25,11 @@ def draw protected - - end # class BarType - end # module Plot - end # module Artist -end # module Rubyplot + end + # class BarType + end + # module Plot + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/plot/base.rb b/lib/rubyplot/artist/plot/base.rb index cb48d40..ed473a2 100644 --- a/lib/rubyplot/artist/plot/base.rb +++ b/lib/rubyplot/artist/plot/base.rb @@ -2,16 +2,15 @@ module Rubyplot module Artist module Plot class Base < Artist::Base - attr_reader :axes, :data, :x_max, :x_min, :y_min, - :y_max + attr_reader :axes, :data, :x_max, :x_min, :y_min, :y_max attr_writer :stroke_width, :stroke_opacity - + def initialize axes super(axes.backend, axes.abs_x, axes.abs_y) @axes = axes @backend = @axes.backend @data = { - label: "", + label: '', color: :default } @normalized_data = { @@ -34,7 +33,6 @@ def label=(label) @data[:label] = label end - def color= color @data[:color] = color end @@ -53,12 +51,16 @@ def data(x_values, y_values) def normalize x_spread = @axes.x_range[1] - @axes.x_range[0] y_spread = @axes.y_range[1] - @axes.y_range[0] - @normalized_data[:x_values] = @data[:x_values].map do |x| - (x.to_f - @axes.x_range[0]) / x_spread - end if @data[:x_values] - @normalized_data[:y_values] = @data[:y_values].map do |y| - (y.to_f - @axes.y_range[0]) / y_spread - end if @data[:y_values] + if @data[:x_values] + @normalized_data[:x_values] = @data[:x_values].map do |x| + (x.to_f - @axes.x_range[0]) / x_spread + end + end + if @data[:y_values] + @normalized_data[:y_values] = @data[:y_values].map do |y| + (y.to_f - @axes.y_range[0]) / y_spread + end + end end end # class Base diff --git a/lib/rubyplot/artist/plot/bubble.rb b/lib/rubyplot/artist/plot/bubble.rb index 5b7dedc..86242cd 100644 --- a/lib/rubyplot/artist/plot/bubble.rb +++ b/lib/rubyplot/artist/plot/bubble.rb @@ -5,7 +5,6 @@ class Bubble < Artist::Plot::Base # Width in pixels of the border of each bubble. attr_reader :stroke_width attr_reader :z_max, :z_min - def initialize(*) super @bubbles = [] @@ -36,7 +35,11 @@ def draw end @bubbles.each(&:draw) end - end # class Bubble - end # module Plot - end # module Artist -end # module Rubyplot + end + # class Bubble + end + # module Plot + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/plot/multi_bars.rb b/lib/rubyplot/artist/plot/multi_bars.rb index edcd12c..4109196 100644 --- a/lib/rubyplot/artist/plot/multi_bars.rb +++ b/lib/rubyplot/artist/plot/multi_bars.rb @@ -10,7 +10,7 @@ module Plot class MultiBars < Artist::Plot::Base # The max. width that each bar can occupy. attr_reader :max_bar_width - + def initialize(*args, bar_plots:) super(args[0]) @bar_plots = bar_plots @@ -33,8 +33,7 @@ def draw private def configure_plot_geometry_data - - @num_max_slots = @bar_plots.map { |bar| bar.num_bars }.max + @num_max_slots = @bar_plots.map(&:num_bars).max @max_slot_width = (@axes.x_axis.abs_x2 - @axes.x_axis.abs_x1).abs / @num_max_slots # FIXME: figure out a way to specify inter-box space somehow. @spacing_ratio = @bar_plots[0].spacing_ratio @@ -48,10 +47,8 @@ def configure_plot_geometry_data def configure_x_ticks @axes.num_x_ticks = @num_max_slots - labels = @axes.x_ticks || Array.new(@num_max_slots) { |i| i.to_s } - if labels.size != @axes.num_x_ticks - labels = labels[0...@axes.num_x_ticks] - end + labels = @axes.x_ticks || Array.new(@num_max_slots, &:to_s) + labels = labels[0...@axes.num_x_ticks] if labels.size != @axes.num_x_ticks @axes.x_ticks = labels.map.with_index do |label, i| Rubyplot::Artist::XTick.new( @axes, diff --git a/lib/rubyplot/artist/plot/multi_stacked_bar.rb b/lib/rubyplot/artist/plot/multi_stacked_bar.rb index 6146178..7939c00 100644 --- a/lib/rubyplot/artist/plot/multi_stacked_bar.rb +++ b/lib/rubyplot/artist/plot/multi_stacked_bar.rb @@ -35,7 +35,7 @@ def renormalize_data end def configure_plot_geometry_data - @num_max_slots = @stacked_bars.map { |bar| bar.num_bars }.max + @num_max_slots = @stacked_bars.map(&:num_bars).max @max_slot_width = @axes.x_axis.length / @num_max_slots @spacing_ratio = @stacked_bars[0].spacing_ratio @padding = @spacing_ratio * @max_slot_width @@ -48,10 +48,8 @@ def configure_plot_geometry_data def configure_x_ticks @axes.num_x_ticks = @num_max_slots - labels = @axes.x_ticks || Array.new(@num_max_slots) { |i| i.to_s } - if labels.size != @axes.num_x_ticks - labels = labels[0...@axes.num_x_ticks] - end + labels = @axes.x_ticks || Array.new(@num_max_slots, &:to_s) + labels = labels[0...@axes.num_x_ticks] if labels.size != @axes.num_x_ticks @axes.x_ticks = labels.map.with_index do |label, i| Rubyplot::Artist::XTick.new( @axes, @@ -70,11 +68,15 @@ def set_bar_dims bar, plot_index bar.num_bars.times do |i| pedestal_height = plots_below.map { |p| p.member_height(i) }.inject(:+) || 0 bar.abs_x_left[i] = @axes.abs_x + @axes.y_axis_margin + - i * @max_slot_width + @padding / 2 + i * @max_slot_width + @padding / 2 bar.abs_y_left[i] = (@axes.abs_y + @axes.y_axis.length) - pedestal_height end end - end # class StackedBar - end # module Plot - end # module Artist -end # module Rubyplot + end + # class StackedBar + end + # module Plot + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/plot/stacked_bar.rb b/lib/rubyplot/artist/plot/stacked_bar.rb index 42c2c89..c7f3314 100644 --- a/lib/rubyplot/artist/plot/stacked_bar.rb +++ b/lib/rubyplot/artist/plot/stacked_bar.rb @@ -9,8 +9,8 @@ class StackedBar < Artist::Plot::Base # Array of Y co-ordinates of the lower left corner of each stacked bar. attr_accessor :abs_y_left # Width in pixels of each bar. - attr_accessor :bar_width - + attr_accessor :bar_width + def initialize(*) super @spacing_ratio = 0.1 @@ -63,7 +63,11 @@ def setup_bar_rectangles ) end end - end # class StackedBar - end # module Plot - end # module Artist -end # module Rubyplot + end + # class StackedBar + end + # module Plot + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/polygon.rb b/lib/rubyplot/artist/polygon.rb index d1aabba..f84ad54 100644 --- a/lib/rubyplot/artist/polygon.rb +++ b/lib/rubyplot/artist/polygon.rb @@ -17,6 +17,9 @@ def draw fill_opacity: @fill_opacity ) end - end # class Polygon - end # module Artist -end # module Rubyplot + end + # class Polygon + end + # module Artist +end +# module Rubyplot diff --git a/lib/rubyplot/artist/rectangle.rb b/lib/rubyplot/artist/rectangle.rb index fe1ec55..64444dc 100644 --- a/lib/rubyplot/artist/rectangle.rb +++ b/lib/rubyplot/artist/rectangle.rb @@ -3,7 +3,6 @@ module Artist class Rectangle < Base attr_reader :width, :height, :border_color, :fill_color - # Create a Rectangle for drawing on the canvas. # # @param abs_x [Float] Absolute X co-ordinate of the upper left corner. diff --git a/lib/rubyplot/artist/tick/base.rb b/lib/rubyplot/artist/tick/base.rb index 08eefa1..aee1e58 100644 --- a/lib/rubyplot/artist/tick/base.rb +++ b/lib/rubyplot/artist/tick/base.rb @@ -19,11 +19,11 @@ class Base < Artist::Base # rubocop:disable Metrics/ParameterLists def initialize(owner,abs_x:,abs_y:,length:,label:,label_distance:, - tick_opacity: 0.0,tick_width: 1.0) + tick_opacity: 0.0,tick_width: 1.0) super(owner.backend, abs_x, abs_y) @owner = owner @length = length - @label_text = label #Rubyplot::Utils.format_label label + @label_text = label # Rubyplot::Utils.format_label label @label_distance = label_distance @tick_opacity = tick_opacity @tick_width = tick_width diff --git a/lib/rubyplot/artist/tick/x_tick.rb b/lib/rubyplot/artist/tick/x_tick.rb index 24df354..b647cac 100644 --- a/lib/rubyplot/artist/tick/x_tick.rb +++ b/lib/rubyplot/artist/tick/x_tick.rb @@ -20,10 +20,9 @@ def draw ) @label.draw end - end + end # class XTick - end + end # class Artist -end +end # module Rubyplot - diff --git a/lib/rubyplot/backend/magick_wrapper.rb b/lib/rubyplot/backend/magick_wrapper.rb index 96d002a..2da0742 100644 --- a/lib/rubyplot/backend/magick_wrapper.rb +++ b/lib/rubyplot/backend/magick_wrapper.rb @@ -122,8 +122,8 @@ def draw_circle(x_pos:,y_pos:,radius:,stroke_opacity:,stroke_width:,color:) # # @param coords [Array[Array]] Array of Arrays where first element of each sub-array is # the X co-ordinate and the second element is the Y co-ordinate. - def draw_polygon(coords: , fill_opacity: 0.0, color: "#000000", - stroke: "transparent") + def draw_polygon(coords:, fill_opacity: 0.0, color: '#000000', + stroke: 'transparent') @draw.stroke stroke @draw.fill color @draw.fill_opacity fill_opacity diff --git a/lib/rubyplot/color.rb b/lib/rubyplot/color.rb index 820ed30..d496fe4 100644 --- a/lib/rubyplot/color.rb +++ b/lib/rubyplot/color.rb @@ -2,42 +2,42 @@ module Rubyplot module Color # A list of contrasting colors that is used in Bartype BasePlots by default CONTRASTING_COLORS = { - gun_powder: '#4a465a', - eastern_blue: '#0083a3', - bittersweet: '#ff6a6a', - light_pink: '#ffaeb9', - violet: '#ee82ee', - bright_turquoise: '#00e5ee', - spring_green: '#00ff7f', - green_yellow: '#c0ff3e', - orange: '#ffa500', - misty_rose: '#ffe4e1', - silver: '#bdbdbd', - falu_red: '#8b2500', - royal_blue: '#436eee', - crimson: '#dc143c', - crimson: '#e6194b', - fruit_salad: '#3cb44b', - lemon: '#ffe119', - bondi_blue: '#0082c8', - sun: '#f58231', - dark_orchid: '#911eb4', - turquoise: '#46f0f0', - razzle_dazzle_rose: '#f032e6', - pear: '#d2f53c', - your_pink: '#fabebe', - teal: '#008080', - mauve: '#e6beff', - hot_toddy: '#aa6e28', - lemon_chiffon: '#fffac8', - maroon: '#800000', - magic_mint: '#aaffc3', - olive: '#808000', - sandy_beach: '#ffd8b1', - navy: '#000080', - grey: '#808080', - pattens_blue: '#d1edf5' - }.freeze + gun_powder: '#4a465a', + eastern_blue: '#0083a3', + bittersweet: '#ff6a6a', + light_pink: '#ffaeb9', + violet: '#ee82ee', + bright_turquoise: '#00e5ee', + spring_green: '#00ff7f', + green_yellow: '#c0ff3e', + orange: '#ffa500', + misty_rose: '#ffe4e1', + silver: '#bdbdbd', + falu_red: '#8b2500', + royal_blue: '#436eee', + crimson: '#dc143c', + crimson: '#e6194b', + fruit_salad: '#3cb44b', + lemon: '#ffe119', + bondi_blue: '#0082c8', + sun: '#f58231', + dark_orchid: '#911eb4', + turquoise: '#46f0f0', + razzle_dazzle_rose: '#f032e6', + pear: '#d2f53c', + your_pink: '#fabebe', + teal: '#008080', + mauve: '#e6beff', + hot_toddy: '#aa6e28', + lemon_chiffon: '#fffac8', + maroon: '#800000', + magic_mint: '#aaffc3', + olive: '#808000', + sandy_beach: '#ffd8b1', + navy: '#000080', + grey: '#808080', + pattens_blue: '#d1edf5' + }.freeze # A list of color symbols inspired by xkcd survey # https://xkcd.com/color/rgb/ diff --git a/lib/rubyplot/utils.rb b/lib/rubyplot/utils.rb index 1021290..5f1288c 100644 --- a/lib/rubyplot/utils.rb +++ b/lib/rubyplot/utils.rb @@ -4,7 +4,7 @@ module Utils class << self def format_label label if label.is_a? Float - format('%0.2f', label) + '%0.2f' % label elsif label.is_a? String label end From 1d845bfec59e1bd1f6a420c2a7ceedcff3f6cbdf Mon Sep 17 00:00:00 2001 From: arzoo14 Date: Wed, 26 Dec 2018 01:47:42 +0530 Subject: [PATCH 9/9] fixed_rubocop_errors --- lib/rubyplot/magick_wrapper.rb | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 lib/rubyplot/magick_wrapper.rb diff --git a/lib/rubyplot/magick_wrapper.rb b/lib/rubyplot/magick_wrapper.rb deleted file mode 100644 index 5bcd9b1..0000000 --- a/lib/rubyplot/magick_wrapper.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rmagick' - -require_relative 'magick_wrapper/artist' -require_relative 'magick_wrapper/themes' -require_relative 'magick_wrapper/plot'