gnuplot-multiplot 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b4c0653c1594f2ae3242908f8170dbd8b6ffa861
4
+ data.tar.gz: 7b7df0ec132ddd21fc57277c857e4e5954f9a904
5
+ SHA512:
6
+ metadata.gz: 7d918578d37d13808ae03b1922c22285b08da6553d270c908b30bb0e88e4fc4ced6caffbc9fa908281a173287b46b3863b6e4e16e247b809d3ef1c622f413de9
7
+ data.tar.gz: 264ae370989eb1b9207af59c78d6f2bd3ed740d43c6d54bcf44d2290120175767c8ee719f7a00939be823c71fc0b3fa519c881557549d480445d662f713ab29c
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gnuplot-multiplot.gemspec
4
+ gemspec
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2014 Brigham Young University
2
+ author: John T. Prince
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # Gnuplot::Multiplot
2
+
3
+ Enhances the gnuplot gem with a simple interface to multiplot functionality.
4
+
5
+ ## Installation
6
+
7
+ gem install gnuplot-multiplot
8
+
9
+ gnuplot-multiplot includes gnuplot as a dependency, so you get both if you
10
+ install the multiplot gem.
11
+
12
+ ## Examples
13
+
14
+ ```ruby
15
+ require 'gnuplot/multiplot'
16
+
17
+ x = (0..50).collect { |v| v.to_f }
18
+ mult2 = x.map {|v| v * 2 }]
19
+ squares = x.map {|v| v * 4 }
20
+
21
+ Gnuplot.open do |gp|
22
+ Gnuplot::Multiplot.new(gp, layout: [2,1]) do |mp|
23
+ Gnuplot::Plot.new(mp) do |plot|
24
+ plot.data << Gnuplot::DataSet.new( [x, mult2] )
25
+ end
26
+
27
+ Gnuplot::Plot.new(mp) do |plot|
28
+ plot.data << Gnuplot::DataSet.new( [x, squares] )
29
+ end
30
+ end
31
+ end
32
+ ```
33
+
34
+ Options for multiplot may also be passed in as a gnuplot-ready String:
35
+
36
+ ```ruby
37
+ Gnuplot::Multiplot.new(gp, %Q{layout 2,1 title "some title"}) do |mp|
38
+ ...
39
+ end
40
+ ```
41
+
42
+ ## Options
43
+
44
+ title: String,
45
+ font: String (fontspec),
46
+ enhanced: true/false, # noenhanced if false
47
+ layout: [num_rows,num_cols],
48
+ rowsfirst: true/false, # columnsfirst if false
49
+ downwards: true/false, # upwards if false
50
+ scale: Float (xscale) || [Float (xscale), Float (yscale)],
51
+ offset: Float (xoffset) || [Float (xoffset), Float (yoffset)],
52
+
53
+ ## An inconsistent inferface?
54
+
55
+ The gnuplot gem is very object oriented. Virtually no options are passed in
56
+ using a hash, as done here with multiplot. To be consistent with the gnuplot
57
+ gem the various properties of multiplot should probably be set as attributes
58
+ similar to Gnuplot::DataSet. However, given how gnuplot is currently
59
+ implemented, it would require several hacks to achieve (e.g., the first Plot
60
+ called would need to prompt the multiplot object to issue its commands). This
61
+ gem's interface, while not as consistent with the current gnuplot gem as one
62
+ might like, is simple and minimally invasive. To build something more
63
+ consistent with the current gnuplot interface would require a rewrite of
64
+ gnuplot, IMHO.
65
+
66
+ ## Why not just pipe in the multiplot commands directly?
67
+
68
+ It's not hard to pipe in your own commands for a multiplot (it's even uglier
69
+ than this interface, of course), but you still have to alter the default
70
+ behavior of Plot.new to add in the necessary newlines between plots. This gem
71
+ takes care of those necessary newlines.
72
+
73
+ ## Copying
74
+
75
+ MIT License (see LICENSE)
@@ -0,0 +1,19 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ end
8
+
9
+ task :default => :spec
10
+
11
+ require 'rdoc/task'
12
+ Rake::RDocTask.new do |rdoc|
13
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
14
+
15
+ rdoc.rdoc_dir = 'rdoc'
16
+ rdoc.title = "rubabel #{version}"
17
+ rdoc.rdoc_files.include('README*')
18
+ rdoc.rdoc_files.include('lib/**/*.rb')
19
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gnuplot/multiplot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gnuplot-multiplot"
8
+ spec.version = Gnuplot::Multiplot::VERSION
9
+ spec.authors = ["John T. Prince"]
10
+ spec.email = ["jtprince@gmail.com"]
11
+ spec.summary = %q{multiplot for the gnuplot gem}
12
+ spec.description = %q{simple multiplot interface to enhance the gnuplot gem}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ [
22
+ ["gnuplot", "~> 2.6.2"],
23
+ ].each do |args|
24
+ spec.add_dependency(*args)
25
+ end
26
+
27
+ [
28
+ ["bundler", "~> 1.5.3"],
29
+ ["rake"],
30
+ ["rspec", "~> 2.14.1"],
31
+ ["rdoc", "~> 4.1.0"],
32
+ ["simplecov", "~> 0.8.2"],
33
+ ].each do |args|
34
+ spec.add_development_dependency(*args)
35
+ end
36
+
37
+ end
@@ -0,0 +1,52 @@
1
+ require "gnuplot/multiplot/version"
2
+ require 'gnuplot'
3
+
4
+ module Gnuplot
5
+ module MultiplotBehavior
6
+ def initialize(io = nil, cmd = "plot")
7
+ reply = super(io, cmd)
8
+ io << "\n"
9
+ reply
10
+ end
11
+ end
12
+ class Plot
13
+ prepend MultiplotBehavior
14
+ end
15
+ end
16
+
17
+ module Gnuplot
18
+
19
+ class Multiplot
20
+ NEGATIVE_BOOLEANS = {
21
+ enhanced: :noenhanced,
22
+ rowsfirst: :columnsfirst,
23
+ downwards: :upwards,
24
+ }
25
+
26
+ def initialize(gnuplot, opts={}, &block)
27
+ string =
28
+ if opts.is_a?(Hash)
29
+ opts.map {|key, val|
30
+ if NEGATIVE_BOOLEANS.has_key?(key)
31
+ val ? key : NEGATIVE_BOOLEANS[key]
32
+ else
33
+ pair =
34
+ if val.is_a?(Array)
35
+ [key, val.join(", ")]
36
+ elsif key == :title
37
+ [key, "\"#{val}\""]
38
+ else
39
+ [key, val]
40
+ end
41
+ pair.join(" ")
42
+ end
43
+ }.join(" ")
44
+ else
45
+ opts
46
+ end
47
+ gnuplot << "set multiplot " << string << "\n"
48
+ block.call(gnuplot)
49
+ gnuplot << "unset multiplot\n"
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module Gnuplot
2
+ class Multiplot
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+ require 'gnuplot/multiplot'
3
+ require 'stringio'
4
+
5
+ class String
6
+ def unindent
7
+ gsub(/^#{scan(/^\s*/).min_by{|l|l.length}}/, "")
8
+ end
9
+ end
10
+
11
+ describe Gnuplot::Multiplot do
12
+ describe 'with a simple dataset' do
13
+ let(:xs) { (3..4).collect { |v| v.to_f } }
14
+ let(:ys) do
15
+ { mult2: xs.map {|v| v * 2 },
16
+ square: xs.map {|v| v ** 2 },
17
+ }
18
+ end
19
+ let(:expected) {
20
+ <<-OUTPUT.unindent
21
+ set multiplot layout 2, 1 title "one title to rule them all"
22
+ set title "mult2"
23
+ plot '-' notitle
24
+ 3.0 6.0
25
+ 4.0 8.0
26
+ e
27
+ set title "square"
28
+ plot '-' notitle
29
+ 3.0 9.0
30
+ 4.0 16.0
31
+ e
32
+ unset multiplot
33
+ OUTPUT
34
+ }
35
+
36
+ describe 'simple plot' do
37
+ it 'uses hash options' do
38
+ gp = StringIO.new
39
+ Gnuplot::Multiplot.new(gp, layout: [2,1], title: "one title to rule them all", ) do |mp|
40
+ %i{mult2 square}.each do |response|
41
+ Gnuplot::Plot.new(mp) do |plot|
42
+ plot.title response
43
+ plot.data << Gnuplot::DataSet.new( [xs, ys[response]] ) {|ds| ds.notitle }
44
+ end
45
+ end
46
+ end
47
+
48
+ gp.rewind
49
+ expect(gp.string).to eq expected
50
+ end
51
+
52
+ it 'uses string options' do
53
+ gp = StringIO.new
54
+ Gnuplot::Multiplot.new(gp, "layout 2, 1 title \"one title to rule them all\"" ) do |mp|
55
+ %i{mult2 square}.each do |response|
56
+ Gnuplot::Plot.new(mp) do |plot|
57
+ plot.title response
58
+ plot.data << Gnuplot::DataSet.new( [xs, ys[response]] ) {|ds| ds.notitle }
59
+ end
60
+ end
61
+ end
62
+
63
+ gp.rewind
64
+ expect(gp.string).to eq expected
65
+ end
66
+ end
67
+ end
68
+
69
+
70
+ xit 'plots a stacked plot demo (from gnuplot demo site)' do
71
+ params = {
72
+ boxwidth: "0.3 absolute",
73
+ style: "fill solid 1.00 border",
74
+ tmargin: 0,
75
+ bmargin: 0,
76
+ lmargin: 3,
77
+ rmargin: 3,
78
+ yrange: "[0 : 10]",
79
+ key: "autotitle column nobox samplen 1 noenhanced",
80
+ style: "data boxes",
81
+ xtics: "nomirror",
82
+ tics: "scale 0 font \",8\"",
83
+ }
84
+ unset = %w{xtics ytics title}
85
+ data = { Hungary: [3,10,8,7], Germany: [2,1,1,8,1], UK: [2,9,3,3] }
86
+
87
+ Gnuplot.open do |gp|
88
+ Gnuplot::Multiplot.new(gp, layout: [4,1], title: "Auto-layout of stacked plots") do |mp|
89
+ data.each do |country, ydata|
90
+ Gnuplot::Plot.new(gp) do |plot|
91
+ params.each do |pair|
92
+ plot.set(*pair)
93
+ end
94
+ unset.each {|val| plot.unset(val) }
95
+ if country == data.keys.last
96
+ plot.xlabel "Immigration to U.S. by Decade"
97
+ plot.xtics %w(1900-1909 1910-1919 1920-infinity booyah).each_with_index.map {|v,i| "\"#{v}\" #{i}" }.join(", ")
98
+
99
+ end
100
+
101
+ plot.data << Gnuplot::DataSet.new( [[0,1,2,3], ydata] ) do |ds|
102
+ ds.title = country
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+
@@ -0,0 +1,25 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rspec'
5
+
6
+ require 'rspec/core/formatters/progress_formatter'
7
+ # doesn't say so much about pending guys
8
+ class QuietPendingFormatter < RSpec::Core::Formatters::ProgressFormatter
9
+ def example_pending(example)
10
+ output.print pending_color('*')
11
+ end
12
+ end
13
+
14
+ require 'rspec/core/formatters/documentation_formatter'
15
+ class QuietPendingDocFormatter < RSpec::Core::Formatters::DocumentationFormatter
16
+ def example_pending(example)
17
+ output.puts pending_color( "<pending>: #{example.execution_result[:pending_message]}" )
18
+ end
19
+ end
20
+
21
+ RSpec.configure do |config|
22
+ config.treat_symbols_as_metadata_keys_with_true_values = true
23
+ config.formatter = QuietPendingDocFormatter
24
+ config.color = true
25
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gnuplot-multiplot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John T. Prince
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gnuplot
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.6.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.6.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.8.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.8.2
97
+ description: simple multiplot interface to enhance the gnuplot gem
98
+ email:
99
+ - jtprince@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - gnuplot-multiplot.gemspec
110
+ - lib/gnuplot/multiplot.rb
111
+ - lib/gnuplot/multiplot/version.rb
112
+ - spec/gnuplot/multiplot_spec.rb
113
+ - spec/spec_helper.rb
114
+ homepage: ''
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.2.2
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: multiplot for the gnuplot gem
138
+ test_files:
139
+ - spec/gnuplot/multiplot_spec.rb
140
+ - spec/spec_helper.rb