From 6593ef7cf347078ec30edcbe4f5dff7dd7d4ffd7 Mon Sep 17 00:00:00 2001 From: Renat Arifulov Date: Thu, 2 Feb 2012 15:48:21 +0400 Subject: [PATCH 01/79] Fixed using SPlot with a function wroted by string --- examples/3d_surface_plot.rb | 13 +++++++++++++ lib/gnuplot.rb | 26 +++++++++++--------------- 2 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 examples/3d_surface_plot.rb diff --git a/examples/3d_surface_plot.rb b/examples/3d_surface_plot.rb new file mode 100644 index 0000000..2cd7f7a --- /dev/null +++ b/examples/3d_surface_plot.rb @@ -0,0 +1,13 @@ +require "gnuplot" + +Gnuplot.open do |gp| + Gnuplot::SPlot.new( gp ) do |plot| + plot.grid + + plot.data = [ + Gnuplot::DataSet.new( "x**2+y**2" ) do |ds| + ds.with = "pm3d" + end + ] + end +end diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index 24bec17..17f0533 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -91,8 +91,12 @@ def initialize (io = nil, cmd = "plot") @arbitrary_lines = [] @data = [] yield self if block_given? - puts "writing this to gnuplot:\n" + to_gplot + "\n" if $VERBOSE - io << to_gplot if io + puts "writing this to gnuplot:\n" + to_gplot + "\n" if $VERBOSE + + if io + io << to_gplot + io << store_datasets + end end attr_accessor :arbitrary_lines @@ -137,15 +141,17 @@ def to_gplot (io = "") @sets.each { |var, val| io << "set #{var} #{val}\n" } @arbitrary_lines.each{|line| io << line << "\n" } - if @data.size > 0 then + io + end + + def store_datasets (io = "") + if @data.size > 0 io << @cmd << " " << @data.collect { |e| e.plot_args }.join(", ") io << "\n" v = @data.collect { |ds| ds.to_gplot } io << v.compact.join("e\n") end - - io end end @@ -158,16 +164,6 @@ def initialize (io = nil, cmd = "splot") def to_gplot (io = "") @sets.each { |var, val| io << "set #{var} #{val}\n" } - if @data.size > 0 then - io << @cmd << " " - io << @data.collect { |e| e.plot_args }.join(", ") - io << "\n" - - @data.each do |ds| - io << ds.to_gsplot << "e\n" - end - end - io end From 9b12430b207827e4b2ab1ae670b61b9ec0022e36 Mon Sep 17 00:00:00 2001 From: Renat Arifulov Date: Fri, 3 Feb 2012 11:57:05 +0400 Subject: [PATCH 02/79] forget return io variable in the method store_datasets --- lib/gnuplot.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index 17f0533..f21b047 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -152,6 +152,8 @@ def store_datasets (io = "") v = @data.collect { |ds| ds.to_gplot } io << v.compact.join("e\n") end + + io end end From d61d6fd820a71d1f6adbaac1f378b21abdc417d1 Mon Sep 17 00:00:00 2001 From: rogerdpack Date: Tue, 20 Mar 2012 12:30:57 -0600 Subject: [PATCH 03/79] yea finally fixed --- Rakefile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Rakefile b/Rakefile index 44be56f..1a4e590 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,3 @@ -begin - require 'psych' # boo -rescue ::LoadError -end - require 'jeweler' Jeweler::Tasks.new do |s| s.name = 'gnuplot' From e18e3f38d0faf2275e96c2cb97e87afe33bf582f Mon Sep 17 00:00:00 2001 From: rogerdpack Date: Tue, 20 Mar 2012 12:35:10 -0600 Subject: [PATCH 04/79] allow for paths with spaces in them for the executable yikes --- lib/gnuplot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index 24bec17..33b7bde 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -55,7 +55,7 @@ def Gnuplot.which_helper bin # # Return the path to the gnuplot executable or nil if one cannot be found. def Gnuplot.gnuplot( persist = true ) - cmd = which( ENV['RB_GNUPLOT'] || 'gnuplot' ) + cmd = '"' + which( ENV['RB_GNUPLOT'] || 'gnuplot' ) + '"' raise 'gnuplot executable not found' unless cmd cmd += " -persist" if persist cmd From 34819ac0a737d46b162e5959682ee282e6494d44 Mon Sep 17 00:00:00 2001 From: rogerdpack Date: Tue, 20 Mar 2012 12:46:27 -0600 Subject: [PATCH 05/79] attempt fix ylabels etc --- examples/3d_surface_plot.rb | 3 ++- examples/discrete_points.rb | 5 ++--- examples/multiple_data_sets.rb | 4 ++-- examples/output_image_file.rb | 7 ++++--- examples/sin_wave.rb | 5 +++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/examples/3d_surface_plot.rb b/examples/3d_surface_plot.rb index 2cd7f7a..3c02451 100644 --- a/examples/3d_surface_plot.rb +++ b/examples/3d_surface_plot.rb @@ -10,4 +10,5 @@ end ] end -end + sleep 10 +end \ No newline at end of file diff --git a/examples/discrete_points.rb b/examples/discrete_points.rb index bd7ada4..09308bc 100644 --- a/examples/discrete_points.rb +++ b/examples/discrete_points.rb @@ -4,8 +4,8 @@ Gnuplot::Plot.new( gp ) do |plot| plot.title "Array Plot Example" - plot.ylabel "x" - plot.xlabel "x^2" + plot.ylabel "x^2" + plot.xlabel "x" x = (0..50).collect { |v| v.to_f } y = x.collect { |v| v ** 2 } @@ -14,6 +14,5 @@ ds.with = "linespoints" ds.notitle end - end end diff --git a/examples/multiple_data_sets.rb b/examples/multiple_data_sets.rb index eee98b5..845032a 100644 --- a/examples/multiple_data_sets.rb +++ b/examples/multiple_data_sets.rb @@ -5,8 +5,8 @@ plot.xrange "[-10:10]" plot.title "Sin Wave Example" - plot.ylabel "x" - plot.xlabel "sin(x)" + plot.ylabel "sin(x)" + plot.xlabel "x" x = (0..50).collect { |v| v.to_f } y = x.collect { |v| v ** 2 } diff --git a/examples/output_image_file.rb b/examples/output_image_file.rb index b8ae639..2a126f1 100644 --- a/examples/output_image_file.rb +++ b/examples/output_image_file.rb @@ -15,13 +15,13 @@ # for a list of recognized terminals. # plot.terminal "gif" - plot.output File.expand_path("../sin_wave.gif", __FILE__) + plot.output File.expand_path("../sin_wave.gif", __FILE__) # see sin_wave.rb plot.xrange "[-10:10]" plot.title "Sin Wave Example" - plot.ylabel "x" - plot.xlabel "sin(x)" + plot.ylabel "sin(x)" + plot.xlabel "x" plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds| ds.with = "lines" @@ -30,3 +30,4 @@ end end +puts 'created sin_wave.gif' diff --git a/examples/sin_wave.rb b/examples/sin_wave.rb index f63a98c..6701590 100644 --- a/examples/sin_wave.rb +++ b/examples/sin_wave.rb @@ -5,8 +5,8 @@ plot.xrange "[-10:10]" plot.title "Sin Wave Example" - plot.ylabel "x" - plot.xlabel "sin(x)" + plot.ylabel "sin(x)" + plot.xlabel "x" plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds| ds.with = "lines" @@ -14,4 +14,5 @@ end end + sleep 10 end \ No newline at end of file From 5950d5a0757510729b7c09fd8c7890269d5f06bb Mon Sep 17 00:00:00 2001 From: rogerdpack Date: Tue, 20 Mar 2012 12:47:49 -0600 Subject: [PATCH 06/79] v bump --- ChangeLog | 3 +++ Rakefile | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c23484b..b903f9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2.4.0 + * Allow for 3D plots, fix examples. Thanks everybody! + 2.3.6 * Cleanup readme (thanks blambeau again, really, for the snippets) diff --git a/Rakefile b/Rakefile index 1a4e590..95247f5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,8 @@ require 'jeweler' Jeweler::Tasks.new do |s| s.name = 'gnuplot' - s.description = s.summary = "Utility library to aid in interacting with gnuplot" - s.version = "2.3.6" + s.description = s.summary = "Utility library to aid in interacting with gnuplot from ruby" + s.version = "2.4.0" s.autorequire = 'gnuplot.rb' s.email = "rogerpack2005@gmail.com" s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master" From 68b5fd9c46718fd3f0dbca97aa976db39b63bc65 Mon Sep 17 00:00:00 2001 From: rogerdpack Date: Tue, 20 Mar 2012 12:50:21 -0600 Subject: [PATCH 07/79] add author --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 95247f5..83b1d90 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,7 @@ Jeweler::Tasks.new do |s| s.name = 'gnuplot' s.description = s.summary = "Utility library to aid in interacting with gnuplot from ruby" s.version = "2.4.0" + s.authors='roger pack' s.autorequire = 'gnuplot.rb' s.email = "rogerpack2005@gmail.com" s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master" From ab10fb8e6dbbc5b3cb7f24452572e64056ac5edb Mon Sep 17 00:00:00 2001 From: rogerdpack Date: Tue, 20 Mar 2012 13:46:08 -0600 Subject: [PATCH 08/79] more quotation marks --- lib/gnuplot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index 167f663..92cd27f 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -83,7 +83,7 @@ def Gnuplot.open( persist=true ) class Plot attr_accessor :cmd, :data, :sets - QUOTED = [ "title", "output", "xlabel", "ylabel" ] + QUOTED = [ "title", "output", "xlabel", "x2label", "ylabel", "y2label", "clabel", "cblabel", "zlabel" ] def initialize (io = nil, cmd = "plot") @cmd = cmd From 1f59b7e2b8eab8a15cb9315b81215bc182e8a725 Mon Sep 17 00:00:00 2001 From: rogerdpack Date: Tue, 20 Mar 2012 13:46:44 -0600 Subject: [PATCH 09/79] 2.4.1 bump --- ChangeLog | 3 +++ Rakefile | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b903f9f..4a9cdf9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2.4.1 + * Quote escape more strings. Thanks for the tip! + 2.4.0 * Allow for 3D plots, fix examples. Thanks everybody! diff --git a/Rakefile b/Rakefile index 83b1d90..5b8c3aa 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ require 'jeweler' Jeweler::Tasks.new do |s| s.name = 'gnuplot' s.description = s.summary = "Utility library to aid in interacting with gnuplot from ruby" - s.version = "2.4.0" + s.version = "2.4.1" s.authors='roger pack' s.autorequire = 'gnuplot.rb' s.email = "rogerpack2005@gmail.com" From 6090435d30f5ceca64adf1c769e16fa7138271ae Mon Sep 17 00:00:00 2001 From: rogerdpack Date: Tue, 22 May 2012 16:07:53 -0600 Subject: [PATCH 10/79] right error message --- lib/gnuplot.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index 92cd27f..9191450 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -55,8 +55,9 @@ def Gnuplot.which_helper bin # # Return the path to the gnuplot executable or nil if one cannot be found. def Gnuplot.gnuplot( persist = true ) - cmd = '"' + which( ENV['RB_GNUPLOT'] || 'gnuplot' ) + '"' - raise 'gnuplot executable not found' unless cmd + exe_loc = which( ENV['RB_GNUPLOT'] || 'gnuplot' ) + raise 'gnuplot executable not found on path' unless exe_loc + cmd = '"' + exe_loc + '"' cmd += " -persist" if persist cmd end From 7246cafdae2b9f56c21feb4b7dd08b731ccf1d5c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 27 Jun 2012 08:19:18 -0600 Subject: [PATCH 11/79] make output saveable --- lib/gnuplot.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index 9191450..c34a76f 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -71,9 +71,15 @@ def Gnuplot.gnuplot( persist = true ) # todo Add a method to pass the gnuplot path to the function. def Gnuplot.open( persist=true ) - cmd = Gnuplot.gnuplot( persist ) or raise 'gnuplot not found' - IO::popen( cmd, "w") { |io| yield io } - end + cmd = Gnuplot.gnuplot( persist ) + IO::popen( cmd, "w+") { |io| + yield io + io.close_write + @output = io.read + } + return @output + end + # Holds command information and performs the formatting of that command From 6aadf28b4c2fc92a7bf118c0a44d63aca54320b3 Mon Sep 17 00:00:00 2001 From: rogerdpack Date: Wed, 27 Jun 2012 08:21:52 -0600 Subject: [PATCH 12/79] test task --- Rakefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Rakefile b/Rakefile index 5b8c3aa..3c3576f 100644 --- a/Rakefile +++ b/Rakefile @@ -7,4 +7,13 @@ Jeweler::Tasks.new do |s| s.autorequire = 'gnuplot.rb' s.email = "rogerpack2005@gmail.com" s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master" +end + +desc 'run unit tests' +task :test do +Dir.chdir 'test' +for file in Dir['*'] + system("ruby #{file}") +end + end \ No newline at end of file From fba9cee574ed4047de0d5937032f4c90ea821b53 Mon Sep 17 00:00:00 2001 From: rogerdpack Date: Wed, 27 Jun 2012 08:28:41 -0600 Subject: [PATCH 13/79] use jeweler2, v bump --- ChangeLog | 3 +++ Rakefile | 15 +++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a9cdf9..7006edf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2.5.0 + * save output to instance variable, thanks for the patch. + 2.4.1 * Quote escape more strings. Thanks for the tip! diff --git a/Rakefile b/Rakefile index 3c3576f..4ea5618 100644 --- a/Rakefile +++ b/Rakefile @@ -1,19 +1,18 @@ -require 'jeweler' +require 'jeweler2' Jeweler::Tasks.new do |s| s.name = 'gnuplot' s.description = s.summary = "Utility library to aid in interacting with gnuplot from ruby" - s.version = "2.4.1" + s.version = "2.5.0" s.authors='roger pack' - s.autorequire = 'gnuplot.rb' s.email = "rogerpack2005@gmail.com" s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master" end desc 'run unit tests' task :test do -Dir.chdir 'test' -for file in Dir['*'] - system("ruby #{file}") + Dir.chdir 'test' + for file in Dir['*'] + system("ruby #{file}") + end end - -end \ No newline at end of file +Jeweler::RubygemsDotOrgTasks.new \ No newline at end of file From c01583f9011657206504ae48055a140a68009c29 Mon Sep 17 00:00:00 2001 From: Magnus Mueller Date: Wed, 8 Aug 2012 14:43:56 +0200 Subject: [PATCH 14/79] Allow unsetting a gnuplot variable This change adds a method Gnuplot::Plot.unset(var) to unset the Gnuplot variable var. As the order of sets and unsets are important for Gnuplot, a new array "settings" was introduced in which the set and unset tasks are accumulated. --- lib/gnuplot.rb | 23 +++++++++++++++++------ test/test_gnuplot.rb | 18 +++++++++++++++--- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index c34a76f..b7b5199 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -88,13 +88,13 @@ def Gnuplot.open( persist=true ) # object set the various properties and add data sets. class Plot - attr_accessor :cmd, :data, :sets + attr_accessor :cmd, :data, :settings QUOTED = [ "title", "output", "xlabel", "x2label", "ylabel", "y2label", "clabel", "cblabel", "zlabel" ] def initialize (io = nil, cmd = "plot") @cmd = cmd - @sets = [] + @settings = [] @arbitrary_lines = [] @data = [] yield self if block_given? @@ -125,7 +125,12 @@ def method_missing( methId, *args ) def set ( var, value = "" ) value = "\"#{value}\"" if QUOTED.include? var unless value =~ /^'.*'$/ - @sets << [ var, value ] + @settings << [ :set, var, value ] + end + + # Unset a variable. +Var+ must be a gnuplot variable. + def unset ( var ) + @settings << [ :unset, var ] end @@ -134,8 +139,12 @@ def set ( var, value = "" ) # gnuplot process. def [] ( var ) - v = @sets.assoc( var ) - v[1] || nil + v = @settings.rassoc( var ) + if v.nil? or v.first == :unset + nil + else + v[2] + end end @@ -145,7 +154,9 @@ def add_data ( ds ) def to_gplot (io = "") - @sets.each { |var, val| io << "set #{var} #{val}\n" } + @settings.each do |setting| + io << setting.map(&:to_s).join(" ") << "\n" + end @arbitrary_lines.each{|line| io << line << "\n" } io diff --git a/test/test_gnuplot.rb b/test/test_gnuplot.rb index 8216130..f873143 100644 --- a/test/test_gnuplot.rb +++ b/test/test_gnuplot.rb @@ -56,11 +56,13 @@ def test_no_data plot = Gnuplot::Plot.new do |p| p.set "output", "'foo'" p.set "terminal", "postscript enhanced" + p.unset "border" end - assert( plot.sets == - [ ["output", "'foo'"], - ["terminal", "postscript enhanced"] ] ) + assert( plot.settings == + [ [:set, "output", "'foo'"], + [:set, "terminal", "postscript enhanced"], + [:unset, "border"] ] ) assert( plot.to_gplot, \ @@ -78,6 +80,16 @@ def test_set assert "'foo'", plot["title"] end + def test_unset + plot = Gnuplot::Plot.new do |p| + p.unset "title" + end + assert_nil plot["title"] + + plot.unset "title" + assert_nil plot["title"] + end + end From 29e02a9a53908af06a81a6643ddc1949d039faef Mon Sep 17 00:00:00 2001 From: Casper Holmgreen Date: Thu, 23 Aug 2012 14:55:43 -0400 Subject: [PATCH 15/79] Corrected the labels in the second example of README.textile --- README.textile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.textile b/README.textile index 43b6773..b6b0463 100644 --- a/README.textile +++ b/README.textile @@ -143,8 +143,8 @@ Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| plot.title "Array Plot Example" - plot.ylabel "x" - plot.xlabel "x^2" + plot.xlabel "x" + plot.ylabel "x^2" x = (0..50).collect { |v| v.to_f } y = x.collect { |v| v ** 2 } @@ -199,4 +199,4 @@ plot.arbitrary_lines << "set ylabel \"y label" font \"Helvetica,20\"" See more in the examples folder. Also since this is basically just a wrapper for gnuplot itself, you should be able to do anything that it can do (demos: -http://gnuplot.sourceforge.net/demo_4.4/ ) \ No newline at end of file +http://gnuplot.sourceforge.net/demo_4.4/ ) From b332d0beadbc479a939c8cd57963bb5e5fa40221 Mon Sep 17 00:00:00 2001 From: Gregory Goltsov Date: Mon, 12 Nov 2012 21:27:25 +0000 Subject: [PATCH 16/79] Readme steps bug fix. --- README.textile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.textile b/README.textile index b6b0463..00d628b 100644 --- a/README.textile +++ b/README.textile @@ -25,16 +25,17 @@ h2. Ruby Gnuplot Concepts The object model for the Ruby gnuplot wrapper directly mimics this - layout and flow. The following are the standard steps for generating a + layout and flow. The following are the standard steps for generating a plot: -p. Instantiate a Plot or Splot object and set parameters by gnuplot variable name. -p. Instantiate DataSet objects and attach Ruby objects containing +# Instantiate a Plot or Splot object and set parameters by gnuplot variable name. + +# Instantiate DataSet objects and attach Ruby objects containing the data to be plotted to the DataSet. Attach properties that modify the plot command using the modifier name. -p. Send the Plot/Splot object to a Gnuplot instance for +# Send the Plot/Splot object to a Gnuplot instance for plotting. The Version 2.0 interface makes very heavy use of blocks leading to very @@ -42,7 +43,6 @@ p. Send the Plot/Splot object to a Gnuplot instance for Gnuplot.open - bq. Instantiates a new Gnuplot process. The path to the executable is determined on a Unix or MacOSX system using the which command. Windows @@ -69,7 +69,7 @@ bq. object can be associated with a DataSet as long as it understands the to_gplot method. - to_gplot +to_gplot bq. Within Gnuplot, plot data is read in very simple formats. The From 5ff65fe2c4d3c494d275a812a1cbb5ea65575606 Mon Sep 17 00:00:00 2001 From: Gregory Goltsov Date: Mon, 12 Nov 2012 21:34:59 +0000 Subject: [PATCH 17/79] Bulleted lists fixes, wrapped all the inline code properly. --- README.textile | 74 ++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/README.textile b/README.textile index 00d628b..edfab64 100644 --- a/README.textile +++ b/README.textile @@ -29,56 +29,57 @@ h2. Ruby Gnuplot Concepts plot: -# Instantiate a Plot or Splot object and set parameters by gnuplot variable name. +# Instantiate a @Plot@ or @Splot@ object and set parameters by gnuplot +# variable name. -# Instantiate DataSet objects and attach Ruby objects containing - the data to be plotted to the DataSet. Attach properties that modify - the plot command using the modifier name. +# Instantiate @DataSet@ objects and attach Ruby objects containing + the data to be plotted to the @DataSet@. Attach properties that modify + the plot command using the modifier name. -# Send the Plot/Splot object to a Gnuplot instance for - plotting. +# Send the @Plot@/@Splot@ object to a @Gnuplot@ instance for + plotting. The Version 2.0 interface makes very heavy use of blocks leading to very readable code. -Gnuplot.open +@Gnuplot.open@ bq. - Instantiates a new Gnuplot process. The path to the executable is + Instantiates a new Gnuplot process. The path to the executable is determined on a Unix or MacOSX system using the which command. Windows users, I have no idea what to do. If a block is given to the function the opened process is passed into - the block. This mimics the most common usage of the File.open method. + the block. This mimics the most common usage of the @File.open@ method. -Plot.new +@Plot.new@ -SPlot.new +@SPlot.new@ bq. - Create a new Plot or Splot object. DataSets are attached to the object + Create a new @Plot@ or @SPlot@ object. @DataSet@s are attached to the object to specify the data and its properties. If a block is given to the function, the plot object is passed into the block. -DataSet.new +@DataSet.new@ bq. Associates a Ruby object containing the data to plot with the properties - that will be passed to the plot command for that dataset. Any Ruby - object can be associated with a DataSet as long as it understands the - to_gplot method. + that will be passed to the plot command for that dataset. Any Ruby + object can be associated with a @DataSet@ as long as it understands the + @to_gplot@ method. -to_gplot +@to_gplot@ bq. Within Gnuplot, plot data is read in very simple formats. The - to_gplot method is expected to write the data of the object in a format - that is understandable by Gnuplot. One of the many great things about - Ruby is that methods can be added after the original declaration. The - gnuplot module defines the to_gplot method on the following classes: - Array, String, and Matrix. - Simply define a to_gplot method on your own class to tie the class into + @to_gplot@ method is expected to write the data of the object in a format + that is understandable by Gnuplot. One of the many great things about + Ruby is that methods can be added after the original declaration. The + gnuplot module defines the @to_gplot@ method on the following classes: + @Array@, @String@, and @Matrix@. + Simply define a @to_gplot@ method on your own class to tie the class into gnuplot. h2. Examples @@ -89,26 +90,26 @@ h3. Simple sin wave bq. The following example simply plots the value of sin(x) between the ranges of -10 and 10. A few points to notice: -p. The code uses nested blocks to construct the plot. The newly +* The code uses nested blocks to construct the plot. The newly created object is passed to the block so it can be modified in place. -p. Each of the gnuplot plot variables are modified using the +* Each of the gnuplot plot variables are modified using the variable name as a method name on the plot object or on the dataset object. The wrapper also takes care of the single quoting that is - required on some of the variables like title, ylabel, and xlabel. + required on some of the variables like @title@, @ylabel@, and @xlabel@. -p. The plot object simply has an array of DataSets. The +* The plot object simply has an array of @DataSet@s. The constructor initializes this empty array before yielding to the - block. This method uses the << operator to add the DataSet to + block. This method uses the @<<@ operator to add the @DataSet@ to the plot. -p. When the plot block ends, if an IO object is given to the Plot - constructor, the plot commands will be written to the IO object. +* When the plot block ends, if an @IO@ object is given to the @Plot@ + constructor, the plot commands will be written to the @IO@ object. Any object can be passed to the constructor as long as it - understands the << operator. + understands the @<<@ operator.
 Gnuplot.open do |gp|
@@ -130,13 +131,14 @@ end
 
