diff --git a/.gitignore b/.gitignore
index c22eb69..9bbd516 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,5 @@
/html/
/spec/reports/
/tmp/
-/.idea/
\ No newline at end of file
+/.idea/
+*.gem
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 8cba926..863170c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,23 +1,26 @@
notifications:
email: false
language: ruby
+sudo: required
+os:
+ - osx
rvm:
- - ruby-2.0
- - ruby-2.1.5
- ruby-2.2.2
- - jruby-9.0.0.0.pre2
-env:
- - JRUBY_OPTS="-Xcli.debug=true --debug"
+ - ruby-2.3.0
+ - ruby-2.5.0
addons:
code_climate:
- repo_token: bbd2a5e077e4b62bd8ba21a74a2ba901defc43506812f6192efc6b2a25c20d49
+ repo_token: 60d9731d654527cb53aabc7db15bcde87d701ddb6b1cba8fc0da6aba16d00bb1
before_install:
- - sudo add-apt-repository "deb http://cz.archive.ubuntu.com/ubuntu vivid main universe"
- - sudo apt-get update -q
- - sudo rm -rf /etc/dpkg/dpkg.cfg.d/multiarch
- - sudo apt-get install gnuplot5
+ - brew update
+ - brew install pdflib-lite
+ - brew install gnuplot --with-png --with-jpeg --with-cairo --with-svg
+ - ulimit -S -n 4096
+ - gem update bundler
- bundle install
install:
- bundle exec rake install
script:
- bundle exec rake spec
+after_success:
+ - bundle exec codeclimate-test-reporter
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..923c9a1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,192 @@
+# GnuplotRB
+GnuplotRB is a plot generator for Ruby based on
+[Gnuplot](http://www.gnuplot.info).
+
+This software has been developed as a product in Google Summer of Code 2015 (GSoC2015). Its progress may be saw in [SciRuby mailing list](https://groups.google.com/forum/?fromgroups#!topic/sciruby-dev/lhWvb5hWc3k) or in [project's blog](http://www.evgrafov.work/gnuplotrb/).
+
+[](https://badge.fury.io/rb/gnuplotrb)
+[](https://gemnasium.com/github.com/SciRuby/gnuplotrb)
+[](https://travis-ci.org/SciRuby/gnuplotrb)
+[](https://codeclimate.com/github/SciRuby/gnuplotrb)
+[](https://codeclimate.com/github/SciRuby/gnuplotrb/coverage)
+
+## Table of contents
+* [Installation](https://github.com/sciruby/gnuplotrb#installation)
+* [Getting started](https://github.com/sciruby/gnuplotrb#getting-started)
+ - [Plottable classes](https://github.com/sciruby/gnuplotrb#plottable-classes)
+ - [Notebooks](https://github.com/sciruby/gnuplotrb#notebooks)
+ - [Plain examples](https://github.com/sciruby/gnuplotrb#plain-examples)
+* [Contributing](https://github.com/sciruby/gnuplotrb#contributing)
+
+## Installation
+### Dependencies
+* Ruby 2.0+
+* It is required to install [gnuplot 5.0](http://www.gnuplot.info/download.html) to use that gem.
+
+### Gem installation
+#### Install latest stable version from Rubygems
+
+```sh
+gem install gnuplotrb
+```
+
+#### Install latest stable version using bundler
+* add `gem gnuplotrb` to your `Gemfile`
+* run `bundle install`
+
+#### Install latest version from source (may be unstable)
+
+```sh
+git clone https://github.com/sciruby/gnuplotrb.git
+cd gnuplotrb
+bundle install
+rake install
+```
+
+## Getting started
+GnuplotRB gem is based on [Gnuplot](http://www.gnuplot.info/) so I would recommend to use [Gnuplot doc](http://www.gnuplot.info/docs_5.0/gnuplot.pdf) and [GnuplotRB doc at Rubydoc](https://rubygems.org/gems/gnuplotrb) in cases when docs and examples (as notebooks and plain examples) present here are not enough to explain how to plot something.
+
+### Plottable classes
+Each of plottable classes may be outputted to image file using ```#to_png```, ```#to_svg```, ```#to_gif``` and so on methods. You can read more about it in [GnuplotRB doc](https://rubygems.org/gems/gnuplotrb) related to Plottable module or see examples in [beginners
+notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/basic_usage.ipynb).
+
+#### Dataset
+Single dataset may be created with math formula ('sin(x)') or some data. If your data is stored in a file you can just pass a filename (e.g. 'gnuplotrb.data'). Dataset may also be constructed out of data contained in Ruby classes (Array, Daru containers), see [example notebooks](https://github.com/sciruby/gnuplotrb#possible-datasources).
+
+Dataset have several possible options which are explained in [gnuplot
+doc](http://www.gnuplot.info/docs_5.0/gnuplot.pdf) (pp. 80-102). Options are passed to Dataset.new as hash and are tranlated into gnuplot format before plotting:
+
+```ruby
+Dataset.new(data, with: 'lines', using: '1:2')
+```
+
+Examples of option translation (nested containers allowed):
+
+* Hash:
+
+```ruby
+{ key1: "value1", key2: { nested_key1: "nested_value1" } } # => "key1 value1 key2 nested key1 nested_value1"
+```
+
+* Hashes with underscored keys (see [#7](https://github.com/dilcom/gnuplotrb/issues/7)):
+
+```ruby
+{ style_data: 'histograms' } #=> "style data histograms"
+```
+
+* Range:
+
+```ruby
+{ xrange: 0..100 } # => "xrange [0:100]"
+```
+
+* Array (often used with nested hashes) and Array of Numeric
+
+```ruby
+['png', { size: [400, 500] }] # => "png size 400,500"
+```
+
+* Others
+
+```ruby
+some_object # => some_object.to_s
+```
+
+Once Dataset created, it may be updated with new data or options. Methods related to updating are explained in [a notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/updating_data.ipynb).
+
+Just as other Plottable object Dataset has several plotting methods which are desribed in [beginners notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/basic_usage.ipynb).
+
+#### Plot
+Plot is a container for several datasets and layout options:
+```ruby
+Plot.new(ds1, ds2, ds2, xrange: 1..10)
+```
+
+Datasets contained bu Plot are outputted on single xy plain.
+
+Plot's options are explained in [gnuplot doc](http://www.gnuplot.info/docs_5.0/gnuplot.pdf) (pp. 105-181). Plot options are translated into gnuplot format the same way as Dataset's (except adding 'set' before each option). Plot's datasets and Plot itself may be updated with almost the same methods as desribed in Dataset section above.
+
+#### Splot
+Almost the same as Plot but for 3-D plots. See Plot section.
+
+#### Multiplot
+
+Container for several Plot or Splot objects, each of them is plotted in its own xy(z) space. So Multiplot offers single layout (image filewindow) for several plots. It's grid is tuned by :layout option, and you can also set layout's title:
+```ruby
+Multiplot.new(plot1, plot2, splot1, layout: [3, 1], title: 'Three plots on a layout')
+```
+
+Updating methods for Multiplot are almost the same as Plot's and Dataset's and are covered in Multiplot's docs and [multiplot notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/multiplot_layout.ipynb). See examples there.
+
+#### Animation
+
+Animation is a container for several Plot, Splot or Multiplot objects. Each of contained items is considered as frame in gif animation which is creating by ```#plot``` call. Animation's frames and options may be modifyed or updated just as other classes above. Animation does not support methods like ```#to_png``` and may be plotted only with ```#plot``` method. Please see [related notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/animated_plots.ipynb) and docs at RubyDoc for examples.
+
+### Notebooks
+
+This notebooks are powered by [Ruby kernel](https://github.com/SciRuby/iruby/) for [IPython/Jupyter](https://jupyter.org/). I placed them here to show some GnuplotRB's capabilities and ways of using it together with iRuby.
+
+To use GnuplotRB gem with iRuby you need to install them both.
+
+* iRuby installation is covered in its [README](https://github.com/SciRuby/iruby/blob/master/README.md). It also covers installation of iPython and other dependecies.
+* GnuplotRB gem installation covered in [README](https://github.com/sciruby/gnuplotrb#installation) too.
+
+
+#### Embedding plots into iRuby
+Using GnuplotRB inside iRuby notebooks is covered in:
+
+* [Basic usage notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/basic_usage.ipynb).
+
+#### 2D and 3D plots
+GnuplotRB is capable to plot vast range of plots from histograms to 3D
+heatmaps. Gem's repository contains examples of several plot types:
+
+* [Heatmaps](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/heatmaps.ipynb)
+* [Vectorfield](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/vector_field.ipynb) (Thanks, [Alexej](https://github.com/agisga))
+* [Math equations](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/math_plots.ipynb)
+* [3D visualizations](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/3d_plot.ipynb)
+* [Histogram](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/histogram.ipynb)
+
+
+#### Possible datasources
+GnuplotRB may take data in Ruby container or in a file. Supported containers
+for now are `Array`, `Daru::Vector` and `Daru::DataFrame`. When data given in file,
+GnuplotRB pass filename to Gnuplot **without** reading the file into memory.
+
+Examples of using different datasources:
+
+* [Data given in file or Ruby Array](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/points_from_different_sources.ipynb)
+* [Data given in Daru containers](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/plotting_from_daru.ipynb)
+* [Data given in Daru containers (with timeseries)](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/time_series_from_daru.ipynb)
+* [Updating plots with new data](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/updating_data.ipynb)
+
+
+#### Multiplot
+You can not only plot several datasets in single coordinate system but place
+several coordinate systems on a canvas.
+
+* [Multiplot example notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/multiplot_layout.ipynb).
+
+#### Animation
+It's possible to use several plots (Plot, Splot or Multiplot objects) to create gif animation.
+
+* [Animation example notebook](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/animated_plots.ipynb).
+
+
+#### Fitting data with formula
+GnuplotRB also may be used to fit some data with given math formula.
+
+* [Fitting data](http://nbviewer.ipython.org/github/sciruby/gnuplotrb/blob/master/notebooks/fitting_data.ipynb)
+
+
+### Plain examples
+You may find several examples in [examples directory](https://github.com/sciruby/gnuplotrb/tree/master/examples).
+
+## Contributing
+
+1. [Fork repository](https://github.com/sciruby/gnuplotrb/fork)
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create a new Pull Request
+
diff --git a/README.rdoc b/README.rdoc
deleted file mode 100644
index 9e23585..0000000
--- a/README.rdoc
+++ /dev/null
@@ -1,163 +0,0 @@
-= GnuplotRB
-
-GnuplotRB is a plot generator for Ruby based on {Gnuplot}[http://www.gnuplot.info].
-
-This software has been developed as a product in Google Summer of Code 2015 (GSoC2015). Its progress may be saw in {SciRuby mailing list}[https://groups.google.com/forum/?fromgroups#!topic/sciruby-dev/lhWvb5hWc3k] or in {project's blog}[http://www.evgrafov.work/gnuplotrb/].
-
-{
}[https://rubygems.org/gems/gnuplotrb]
-
-{
}[https://gemnasium.com/dilcom/gnuplotrb]
-
-{
}[https://travis-ci.org/dilcom/gnuplotrb]
-{
}[https://codeclimate.com/github/dilcom/gnuplotrb]
-{
}[https://codeclimate.com/github/dilcom/gnuplotrb]
-
-== Table of contents
-* {Installation}[https://github.com/dilcom/gnuplotrb#installation]
-* {Getting started}[https://github.com/dilcom/gnuplotrb#getting-started]
- * {Plottable classes}[https://github.com/dilcom/gnuplotrb#plottable-classes]
- * {Notebooks}[https://github.com/dilcom/gnuplotrb#notebooks]
- * {Plain examples}[https://github.com/dilcom/gnuplotrb#plain-examples]
-* {Contributing}[https://github.com/dilcom/gnuplotrb#contributing]
-
-== Installation
-=== Dependencies
-* Ruby 2.0+
-* It is required to install {gnuplot 5.0}[http://www.gnuplot.info/download.html] to use that gem.
-=== Gem installation
-==== Install latest stable version from Rubygems
- gem install gnuplotrb
-==== Install latest stable version using bundler
-* add
- gem 'gnuplotrb'
- to your Gemfile
-* run
- bundle install
-==== Install latest version from source (may be unstable)
- git clone https://github.com/dilcom/gnuplotrb.git
- cd gnuplotrb
- bundle install
- rake install
-
-== Getting started
-
-GnuplotRB gem is based on {Gnuplot}[http://www.gnuplot.info/] so I would recommend to use {Gnuplot doc}[http://www.gnuplot.info/docs_5.0/gnuplot.pdf] and {GnuplotRB doc at Rubydoc}[https://rubygems.org/gems/gnuplotrb] in cases when docs and examples (as notebooks and plain examples) present here are not enough to explain how to plot something.
-
-=== Plottable classes
-
-Each of plottable classes may be outputted to image file using ```#to_png```, ```#to_svg```, ```#to_gif``` and so on methods. You can read more about it in {GnuplotRB doc}[https://rubygems.org/gems/gnuplotrb] related to Plottable module or see examples in {beginners notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/basic_usage.ipynb].
-
-==== Dataset
-Single dataset may be created with math formula ('sin(x)') or some data. If your data is stored in a file you can just pass a filename (e.g. 'gnuplotrb.data'). Dataset may also be constructed out of data contained in Ruby classes (Array, Daru containers), see {example notebooks}[https://github.com/dilcom/gnuplotrb#possible-datasources].
-
-Dataset have several possible options which are explained in {gnuplot doc}[http://www.gnuplot.info/docs_5.0/gnuplot.pdf] (pp. 80-102). Options are passed to Dataset.new as hash and are tranlated into gnuplot format before plotting:
- Dataset.new(data, with: 'lines', using: '1:2')
-Examples of option translation (nested containers allowed):
-* Hash:
- { key1: "value1", key2: { nested_key1: "nested_value1" } }
- # =>
- "key1 value1 key2 nested key1 nested_value1"
-* Hashes with underscored keys (see {#7}[https://github.com/dilcom/gnuplotrb/issues/7]):
- { style_data: 'histograms' }
- #=>
- "style data histograms"
-* Range:
- { xrange: 0..100 }
- # =>
- "xrange [0:100]"
-* Array (often used with nested hashes) and Array of Numeric
- ['png', { size: [400, 500] }]
- # =>
- "png size 400,500"
-* Others
- some_object
- # =>
- some_object.to_s
-
-Once Dataset created, it may be updated with new data or options. Methods related to updating are explained in {a notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/updating_data.ipynb].
-
-Just as other Plottable object Dataset has several plotting methods which are desribed in {beginners notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/basic_usage.ipynb].
-
-==== Plot
-Plot is a container for several datasets and layout options:
- Plot.new(ds1, ds2, ds2, xrange: 1..10)
-
-Datasets contained bu Plot are outputted on single xy plain.
-
-Plot's options are explained in {gnuplot doc}[http://www.gnuplot.info/docs_5.0/gnuplot.pdf] (pp. 105-181). Plot options are translated into gnuplot format the same way as Dataset's (except adding 'set' before each option). Plot's datasets and Plot itself may be updated with almost the same methods as desribed in Dataset section above.
-
-==== Splot
-Almost the same as Plot but for 3-D plots. See Plot section.
-
-==== Multiplot
-
-Container for several Plot or Splot objects, each of them is plotted in its own xy(z) space. So Multiplot offers single layout (image file\window) for several plots. It's grid is tuned by :layout option, and you can also set layout's title:
- Multiplot.new(plot1, plot2, splot1, layout: [3, 1], title: 'Three plots on a layout')
-
-Updating methods for Multiplot are almost the same as Plot's and Dataset's and are covered in Multiplot's docs and {multiplot notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/multiplot_layout.ipynb]. See examples there.
-
-==== Animation
-
-Animation is a container for several Plot, Splot or Multiplot objects. Each of contained items is considered as frame in gif animation which is creating by ```#plot``` call. Animation's frames and options may be modifyed or updated just as other classes above. Animation does not support methods like ```#to_png``` and may be plotted only with ```#plot``` method. Please see {related notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/animated_plots.ipynb] and docs at RubyDoc for examples.
-
-=== Notebooks
-
-This notebooks are powered by {Ruby kernel}[https://github.com/SciRuby/iruby/] for {IPython/Jupyter}[https://jupyter.org/].
-I placed them here to show some GnuplotRB's capabilities and ways of using it together with iRuby.
-
-To use GnuplotRB gem with iRuby you need to install them both.
-
-* iRuby installation is covered in its {README}[https://github.com/SciRuby/iruby/blob/master/README.md].
- It also covers installation of iPython and other dependecies.
-* GnuplotRB gem installation covered in {README}[https://github.com/dilcom/gnuplotrb#installation] too.
-
-==== Embedding plots into iRuby
-Using GnuplotRB inside iRuby notebooks is covered in:
-
-* {Basic usage notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/basic_usage.ipynb].
-
-==== 2D and 3D plots
-GnuplotRB is capable to plot vast range of plots from histograms to 3D heatmaps. Gem's repository contains examples of several plot types:
-
-* {Heatmaps}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/heatmaps.ipynb]
-* {Vector field}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/vector_field.ipynb] (Thanks, {Alexej}[https://github.com/agisga])
-* {Math equations}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/math_plots.ipynb]
-* {3D visualizations}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/3d_plot.ipynb]
-* {Histogram}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/histogram.ipynb]
-
-==== Possible datasources
-GnuplotRB may take data in Ruby container or in a file. Supported containers for now are Arrays, Daru::Vector and Daru::DataFrame.
-When data given in file, GnuplotRB pass filename to Gnuplot *without* reading the file into memory.
-
-Examples of using different datasources:
-
-* {Data given in file or Ruby Array}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/points_from_different_sources.ipynb]
-* {Data given in Daru containers}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/plotting_from_daru.ipynb]
-* {Data given in Daru containers (with timeseries)}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/time_series_from_daru.ipynb]
-* {Updating plots with new data}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/updating_data.ipynb]
-
-==== Multiplot
-You can not only plot several datasets in single coordinate system but place several coordinate systems on a canvas.
-
-* {Multiplot example notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/multiplot_layout.ipynb].
-
-==== Animation
-It's possible to use several plots (Plot, Splot or Multiplot objects) to create gif animation.
-
-* {Animation example notebook}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/animated_plots.ipynb].
-
-==== Fitting data with formula
-GnuplotRB also may be used to fit some data with given math formula.
-
-* {Fitting data}[http://nbviewer.ipython.org/github/dilcom/gnuplotrb/blob/master/notebooks/fitting_data.ipynb]
-
-=== Plain examples
-You may find several examples in {examples directory}[https://github.com/dilcom/gnuplotrb/tree/master/examples].
-
-== Contributing
-
-1. {Fork repository}[https://github.com/dilcom/gnuplotrb/fork]
-2. Create your feature branch (`git checkout -b my-new-feature`)
-3. Commit your changes (`git commit -am 'Add some feature'`)
-4. Push to the branch (`git push origin my-new-feature`)
-5. Create a new Pull Request
diff --git a/Rakefile b/Rakefile
index 2650165..2c66f8f 100644
--- a/Rakefile
+++ b/Rakefile
@@ -6,11 +6,11 @@ require 'rubocop/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb'].uniq
- spec.rspec_opts = '--format documentation'
+ spec.rspec_opts = '--format documentation --color'
end
YARD::Rake::YardocTask.new(:doc) do |t|
- t.files = %w(README.rdoc lib) # optional
+ t.files = %w(README.md lib) # optional
end
RuboCop::RakeTask.new(:cop)
diff --git a/gnuplotrb.gemspec b/gnuplotrb.gemspec
index 236cee4..d562580 100644
--- a/gnuplotrb.gemspec
+++ b/gnuplotrb.gemspec
@@ -11,14 +11,14 @@ Gem::Specification.new do |spec|
spec.summary = 'Ruby bindings for gnuplot'
spec.description = 'Renewed ruby bindings for gnuplot. Started at GSoC 2015.'
- spec.homepage = 'https://github.com/dilcom/gnuplotrb'
+ spec.homepage = 'https://github.com/SciRuby/gnuplotrb'
spec.license = 'MIT'
spec.required_ruby_version = '>= 2.0'
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(/^(test|spec|unimplemented_features|examples|future_work|notebooks|\..+)/) }
spec.require_paths = ['lib']
- spec.add_runtime_dependency 'hamster', '~> 1.0'
+ spec.add_runtime_dependency 'hamster', '~> 3.0'
spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.2'
@@ -26,5 +26,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rubocop', '~> 0.29'
spec.add_development_dependency 'codeclimate-test-reporter'
spec.add_development_dependency 'chunky_png'
+ spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'daru'
end
diff --git a/lib/gnuplotrb.rb b/lib/gnuplotrb.rb
index d1e0731..a20f7f7 100644
--- a/lib/gnuplotrb.rb
+++ b/lib/gnuplotrb.rb
@@ -19,6 +19,8 @@ def require_if_available(name)
require 'gnuplotrb/external_classes/string'
require 'gnuplotrb/external_classes/array'
require 'gnuplotrb/external_classes/daru'
+require 'gnuplotrb/external_classes/dir'
+
require 'gnuplotrb/version'
require 'gnuplotrb/staff/settings'
diff --git a/lib/gnuplotrb/animation.rb b/lib/gnuplotrb/animation.rb
index 932d765..88b340e 100644
--- a/lib/gnuplotrb/animation.rb
+++ b/lib/gnuplotrb/animation.rb
@@ -58,7 +58,7 @@ def plot(path = nil, **options)
plot_opts.merge(term: ['gif', anim_opts])
end.to_h
need_output = plot_options[:output].nil?
- plot_options[:output] = Dir::Tmpname.make_tmpname('anim', 0) if need_output
+ plot_options[:output] = Dir.gnuplot_tmpname('anim') if need_output
terminal = Terminal.new
multiplot(terminal, plot_options)
# guaranteed wait for plotting to finish
diff --git a/lib/gnuplotrb/external_classes/dir.rb b/lib/gnuplotrb/external_classes/dir.rb
new file mode 100644
index 0000000..2143ff9
--- /dev/null
+++ b/lib/gnuplotrb/external_classes/dir.rb
@@ -0,0 +1,9 @@
+##
+# Utility methods for GnuplotRB.
+class Dir
+ # @return temporary file name
+ def self.gnuplot_tmpname(name)
+ t = Time.now.strftime('%Y%m%d')
+ "#{Dir.tmpdir}/gnuplotrb-#{name}-#{t}-#{$PID}-#{rand(0x100000000).to_s(36)}"
+ end
+end
diff --git a/lib/gnuplotrb/mixins/plottable.rb b/lib/gnuplotrb/mixins/plottable.rb
index 18ad3b3..9b0f98b 100644
--- a/lib/gnuplotrb/mixins/plottable.rb
+++ b/lib/gnuplotrb/mixins/plottable.rb
@@ -65,7 +65,7 @@ def method_missing(meth_id, *args)
# @return [true] for existing methods and
# #to_|term_name| when name is a valid terminal type.
# @return [false] otherwise
- def respond_to?(meth_id)
+ def respond_to?(meth_id, include_all=false)
# Next line is here to force iRuby use #to_iruby
# instead of #to_svg.
return super if defined? IRuby
@@ -110,7 +110,7 @@ def to_specific_term(terminal, path = nil, **options)
if path
result = plot(term: [terminal, options], output: path)
else
- path = Dir::Tmpname.make_tmpname(terminal, 0)
+ path = Dir.gnuplot_tmpname(terminal)
plot(term: [terminal, options], output: path)
result = File.binread(path)
File.delete(path)
diff --git a/lib/gnuplotrb/multiplot.rb b/lib/gnuplotrb/multiplot.rb
index f47f30f..9f06017 100644
--- a/lib/gnuplotrb/multiplot.rb
+++ b/lib/gnuplotrb/multiplot.rb
@@ -26,7 +26,7 @@ class Multiplot
# @param options [Hash] see options in top class docs
def initialize(*plots, **options)
@plots = plots[0].is_a?(Hamster::Vector) ? plots[0] : Hamster::Vector.new(plots)
- @options = Hamster.hash(options)
+ @options = Hamster::Hash[options]
OptionHandling.validate_terminal_options(@options)
yield(self) if block_given?
end
diff --git a/lib/gnuplotrb/plot.rb b/lib/gnuplotrb/plot.rb
index e5d14e1..1fb46f6 100644
--- a/lib/gnuplotrb/plot.rb
+++ b/lib/gnuplotrb/plot.rb
@@ -49,9 +49,9 @@ def initialize(*datasets)
# had to relace **options arg with this because in some cases
# Daru::DataFrame was mentioned as hash and added to options
# instead of plots
- @options = Hamster.hash
+ @options = Hamster::Hash.empty
if datasets[-1].is_a?(Hamster::Hash) || datasets[-1].is_a?(Hash)
- @options = Hamster.hash(datasets[-1])
+ @options = Hamster::Hash[datasets[-1]]
datasets = datasets[0..-2]
end
@datasets = parse_datasets_array(datasets)
@@ -284,6 +284,7 @@ def parse_datasets_array(datasets)
when Hamster::Vector
datasets[0]
when (defined?(Daru) ? Daru::DataFrame : nil)
+ set_name_from_daru_dataframe(datasets[0])
Hamster::Vector.new(datasets[0].map { |ds| dataset_from_any(ds) })
else
Hamster::Vector.new(datasets.map { |ds| dataset_from_any(ds) })
@@ -295,5 +296,9 @@ def parse_datasets_array(datasets)
def new_with_options(options)
self.class.new(@datasets, options)
end
+
+ def set_name_from_daru_dataframe(dataframe)
+ self.title = dataframe.name unless title
+ end
end
end
diff --git a/lib/gnuplotrb/staff/datablock.rb b/lib/gnuplotrb/staff/datablock.rb
index 2794ca6..3022a54 100644
--- a/lib/gnuplotrb/staff/datablock.rb
+++ b/lib/gnuplotrb/staff/datablock.rb
@@ -13,7 +13,7 @@ def initialize(data, stored_in_file = false)
@stored_in_file = stored_in_file
data_str = data.to_gnuplot_points
if @stored_in_file
- @file_name = Dir::Tmpname.make_tmpname('tmp_data', 0)
+ @file_name = Dir.gnuplot_tmpname('tmp_data')
File.write(@file_name, data_str)
name = File.join(Dir.pwd, @file_name)
ObjectSpace.define_finalizer(self, proc { File.delete(name) })
diff --git a/lib/gnuplotrb/staff/dataset.rb b/lib/gnuplotrb/staff/dataset.rb
index a9be269..5bd5f8e 100644
--- a/lib/gnuplotrb/staff/dataset.rb
+++ b/lib/gnuplotrb/staff/dataset.rb
@@ -234,7 +234,7 @@ def new_with_options(options)
# Initialize Dataset from given String
def init_string(data, options)
@type, @data = File.exist?(data) ? [:datafile, "'#{data}'"] : [:math_function, data.clone]
- @options = Hamster.hash(options)
+ @options = Hamster::Hash[options]
end
##
@@ -242,14 +242,16 @@ def init_string(data, options)
def init_dblock(data, options)
@type = :datablock
@data = data.clone
- @options = Hamster.hash(options)
+ @options = Hamster::Hash[options]
end
##
# Create new value for 'using' option based on column count
def get_daru_columns(data, cnt)
new_opt = (2..cnt).to_a.join(':')
- if data.index[0].is_a?(DateTime) || data.index[0].is_a?(Numeric)
+ # check if DateTimeIndex. If not, assume it is Daru::Index and check for
+ # numeric value in the index.
+ if data.index.instance_of?(Daru::DateTimeIndex) || data.index.first[0].is_a?(Numeric)
"1:#{new_opt}"
else
"#{new_opt}:xtic(1)"
@@ -288,7 +290,7 @@ def init_daru_vector(data, options)
def init_default(data, file: false, **options)
@type = :datablock
@data = Datablock.new(data, file)
- @options = Hamster.hash(options)
+ @options = Hamster::Hash[options]
end
end
end
diff --git a/lib/gnuplotrb/staff/settings.rb b/lib/gnuplotrb/staff/settings.rb
index 86e2fb8..147273f 100644
--- a/lib/gnuplotrb/staff/settings.rb
+++ b/lib/gnuplotrb/staff/settings.rb
@@ -7,6 +7,8 @@ module Settings
MIN_GNUPLOT_VERSION = 5.0
class << self
+ DEFAULT_MAX_FIT_DELAY = 5
+ DEFAULT_GNUPLOT_PATH = 'gnuplot'
##
# For heavy calculations max_fit_delay may be increased.
attr_writer :max_fit_delay
@@ -18,7 +20,7 @@ class << self
# this behaviour is considered as errorneus.
# @return [Integer] seconds to wait for output
def max_fit_delay
- @max_fit_delay ||= 5
+ @max_fit_delay ||= DEFAULT_MAX_FIT_DELAY
end
##
@@ -26,7 +28,7 @@ def max_fit_delay
# Default value: 'gnuplot'.
# @return [String] path to gnuplot executable
def gnuplot_path
- self.gnuplot_path = 'gnuplot' unless defined?(@gnuplot_path)
+ self.gnuplot_path = DEFAULT_GNUPLOT_PATH unless defined?(@gnuplot_path)
@gnuplot_path
end
@@ -72,8 +74,15 @@ def validate_version(path)
.read
.match(/gnuplot ([^ ]+)/)[1]
.to_f
- message = "Your Gnuplot version is #{@version}, please update it to at least 5.0"
- fail(ArgumentError, message) if @version < MIN_GNUPLOT_VERSION
+ raise(
+ ArgumentError,
+ "Your Gnuplot version is #{@version}, please update it to at least 5.0"
+ ) if @version < MIN_GNUPLOT_VERSION
+ rescue Errno::ENOENT
+ raise(
+ ArgumentError,
+ "Can't find Gnuplot executable. Please make sure it's installed and added to PATH."
+ )
end
end
end
diff --git a/lib/gnuplotrb/version.rb b/lib/gnuplotrb/version.rb
index ac3225f..277b88b 100644
--- a/lib/gnuplotrb/version.rb
+++ b/lib/gnuplotrb/version.rb
@@ -4,5 +4,5 @@
module GnuplotRB
##
# Gem version
- VERSION = '0.3.1'
+ VERSION = '0.4.0'.freeze
end
diff --git a/spec/animation_spec.rb b/spec/animation_spec.rb
index e06b32a..10f7fdf 100644
--- a/spec/animation_spec.rb
+++ b/spec/animation_spec.rb
@@ -33,7 +33,7 @@
context 'option handling' do
before do
- @options = Hamster.hash(title: 'GnuplotRB::Animation', yrange: 0..3)
+ @options = Hamster::Hash[title: 'GnuplotRB::Animation', yrange: 0..3]
@anim = Animation.new(**@options)
end
diff --git a/spec/dataset_spec.rb b/spec/dataset_spec.rb
index a4c6524..e49347d 100644
--- a/spec/dataset_spec.rb
+++ b/spec/dataset_spec.rb
@@ -104,7 +104,7 @@
context 'options handling' do
before do
- @options = Hamster.hash(title: 'GnuplotRB::Dataset', with: 'lines')
+ @options = Hamster::Hash[title: 'GnuplotRB::Dataset', with: 'lines']
@dataset = Dataset.new('sin(x)', @options)
end
@@ -124,7 +124,7 @@
end
it 'should allow to safely set several options at once' do
- new_options = Hamster.hash(title: 'Some new title', with: 'lines', lt: 3)
+ new_options = Hamster::Hash[title: 'Some new title', with: 'lines', lt: 3]
new_dataset = @dataset.options(new_options)
@options.each { |key, value| expect(@dataset.send(key)).to eql(value) }
new_options.each { |key, value| expect(new_dataset.send(key)).to eql(value) }
@@ -136,7 +136,7 @@
x = (0..10).to_a
y = x.map { |xx| Math.exp(-xx) }
@data = [x, y]
- @options = Hamster.hash(title: 'GnuplotRB::Dataset', with: 'lines')
+ @options = Hamster::Hash[title: 'GnuplotRB::Dataset', with: 'lines']
@sinx = Dataset.new('sin(x)', @options)
@dataset = Dataset.new([x, y])
@temp_file_dataset = Dataset.new([x, y], file: true)
@@ -144,7 +144,7 @@
it 'should update options' do
# works just as Dataset#options(...)
- new_options = Hamster.hash(title: 'Some new title', with: 'lines', lt: 3)
+ new_options = Hamster::Hash[title: 'Some new title', with: 'lines', lt: 3]
new_dataset = @sinx.update(new_options)
@options.each { |key, value| expect(@sinx.send(key)).to eql(value) }
new_options.each { |key, value| expect(new_dataset.send(key)).to eql(value) }
diff --git a/spec/multiplot_spec.rb b/spec/multiplot_spec.rb
index 14465c8..d090705 100644
--- a/spec/multiplot_spec.rb
+++ b/spec/multiplot_spec.rb
@@ -33,7 +33,7 @@
context 'option handling' do
before do
- @options = Hamster.hash(title: 'GnuplotRB::Multiplot', yrange: 0..3)
+ @options = Hamster::Hash[title: 'GnuplotRB::Multiplot', yrange: 0..3]
@mp = Multiplot.new(**@options)
end
diff --git a/spec/plot_spec.rb b/spec/plot_spec.rb
index fdc78a7..41f6a7b 100644
--- a/spec/plot_spec.rb
+++ b/spec/plot_spec.rb
@@ -16,11 +16,6 @@
@title = 'Awesome spec'
@formula = %w(sin(x) cos(x) exp(-x))
@options = { title: @title, term: 'dumb' }
- @df = Daru::DataFrame.new(
- Build: [312, 630, 315, 312],
- Test: [525, 1050, 701, 514],
- Deploy: [215, 441, 370, 220]
- )
end
it 'should be created out of sequence of datasets' do
@@ -38,16 +33,44 @@
expect(plot.title).to eql(@title)
end
- it 'should be created out of Daru::DataFrame' do
- p = Plot.new(@df)
- expect(p).to be_an_instance_of(Plot)
- expect(p.datasets.size).to be_eql(3)
+ context 'creation out of Daru::DataFrame' do
+ let(:df) do
+ Daru::DataFrame.new(
+ {
+ Build: [312, 630, 315, 312],
+ Test: [525, 1050, 701, 514],
+ Deploy: [215, 441, 370, 220]
+ },
+ index: [0, 1, 2, 3],
+ name: 'Dummy DataFrame'
+ )
+ end
+
+ subject { Plot.new(df) }
+
+ it { is_expected.to be_an_instance_of Plot }
+
+ it 'creates datasets for each column except index' do
+ expect(subject.datasets.size).to be 3
+ end
+
+ it 'takes name for plot from DataFrame' do
+ expect(subject.title).to eql(df.name)
+ end
+
+ context 'with title option given' do
+ subject { Plot.new(df, title: 'Not a DataFrame') }
+
+ it "uses title option instead of DataFrame name" do
+ expect(subject.title).not_to eql(df.name)
+ end
+ end
end
end
context 'options handling' do
before do
- @options = Hamster.hash(title: 'GnuplotRB::Plot', yrange: 0..3)
+ @options = Hamster::Hash[title: 'GnuplotRB::Plot', yrange: 0..3]
@plot = Plot.new(**@options)
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 9b2c881..7642e57 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,12 +1,11 @@
require 'simplecov'
-require 'codeclimate-test-reporter'
require 'digest'
require 'chunky_png'
require 'digest/md5'
-SimpleCov.add_filter 'vendor'
-SimpleCov.add_filter 'examples'
-SimpleCov.formatter = CodeClimate::TestReporter::Formatter
-SimpleCov.start CodeClimate::TestReporter.configuration.profile
+
+SimpleCov.start do
+ add_filter 'examples'
+end
require 'gnuplotrb'
diff --git a/spec/splot_spec.rb b/spec/splot_spec.rb
index 2089612..492c18a 100644
--- a/spec/splot_spec.rb
+++ b/spec/splot_spec.rb
@@ -27,7 +27,7 @@
context 'options handling' do
before do
- @options = Hamster.hash(title: 'GnuplotRB::Plot', yrange: 0..3)
+ @options = Hamster::Hash[title: 'GnuplotRB::Plot', yrange: 0..3]
@plot = Splot.new(**@options)
end