text: !function(a,b){"use strict";if("object"==typeof exports)module.exports=b(require("d3"));else if("function"==typeof define&&define.amd)define(["d3"],function(c){return a.Scrollgrid=b(c),a.Scrollgrid});else if(a.d3)a.Scrollgrid=b(a.d3);else{if(!console||!console.warn)throw"scrollgrid requires d3 to run.  Are you missing a reference to the d3 library?";console.warn("scrollgrid requires d3 to run.  Are you missing a reference to the d3 library?")}}(this,function(a){"use strict";var b=function(b){var c=this.internal,d=c.sizes,e=c.interaction,f=c.render,g=c.dom,h=d.virtual,i=d.physical;b=b||{},b.target?1!==a.select(b.target).length?c.raise('target should be a d3/jquery selector identifying a single div.  E.g. "#tableContainer" where you have a div with id "tableContainer".  Please check that your selector is matching 1 and only 1 div.'):b.data?(i.rowHeight=b.rowHeight||30,i.dragHandleWidth=b.dragHandleWidth||8,i.headerRowHeight=b.headerRowHeight||i.rowHeight,i.footerRowHeight=b.footerRowHeight||i.rowHeight,i.defaultColumnWidth=b.defaultColumnWidth||100,i.cellPadding=b.cellPadding||6,i.divSizeLimit=1e6,e.allowColumnResizing=b.allowColumnResizing||!0,h.top=b.headerRows||0,h.bottom=b.footerRows||0,h.left=b.headerColumns||0,h.right=b.footerColumns||0,this.target=b.target,f.setDefaultStyles.call(this),f.formatRules=b.formatRules||[],f.cellWaitText=b.cellWaitText||"loading...",this.setData(b.data),i.initialiseColumnSizes.call(this),h.innerWidth=h.outerWidth-h.left-h.right,h.innerHeight=h.outerHeight-h.top-h.bottom,g.populateDOM.call(this),g.layoutDOM.call(this),this.draw(),(void 0===b.autoResize||b.autoResize)&&g.setAutoResize.call(this)):c.raise("data is a required field, please provide data in an array of arrays, where every array is of the same length. If this is not the format of your data please check the Scrollgrid.transformers namespace for some helpful converters."):c.raise('target is a required field, please provide a selector string for the container. The selector string should be a d3/jquery selector identifying a single div.  E.g. "#tableContainer" where you have a div with id "tableContainer".')};return b.init=function(a,c){c.target=a;var d=new b(c);return d},b.adapters={},b.prototype.internal={sizes:{virtual:{},physical:{}},interaction:{},dom:{},render:{}},b.prototype.internal.dom.layoutDOM=function(a){var b=this.internal,c=b.dom,d=b.sizes,e=d.physical;c.parent.style("position","relative"),c.container.style("position","relative").style("width",a&&a.width?a.width+"px":"100%").style("height",a&&a.height?a.height+"px":"100%").style("font-size",0),c.container.node().offsetWidth>c.parent.node().offsetWidth&&c.container.style("width","100%"),c.container.node().offsetHeight>c.parent.node().offsetHeight&&c.container.style("height","100%"),d.calculatePhysicalBounds.call(this),c.setAbsolutePosition.call(this,c.left.svg,0,e.top,e.left,e.visibleInnerHeight),c.setRelativePosition.call(this,c.top.svg,e.left,e.visibleInnerWidth,e.top,"hidden"),c.setRelativePosition.call(this,c.main.viewport,e.left,e.visibleInnerWidth,e.visibleInnerHeight,"auto"),c.setAbsolutePosition.call(this,c.right.svg,e.left+e.visibleInnerWidth,e.top,e.right,e.visibleInnerHeight),c.setRelativePosition.call(this,c.bottom.svg,e.left,e.visibleInnerWidth,e.bottom,"hidden"),c.setAbsolutePosition.call(this,c.top.left.svg,0,0,e.left+e.dragHandleWidth/2,e.top),c.setAbsolutePosition.call(this,c.top.right.svg,e.left+e.visibleInnerWidth-e.dragHandleWidth/2,0,e.right+e.dragHandleWidth/2,e.top),c.setAbsolutePosition.call(this,c.bottom.left.svg,0,e.top+e.visibleInnerHeight,e.left,e.bottom),c.setAbsolutePosition.call(this,c.bottom.right.svg,e.left+e.visibleInnerWidth,e.top+e.visibleInnerHeight,e.right,e.bottom),c.setAbsolutePosition.call(this,c.main.svg,e.left,e.top,e.visibleInnerWidth,e.visibleInnerHeight),c.top.right.transform.attr("transform","translate("+e.dragHandleWidth/2+", 0)"),c.main.viewport.on("scroll",this.draw.bind(this)),c.setScrollerSize.call(this),e.verticalScrollbarWidth=c.main.viewport.node().offsetWidth-c.main.viewport.node().clientWidth,e.horizontalScrollbarHeight=c.main.viewport.node().offsetHeight-c.main.viewport.node().clientHeight},b.prototype.internal.dom.populateDOM=function(){var b=this.internal,c=this.style,d=b.dom;d.parent=a.select(this.target),d.container=d.parent.append("div"),d.left=d.populatePanel.call(this,c.left.panel),d.top=d.populatePanel.call(this,c.top.panel),d.top.left=d.populatePanel.call(this,c.top.left.panel),d.top.right=d.populatePanel.call(this,c.top.right.panel),d.main=d.populatePanel.call(this,c.main.panel),d.main.viewport=d.container.append("div"),d.right=d.populatePanel.call(this,c.right.panel),d.bottom=d.populatePanel.call(this,c.bottom.panel),d.bottom.left=d.populatePanel.call(this,c.bottom.left.panel),d.bottom.right=d.populatePanel.call(this,c.bottom.right.panel),d.main.scroller=d.main.viewport.append("div"),d.top.dragHandles=d.top.transform.append("g")},b.prototype.internal.dom.populatePanel=function(a){var b=this.internal.dom,c={};return c.svg=b.container.append("svg"),c.svg.attr("class",a),c.transform=c.svg.append("g"),c.background=c.transform.append("g"),c.content=c.transform.append("g"),c},b.prototype.internal.dom.setAbsolutePosition=function(a,b,c,d,e){return a.style("position","absolute").style("overflow","hidden").style("left",b+"px").style("top",c+"px").style("width",d+"px").style("height",e+"px")},b.prototype.internal.dom.setAutoResize=function(){var a=window.onresize,b=this.internal,c=b.dom;window.onresize=function(){a&&a(),c.layoutDOM.call(this),this.draw(),c.setScrollerSize.call(this)}.bind(this)},b.prototype.internal.dom.setRelativePosition=function(a,b,c,d,e){return a.style("overflow",e).style("position","relative").style("margin-left",b).style("width",c+"px").style("height",d+"px")},b.prototype.internal.dom.setScrollerSize=function(){var a=this.internal,b=a.dom,c=a.sizes,d=c.physical;d.scrollerWidth=Math.min(d.totalInnerWidth,d.divSizeLimit),d.scrollerHeight=Math.min(d.totalInnerHeight,d.divSizeLimit),b.main.scroller.style("width",d.scrollerWidth+"px").style("height",d.scrollerHeight+"px")},b.prototype.internal.interaction.addResizeHandles=function(a,b,c){var d,e=this.internal,f=this.style,g=e.sizes,h=e.interaction,i=g.physical;d=a.selectAll(".gi-no-style--resize-handle-selector").data(b,function(a){return a.key}),d.enter().append("rect").attr("class","gi-no-style--resize-handle-selector "+f.resizeHandle).attr("transform","translate("+-1*i.dragHandleWidth/2+", 0)").attr("y",0).attr("width",i.dragHandleWidth).attr("height",i.top).on("dblclick",h.autoResizeColumn.bind(this)).call(h.getColumnResizer.call(this,c)),d.attr("x",function(a){return a.x+(c?0:a.width)}),d.exit().remove()},b.prototype.internal.interaction.autoResizeColumn=function(a){var b=this.internal,c=b.dom,d=0,e=b.sizes;a.column&&(d=Math.max(d,e.getExistingTextBound.call(this,c.top.left.svg,a.columnIndex).width),d=Math.max(d,e.getExistingTextBound.call(this,c.top.svg,a.columnIndex).width),d=Math.max(d,e.getExistingTextBound.call(this,c.top.right.svg,a.columnIndex).width),d=Math.max(d,e.getExistingTextBound.call(this,c.left.svg,a.columnIndex).width),d=Math.max(d,e.getExistingTextBound.call(this,c.main.svg,a.columnIndex).width),d=Math.max(d,e.getExistingTextBound.call(this,c.right.svg,a.columnIndex).width),d=Math.max(d,e.getExistingTextBound.call(this,c.bottom.left.svg,a.columnIndex).width),d=Math.max(d,e.getExistingTextBound.call(this,c.bottom.svg,a.columnIndex).width),d=Math.max(d,e.getExistingTextBound.call(this,c.bottom.right.svg,a.columnIndex).width),a.column.width=d+2*e.physical.cellPadding,this.internal.dom.layoutDOM.call(this),this.draw())},b.prototype.internal.interaction.columnResizeEnd=function(a){a.classed("dragging",!1)},b.prototype.internal.interaction.columnResizeStart=function(b){a.event.sourceEvent.stopPropagation(),b.classed("dragging",!0)},b.prototype.internal.interaction.columnResizing=function(b,c,d){d?c.column.width+=c.x-a.event.x:c.column.width-=c.x-a.event.x,c.x=a.event.x,c.column.width<0&&(c.column.width=0),b.attr("x",c.x),this.internal.dom.layoutDOM.call(this),this.draw()},b.prototype.internal.interaction.getColumnResizer=function(b){var c=this.internal,d=c.interaction,e=this;return a.behavior.drag().origin(function(a){return a}).on("dragstart",function(b){d.columnResizeStart.call(e,a.select(this),b)}).on("drag",function(c){d.columnResizing.call(e,a.select(this),c,b)}).on("dragend",function(b){d.columnResizeEnd.call(e,a.select(this),b)})},b.prototype.internal.raise=function(a){if(!console||!console.error)throw a;console.error(a)},b.prototype.internal.render.applyRules=function(a){var b,c,d,e,f,g,h=this.internal,i=h.render,j=h.sizes,k=j.virtual,l={};if(i.formatRules)for(d=0;d<a.length;d+=1){for(l={},f=a[d].rowIndex+1,g=a[d].columnIndex+1,e=0;e<i.formatRules.length;e+=1)if(b=i.formatRules[e],i.matchRule.call(this,b.row,f,k.outerHeight)&&i.matchRule.call(this,b.column,g,k.outerWidth))for(c in b)b.hasOwnProperty(c)&&"row"!==c&&"column"!==c&&(l[c]=b[c]);l.formatter&&(a[d].formatter=l.formatter),l.alignment&&(a[d].alignment=l.alignment),l.cellPadding&&(a[d].cellPadding=l.cellPadding),l.backgroundStyle&&(a[d].backgroundStyle+=" "+l.backgroundStyle),l.foregroundStyle&&(a[d].foregroundStyle+=" "+l.foregroundStyle)}},b.prototype.internal.render.applyTranslation=function(a,b){var c=this.internal.dom;c.main.transform.attr("transform","translate("+-1*a+", "+-1*b+")"),c.top.transform.attr("transform","translate("+-1*a+", 0)"),c.bottom.transform.attr("transform","translate("+-1*a+", 0)"),c.left.transform.attr("transform","translate(0, "+-1*b+")"),c.right.transform.attr("transform","translate(0, "+-1*b+")")},b.prototype.internal.render.calculateCellAdjustments=function(a,b){var c=this.internal,d=c.sizes,e=d.virtual,f=d.physical,g={x:0,y:0,height:0,width:0};return(a<e.top||a>=e.outerHeight-e.bottom)&&b===e.outerWidth-e.right-1&&(g.width+=f.verticalScrollbarWidth),(b<e.left||b>=e.outerWidth-e.right)&&a===e.outerHeight-e.bottom-1&&(g.height+=f.horizontalScrollbarHeight),a===e.top-1&&(g.height-=1),a===e.top&&a>0&&(g.height+=1,g.y-=1),b===e.left-1&&(g.width-=1),b===e.left&&b>0&&(g.width+=1,g.x-=1),a===e.outerHeight-1&&(g.height-=1),b===e.outerWidth-1&&(g.width-=1),g},b.prototype.internal.render.getDataBounds=function(a){var b,c,d,e,f=this.internal,g=this.columns,h=f.sizes,i=h.virtual,j=h.physical,k=0,l={physical:{x:0,y:0},virtual:{top:Math.max(Math.floor(i.innerHeight*(a.top/j.totalInnerHeight)-1),0),bottom:Math.min(Math.ceil(i.innerHeight*(a.bottom/j.totalInnerHeight)+1),i.innerHeight)}};for(l.physical.y=l.virtual.top*j.rowHeight-a.top,b=0;b<i.innerWidth;b+=1){if(c=g[b+i.left].width,void 0===d&&(b===i.innerWidth-1||k+c>a.left)&&(d=b,l.physical.x=k-a.left),void 0===e&&(b===i.innerWidth-1||k+c>a.right)){e=b+1;break}k+=c}return l.virtual.left=Math.max(Math.floor(d),0),l.virtual.right=Math.min(Math.ceil(e+1),i.innerWidth),l},b.prototype.internal.render.getDataInBounds=function(a){var b,c,d,e,f,g,h,i,j,k=this.internal,l=k.sizes,m=k.render,n=l.physical,o=this.columns,p=0,q=[];for(h=a.startY,j=this.adapter.loadDataRange(a),c=a.top||0,b=0;c<a.bottom;c+=1){for(p=n.getRowHeight.call(this,c),g=a.startX||0,d=a.left||0;d<a.right;d+=1,b+=1)i=m.calculateCellAdjustments.call(this,c,d),f=o[d],e=Math.floor(g)+i.x+.5,q[b]={key:d+"_"+c,x:e,y:Math.floor(h)+i.y+.5,width:Math.ceil(f.width)+i.width,height:Math.ceil(p)+i.height,backgroundStyle:this.style.cellBackgroundPrefix+"r"+(c+1)+"-c"+(d+1),foregroundStyle:this.style.cellForegroundPrefix+"r"+(c+1)+"-c"+(d+1),cellPadding:n.cellPadding,alignment:"left",rowIndex:c,columnIndex:d,column:f,formatter:null,getValue:j},g+=f.width;h+=p}return m.applyRules.call(this,q),q},b.prototype.internal.render.getTextAnchor=function(a){var b="start";return"center"===a.alignment?b="middle":"right"===a.alignment&&(b="end"),b},b.prototype.internal.render.getTextPosition=function(a){var b=a.x;return b+="center"===a.alignment?a.width/2:"right"===a.alignment?a.width-a.cellPadding:a.cellPadding},b.prototype.internal.render.getVisibleRegion=function(){var a,b=this.internal,c=b.sizes,d=c.physical,e=b.dom;return a={},a.left=Math.max(0,d.totalInnerWidth-e.main.viewport.node().clientWidth)*(e.main.viewport.node().scrollLeft/(d.scrollerWidth-e.main.viewport.node().clientWidth)),a.top=Math.max(0,d.totalInnerHeight-e.main.viewport.node().clientHeight)*(e.main.viewport.node().scrollTop/(d.scrollerHeight-e.main.viewport.node().clientHeight)),a.right=a.left+e.main.viewport.node().clientWidth,a.bottom=a.top+e.main.viewport.node().clientHeight,a},b.prototype.internal.render.matchRule=function(a,b,c){var d,e,f,g,h,i=!1;if(a&&"*"!==a)for(d=a.toString().replace(/\s/g,"").split(","),h=0;h<d.length&&(e=d[h].indexOf(":"),-1!==e?(f=parseFloat(d[h].substring(0,e)),g=parseFloat(d[h].substring(e+1))):(f=parseFloat(d[h]),g=f),f=0>f?c+f+1:f,g=0>g?c+g+1:g,!(i=i||Math.min(f,g)<=b&&Math.max(f,g)>=b));h+=1);else i=!0;return i},b.prototype.internal.render.renderBackground=function(a,b){var c;return c=a.selectAll(".gi-no-style--background-selector").data(b,function(a){return a.key}),c.enter().append("rect").attr("class",function(a){return"gi-no-style--background-selector "+a.backgroundStyle}),c.attr("x",function(a){return a.x}).attr("y",function(a){return a.y}).attr("width",function(a){return a.width}).attr("height",function(a){return a.height}),c.exit().remove(),c},b.prototype.internal.render.renderForeground=function(b,c){var d,e=this.internal,f=e.render;return d=b.selectAll(".gi-no-style--text-selector").data(c,function(a){return a.key}),d.enter().append("text").attr("class",function(a){return"gi-no-style--text-selector "+a.foregroundStyle}).style("text-anchor",f.getTextAnchor.bind(this)).attr("dy","0.35em"),d.attr("x",f.getTextPosition.bind(this)).attr("y",function(a){return a.y+a.height/2}).each(function(b){var c=a.select(this);c.text(f.cellWaitText),b.getValue(b.rowIndex,b.columnIndex,function(a){c.text(b.formatter?b.formatter(a):a)})}),d.exit().remove(),d},b.prototype.internal.render.renderRegion=function(a,b,c,d){var e=this.internal,f=e.render,g=e.interaction,h=e.sizes,i=h.physical,j=e.dom,k=f.getDataInBounds.call(this,{startX:b.x||0,startY:b.y||0,top:d.top||0,bottom:d.bottom||0,left:c.left||0,right:c.right||0});f.renderBackground.call(this,a.background,k),f.renderForeground.call(this,a.content,k),!g.allowColumnResizing||a!==j.top&&a!==j.top.left&&a!==j.top.right||g.addResizeHandles.call(this,a.content,k,a===j.top.right&&i.totalInnerWidth>i.visibleInnerWidth)},b.prototype.internal.render.setDefaultStyles=function(){this.style={left:{panel:"gi-fixed gi-left"},top:{panel:"gi-fixed gi-top",left:{panel:"gi-fixed gi-top-left"},right:{panel:"gi-fixed gi-top-right"}},right:{panel:"gi-fixed gi-right",left:{panel:"gi-fixed gi-top-left"}},bottom:{panel:"gi-fixed gi-bottom",left:{panel:"gi-fixed gi-bottom-left"},right:{panel:"gi-fixed gi-bottom-right"}},main:{panel:"gi-grid"},resizeHandle:"gi-resize-handle",cellBackgroundPrefix:"gi-cell-background-",cellForegroundPrefix:"gi-cell-foreground-"}},b.prototype.internal.sizes.calculatePhysicalBounds=function(){var a,b=this.internal,c=b.sizes,d=c.virtual,e=c.physical;for(e.left=0,a=0;a<d.left;a+=1)e.left+=this.columns[a].width;for(e.totalInnerWidth=0,a=d.left;a<d.outerWidth-d.right;a+=1)e.totalInnerWidth+=this.columns[a].width;for(e.right=0,a=d.outerWidth-d.right;a<d.outerWidth;a+=1)e.right+=this.columns[a].width;e.top=d.top*e.headerRowHeight,e.bottom=d.bottom*e.footerRowHeight,e.visibleInnerWidth=b.dom.container.node().offsetWidth-e.left-e.right,e.visibleInnerHeight=b.dom.container.node().offsetHeight-e.top-e.bottom,e.totalInnerHeight=d.innerHeight*e.rowHeight},b.prototype.internal.sizes.calculateTextBound=function(a,b){var c,d,e={width:0,height:0};return c=a.append("text").text(b),d=c.node().getBBox(),e.width=d.width,e.height=d.height,c.remove(),e},b.prototype.internal.sizes.getExistingTextBound=function(b,c,d){var e={width:0,height:0};return b.selectAll("text").filter(function(a){return!(void 0!==c&&a.columnIndex!==c||void 0!==d&&a.rowIndex!==d)}).each(function(){var b=a.select(this).node().getBBox();b.width>e.width&&(e.width=b.width),b.height>e.height&&(e.height=b.height)}),e},b.prototype.internal.sizes.physical.getRowHeight=function(a){var b=this.internal,c=b.sizes,d=c.physical,e=c.virtual,f=0;return f=a<e.top?d.headerRowHeight:a<e.outerHeight-e.bottom?d.rowHeight:d.footerRowHeight},b.prototype.internal.sizes.physical.initialiseColumnSizes=function(){var a,b,c,d=this.internal,e=d.render,f=d.sizes,g=f.physical,h=f.virtual;for(this.columns=this.columns||[],a=0;a<h.outerWidth;a+=1){if(c=g.defaultColumnWidth,e.formatRules&&e.formatRules.length>0)for(b=e.formatRules.length-1;b>=0;b-=1)if(e.formatRules[b].columnWidth&&e.matchRule.call(this,e.formatRules[b].column,a+1,h.outerWidth)){c=e.formatRules[b].columnWidth;break}this.columns[a]={width:c}}},b.adapters.simple=function(a){var b,c=this.internal,d=!1,e=!0,f=0,g=a;for(b=0;b<g.length;b+=1){if(!g[b]||"[object Array]"!==Object.prototype.toString.call(g[b])){e=!1,c.raise("Invalid data row found");break}d=f&&(d||f!==g[b].length),(!f||g[b].length>f)&&(f=g[b].length)}if(e&&f>0&&d)for(b=0;b<g.length;b+=1)for(;g[b].length<f;)g[b].push("");this.getRowCount=function(){return g.length},this.getColumnCount=function(){return f},this.loadDataRange=function(){return function(a,b,c){c(g[a][b])}}},b.prototype.draw=function(){var a,b,c=this.internal,d=c.render,e=c.sizes,f=c.dom,g=e.virtual,h=e.physical,i=d.getVisibleRegion.call(this),j=d.getDataBounds.call(this,i),k={},l=j.physical,m=j.virtual,n={top:{top:0,bottom:g.top},middle:{top:g.top+m.top,bottom:g.top+m.bottom},bottom:{top:g.outerHeight-g.bottom,bottom:g.outerHeight}},o={left:{left:0,right:g.left},middle:{left:g.left+m.left,right:g.left+m.right},right:{left:g.outerWidth-g.right,right:g.outerWidth}};d.renderRegion.call(this,f.top.left,{},o.left,n.top),d.renderRegion.call(this,f.top,{x:l.x},o.middle,n.top),d.renderRegion.call(this,f.top.right,{},o.right,n.top),d.renderRegion.call(this,f.left,{y:l.y},o.left,n.middle),d.renderRegion.call(this,f.main,{x:l.x,y:l.y},o.middle,n.middle),d.renderRegion.call(this,f.right,{y:l.y},o.right,n.middle),d.renderRegion.call(this,f.bottom.left,{},o.left,n.bottom),d.renderRegion.call(this,f.bottom,{x:l.x},o.middle,n.bottom),d.renderRegion.call(this,f.bottom.right,{},o.right,n.bottom),a=h.left+h.totalInnerWidth+h.right+h.verticalScrollbarWidth,k.width=a<f.parent.node().offsetWidth?a:null,b=h.top+h.totalInnerHeight+h.bottom+h.horizontalScrollbarHeight,k.height=b<f.parent.node().offsetHeight?b:null,f.layoutDOM.call(this,k)},b.prototype.setData=function(a){var c=this.internal,d=c.sizes,e=d.virtual;this.adapter=a&&"[object Array]"===Object.prototype.toString.call(a)&&a.length>e.top+e.bottom?new b.adapters.simple(a):a,e.outerHeight=this.adapter.getRowCount(),e.outerWidth=this.adapter.getColumnCount()},b});