1 /**
  2  * Source: NodeLayer.js
  3  * Copyright (c) 2013-2014 Oculus Info Inc.
  4  * @fileOverview Aperture Node Layer
  5  */
  6 
  7 aperture = (
  8 /** @private */
  9 function(namespace) {
 10 
 11 	/**
 12 	 * @exports NodeLayer as aperture.NodeLayer
 13 	 */
 14 	var NodeLayer = aperture.PlotLayer.extend( 'aperture.NodeLayer',
 15 	/** @lends NodeLayer# */
 16 	{
 17 		/**
 18 		 * @augments aperture.PlotLayer
 19 		 * @class Layer that takes in x/y visual mappings and draws all child layer
 20 		 * items at the specified x/y.  Also allows mapping of x and y anchor positions.
 21 		 * Supports DOM and Vector child layers.  The following data mappings are understood:
 22 
 23 		 * @mapping {Number} node-x
 24 		 *   The x-coordinate at which to locate the child layer visuals.
 25 		 * 
 26 		 * @mapping {Number} node-y
 27 		 *   The y-coordinate at which to locate the child layer visuals.
 28 		 * 
 29 		 * @mapping {Number} width
 30 		 *   The declared width of the node, which may factor into layout.
 31 		 * 
 32 		 * @mapping {Number} height
 33 		 *   The declared height of the node, which may factor into layout.
 34 		 * 
 35 		 * @constructs
 36 		 * @factoryMade
 37 		 */
 38 		init : function(spec, mappings) {
 39 			aperture.PlotLayer.prototype.init.call(this, spec, mappings);
 40 		},
 41 
 42 		canvasType : aperture.canvas.VECTOR_CANVAS,
 43 
 44 		render : function(changeSet) {
 45 			var that = this,
 46 				x, y, xAnchor, yAnchor, width, height, item;
 47 			
 48 			// Treat adds and modifies the same - just need to update positions
 49 			aperture.util.forEach(changeSet.updates, function( node ) {
 50 				item = node.data;
 51 				// Discover the mapped visual properties
 52 				x = this.valueFor('node-x', item, 0);
 53 				y = this.valueFor('node-y', item, 0);
 54 				width = this.valueFor('width', item , 1);
 55 				height = this.valueFor('height', item , 1);
 56 
 57 				// Update the given node in place with these values
 58 				node.position = [x,y];
 59 
 60 				node.userData.id = item.id;
 61 				
 62 				// Update width/height (if it matters?)
 63 				node.width = width;
 64 				node.height = height;
 65 			}, this);
 66 			
 67 			
 68 			// will call renderChild for each child.
 69 			aperture.PlotLayer.prototype.render.call( this, changeSet );
 70 		}
 71 
 72 	});
 73 
 74 	namespace.NodeLayer = NodeLayer;
 75 
 76 	/**
 77 	 * @class NodeLink is a {@link aperture.NodeLayer NodeLayer}  vizlet, suitable for adding to the DOM.
 78 	 * @augments aperture.NodeLayer
 79 	 * @name aperture.NodeLink
 80 	 *
 81 	 * @constructor
 82 	 * @param {String|Element} parent
 83 	 *      A string specifying the id of the DOM element container for the vizlet or
 84 	 *      a DOM element itself.
 85 	 * @param {Object} [mappings]
 86 	 *      An optional initial set of property mappings.
 87 	 *
 88 	 * @see aperture.NodeLayer
 89 	 */
 90 	namespace.NodeLink = aperture.vizlet.make( NodeLayer );
 91 
 92 	return namespace;
 93 
 94 }(aperture || {}));
 95