-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathofp.min.js
1 lines (1 loc) · 3.14 KB
/
ofp.min.js
1
ofp={version:"0.0.1"},d3.selection.prototype.size=function(){var e=0;return this.each(function(){++e}),e},ofp.Layer=function(e,s){function i(){n.layerType.idList.forEach(function(e){var s=t.svg.selectAll(e);s&&s.size()>0&&!s.classed(n.layerType.className)&&s.classed(n.layerType.className,!0)})}this.name=e.name,this.layerType=e;var t=s,n=this;this.remove=function(){this.layer.remove(),this.layer=d3.selectAll(this.layerType.idList.join())},i(),this.layer=t.svg.selectAll("."+e.className),this.elements=this.layer.selectAll("polygon, line, path, text"),console.log("Initialized Layer: "+this.layerType.name+" with "+this.elements.size()+" elements.")},ofp.Layer.prototype={name:"",layerType:null,layer:null,hide:function(){this.layer.style("display","none")},show:function(){this.layer.style("display","")},size:function(){return this.layer.size()}},ofp.LayerType=function(e,s,i){this.name=e,this.className=s,this.idList=i},ofp.LayerType.prototype={name:"",className:"",idList:[]},ofp.LayerType.Space=new ofp.LayerType("Space","ofp-space",["#bgspa_space_area_b"]),ofp.LayerType.Column=new ofp.LayerType("Column","ofp-column",["#Column","#bgspa_column_area_b"]),ofp.LayerType.Construction=new ofp.LayerType("Construction","ofp-construction",["#Constructions","#Frames"]),ofp.LayerType.DimensionAnnotations=new ofp.LayerType("Dimension Annotations","ofp-annotations-dimensions",["#Dimension","#A-ANNO-DIMS"]),ofp.FloorPlan=function(e,s){"use strict";function i(){return p.innerHTML}var t,n,o,a,r;if(this.svg=d3.select(e).select("svg"),s){var l;for(l in s)s.hasOwnProperty(l)&&(this[l]=new ofp.Layer(s[l],this),this.layers.push(this[l]))}else{for(t=this.svg.selectAll("g"),n=t[0],r=0;n.length>r;r++)o=n[r],o.id&&(o.id.match(/^[0-9]/m)&&(o.id="a"+o.id),o.id=o.id.replace(/ /gm,""),a=new ofp.LayerType(o.id,"ofp-"+o.id,["#"+o.id]),this[o.id]=new ofp.Layer(a,this),this.layers.push(this[o.id]));n&&0!==n.length||(this.spaces=new ofp.Layer(ofp.LayerType.Space,this),this.layers.push(this.spaces),this.columns=new ofp.Layer(ofp.LayerType.Column,this),this.layers.push(this.columns),this.constructions=new ofp.Layer(ofp.LayerType.Construction,this),this.layers.push(this.constructions),this.dimensionAnnotations=new ofp.Layer(ofp.LayerType.DimensionAnnotations,this),this.layers.push(this.dimensionAnnotations))}var p=e;this.exportSVG=function(){var e=i(),s='<?xml version="1.0" encoding="iso-8859-1"?>\n<!DOCTYPE svg [ \n]>\n';return e=e.replace(/^\s+|\s+$/g,""),e=e.replace(/^]/gm,""),e=e.replace(/!\[CDATA/gm,"<![CDATA"),e=e.replace(/baseprofile/gm,"baseProfile"),e=e.replace(/viewbox/gm,"viewBox"),e=e.replace(/preserveaspectratio/gm,"preserveAspectRatio"),e=e.replace(/patternunits/gm,"patternUnits"),s+e}},ofp.FloorPlan.prototype={svg:null,layers:[],getViewBox:function(){"use strict";var e,s,i;return e=this.svg[0][0],e&&e.viewBox&&e.viewBox.baseVal?i=e.viewBox.baseVal:(s=e.attributes.viewbox._nodeValue.split(" "),i={x:s[0],y:s[1],width:s[2],height:s[3]}),i.toString=function(){return"SVG ViewBox xMin:"+this.x+" yMin:"+this.y+" width:"+this.width+" height:"+this.height},console.log(""+i),i},getAvailableLayers:function(){"use strict";var e=[];return this.layers.forEach(function(s){s.size()>0&&e.push(s)}),e}};