How to show values upon mouse hover in Gnuplot in SVG?

Viewed 332

After noticing the interactive gnuplot graphic upon https://lwn.net/Articles/723818/ showing country names on a mouse hover, I am wondering how to simply show the values of the points in a plot.

For example I want to hover over the "daughter bar" in https://s.natalian.org/2020-08-24/mouse-hover.svg and see 60 clearly.

SVG hover

However right now it just shows co-ordinates IIUC. How do I fix this?

set term svg mouse standalone
reset
$heights << EOD
dad                     181
mom                     170
son                     100
daughter        60
EOD

unset key
set boxwidth 0.5
set style fill solid
set yrange [0:*]

plot '$heights' using 2:xtic(1) with boxes
set output '/tmp/mouse-hover.svg'
replot
1 Answers

You are looking for hypertext, check help hypertext. You have to use point to anchor the hypertext. Play with the pointsize (here ps 3) to change the area where the mouse will display the hypertext. Since you probably don't want to display a colored point at the top of your box, make the color transparent, e.g. lc rgb 0xff123456.

Unfortunately, I haven't found (yet) anything in the gnuplot documentation how to make the font of this hypertext larger. The option font ",30" does not have any effect. If you find out please let me know. Apparently in wxt terminal you can do it (see gnuplot: Hypertext with monospace?).

Code:

### SVG standalone with hypertext
reset session
set term svg mouse standalone enhanced
set output 'tbSVGstandalone.svg'

$heights <<EOD
dad            181
mom            170
son            100
daughter        60
EOD

unset key
set boxwidth 0.5
set style fill solid
set yrange [0:*]

plot '$heights' u 2:xtic(1) w boxes,\
     '' u 0:2:2 w labels hypertext point pt 7 ps 3 lc rgb 0xff123456
set output
### end of code

Result: (screenshot of SVG in Firefox. It looks like I can't place a SVG here, at least I don't know how.)

enter image description here

Related