jquery.flot.canvaswrapper

This plugin contains the function for creating and manipulating both the canvas layers and svg layers.

The Canvas object is a wrapper around an HTML5 canvas tag. The constructor Canvas(cls, container) takes as parameters cls, the list of classes to apply to the canvas adnd the containter, element onto which to append the canvas. The canvas operations don’t work unless the canvas is attached to the DOM.

jquery.canvaswrapper.js API functions

Resizes the canvas to the given dimensions. The width represents the new width of the canvas, meanwhile the height is the new height of the canvas, both of them in pixels.

Clears the entire canvas area, not including any overlaid HTML text

Finishes rendering the canvas, including managing the text overlay.

Creates (if necessary) and returns the SVG overlay container. The classes string represents the string of space-separated CSS classes used to uniquely identify the text layer. It return the svg-layer div.

Creates (if necessary) and returns a text info object. The object looks like this:

 {
     width //Width of the text's wrapper div.
     height //Height of the text's wrapper div.
     element //The HTML div containing the text.
     positions //Array of positions at which this text is drawn.
  }

The positions array contains objects that look like this:

  {
     active //Flag indicating whether the text should be visible.
     rendered //Flag indicating whether the text is currently visible.
     element //The HTML div containing the text.
     text //The actual text and is identical with element[0].textContent.
     x //X coordinate at which to draw the text.
     y //Y coordinate at which to draw the text.
  }

Each position after the first receives a clone of the original element. The idea is that that the width, height, and general ‘identity’ of the text is constant no matter where it is placed; the placements are a secondary property.

Canvas maintains a cache of recently-used text info objects; getTextInfo either returns the cached element or creates a new entry.

The layer parameter is string of space-separated CSS classes uniquely identifying the layer containing this text. Text is the text string to retrieve info for. Font is either a string of space-separated CSS classes or a font-spec object, defining the text’s font and style. Angle is the angle at which to rotate the text, in degrees. Angle is currently unused, it will be implemented in the future. The last parameter is the Maximum width of the text before it wraps. The method returns a text info object.

Adds a text string to the canvas text overlay. The text isn’t drawn immediately; it is marked as rendering, which will result in its addition to the canvas on the next render pass.

The layer is string of space-separated CSS classes uniquely identifying the layer containing this text. X and Y represents the X and Y coordinate at which to draw the text. and text is the string to draw

Clears the cache used to speed up the text size measurements. As an (unfortunate) side effect all text within the text Layer is removed. Use this function before plot.setupGrid() and plot.draw() if the plot just became visible or the styles changed.