1 /** 2 * A d3 container for the Raphael paper, with delegate helpers to Raphael and select/selectAll functionality. 3 * 4 * @param paper 5 * @constructor 6 * @version Internal; Subject to change 7 * @private 8 */ 9 var D3RaphaelRoot = function(paper) { 10 d3_raphael_addCustomAttributes(paper); 11 this.paper = paper; 12 }; 13 14 /** 15 * Performs a select on the elements in the Raphael paper. 16 * 17 * @param {String} type raphael selector string (currently limited to a Raphael primitive type name, ie: rect, circle, ellipse, text, and path) 18 * @return {D3RaphaelSelection} 19 * @private 20 * @version Internal; Subject to change 21 */ 22 D3RaphaelRoot.prototype.select = function(type) { 23 return d3_raphael_selection([d3_raphael_type_selector(type, this, true)], this) 24 }; 25 26 /** 27 * Performs a selectAll on the elements in the Raphael paper. 28 * 29 * @param {String} type raphael selector string (currently limited to a Raphael primitive type name, ie: rect, circle, ellipse, text, and path) 30 * @return {D3RaphaelSelection} 31 * @private 32 */ 33 D3RaphaelRoot.prototype.selectAll = function(type) { 34 return d3_raphael_selection([d3_raphael_type_selector(type, this, false)], this) 35 }; 36 37 /** 38 * Creates a Raphael paper primitive object. 39 * 40 * @param {String} type type name 41 * @return {*} 42 * @private 43 */ 44 D3RaphaelRoot.prototype.create = function(type) { 45 if(d3_raphael_paperShapes.indexOf(type) < 0) 46 throw "Unsupported shape: " + type; 47 48 return this[type](); 49 }; 50 51 /** 52 * Raphael primitives supported by d34raphael. <br /> 53 * Currently: <code>["circle", "ellipse", "rect", "text", "path"]</code> 54 * 55 * @type {Array} 56 * @constant 57 */ 58 var d3_raphael_paperShapes = ["circle", "ellipse", "rect", "text", "path"]; 59 var d3_raphael_paperDelegateMethods = d3_raphael_paperShapes.concat(["forEach"]); 60 61 function d3_raphael_rootToPaperDelegate(method_name) { 62 return function() { return this.paper[method_name].apply(this.paper, arguments); } 63 }; 64 65 for(var i = 0; i < d3_raphael_paperDelegateMethods.length; i++) { 66 var method_name = d3_raphael_paperDelegateMethods[i]; 67 68 D3RaphaelRoot.prototype[method_name] = d3_raphael_rootToPaperDelegate(method_name); 69 };