Cleanup and refactoring

This commit is contained in:
2024-02-24 08:51:25 +11:00
parent 96c1df617f
commit 2c11fda9ce
5 changed files with 118 additions and 81 deletions

View File

@@ -25,20 +25,22 @@ module Adamantium
latdiff = maxlat - minlat
londiff = maxlon - minlon
svg = Gnuplot.open do |gp|
Gnuplot::Plot.new(gp) do |plot|
plot.arbitrary_lines << "unset border"
plot.arbitrary_lines << "unset xtics"
plot.arbitrary_lines << "unset ytics"
plot.arbitrary_lines << "set size ratio -1"
plot.arbitrary_lines << "set yrange [#{minlat}:#{maxlat}]" if latdiff >= londiff # portrait
plot.arbitrary_lines << "set xrange [#{minlon}:#{maxlon}]" if latdiff < londiff # landscape
plot.arbitrary_lines << "set term svg"
plot.data << Gnuplot::DataSet.new([x, y]) do |ds|
ds.with = "lines"
ds.linewidth = 4
ds.linecolor = 'rgb "#84cc16"'
ds.notitle
svg = with_silent_output do
Gnuplot.open do |gp|
Gnuplot::Plot.new(gp) do |plot|
plot.arbitrary_lines << "unset border"
plot.arbitrary_lines << "unset xtics"
plot.arbitrary_lines << "unset ytics"
plot.arbitrary_lines << "set size ratio -1"
plot.arbitrary_lines << "set yrange [#{minlat}:#{maxlat}]" if latdiff >= londiff # portrait
plot.arbitrary_lines << "set xrange [#{minlon}:#{maxlon}]" if latdiff < londiff # landscape
plot.arbitrary_lines << "set term svg"
plot.data << Gnuplot::DataSet.new([x, y]) do |ds|
ds.with = "lines"
ds.linewidth = 4
ds.linecolor = 'rgb "#84cc16"'
ds.notitle
end
end
end
end
@@ -47,6 +49,16 @@ module Adamantium
Success({svg: svg, distance: gpx.distance(units: "kilometers"), duration: gpx.duration})
end
private
define_method(:with_silent_output) do |&block|
orig_verbose = $VERBOSE
$VERBOSE = nil
result = block.call
$VERBOSE = orig_verbose
result
end
end
end
end