Or you can write it out to a file (the above snippet displays the graph, in Linux, but in windows you'd need to write it to a file). -See the file examples/output_image_file.rb. + +See the file @examples/output_image_file.rb@. h3. Plotting discrete points -Array data can be plotted quite easily since Arrays have a defined to_gplot method. +Array data can be plotted quite easily since @Array@s have a defined @to_gplot@ method. -Simply pass an array of data to the constructor of the DataSet object or set the data property of the DataSet. In this example, because there are two arrays, each array will be a single column of data to the gnuplot process. +Simply pass an array of data to the constructor of the @DataSet@ object or set the data property of the @DataSet@. In this example, because there are two arrays, each array will be a single column of data to the gnuplot process.
 Gnuplot.open do |gp|
@@ -159,9 +161,9 @@ end
     
 h3. Multiple Data Sets
 
-As many data sets as are desired can be attached to a plot. Each of these can have their own plot modifiers. Notice in this example how the data array is explicitly set instead of using the << operator.
+As many data sets as are desired can be attached to a plot. Each of these can have their own plot modifiers. Notice in this example how the data array is explicitly set instead of using the @<<@ operator.
 
-Also in this example, the commands are not written to the Gnuplot process but are instead written to a File called gnuplot.dat. This file can later be run directly by a gnuplot process as it contains only the gnuplot commands.
+Also in this example, the commands are not written to the Gnuplot process but are instead written to a File called @gnuplot.dat@. This file can later be run directly by a gnuplot process as it contains only the gnuplot commands.
 
 
 File.open( "gnuplot.dat", "w") do |gp|

From dcb45ab85a3bbfe267433bb4cb0ac412a53abb12 Mon Sep 17 00:00:00 2001
From: Gregory Goltsov 
Date: Mon, 12 Nov 2012 21:39:54 +0000
Subject: [PATCH 18/79] Oops, textile lists don't behave the expected way.
 Fixed.

---
 README.textile | 31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/README.textile b/README.textile
index edfab64..e42d7d0 100644
--- a/README.textile
+++ b/README.textile
@@ -29,15 +29,11 @@ h2.  Ruby Gnuplot Concepts
       plot:
     
     
-#     Instantiate a @Plot@ or @Splot@ object and set parameters by gnuplot
-#     variable name. 
+#     Instantiate a @Plot@ or @Splot@ object and set parameters by gnuplot variable name. 
 
-#     Instantiate @DataSet@ objects and attach Ruby objects containing
-      the data to be plotted to the @DataSet@. Attach properties that modify
-      the plot command using the modifier name.
+#     Instantiate @DataSet@ objects and attach Ruby objects containing the data to be plotted to the @DataSet@. Attach properties that modify the plot command using the modifier name.
       
-#     Send the @Plot@/@Splot@ object to a @Gnuplot@ instance for
-      plotting.  
+#     Send the @Plot@/@Splot@ object to a @Gnuplot@ instance for plotting.  
 
       The Version 2.0 interface makes very heavy use of blocks leading to very
       readable code.
@@ -90,26 +86,13 @@ h3.  Simple sin wave
 bq. The following example simply plots the value of sin(x) between the
       ranges of -10 and 10.  A few points to notice:
     
-*  The code uses nested blocks to construct the plot.  The newly
-	  created object is passed to the block so it can be modified in
-	  place.
+*  The code uses nested blocks to construct the plot.  The newly created object is passed to the block so it can be modified in place.
       
-*  Each of the gnuplot plot variables are modified using the 
-	  variable name as a method name on the plot object or on the dataset
-	  object.  The wrapper also takes care of the single quoting that is
-	  required on some of the variables like @title@, @ylabel@, and @xlabel@.
-	
+*  Each of the gnuplot plot variables are modified using the variable name as a method name on the plot object or on the dataset object.  The wrapper also takes care of the single quoting that is required on some of the variables like @title@, @ylabel@, and @xlabel@.
       
-*  The plot object simply has an array of @DataSet@s.  The
-	  constructor initializes this empty array before yielding to the
-	  block.  This method uses the @<<@ operator to add the @DataSet@ to
-	  the plot.
-	
+*  The plot object simply has an array of @DataSet@s.  The constructor initializes this empty array before yielding to the block.  This method uses the @<<@ operator to add the @DataSet@ to the plot.
       
-*  When the plot block ends, if an @IO@ object is given to the @Plot@
-	  constructor, the plot commands will be written to the @IO@ object.
-	  Any object can be passed to the constructor as long as it
-	  understands the @<<@ operator.
+*  When the plot block ends, if an @IO@ object is given to the @Plot@ constructor, the plot commands will be written to the @IO@ object.  Any object can be passed to the constructor as long as it understands the @<<@ operator.
 	  
 
 Gnuplot.open do |gp|

From 91b2895a92b68b017ceab15dddb9606c2bd9c822 Mon Sep 17 00:00:00 2001
From: Gregory Goltsov 
Date: Tue, 13 Nov 2012 16:47:42 +0000
Subject: [PATCH 19/79] Apparently inline code is harder than it looks.

---
 README.textile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.textile b/README.textile
index e42d7d0..e888dd6 100644
--- a/README.textile
+++ b/README.textile
@@ -53,7 +53,7 @@ bq.
 @SPlot.new@
  
 bq. 
-      Create a new @Plot@ or @SPlot@ object. @DataSet@s are attached to the object
+      Create a new @Plot@ or @SPlot@ object. @DataSet@ s are attached to the object
       to specify the data and its properties. 
       If a block is given to the function, the plot object is passed into the
       block.

From b072352728121eec8068d03ef7c46e15a5d7cc3e Mon Sep 17 00:00:00 2001
From: Gregory Goltsov 
Date: Tue, 13 Nov 2012 16:54:48 +0000
Subject: [PATCH 20/79] Added linecolor property.

---
 lib/gnuplot.rb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb
index c34a76f..d69e3d2 100644
--- a/lib/gnuplot.rb
+++ b/lib/gnuplot.rb
@@ -195,11 +195,11 @@ def to_gplot (io = "")
   # @todo Use the delegator to delegate to the data property.
 
   class DataSet 
-    attr_accessor :title, :with, :using, :data, :linewidth, :matrix, :smooth, :axes
+    attr_accessor :title, :with, :using, :data, :linewidth, :linecolor, :matrix, :smooth, :axes
   
     def initialize (data = nil)
       @data = data
-      @title = @with = @using = @linewidth = @matrix = @smooth = @axes = nil # avoid warnings
+      @title = @with = @using = @linewidth = @linecolor = @matrix = @smooth = @axes = nil # avoid warnings
       yield self if block_given?
     end
         
@@ -226,6 +226,7 @@ def plot_args (io = "")
       io << " matrix" if @matrix
       io << " smooth #{@smooth}" if @smooth
       io << " with #{@with}" if @with
+      io << " linecolor #{@linecolor}" if @linecolor
       io << " linewidth #{@linewidth}" if @linewidth
       io
     end

From d561bfae7d4017379e309dca95c329f11a0d6fdb Mon Sep 17 00:00:00 2001
From: rogerdpack 
Date: Thu, 15 Nov 2012 14:06:49 -0700
Subject: [PATCH 21/79] v bump 2.6.0 thanks guys

---
 ChangeLog | 3 +++
 Rakefile  | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 7006edf..3b96c1a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2.6.0
+* better readme, allow for unsetting variables, thanks @kot-behemoth and @evnu
+
 2.5.0
  * save output to instance variable, thanks for the patch.
 
diff --git a/Rakefile b/Rakefile
index 4ea5618..f8ec160 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,7 +2,7 @@ require 'jeweler2'
 Jeweler::Tasks.new do |s|
   s.name = 'gnuplot'
   s.description = s.summary = "Utility library to aid in interacting with gnuplot from ruby"
-  s.version = "2.5.0"
+  s.version = "2.6.0"
   s.authors='roger pack'
   s.email = "rogerpack2005@gmail.com"
   s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master"

From 987198a13640c65f0d66b998899961c4196082d9 Mon Sep 17 00:00:00 2001
From: TheKnight 
Date: Sun, 9 Dec 2012 08:10:48 +0400
Subject: [PATCH 22/79] Fix bug in SPlot.to_gplot implementation.

---
 lib/gnuplot.rb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb
index a66b18e..aa1028a 100644
--- a/lib/gnuplot.rb
+++ b/lib/gnuplot.rb
@@ -182,8 +182,9 @@ def initialize (io = nil, cmd = "splot")
     end
     
     def to_gplot (io = "")
-      @sets.each { |var, val| io << "set #{var} #{val}\n" }
-
+      @settings.each do |setting|
+          io << setting.map(&:to_s).join(" ") << "\n"
+      end
       io
     end
 

From 10ee9f2ffd37b71ed2d4a2f1f8d09d7c899b4828 Mon Sep 17 00:00:00 2001
From: llrt 
Date: Wed, 12 Dec 2012 10:16:14 -0200
Subject: [PATCH 23/79] Make SPlot.to_gplot use parent's implementation

---
 lib/gnuplot.rb | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb
index a66b18e..0ee51d4 100644
--- a/lib/gnuplot.rb
+++ b/lib/gnuplot.rb
@@ -175,16 +175,20 @@ def store_datasets (io = "")
     end
   end
 
+  # Analogous to Plot class, holds command information and performs the formatting of that command
+  # information to a Gnuplot process. Should be used when for drawing 3D plots.
+
   class SPlot < Plot
 
     def initialize (io = nil, cmd = "splot")
       super
     end
     
+    # Currently using the implementation from parent class Plot.
+    # Leaving the method explicit here, though, as to allow an specific
+    # implementation for SPlot in the future.
     def to_gplot (io = "")
-      @sets.each { |var, val| io << "set #{var} #{val}\n" }
-
-      io
+      super
     end
 
   end

From c92bd4684f096971db044570b079c8038ed2e036 Mon Sep 17 00:00:00 2001
From: rogerdpack 
Date: Fri, 28 Dec 2012 08:44:47 -0700
Subject: [PATCH 24/79] v bump 0.6.1

---
 ChangeLog | 3 +++
 Rakefile  | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 3b96c1a..0698188 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2.6.1
+* TheKnight 	Fix bug in SPlot.to_gplot implementation. 
+
 2.6.0
 * better readme, allow for unsetting variables, thanks @kot-behemoth and @evnu
 
diff --git a/Rakefile b/Rakefile
index f8ec160..850c6d3 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,7 +2,7 @@ require 'jeweler2'
 Jeweler::Tasks.new do |s|
   s.name = 'gnuplot'
   s.description = s.summary = "Utility library to aid in interacting with gnuplot from ruby"
-  s.version = "2.6.0"
+  s.version = "2.6.1"
   s.authors='roger pack'
   s.email = "rogerpack2005@gmail.com"
   s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master"
@@ -15,4 +15,5 @@ task :test do
     system("ruby #{file}")
   end
 end
+
 Jeweler::RubygemsDotOrgTasks.new
\ No newline at end of file

From de034858c7aca5ec8c77a5508f4b93256e752f2a Mon Sep 17 00:00:00 2001
From: Pierre Yager 
Date: Wed, 6 Feb 2013 23:24:55 +0100
Subject: [PATCH 25/79] Exposed DataSet#index property

Use of index property is required for me to be able to draw a curve based on a simple dataset of values (x, y) :

dataset = Gnuplot::DataSet.new( [x, y] ) do |ds|
  ds.with = "linespoints"
  ds.notitle
  ds.using = "1:2"
  ds.index = 0
end
---
 lib/gnuplot.rb | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb
index 0ee51d4..89cae33 100644
--- a/lib/gnuplot.rb
+++ b/lib/gnuplot.rb
@@ -210,11 +210,11 @@ def to_gplot (io = "")
   # @todo Use the delegator to delegate to the data property.
 
   class DataSet 
-    attr_accessor :title, :with, :using, :data, :linewidth, :linecolor, :matrix, :smooth, :axes
+    attr_accessor :title, :with, :using, :data, :linewidth, :linecolor, :matrix, :smooth, :axes, :index
   
     def initialize (data = nil)
       @data = data
-      @title = @with = @using = @linewidth = @linecolor = @matrix = @smooth = @axes = nil # avoid warnings
+      @title = @with = @using = @linewidth = @linecolor = @matrix = @smooth = @axes = @index = nil # avoid warnings
       yield self if block_given?
     end
         
@@ -228,6 +228,8 @@ def plot_args (io = "")
 
       io << ( (@data.instance_of? String) ? @data : "'-'" )
 
+      io << " index #{@index}" if @index
+
       io << " using #{@using}" if @using
      
       io << " axes #{@axes}" if @axes

From 9676b48855065062f25818cc23e71e219f722711 Mon Sep 17 00:00:00 2001
From: Rafael Rosa Fu 
Date: Tue, 12 Feb 2013 18:46:03 -0500
Subject: [PATCH 26/79] Make 3d_surface_plot behave like the other examples

It was missing lib directory in the load path
---
 examples/3d_surface_plot.rb | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/3d_surface_plot.rb b/examples/3d_surface_plot.rb
index 3c02451..942d8ce 100644
--- a/examples/3d_surface_plot.rb
+++ b/examples/3d_surface_plot.rb
@@ -1,3 +1,4 @@
+$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
 require "gnuplot"
 
 Gnuplot.open do |gp|
@@ -11,4 +12,4 @@
     ]
   end
   sleep 10
-end
\ No newline at end of file
+end

From e7d2e541e7644c6073157bd9e1eeccc96758dbfa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Magnus=20M=C3=BCller?= 
Date: Tue, 30 Apr 2013 09:36:50 +0200
Subject: [PATCH 27/79] Add helper to create linestyles

---
 lib/gnuplot.rb       | 69 ++++++++++++++++++++++++++++++++++++++++++--
 test/test_gnuplot.rb | 28 ++++++++++++++++++
 2 files changed, 95 insertions(+), 2 deletions(-)

diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb
index 89cae33..f8faf42 100644
--- a/lib/gnuplot.rb
+++ b/lib/gnuplot.rb
@@ -97,6 +97,7 @@ def initialize (io = nil, cmd = "plot")
       @settings = []
       @arbitrary_lines = []
       @data = []
+      @styles = []
       yield self if block_given?
       puts "writing this to gnuplot:\n" + to_gplot + "\n" if $VERBOSE
 
@@ -147,6 +148,64 @@ def [] ( var )
       end
     end
 
+    class Style
+      attr_accessor :linestyle, :linetype, :linewidth, :linecolor,
+        :pointtype, :pointsize, :fill, :index
+
+      alias :ls :linestyle
+      alias :lt :linetype
+      alias :lw :linewidth
+      alias :lc :linecolor
+      alias :pt :pointtype
+      alias :ps :pointsize
+      alias :fs :fill
+
+      alias :ls= :linestyle=
+      alias :lt= :linetype=
+      alias :lw= :linewidth=
+      alias :lc= :linecolor=
+      alias :pt= :pointtype=
+      alias :ps= :pointsize=
+      alias :fs= :fill=
+
+      STYLES = [:ls, :lt, :lw, :lc, :pt, :ps, :fs]
+
+      def Style.increment_index
+        @index ||= 0
+        @index += 1
+
+        @index
+      end
+
+      def initialize
+        STYLES.each do |s|
+          send("#{s}=", nil)
+        end
+        yield self if block_given?
+
+        # only set the index if the user didn't do it
+        @index = Style::increment_index if index.nil?
+      end
+
+      def to_s
+        str = "set style line #{index}"
+        STYLES.each do |s|
+          style = send(s)
+          if not style.nil?
+            str << " #{s} #{style}"
+          end
+        end
+
+        str
+      end
+    end
+
+    # Create a gnuplot linestyle
+    def style &blk
+      s = Style.new &blk
+      @styles << s
+      s
+    end
 
     def add_data ( ds )
       @data << ds
@@ -157,6 +216,7 @@ def to_gplot (io = "")
       @settings.each do |setting|
           io << setting.map(&:to_s).join(" ") << "\n"
       end
+      @styles.each{|s| io << s.to_s << "\n"}
       @arbitrary_lines.each{|line| io << line << "\n" }
 
       io
@@ -210,11 +270,15 @@ def to_gplot (io = "")
   # @todo Use the delegator to delegate to the data property.
 
   class DataSet 
-    attr_accessor :title, :with, :using, :data, :linewidth, :linecolor, :matrix, :smooth, :axes, :index
+    attr_accessor :title, :with, :using, :data, :linewidth, :linecolor, :matrix, :smooth, :axes, :index, :linestyle
+
+    alias :ls :linestyle
+    alias :ls= :linestyle=
   
     def initialize (data = nil)
       @data = data
-      @title = @with = @using = @linewidth = @linecolor = @matrix = @smooth = @axes = @index = nil # avoid warnings
+      @linestyle = @title = @with = @using = @linewidth = @linecolor = @matrix =
+          @smooth = @axes = @index = nil # avoid warnings
       yield self if block_given?
     end
         
@@ -245,6 +309,7 @@ def plot_args (io = "")
       io << " with #{@with}" if @with
       io << " linecolor #{@linecolor}" if @linecolor
       io << " linewidth #{@linewidth}" if @linewidth
+      io << " linestyle #{@linestyle.index}" if @linestyle
       io
     end
 
diff --git a/test/test_gnuplot.rb b/test/test_gnuplot.rb
index f873143..6b301e9 100644
--- a/test/test_gnuplot.rb
+++ b/test/test_gnuplot.rb
@@ -90,6 +90,34 @@ def test_unset
     assert_nil plot["title"]
   end
 
+  def test_style
+    plot = Gnuplot::Plot.new do |p|
+      s1 = p.style do |s|
+        s.ls = 1
+        s.lt = 1
+        s.lc = 1
+        s.pt = 1
+        s.ps = 1
+      end
+      assert s1.to_s == "set style line 1 ls 1 lt 1 lc 1 pt 1 ps 1", "correct style definition"
+      assert s1.index == 1, "set index correctly"
+
+      s2 = p.style do |s|
+        s.ls = 2
+      end
+      assert s2.to_s == "set style line 2 ls 2", "correct style definition"
+      assert s2.index == 2, "index must be incremented"
+
+      ds = Gnuplot::DataSet.new do |ds|
+        ds.with = "lines" 
+        ds.linestyle = s1
+        ds.data = [ [0, 1, 2], [1, 2, 5] ]
+      end
+
+      assert ds.plot_args == "'-' with lines linestyle 1", "convert linestyle to index" # index of s1
+    end
+  end
+
 end
 
 

From 5d827be315593d7bd6da44c2a6569acc7e6565a8 Mon Sep 17 00:00:00 2001
From: Russell Smith 
Date: Sat, 8 Mar 2014 13:49:13 -0800
Subject: [PATCH 28/79] Fix unescaped quote in example

---
 README.textile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.textile b/README.textile
index e888dd6..04a0280 100644
--- a/README.textile
+++ b/README.textile
@@ -180,7 +180,7 @@ end
 You can also add arbitrary lines to the output 
 
 
-plot.arbitrary_lines << "set ylabel \"y label" font \"Helvetica,20\""
+plot.arbitrary_lines << "set ylabel \"y label\" font \"Helvetica,20\""
 
