VMLGraphic.js revision 09688ec5ffb8b9cf9883a770e2f9ebd60b28888d
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * VMLGraphic is a simple drawing api that allows for basic drawing operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @class VMLGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @constructor
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp getXY: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Initializes the class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method initializer
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.setSize(w, h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Indicates whether or not the instance will automatically redraw after a change is made to a shape.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * This property will get set to false when batching operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property autoDraw
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Boolean
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @default true
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Clears the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method clear
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp clear: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes all nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method destroy
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp destroy: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes all child nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _removeChildren
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Shows and and hides a the graphic instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method toggleVisible
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param val {Boolean} indicates whether the instance should be visible.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Toggles visibility
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _toggleVisible
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {HTMLElement} node element to toggle
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Boolean} val indicates visibilitye
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for(; i < len; ++i)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the size of the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method setSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param w {Number} width to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param h {Number} height to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp setSize: function(w, h) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w = Math.round(w);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = Math.round(h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the positon of the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method setPosition
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate for the object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate for the object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp setPosition: function(x, y)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x = Math.round(x);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y = Math.round(y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds the graphics node to the dom.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method render
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {HTMLElement} parentNode node in which to render the graphics node into.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w = parseInt(parentNode.getComputedStyle("width"), 10);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = parseInt(parentNode.getComputedStyle("height"), 10);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.setSize(w, h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Updates the size of the graphics object
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _trackSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} w width
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} h height
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _trackSize: function(w, h) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (w > this._width) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (h > this._height) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Clears the properties
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _initProps
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _initProps: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._fillColor = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._fillProps = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._fill = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._stroked = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._dashstyle = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Creates a group element
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _createGraphic: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var group = document.createElement('<group xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:block;zoom:1;" />');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Creates a graphic node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createGraphicNode
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} type node type to create
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} pe specified pointer-events value
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return HTMLElement
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return document.createElement('<' + type + ' xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:inline-block;zoom:1;" />');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds a shape instance to the graphic instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method addShape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Shape} shape The shape instance to be added to the graphic.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Returns a shape based on the id of its dom node.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method getShapeById
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} id Dom id of the shape's node attribute.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return Shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Generates a shape instance by type.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method getShape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} type type of shape to generate.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Object} cfg attributes for the shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return Shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds a child to the <code>node</code>.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method addChild
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {HTMLElement} element to add
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Allows for creating multiple shapes in order to batch appending and redraw operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method batch
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Function} method Method to execute.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.autoDraw = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._frag = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.autoDraw = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Updates the size of the graphics container and.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method updateSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp updateSize: function(e)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //len = shapes.length,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //for(; i < len; ++i)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //shape = this.getShapeById(shapes[i].getAttribute("id"));