Commit Graph

17 Commits (bf3fffd1e1bc52a5d1b62976fef6688ffe06999b)

Author SHA1 Message Date
David Schnur 35a16ae7fd Switch back to 'middle' baseline rendering.
Ole's original implementation used 'middle', which I switched away from.
After a great deal of testing it turns out that 'middle' does in fact
provide the most consistent results, so we're switching back to it.
13 years ago
David Schnur 9ca3e83447 Use actual line height for canvas text rendering. 13 years ago
David Schnur 825cd36e96 Pre-compute coordinates for each line of text.
The values don't change, so there's no reason to repeat those
calculations on every redraw.  The resulting code is not just faster,
but also smaller and simpler, and we no longer need to store halign in
the text info object.
13 years ago
David Schnur f99a225ffc Set the text baseline only once.
The setting is the same for everything, so there's no reason to re-set
it every time.
13 years ago
David Schnur aefe4e729b Round text coordinates consistently.
The core implementation used parseInt, which was originally to catch
text values, but really only stayed due to its side-effect of flooring
the values.  The canvas implementation has never rounded coordinates.
This led to various one-pixel rendering glitches between the two
implementations.  I've fixed the problem by consistently rounding
coordinates to the nearest whole number.
13 years ago
David Schnur 606c02b842 Tiny optimization; don't set info.y twice. 13 years ago
David Schnur a1b4afc57d A better fix for the font-size 'smaller' problem.
This resolves #991, replacing the earlier temporary patch.  It takes
advantage of the fact that line-height can take the form of a unit-less
integer, in which case it mirrors the font-size, even when it is
something abstract, like 'smaller'.  We can then read the dummy
element's height to learn the effective font-size.
13 years ago
David Schnur 13c71fa03c Temporary patch for font-size parsing issue.
This partially addresses #991, but a more complete solution, or better
documentation, is still necessary.
13 years ago
David Schnur c41b09b844 Only save references to old Canvas methods once.
Plugins are re-initialized with each re-plot (which may not be the right
thing to do, but that's how it works for now).  The previous approach of
saving references to the original Canvas functions therefore broke,
since the second time around we'd get a reference to our new function.
Instead we hold those references as globals within the plugin, and only
set them once.

This whole idea of replacing prototype functions is, now that I step
back and look at it, really awful.  This needs to be changed ASAP to
something less ridiculous.
13 years ago
martinqt 1e6c45bd95 Update js files 13 years ago
David Schnur a2dd0645aa Break text styles into their own cache tier.
Previously the cache was divided only by layer, with entries keyed on a
string built from the text and style.  Now the style has its own tier in
the cache, i.e. layers > styles > text > info.

This introduces some complexity, since the nested for loops are ugly,
but at the same time we avoid having to create the cache-key strings.
More importantly it solves the problem of uniqueness that exists when we
try to join strings that may contain arbitrary text.  It also allows a
further optimization in the canvas plugin, which can now set text style
and color just once per distinct style, instead of with every string.
13 years ago
David Schnur 77e50b175d Allow text to be divided between multiple layers.
This lets users 'namespace' text more naturally, i.e. placing x-axis
labels in a different container from y-axis labels, providing more
flexibility when it comes to styling and interactivity.

Internally the text cache now has a second tier: layers > text > info.
13 years ago
David Schnur 4203a66eba Add text to its actual layer before measuring it.
The getTextInfo method previously added new text to the top-level
container when measuring it.  Now it adds the text to the text layer,
just as it will be when rendered, so that parent-child CSS rules can
resolve correctly.

This also avoids having to safe a reference to the top-level container,
since it wasn't used anywhere else.
13 years ago
David Schnur a036aa962a Reverse cache key order to ensure uniqueness.
Also switch from dashes to pipes, and remove the angle for now, since we
don't currently support rotated text.
13 years ago
David Schnur a9a31644c7 Replace drawText with add and remove methods.
Every cache element now contains the actual text element instead of just
its HTML, plus a flag indicating whether it is visible.  The addText and
removeText methods control the state of this flag, and the render method
uses it to manage elements within the text container.  So where we
previously used drawText to actually render text, now we add each string
once, then let the render method take care of drawing them as necessary.

This dramatically improves performance by eliminating the need to clear
and re-populate HTML text on every drawing cycle.  Since the elements
are now static between add/remove calls, this also allows users to add
interactivity, as they could in 0.7.  Finally, it eliminates the need
for a separate 'hot' cache.

I also removed the unnecessary 'dimensions' object; it's easier and
faster to store the width and height at the top level of the info
object.
13 years ago
David Schnur a0529ee8b1 Moved canvas tick rendering into a plugin.
The base implementation uses the new drawText and getTextInfo methods to
draw text in HTML.  Canvas rendering has been moved to overrides of
these methods within the canvas-render plugin.
13 years ago
David Schnur 42d5592add Added a basic frame for the canvas-drawing plugin. 13 years ago