def self.ggplot(data, script = nil, width = nil, height = nil, options = {})
width ||= 2
height ||= 2
values = []
options = options.dup
sources = [:plot, :svg, options[:source]].flatten.compact
options.delete :source
entity_geom = options.delete :entity_geom
field_classes = options[:field_classes]
fast = options[:fast]
if fast
save_method = "rbbt.SVG.save.fast"
else
save_method = "rbbt.SVG.save"
end
if data
field_classes = R.field_classes(data) if field_classes.nil?
if field_classes.any?
options[:R_open] ||= "colClasses=c('character'," + field_classes * ", " + ')'
else
options[:R_open] ||= "colClasses=c('character')"
end
TmpFile.with_file nil, true, :extension => 'svg' do |tmpfile|
if entity_geom
data.R <<-EOF, sources, options
plot = { #{script} }
#{save_method}('#{tmpfile}', plot, width = #{R.ruby2R width}, height = #{R.ruby2R height}, entity.geom=#{R.ruby2R(entity_geom)}, data=data)
data = NULL
EOF
else
data.R <<-EOF, sources, options
plot = { #{script} }
#{save_method}('#{tmpfile}', plot, width = #{R.ruby2R width}, height = #{R.ruby2R height})
data = NULL
EOF
end
Open.read(tmpfile).gsub(/(glyph\d+-\d+)/, '\1-' + File.basename(tmpfile))
end
else
TmpFile.with_file nil, true, :extension => 'svg' do |tmpfile|
R.run <<-EOF, sources, options
plot = { #{script} }
#{save_method}('#{tmpfile}', plot, width = #{R.ruby2R width}, height = #{R.ruby2R height})
data = NULL
EOF
Open.read(tmpfile).gsub(/(glyph\d+-\d+)/, '\1-' + File.basename(tmpfile))
end
end
end