Skip to content

Commit 8eb868b

Browse files
committed
Gnuplot.new: new keyword option: path, persist
1 parent bf174fc commit 8eb868b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/numo/gnuplot.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ def initialize(&block)
3535
@block = block
3636
end
3737

38+
@@pool = nil
39+
3840
def to_iruby
3941
require 'tempfile'
4042
tempfile_svg = Tempfile.open(['plot','.svg'])
4143
# output SVG to tmpfile
42-
gp = Gnuplot.default
44+
@@pool ||= Gnuplot.new(persist:false)
45+
gp = @@pool
4346
gp.reset
4447
gp.set terminal:'svg'
4548
gp.set output:tempfile_svg.path
@@ -51,12 +54,15 @@ def to_iruby
5154
end
5255
end
5356

54-
def initialize(gnuplot_command="gnuplot")
57+
def initialize(path:"gnuplot", persist:true)
58+
@path = path
59+
@persist = persist
5560
@history = []
5661
@debug = false
5762
r0,@iow = IO.pipe
5863
@ior,w2 = IO.pipe
59-
IO.popen(gnuplot_command,:in=>r0,:err=>w2)
64+
path += " -persist" if persist
65+
IO.popen(path,:in=>r0,:err=>w2)
6066
r0.close
6167
w2.close
6268
@gnuplot_version = send_cmd("print GPVAL_VERSION")[0].chomp
@@ -69,6 +75,8 @@ def initialize(gnuplot_command="gnuplot")
6975
end
7076
end
7177

78+
attr_reader :path
79+
attr_reader :persist
7280
attr_reader :history
7381
attr_reader :last_message
7482
attr_reader :gnuplot_version

0 commit comments

Comments
 (0)