VMLGraphic.js revision a89ad754cce3cfc8aee71760e10217b54020360d
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * VMLGraphic is a simple drawing api that allows for basic drawing operations.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @class VMLGraphic
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @constructor
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippVMLGraphic = function() {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp VMLGraphic.superclass.constructor.apply(this, arguments);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Key value pairs in which a shape instance is associated with its id.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute shapes
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type Object
16178708ecddc36b034aea99e129ceffa009ac05Tripp * @readOnly
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp getter: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this._shapes;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Object containing size and coordinate data for the content of a Graphic in relation to the coordSpace node.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @attribute _coordPlaneNode
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type Object
f69d245bb21be88752420e834a6b6be37e9b525fTripp getter: function()
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp return this._contentBox;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * The html element that represents to coordinate system of the Graphic instance.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute coordPlaneNode
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type HTMLElement
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp getter: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp getXY: function()
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Initializes the class.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method initializer
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._coordPlaneNode.setAttribute("id", this.get("id"));
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Indicates whether or not the instance will automatically redraw after a change is made to a shape.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * This property will get set to false when batching operations.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @property autoDraw
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @type Boolean
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @default true
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Clears the graphics object.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method clear
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp clear: function() {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Removes all nodes.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method destroy
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp destroy: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._coordPlaneNode.parentNode.removeChild(this._coordPlaneNode);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Removes all shape instances from the dom.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method removeAllShapes
f69d245bb21be88752420e834a6b6be37e9b525fTripp * Removes all child nodes.
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @method _removeChildren
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @param node
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Shows and and hides a the graphic instance.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method toggleVisible
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @param val {Boolean} indicates whether the instance should be visible.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Toggles visibility
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _toggleVisible
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {HTMLElement} node element to toggle
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Boolean} val indicates visibilitye
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for(; i < len; ++i)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Sets the size of the graphics object.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method setContentSize
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param w {Number} width to set for the instance.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param h {Number} height to set for the instance.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp setContentSize: function(w, h) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp w = Math.round(w);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp h = Math.round(h);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Sets the positon of the graphics object.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method setPosition
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} x x-coordinate for the object.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} y y-coordinate for the object.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp setPosition: function(x, y)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp x = Math.round(x);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp y = Math.round(y);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Adds the graphics node to the dom.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method render
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {HTMLElement} parentNode node in which to render the graphics node into.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp w = this.get("width") || parseInt(parentNode.getComputedStyle("width"), 10),
f69d245bb21be88752420e834a6b6be37e9b525fTripp h = this.get("height") || parseInt(parentNode.getComputedStyle("height"), 10);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Clears the properties
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _initProps
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _initProps: function() {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._fillColor = null;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this._fillProps = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._fill = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._stroked = false;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._dashstyle = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Creates a group element
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _createGraphic
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp _createGraphic: function() {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp var group = document.createElement('<group xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:block;zoom:1;" />');
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Creates a graphic node
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method _createGraphicNode
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {String} type node type to create
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {String} pe specified pointer-events value
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @return HTMLElement
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp return document.createElement('<' + type + ' xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:inline-block;zoom:1;" />');
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Adds a shape instance to the graphic instance.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method addShape
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {Shape} shape The shape instance to be added to the graphic.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Returns a shape based on the id of its dom node.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method getShapeById
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {String} id Dom id of the shape's node attribute.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @return Shape
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Generates a shape instance by type.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method getShape
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {String} type type of shape to generate.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {Object} cfg attributes for the shape
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @return Shape
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Removes a shape instance from from the graphic instance.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method removeShape
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {Shape|String}
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Adds a child to the <code>node</code>.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @method addChild
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {HTMLElement} element to add
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Allows for creating multiple shapes in order to batch appending and redraw operations.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @method batch
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {Function} method Method to execute.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp this.autoDraw = false;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp this._frag = null;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp this.autoDraw = true;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Updates the size of the graphics container and.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @method updateContentBox