65 lines
2.8 KiB
Bash
Executable File
65 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# Make gnuplot fill the legend box - but only when the legend is inside the axes.
|
|
#
|
|
# Octave's gnuplot backend emits `set key ...` but never `set key opaque`, and
|
|
# gnuplot's default is noopaque - so a legend drawn INSIDE the axes has a
|
|
# transparent background and plot lines run straight through the text. On a
|
|
# busy plot the legend becomes unreadable, which is exactly when a legend
|
|
# matters most. The legend axes already has color [1 1 1]; Octave simply never
|
|
# tells gnuplot to fill it.
|
|
#
|
|
# An OUTSIDE key needs the opposite. gnuplot packs a key below the axes flush
|
|
# against the x-axis label - a one-pixel gap, whatever the type size - so the
|
|
# fill lands on the label's descenders and erases the tail of every g, y and p
|
|
# in it: "from the trigger edge" renders as "from the triaaer edae". Out there
|
|
# the key sits on the white margin with no plot lines to hide behind it, so
|
|
# the fill buys nothing and costs the label. `noopaque` is also stated rather
|
|
# than left to the default, because `set key opaque` set by an earlier axes
|
|
# persists through the rest of a multiplot stream.
|
|
#
|
|
# Done at image build time rather than at runtime because it edits a vendored
|
|
# Octave library file: in the Dockerfile it is reproducible, visible in review,
|
|
# and cannot be half-applied. It exits 0 when the anchor is absent, so an
|
|
# Octave upgrade that moves this code degrades to the old rendering instead of
|
|
# failing the build.
|
|
set -e
|
|
|
|
ANCHOR='__do_enhanced_option__ (enhanced, hlgnd));'
|
|
ADDED='owuitools: gnuplot defaults to a transparent key'
|
|
found=0
|
|
|
|
for f in /usr/share/octave/*/m/plot/util/private/__gnuplot_draw_axes__.m; do
|
|
[ -f "$f" ] || continue
|
|
if grep -q "$ADDED" "$f"; then
|
|
echo "legend-opaque: already applied to $f"
|
|
found=1
|
|
continue
|
|
fi
|
|
n=$(grep -c "$ANCHOR" "$f" || true)
|
|
if [ "$n" != "1" ]; then
|
|
echo "legend-opaque: anchor appears $n times in $f, skipping"
|
|
continue
|
|
fi
|
|
awk -v anchor="$ANCHOR" -v added="$ADDED" '
|
|
{ print }
|
|
index($0, anchor) && !done {
|
|
done = 1
|
|
print " ## " added ", so plot lines show"
|
|
print " ## through the legend text. The legend axes is already white."
|
|
print " ## Outside the axes the fill has nothing to hide and lands on"
|
|
print " ## the x-axis label instead, so there it is turned off - and"
|
|
print " ## said out loud, because opaque persists across a multiplot."
|
|
print " if (strcmp (inout, \"inside\"))"
|
|
print " fputs (plot_stream, \"set key opaque;\\n\");"
|
|
print " else"
|
|
print " fputs (plot_stream, \"set key noopaque;\\n\");"
|
|
print " endif"
|
|
}
|
|
' "$f" > "$f.owuitools" && mv "$f.owuitools" "$f"
|
|
echo "legend-opaque: applied to $f"
|
|
found=1
|
|
done
|
|
|
|
[ "$found" = "1" ] || echo "legend-opaque: target not found, skipping"
|
|
exit 0
|