This creates a single command: voronoi_labels!(…) to directly annotate the graph.
(This currently requires an edit to VoronoiCells, see pull request here. )
using Random
Random.seed!(1)
using CairoMakie
include("voronoi-labels.jl")
f = lines(cumsum(randn(100)), label="Are Great",
color=Cycled(1), marker=:rect)
lines!(f.axis, cumsum(randn(100)), label="Direct",
color=Cycled(2))
lines!(f.axis, cumsum(randn(100)), label="Labels",
color=Cycled(3))
# make it look nicer
f.axis.topspinevisible = false
f.axis.leftspinevisible = false
f.axis.rightspinevisible = false
f.axis.xgridvisible = false
labels = voronoi_labels!(f; offset=1.0)
labels[1].offset[] = 1.5 # manual tweak of one label
f
What I need help with
I’m trying to gauge interest in this idea and ideally, solicit some help.
Interaction with Makie:
working with scales – everything really should work in screen / pixel space;
what’s the best way to get and plot things directly in screen space on top of
an existing axis with lines / scatter?
getting bounding boxes of labels/ checking intersections/etc. (boundingbox(text!(...)) does something I can’t seem to figure out in terms of information about plots in the axis.
thoughts on how else this might be done / made easier / etc.!
Vision
The idea is to make adding even easier than a legend!
There are a few ways to add these automatic labels in other software.
I really like the idea of direct labelling. One reason why I’ve so far stayed away from implementing something like it is that I couldn’t quickly come up with clear semantics how labels should be placed given that a multitude of plot objects might be in a given Axis, and the Axis can change size due to layout recalculations. Effectively, the position of one label would depend on all other plot objects in the Axis, correct? (In order to minimize visual overlap). Right now, one plot object doesn’t even have access to the others in the same Axis, so that part is not quite clear to me. And if it’s supposed to work with interactive figures, the updating process would also have to be clarified.
Overall, great effort, and I’m very interested to see where this goes.
The interaction with interactive plots will be interesting. Right now, I’m just trying to get things to make sense and be easy to use and give good results for a static plot. However, I would note that just the simple axis and ticks have all of the same challenges in terms of number of plots and datapoints, etc. I will try and take a quick look at how they solve similar issues.