diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..68a3a04 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,18 @@ +language: + ruby + +rvm: + - '2.0' + - '2.1' + - '2.2' + - '2.3.0' + - '2.4.0' + +script: + - bundle exec rspec + - bundle exec rubocop + +install: + - gem install bundler + - gem install rainbow -v '2.2.1' + - bundle install diff --git a/Gemfile b/Gemfile index 851fabc..fe47135 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,8 @@ source 'https://rubygems.org' + gemspec + +group :test do + gem 'rake' + gem 'rspec' +end diff --git a/Rakefile b/Rakefile index 4b5fcc9..e749f14 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,18 @@ +require "bundler/gem_tasks" +require "rake" + +require 'bundler/setup' +require 'rubygems/tasks' +Gem::Tasks.new + require 'rspec/core/rake_task' -require 'rake/extensiontask' +RSpec::Core::RakeTask.new + +require 'rubocop/rake_task' +RuboCop::RakeTask.new + +desc 'Default: run unit specs.' +task :default => %w[spec rubocop] gemspec = eval(IO.read('rubyplot.gemspec')) diff --git a/lib/rubyplot.rb b/lib/rubyplot.rb index 2840aa3..35591cc 100644 --- a/lib/rubyplot.rb +++ b/lib/rubyplot.rb @@ -12,13 +12,12 @@ require 'rubyplot/subplot' require 'rubyplot/spi' -require 'grruby.so' require 'rubyplot/gr_wrapper' module Rubyplot def self.backend b = ENV['RUBYPLOT_BACKEND'] - return b.to_sym if %w[magick gr].include?(b) + return b.to_sym if %w[magick ].include?(b) :magick end diff --git a/lib/rubyplot/artist/axes.rb b/lib/rubyplot/artist/axes.rb index 8370889..7de28b8 100644 --- a/lib/rubyplot/artist/axes.rb +++ b/lib/rubyplot/artist/axes.rb @@ -246,10 +246,12 @@ def with_backend(plot_type, *args) # Figure out the co-ordinates of the title text w.r.t Axes. def configure_title + @texts << 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.' + ) end diff --git a/lib/rubyplot/artist/axis/base.rb b/lib/rubyplot/artist/axis/base.rb index 7513b9a..21eda82 100644 --- a/lib/rubyplot/artist/axis/base.rb +++ b/lib/rubyplot/artist/axis/base.rb @@ -23,11 +23,13 @@ def initialize axes @lines = [] end + def draw configure_title @lines.each(&:draw) @texts.each(&:draw) end + end # class Base end diff --git a/lib/rubyplot/artist/text.rb b/lib/rubyplot/artist/text.rb index 1f00e10..0917bb1 100644 --- a/lib/rubyplot/artist/text.rb +++ b/lib/rubyplot/artist/text.rb @@ -7,11 +7,13 @@ class Text < Artist::Base # rubocop:disable Metrics/ParameterLists def initialize(text, owner, abs_x:, abs_y:,font: nil, + color: '#000000',pointsize:,stroke: 'transparent', internal_label: '', rotation: nil, weight: nil, gravity: nil ) super(owner.backend, abs_x, abs_y) + @text = text @owner = owner @font = font diff --git a/lib/rubyplot/backend/magick_wrapper.rb b/lib/rubyplot/backend/magick_wrapper.rb index f0704d6..f4f9fdb 100644 --- a/lib/rubyplot/backend/magick_wrapper.rb +++ b/lib/rubyplot/backend/magick_wrapper.rb @@ -16,6 +16,8 @@ def initialize @draw = Magick::Draw.new end + + # Height in pixels of particular text. # @param text [String] Text to be measured. def text_height(text, font, font_size) diff --git a/spec/axes_spec.rb b/spec/axes_spec.rb index 522d449..f2afc37 100644 --- a/spec/axes_spec.rb +++ b/spec/axes_spec.rb @@ -484,5 +484,3 @@ end # context "#x_ticks=" end # Rubyplot::Axes end # describe backends - - diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6688345..d0464b6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,8 @@ require 'fileutils' require 'pry' require 'rubyplot' +require 'rspec' +require 'rmagick' TEMP_DIR = "temp/" FIXTURES_DIR = "fixtures/"