var Interceptor = { prevTotalCount :0, totalCount : 0, currentColor : 'white', objectArea : 0, objectDescription : '', bgColor : 'white', coordinates : [], canvasDetails : { width : 0, height: 0 }, setupObject : { objectArray : [], objectCount : 0, objectTypeCount : {} }, drawObject : { objectArray : [], objectCount : 0, objectTypeCount : {} }, isCleared : false, noRows: 10, noCols: 10, coordLoc : {}, getColorName : function(arguments) { if(arguments.length==3) { //assuming that we are doing RGB - convert RGB values to a name var color = '#' + arguments[0].toString(16).paddingLeft("00") + arguments[1].toString(16).paddingLeft("00") + arguments[2].toString(16).paddingLeft("00"); var n_match = ntc.name(color); return n_match[1]; } else if(arguments.length==1) { if(!(typeof(arguments[0])).localeCompare("number")) { //assuming that we are doing RGB - this would be a grayscale number if(arguments[0]<10) { return 'black'; } else if(arguments[0]>240) { return 'white'; } else { return 'grey'; } } else if(!(typeof(arguments[0])).localeCompare("string")) { if(!arguments[0].charAt(0).localeCompare('#')) { //if user has entered a hex color var n_match = ntc.name(arguments[0]); return n_match[1]; } else { return arguments[0]; } } } }, /* return which part of the canvas an object os present */ canvasAreaLocation : function(x,arguments,canvasX,canvasY){ var x_loc,y_loc; for(var i=0;i-1) { x_loc = a; } else if(x.params[i].description.indexOf("y-coordinate")>-1) { y_loc = a; } } if(x_loc<0.4*canvasX) { if(y_loc<0.4*canvasY) { return 'top left'; } else if(y_loc>0.6*canvasY) { return 'bottom left'; } else { return 'mid left'; } } else if(x_loc>0.6*canvasX) { if(y_loc<0.4*canvasY) { return 'top right'; } else if(y_loc>0.6*canvasY) { return 'bottom right'; } else { return 'mid right'; } } else { if(y_loc<0.4*canvasY) { return 'top middle'; } else if(y_loc>0.6*canvasY) { return 'bottom middle'; } else { return 'middle'; } } }, /* return which part of the canvas an object os present */ canvasLocator : function(x,arguments,canvasX,canvasY){ var x_loc, y_loc; var locX, locY; for(var i=0;i-1) { x_loc = a; } else if(x.params[i].description.indexOf("y-coordinate")>-1) { y_loc = a; } } locX = Math.floor((x_loc/canvasX)*this.noRows); locY = Math.floor((y_loc/canvasY)*this.noCols); if( locX == this.noRows) { locX = locX - 1; } if( locY == this.noCols) { locY = locY - 1; } return({ locX: locX, locY: locY }) }, clearVariables : function(object) { object.objectTypeCount = {}; object.objectCount = 0; this.isCleared = true; return object; }, createShadowDOMElement : function(document) { var contentTable = document.getElementById('textOutput-content-table'); for(var i=0; i createCanvas if(!x.name.localeCompare('createCanvas')) { this.canvasDetails.width = arguments[0]; this.canvasDetails.height = arguments[1]; } } /* Here - most of the functions are generalised, but some need specific outputs */ /* for `fill` function */ if(!x.name.localeCompare('fill')) { this.currentColor = this.getColorName(arguments); } /* for `background` function */ else if(!x.name.localeCompare('background')) { this.bgColor = this.getColorName(arguments); } /* for 2D functions and text function */ else if(!x.module.localeCompare('Shape') || !x.module.localeCompare('Typography') &&((!x.submodule)||(x.submodule.localeCompare('Attributes')!=0)) ){ this.objectArea = this.getObjectArea(x.name, arguments); var canvasLocation = this.canvasAreaLocation(x, arguments ,width,height); this.coordLoc = this.canvasLocator(x,arguments,width,height); /* in case of text, the description should be what is in the content */ if(x.name.localeCompare('text')){ this.objectDescription = x.name; } else { this.objectDescription = arguments[0].substring(0,20); } objectArray[objectCount] = { 'type' : this.currentColor + ' - ' + this.objectDescription , 'location': canvasLocation, //top left vs top right etc 'coordLoc': this.coordLoc, // 3,3 vs 5,3 etc 'area': this.objectArea, 'co-ordinates': this.coordinates // coordinates of where the objects are drawn }; this.coordinates = []; /*add the object(shape/text) parameters in objectArray */ for(var i=0;i-1) { objectArray[objectCount]['co-ordinates'].push(arguments[i]+'x') } else if(x.params[i].description.indexOf("y-coordinate")>-1) { objectArray[objectCount]['co-ordinates'].push(arguments[i]+'y') } else{ objectArray[objectCount][x.params[i].description]=arguments[i]; } } if(objectTypeCount[x.name]) { objectTypeCount[x.name]++; } else { objectTypeCount[x.name]=1; } objectCount++; } return ({ objectCount : objectCount, objectArray : objectArray, objectTypeCount : objectTypeCount }); }, populateTable : function(objectArray,document_passed) { if(this.totalCount<100) { for(var i=0;i 1 ) { elementSummary.innerHTML += ' Contains ' + this.totalCount + ' objects - '; } else { elementSummary.innerHTML += ' Contains ' + this.totalCount + ' object - '; } if(object2.objectCount>0 || object1.objectCount>0 ) { totObjectTypeCount = MergeObjRecursive(object1.objectTypeCount, object2.objectTypeCount); var keys = Object.keys(totObjectTypeCount); for(var i=0;i