Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/gnuplotrb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def require_if_available(name)
require 'gnuplotrb/external_classes/string'
require 'gnuplotrb/external_classes/array'
require 'gnuplotrb/external_classes/daru'
require 'gnuplotrb/external_classes/dir'


require 'gnuplotrb/version'
require 'gnuplotrb/staff/settings'
Expand Down
2 changes: 1 addition & 1 deletion lib/gnuplotrb/animation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def plot(path = nil, **options)
plot_opts.merge(term: ['gif', anim_opts])
end.to_h
need_output = plot_options[:output].nil?
plot_options[:output] = Dir::Tmpname.make_tmpname('anim', 0) if need_output
plot_options[:output] = Dir.gnuplot_tmpname('anim') if need_output
terminal = Terminal.new
multiplot(terminal, plot_options)
# guaranteed wait for plotting to finish
Expand Down
9 changes: 9 additions & 0 deletions lib/gnuplotrb/external_classes/dir.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
##
# Utility methods for GnuplotRB.
class Dir
# @return temporary file name
def self.gnuplot_tmpname(name)
t = Time.now.strftime('%Y%m%d')
"#{Dir.tmpdir}/gnuplotrb-#{name}-#{t}-#{$PID}-#{rand(0x100000000).to_s(36)}"
end
end
2 changes: 1 addition & 1 deletion lib/gnuplotrb/mixins/plottable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def to_specific_term(terminal, path = nil, **options)
if path
result = plot(term: [terminal, options], output: path)
else
path = Dir::Tmpname.make_tmpname(terminal, 0)
path = Dir.gnuplot_tmpname(terminal)
plot(term: [terminal, options], output: path)
result = File.binread(path)
File.delete(path)
Expand Down
2 changes: 1 addition & 1 deletion lib/gnuplotrb/staff/datablock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(data, stored_in_file = false)
@stored_in_file = stored_in_file
data_str = data.to_gnuplot_points
if @stored_in_file
@file_name = Dir::Tmpname.make_tmpname('tmp_data', 0)
@file_name = Dir.gnuplot_tmpname('tmp_data')
File.write(@file_name, data_str)
name = File.join(Dir.pwd, @file_name)
ObjectSpace.define_finalizer(self, proc { File.delete(name) })
Expand Down