Hi,
I do have an idea.
Problem:
The problem is, that a plot has a huge amount of places where
you will want to tweak its appearance e.g. fonts are used in
- plot title
- axis title
- axis label
- legend entries
- legend title (not jet)
- facet labels (not jet)
- text glyphs (not jet)
and each requires a font. Switching from Arial for plots used on
the web to Concrete Roman for publishing is painful: If you forget
to change to font on the plot title your plot mixes different fonts.
(Gnuplot suffers from this issue.)
Additional ugliness for font comes from fonts being loaded and
the necessity to deal with the associated failures.
Solution:
What works well are themes and a hierarchical organisation.
CSS is not that bad, it just has a complex box model.
How about packing all styling information into a new type Theme
which provides hierarchical settings with fallback to settings
"higher up"? Creating (or instantiating) a theme may fail (e.g.
because fonts are unavailable) but using a theme will is always
possible.
This would allow e.g. an axis to retrieve the tic label font
(typeface, size, color) if tics labels have to be drawn. If no special
tic label size is specified in the theme the value is looked up
in one of the parent nodes.
Such a hierarchy could look like the one ggplot2 uses, see
http://docs.ggplot2.org/current/theme.html
Examples:
E.g. theme["/axis.line.color"] = blue could set the color of
any line related to an axis to be blue while
theme["/axis/x/tics/major.font.size"] = 8 would fix the font size
of the major tics label to 8. Unset values propagate up and may
end accessing theme["/.font.size"] which is the global font size.
Maybe an autogenerated color axis (needed because some
ColorBubbles Plotter is used) could be set up pragmatically by
a plot. It would use theme["/axis/color/tics/label.font..."] to
draw the tic labels; if unset this might use some global setting.
Such theming would allow to provide high quality themes, e.g.
Traditional, Ggplot2, Gnuplot to mimic common plot appearances.
Benefit:
Having themed plot would:
- replace lots of draw.{Text,Line}Style fields with either a theme
or a theme parameter to the drawing methods.
- allow to add new visual stuff easily, e.g. a box around legends
or a background to legends or a title to the legends: You need
one switch to turn it on/of and entries in the default themes.
- allow to have non-failing functions/methods, e.g. a constructor
plot.NewFrom(theme Theme) *plot.Plot would be possible.
TODO: Find a typesafe representation of various style settings and
a sensible hierarchy.
Drawbacks:
Lots of code changes, and incompatible API changes.
What do you think?
V.
--
Dr. Volker Dobler