See more in the examples folder. Also since this is basically just a wrapper for gnuplot itself, you should be able to do anything that it can do (demos: From d9c2b05417100b6fdc098321268e2ec6d2158875 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Sat, 15 Mar 2014 01:07:33 -0400 Subject: [PATCH 29/79] Handle empty arrays in Array#to_gplot. --- lib/gnuplot.rb | 81 ++++++++++++++++++++++---------------------- test/test_gnuplot.rb | 38 +++++++++++++-------- 2 files changed, 64 insertions(+), 55 deletions(-) diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index f8faf42..ff10a75 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -1,21 +1,21 @@ # Methods and variables for interacting with the gnuplot process. Most of # these methods are for sending data to a gnuplot process, not for reading from -# it. Most of the methods are implemented as added methods to the built in +# it. Most of the methods are implemented as added methods to the built in # classes. require 'matrix' - + module Gnuplot # Trivial implementation of the which command that uses the PATH environment # variable to attempt to find the given application. The application must # be executable and reside in one of the directories in the PATH environment # to be found. The first match that is found will be returned. - # + # # bin [String] The name of the executable to search for. - # + # # Return the full path to the first match or nil if no match is found. - # + # def Gnuplot.which ( bin ) if RUBY_PLATFORM =~ /mswin|mingw/ all = [bin, bin + '.exe'] @@ -41,18 +41,18 @@ def Gnuplot.which_helper bin # This is an implementation that works when the which command is # available. - # + # # IO.popen("which #{bin}") { |io| return io.readline.chomp } return nil - end + end # Find the path to the gnuplot executable. The name of the executable can # be specified using the RB_GNUPLOT environment variable but will default to - # the command 'gnuplot'. - # + # the command 'gnuplot'. + # # persist [bool] Add the persist flag to the gnuplot executable - # + # # Return the path to the gnuplot executable or nil if one cannot be found. def Gnuplot.gnuplot( persist = true ) exe_loc = which( ENV['RB_GNUPLOT'] || 'gnuplot' ) @@ -61,15 +61,15 @@ def Gnuplot.gnuplot( persist = true ) cmd += " -persist" if persist cmd end - + # Open a gnuplot process that exists in the current PATH. If the persist # flag is true then the -persist flag is added to the command line. The - # path to the gnuplot executable is determined using the 'which' command. + # path to the gnuplot executable is determined using the 'which' command. # # See the gnuplot documentation for information on the persist flag. # # todo Add a method to pass the gnuplot path to the function. - + def Gnuplot.open( persist=true ) cmd = Gnuplot.gnuplot( persist ) IO::popen( cmd, "w+") { |io| @@ -77,11 +77,11 @@ def Gnuplot.open( persist=true ) io.close_write @output = io.read } - return @output + return @output end - - - + + + # Holds command information and performs the formatting of that command # information to a Gnuplot process. When constructing a new plot for # gnuplot, this is the first object that must be instantiated. On this @@ -101,7 +101,7 @@ def initialize (io = nil, cmd = "plot") yield self if block_given? puts "writing this to gnuplot:\n" + to_gplot + "\n" if $VERBOSE - if io + if io io << to_gplot io << store_datasets end @@ -119,7 +119,7 @@ def method_missing( methId, *args ) # Set a variable to the given value. +Var+ must be a gnuplot variable and # +value+ must be the value to set it to. Automatic quoting will be - # performed if the variable requires it. + # performed if the variable requires it. # # This is overloaded by the +method_missing+ method so see that for more # readable code. @@ -230,7 +230,7 @@ def store_datasets (io = "") v = @data.collect { |ds| ds.to_gplot } io << v.compact.join("e\n") end - + io end end @@ -243,7 +243,7 @@ class SPlot < Plot def initialize (io = nil, cmd = "splot") super end - + # Currently using the implementation from parent class Plot. # Leaving the method explicit here, though, as to allow an specific # implementation for SPlot in the future. @@ -258,7 +258,7 @@ def to_gplot (io = "") # has a reference to the actual data being plotted as well as settings that # control the "plot" command. The data object must support the to_gplot # command. - # + # # +data+ The data that will be plotted. The only requirement is that the # object understands the to_gplot method. # @@ -269,25 +269,25 @@ def to_gplot (io = "") # # @todo Use the delegator to delegate to the data property. - class DataSet + class DataSet attr_accessor :title, :with, :using, :data, :linewidth, :linecolor, :matrix, :smooth, :axes, :index, :linestyle alias :ls :linestyle alias :ls= :linestyle= - + def initialize (data = nil) @data = data @linestyle = @title = @with = @using = @linewidth = @linecolor = @matrix = @smooth = @axes = @index = nil # avoid warnings yield self if block_given? end - + def notitle @title = "notitle" end def plot_args (io = "") - + # Order of these is important or gnuplot barfs on 'em io << ( (@data.instance_of? String) ? @data : "'-'" ) @@ -295,13 +295,13 @@ def plot_args (io = "") io << " index #{@index}" if @index io << " using #{@using}" if @using - + io << " axes #{@axes}" if @axes - + io << case @title when /notitle/ then " notitle" when nil then "" - else " title '#{@title}'" + else " title '#{@title}'" end io << " matrix" if @matrix @@ -328,19 +328,20 @@ def to_gsplot else @data.to_gsplot end end - + end end class Array def to_gplot - if ( self[0].kind_of? Array ) then + return "" if self.empty? + + case self[0] + when Array tmp = self[0].zip( *self[1..-1] ) tmp.collect { |a| a.join(" ") }.join("\n") + "\ne" - elsif ( self[0].kind_of? Numeric ) then - s = "" - self.length.times { |i| s << "#{self[i]}\n" } - s + when Numeric + self.join("\n") else self[0].zip( *self[1..-1] ).to_gplot end @@ -348,7 +349,7 @@ def to_gplot def to_gsplot f = "" - + if ( self[0].kind_of? Array ) then x = self[0] y = self[1] @@ -365,16 +366,16 @@ def to_gsplot else self[0].zip( *self[1..-1] ).to_gsplot end - + f end end - + class Matrix def to_gplot (x = nil, y = nil) xgrid = x || (0...self.column_size).to_a ygrid = y || (0...self.row_size).to_a - + f = "" ygrid.length.times do |j| y = ygrid[j] @@ -384,7 +385,7 @@ def to_gplot (x = nil, y = nil) end end end - + f end diff --git a/test/test_gnuplot.rb b/test/test_gnuplot.rb index 6b301e9..18d8e34 100644 --- a/test/test_gnuplot.rb +++ b/test/test_gnuplot.rb @@ -4,15 +4,23 @@ require 'test/unit' class StdDataTest < Test::Unit::TestCase - + def test_array_1d data = (0..5).to_a ds = Gnuplot::DataSet.new( data ) - + assert data == ds.data assert data.join("\n") + "\n", ds.to_gplot end + def test_empty_array + data = [] + ds = Gnuplot::DataSet.new( data ) + + assert data == ds.data + assert "" == ds.to_gplot + end + # Test a multidimensional array. @@ -20,10 +28,10 @@ def test_array_nd d1 = (0..3).to_a d2 = d1.collect { |v| 3 * v } d3 = d2.collect { |v| 4 * v } - + data = [ d1, d2, d3 ] ds = Gnuplot::DataSet.new( data ) - + assert data == ds.data assert "0 0 0\n1 3 12\n2 6 24\n3 9 36\n", ds.to_gplot end @@ -34,24 +42,24 @@ class DataSetTest < Test::Unit::TestCase def test_yield_ctor ds = Gnuplot::DataSet.new do |ds| - ds.with = "lines" + ds.with = "lines" ds.using = "1:2" ds.data = [ [0, 1, 2], [1, 2, 5] ] end - + assert "lines", ds.with assert "1:2", ds.using assert nil == ds.title assert [ [0, 1, 2], [1, 2, 5] ] == ds.data assert "'-' using 1:2 with lines", ds.plot_args - assert "0 1\n1 2\n2 5\n", ds.to_gplot + assert "0 1\n1 2\n2 5\n", ds.to_gplot end - + end class PlotTest < Test::Unit::TestCase - + def test_no_data plot = Gnuplot::Plot.new do |p| p.set "output", "'foo'" @@ -60,10 +68,10 @@ def test_no_data end assert( plot.settings == - [ [:set, "output", "'foo'"], + [ [:set, "output", "'foo'"], [:set, "terminal", "postscript enhanced"], [:unset, "border"] ] ) - + assert( plot.to_gplot, \ "set output 'foo'\nset terminal postscript enhanced\n" ) @@ -109,7 +117,7 @@ def test_style assert s2.index == 2, "index must be incremented" ds = Gnuplot::DataSet.new do |ds| - ds.with = "lines" + ds.with = "lines" ds.linestyle = s1 ds.data = [ [0, 1, 2], [1, 2, 5] ] end @@ -134,7 +142,7 @@ class GnuplotModuleTest def test_which # Put the spaces around the command to make sure that it gets stripped - # properly. + # properly. assert( CONFIG["SHELL"], Gnuplot::which(" sh " ) ) assert( CONFIG["SHELL"], Gnuplot::which( CONFIG["SHELL"] ) ) end @@ -151,10 +159,10 @@ def test_gnuplot # name (one that is in the path) then I should get the shell name as the # result of the gnuplot call. - ENV["RB_GNUPLOT"] = "sh" + ENV["RB_GNUPLOT"] = "sh" assert( CONFIG["SHELL"], Gnuplot.gnuplot(false) ) end - + end From 3062885c7635677210e6e956f737a8bbb0640cf6 Mon Sep 17 00:00:00 2001 From: Martin Asser Hansen Date: Wed, 25 Jun 2014 15:41:08 +0200 Subject: [PATCH 30/79] output verbose message to instead of --- lib/gnuplot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index ff10a75..592b3e6 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -99,7 +99,7 @@ def initialize (io = nil, cmd = "plot") @data = [] @styles = [] yield self if block_given? - puts "writing this to gnuplot:\n" + to_gplot + "\n" if $VERBOSE + $stderr.puts "writing this to gnuplot:\n" + to_gplot + "\n" if $VERBOSE if io io << to_gplot From 65a1167764fec113294c9d509e5c3a15f0aad7cb Mon Sep 17 00:00:00 2001 From: Joe Norton Date: Sun, 29 Jun 2014 21:03:58 -0700 Subject: [PATCH 31/79] add test as default task in rake --- Rakefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 850c6d3..d8ae9ee 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ require 'jeweler2' -Jeweler::Tasks.new do |s| +Jeweler::Tasks.new do |s| s.name = 'gnuplot' s.description = s.summary = "Utility library to aid in interacting with gnuplot from ruby" s.version = "2.6.1" @@ -8,6 +8,8 @@ Jeweler::Tasks.new do |s| s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master" end +task :default => :test + desc 'run unit tests' task :test do Dir.chdir 'test' From 11daf3a201a629be9916e89bdeca7bd1945d420e Mon Sep 17 00:00:00 2001 From: Dustin Morrill Date: Wed, 9 Jul 2014 13:15:23 -0600 Subject: [PATCH 32/79] Cleaned up packaging system, listed dependencies explicitly, removed warnings from tests, added tasks to Rakefile, and added version file --- Gemfile | 4 ++++ Rakefile | 36 ++++++++++++++++++++---------------- lib/ruby_gnuplot/version.rb | 3 +++ ruby_gnuplot.gemspec | 21 +++++++++++++++++++++ test/arrtest.rb | 12 ++++++------ test/histtest.rb | 4 ++-- test/multtest.rb | 12 ++++++------ test/sinwave.rb | 12 ++++++------ test/test_gnuplot.rb | 12 ++++++------ 9 files changed, 74 insertions(+), 42 deletions(-) create mode 100644 Gemfile create mode 100644 lib/ruby_gnuplot/version.rb create mode 100644 ruby_gnuplot.gemspec diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..1ad452f --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in acpc_dealer.gemspec +gemspec diff --git a/Rakefile b/Rakefile index d8ae9ee..a0ac068 100644 --- a/Rakefile +++ b/Rakefile @@ -1,21 +1,25 @@ -require 'jeweler2' -Jeweler::Tasks.new do |s| - s.name = 'gnuplot' - s.description = s.summary = "Utility library to aid in interacting with gnuplot from ruby" - s.version = "2.6.1" - s.authors='roger pack' - s.email = "rogerpack2005@gmail.com" - s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master" -end +require "bundler/gem_tasks" +require 'rake' +require 'rake/clean' +require 'rake/testtask' +require 'rubygems/package_task' -task :default => :test +require_relative 'lib/ruby_gnuplot/version' desc 'run unit tests' -task :test do - Dir.chdir 'test' - for file in Dir['*'] - system("ruby #{file}") - end +task :default => [:test] + +task :build + +Rake::TestTask.new do |t| + t.libs << "lib" << 'spec/support' + t.test_files = FileList['test/**/*.rb'] + t.verbose = false + t.warning = false +end + +def gemspec + @clean_gemspec ||= eval(File.read(File.expand_path('../ruby_gnuplot.gemspec', __FILE__))) end -Jeweler::RubygemsDotOrgTasks.new \ No newline at end of file +Gem::PackageTask.new(gemspec) { |pkg| } diff --git a/lib/ruby_gnuplot/version.rb b/lib/ruby_gnuplot/version.rb new file mode 100644 index 0000000..ba6c60b --- /dev/null +++ b/lib/ruby_gnuplot/version.rb @@ -0,0 +1,3 @@ +module RubyGnuplot + VERSION = "2.6.1" +end diff --git a/ruby_gnuplot.gemspec b/ruby_gnuplot.gemspec new file mode 100644 index 0000000..c9cf609 --- /dev/null +++ b/ruby_gnuplot.gemspec @@ -0,0 +1,21 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'ruby_gnuplot/version' + +Gem::Specification.new do |s| + s.name = 'gnuplot' + s.description = s.summary = "Utility library to aid in interacting with gnuplot from ruby" + s.version = RubyGnuplot::VERSION + s.authors='roger pack' + s.email = "rogerpack2005@gmail.com" + s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master" + s.license = "BSD" + + s.files = `git ls-files`.split($/) + s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } + s.test_files = s.files.grep(%r{^(test|spec|features)/}) + s.require_paths = ["lib"] + + s.add_development_dependency 'minitest' +end diff --git a/test/arrtest.rb b/test/arrtest.rb index 208072c..00a95a3 100644 --- a/test/arrtest.rb +++ b/test/arrtest.rb @@ -1,12 +1,12 @@ -require '../lib/gnuplot' +require 'gnuplot' Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| - + plot.title "Array Plot Example" plot.ylabel "x" plot.xlabel "x^2" - + x = (0..50).collect { |v| v.to_f } y = x.collect { |v| v ** 2 } @@ -14,8 +14,8 @@ ds.with = "linespoints" ds.notitle end - + end - + end - + diff --git a/test/histtest.rb b/test/histtest.rb index dd09e24..d90bc0d 100644 --- a/test/histtest.rb +++ b/test/histtest.rb @@ -1,4 +1,4 @@ -require '../lib/gnuplot' +require 'gnuplot' Gnuplot.open do |gp| gp << "bin(x, s) = s*int(x/s)\n" @@ -10,7 +10,7 @@ x = (0..500).collect { |v| (rand()-0.5)**3 } plot.data << Gnuplot::DataSet.new( [x] ) do |ds| - ds.title = "smooth frequency" + ds.title = "smooth frequency" ds.using = "(bin($1,.01)):(1.)" ds.smooth = "freq" ds.with = "boxes" diff --git a/test/multtest.rb b/test/multtest.rb index 1aeb1d5..3bf4983 100644 --- a/test/multtest.rb +++ b/test/multtest.rb @@ -1,14 +1,14 @@ -require '../lib/gnuplot' +require 'gnuplot' # File.open( "gnuplot.dat", "w") do |gp| Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| - + plot.xrange "[-10:10]" plot.title "Sin Wave Example" plot.ylabel "x" plot.xlabel "sin(x)" - + x = (0..50).collect { |v| v.to_f } y = x.collect { |v| v ** 2 } @@ -18,7 +18,7 @@ ds.title = "String function" ds.linewidth = 4 }, - + Gnuplot::DataSet.new( [x, y] ) { |ds| ds.with = "linespoints" ds.title = "Array data" @@ -26,6 +26,6 @@ ] end - + end - + diff --git a/test/sinwave.rb b/test/sinwave.rb index f7e7131..78db32e 100644 --- a/test/sinwave.rb +++ b/test/sinwave.rb @@ -1,19 +1,19 @@ -require '../lib/gnuplot' +require 'gnuplot' Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| - + plot.xrange "[-10:10]" plot.title "Sin Wave Example" plot.ylabel "x" plot.xlabel "sin(x)" - + plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds| ds.with = "lines" ds.linewidth = 4 end - + end - + end - + diff --git a/test/test_gnuplot.rb b/test/test_gnuplot.rb index 18d8e34..19b7625 100644 --- a/test/test_gnuplot.rb +++ b/test/test_gnuplot.rb @@ -1,9 +1,9 @@ # -*- ruby -*- -require '../lib/gnuplot' -require 'test/unit' +require 'gnuplot' +require 'minitest/autorun' -class StdDataTest < Test::Unit::TestCase +class StdDataTest < MiniTest::Test def test_array_1d data = (0..5).to_a @@ -38,7 +38,7 @@ def test_array_nd end -class DataSetTest < Test::Unit::TestCase +class DataSetTest < MiniTest::Test def test_yield_ctor ds = Gnuplot::DataSet.new do |ds| @@ -58,7 +58,7 @@ def test_yield_ctor end -class PlotTest < Test::Unit::TestCase +class PlotTest < MiniTest::Test def test_no_data plot = Gnuplot::Plot.new do |p| @@ -130,7 +130,7 @@ def test_style require 'rbconfig' -CONFIG = Config::MAKEFILE_CONFIG +CONFIG = RbConfig::MAKEFILE_CONFIG # This attempts to test the functions that comprise the gnuplot package. Most # of the bug reports that I get for this package have to do with finding the From 8e5d872fdfc14f1f94d9f12a3108211e84b53007 Mon Sep 17 00:00:00 2001 From: Dustin Morrill Date: Wed, 9 Jul 2014 13:19:56 -0600 Subject: [PATCH 33/79] Update Rakefile Removed unnecessary explicit task --- Rakefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index a0ac068..bc3514b 100644 --- a/Rakefile +++ b/Rakefile @@ -7,9 +7,7 @@ require 'rubygems/package_task' require_relative 'lib/ruby_gnuplot/version' desc 'run unit tests' -task :default => [:test] - -task :build +task :default => :test Rake::TestTask.new do |t| t.libs << "lib" << 'spec/support' From 6b9ebad96b35b43aa42bd53e03b48f0fbf14686c Mon Sep 17 00:00:00 2001 From: Dustin Morrill Date: Wed, 9 Jul 2014 13:20:31 -0600 Subject: [PATCH 34/79] Update Gemfile Fixed copy-paste typo --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 1ad452f..3ef8ff9 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' -# Specify your gem's dependencies in acpc_dealer.gemspec +# Specify your gem's dependencies in ruby_gnuplot.gemspec gemspec From 4c1147fcc5564268650445a9c8bbabb2e86149b8 Mon Sep 17 00:00:00 2001 From: Rakibul Islam Date: Sun, 19 Jul 2015 18:08:34 -0400 Subject: [PATCH 35/79] Installation steps and ReadMe Cleanups * Pre-requisites and Installation steps to use gnuplot gem * Updated ReadMe for better readability --- README.textile | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/README.textile b/README.textile index 04a0280..9a42805 100644 --- a/README.textile +++ b/README.textile @@ -14,6 +14,17 @@ h2. History and Background been using it actively ever since. Now rdp maintains it. See also the changelog for more detail. +h2. Pre-requisites and Installation + + 1. Install XQuartz from here: + @http://xquartz.macosforge.org/landing/@ + + 2. Install gnuplot with homebrew: + @brew install gnuplot --with-x11@ + + 3. Install gnuplot gem: + @gem install gnuplot@ + h2. Ruby Gnuplot Concepts Gnuplot has a very simple conceptual model. Calls to _Set_ are @@ -29,11 +40,11 @@ h2. Ruby Gnuplot Concepts plot: -# Instantiate a @Plot@ or @Splot@ object and set parameters by gnuplot variable name. + 1. Instantiate a @Plot@ or @Splot@ object and set parameters by gnuplot variable name. -# Instantiate @DataSet@ objects and attach Ruby objects containing the data to be plotted to the @DataSet@. Attach properties that modify the plot command using the modifier name. + 2. Instantiate @DataSet@ objects and attach Ruby objects containing the data to be plotted to the @DataSet@. Attach properties that modify the plot command using the modifier name. -# Send the @Plot@/@Splot@ object to a @Gnuplot@ instance for plotting. + 3. Send the @Plot@/@Splot@ object to a @Gnuplot@ instance for plotting. The Version 2.0 interface makes very heavy use of blocks leading to very readable code. From 3d5c2c61afe02223203d1987ed757e18825b9e1d Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Fri, 2 Dec 2016 05:10:23 -0600 Subject: [PATCH 36/79] Fix axis labels in example --- README.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.textile b/README.textile index 9a42805..9f43cb9 100644 --- a/README.textile +++ b/README.textile @@ -111,8 +111,8 @@ Gnuplot.open do |gp| plot.xrange "[-10:10]" plot.title "Sin Wave Example" - plot.ylabel "x" - plot.xlabel "sin(x)" + plot.xlabel "x" + plot.ylabel "sin(x)" plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds| ds.with = "lines" From d943c06822be71f0c41d107f09f85e938269a639 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 1 Sep 2017 10:34:39 +0100 Subject: [PATCH 37/79] correct spelling mistake --- README.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.textile b/README.textile index 9f43cb9..4ec5086 100644 --- a/README.textile +++ b/README.textile @@ -30,7 +30,7 @@ h2. Ruby Gnuplot Concepts Gnuplot has a very simple conceptual model. Calls to _Set_ are made to set parameters and either _Plot_ or _Splot_ is called to generate the actual plot. The _dataset_ to be - plotted can be specified in a number of ways, contained in a seperate + plotted can be specified in a number of ways, contained in a separate file, generated from a function, read from standard input, or read immediately after the plot command. From 21db9771ba37ba9ca29f2259273ef44b1a784b6e Mon Sep 17 00:00:00 2001 From: darthjee Date: Fri, 25 Oct 2019 18:39:40 +0200 Subject: [PATCH 38/79] Add docker compose and docker file --- Dockerfile | 10 ++++++++++ docker-compose.yml | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b547c13 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM ruby:2.5.0 as base + +RUN useradd -u 1000 gnuplot; \ + mkdir -p /home/gnuplot/gnuplot; \ + chown gnuplot.gnuplot -R /home/gnuplot + +WORKDIR /home/gnuplot/gnuplot + +USER gnuplot +RUN gem install bundler diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a57db23 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3' +services: + base: &base + image: ruby_gnuplot + working_dir: /home/gnuplot/gnuplot + volumes: + - .:/home/gnuplot/gnuplot + + base_build: + <<: *base + build: . + command: echo done + + ruby_gnuplot: + <<: *base + container_name: ruby_gnuplot + depends_on: [base_build] From 6d8492f1a7a3dc3d8c8d2d1ed067d293f33552c7 Mon Sep 17 00:00:00 2001 From: darthjee Date: Fri, 25 Oct 2019 18:54:22 +0200 Subject: [PATCH 39/79] Install needed packages --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b547c13..fc14e49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM ruby:2.5.0 as base +RUN apt-get update && apt-get install -y gnuplot + RUN useradd -u 1000 gnuplot; \ mkdir -p /home/gnuplot/gnuplot; \ chown gnuplot.gnuplot -R /home/gnuplot @@ -7,4 +9,4 @@ RUN useradd -u 1000 gnuplot; \ WORKDIR /home/gnuplot/gnuplot USER gnuplot -RUN gem install bundler +RUN gem install jeweler2 From 43f5fbf7ed3e6fe00165f2076b069739b90d6cbc Mon Sep 17 00:00:00 2001 From: darthjee Date: Mon, 28 Oct 2019 12:27:42 +0100 Subject: [PATCH 40/79] Chnage entrypoint --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index a57db23..92cfe29 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,3 +15,4 @@ services: <<: *base container_name: ruby_gnuplot depends_on: [base_build] + command: /bin/bash From 39b45e92e314b9c433ba636210e80d07c86fa03c Mon Sep 17 00:00:00 2001 From: darthjee Date: Mon, 28 Oct 2019 12:29:51 +0100 Subject: [PATCH 41/79] Simplify docker-compose file --- docker-compose.yml | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 92cfe29..61d4e71 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,18 +1,9 @@ version: '3' services: - base: &base - image: ruby_gnuplot - working_dir: /home/gnuplot/gnuplot - volumes: - - .:/home/gnuplot/gnuplot - - base_build: - <<: *base - build: . - command: echo done - ruby_gnuplot: - <<: *base + build: . + working_dir: /home/gnuplot/gnuplot container_name: ruby_gnuplot - depends_on: [base_build] command: /bin/bash + volumes: + - .:/home/gnuplot/gnuplot From e7b7c648fc262b54d2d8c0cbabf1d2a23002d911 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 20:15:32 +0100 Subject: [PATCH 42/79] Update dockerfile acording to new bundle format --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fc14e49..b6d5643 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,7 @@ RUN useradd -u 1000 gnuplot; \ WORKDIR /home/gnuplot/gnuplot USER gnuplot -RUN gem install jeweler2 + +COPY ./ ./ + +RUN gem install bundler; bundle install From 3e2d95b5ad1df794c703fe3e0b4ea8aad75e5462 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 21:16:44 +0100 Subject: [PATCH 43/79] Add gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b844b14 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Gemfile.lock From 7b23f81eacef4a15b7fd4affffa565484db58c34 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 22:21:24 +0100 Subject: [PATCH 44/79] Avoid Gnuplot.lock copy --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b6d5643..8123674 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,8 @@ WORKDIR /home/gnuplot/gnuplot USER gnuplot -COPY ./ ./ +COPY lib/ ./lib/ +COPY *.gemspec ./ +COPY Gemfile ./ RUN gem install bundler; bundle install From 7cd0b4cc670ea66a6e8497c99f409915790f81db Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 21:13:33 +0100 Subject: [PATCH 45/79] Add rspec --- ruby_gnuplot.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/ruby_gnuplot.gemspec b/ruby_gnuplot.gemspec index c9cf609..c0fcedc 100644 --- a/ruby_gnuplot.gemspec +++ b/ruby_gnuplot.gemspec @@ -18,4 +18,5 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_development_dependency 'minitest' + s.add_development_dependency 'rspec', '3.9.0' end From 5024cdd840e33afaee5e2ff02c8fee5a7531bc82 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 21:14:51 +0100 Subject: [PATCH 46/79] add rspec --- .rspec | 2 + spec/spec_helper.rb | 100 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 .rspec create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..3687797 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--require spec_helper +--color diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..251aa51 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,100 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end From 8e42b9082f8a709031e9e80b7c4e682c544ea158 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 22:04:00 +0100 Subject: [PATCH 47/79] Add arrtest_spec --- spec/integration/arrtest_spec.rb | 39 ++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 2 ++ spec/tmp/.keep | 0 3 files changed, 41 insertions(+) create mode 100644 spec/integration/arrtest_spec.rb create mode 100644 spec/tmp/.keep diff --git a/spec/integration/arrtest_spec.rb b/spec/integration/arrtest_spec.rb new file mode 100644 index 0000000..f0e3bbf --- /dev/null +++ b/spec/integration/arrtest_spec.rb @@ -0,0 +1,39 @@ +describe "Array Plot Example" do + let(:file_path) { 'spec/tmp/array_plot.eps' } + let(:fixture_path) { 'spec/fixtures/plots/array_plot.eps' } + + let(:file_content) { File.read(file_path) } + let(:fixture_content) { File.read(fixture_path) } + + before do + path = file_path + + Gnuplot.open do |gp| + Gnuplot::Plot.new( gp ) do |plot| + + plot.title "Array Plot Example" + plot.ylabel "x" + plot.xlabel "x^2" + plot.set "term","postscript eps" + plot.set "out", "'#{path}'" + + x = (0..50).collect { |v| v.to_f } + y = x.collect { |v| v ** 2 } + + plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds| + ds.with = "linespoints" + ds.notitle + end + end + end + + end + + after do + File.delete(file_path) + end + + it do + expect(file_content).to eq(fixture_content) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 251aa51..8e96672 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,8 @@ # it. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +require "gnuplot" + RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest diff --git a/spec/tmp/.keep b/spec/tmp/.keep new file mode 100644 index 0000000..e69de29 From b6742ae88ea71a8321890ab912528c5b306207f1 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 22:28:45 +0100 Subject: [PATCH 48/79] Add sample example for arr_spec --- spec/fixtures/plots/array_plot.eps | 810 +++++++++++++++++++++++++++++ spec/integration/arrtest_spec.rb | 9 +- 2 files changed, 817 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/plots/array_plot.eps diff --git a/spec/fixtures/plots/array_plot.eps b/spec/fixtures/plots/array_plot.eps new file mode 100644 index 0000000..98b8de1 --- /dev/null +++ b/spec/fixtures/plots/array_plot.eps @@ -0,0 +1,810 @@ +%!PS-Adobe-2.0 EPSF-2.0 +%%Title: spec/tmp/array_plot.eps +%%Creator: gnuplot 5.0 patchlevel 5 +%%CreationDate: Wed Nov 6 21:24:07 2019 +%%DocumentFonts: (atend) +%%BoundingBox: 50 50 410 302 +%%EndComments +%%BeginProlog +/gnudict 256 dict def +gnudict begin +% +% The following true/false flags may be edited by hand if desired. +% The unit line width and grayscale image gamma correction may also be changed. +% +/Color false def +/Blacktext false def +/Solid false def +/Dashlength 1 def +/Landscape false def +/Level1 false def +/Level3 false def +/Rounded false def +/ClipToBoundingBox false def +/SuppressPDFMark false def +/TransparentPatterns false def +/gnulinewidth 5.000 def +/userlinewidth gnulinewidth def +/Gamma 1.0 def +/BackgroundColor {-1.000 -1.000 -1.000} def +% +/vshift -46 def +/dl1 { + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if +} def +/dl2 { + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + Rounded { currentlinewidth 0.75 mul add } if +} def +/hpt_ 31.5 def +/vpt_ 31.5 def +/hpt hpt_ def +/vpt vpt_ def +/doclip { + ClipToBoundingBox { + newpath 50 50 moveto 410 50 lineto 410 302 lineto 50 302 lineto closepath + clip + } if +} def +% +% Gnuplot Prolog Version 5.1 (Oct 2015) +% +%/SuppressPDFMark true def +% +/M {moveto} bind def +/L {lineto} bind def +/R {rmoveto} bind def +/V {rlineto} bind def +/N {newpath moveto} bind def +/Z {closepath} bind def +/C {setrgbcolor} bind def +/f {rlineto fill} bind def +/g {setgray} bind def +/Gshow {show} def % May be redefined later in the file to support UTF-8 +/vpt2 vpt 2 mul def +/hpt2 hpt 2 mul def +/Lshow {currentpoint stroke M 0 vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/Rshow {currentpoint stroke M dup stringwidth pop neg vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def + /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def +/DL {Color {setrgbcolor Solid {pop []} if 0 setdash} + {pop pop pop 0 setgray Solid {pop []} if 0 setdash} ifelse} def +/BL {stroke userlinewidth 2 mul setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +/AL {stroke userlinewidth 2 div setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +/UL {dup gnulinewidth mul /userlinewidth exch def + dup 1 lt {pop 1} if 10 mul /udl exch def} def +/PL {stroke userlinewidth setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +3.8 setmiterlimit +% Classic Line colors (version 5.0) +/LCw {1 1 1} def +/LCb {0 0 0} def +/LCa {0 0 0} def +/LC0 {1 0 0} def +/LC1 {0 1 0} def +/LC2 {0 0 1} def +/LC3 {1 0 1} def +/LC4 {0 1 1} def +/LC5 {1 1 0} def +/LC6 {0 0 0} def +/LC7 {1 0.3 0} def +/LC8 {0.5 0.5 0.5} def +% Default dash patterns (version 5.0) +/LTB {BL [] LCb DL} def +/LTw {PL [] 1 setgray} def +/LTb {PL [] LCb DL} def +/LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def +/LT0 {PL [] LC0 DL} def +/LT1 {PL [2 dl1 3 dl2] LC1 DL} def +/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def +/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def +/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [4 dl1 2 dl2] LC5 DL} def +/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def +/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def +/SL {[] 0 setdash} def +/Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def +/Dia {stroke [] 0 setdash 2 copy vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath stroke + Pnt} def +/Pls {stroke [] 0 setdash vpt sub M 0 vpt2 V + currentpoint stroke M + hpt neg vpt neg R hpt2 0 V stroke + } def +/Box {stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath stroke + Pnt} def +/Crs {stroke [] 0 setdash exch hpt sub exch vpt add M + hpt2 vpt2 neg V currentpoint stroke M + hpt2 neg 0 R hpt2 vpt2 V stroke} def +/TriU {stroke [] 0 setdash 2 copy vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath stroke + Pnt} def +/Star {2 copy Pls Crs} def +/BoxF {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath fill} def +/TriUF {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath fill} def +/TriD {stroke [] 0 setdash 2 copy vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath stroke + Pnt} def +/TriDF {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath fill} def +/DiaF {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath fill} def +/Pent {stroke [] 0 setdash 2 copy gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath stroke grestore Pnt} def +/PentF {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath fill grestore} def +/Circle {stroke [] 0 setdash 2 copy + hpt 0 360 arc stroke Pnt} def +/CircleF {stroke [] 0 setdash hpt 0 360 arc fill} def +/C0 {BL [] 0 setdash 2 copy moveto vpt 90 450 arc} bind def +/C1 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc closepath fill + vpt 0 360 arc closepath} bind def +/C2 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C3 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C4 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 180 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C5 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc + 2 copy moveto + 2 copy vpt 180 270 arc closepath fill + vpt 0 360 arc} bind def +/C6 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C7 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C8 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 270 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C9 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 270 450 arc closepath fill + vpt 0 360 arc closepath} bind def +/C10 {BL [] 0 setdash 2 copy 2 copy moveto vpt 270 360 arc closepath fill + 2 copy moveto + 2 copy vpt 90 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C11 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 180 arc closepath fill + 2 copy moveto + 2 copy vpt 270 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C12 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 180 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C13 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc closepath fill + 2 copy moveto + 2 copy vpt 180 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C14 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 360 arc closepath fill + vpt 0 360 arc} bind def +/C15 {BL [] 0 setdash 2 copy vpt 0 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/Rec {newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto + neg 0 rlineto closepath} bind def +/Square {dup Rec} bind def +/Bsquare {vpt sub exch vpt sub exch vpt2 Square} bind def +/S0 {BL [] 0 setdash 2 copy moveto 0 vpt rlineto BL Bsquare} bind def +/S1 {BL [] 0 setdash 2 copy vpt Square fill Bsquare} bind def +/S2 {BL [] 0 setdash 2 copy exch vpt sub exch vpt Square fill Bsquare} bind def +/S3 {BL [] 0 setdash 2 copy exch vpt sub exch vpt2 vpt Rec fill Bsquare} bind def +/S4 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def +/S5 {BL [] 0 setdash 2 copy 2 copy vpt Square fill + exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def +/S6 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill Bsquare} bind def +/S7 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill + 2 copy vpt Square fill Bsquare} bind def +/S8 {BL [] 0 setdash 2 copy vpt sub vpt Square fill Bsquare} bind def +/S9 {BL [] 0 setdash 2 copy vpt sub vpt vpt2 Rec fill Bsquare} bind def +/S10 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt Square fill + Bsquare} bind def +/S11 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt2 vpt Rec fill + Bsquare} bind def +/S12 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill Bsquare} bind def +/S13 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill + 2 copy vpt Square fill Bsquare} bind def +/S14 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill + 2 copy exch vpt sub exch vpt Square fill Bsquare} bind def +/S15 {BL [] 0 setdash 2 copy Bsquare fill Bsquare} bind def +/D0 {gsave translate 45 rotate 0 0 S0 stroke grestore} bind def +/D1 {gsave translate 45 rotate 0 0 S1 stroke grestore} bind def +/D2 {gsave translate 45 rotate 0 0 S2 stroke grestore} bind def +/D3 {gsave translate 45 rotate 0 0 S3 stroke grestore} bind def +/D4 {gsave translate 45 rotate 0 0 S4 stroke grestore} bind def +/D5 {gsave translate 45 rotate 0 0 S5 stroke grestore} bind def +/D6 {gsave translate 45 rotate 0 0 S6 stroke grestore} bind def +/D7 {gsave translate 45 rotate 0 0 S7 stroke grestore} bind def +/D8 {gsave translate 45 rotate 0 0 S8 stroke grestore} bind def +/D9 {gsave translate 45 rotate 0 0 S9 stroke grestore} bind def +/D10 {gsave translate 45 rotate 0 0 S10 stroke grestore} bind def +/D11 {gsave translate 45 rotate 0 0 S11 stroke grestore} bind def +/D12 {gsave translate 45 rotate 0 0 S12 stroke grestore} bind def +/D13 {gsave translate 45 rotate 0 0 S13 stroke grestore} bind def +/D14 {gsave translate 45 rotate 0 0 S14 stroke grestore} bind def +/D15 {gsave translate 45 rotate 0 0 S15 stroke grestore} bind def +/DiaE {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath stroke} def +/BoxE {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath stroke} def +/TriUE {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath stroke} def +/TriDE {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath stroke} def +/PentE {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath stroke grestore} def +/CircE {stroke [] 0 setdash + hpt 0 360 arc stroke} def +/Opaque {gsave closepath 1 setgray fill grestore 0 setgray closepath} def +/DiaW {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V Opaque stroke} def +/BoxW {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V Opaque stroke} def +/TriUW {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V Opaque stroke} def +/TriDW {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V Opaque stroke} def +/PentW {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + Opaque stroke grestore} def +/CircW {stroke [] 0 setdash + hpt 0 360 arc Opaque stroke} def +/BoxFill {gsave Rec 1 setgray fill grestore} def +/Density { + /Fillden exch def + currentrgbcolor + /ColB exch def /ColG exch def /ColR exch def + /ColR ColR Fillden mul Fillden sub 1 add def + /ColG ColG Fillden mul Fillden sub 1 add def + /ColB ColB Fillden mul Fillden sub 1 add def + ColR ColG ColB setrgbcolor} def +/BoxColFill {gsave Rec PolyFill} def +/PolyFill {gsave Density fill grestore grestore} def +/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def +% +% PostScript Level 1 Pattern Fill routine for rectangles +% Usage: x y w h s a XX PatternFill +% x,y = lower left corner of box to be filled +% w,h = width and height of box +% a = angle in degrees between lines and x-axis +% XX = 0/1 for no/yes cross-hatch +% +/PatternFill {gsave /PFa [ 9 2 roll ] def + PFa 0 get PFa 2 get 2 div add PFa 1 get PFa 3 get 2 div add translate + PFa 2 get -2 div PFa 3 get -2 div PFa 2 get PFa 3 get Rec + TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse + clip + currentlinewidth 0.5 mul setlinewidth + /PFs PFa 2 get dup mul PFa 3 get dup mul add sqrt def + 0 0 M PFa 5 get rotate PFs -2 div dup translate + 0 1 PFs PFa 4 get div 1 add floor cvi + {PFa 4 get mul 0 M 0 PFs V} for + 0 PFa 6 get ne { + 0 1 PFs PFa 4 get div 1 add floor cvi + {PFa 4 get mul 0 2 1 roll M PFs 0 V} for + } if + stroke grestore} def +% +/languagelevel where + {pop languagelevel} {1} ifelse +dup 2 lt + {/InterpretLevel1 true def + /InterpretLevel3 false def} + {/InterpretLevel1 Level1 def + 2 gt + {/InterpretLevel3 Level3 def} + {/InterpretLevel3 false def} + ifelse } + ifelse +% +% PostScript level 2 pattern fill definitions +% +/Level2PatternFill { +/Tile8x8 {/PaintType 2 /PatternType 1 /TilingType 1 /BBox [0 0 8 8] /XStep 8 /YStep 8} + bind def +/KeepColor {currentrgbcolor [/Pattern /DeviceRGB] setcolorspace} bind def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke} +>> matrix makepattern +/Pat1 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke + 0 4 M 4 8 L 8 4 L 4 0 L 0 4 L stroke} +>> matrix makepattern +/Pat2 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 0 8 L + 8 8 L 8 0 L 0 0 L fill} +>> matrix makepattern +/Pat3 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -4 8 M 8 -4 L + 0 12 M 12 0 L stroke} +>> matrix makepattern +/Pat4 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -4 0 M 8 12 L + 0 -4 M 12 8 L stroke} +>> matrix makepattern +/Pat5 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -2 8 M 4 -4 L + 0 12 M 8 -4 L 4 12 M 10 0 L stroke} +>> matrix makepattern +/Pat6 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -2 0 M 4 12 L + 0 -4 M 8 12 L 4 -4 M 10 8 L stroke} +>> matrix makepattern +/Pat7 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 8 -2 M -4 4 L + 12 0 M -4 8 L 12 4 M 0 10 L stroke} +>> matrix makepattern +/Pat8 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 -2 M 12 4 L + -4 0 M 12 8 L -4 4 M 8 10 L stroke} +>> matrix makepattern +/Pat9 exch def +/Pattern1 {PatternBgnd KeepColor Pat1 setpattern} bind def +/Pattern2 {PatternBgnd KeepColor Pat2 setpattern} bind def +/Pattern3 {PatternBgnd KeepColor Pat3 setpattern} bind def +/Pattern4 {PatternBgnd KeepColor Landscape {Pat5} {Pat4} ifelse setpattern} bind def +/Pattern5 {PatternBgnd KeepColor Landscape {Pat4} {Pat5} ifelse setpattern} bind def +/Pattern6 {PatternBgnd KeepColor Landscape {Pat9} {Pat6} ifelse setpattern} bind def +/Pattern7 {PatternBgnd KeepColor Landscape {Pat8} {Pat7} ifelse setpattern} bind def +} def +% +% +%End of PostScript Level 2 code +% +/PatternBgnd { + TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse +} def +% +% Substitute for Level 2 pattern fill codes with +% grayscale if Level 2 support is not selected. +% +/Level1PatternFill { +/Pattern1 {0.250 Density} bind def +/Pattern2 {0.500 Density} bind def +/Pattern3 {0.750 Density} bind def +/Pattern4 {0.125 Density} bind def +/Pattern5 {0.375 Density} bind def +/Pattern6 {0.625 Density} bind def +/Pattern7 {0.875 Density} bind def +} def +% +% Now test for support of Level 2 code +% +Level1 {Level1PatternFill} {Level2PatternFill} ifelse +% +/Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont +dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall +currentdict end definefont pop +% +/MFshow { + { dup 5 get 3 ge + { 5 get 3 eq {gsave} {grestore} ifelse } + {dup dup 0 get findfont exch 1 get scalefont setfont + [ currentpoint ] exch dup 2 get 0 exch R dup 5 get 2 ne {dup dup 6 + get exch 4 get {textshow} {stringwidth pop 0 R} ifelse }if dup 5 get 0 eq + {dup 3 get {2 get neg 0 exch R pop} {pop aload pop M} ifelse} {dup 5 + get 1 eq {dup 2 get exch dup 3 get exch 6 get stringwidth pop -2 div + dup 0 R} {dup 6 get stringwidth pop -2 div 0 R 6 get + textshow 2 index {aload pop M neg 3 -1 roll neg R pop pop} {pop pop pop + pop aload pop M} ifelse }ifelse }ifelse } + ifelse } + forall} def +/Gswidth {dup type /stringtype eq {stringwidth} {pop (n) stringwidth} ifelse} def +/MFwidth {0 exch { dup 5 get 3 ge { 5 get 3 eq { 0 } { pop } ifelse } + {dup 3 get{dup dup 0 get findfont exch 1 get scalefont setfont + 6 get Gswidth pop add} {pop} ifelse} ifelse} forall} def +/MLshow { currentpoint stroke M + 0 exch R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/MRshow { currentpoint stroke M + exch dup MFwidth neg 3 -1 roll R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/MCshow { currentpoint stroke M + exch dup MFwidth -2 div 3 -1 roll R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/XYsave { [( ) 1 2 true false 3 ()] } bind def +/XYrestore { [( ) 1 2 true false 4 ()] } bind def +Level1 SuppressPDFMark or +{} { +/SDict 10 dict def +systemdict /pdfmark known not { + userdict /pdfmark systemdict /cleartomark get put +} if +SDict begin [ + /Title (spec/tmp/array_plot.eps) + /Subject (gnuplot plot) + /Creator (gnuplot 5.0 patchlevel 5) +% /Producer (gnuplot) +% /Keywords () + /CreationDate (Wed Nov 6 21:24:07 2019) + /DOCINFO pdfmark +end +} ifelse +% +% Support for boxed text - Ethan A Merritt May 2005 +% +/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put + userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put + /Boxing true def } def +/ExtendTextBox { Boxing + { gsave dup false charpath pathbbox + dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse + dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse + dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse + dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse + grestore } if } def +/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M + TBx1 TBxmargin sub TBy2 TBymargin add L + TBx2 TBxmargin add TBy2 TBymargin add L + TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def +/DrawTextBox { PopTextBox stroke /Boxing false def} def +/FillTextBox { gsave PopTextBox 1 1 1 setrgbcolor fill grestore /Boxing false def} def +0 0 0 0 InitTextBox +/TBxmargin 20 def +/TBymargin 20 def +/Boxing false def +/textshow { ExtendTextBox Gshow } def +% +% redundant definitions for compatibility with prologue.ps older than 5.0.2 +/LTB {BL [] LCb DL} def +/LTb {PL [] LCb DL} def +end +%%EndProlog +%%Page: 1 1 +gnudict begin +gsave +doclip +50 50 translate +0.050 0.050 scale +0 setgray +newpath +(Helvetica) findfont 140 scalefont setfont +BackgroundColor 0 lt 3 1 roll 0 lt exch 0 lt or or not {BackgroundColor C 1.000 0 0 7200.00 5040.00 BoxColFill} if +1.000 UL +LTb +LCb setrgbcolor +770 588 M +63 0 V +6114 0 R +-63 0 V +stroke +686 588 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +770 1394 M +63 0 V +6114 0 R +-63 0 V +stroke +686 1394 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 500)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +770 2200 M +63 0 V +6114 0 R +-63 0 V +stroke +686 2200 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 1000)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +770 3007 M +63 0 V +6114 0 R +-63 0 V +stroke +686 3007 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 1500)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +770 3813 M +63 0 V +6114 0 R +-63 0 V +stroke +686 3813 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 2000)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +770 4619 M +63 0 V +6114 0 R +-63 0 V +stroke +686 4619 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 2500)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +770 588 M +0 63 V +0 3968 R +0 -63 V +stroke +770 448 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +2005 588 M +0 63 V +0 3968 R +0 -63 V +stroke +2005 448 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 10)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +3241 588 M +0 63 V +0 3968 R +0 -63 V +stroke +3241 448 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 20)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +4476 588 M +0 63 V +0 3968 R +0 -63 V +stroke +4476 448 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 30)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +5712 588 M +0 63 V +0 3968 R +0 -63 V +stroke +5712 448 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 40)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +6947 588 M +0 63 V +0 3968 R +0 -63 V +stroke +6947 448 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 50)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +1.000 UL +LTB +LCb setrgbcolor +770 4619 N +770 588 L +6177 0 V +0 4031 V +-6177 0 V +Z stroke +1.000 UP +1.000 UL +LTb +LCb setrgbcolor +LCb setrgbcolor +112 2603 M +currentpoint gsave translate -270 rotate 0 0 moveto +[ [(Helvetica) 140.0 0.0 true true 0 (x)] +] -46.7 MCshow +grestore +LTb +LCb setrgbcolor +3858 238 M +[ [(Helvetica) 140.0 0.0 true true 0 (x)] +[(Helvetica) 112.0 70.0 true true 0 (2)] +] -60.7 MCshow +LTb +LCb setrgbcolor +3858 4829 M +[ [(Helvetica) 140.0 0.0 true true 0 (Array Plot Example)] +] -46.7 MCshow +% Begin plot #1 +1.000 UP +1.000 UL +LTb +LCb setrgbcolor +770 588 M +124 2 V +123 4 V +124 9 V +123 11 V +124 14 V +123 18 V +124 21 V +123 24 V +124 28 V +123 30 V +124 34 V +123 37 V +124 40 V +124 44 V +123 47 V +124 50 V +123 53 V +124 56 V +123 60 V +124 63 V +123 66 V +124 69 V +123 73 V +124 76 V +124 79 V +123 82 V +124 85 V +123 89 V +124 92 V +123 95 V +124 99 V +123 101 V +124 105 V +123 108 V +124 111 V +123 115 V +124 117 V +124 121 V +123 124 V +124 128 V +123 130 V +124 134 V +123 137 V +124 141 V +123 143 V +124 147 V +123 150 V +124 153 V +123 156 V +124 160 V +770 588 Pls +894 590 Pls +1017 594 Pls +1141 603 Pls +1264 614 Pls +1388 628 Pls +1511 646 Pls +1635 667 Pls +1758 691 Pls +1882 719 Pls +2005 749 Pls +2129 783 Pls +2252 820 Pls +2376 860 Pls +2500 904 Pls +2623 951 Pls +2747 1001 Pls +2870 1054 Pls +2994 1110 Pls +3117 1170 Pls +3241 1233 Pls +3364 1299 Pls +3488 1368 Pls +3611 1441 Pls +3735 1517 Pls +3859 1596 Pls +3982 1678 Pls +4106 1763 Pls +4229 1852 Pls +4353 1944 Pls +4476 2039 Pls +4600 2138 Pls +4723 2239 Pls +4847 2344 Pls +4970 2452 Pls +5094 2563 Pls +5217 2678 Pls +5341 2795 Pls +5465 2916 Pls +5588 3040 Pls +5712 3168 Pls +5835 3298 Pls +5959 3432 Pls +6082 3569 Pls +6206 3710 Pls +6329 3853 Pls +6453 4000 Pls +6576 4150 Pls +6700 4303 Pls +6823 4459 Pls +6947 4619 Pls +% End plot #1 +2.000 UL +LTb +LCb setrgbcolor +1.000 UL +LTB +LCb setrgbcolor +770 4619 N +770 588 L +6177 0 V +0 4031 V +-6177 0 V +Z stroke +1.000 UP +1.000 UL +LTb +LCb setrgbcolor +stroke +grestore +end +showpage +%%Trailer +%%DocumentFonts: Helvetica diff --git a/spec/integration/arrtest_spec.rb b/spec/integration/arrtest_spec.rb index f0e3bbf..9af5de0 100644 --- a/spec/integration/arrtest_spec.rb +++ b/spec/integration/arrtest_spec.rb @@ -2,8 +2,13 @@ let(:file_path) { 'spec/tmp/array_plot.eps' } let(:fixture_path) { 'spec/fixtures/plots/array_plot.eps' } - let(:file_content) { File.read(file_path) } - let(:fixture_content) { File.read(fixture_path) } + let(:file_content) do + File.read(file_path).gsub(/CreationDate.*/, "") + end + + let(:fixture_content) do + File.read(fixture_path).gsub(/CreationDate.*/, "") + end before do path = file_path From b97fb8c423e2afb3068b79e64833ec525c5b4491 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 22:29:05 +0100 Subject: [PATCH 49/79] Ignore swap files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b844b14..e82255f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ Gemfile.lock +**/*.swp From 1c72ea5810db9ed47e77c2ccf8132474d5921404 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 22:29:37 +0100 Subject: [PATCH 50/79] Add expectation description --- spec/integration/arrtest_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration/arrtest_spec.rb b/spec/integration/arrtest_spec.rb index 9af5de0..592a50e 100644 --- a/spec/integration/arrtest_spec.rb +++ b/spec/integration/arrtest_spec.rb @@ -38,7 +38,7 @@ File.delete(file_path) end - it do + it "plots expected file" do expect(file_content).to eq(fixture_content) end end From 2b577b1aaf8f0b46aff09d8cbd0b20ffcf420055 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 22:44:37 +0100 Subject: [PATCH 51/79] Add simple plot spec proposal --- spec/lib/ruby_gnuplot/plot_spec.rb | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 spec/lib/ruby_gnuplot/plot_spec.rb diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb new file mode 100644 index 0000000..3a53e43 --- /dev/null +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -0,0 +1,32 @@ +describe Gnuplot::Plot do + subject(:plot) { described_class.new } + + describe '#to_gplot' do + context 'when nothing has been set' do + it "returns an empty string" do + expect(plot.to_gplot).to eq('') + end + end + + context 'when titles and labels have been set' do + let(:expected_string) do + [ + 'set title "Array Plot Example"', + 'set ylabel "x"', + 'set xlabel "x^2"', + '' + ].join("\n") + end + + before do + plot.title "Array Plot Example" + plot.ylabel "x" + plot.xlabel "x^2" + end + + it "sets title and axis labels" do + expect(plot.to_gplot).to eq(expected_string) + end + end + end +end From f550805b7af3ac556a8721a6a834b2f98404ca47 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 22:55:12 +0100 Subject: [PATCH 52/79] Improove gplot spec --- spec/integration/arrtest_spec.rb | 4 +-- spec/lib/ruby_gnuplot/plot_spec.rb | 39 ++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/spec/integration/arrtest_spec.rb b/spec/integration/arrtest_spec.rb index 592a50e..e496bab 100644 --- a/spec/integration/arrtest_spec.rb +++ b/spec/integration/arrtest_spec.rb @@ -19,8 +19,8 @@ plot.title "Array Plot Example" plot.ylabel "x" plot.xlabel "x^2" - plot.set "term","postscript eps" - plot.set "out", "'#{path}'" + plot.set "term","postscript eps" + plot.set "out", "'#{path}'" x = (0..50).collect { |v| v.to_f } y = x.collect { |v| v ** 2 } diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index 3a53e43..c45ce23 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -2,6 +2,18 @@ subject(:plot) { described_class.new } describe '#to_gplot' do + let(:expected_string) do + [ + 'set title "Array Plot Example"', + 'set ylabel "x"', + 'set xlabel "x^2"', + 'set term postscript eps', + 'set output "file.eps"', + '' + ].join("\n") + end + + context 'when nothing has been set' do it "returns an empty string" do expect(plot.to_gplot).to eq('') @@ -9,22 +21,29 @@ end context 'when titles and labels have been set' do - let(:expected_string) do - [ - 'set title "Array Plot Example"', - 'set ylabel "x"', - 'set xlabel "x^2"', - '' - ].join("\n") - end - before do plot.title "Array Plot Example" plot.ylabel "x" plot.xlabel "x^2" + plot.term "postscript eps" + plot.output "file.eps" + end + + it "wraps strings with quotes when needed" do + expect(plot.to_gplot).to eq(expected_string) + end + end + + context 'when variables are set throgh set call' do + before do + plot.set "title", "Array Plot Example" + plot.set "ylabel", "x" + plot.set "xlabel", "x^2" + plot.set "term", "postscript eps" + plot.set "output", "file.eps" end - it "sets title and axis labels" do + it "wraps strings with quotes when needed" do expect(plot.to_gplot).to eq(expected_string) end end From 64fc5de32320f81044b0771ba49d03df709a36dd Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 22:58:14 +0100 Subject: [PATCH 53/79] Use correct format --- spec/integration/arrtest_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/integration/arrtest_spec.rb b/spec/integration/arrtest_spec.rb index e496bab..a5ae38e 100644 --- a/spec/integration/arrtest_spec.rb +++ b/spec/integration/arrtest_spec.rb @@ -19,8 +19,8 @@ plot.title "Array Plot Example" plot.ylabel "x" plot.xlabel "x^2" - plot.set "term","postscript eps" - plot.set "out", "'#{path}'" + plot.term "postscript eps" + plot.output path x = (0..50).collect { |v| v.to_f } y = x.collect { |v| v ** 2 } From 17290ecd36b996605e12e259c791685f657ff7f4 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 23:02:24 +0100 Subject: [PATCH 54/79] Add simplecov --- ruby_gnuplot.gemspec | 3 ++- spec/spec_helper.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ruby_gnuplot.gemspec b/ruby_gnuplot.gemspec index c0fcedc..c070c96 100644 --- a/ruby_gnuplot.gemspec +++ b/ruby_gnuplot.gemspec @@ -18,5 +18,6 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_development_dependency 'minitest' - s.add_development_dependency 'rspec', '3.9.0' + s.add_development_dependency 'rspec', '3.9.0' + s.add_development_dependency 'simplecov', '0.17.0' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8e96672..051338c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,11 @@ # it. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +require 'simplecov' +SimpleCov.start do + add_filter '/spec/' +end + require "gnuplot" RSpec.configure do |config| From 97e2b8cfb7e2763b6150643cc3cbd31808795f33 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 6 Nov 2019 23:02:43 +0100 Subject: [PATCH 55/79] Add coverage to ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e82255f..97c645a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ Gemfile.lock **/*.swp +coverage/ From 7c6ebdf2f44f6abbb7f96a39b88e0f7bc0fc286f Mon Sep 17 00:00:00 2001 From: darthjee Date: Fri, 22 Nov 2019 22:15:17 +0100 Subject: [PATCH 56/79] Replace whitespaces --- test/histtest.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/histtest.rb b/test/histtest.rb index d90bc0d..9207005 100644 --- a/test/histtest.rb +++ b/test/histtest.rb @@ -1,20 +1,20 @@ require 'gnuplot' Gnuplot.open do |gp| - gp << "bin(x, s) = s*int(x/s)\n" + gp << "bin(x, s) = s*int(x/s)\n" - Gnuplot::Plot.new( gp ) do |plot| - plot.title "Histogram" - plot.xlabel "x" - plot.ylabel "frequency" + Gnuplot::Plot.new( gp ) do |plot| + plot.title "Histogram" + plot.xlabel "x" + plot.ylabel "frequency" - x = (0..500).collect { |v| (rand()-0.5)**3 } - plot.data << Gnuplot::DataSet.new( [x] ) do |ds| - ds.title = "smooth frequency" - ds.using = "(bin($1,.01)):(1.)" - ds.smooth = "freq" - ds.with = "boxes" - end + x = (0..500).collect { |v| (rand()-0.5)**3 } + plot.data << Gnuplot::DataSet.new( [x] ) do |ds| + ds.title = "smooth frequency" + ds.using = "(bin($1,.01)):(1.)" + ds.smooth = "freq" + ds.with = "boxes" end + end end From 82c4eb816ecfd48ebc77275db76ebe99f0720c45 Mon Sep 17 00:00:00 2001 From: darthjee Date: Fri, 22 Nov 2019 22:40:24 +0100 Subject: [PATCH 57/79] Add histogram spec --- spec/integration/histtest_spec.rb | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 spec/integration/histtest_spec.rb diff --git a/spec/integration/histtest_spec.rb b/spec/integration/histtest_spec.rb new file mode 100644 index 0000000..47d7aea --- /dev/null +++ b/spec/integration/histtest_spec.rb @@ -0,0 +1,48 @@ +describe "Histogram Plot Example" do + let(:file_path) { 'spec/tmp/histogram_plot.eps' } + let(:fixture_path) { 'spec/fixtures/plots/histogram_plot.eps' } + + let(:file_content) do + File.read(file_path).gsub(/CreationDate.*/, "") + end + + let(:fixture_content) do + File.read(fixture_path).gsub(/CreationDate.*/, "") + end + + before do + path = file_path + collection = (0..500).collect do |_v| + (rand()-0.5)**3 + end + + Gnuplot.open do |gp| + gp << "bin(x, s) = s*int(x/s)\n" + + Gnuplot::Plot.new( gp ) do |plot| + plot.title "Histogram" + plot.xlabel "x" + plot.ylabel "frequency" + + plot.data << Gnuplot::DataSet.new( [collection] ) do |ds| + ds.title = "smooth frequency" + ds.using = "(bin($1,.01)):(1.)" + ds.smooth = "freq" + ds.with = "boxes" + end + + plot.term "postscript eps" + plot.output path + end + end + + end + + after do + File.delete(file_path) + end + + it "plots expected file" do + expect(file_content).to eq(fixture_content) + end +end From 9037db89e6f556b7d6a81c12e5b9aed2e7fe8630 Mon Sep 17 00:00:00 2001 From: darthjee Date: Fri, 22 Nov 2019 23:12:26 +0100 Subject: [PATCH 58/79] Fix histogram spec --- spec/fixtures/plots/histogram_plot.eps | 889 ++++++++++++++++++++++++ spec/integration/histtest_spec.rb | 4 +- spec/spec_helper.rb | 4 + spec/support/models/random_generator.rb | 18 + 4 files changed, 914 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/plots/histogram_plot.eps create mode 100644 spec/support/models/random_generator.rb diff --git a/spec/fixtures/plots/histogram_plot.eps b/spec/fixtures/plots/histogram_plot.eps new file mode 100644 index 0000000..c2edc90 --- /dev/null +++ b/spec/fixtures/plots/histogram_plot.eps @@ -0,0 +1,889 @@ +%!PS-Adobe-2.0 EPSF-2.0 +%%Title: spec/tmp/histogram_plot.eps +%%Creator: gnuplot 5.0 patchlevel 5 +%%CreationDate: Fri Nov 22 22:11:02 2019 +%%DocumentFonts: (atend) +%%BoundingBox: 50 50 410 302 +%%EndComments +%%BeginProlog +/gnudict 256 dict def +gnudict begin +% +% The following true/false flags may be edited by hand if desired. +% The unit line width and grayscale image gamma correction may also be changed. +% +/Color false def +/Blacktext false def +/Solid false def +/Dashlength 1 def +/Landscape false def +/Level1 false def +/Level3 false def +/Rounded false def +/ClipToBoundingBox false def +/SuppressPDFMark false def +/TransparentPatterns false def +/gnulinewidth 5.000 def +/userlinewidth gnulinewidth def +/Gamma 1.0 def +/BackgroundColor {-1.000 -1.000 -1.000} def +% +/vshift -46 def +/dl1 { + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if +} def +/dl2 { + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + Rounded { currentlinewidth 0.75 mul add } if +} def +/hpt_ 31.5 def +/vpt_ 31.5 def +/hpt hpt_ def +/vpt vpt_ def +/doclip { + ClipToBoundingBox { + newpath 50 50 moveto 410 50 lineto 410 302 lineto 50 302 lineto closepath + clip + } if +} def +% +% Gnuplot Prolog Version 5.1 (Oct 2015) +% +%/SuppressPDFMark true def +% +/M {moveto} bind def +/L {lineto} bind def +/R {rmoveto} bind def +/V {rlineto} bind def +/N {newpath moveto} bind def +/Z {closepath} bind def +/C {setrgbcolor} bind def +/f {rlineto fill} bind def +/g {setgray} bind def +/Gshow {show} def % May be redefined later in the file to support UTF-8 +/vpt2 vpt 2 mul def +/hpt2 hpt 2 mul def +/Lshow {currentpoint stroke M 0 vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/Rshow {currentpoint stroke M dup stringwidth pop neg vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def + /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def +/DL {Color {setrgbcolor Solid {pop []} if 0 setdash} + {pop pop pop 0 setgray Solid {pop []} if 0 setdash} ifelse} def +/BL {stroke userlinewidth 2 mul setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +/AL {stroke userlinewidth 2 div setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +/UL {dup gnulinewidth mul /userlinewidth exch def + dup 1 lt {pop 1} if 10 mul /udl exch def} def +/PL {stroke userlinewidth setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +3.8 setmiterlimit +% Classic Line colors (version 5.0) +/LCw {1 1 1} def +/LCb {0 0 0} def +/LCa {0 0 0} def +/LC0 {1 0 0} def +/LC1 {0 1 0} def +/LC2 {0 0 1} def +/LC3 {1 0 1} def +/LC4 {0 1 1} def +/LC5 {1 1 0} def +/LC6 {0 0 0} def +/LC7 {1 0.3 0} def +/LC8 {0.5 0.5 0.5} def +% Default dash patterns (version 5.0) +/LTB {BL [] LCb DL} def +/LTw {PL [] 1 setgray} def +/LTb {PL [] LCb DL} def +/LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def +/LT0 {PL [] LC0 DL} def +/LT1 {PL [2 dl1 3 dl2] LC1 DL} def +/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def +/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def +/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [4 dl1 2 dl2] LC5 DL} def +/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def +/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def +/SL {[] 0 setdash} def +/Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def +/Dia {stroke [] 0 setdash 2 copy vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath stroke + Pnt} def +/Pls {stroke [] 0 setdash vpt sub M 0 vpt2 V + currentpoint stroke M + hpt neg vpt neg R hpt2 0 V stroke + } def +/Box {stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath stroke + Pnt} def +/Crs {stroke [] 0 setdash exch hpt sub exch vpt add M + hpt2 vpt2 neg V currentpoint stroke M + hpt2 neg 0 R hpt2 vpt2 V stroke} def +/TriU {stroke [] 0 setdash 2 copy vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath stroke + Pnt} def +/Star {2 copy Pls Crs} def +/BoxF {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath fill} def +/TriUF {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath fill} def +/TriD {stroke [] 0 setdash 2 copy vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath stroke + Pnt} def +/TriDF {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath fill} def +/DiaF {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath fill} def +/Pent {stroke [] 0 setdash 2 copy gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath stroke grestore Pnt} def +/PentF {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath fill grestore} def +/Circle {stroke [] 0 setdash 2 copy + hpt 0 360 arc stroke Pnt} def +/CircleF {stroke [] 0 setdash hpt 0 360 arc fill} def +/C0 {BL [] 0 setdash 2 copy moveto vpt 90 450 arc} bind def +/C1 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc closepath fill + vpt 0 360 arc closepath} bind def +/C2 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C3 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C4 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 180 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C5 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc + 2 copy moveto + 2 copy vpt 180 270 arc closepath fill + vpt 0 360 arc} bind def +/C6 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C7 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C8 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 270 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C9 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 270 450 arc closepath fill + vpt 0 360 arc closepath} bind def +/C10 {BL [] 0 setdash 2 copy 2 copy moveto vpt 270 360 arc closepath fill + 2 copy moveto + 2 copy vpt 90 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C11 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 180 arc closepath fill + 2 copy moveto + 2 copy vpt 270 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C12 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 180 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C13 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc closepath fill + 2 copy moveto + 2 copy vpt 180 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C14 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 360 arc closepath fill + vpt 0 360 arc} bind def +/C15 {BL [] 0 setdash 2 copy vpt 0 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/Rec {newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto + neg 0 rlineto closepath} bind def +/Square {dup Rec} bind def +/Bsquare {vpt sub exch vpt sub exch vpt2 Square} bind def +/S0 {BL [] 0 setdash 2 copy moveto 0 vpt rlineto BL Bsquare} bind def +/S1 {BL [] 0 setdash 2 copy vpt Square fill Bsquare} bind def +/S2 {BL [] 0 setdash 2 copy exch vpt sub exch vpt Square fill Bsquare} bind def +/S3 {BL [] 0 setdash 2 copy exch vpt sub exch vpt2 vpt Rec fill Bsquare} bind def +/S4 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def +/S5 {BL [] 0 setdash 2 copy 2 copy vpt Square fill + exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def +/S6 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill Bsquare} bind def +/S7 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill + 2 copy vpt Square fill Bsquare} bind def +/S8 {BL [] 0 setdash 2 copy vpt sub vpt Square fill Bsquare} bind def +/S9 {BL [] 0 setdash 2 copy vpt sub vpt vpt2 Rec fill Bsquare} bind def +/S10 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt Square fill + Bsquare} bind def +/S11 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt2 vpt Rec fill + Bsquare} bind def +/S12 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill Bsquare} bind def +/S13 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill + 2 copy vpt Square fill Bsquare} bind def +/S14 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill + 2 copy exch vpt sub exch vpt Square fill Bsquare} bind def +/S15 {BL [] 0 setdash 2 copy Bsquare fill Bsquare} bind def +/D0 {gsave translate 45 rotate 0 0 S0 stroke grestore} bind def +/D1 {gsave translate 45 rotate 0 0 S1 stroke grestore} bind def +/D2 {gsave translate 45 rotate 0 0 S2 stroke grestore} bind def +/D3 {gsave translate 45 rotate 0 0 S3 stroke grestore} bind def +/D4 {gsave translate 45 rotate 0 0 S4 stroke grestore} bind def +/D5 {gsave translate 45 rotate 0 0 S5 stroke grestore} bind def +/D6 {gsave translate 45 rotate 0 0 S6 stroke grestore} bind def +/D7 {gsave translate 45 rotate 0 0 S7 stroke grestore} bind def +/D8 {gsave translate 45 rotate 0 0 S8 stroke grestore} bind def +/D9 {gsave translate 45 rotate 0 0 S9 stroke grestore} bind def +/D10 {gsave translate 45 rotate 0 0 S10 stroke grestore} bind def +/D11 {gsave translate 45 rotate 0 0 S11 stroke grestore} bind def +/D12 {gsave translate 45 rotate 0 0 S12 stroke grestore} bind def +/D13 {gsave translate 45 rotate 0 0 S13 stroke grestore} bind def +/D14 {gsave translate 45 rotate 0 0 S14 stroke grestore} bind def +/D15 {gsave translate 45 rotate 0 0 S15 stroke grestore} bind def +/DiaE {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath stroke} def +/BoxE {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath stroke} def +/TriUE {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath stroke} def +/TriDE {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath stroke} def +/PentE {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath stroke grestore} def +/CircE {stroke [] 0 setdash + hpt 0 360 arc stroke} def +/Opaque {gsave closepath 1 setgray fill grestore 0 setgray closepath} def +/DiaW {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V Opaque stroke} def +/BoxW {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V Opaque stroke} def +/TriUW {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V Opaque stroke} def +/TriDW {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V Opaque stroke} def +/PentW {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + Opaque stroke grestore} def +/CircW {stroke [] 0 setdash + hpt 0 360 arc Opaque stroke} def +/BoxFill {gsave Rec 1 setgray fill grestore} def +/Density { + /Fillden exch def + currentrgbcolor + /ColB exch def /ColG exch def /ColR exch def + /ColR ColR Fillden mul Fillden sub 1 add def + /ColG ColG Fillden mul Fillden sub 1 add def + /ColB ColB Fillden mul Fillden sub 1 add def + ColR ColG ColB setrgbcolor} def +/BoxColFill {gsave Rec PolyFill} def +/PolyFill {gsave Density fill grestore grestore} def +/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def +% +% PostScript Level 1 Pattern Fill routine for rectangles +% Usage: x y w h s a XX PatternFill +% x,y = lower left corner of box to be filled +% w,h = width and height of box +% a = angle in degrees between lines and x-axis +% XX = 0/1 for no/yes cross-hatch +% +/PatternFill {gsave /PFa [ 9 2 roll ] def + PFa 0 get PFa 2 get 2 div add PFa 1 get PFa 3 get 2 div add translate + PFa 2 get -2 div PFa 3 get -2 div PFa 2 get PFa 3 get Rec + TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse + clip + currentlinewidth 0.5 mul setlinewidth + /PFs PFa 2 get dup mul PFa 3 get dup mul add sqrt def + 0 0 M PFa 5 get rotate PFs -2 div dup translate + 0 1 PFs PFa 4 get div 1 add floor cvi + {PFa 4 get mul 0 M 0 PFs V} for + 0 PFa 6 get ne { + 0 1 PFs PFa 4 get div 1 add floor cvi + {PFa 4 get mul 0 2 1 roll M PFs 0 V} for + } if + stroke grestore} def +% +/languagelevel where + {pop languagelevel} {1} ifelse +dup 2 lt + {/InterpretLevel1 true def + /InterpretLevel3 false def} + {/InterpretLevel1 Level1 def + 2 gt + {/InterpretLevel3 Level3 def} + {/InterpretLevel3 false def} + ifelse } + ifelse +% +% PostScript level 2 pattern fill definitions +% +/Level2PatternFill { +/Tile8x8 {/PaintType 2 /PatternType 1 /TilingType 1 /BBox [0 0 8 8] /XStep 8 /YStep 8} + bind def +/KeepColor {currentrgbcolor [/Pattern /DeviceRGB] setcolorspace} bind def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke} +>> matrix makepattern +/Pat1 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke + 0 4 M 4 8 L 8 4 L 4 0 L 0 4 L stroke} +>> matrix makepattern +/Pat2 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 0 8 L + 8 8 L 8 0 L 0 0 L fill} +>> matrix makepattern +/Pat3 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -4 8 M 8 -4 L + 0 12 M 12 0 L stroke} +>> matrix makepattern +/Pat4 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -4 0 M 8 12 L + 0 -4 M 12 8 L stroke} +>> matrix makepattern +/Pat5 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -2 8 M 4 -4 L + 0 12 M 8 -4 L 4 12 M 10 0 L stroke} +>> matrix makepattern +/Pat6 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -2 0 M 4 12 L + 0 -4 M 8 12 L 4 -4 M 10 8 L stroke} +>> matrix makepattern +/Pat7 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 8 -2 M -4 4 L + 12 0 M -4 8 L 12 4 M 0 10 L stroke} +>> matrix makepattern +/Pat8 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 -2 M 12 4 L + -4 0 M 12 8 L -4 4 M 8 10 L stroke} +>> matrix makepattern +/Pat9 exch def +/Pattern1 {PatternBgnd KeepColor Pat1 setpattern} bind def +/Pattern2 {PatternBgnd KeepColor Pat2 setpattern} bind def +/Pattern3 {PatternBgnd KeepColor Pat3 setpattern} bind def +/Pattern4 {PatternBgnd KeepColor Landscape {Pat5} {Pat4} ifelse setpattern} bind def +/Pattern5 {PatternBgnd KeepColor Landscape {Pat4} {Pat5} ifelse setpattern} bind def +/Pattern6 {PatternBgnd KeepColor Landscape {Pat9} {Pat6} ifelse setpattern} bind def +/Pattern7 {PatternBgnd KeepColor Landscape {Pat8} {Pat7} ifelse setpattern} bind def +} def +% +% +%End of PostScript Level 2 code +% +/PatternBgnd { + TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse +} def +% +% Substitute for Level 2 pattern fill codes with +% grayscale if Level 2 support is not selected. +% +/Level1PatternFill { +/Pattern1 {0.250 Density} bind def +/Pattern2 {0.500 Density} bind def +/Pattern3 {0.750 Density} bind def +/Pattern4 {0.125 Density} bind def +/Pattern5 {0.375 Density} bind def +/Pattern6 {0.625 Density} bind def +/Pattern7 {0.875 Density} bind def +} def +% +% Now test for support of Level 2 code +% +Level1 {Level1PatternFill} {Level2PatternFill} ifelse +% +/Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont +dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall +currentdict end definefont pop +% +/MFshow { + { dup 5 get 3 ge + { 5 get 3 eq {gsave} {grestore} ifelse } + {dup dup 0 get findfont exch 1 get scalefont setfont + [ currentpoint ] exch dup 2 get 0 exch R dup 5 get 2 ne {dup dup 6 + get exch 4 get {textshow} {stringwidth pop 0 R} ifelse }if dup 5 get 0 eq + {dup 3 get {2 get neg 0 exch R pop} {pop aload pop M} ifelse} {dup 5 + get 1 eq {dup 2 get exch dup 3 get exch 6 get stringwidth pop -2 div + dup 0 R} {dup 6 get stringwidth pop -2 div 0 R 6 get + textshow 2 index {aload pop M neg 3 -1 roll neg R pop pop} {pop pop pop + pop aload pop M} ifelse }ifelse }ifelse } + ifelse } + forall} def +/Gswidth {dup type /stringtype eq {stringwidth} {pop (n) stringwidth} ifelse} def +/MFwidth {0 exch { dup 5 get 3 ge { 5 get 3 eq { 0 } { pop } ifelse } + {dup 3 get{dup dup 0 get findfont exch 1 get scalefont setfont + 6 get Gswidth pop add} {pop} ifelse} ifelse} forall} def +/MLshow { currentpoint stroke M + 0 exch R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/MRshow { currentpoint stroke M + exch dup MFwidth neg 3 -1 roll R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/MCshow { currentpoint stroke M + exch dup MFwidth -2 div 3 -1 roll R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/XYsave { [( ) 1 2 true false 3 ()] } bind def +/XYrestore { [( ) 1 2 true false 4 ()] } bind def +Level1 SuppressPDFMark or +{} { +/SDict 10 dict def +systemdict /pdfmark known not { + userdict /pdfmark systemdict /cleartomark get put +} if +SDict begin [ + /Title (spec/tmp/histogram_plot.eps) + /Subject (gnuplot plot) + /Creator (gnuplot 5.0 patchlevel 5) +% /Producer (gnuplot) +% /Keywords () + /CreationDate (Fri Nov 22 22:11:02 2019) + /DOCINFO pdfmark +end +} ifelse +% +% Support for boxed text - Ethan A Merritt May 2005 +% +/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put + userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put + /Boxing true def } def +/ExtendTextBox { Boxing + { gsave dup false charpath pathbbox + dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse + dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse + dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse + dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse + grestore } if } def +/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M + TBx1 TBxmargin sub TBy2 TBymargin add L + TBx2 TBxmargin add TBy2 TBymargin add L + TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def +/DrawTextBox { PopTextBox stroke /Boxing false def} def +/FillTextBox { gsave PopTextBox 1 1 1 setrgbcolor fill grestore /Boxing false def} def +0 0 0 0 InitTextBox +/TBxmargin 20 def +/TBymargin 20 def +/Boxing false def +/textshow { ExtendTextBox Gshow } def +% +% redundant definitions for compatibility with prologue.ps older than 5.0.2 +/LTB {BL [] LCb DL} def +/LTb {PL [] LCb DL} def +end +%%EndProlog +%%Page: 1 1 +gnudict begin +gsave +doclip +50 50 translate +0.050 0.050 scale +0 setgray +newpath +(Helvetica) findfont 140 scalefont setfont +BackgroundColor 0 lt 3 1 roll 0 lt exch 0 lt or or not {BackgroundColor C 1.000 0 0 7200.00 5040.00 BoxColFill} if +1.000 UL +LTb +LCb setrgbcolor +686 448 M +63 0 V +6198 0 R +-63 0 V +stroke +602 448 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 911 M +63 0 V +6198 0 R +-63 0 V +stroke +602 911 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 20)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 1375 M +63 0 V +6198 0 R +-63 0 V +stroke +602 1375 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 40)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 1838 M +63 0 V +6198 0 R +-63 0 V +stroke +602 1838 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 60)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 2302 M +63 0 V +6198 0 R +-63 0 V +stroke +602 2302 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 80)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 2765 M +63 0 V +6198 0 R +-63 0 V +stroke +602 2765 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 100)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 3229 M +63 0 V +6198 0 R +-63 0 V +stroke +602 3229 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 120)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 3692 M +63 0 V +6198 0 R +-63 0 V +stroke +602 3692 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 140)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 4156 M +63 0 V +6198 0 R +-63 0 V +stroke +602 4156 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 160)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 4619 M +63 0 V +6198 0 R +-63 0 V +stroke +602 4619 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 180)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 448 M +0 63 V +0 4108 R +0 -63 V +stroke +686 308 M +[ [(Helvetica) 140.0 0.0 true true 0 (-0.1)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +1938 448 M +0 63 V +0 4108 R +0 -63 V +stroke +1938 308 M +[ [(Helvetica) 140.0 0.0 true true 0 (-0.05)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +3190 448 M +0 63 V +0 4108 R +0 -63 V +stroke +3190 308 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +4443 448 M +0 63 V +0 4108 R +0 -63 V +stroke +4443 308 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0.05)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +5695 448 M +0 63 V +0 4108 R +0 -63 V +stroke +5695 308 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0.1)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +6947 448 M +0 63 V +0 4108 R +0 -63 V +stroke +6947 308 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0.15)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +1.000 UL +LTB +LCb setrgbcolor +686 4619 N +686 448 L +6261 0 V +0 4171 V +-6261 0 V +Z stroke +1.000 UP +1.000 UL +LTb +LCb setrgbcolor +LCb setrgbcolor +112 2533 M +currentpoint gsave translate -270 rotate 0 0 moveto +[ [(Helvetica) 140.0 0.0 true true 0 (frequency)] +] -46.7 MCshow +grestore +LTb +LCb setrgbcolor +3816 98 M +[ [(Helvetica) 140.0 0.0 true true 0 (x)] +] -46.7 MCshow +LTb +LCb setrgbcolor +3816 4829 M +[ [(Helvetica) 140.0 0.0 true true 0 (Histogram)] +] -46.7 MCshow +% Begin plot #1 +1.000 UL +LTb +LCb setrgbcolor +LCb setrgbcolor +6296 4486 M +[ [(Helvetica) 140.0 0.0 true true 0 (smooth frequency)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +6380 4451 N +399 0 V +0 70 V +-399 0 V +0 -70 V +Z stroke +811 448 N +0 371 V +251 0 V +0 -371 V +-251 0 V +Z stroke +1062 448 N +0 209 V +250 0 V +0 -209 V +-250 0 V +Z stroke +1312 448 N +0 301 V +251 0 V +0 -301 V +-251 0 V +Z stroke +1563 448 N +0 255 V +250 0 V +0 -255 V +-250 0 V +Z stroke +1813 448 N +0 116 V +250 0 V +0 -116 V +-250 0 V +Z stroke +2063 448 N +0 209 V +251 0 V +0 -209 V +-251 0 V +Z stroke +2314 448 N +0 487 V +250 0 V +0 -487 V +-250 0 V +Z stroke +2564 448 N +0 417 V +251 0 V +0 -417 V +-251 0 V +Z stroke +2815 448 N +0 602 V +250 0 V +0 -602 V +-250 0 V +Z stroke +3065 448 N +0 3754 V +251 0 V +0 -3754 V +-251 0 V +Z stroke +3316 448 N +0 742 V +250 0 V +0 -742 V +-250 0 V +Z stroke +3566 448 N +0 440 V +251 0 V +0 -440 V +-251 0 V +Z stroke +3817 448 N +0 417 V +250 0 V +0 -417 V +-250 0 V +Z stroke +4067 448 N +0 301 V +250 0 V +0 -301 V +-250 0 V +Z stroke +4317 448 N +0 324 V +251 0 V +0 -324 V +-251 0 V +Z stroke +4568 448 N +0 278 V +250 0 V +0 -278 V +-250 0 V +Z stroke +4818 448 N +0 348 V +251 0 V +0 -348 V +-251 0 V +Z stroke +5069 448 N +0 394 V +250 0 V +0 -394 V +-250 0 V +Z stroke +5319 448 N +0 348 V +251 0 V +0 -348 V +-251 0 V +Z stroke +5570 448 N +0 463 V +250 0 V +0 -463 V +-250 0 V +Z stroke +5820 448 N +0 834 V +125 0 V +0 -834 V +-125 0 V +Z stroke +% End plot #1 +2.000 UL +LTb +LCb setrgbcolor +1.000 UL +LTB +LCb setrgbcolor +686 4619 N +686 448 L +6261 0 V +0 4171 V +-6261 0 V +Z stroke +1.000 UP +1.000 UL +LTb +LCb setrgbcolor +stroke +grestore +end +showpage +%%Trailer +%%DocumentFonts: Helvetica diff --git a/spec/integration/histtest_spec.rb b/spec/integration/histtest_spec.rb index 47d7aea..2dda5f3 100644 --- a/spec/integration/histtest_spec.rb +++ b/spec/integration/histtest_spec.rb @@ -12,8 +12,10 @@ before do path = file_path + RandomGenerator.seed(0.17) + collection = (0..500).collect do |_v| - (rand()-0.5)**3 + (RandomGenerator.rand-0.5)**3 end Gnuplot.open do |gp| diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 051338c..38530b9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,6 +20,10 @@ require "gnuplot" +support_files = File.expand_path('spec/support/**/*.rb') + +Dir[support_files].sort.each { |file| require file } + RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest diff --git a/spec/support/models/random_generator.rb b/spec/support/models/random_generator.rb new file mode 100644 index 0000000..96e752e --- /dev/null +++ b/spec/support/models/random_generator.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class RandomGenerator + KAPA = 3.95578 + + class << self + def rand + @rand ||= Random.rand + + @rand = KAPA * @rand * (1 - @rand) + end + + def seed(value) + @rand = value.abs % 1 + @rand = nil if @rand == 0 + end + end +end From 093b6bdee6dc62eef8b345faa2be03d8e5b83354 Mon Sep 17 00:00:00 2001 From: darthjee Date: Fri, 22 Nov 2019 23:19:25 +0100 Subject: [PATCH 59/79] Add sin wave spec --- spec/fixtures/plots/sin_wave_plot.eps | 857 ++++++++++++++++++++++++++ spec/integration/histtest_spec.rb | 2 +- spec/integration/multtest_spec.rb | 57 ++ test/multtest.rb | 10 +- 4 files changed, 920 insertions(+), 6 deletions(-) create mode 100644 spec/fixtures/plots/sin_wave_plot.eps create mode 100644 spec/integration/multtest_spec.rb diff --git a/spec/fixtures/plots/sin_wave_plot.eps b/spec/fixtures/plots/sin_wave_plot.eps new file mode 100644 index 0000000..4dea1f4 --- /dev/null +++ b/spec/fixtures/plots/sin_wave_plot.eps @@ -0,0 +1,857 @@ +%!PS-Adobe-2.0 EPSF-2.0 +%%Title: spec/tmp/sin_wave_plot.eps +%%Creator: gnuplot 5.0 patchlevel 5 +%%CreationDate: Fri Nov 22 22:17:59 2019 +%%DocumentFonts: (atend) +%%BoundingBox: 50 50 410 302 +%%EndComments +%%BeginProlog +/gnudict 256 dict def +gnudict begin +% +% The following true/false flags may be edited by hand if desired. +% The unit line width and grayscale image gamma correction may also be changed. +% +/Color false def +/Blacktext false def +/Solid false def +/Dashlength 1 def +/Landscape false def +/Level1 false def +/Level3 false def +/Rounded false def +/ClipToBoundingBox false def +/SuppressPDFMark false def +/TransparentPatterns false def +/gnulinewidth 5.000 def +/userlinewidth gnulinewidth def +/Gamma 1.0 def +/BackgroundColor {-1.000 -1.000 -1.000} def +% +/vshift -46 def +/dl1 { + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if +} def +/dl2 { + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + Rounded { currentlinewidth 0.75 mul add } if +} def +/hpt_ 31.5 def +/vpt_ 31.5 def +/hpt hpt_ def +/vpt vpt_ def +/doclip { + ClipToBoundingBox { + newpath 50 50 moveto 410 50 lineto 410 302 lineto 50 302 lineto closepath + clip + } if +} def +% +% Gnuplot Prolog Version 5.1 (Oct 2015) +% +%/SuppressPDFMark true def +% +/M {moveto} bind def +/L {lineto} bind def +/R {rmoveto} bind def +/V {rlineto} bind def +/N {newpath moveto} bind def +/Z {closepath} bind def +/C {setrgbcolor} bind def +/f {rlineto fill} bind def +/g {setgray} bind def +/Gshow {show} def % May be redefined later in the file to support UTF-8 +/vpt2 vpt 2 mul def +/hpt2 hpt 2 mul def +/Lshow {currentpoint stroke M 0 vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/Rshow {currentpoint stroke M dup stringwidth pop neg vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def + /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def +/DL {Color {setrgbcolor Solid {pop []} if 0 setdash} + {pop pop pop 0 setgray Solid {pop []} if 0 setdash} ifelse} def +/BL {stroke userlinewidth 2 mul setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +/AL {stroke userlinewidth 2 div setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +/UL {dup gnulinewidth mul /userlinewidth exch def + dup 1 lt {pop 1} if 10 mul /udl exch def} def +/PL {stroke userlinewidth setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +3.8 setmiterlimit +% Classic Line colors (version 5.0) +/LCw {1 1 1} def +/LCb {0 0 0} def +/LCa {0 0 0} def +/LC0 {1 0 0} def +/LC1 {0 1 0} def +/LC2 {0 0 1} def +/LC3 {1 0 1} def +/LC4 {0 1 1} def +/LC5 {1 1 0} def +/LC6 {0 0 0} def +/LC7 {1 0.3 0} def +/LC8 {0.5 0.5 0.5} def +% Default dash patterns (version 5.0) +/LTB {BL [] LCb DL} def +/LTw {PL [] 1 setgray} def +/LTb {PL [] LCb DL} def +/LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def +/LT0 {PL [] LC0 DL} def +/LT1 {PL [2 dl1 3 dl2] LC1 DL} def +/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def +/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def +/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [4 dl1 2 dl2] LC5 DL} def +/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def +/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def +/SL {[] 0 setdash} def +/Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def +/Dia {stroke [] 0 setdash 2 copy vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath stroke + Pnt} def +/Pls {stroke [] 0 setdash vpt sub M 0 vpt2 V + currentpoint stroke M + hpt neg vpt neg R hpt2 0 V stroke + } def +/Box {stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath stroke + Pnt} def +/Crs {stroke [] 0 setdash exch hpt sub exch vpt add M + hpt2 vpt2 neg V currentpoint stroke M + hpt2 neg 0 R hpt2 vpt2 V stroke} def +/TriU {stroke [] 0 setdash 2 copy vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath stroke + Pnt} def +/Star {2 copy Pls Crs} def +/BoxF {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath fill} def +/TriUF {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath fill} def +/TriD {stroke [] 0 setdash 2 copy vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath stroke + Pnt} def +/TriDF {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath fill} def +/DiaF {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath fill} def +/Pent {stroke [] 0 setdash 2 copy gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath stroke grestore Pnt} def +/PentF {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath fill grestore} def +/Circle {stroke [] 0 setdash 2 copy + hpt 0 360 arc stroke Pnt} def +/CircleF {stroke [] 0 setdash hpt 0 360 arc fill} def +/C0 {BL [] 0 setdash 2 copy moveto vpt 90 450 arc} bind def +/C1 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc closepath fill + vpt 0 360 arc closepath} bind def +/C2 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C3 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C4 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 180 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C5 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc + 2 copy moveto + 2 copy vpt 180 270 arc closepath fill + vpt 0 360 arc} bind def +/C6 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C7 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C8 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 270 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C9 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 270 450 arc closepath fill + vpt 0 360 arc closepath} bind def +/C10 {BL [] 0 setdash 2 copy 2 copy moveto vpt 270 360 arc closepath fill + 2 copy moveto + 2 copy vpt 90 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C11 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 180 arc closepath fill + 2 copy moveto + 2 copy vpt 270 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C12 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 180 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C13 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc closepath fill + 2 copy moveto + 2 copy vpt 180 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C14 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 360 arc closepath fill + vpt 0 360 arc} bind def +/C15 {BL [] 0 setdash 2 copy vpt 0 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/Rec {newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto + neg 0 rlineto closepath} bind def +/Square {dup Rec} bind def +/Bsquare {vpt sub exch vpt sub exch vpt2 Square} bind def +/S0 {BL [] 0 setdash 2 copy moveto 0 vpt rlineto BL Bsquare} bind def +/S1 {BL [] 0 setdash 2 copy vpt Square fill Bsquare} bind def +/S2 {BL [] 0 setdash 2 copy exch vpt sub exch vpt Square fill Bsquare} bind def +/S3 {BL [] 0 setdash 2 copy exch vpt sub exch vpt2 vpt Rec fill Bsquare} bind def +/S4 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def +/S5 {BL [] 0 setdash 2 copy 2 copy vpt Square fill + exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def +/S6 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill Bsquare} bind def +/S7 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill + 2 copy vpt Square fill Bsquare} bind def +/S8 {BL [] 0 setdash 2 copy vpt sub vpt Square fill Bsquare} bind def +/S9 {BL [] 0 setdash 2 copy vpt sub vpt vpt2 Rec fill Bsquare} bind def +/S10 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt Square fill + Bsquare} bind def +/S11 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt2 vpt Rec fill + Bsquare} bind def +/S12 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill Bsquare} bind def +/S13 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill + 2 copy vpt Square fill Bsquare} bind def +/S14 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill + 2 copy exch vpt sub exch vpt Square fill Bsquare} bind def +/S15 {BL [] 0 setdash 2 copy Bsquare fill Bsquare} bind def +/D0 {gsave translate 45 rotate 0 0 S0 stroke grestore} bind def +/D1 {gsave translate 45 rotate 0 0 S1 stroke grestore} bind def +/D2 {gsave translate 45 rotate 0 0 S2 stroke grestore} bind def +/D3 {gsave translate 45 rotate 0 0 S3 stroke grestore} bind def +/D4 {gsave translate 45 rotate 0 0 S4 stroke grestore} bind def +/D5 {gsave translate 45 rotate 0 0 S5 stroke grestore} bind def +/D6 {gsave translate 45 rotate 0 0 S6 stroke grestore} bind def +/D7 {gsave translate 45 rotate 0 0 S7 stroke grestore} bind def +/D8 {gsave translate 45 rotate 0 0 S8 stroke grestore} bind def +/D9 {gsave translate 45 rotate 0 0 S9 stroke grestore} bind def +/D10 {gsave translate 45 rotate 0 0 S10 stroke grestore} bind def +/D11 {gsave translate 45 rotate 0 0 S11 stroke grestore} bind def +/D12 {gsave translate 45 rotate 0 0 S12 stroke grestore} bind def +/D13 {gsave translate 45 rotate 0 0 S13 stroke grestore} bind def +/D14 {gsave translate 45 rotate 0 0 S14 stroke grestore} bind def +/D15 {gsave translate 45 rotate 0 0 S15 stroke grestore} bind def +/DiaE {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath stroke} def +/BoxE {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath stroke} def +/TriUE {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath stroke} def +/TriDE {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath stroke} def +/PentE {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath stroke grestore} def +/CircE {stroke [] 0 setdash + hpt 0 360 arc stroke} def +/Opaque {gsave closepath 1 setgray fill grestore 0 setgray closepath} def +/DiaW {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V Opaque stroke} def +/BoxW {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V Opaque stroke} def +/TriUW {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V Opaque stroke} def +/TriDW {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V Opaque stroke} def +/PentW {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + Opaque stroke grestore} def +/CircW {stroke [] 0 setdash + hpt 0 360 arc Opaque stroke} def +/BoxFill {gsave Rec 1 setgray fill grestore} def +/Density { + /Fillden exch def + currentrgbcolor + /ColB exch def /ColG exch def /ColR exch def + /ColR ColR Fillden mul Fillden sub 1 add def + /ColG ColG Fillden mul Fillden sub 1 add def + /ColB ColB Fillden mul Fillden sub 1 add def + ColR ColG ColB setrgbcolor} def +/BoxColFill {gsave Rec PolyFill} def +/PolyFill {gsave Density fill grestore grestore} def +/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def +% +% PostScript Level 1 Pattern Fill routine for rectangles +% Usage: x y w h s a XX PatternFill +% x,y = lower left corner of box to be filled +% w,h = width and height of box +% a = angle in degrees between lines and x-axis +% XX = 0/1 for no/yes cross-hatch +% +/PatternFill {gsave /PFa [ 9 2 roll ] def + PFa 0 get PFa 2 get 2 div add PFa 1 get PFa 3 get 2 div add translate + PFa 2 get -2 div PFa 3 get -2 div PFa 2 get PFa 3 get Rec + TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse + clip + currentlinewidth 0.5 mul setlinewidth + /PFs PFa 2 get dup mul PFa 3 get dup mul add sqrt def + 0 0 M PFa 5 get rotate PFs -2 div dup translate + 0 1 PFs PFa 4 get div 1 add floor cvi + {PFa 4 get mul 0 M 0 PFs V} for + 0 PFa 6 get ne { + 0 1 PFs PFa 4 get div 1 add floor cvi + {PFa 4 get mul 0 2 1 roll M PFs 0 V} for + } if + stroke grestore} def +% +/languagelevel where + {pop languagelevel} {1} ifelse +dup 2 lt + {/InterpretLevel1 true def + /InterpretLevel3 false def} + {/InterpretLevel1 Level1 def + 2 gt + {/InterpretLevel3 Level3 def} + {/InterpretLevel3 false def} + ifelse } + ifelse +% +% PostScript level 2 pattern fill definitions +% +/Level2PatternFill { +/Tile8x8 {/PaintType 2 /PatternType 1 /TilingType 1 /BBox [0 0 8 8] /XStep 8 /YStep 8} + bind def +/KeepColor {currentrgbcolor [/Pattern /DeviceRGB] setcolorspace} bind def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke} +>> matrix makepattern +/Pat1 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke + 0 4 M 4 8 L 8 4 L 4 0 L 0 4 L stroke} +>> matrix makepattern +/Pat2 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 0 8 L + 8 8 L 8 0 L 0 0 L fill} +>> matrix makepattern +/Pat3 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -4 8 M 8 -4 L + 0 12 M 12 0 L stroke} +>> matrix makepattern +/Pat4 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -4 0 M 8 12 L + 0 -4 M 12 8 L stroke} +>> matrix makepattern +/Pat5 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -2 8 M 4 -4 L + 0 12 M 8 -4 L 4 12 M 10 0 L stroke} +>> matrix makepattern +/Pat6 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -2 0 M 4 12 L + 0 -4 M 8 12 L 4 -4 M 10 8 L stroke} +>> matrix makepattern +/Pat7 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 8 -2 M -4 4 L + 12 0 M -4 8 L 12 4 M 0 10 L stroke} +>> matrix makepattern +/Pat8 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 -2 M 12 4 L + -4 0 M 12 8 L -4 4 M 8 10 L stroke} +>> matrix makepattern +/Pat9 exch def +/Pattern1 {PatternBgnd KeepColor Pat1 setpattern} bind def +/Pattern2 {PatternBgnd KeepColor Pat2 setpattern} bind def +/Pattern3 {PatternBgnd KeepColor Pat3 setpattern} bind def +/Pattern4 {PatternBgnd KeepColor Landscape {Pat5} {Pat4} ifelse setpattern} bind def +/Pattern5 {PatternBgnd KeepColor Landscape {Pat4} {Pat5} ifelse setpattern} bind def +/Pattern6 {PatternBgnd KeepColor Landscape {Pat9} {Pat6} ifelse setpattern} bind def +/Pattern7 {PatternBgnd KeepColor Landscape {Pat8} {Pat7} ifelse setpattern} bind def +} def +% +% +%End of PostScript Level 2 code +% +/PatternBgnd { + TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse +} def +% +% Substitute for Level 2 pattern fill codes with +% grayscale if Level 2 support is not selected. +% +/Level1PatternFill { +/Pattern1 {0.250 Density} bind def +/Pattern2 {0.500 Density} bind def +/Pattern3 {0.750 Density} bind def +/Pattern4 {0.125 Density} bind def +/Pattern5 {0.375 Density} bind def +/Pattern6 {0.625 Density} bind def +/Pattern7 {0.875 Density} bind def +} def +% +% Now test for support of Level 2 code +% +Level1 {Level1PatternFill} {Level2PatternFill} ifelse +% +/Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont +dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall +currentdict end definefont pop +% +/MFshow { + { dup 5 get 3 ge + { 5 get 3 eq {gsave} {grestore} ifelse } + {dup dup 0 get findfont exch 1 get scalefont setfont + [ currentpoint ] exch dup 2 get 0 exch R dup 5 get 2 ne {dup dup 6 + get exch 4 get {textshow} {stringwidth pop 0 R} ifelse }if dup 5 get 0 eq + {dup 3 get {2 get neg 0 exch R pop} {pop aload pop M} ifelse} {dup 5 + get 1 eq {dup 2 get exch dup 3 get exch 6 get stringwidth pop -2 div + dup 0 R} {dup 6 get stringwidth pop -2 div 0 R 6 get + textshow 2 index {aload pop M neg 3 -1 roll neg R pop pop} {pop pop pop + pop aload pop M} ifelse }ifelse }ifelse } + ifelse } + forall} def +/Gswidth {dup type /stringtype eq {stringwidth} {pop (n) stringwidth} ifelse} def +/MFwidth {0 exch { dup 5 get 3 ge { 5 get 3 eq { 0 } { pop } ifelse } + {dup 3 get{dup dup 0 get findfont exch 1 get scalefont setfont + 6 get Gswidth pop add} {pop} ifelse} ifelse} forall} def +/MLshow { currentpoint stroke M + 0 exch R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/MRshow { currentpoint stroke M + exch dup MFwidth neg 3 -1 roll R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/MCshow { currentpoint stroke M + exch dup MFwidth -2 div 3 -1 roll R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/XYsave { [( ) 1 2 true false 3 ()] } bind def +/XYrestore { [( ) 1 2 true false 4 ()] } bind def +Level1 SuppressPDFMark or +{} { +/SDict 10 dict def +systemdict /pdfmark known not { + userdict /pdfmark systemdict /cleartomark get put +} if +SDict begin [ + /Title (spec/tmp/sin_wave_plot.eps) + /Subject (gnuplot plot) + /Creator (gnuplot 5.0 patchlevel 5) +% /Producer (gnuplot) +% /Keywords () + /CreationDate (Fri Nov 22 22:17:59 2019) + /DOCINFO pdfmark +end +} ifelse +% +% Support for boxed text - Ethan A Merritt May 2005 +% +/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put + userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put + /Boxing true def } def +/ExtendTextBox { Boxing + { gsave dup false charpath pathbbox + dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse + dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse + dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse + dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse + grestore } if } def +/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M + TBx1 TBxmargin sub TBy2 TBymargin add L + TBx2 TBxmargin add TBy2 TBymargin add L + TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def +/DrawTextBox { PopTextBox stroke /Boxing false def} def +/FillTextBox { gsave PopTextBox 1 1 1 setrgbcolor fill grestore /Boxing false def} def +0 0 0 0 InitTextBox +/TBxmargin 20 def +/TBymargin 20 def +/Boxing false def +/textshow { ExtendTextBox Gshow } def +% +% redundant definitions for compatibility with prologue.ps older than 5.0.2 +/LTB {BL [] LCb DL} def +/LTb {PL [] LCb DL} def +end +%%EndProlog +%%Page: 1 1 +gnudict begin +gsave +doclip +50 50 translate +0.050 0.050 scale +0 setgray +newpath +(Helvetica) findfont 140 scalefont setfont +BackgroundColor 0 lt 3 1 roll 0 lt exch 0 lt or or not {BackgroundColor C 1.000 0 0 7200.00 5040.00 BoxColFill} if +1.000 UL +LTb +LCb setrgbcolor +686 448 M +63 0 V +6198 0 R +-63 0 V +stroke +602 448 M +[ [(Helvetica) 140.0 0.0 true true 0 (-20)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 1143 M +63 0 V +6198 0 R +-63 0 V +stroke +602 1143 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 1838 M +63 0 V +6198 0 R +-63 0 V +stroke +602 1838 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 20)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 2534 M +63 0 V +6198 0 R +-63 0 V +stroke +602 2534 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 40)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 3229 M +63 0 V +6198 0 R +-63 0 V +stroke +602 3229 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 60)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 3924 M +63 0 V +6198 0 R +-63 0 V +stroke +602 3924 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 80)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 4619 M +63 0 V +6198 0 R +-63 0 V +stroke +602 4619 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 100)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 448 M +0 63 V +0 4108 R +0 -63 V +stroke +686 308 M +[ [(Helvetica) 140.0 0.0 true true 0 (-10)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +2251 448 M +0 63 V +0 4108 R +0 -63 V +stroke +2251 308 M +[ [(Helvetica) 140.0 0.0 true true 0 (-5)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +3817 448 M +0 63 V +0 4108 R +0 -63 V +stroke +3817 308 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +5382 448 M +0 63 V +0 4108 R +0 -63 V +stroke +5382 308 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 5)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +6947 448 M +0 63 V +0 4108 R +0 -63 V +stroke +6947 308 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 10)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +1.000 UL +LTB +LCb setrgbcolor +686 4619 N +686 448 L +6261 0 V +0 4171 V +-6261 0 V +Z stroke +1.000 UP +1.000 UL +LTb +LCb setrgbcolor +LCb setrgbcolor +112 2533 M +currentpoint gsave translate -270 rotate 0 0 moveto +[ [(Helvetica) 140.0 0.0 true true 0 (x)] +] -46.7 MCshow +grestore +LTb +LCb setrgbcolor +3816 98 M +[ [(Helvetica) 140.0 0.0 true true 0 (sin\(x\))] +] -46.7 MCshow +LTb +LCb setrgbcolor +3816 4829 M +[ [(Helvetica) 140.0 0.0 true true 0 (Sin Wave Example)] +] -46.7 MCshow +% Begin plot #1 +4.000 UL +LTb +LCb setrgbcolor +LCb setrgbcolor +6296 4486 M +[ [(Helvetica) 140.0 0.0 true true 0 (String function)] +] -46.7 MRshow +4.000 UL +LTb +LCb setrgbcolor +6380 4486 M +399 0 V +686 1162 M +63 -6 V +63 -7 V +64 -7 V +63 -7 V +63 -6 V +63 -7 V +64 -5 V +63 -4 V +63 -3 V +63 -1 V +64 0 V +63 1 V +63 2 V +63 4 V +64 5 V +63 6 V +63 6 V +63 7 V +64 7 V +63 7 V +63 7 V +63 5 V +64 5 V +63 4 V +63 2 V +63 1 V +64 -1 V +63 -1 V +63 -4 V +63 -4 V +64 -5 V +63 -6 V +63 -7 V +63 -7 V +63 -7 V +64 -7 V +63 -6 V +63 -5 V +63 -4 V +64 -4 V +63 -1 V +63 -1 V +63 2 V +64 2 V +63 4 V +63 5 V +63 5 V +64 7 V +63 7 V +63 7 V +63 7 V +64 6 V +63 6 V +63 5 V +63 3 V +64 3 V +63 1 V +63 0 V +63 -2 V +64 -3 V +63 -4 V +63 -6 V +63 -6 V +64 -7 V +63 -6 V +63 -7 V +63 -7 V +63 -6 V +64 -6 V +63 -4 V +63 -3 V +63 -2 V +64 -1 V +63 1 V +63 3 V +63 3 V +64 5 V +63 6 V +63 6 V +63 7 V +64 7 V +63 7 V +63 6 V +63 6 V +64 5 V +63 4 V +63 3 V +63 1 V +64 0 V +63 -2 V +63 -3 V +63 -4 V +64 -5 V +63 -6 V +63 -7 V +63 -7 V +64 -7 V +63 -7 V +63 -6 V +% End plot #1 +% Begin plot #2 +1.000 UP +stroke +1.000 UL +LTb +LT1 +LCb setrgbcolor +LCb setrgbcolor +6296 4346 M +[ [(Helvetica) 140.0 0.0 true true 0 (Array data)] +] -46.7 MRshow +1.000 UP +1.000 UL +LTb +LT1 +LCb setrgbcolor +6380 4346 M +399 0 V +3817 1143 M +313 35 V +313 104 V +313 174 V +313 243 V +313 313 V +313 382 V +313 452 V +313 522 V +313 591 V +313 660 V +3817 1143 Pls +4130 1178 Pls +4443 1282 Pls +4756 1456 Pls +5069 1699 Pls +5382 2012 Pls +5695 2394 Pls +6008 2846 Pls +6321 3368 Pls +6634 3959 Pls +6947 4619 Pls +6579 4346 Pls +% End plot #2 +2.000 UL +LTb +LCb setrgbcolor +1.000 UL +LTB +LCb setrgbcolor +686 4619 N +686 448 L +6261 0 V +0 4171 V +-6261 0 V +Z stroke +1.000 UP +1.000 UL +LTb +LCb setrgbcolor +stroke +grestore +end +showpage +%%Trailer +%%DocumentFonts: Helvetica diff --git a/spec/integration/histtest_spec.rb b/spec/integration/histtest_spec.rb index 2dda5f3..3cc98fa 100644 --- a/spec/integration/histtest_spec.rb +++ b/spec/integration/histtest_spec.rb @@ -14,7 +14,7 @@ path = file_path RandomGenerator.seed(0.17) - collection = (0..500).collect do |_v| + collection = (0..500).collect do (RandomGenerator.rand-0.5)**3 end diff --git a/spec/integration/multtest_spec.rb b/spec/integration/multtest_spec.rb new file mode 100644 index 0000000..41d27d0 --- /dev/null +++ b/spec/integration/multtest_spec.rb @@ -0,0 +1,57 @@ +describe "Sin Wave Plot Example" do + let(:file_path) { 'spec/tmp/sin_wave_plot.eps' } + let(:fixture_path) { 'spec/fixtures/plots/sin_wave_plot.eps' } + + let(:file_content) do + File.read(file_path).gsub(/CreationDate.*/, "") + end + + let(:fixture_content) do + File.read(fixture_path).gsub(/CreationDate.*/, "") + end + + before do + path = file_path + + Gnuplot.open do |gp| + Gnuplot::Plot.new( gp ) do |plot| + + plot.xrange "[-10:10]" + plot.title "Sin Wave Example" + plot.ylabel "x" + plot.xlabel "sin(x)" + + plot.term "postscript eps" + plot.output path + + x = (0..50).collect { |v| v.to_f } + y = x.collect { |v| v ** 2 } + + plot.data = [ + Gnuplot::DataSet.new( "sin(x)" ) { |ds| + ds.with = "lines" + ds.title = "String function" + ds.linewidth = 4 + }, + + Gnuplot::DataSet.new( [x, y] ) { |ds| + ds.with = "linespoints" + ds.title = "Array data" + } + ] + + end + + end + + end + + after do + File.delete(file_path) + end + + it "plots expected file" do + expect(file_content).to eq(fixture_content) + end +end + diff --git a/test/multtest.rb b/test/multtest.rb index 3bf4983..dcd06c1 100644 --- a/test/multtest.rb +++ b/test/multtest.rb @@ -14,14 +14,14 @@ plot.data = [ Gnuplot::DataSet.new( "sin(x)" ) { |ds| - ds.with = "lines" - ds.title = "String function" - ds.linewidth = 4 + ds.with = "lines" + ds.title = "String function" + ds.linewidth = 4 }, Gnuplot::DataSet.new( [x, y] ) { |ds| - ds.with = "linespoints" - ds.title = "Array data" + ds.with = "linespoints" + ds.title = "Array data" } ] From 15e80d890f08e9b7d78321657528af5a4ccacfc6 Mon Sep 17 00:00:00 2001 From: darthjee Date: Fri, 22 Nov 2019 23:28:26 +0100 Subject: [PATCH 60/79] Rename test --- .../plots/{sin_wave_plot.eps => multtest_plot.eps} | 8 ++++---- spec/integration/multtest_spec.rb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename spec/fixtures/plots/{sin_wave_plot.eps => multtest_plot.eps} (99%) diff --git a/spec/fixtures/plots/sin_wave_plot.eps b/spec/fixtures/plots/multtest_plot.eps similarity index 99% rename from spec/fixtures/plots/sin_wave_plot.eps rename to spec/fixtures/plots/multtest_plot.eps index 4dea1f4..7575c79 100644 --- a/spec/fixtures/plots/sin_wave_plot.eps +++ b/spec/fixtures/plots/multtest_plot.eps @@ -1,7 +1,7 @@ %!PS-Adobe-2.0 EPSF-2.0 -%%Title: spec/tmp/sin_wave_plot.eps +%%Title: spec/tmp/multtest_plot.eps %%Creator: gnuplot 5.0 patchlevel 5 -%%CreationDate: Fri Nov 22 22:17:59 2019 +%%CreationDate: Fri Nov 22 22:28:48 2019 %%DocumentFonts: (atend) %%BoundingBox: 50 50 410 302 %%EndComments @@ -464,12 +464,12 @@ systemdict /pdfmark known not { userdict /pdfmark systemdict /cleartomark get put } if SDict begin [ - /Title (spec/tmp/sin_wave_plot.eps) + /Title (spec/tmp/multtest_plot.eps) /Subject (gnuplot plot) /Creator (gnuplot 5.0 patchlevel 5) % /Producer (gnuplot) % /Keywords () - /CreationDate (Fri Nov 22 22:17:59 2019) + /CreationDate (Fri Nov 22 22:28:48 2019) /DOCINFO pdfmark end } ifelse diff --git a/spec/integration/multtest_spec.rb b/spec/integration/multtest_spec.rb index 41d27d0..31c5923 100644 --- a/spec/integration/multtest_spec.rb +++ b/spec/integration/multtest_spec.rb @@ -1,6 +1,6 @@ -describe "Sin Wave Plot Example" do - let(:file_path) { 'spec/tmp/sin_wave_plot.eps' } - let(:fixture_path) { 'spec/fixtures/plots/sin_wave_plot.eps' } +describe "Multtest Plot Example" do + let(:file_path) { 'spec/tmp/multtest_plot.eps' } + let(:fixture_path) { 'spec/fixtures/plots/multtest_plot.eps' } let(:file_content) do File.read(file_path).gsub(/CreationDate.*/, "") @@ -47,7 +47,7 @@ end after do - File.delete(file_path) + File.delete(file_path) end it "plots expected file" do From 53369f7669c702ea9913614ad8144ac541828fbf Mon Sep 17 00:00:00 2001 From: darthjee Date: Fri, 22 Nov 2019 23:31:22 +0100 Subject: [PATCH 61/79] Add sinwave spec --- spec/fixtures/plots/sin_wave_plot.eps | 862 ++++++++++++++++++++++++++ spec/integration/sinwave_spec.rb | 46 ++ 2 files changed, 908 insertions(+) create mode 100644 spec/fixtures/plots/sin_wave_plot.eps create mode 100644 spec/integration/sinwave_spec.rb diff --git a/spec/fixtures/plots/sin_wave_plot.eps b/spec/fixtures/plots/sin_wave_plot.eps new file mode 100644 index 0000000..f30514a --- /dev/null +++ b/spec/fixtures/plots/sin_wave_plot.eps @@ -0,0 +1,862 @@ +%!PS-Adobe-2.0 EPSF-2.0 +%%Title: spec/tmp/sin_wave_plot.eps +%%Creator: gnuplot 5.0 patchlevel 5 +%%CreationDate: Fri Nov 22 22:30:52 2019 +%%DocumentFonts: (atend) +%%BoundingBox: 50 50 410 302 +%%EndComments +%%BeginProlog +/gnudict 256 dict def +gnudict begin +% +% The following true/false flags may be edited by hand if desired. +% The unit line width and grayscale image gamma correction may also be changed. +% +/Color false def +/Blacktext false def +/Solid false def +/Dashlength 1 def +/Landscape false def +/Level1 false def +/Level3 false def +/Rounded false def +/ClipToBoundingBox false def +/SuppressPDFMark false def +/TransparentPatterns false def +/gnulinewidth 5.000 def +/userlinewidth gnulinewidth def +/Gamma 1.0 def +/BackgroundColor {-1.000 -1.000 -1.000} def +% +/vshift -46 def +/dl1 { + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if +} def +/dl2 { + 10.0 Dashlength userlinewidth gnulinewidth div mul mul mul + Rounded { currentlinewidth 0.75 mul add } if +} def +/hpt_ 31.5 def +/vpt_ 31.5 def +/hpt hpt_ def +/vpt vpt_ def +/doclip { + ClipToBoundingBox { + newpath 50 50 moveto 410 50 lineto 410 302 lineto 50 302 lineto closepath + clip + } if +} def +% +% Gnuplot Prolog Version 5.1 (Oct 2015) +% +%/SuppressPDFMark true def +% +/M {moveto} bind def +/L {lineto} bind def +/R {rmoveto} bind def +/V {rlineto} bind def +/N {newpath moveto} bind def +/Z {closepath} bind def +/C {setrgbcolor} bind def +/f {rlineto fill} bind def +/g {setgray} bind def +/Gshow {show} def % May be redefined later in the file to support UTF-8 +/vpt2 vpt 2 mul def +/hpt2 hpt 2 mul def +/Lshow {currentpoint stroke M 0 vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/Rshow {currentpoint stroke M dup stringwidth pop neg vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R + Blacktext {gsave 0 setgray textshow grestore} {textshow} ifelse} def +/UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def + /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def +/DL {Color {setrgbcolor Solid {pop []} if 0 setdash} + {pop pop pop 0 setgray Solid {pop []} if 0 setdash} ifelse} def +/BL {stroke userlinewidth 2 mul setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +/AL {stroke userlinewidth 2 div setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +/UL {dup gnulinewidth mul /userlinewidth exch def + dup 1 lt {pop 1} if 10 mul /udl exch def} def +/PL {stroke userlinewidth setlinewidth + Rounded {1 setlinejoin 1 setlinecap} if} def +3.8 setmiterlimit +% Classic Line colors (version 5.0) +/LCw {1 1 1} def +/LCb {0 0 0} def +/LCa {0 0 0} def +/LC0 {1 0 0} def +/LC1 {0 1 0} def +/LC2 {0 0 1} def +/LC3 {1 0 1} def +/LC4 {0 1 1} def +/LC5 {1 1 0} def +/LC6 {0 0 0} def +/LC7 {1 0.3 0} def +/LC8 {0.5 0.5 0.5} def +% Default dash patterns (version 5.0) +/LTB {BL [] LCb DL} def +/LTw {PL [] 1 setgray} def +/LTb {PL [] LCb DL} def +/LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def +/LT0 {PL [] LC0 DL} def +/LT1 {PL [2 dl1 3 dl2] LC1 DL} def +/LT2 {PL [1 dl1 1.5 dl2] LC2 DL} def +/LT3 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC3 DL} def +/LT4 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def +/LT5 {PL [4 dl1 2 dl2] LC5 DL} def +/LT6 {PL [1.5 dl1 1.5 dl2 1.5 dl1 1.5 dl2 1.5 dl1 6 dl2] LC6 DL} def +/LT7 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC7 DL} def +/LT8 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC8 DL} def +/SL {[] 0 setdash} def +/Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def +/Dia {stroke [] 0 setdash 2 copy vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath stroke + Pnt} def +/Pls {stroke [] 0 setdash vpt sub M 0 vpt2 V + currentpoint stroke M + hpt neg vpt neg R hpt2 0 V stroke + } def +/Box {stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath stroke + Pnt} def +/Crs {stroke [] 0 setdash exch hpt sub exch vpt add M + hpt2 vpt2 neg V currentpoint stroke M + hpt2 neg 0 R hpt2 vpt2 V stroke} def +/TriU {stroke [] 0 setdash 2 copy vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath stroke + Pnt} def +/Star {2 copy Pls Crs} def +/BoxF {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath fill} def +/TriUF {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath fill} def +/TriD {stroke [] 0 setdash 2 copy vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath stroke + Pnt} def +/TriDF {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath fill} def +/DiaF {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath fill} def +/Pent {stroke [] 0 setdash 2 copy gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath stroke grestore Pnt} def +/PentF {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath fill grestore} def +/Circle {stroke [] 0 setdash 2 copy + hpt 0 360 arc stroke Pnt} def +/CircleF {stroke [] 0 setdash hpt 0 360 arc fill} def +/C0 {BL [] 0 setdash 2 copy moveto vpt 90 450 arc} bind def +/C1 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc closepath fill + vpt 0 360 arc closepath} bind def +/C2 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C3 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C4 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 180 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C5 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc + 2 copy moveto + 2 copy vpt 180 270 arc closepath fill + vpt 0 360 arc} bind def +/C6 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C7 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 270 arc closepath fill + vpt 0 360 arc closepath} bind def +/C8 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 270 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C9 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 270 450 arc closepath fill + vpt 0 360 arc closepath} bind def +/C10 {BL [] 0 setdash 2 copy 2 copy moveto vpt 270 360 arc closepath fill + 2 copy moveto + 2 copy vpt 90 180 arc closepath fill + vpt 0 360 arc closepath} bind def +/C11 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 180 arc closepath fill + 2 copy moveto + 2 copy vpt 270 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C12 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 180 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C13 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 0 90 arc closepath fill + 2 copy moveto + 2 copy vpt 180 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/C14 {BL [] 0 setdash 2 copy moveto + 2 copy vpt 90 360 arc closepath fill + vpt 0 360 arc} bind def +/C15 {BL [] 0 setdash 2 copy vpt 0 360 arc closepath fill + vpt 0 360 arc closepath} bind def +/Rec {newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto + neg 0 rlineto closepath} bind def +/Square {dup Rec} bind def +/Bsquare {vpt sub exch vpt sub exch vpt2 Square} bind def +/S0 {BL [] 0 setdash 2 copy moveto 0 vpt rlineto BL Bsquare} bind def +/S1 {BL [] 0 setdash 2 copy vpt Square fill Bsquare} bind def +/S2 {BL [] 0 setdash 2 copy exch vpt sub exch vpt Square fill Bsquare} bind def +/S3 {BL [] 0 setdash 2 copy exch vpt sub exch vpt2 vpt Rec fill Bsquare} bind def +/S4 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def +/S5 {BL [] 0 setdash 2 copy 2 copy vpt Square fill + exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def +/S6 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill Bsquare} bind def +/S7 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill + 2 copy vpt Square fill Bsquare} bind def +/S8 {BL [] 0 setdash 2 copy vpt sub vpt Square fill Bsquare} bind def +/S9 {BL [] 0 setdash 2 copy vpt sub vpt vpt2 Rec fill Bsquare} bind def +/S10 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt Square fill + Bsquare} bind def +/S11 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt2 vpt Rec fill + Bsquare} bind def +/S12 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill Bsquare} bind def +/S13 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill + 2 copy vpt Square fill Bsquare} bind def +/S14 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill + 2 copy exch vpt sub exch vpt Square fill Bsquare} bind def +/S15 {BL [] 0 setdash 2 copy Bsquare fill Bsquare} bind def +/D0 {gsave translate 45 rotate 0 0 S0 stroke grestore} bind def +/D1 {gsave translate 45 rotate 0 0 S1 stroke grestore} bind def +/D2 {gsave translate 45 rotate 0 0 S2 stroke grestore} bind def +/D3 {gsave translate 45 rotate 0 0 S3 stroke grestore} bind def +/D4 {gsave translate 45 rotate 0 0 S4 stroke grestore} bind def +/D5 {gsave translate 45 rotate 0 0 S5 stroke grestore} bind def +/D6 {gsave translate 45 rotate 0 0 S6 stroke grestore} bind def +/D7 {gsave translate 45 rotate 0 0 S7 stroke grestore} bind def +/D8 {gsave translate 45 rotate 0 0 S8 stroke grestore} bind def +/D9 {gsave translate 45 rotate 0 0 S9 stroke grestore} bind def +/D10 {gsave translate 45 rotate 0 0 S10 stroke grestore} bind def +/D11 {gsave translate 45 rotate 0 0 S11 stroke grestore} bind def +/D12 {gsave translate 45 rotate 0 0 S12 stroke grestore} bind def +/D13 {gsave translate 45 rotate 0 0 S13 stroke grestore} bind def +/D14 {gsave translate 45 rotate 0 0 S14 stroke grestore} bind def +/D15 {gsave translate 45 rotate 0 0 S15 stroke grestore} bind def +/DiaE {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V closepath stroke} def +/BoxE {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V closepath stroke} def +/TriUE {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V closepath stroke} def +/TriDE {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V closepath stroke} def +/PentE {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + closepath stroke grestore} def +/CircE {stroke [] 0 setdash + hpt 0 360 arc stroke} def +/Opaque {gsave closepath 1 setgray fill grestore 0 setgray closepath} def +/DiaW {stroke [] 0 setdash vpt add M + hpt neg vpt neg V hpt vpt neg V + hpt vpt V hpt neg vpt V Opaque stroke} def +/BoxW {stroke [] 0 setdash exch hpt sub exch vpt add M + 0 vpt2 neg V hpt2 0 V 0 vpt2 V + hpt2 neg 0 V Opaque stroke} def +/TriUW {stroke [] 0 setdash vpt 1.12 mul add M + hpt neg vpt -1.62 mul V + hpt 2 mul 0 V + hpt neg vpt 1.62 mul V Opaque stroke} def +/TriDW {stroke [] 0 setdash vpt 1.12 mul sub M + hpt neg vpt 1.62 mul V + hpt 2 mul 0 V + hpt neg vpt -1.62 mul V Opaque stroke} def +/PentW {stroke [] 0 setdash gsave + translate 0 hpt M 4 {72 rotate 0 hpt L} repeat + Opaque stroke grestore} def +/CircW {stroke [] 0 setdash + hpt 0 360 arc Opaque stroke} def +/BoxFill {gsave Rec 1 setgray fill grestore} def +/Density { + /Fillden exch def + currentrgbcolor + /ColB exch def /ColG exch def /ColR exch def + /ColR ColR Fillden mul Fillden sub 1 add def + /ColG ColG Fillden mul Fillden sub 1 add def + /ColB ColB Fillden mul Fillden sub 1 add def + ColR ColG ColB setrgbcolor} def +/BoxColFill {gsave Rec PolyFill} def +/PolyFill {gsave Density fill grestore grestore} def +/h {rlineto rlineto rlineto gsave closepath fill grestore} bind def +% +% PostScript Level 1 Pattern Fill routine for rectangles +% Usage: x y w h s a XX PatternFill +% x,y = lower left corner of box to be filled +% w,h = width and height of box +% a = angle in degrees between lines and x-axis +% XX = 0/1 for no/yes cross-hatch +% +/PatternFill {gsave /PFa [ 9 2 roll ] def + PFa 0 get PFa 2 get 2 div add PFa 1 get PFa 3 get 2 div add translate + PFa 2 get -2 div PFa 3 get -2 div PFa 2 get PFa 3 get Rec + TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse + clip + currentlinewidth 0.5 mul setlinewidth + /PFs PFa 2 get dup mul PFa 3 get dup mul add sqrt def + 0 0 M PFa 5 get rotate PFs -2 div dup translate + 0 1 PFs PFa 4 get div 1 add floor cvi + {PFa 4 get mul 0 M 0 PFs V} for + 0 PFa 6 get ne { + 0 1 PFs PFa 4 get div 1 add floor cvi + {PFa 4 get mul 0 2 1 roll M PFs 0 V} for + } if + stroke grestore} def +% +/languagelevel where + {pop languagelevel} {1} ifelse +dup 2 lt + {/InterpretLevel1 true def + /InterpretLevel3 false def} + {/InterpretLevel1 Level1 def + 2 gt + {/InterpretLevel3 Level3 def} + {/InterpretLevel3 false def} + ifelse } + ifelse +% +% PostScript level 2 pattern fill definitions +% +/Level2PatternFill { +/Tile8x8 {/PaintType 2 /PatternType 1 /TilingType 1 /BBox [0 0 8 8] /XStep 8 /YStep 8} + bind def +/KeepColor {currentrgbcolor [/Pattern /DeviceRGB] setcolorspace} bind def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke} +>> matrix makepattern +/Pat1 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke + 0 4 M 4 8 L 8 4 L 4 0 L 0 4 L stroke} +>> matrix makepattern +/Pat2 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 0 M 0 8 L + 8 8 L 8 0 L 0 0 L fill} +>> matrix makepattern +/Pat3 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -4 8 M 8 -4 L + 0 12 M 12 0 L stroke} +>> matrix makepattern +/Pat4 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -4 0 M 8 12 L + 0 -4 M 12 8 L stroke} +>> matrix makepattern +/Pat5 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -2 8 M 4 -4 L + 0 12 M 8 -4 L 4 12 M 10 0 L stroke} +>> matrix makepattern +/Pat6 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop -2 0 M 4 12 L + 0 -4 M 8 12 L 4 -4 M 10 8 L stroke} +>> matrix makepattern +/Pat7 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 8 -2 M -4 4 L + 12 0 M -4 8 L 12 4 M 0 10 L stroke} +>> matrix makepattern +/Pat8 exch def +<< Tile8x8 + /PaintProc {0.5 setlinewidth pop 0 -2 M 12 4 L + -4 0 M 12 8 L -4 4 M 8 10 L stroke} +>> matrix makepattern +/Pat9 exch def +/Pattern1 {PatternBgnd KeepColor Pat1 setpattern} bind def +/Pattern2 {PatternBgnd KeepColor Pat2 setpattern} bind def +/Pattern3 {PatternBgnd KeepColor Pat3 setpattern} bind def +/Pattern4 {PatternBgnd KeepColor Landscape {Pat5} {Pat4} ifelse setpattern} bind def +/Pattern5 {PatternBgnd KeepColor Landscape {Pat4} {Pat5} ifelse setpattern} bind def +/Pattern6 {PatternBgnd KeepColor Landscape {Pat9} {Pat6} ifelse setpattern} bind def +/Pattern7 {PatternBgnd KeepColor Landscape {Pat8} {Pat7} ifelse setpattern} bind def +} def +% +% +%End of PostScript Level 2 code +% +/PatternBgnd { + TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse +} def +% +% Substitute for Level 2 pattern fill codes with +% grayscale if Level 2 support is not selected. +% +/Level1PatternFill { +/Pattern1 {0.250 Density} bind def +/Pattern2 {0.500 Density} bind def +/Pattern3 {0.750 Density} bind def +/Pattern4 {0.125 Density} bind def +/Pattern5 {0.375 Density} bind def +/Pattern6 {0.625 Density} bind def +/Pattern7 {0.875 Density} bind def +} def +% +% Now test for support of Level 2 code +% +Level1 {Level1PatternFill} {Level2PatternFill} ifelse +% +/Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont +dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall +currentdict end definefont pop +% +/MFshow { + { dup 5 get 3 ge + { 5 get 3 eq {gsave} {grestore} ifelse } + {dup dup 0 get findfont exch 1 get scalefont setfont + [ currentpoint ] exch dup 2 get 0 exch R dup 5 get 2 ne {dup dup 6 + get exch 4 get {textshow} {stringwidth pop 0 R} ifelse }if dup 5 get 0 eq + {dup 3 get {2 get neg 0 exch R pop} {pop aload pop M} ifelse} {dup 5 + get 1 eq {dup 2 get exch dup 3 get exch 6 get stringwidth pop -2 div + dup 0 R} {dup 6 get stringwidth pop -2 div 0 R 6 get + textshow 2 index {aload pop M neg 3 -1 roll neg R pop pop} {pop pop pop + pop aload pop M} ifelse }ifelse }ifelse } + ifelse } + forall} def +/Gswidth {dup type /stringtype eq {stringwidth} {pop (n) stringwidth} ifelse} def +/MFwidth {0 exch { dup 5 get 3 ge { 5 get 3 eq { 0 } { pop } ifelse } + {dup 3 get{dup dup 0 get findfont exch 1 get scalefont setfont + 6 get Gswidth pop add} {pop} ifelse} ifelse} forall} def +/MLshow { currentpoint stroke M + 0 exch R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/MRshow { currentpoint stroke M + exch dup MFwidth neg 3 -1 roll R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/MCshow { currentpoint stroke M + exch dup MFwidth -2 div 3 -1 roll R + Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def +/XYsave { [( ) 1 2 true false 3 ()] } bind def +/XYrestore { [( ) 1 2 true false 4 ()] } bind def +Level1 SuppressPDFMark or +{} { +/SDict 10 dict def +systemdict /pdfmark known not { + userdict /pdfmark systemdict /cleartomark get put +} if +SDict begin [ + /Title (spec/tmp/sin_wave_plot.eps) + /Subject (gnuplot plot) + /Creator (gnuplot 5.0 patchlevel 5) +% /Producer (gnuplot) +% /Keywords () + /CreationDate (Fri Nov 22 22:30:52 2019) + /DOCINFO pdfmark +end +} ifelse +% +% Support for boxed text - Ethan A Merritt May 2005 +% +/InitTextBox { userdict /TBy2 3 -1 roll put userdict /TBx2 3 -1 roll put + userdict /TBy1 3 -1 roll put userdict /TBx1 3 -1 roll put + /Boxing true def } def +/ExtendTextBox { Boxing + { gsave dup false charpath pathbbox + dup TBy2 gt {userdict /TBy2 3 -1 roll put} {pop} ifelse + dup TBx2 gt {userdict /TBx2 3 -1 roll put} {pop} ifelse + dup TBy1 lt {userdict /TBy1 3 -1 roll put} {pop} ifelse + dup TBx1 lt {userdict /TBx1 3 -1 roll put} {pop} ifelse + grestore } if } def +/PopTextBox { newpath TBx1 TBxmargin sub TBy1 TBymargin sub M + TBx1 TBxmargin sub TBy2 TBymargin add L + TBx2 TBxmargin add TBy2 TBymargin add L + TBx2 TBxmargin add TBy1 TBymargin sub L closepath } def +/DrawTextBox { PopTextBox stroke /Boxing false def} def +/FillTextBox { gsave PopTextBox 1 1 1 setrgbcolor fill grestore /Boxing false def} def +0 0 0 0 InitTextBox +/TBxmargin 20 def +/TBymargin 20 def +/Boxing false def +/textshow { ExtendTextBox Gshow } def +% +% redundant definitions for compatibility with prologue.ps older than 5.0.2 +/LTB {BL [] LCb DL} def +/LTb {PL [] LCb DL} def +end +%%EndProlog +%%Page: 1 1 +gnudict begin +gsave +doclip +50 50 translate +0.050 0.050 scale +0 setgray +newpath +(Helvetica) findfont 140 scalefont setfont +BackgroundColor 0 lt 3 1 roll 0 lt exch 0 lt or or not {BackgroundColor C 1.000 0 0 7200.00 5040.00 BoxColFill} if +/Helvetica findfont 140 scalefont setfont +/vshift -46 def +1.000 UL +LTb +LCb setrgbcolor +686 448 M +63 0 V +6198 0 R +-63 0 V +stroke +602 448 M +[ [(Helvetica) 140.0 0.0 true true 0 (-1)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 865 M +63 0 V +6198 0 R +-63 0 V +stroke +602 865 M +[ [(Helvetica) 140.0 0.0 true true 0 (-0.8)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 1282 M +63 0 V +6198 0 R +-63 0 V +stroke +602 1282 M +[ [(Helvetica) 140.0 0.0 true true 0 (-0.6)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 1699 M +63 0 V +6198 0 R +-63 0 V +stroke +602 1699 M +[ [(Helvetica) 140.0 0.0 true true 0 (-0.4)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 2116 M +63 0 V +6198 0 R +-63 0 V +stroke +602 2116 M +[ [(Helvetica) 140.0 0.0 true true 0 (-0.2)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 2534 M +63 0 V +6198 0 R +-63 0 V +stroke +602 2534 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 2951 M +63 0 V +6198 0 R +-63 0 V +stroke +602 2951 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0.2)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 3368 M +63 0 V +6198 0 R +-63 0 V +stroke +602 3368 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0.4)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 3785 M +63 0 V +6198 0 R +-63 0 V +stroke +602 3785 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0.6)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 4202 M +63 0 V +6198 0 R +-63 0 V +stroke +602 4202 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0.8)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 4619 M +63 0 V +6198 0 R +-63 0 V +stroke +602 4619 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 1)] +] -46.7 MRshow +1.000 UL +LTb +LCb setrgbcolor +686 448 M +0 63 V +0 4108 R +0 -63 V +stroke +686 308 M +[ [(Helvetica) 140.0 0.0 true true 0 (-10)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +2251 448 M +0 63 V +0 4108 R +0 -63 V +stroke +2251 308 M +[ [(Helvetica) 140.0 0.0 true true 0 (-5)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +3817 448 M +0 63 V +0 4108 R +0 -63 V +stroke +3817 308 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 0)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +5382 448 M +0 63 V +0 4108 R +0 -63 V +stroke +5382 308 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 5)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +6947 448 M +0 63 V +0 4108 R +0 -63 V +stroke +6947 308 M +[ [(Helvetica) 140.0 0.0 true true 0 ( 10)] +] -46.7 MCshow +1.000 UL +LTb +LCb setrgbcolor +1.000 UL +LTB +LCb setrgbcolor +686 4619 N +686 448 L +6261 0 V +0 4171 V +-6261 0 V +Z stroke +1.000 UP +1.000 UL +LTb +LCb setrgbcolor +LCb setrgbcolor +112 2533 M +currentpoint gsave translate -270 rotate 0 0 moveto +[ [(Helvetica) 140.0 0.0 true true 0 (x)] +] -46.7 MCshow +grestore +LTb +LCb setrgbcolor +3816 98 M +[ [(Helvetica) 140.0 0.0 true true 0 (sin\(x\))] +] -46.7 MCshow +LTb +LCb setrgbcolor +3816 4829 M +[ [(Helvetica) 140.0 0.0 true true 0 (Sin Wave Example)] +] -46.7 MCshow +% Begin plot #1 +4.000 UL +LTb +LCb setrgbcolor +/Helvetica findfont 140 scalefont setfont +LCb setrgbcolor +6296 4486 M +(sin\(x\)) Rshow +4.000 UL +LTb +LCb setrgbcolor +6380 4486 M +399 0 V +686 3668 M +63 -374 V +63 -405 V +64 -420 V +63 -417 V +63 -397 V +63 -362 V +64 -311 V +63 -248 V +63 -175 V +63 -95 V +64 -10 V +63 74 V +63 156 V +63 231 V +64 297 V +63 350 V +63 390 V +63 414 V +64 420 V +63 411 V +63 383 V +63 341 V +64 284 V +63 216 V +63 140 V +63 57 V +64 -28 V +63 -111 V +63 -191 V +63 -262 V +64 -322 V +63 -370 V +63 -403 V +63 -419 V +63 -418 V +64 -400 V +63 -366 V +63 -317 V +63 -255 V +64 -183 V +63 -103 V +63 -19 V +63 66 V +64 147 V +63 224 V +63 291 V +63 345 V +64 387 V +63 412 V +63 421 V +63 412 V +64 387 V +63 345 V +63 291 V +63 224 V +64 147 V +63 66 V +63 -19 V +63 -103 V +64 -183 V +63 -255 V +63 -317 V +63 -366 V +64 -400 V +63 -418 V +63 -419 V +63 -403 V +63 -370 V +64 -322 V +63 -262 V +63 -191 V +63 -111 V +64 -28 V +63 57 V +63 140 V +63 216 V +64 284 V +63 341 V +63 383 V +63 411 V +64 420 V +63 414 V +63 390 V +63 350 V +64 297 V +63 231 V +63 156 V +63 74 V +64 -10 V +63 -95 V +63 -175 V +63 -248 V +64 -311 V +63 -362 V +63 -397 V +63 -417 V +64 -420 V +63 -405 V +63 -374 V +% End plot #1 +stroke +2.000 UL +LTb +LCb setrgbcolor +1.000 UL +LTB +LCb setrgbcolor +686 4619 N +686 448 L +6261 0 V +0 4171 V +-6261 0 V +Z stroke +1.000 UP +1.000 UL +LTb +LCb setrgbcolor +stroke +grestore +end +showpage +%%Trailer +%%DocumentFonts: Helvetica diff --git a/spec/integration/sinwave_spec.rb b/spec/integration/sinwave_spec.rb new file mode 100644 index 0000000..821502c --- /dev/null +++ b/spec/integration/sinwave_spec.rb @@ -0,0 +1,46 @@ +describe "Sin Wave Plot Example" do + let(:file_path) { 'spec/tmp/sin_wave_plot.eps' } + let(:fixture_path) { 'spec/fixtures/plots/sin_wave_plot.eps' } + + let(:file_content) do + File.read(file_path).gsub(/CreationDate.*/, "") + end + + let(:fixture_content) do + File.read(fixture_path).gsub(/CreationDate.*/, "") + end + + before do + path = file_path + + Gnuplot.open do |gp| + Gnuplot::Plot.new( gp ) do |plot| + + plot.xrange "[-10:10]" + plot.title "Sin Wave Example" + plot.ylabel "x" + plot.xlabel "sin(x)" + + plot.term "postscript eps" + plot.output path + + plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds| + ds.with = "lines" + ds.linewidth = 4 + end + + end + + end + + end + + after do + File.delete(file_path) + end + + it "plots expected file" do + expect(file_content).to eq(fixture_content) + end +end + From 67245c701d6100da60d54a1bf9f48bd682ccc049 Mon Sep 17 00:00:00 2001 From: darthjee Date: Sun, 24 Nov 2019 10:21:41 +0100 Subject: [PATCH 62/79] Add initialization spec --- spec/lib/ruby_gnuplot/plot_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index c45ce23..b831ef5 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -47,5 +47,21 @@ expect(plot.to_gplot).to eq(expected_string) end end + + context "when setting from inside initialization" do + subject(:plot) do + described_class.new do |p| + p.title "Array Plot Example" + p.ylabel "x" + p.xlabel "x^2" + p.term "postscript eps" + p.output "file.eps" + end + end + + it "wraps strings with quotes when needed" do + expect(plot.to_gplot).to eq(expected_string) + end + end end end From 6cd22ae7c4aa28410fc93004f1906af6360b7143 Mon Sep 17 00:00:00 2001 From: darthjee Date: Sun, 24 Nov 2019 10:32:48 +0100 Subject: [PATCH 63/79] Add quotting sets spec --- spec/lib/ruby_gnuplot/plot_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index b831ef5..a69a1ee 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -1,3 +1,15 @@ +shared_examples 'quotes value when setting in a plot for' do |field| + describe "##{field}" do + before do + plot.public_send(field, 'text') + end + + it 'quotes value when setting it' do + expect(plot.to_gplot).to eq("set #{field} \"text\"\n") + end + end +end + describe Gnuplot::Plot do subject(:plot) { described_class.new } @@ -64,4 +76,14 @@ end end end + + it_behaves_like 'quotes value when setting in a plot for', :title + it_behaves_like 'quotes value when setting in a plot for', :output + it_behaves_like 'quotes value when setting in a plot for', :xlabel + it_behaves_like 'quotes value when setting in a plot for', :x2label + it_behaves_like 'quotes value when setting in a plot for', :ylabel + it_behaves_like 'quotes value when setting in a plot for', :y2label + it_behaves_like 'quotes value when setting in a plot for', :clabel + it_behaves_like 'quotes value when setting in a plot for', :cblabel + it_behaves_like 'quotes value when setting in a plot for', :zlabel end From 9ee1f5bb79312c0725847a7b518d9e92322a6cce Mon Sep 17 00:00:00 2001 From: darthjee Date: Sun, 24 Nov 2019 10:38:58 +0100 Subject: [PATCH 64/79] Placeholder for style spec --- spec/lib/ruby_gnuplot/style_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 spec/lib/ruby_gnuplot/style_spec.rb diff --git a/spec/lib/ruby_gnuplot/style_spec.rb b/spec/lib/ruby_gnuplot/style_spec.rb new file mode 100644 index 0000000..8383fb8 --- /dev/null +++ b/spec/lib/ruby_gnuplot/style_spec.rb @@ -0,0 +1,5 @@ +describe Gnuplot::Plot do + subject(:style) { described_class.new } + + xit "Adds tests here" +end From 4e023d68f481830ed93dc3652eb6f2c30b19d00a Mon Sep 17 00:00:00 2001 From: darthjee Date: Sun, 24 Nov 2019 13:03:03 +0100 Subject: [PATCH 65/79] Add Plot#[] spec --- spec/lib/ruby_gnuplot/plot_spec.rb | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index a69a1ee..e0ca332 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -86,4 +86,59 @@ it_behaves_like 'quotes value when setting in a plot for', :clabel it_behaves_like 'quotes value when setting in a plot for', :cblabel it_behaves_like 'quotes value when setting in a plot for', :zlabel + + describe '[]' do + context 'when value was never set' do + it { expect(plot['key']).to be_nil } + end + + context 'when value was only unset' do + before { plot.unset 'title' } + + it { expect(plot['title']).to be_nil } + end + + context 'when value was set only once' do + before { plot.title "My Title" } + + it "returns the value to be used (quoted when needed)" do + expect(plot['title']).to eq('"My Title"') + end + end + + context 'when value was set twice' do + before do + plot.title "My Title" + plot.title "My New Title" + end + + # TODO: check specification + xit "returns the last value set" do + expect(plot['title']).to eq('"My New Title"') + end + end + + context 'when value was set then unset' do + before do + plot.title "My Title" + plot.unset "title" + end + + # TODO: check specification + xit { expect(plot['title']).to be_nil } + end + + context 'when value was set, unset and set again' do + before do + plot.title "My Title" + plot.unset "title" + plot.title "My New Title" + end + + # TODO: check specification + xit "returns the last value set" do + expect(plot['title']).to eq('"My New Title"') + end + end + end end From ff92d733b8aed7559d89b4e3dab0face6d8a59c1 Mon Sep 17 00:00:00 2001 From: darthjee Date: Sun, 24 Nov 2019 13:16:34 +0100 Subject: [PATCH 66/79] Add spec over Plot#unset --- spec/lib/ruby_gnuplot/plot_spec.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index e0ca332..1753526 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -87,7 +87,33 @@ it_behaves_like 'quotes value when setting in a plot for', :cblabel it_behaves_like 'quotes value when setting in a plot for', :zlabel - describe '[]' do + describe '#unset' do + let(:expected_string) do + [ + 'set title "My Title"', + 'unset title', + '' + ].join("\n") + end + + before do + plot.title 'My Title' + end + + # TODO: check specification + xit 'changes value in current settings' do + expect { plot.unset 'title' } + .to change { plot['title'] } + .from('My title').to(nil) + end + + it 'unsets key on output' do + plot.unset 'title' + expect(plot.to_gplot).to eq(expected_string) + end + end + + describe '#[]' do context 'when value was never set' do it { expect(plot['key']).to be_nil } end From 1134bb52aeb97da56d1e9983ec39fc26db3344ce Mon Sep 17 00:00:00 2001 From: darthjee Date: Mon, 25 Nov 2019 09:23:09 +0100 Subject: [PATCH 67/79] Checks changes in settings --- spec/lib/ruby_gnuplot/plot_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index 1753526..5913d63 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -7,6 +7,16 @@ it 'quotes value when setting it' do expect(plot.to_gplot).to eq("set #{field} \"text\"\n") end + + it 'enquees into settings' do + expect { plot.public_send(field, 'new text') } + .to change(plot, :settings) + .from([[:set, field.to_s, '"text"']]) + .to([ + [:set, field.to_s, '"text"'], + [:set, field.to_s, '"new text"'] + ]) + end end end From 2a802c3bd3dbf4bca32eb4c8b4610f079b6e6132 Mon Sep 17 00:00:00 2001 From: darthjee Date: Mon, 25 Nov 2019 09:27:12 +0100 Subject: [PATCH 68/79] Add method missing spec --- spec/lib/ruby_gnuplot/plot_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index 5913d63..f514695 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -177,4 +177,22 @@ end end end + + describe 'method missing' do + it 'delegates to set call' do + expect { plot.fake_field('value') } + .to change(plot, :settings) + .from([]) + .to([[:set, 'fake_field', 'value']]) + end + + context 'when field should be quoted' do + it 'delegates to set call and quote it' do + expect { plot.output('value') } + .to change(plot, :settings) + .from([]) + .to([[:set, 'output', '"value"']]) + end + end + end end From b4424337da0cbd5ed0973ab71516425fe5d4779c Mon Sep 17 00:00:00 2001 From: darthjee Date: Tue, 26 Nov 2019 09:18:01 +0100 Subject: [PATCH 69/79] Add spec over style class --- spec/lib/ruby_gnuplot/style_spec.rb | 65 ++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/spec/lib/ruby_gnuplot/style_spec.rb b/spec/lib/ruby_gnuplot/style_spec.rb index 8383fb8..b80f845 100644 --- a/spec/lib/ruby_gnuplot/style_spec.rb +++ b/spec/lib/ruby_gnuplot/style_spec.rb @@ -1,5 +1,66 @@ -describe Gnuplot::Plot do +describe Gnuplot::Plot::Style do subject(:style) { described_class.new } - xit "Adds tests here" + let(:index) { style.index } + + describe '#to_s' do + context "when nothing has been set" do + it 'creates an empty style' do + expect(style.to_s).to eq("set style line #{index}") + end + end + + context 'when setting the stype' do + before do + style.ls = 1 + style.lw = 2 + style.lc = 3 + style.pt = 4 + style.ps = 5 + style.fs = 6 + end + + it 'creates and indexes the style' do + expect(style.to_s).to eq( + "set style line #{index} ls 1 lw 2 lc 3 pt 4 ps 5 fs 6" + ) + end + end + + context 'when setting the stype on initialize' do + subject(:style) do + described_class.new do |style| + style.ls = 1 + style.lw = 2 + style.lc = 3 + style.pt = 4 + style.ps = 5 + style.fs = 6 + end + end + + it 'creates and indexes the style' do + expect(style.to_s).to eq( + "set style line #{index} ls 1 lw 2 lc 3 pt 4 ps 5 fs 6" + ) + end + end + + context 'when setting using the full method name' do + before do + style.linestyle = 1 + style.linewidth = 2 + style.linecolor = 3 + style.pointtype = 4 + style.pointsize = 5 + style.fill = 6 + end + + it 'creates and indexes the style' do + expect(style.to_s).to eq( + "set style line #{index} ls 1 lw 2 lc 3 pt 4 ps 5 fs 6" + ) + end + end + end end From cf8c5024b4681eaf6d36127a8815de18daab95d3 Mon Sep 17 00:00:00 2001 From: darthjee Date: Tue, 26 Nov 2019 10:17:05 +0100 Subject: [PATCH 70/79] Fix Plot#[] --- lib/gnuplot.rb | 2 +- spec/lib/ruby_gnuplot/plot_spec.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index 592b3e6..21ca23d 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -140,7 +140,7 @@ def unset ( var ) # gnuplot process. def [] ( var ) - v = @settings.rassoc( var ) + v = @settings.reverse.rassoc( var ) if v.nil? or v.first == :unset nil else diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index f514695..8e86d43 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -111,10 +111,10 @@ end # TODO: check specification - xit 'changes value in current settings' do + it 'changes value in current settings' do expect { plot.unset 'title' } .to change { plot['title'] } - .from('My title').to(nil) + .from('"My Title"').to(nil) end it 'unsets key on output' do @@ -149,7 +149,7 @@ end # TODO: check specification - xit "returns the last value set" do + it "returns the last value set" do expect(plot['title']).to eq('"My New Title"') end end @@ -161,7 +161,7 @@ end # TODO: check specification - xit { expect(plot['title']).to be_nil } + it { expect(plot['title']).to be_nil } end context 'when value was set, unset and set again' do @@ -172,7 +172,7 @@ end # TODO: check specification - xit "returns the last value set" do + it "returns the last value set" do expect(plot['title']).to eq('"My New Title"') end end From 5e0055f4ca7fc7ca6bfc70c7bc61956026b03e5f Mon Sep 17 00:00:00 2001 From: darthjee Date: Tue, 26 Nov 2019 10:19:20 +0100 Subject: [PATCH 71/79] Fix Plot#[] --- lib/gnuplot.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gnuplot.rb b/lib/gnuplot.rb index 592b3e6..21ca23d 100644 --- a/lib/gnuplot.rb +++ b/lib/gnuplot.rb @@ -140,7 +140,7 @@ def unset ( var ) # gnuplot process. def [] ( var ) - v = @settings.rassoc( var ) + v = @settings.reverse.rassoc( var ) if v.nil? or v.first == :unset nil else From 8a0702c10861c3ecb5383adec7b69758be7effe4 Mon Sep 17 00:00:00 2001 From: darthjee Date: Tue, 26 Nov 2019 17:15:38 +0100 Subject: [PATCH 72/79] Add rubocop --- .rubocop.yml | 2 + .rubocop_todo.yml | 654 +++++++++++++++++++++++++++++++++++++++++++ ruby_gnuplot.gemspec | 6 +- 3 files changed, 660 insertions(+), 2 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..6cc5ed4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +require: rubocop-rspec +inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..2d1a124 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,654 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2019-11-26 16:16:51 +0000 using RuboCop version 0.73.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/AlignArguments: + Exclude: + - 'lib/gnuplot.rb' + - 'test/test_gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/AlignArray: + Exclude: + - 'test/test_gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'ruby_gnuplot.gemspec' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines. +Layout/EmptyLineBetweenDefs: + Exclude: + - 'lib/gnuplot.rb' + - 'test/test_gnuplot.rb' + +# Offense count: 13 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'lib/gnuplot.rb' + - 'spec/lib/ruby_gnuplot/plot_spec.rb' + - 'test/test_gnuplot.rb' + +# Offense count: 21 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Exclude: + - 'examples/multiple_data_sets.rb' + - 'spec/integration/arrtest_spec.rb' + - 'spec/integration/histtest_spec.rb' + - 'spec/integration/multtest_spec.rb' + - 'spec/integration/sinwave_spec.rb' + - 'test/arrtest.rb' + - 'test/multtest.rb' + - 'test/sinwave.rb' + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Exclude: + - 'lib/gnuplot.rb' + - 'test/test_gnuplot.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/EmptyLinesAroundMethodBody: + Exclude: + - 'lib/gnuplot.rb' + - 'test/test_gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines +Layout/EmptyLinesAroundModuleBody: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'test/test_gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IndentationWidth. +Layout/IndentAssignment: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_brackets +Layout/IndentFirstArrayElement: + EnforcedStyle: consistent + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: normal, indented_internal_methods +Layout/IndentationConsistency: + Exclude: + - 'examples/multiple_data_sets.rb' + - 'lib/gnuplot.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: Width, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'examples/3d_surface_plot.rb' + - 'lib/gnuplot.rb' + - 'spec/integration/multtest_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Layout/SpaceAfterComma: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 13 +# Cop supports --auto-correct. +Layout/SpaceAfterMethodName: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, no_space +Layout/SpaceAroundEqualsInParameterDefault: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Layout/SpaceAroundOperators: + Exclude: + - 'examples/discrete_points.rb' + - 'examples/multiple_data_sets.rb' + - 'ruby_gnuplot.gemspec' + - 'spec/integration/arrtest_spec.rb' + - 'spec/integration/histtest_spec.rb' + - 'spec/integration/multtest_spec.rb' + - 'test/arrtest.rb' + - 'test/histtest.rb' + - 'test/multtest.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceBeforeBlockBraces: + Exclude: + - 'examples/histogram.rb' + - 'lib/gnuplot.rb' + +# Offense count: 18 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideArrayLiteralBrackets: + Exclude: + - 'lib/gnuplot.rb' + - 'test/test_gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Layout/SpaceInsideArrayPercentLiteral: + Exclude: + - 'examples/histogram.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'examples/histogram.rb' + - 'lib/gnuplot.rb' + +# Offense count: 120 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, no_space +Layout/SpaceInsideParens: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: IndentationWidth. +Layout/Tab: + Exclude: + - 'examples/3d_surface_plot.rb' + - 'examples/multiple_data_sets.rb' + - 'lib/gnuplot.rb' + - 'test/test_gnuplot.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingBlankLines: + Exclude: + - 'examples/histogram.rb' + - 'examples/sin_wave.rb' + - 'spec/integration/multtest_spec.rb' + - 'spec/integration/sinwave_spec.rb' + - 'test/arrtest.rb' + - 'test/histtest.rb' + - 'test/multtest.rb' + - 'test/sinwave.rb' + - 'test/test_gnuplot.rb' + +# Offense count: 27 +# Cop supports --auto-correct. +# Configuration parameters: AllowInHeredoc. +Layout/TrailingWhitespace: + Exclude: + - 'examples/discrete_points.rb' + - 'examples/histogram.rb' + - 'examples/multiple_data_sets.rb' + - 'examples/output_image_file.rb' + - 'examples/sin_wave.rb' + +# Offense count: 1 +Lint/AmbiguousOperator: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 2 +Lint/ShadowingOuterLocalVariable: + Exclude: + - 'test/test_gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'test/histtest.rb' + +# Offense count: 1 +Lint/UselessAssignment: + Exclude: + - 'test/test_gnuplot.rb' + +# Offense count: 3 +Metrics/AbcSize: + Max: 23 + +# Offense count: 9 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine +Metrics/BlockLength: + Max: 143 + +# Offense count: 1 +Metrics/CyclomaticComplexity: + Max: 13 + +# Offense count: 8 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 22 + +# Offense count: 1 +Metrics/PerceivedComplexity: + Max: 12 + +# Offense count: 1 +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: + Exclude: + - 'Rakefile' + +# Offense count: 4 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: io, id, to, by, on, in, at, ip, db +Naming/UncommunicativeMethodParamName: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: snake_case, camelCase +Naming/VariableName: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 4 +RSpec/DescribeClass: + Exclude: + - 'spec/integration/arrtest_spec.rb' + - 'spec/integration/histtest_spec.rb' + - 'spec/integration/multtest_spec.rb' + - 'spec/integration/sinwave_spec.rb' + +# Offense count: 1 +# Configuration parameters: Max. +RSpec/ExampleLength: + Exclude: + - 'spec/lib/ruby_gnuplot/plot_spec.rb' + +# Offense count: 1 +# Configuration parameters: CustomTransform, IgnoreMethods. +RSpec/FilePath: + Exclude: + - 'spec/lib/ruby_gnuplot/style_spec.rb' + +# Offense count: 1 +Security/Eval: + Exclude: + - 'Rakefile' + +# Offense count: 16 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: prefer_alias, prefer_alias_method +Style/Alias: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, conditionals +Style/AndOr: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/BlockComments: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners. +# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'examples/multiple_data_sets.rb' + - 'lib/gnuplot.rb' + - 'spec/integration/multtest_spec.rb' + - 'test/multtest.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: is_a?, kind_of? +Style/ClassCheck: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Style/ClassMethods: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +Style/ColonMethodCall: + Exclude: + - 'lib/gnuplot.rb' + - 'test/test_gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 7 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/Encoding: + Exclude: + - 'ruby_gnuplot.gemspec' + +# Offense count: 9 +# Cop supports --auto-correct. +Style/ExpandPathArguments: + Exclude: + - 'Rakefile' + - 'examples/3d_surface_plot.rb' + - 'examples/discrete_points.rb' + - 'examples/histogram.rb' + - 'examples/multiple_data_sets.rb' + - 'examples/output_image_file.rb' + - 'examples/sin_wave.rb' + - 'ruby_gnuplot.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: each, for +Style/For: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 23 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, never +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 1 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + EnforcedStyle: hash_rockets + +# Offense count: 3 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +Style/IfUnlessModifierOfIfUnless: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +Style/MethodCallWithoutArgsParentheses: + Exclude: + - 'test/histtest.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline +Style/MethodDefParentheses: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +Style/MethodMissingSuper: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +Style/MissingRespondToMissing: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/MultilineIfThen: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Exclude: + - 'lib/gnuplot.rb' + - 'lib/ruby_gnuplot/version.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: both, prefix, postfix +Style/NegatedIf: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/NestedModifier: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/Not: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 18 +# Cop supports --auto-correct. +# Configuration parameters: Strict. +Style/NumericLiterals: + MinDigits: 7 + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/gnuplot.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowSafeAssignment, AllowInMultilineConditions. +Style/ParenthesesAroundCondition: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'examples/histogram.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Style/RedundantSelf: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: use_perl_names, use_english_names +Style/SpecialGlobalVars: + Exclude: + - 'ruby_gnuplot.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/StderrPuts: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 235 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: MinSize. +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: brackets + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'examples/discrete_points.rb' + - 'examples/histogram.rb' + - 'examples/multiple_data_sets.rb' + - 'lib/gnuplot.rb' + - 'spec/integration/arrtest_spec.rb' + - 'spec/integration/multtest_spec.rb' + - 'test/arrtest.rb' + - 'test/multtest.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, AllowSafeAssignment. +# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex +Style/TernaryParentheses: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArrayLiteral: + Exclude: + - 'examples/histogram.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + EnforcedStyle: percent + MinSize: 10 + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: forbid_for_all_comparison_operators, forbid_for_equality_operators_only, require_for_all_comparison_operators, require_for_equality_operators_only +Style/YodaCondition: + Exclude: + - 'test/test_gnuplot.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/ZeroLengthPredicate: + Exclude: + - 'lib/gnuplot.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 115 diff --git a/ruby_gnuplot.gemspec b/ruby_gnuplot.gemspec index c070c96..97239a1 100644 --- a/ruby_gnuplot.gemspec +++ b/ruby_gnuplot.gemspec @@ -18,6 +18,8 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.add_development_dependency 'minitest' - s.add_development_dependency 'rspec', '3.9.0' - s.add_development_dependency 'simplecov', '0.17.0' + s.add_development_dependency 'rspec', '3.9.0' + s.add_development_dependency 'rubocop', '0.73.0' + s.add_development_dependency 'rubocop-rspec', '1.33.0' + s.add_development_dependency 'simplecov', '0.17.0' end From 91fca063b14d82f4c394ce47a24f8247130224b7 Mon Sep 17 00:00:00 2001 From: darthjee Date: Tue, 26 Nov 2019 17:18:35 +0100 Subject: [PATCH 73/79] Apply rubocop fixes --- .rubocop.yml | 7 ++ .rubocop_todo.yml | 66 ++--------- spec/integration/arrtest_spec.rb | 6 +- spec/integration/histtest_spec.rb | 3 +- spec/integration/multtest_spec.rb | 19 ++-- spec/integration/sinwave_spec.rb | 5 - .../lib/ruby_gnuplot/{ => plot}/style_spec.rb | 0 spec/lib/ruby_gnuplot/plot_spec.rb | 13 ++- spec/spec_helper.rb | 104 +++++++++--------- spec/support/models/random_generator.rb | 2 +- 10 files changed, 86 insertions(+), 139 deletions(-) rename spec/lib/ruby_gnuplot/{ => plot}/style_spec.rb (100%) diff --git a/.rubocop.yml b/.rubocop.yml index 6cc5ed4..2b2ba5e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,2 +1,9 @@ require: rubocop-rspec inherit_from: .rubocop_todo.yml + +AllCops: + TargetRubyVersion: 2.5 + +RSpec/DescribeClass: + Exclude: + - 'spec/**/*_spec.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2d1a124..961b79d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2019-11-26 16:16:51 +0000 using RuboCop version 0.73.0. +# on 2019-11-26 16:32:38 +0000 using RuboCop version 0.73.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -41,25 +41,20 @@ Layout/EmptyLineBetweenDefs: - 'lib/gnuplot.rb' - 'test/test_gnuplot.rb' -# Offense count: 13 +# Offense count: 12 # Cop supports --auto-correct. Layout/EmptyLines: Exclude: - 'lib/gnuplot.rb' - - 'spec/lib/ruby_gnuplot/plot_spec.rb' - 'test/test_gnuplot.rb' -# Offense count: 21 +# Offense count: 10 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: empty_lines, no_empty_lines Layout/EmptyLinesAroundBlockBody: Exclude: - 'examples/multiple_data_sets.rb' - - 'spec/integration/arrtest_spec.rb' - - 'spec/integration/histtest_spec.rb' - - 'spec/integration/multtest_spec.rb' - - 'spec/integration/sinwave_spec.rb' - 'test/arrtest.rb' - 'test/multtest.rb' - 'test/sinwave.rb' @@ -102,13 +97,6 @@ Layout/IndentAssignment: Exclude: - 'lib/gnuplot.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_brackets -Layout/IndentFirstArrayElement: - EnforcedStyle: consistent - # Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. @@ -118,14 +106,13 @@ Layout/IndentationConsistency: - 'examples/multiple_data_sets.rb' - 'lib/gnuplot.rb' -# Offense count: 6 +# Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: Width, IgnoredPatterns. Layout/IndentationWidth: Exclude: - 'examples/3d_surface_plot.rb' - 'lib/gnuplot.rb' - - 'spec/integration/multtest_spec.rb' # Offense count: 2 # Cop supports --auto-correct. @@ -147,7 +134,7 @@ Layout/SpaceAroundEqualsInParameterDefault: Exclude: - 'lib/gnuplot.rb' -# Offense count: 9 +# Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment. Layout/SpaceAroundOperators: @@ -155,9 +142,6 @@ Layout/SpaceAroundOperators: - 'examples/discrete_points.rb' - 'examples/multiple_data_sets.rb' - 'ruby_gnuplot.gemspec' - - 'spec/integration/arrtest_spec.rb' - - 'spec/integration/histtest_spec.rb' - - 'spec/integration/multtest_spec.rb' - 'test/arrtest.rb' - 'test/histtest.rb' - 'test/multtest.rb' @@ -215,7 +199,7 @@ Layout/Tab: - 'lib/gnuplot.rb' - 'test/test_gnuplot.rb' -# Offense count: 9 +# Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: final_newline, final_blank_line @@ -223,8 +207,6 @@ Layout/TrailingBlankLines: Exclude: - 'examples/histogram.rb' - 'examples/sin_wave.rb' - - 'spec/integration/multtest_spec.rb' - - 'spec/integration/sinwave_spec.rb' - 'test/arrtest.rb' - 'test/histtest.rb' - 'test/multtest.rb' @@ -308,26 +290,6 @@ Naming/VariableName: Exclude: - 'lib/gnuplot.rb' -# Offense count: 4 -RSpec/DescribeClass: - Exclude: - - 'spec/integration/arrtest_spec.rb' - - 'spec/integration/histtest_spec.rb' - - 'spec/integration/multtest_spec.rb' - - 'spec/integration/sinwave_spec.rb' - -# Offense count: 1 -# Configuration parameters: Max. -RSpec/ExampleLength: - Exclude: - - 'spec/lib/ruby_gnuplot/plot_spec.rb' - -# Offense count: 1 -# Configuration parameters: CustomTransform, IgnoreMethods. -RSpec/FilePath: - Exclude: - - 'spec/lib/ruby_gnuplot/style_spec.rb' - # Offense count: 1 Security/Eval: Exclude: @@ -349,13 +311,7 @@ Style/AndOr: Exclude: - 'lib/gnuplot.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Style/BlockComments: - Exclude: - - 'spec/spec_helper.rb' - -# Offense count: 8 +# Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners. # SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces @@ -366,7 +322,6 @@ Style/BlockDelimiters: Exclude: - 'examples/multiple_data_sets.rb' - 'lib/gnuplot.rb' - - 'spec/integration/multtest_spec.rb' - 'test/multtest.rb' # Offense count: 2 @@ -535,7 +490,6 @@ Style/NumericLiterals: # SupportedStyles: predicate, comparison Style/NumericPredicate: Exclude: - - 'spec/**/*' - 'lib/gnuplot.rb' # Offense count: 3 @@ -593,7 +547,7 @@ Style/StringLiterals: Style/SymbolArray: EnforcedStyle: brackets -# Offense count: 9 +# Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: IgnoredMethods. # IgnoredMethods: respond_to, define_method @@ -603,8 +557,6 @@ Style/SymbolProc: - 'examples/histogram.rb' - 'examples/multiple_data_sets.rb' - 'lib/gnuplot.rb' - - 'spec/integration/arrtest_spec.rb' - - 'spec/integration/multtest_spec.rb' - 'test/arrtest.rb' - 'test/multtest.rb' @@ -646,7 +598,7 @@ Style/ZeroLengthPredicate: Exclude: - 'lib/gnuplot.rb' -# Offense count: 7 +# Offense count: 9 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/spec/integration/arrtest_spec.rb b/spec/integration/arrtest_spec.rb index a5ae38e..49485f4 100644 --- a/spec/integration/arrtest_spec.rb +++ b/spec/integration/arrtest_spec.rb @@ -15,15 +15,14 @@ Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| - plot.title "Array Plot Example" plot.ylabel "x" plot.xlabel "x^2" plot.term "postscript eps" plot.output path - x = (0..50).collect { |v| v.to_f } - y = x.collect { |v| v ** 2 } + x = (0..50).collect(&:to_f) + y = x.collect { |v| v**2 } plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds| ds.with = "linespoints" @@ -31,7 +30,6 @@ end end end - end after do diff --git a/spec/integration/histtest_spec.rb b/spec/integration/histtest_spec.rb index 3cc98fa..7301023 100644 --- a/spec/integration/histtest_spec.rb +++ b/spec/integration/histtest_spec.rb @@ -15,7 +15,7 @@ RandomGenerator.seed(0.17) collection = (0..500).collect do - (RandomGenerator.rand-0.5)**3 + (RandomGenerator.rand - 0.5)**3 end Gnuplot.open do |gp| @@ -37,7 +37,6 @@ plot.output path end end - end after do diff --git a/spec/integration/multtest_spec.rb b/spec/integration/multtest_spec.rb index 31c5923..3da4043 100644 --- a/spec/integration/multtest_spec.rb +++ b/spec/integration/multtest_spec.rb @@ -15,7 +15,6 @@ Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| - plot.xrange "[-10:10]" plot.title "Sin Wave Example" plot.ylabel "x" @@ -24,34 +23,30 @@ plot.term "postscript eps" plot.output path - x = (0..50).collect { |v| v.to_f } - y = x.collect { |v| v ** 2 } + x = (0..50).collect(&:to_f) + y = x.collect { |v| v**2 } plot.data = [ - Gnuplot::DataSet.new( "sin(x)" ) { |ds| + Gnuplot::DataSet.new( "sin(x)" ) do |ds| ds.with = "lines" ds.title = "String function" ds.linewidth = 4 - }, + end, - Gnuplot::DataSet.new( [x, y] ) { |ds| + Gnuplot::DataSet.new( [x, y] ) do |ds| ds.with = "linespoints" ds.title = "Array data" - } + end ] - end - end - end after do - File.delete(file_path) + File.delete(file_path) end it "plots expected file" do expect(file_content).to eq(fixture_content) end end - diff --git a/spec/integration/sinwave_spec.rb b/spec/integration/sinwave_spec.rb index 821502c..c27e7f5 100644 --- a/spec/integration/sinwave_spec.rb +++ b/spec/integration/sinwave_spec.rb @@ -15,7 +15,6 @@ Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| - plot.xrange "[-10:10]" plot.title "Sin Wave Example" plot.ylabel "x" @@ -28,11 +27,8 @@ ds.with = "lines" ds.linewidth = 4 end - end - end - end after do @@ -43,4 +39,3 @@ expect(file_content).to eq(fixture_content) end end - diff --git a/spec/lib/ruby_gnuplot/style_spec.rb b/spec/lib/ruby_gnuplot/plot/style_spec.rb similarity index 100% rename from spec/lib/ruby_gnuplot/style_spec.rb rename to spec/lib/ruby_gnuplot/plot/style_spec.rb diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index 8e86d43..4acdd21 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -4,6 +4,13 @@ plot.public_send(field, 'text') end + let(:expected_settings) do + [ + [:set, field.to_s, '"text"'], + [:set, field.to_s, '"new text"'] + ] + end + it 'quotes value when setting it' do expect(plot.to_gplot).to eq("set #{field} \"text\"\n") end @@ -12,10 +19,7 @@ expect { plot.public_send(field, 'new text') } .to change(plot, :settings) .from([[:set, field.to_s, '"text"']]) - .to([ - [:set, field.to_s, '"text"'], - [:set, field.to_s, '"new text"'] - ]) + .to(expected_settings) end end end @@ -35,7 +39,6 @@ ].join("\n") end - context 'when nothing has been set' do it "returns an empty string" do expect(plot.to_gplot).to eq('') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 38530b9..e2940fd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -55,57 +55,55 @@ # triggering implicit auto-inclusion in groups with matching metadata. config.shared_context_metadata_behavior = :apply_to_host_groups -# The settings below are suggested to provide a good initial experience -# with RSpec, but feel free to customize to your heart's content. -=begin - # This allows you to limit a spec run to individual examples or groups - # you care about by tagging them with `:focus` metadata. When nothing - # is tagged with `:focus`, all examples get run. RSpec also provides - # aliases for `it`, `describe`, and `context` that include `:focus` - # metadata: `fit`, `fdescribe` and `fcontext`, respectively. - config.filter_run_when_matching :focus - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ - # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ - # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode - config.disable_monkey_patching! - - # This setting enables warnings. It's recommended, but in some cases may - # be too noisy due to issues in dependencies. - config.warnings = true - - # Many RSpec users commonly either run the entire suite or an individual - # file, and it's useful to allow more verbose output when running an - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = "doc" - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # Run specs in random order to surface order dependencies. If you find an - # order dependency and want to debug it, you can fix the order by providing - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + # config.disable_monkey_patching! + # + # # This setting enables warnings. It's recommended, but in some cases may + # # be too noisy due to issues in dependencies. + # config.warnings = true + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed end diff --git a/spec/support/models/random_generator.rb b/spec/support/models/random_generator.rb index 96e752e..5ad8062 100644 --- a/spec/support/models/random_generator.rb +++ b/spec/support/models/random_generator.rb @@ -12,7 +12,7 @@ def rand def seed(value) @rand = value.abs % 1 - @rand = nil if @rand == 0 + @rand = nil if @rand.zero? end end end From 0ba30730d44c7b17a27847d50cac3efc146778ef Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 27 Nov 2019 09:28:38 +0100 Subject: [PATCH 74/79] Add spec for Plot#style --- .rubocop.yml | 4 ++++ spec/lib/ruby_gnuplot/plot_spec.rb | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 2b2ba5e..be02188 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,3 +7,7 @@ AllCops: RSpec/DescribeClass: Exclude: - 'spec/**/*_spec.rb' + +Metrics/BlockLength: + Exclude: + - 'spec/**/*_spec.rb' diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index 4acdd21..0b2db45 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -198,4 +198,23 @@ end end end + + describe '#style' do + subject(:plot) do + described_class.new do |p| + p.title 'My title' + p.style do |style| + style.ls = 1 + end + end + end + + let(:expected_output) do + /^set title "My title"\nset style line \d+ ls 1\n$/ + end + + it 'adds style to gplot output' do + expect(plot.to_gplot).to match(expected_output) + end + end end From 93ba7af80d19fd1968677b8eafc81281853b5f7c Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 27 Nov 2019 09:29:13 +0100 Subject: [PATCH 75/79] Remove TODOs --- spec/lib/ruby_gnuplot/plot_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/lib/ruby_gnuplot/plot_spec.rb b/spec/lib/ruby_gnuplot/plot_spec.rb index 0b2db45..49e4279 100644 --- a/spec/lib/ruby_gnuplot/plot_spec.rb +++ b/spec/lib/ruby_gnuplot/plot_spec.rb @@ -113,7 +113,6 @@ plot.title 'My Title' end - # TODO: check specification it 'changes value in current settings' do expect { plot.unset 'title' } .to change { plot['title'] } @@ -151,7 +150,6 @@ plot.title "My New Title" end - # TODO: check specification it "returns the last value set" do expect(plot['title']).to eq('"My New Title"') end @@ -163,7 +161,6 @@ plot.unset "title" end - # TODO: check specification it { expect(plot['title']).to be_nil } end @@ -174,7 +171,6 @@ plot.title "My New Title" end - # TODO: check specification it "returns the last value set" do expect(plot['title']).to eq('"My New Title"') end From 1564edc4c5cbfbf38302b50a888a5ca917064b03 Mon Sep 17 00:00:00 2001 From: darthjee Date: Wed, 27 Nov 2019 18:20:10 +0100 Subject: [PATCH 76/79] Add data set spec --- spec/lib/ruby_gnuplot/data_set_spec.rb | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 spec/lib/ruby_gnuplot/data_set_spec.rb diff --git a/spec/lib/ruby_gnuplot/data_set_spec.rb b/spec/lib/ruby_gnuplot/data_set_spec.rb new file mode 100644 index 0000000..380aaab --- /dev/null +++ b/spec/lib/ruby_gnuplot/data_set_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Gnuplot::DataSet do + subject(:data_set) { described_class.new(data) } + + describe '#to_gplot' do + context 'when data is an empty array' do + let(:data) { [] } + + it do + expect(data_set.to_gplot).to eq('') + end + end + + context 'when data is an array of numbers' do + let(:data) { [1, 10.0, 2.3] } + + it 'converts to gplot format' do + expect(data_set.to_gplot).to eq("1\n10.0\n2.3") + end + end + + context 'when data is a matrix of numbers' do + let(:data) { [[1, 10.0], [0, 2]] } + + it 'converts to gplot matrix format' do + expect(data_set.to_gplot).to eq("1 0\n10.0 2\ne") + end + end + + context 'when data is a string' do + let(:data) { 'x' } + + it do + expect(data_set.to_gplot).to be_nil + end + end + + context 'when data is an instance of Matrix' do + xit 'to be implemented' + end + + context 'when data is nil' do + let(:data) { nil } + + it do + expect(data_set.to_gplot).to be_nil + end + + it 'assigns data' do + expect(data_set.data).to eq(data) + end + end + end +end From 6decfe0848094128c0d5b6d6cacc45ef53106afb Mon Sep 17 00:00:00 2001 From: darthjee Date: Thu, 28 Nov 2019 22:10:19 +0100 Subject: [PATCH 77/79] Add spec for data set with properties --- spec/lib/ruby_gnuplot/data_set_spec.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/spec/lib/ruby_gnuplot/data_set_spec.rb b/spec/lib/ruby_gnuplot/data_set_spec.rb index 380aaab..a42505f 100644 --- a/spec/lib/ruby_gnuplot/data_set_spec.rb +++ b/spec/lib/ruby_gnuplot/data_set_spec.rb @@ -3,6 +3,8 @@ describe Gnuplot::DataSet do subject(:data_set) { described_class.new(data) } + let(:data) { nil } + describe '#to_gplot' do context 'when data is an empty array' do let(:data) { [] } @@ -41,8 +43,6 @@ end context 'when data is nil' do - let(:data) { nil } - it do expect(data_set.to_gplot).to be_nil end @@ -51,5 +51,20 @@ expect(data_set.data).to eq(data) end end + + context 'when setting attributes' do + subject(:data_set) do + described_class.new do |ds| + ds.with = 'lines' + ds.using = '1:2' + ds.data = [ [0, 1, 2], [1, 2, 5] ] + end + end + + it 'returns only the data' do + expect(data_set.to_gplot) + .to eq("0 1\n1 2\n2 5\ne") + end + end end end From 21fabe5b16658cf7771aaecb9b387c938910240e Mon Sep 17 00:00:00 2001 From: darthjee Date: Thu, 28 Nov 2019 22:25:21 +0100 Subject: [PATCH 78/79] WIP add spec for plot args --- spec/lib/ruby_gnuplot/data_set_spec.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/lib/ruby_gnuplot/data_set_spec.rb b/spec/lib/ruby_gnuplot/data_set_spec.rb index a42505f..efb96f8 100644 --- a/spec/lib/ruby_gnuplot/data_set_spec.rb +++ b/spec/lib/ruby_gnuplot/data_set_spec.rb @@ -52,7 +52,7 @@ end end - context 'when setting attributes' do + context 'when setting attributes in a block' do subject(:data_set) do described_class.new do |ds| ds.with = 'lines' @@ -67,4 +67,23 @@ end end end + + describe '#plot_args' do + context 'when setting attributes on initialize block' do + subject(:data_set) do + described_class.new do |ds| + ds.with = 'lines' + ds.using = '1:2' + ds.data = data + end + end + + let(:data) { [ [0, 1, 2], [1, 2, 5] ] } + + it 'returns plot attributes' do + expect(data_set.plot_args) + .to eq("'-' using 1:2 with lines") + end + end + end end From ac66888a0240b4227248d7f520c25a9ef87a4850 Mon Sep 17 00:00:00 2001 From: Roger Pack Date: Fri, 20 Dec 2019 07:31:31 -0700 Subject: [PATCH 79/79] Update README.textile Note security, thanks Emil --- README.textile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.textile b/README.textile index 4ec5086..3757e4e 100644 --- a/README.textile +++ b/README.textile @@ -16,10 +16,10 @@ h2. History and Background h2. Pre-requisites and Installation - 1. Install XQuartz from here: + 1. (mac) Install XQuartz from here: @http://xquartz.macosforge.org/landing/@ - 2. Install gnuplot with homebrew: + 2. Install gnuplot with homebrew (not OS X? install it using your package manager): @brew install gnuplot --with-x11@ 3. Install gnuplot gem: @@ -188,6 +188,8 @@ File.open( "gnuplot.dat", "w") do |gp| end
+h3. Miscellanrous + You can also add arbitrary lines to the output
@@ -196,3 +198,9 @@ plot.arbitrary_lines << "set ylabel \"y label\" font \"Helvetica,20\""
 
 See more in the examples folder.  Also since this is basically just a wrapper for gnuplot itself, you should be able to do anything that it can do (demos: 
 http://gnuplot.sourceforge.net/demo_4.4/ ) 
+
+h3. Security
+
+Note that if you pass any user-controlled strings to the gem, it's possible for an attacker to run arbitrary commands.
+
+In addition to title, any other graph properties that accept strings should be affected too.  they're all passed to the system command.  So only use strings you trust.