walden - glad to hear someone else also struggles with how to balance
CSS vs Java API specification.
Peter- the Adobe link and related suggestions were particularly
helpful/relevant.
Though the Adobe approach that carefully blends both CSS and api based
specifications looks quite sophisticated, I don't think it's feasible
to add anything that complex to GChart (maybe in a future version if
other/smarter people got involved).
The justification for my decision not to include "deep" CSS support in
GChart is contained in the following (not yet released) javadoc
excerpt (I've changed my mind many times already on this decision, so
if someone comes up with a compelling argument on the other side, I
would not be surprised if I changed it again).
<gchart-javadoc-excerpt>
CSS Style Rule
.gchart-GChart { the GChart's primary top-level styles }
Why such limited CSS support?
One person asked, to paraphrase, "why doesn't GChart provide, say,
a stylename like gchart-GChart-curve-1 that would allow me to style
the first curve?"
Because stylename support is a GWT best practice, I seriously
considered such an approach. But I ultimately decided (except for the
top-level stylename above) to go with a straight Java API based
specification instead because:
* Despite a lot of effort, I couldn't find a good algorithm
for placing tick labels properly unless I knew the font size in pixels
before the chart was rendered in the browser. It is because GChart's
Java API only allows tick label font sizes to be specified in pixels
(ruling out, for example, the relative units CSS allows) that GChart's
simple tick label placement algorithm can work. In general, having all
the info needed to layout chart elements up front (independent of what
is going on in the page that contains the GChart) makes the task of
laying out the chart a lot easier to handle.
* Since Google may add a browser independent vector graphics
library to a future GWT version, I didn't want to lock GChart into an
HTML element based rendering scheme (any stylesheet based curve color
specs could break if GChart started rendering curves with such a
vector graphics package). In general, I wanted to "keep GChart's
implementation options open" by not tacitly exposing their internal
element structure via "deep" stylenames.
* GChart applications could require fine-grained, dynamic
control over chart features (e.g., letting the user select a curve's
color from a pop-up with hundreds of possible choices). CSS is best
for switching between a few predefined style categories (e.g. selected
vs unselected tree items) rather than for such fine-grained control.
Thus even if CSS support were provided and adequate for some
applications, finer-grained API-based styling control would likely
still be needed for others. But having some styling use a stylesheet,
and other styling the Java API, could create additional confusion for
users.
* GChart's Java API specification approach, though not fully
leveraging CSS, compensates for this limitation by providing these
benefits:
o It results in a much more succinct and centralized
(and easy to test) specification of what a GChart can do. Of the
myriad of potential CSS options you might consider using, the API
provides only those you are likely to need. And, because the the CSS
styling options are restricted, they are more likely to have been
cross-browser tested and thus to actually work.
o Your Java IDE's drop down lists and such work with
every GChart feature--thanks to wrapper API methods around GChart's
CSS-powered features. No need to switch from Java IDE tooling to CSS
tooling (which, if your CSS tools are as primitive as mine, is often
just a text editor and a manual).
o Method names can be GChart-specific in a way that
makes it more obvious what they do, and the full OO syntax of Java
clarifies how each specification changes the GChart in question. With
CSS (except for the stylename itself) you are stuck using the generic,
low-level, element-related names for the actual properties. These may
or may not be appropriate, depending on the exact role those element
attributes play in realizing chart features.
o Although CSS has a vast syntax, in point of fact only
a handful of these choices are applicable for a GChart. Thus I didn't
have to add many CSS wrapper methods, and the "API clutter" issue that
often comes up with the use of such wrapper methods was not a serious
concern.
o You still use standard CSS syntax in the arguments you
pass to these CSS wrapper methods. Thus you can still leverage your
CSS knowledge--just not via a stylesheet, and in a more restricted
way.
Overall, your ability to control a GChart's styling directly from
a CSS stylesheet without using Java is analogous to what you get with
a GIF or PGN image: with the exception of a few top-level features
(like border and background for the entire image or GChart), the
detailed internal styling cannot be changed via a CSS stylesheet. This
very limited level of CSS stylesheet control has never been a serious
problem for better known, server-based, charting tools like jFreeChart
or the Google Chart API. So I think it will work out OK for GChart,
too.
</gchart-javadoc-excerpt>