forked from mode/alamode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alamode.min.js
1 lines (1 loc) · 51.4 KB
/
alamode.min.js
1
var version="0.23",alamode={reportError:function(t){"function"==typeof modeReportAlamodeError&&modeReportAlamodeError(new Error(t)),$("<h1 class='mode-error'>").text(t).prependTo(document.body)},getColumnsFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.columns:(alamode.reportError("No such query: '"+e+"'"),[])},getDataFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.content:(alamode.reportError("No such query: '"+e+"'"),[])},makeId:function(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",a="",n=0;n<t;n++)a+=e.charAt(Math.floor(Math.random()*e.length));return a},addContainerElement:function(t,e){return e=e||!1,id=alamode.makeId(10),"body"==t?$("<div id='"+id+"'></div>").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content"):0===$(t).length?alamode.reportError("No such element: '"+t+"'"):(e&&$(t).empty(),$(t).addClass("mode-graphic-container"),$(t).addClass(id)),"."+id},addLinksToTables:function(t){var r="#"+t.table_id,e=t.link_columns,a=t.link_urls,n=t.query_name,d=t.open_in_new_tab||!1,o=[],s={},c=(e.forEach(function(t,e){o.push({column:t,link_string:a[e]})}),alamode.getDataFromQuery(n));alamode.getColumnsFromQuery(n);function l(e){var t,a=$(r+" table"),n=$(r+" .js-header-table"),n=n?$(r+" .js-col-header"):$(n).find("th"),a=a.find("tr");n.each(function(){text=$(this).find(".axel-table-header-label").text(),t=$(this).attr("data-axel-column"),s[text]=t-1}),a.each(function(t){var l,i;0<t&&t<=c.length&&(l=$(this).find("td"),i=l.first().attr("data-axel-rowkey"),e.forEach(function(t){var e=s[t.column],a=l.eq(e).text();for(url=t.link_string;-1!=url.indexOf("{{");){var n=url.length,r=url.indexOf("{{"),n=url.substring(r+2,n).indexOf("}}"),o=url.substring(r+2,r+n+2),r=url.substring(r,r+n+4),n=c[i][o];url=url.replace(r,n)}t="<a target='"+(d?"_blank":"_top")+"' href='"+encodeURI(url)+"'>"+a+"</a>";l.eq(e).html(t)}))})}setTimeout(function(){l(o)},1e3),$(r).mousemove(function(){l(o)})},customChartColors:function(t){var e=t.charts,o=t.colors,l=t.opacity,d=t.line_dashes;function m(t,e){var t=$("#"+t),a=(0<t.find(".nv-bar").length?t.find(".nv-group"):0<t.find(".nv-line").length||0<t.find(".nv-areaWrap").length?t.find(".nv-noninteractive"):t.find(".nv-pie .nv-slice")).length,n=t.find(".nv-series .nv-legend-symbol"),r={},o={},l={},d=0;if(0==n.length&&a<=1)r[l[o[0]=d]=0]=e[0];else if(0==n.length&&1<a)for(i=0;i<a;i++)o[i]=i,r=e;else for(i=0;i<n.length;i++)r[i]=e[i%Object.keys(e).length];return n.each(function(t){1==$(this).css("fill-opacity")?(l[o[t]=d]=t,d+=1):o[t]=-1}),{chart:t,legend:n,colors:r,m:o,r:l,seriesCount:a}}"all"==e&&(e=[],$("mode-chart").each(function(){e.push(this.id)})),setInterval(function(){e.forEach(function(t){var e,a=(t=m(t,o)).chart,n=t.colors,r=t.m;for(e in n)a.find(".nv-linesWrap .nv-groups .nv-series-"+r[e]).css({fill:n[e],stroke:n[e]}),a.find(".nv-barsWrap .nv-groups .nv-series-"+r[e]+" rect").css({fill:n[e],stroke:n[e]}),a.find(".nv-linePlusBar .nv-barsWrap .nv-bars rect").each(function(t){$(this).css({fill:n[0],stroke:n[0]})}),a.find(".nv-linePlusBar .nv-linesWrap .nv-groups .nv-series-0").css({fill:n[1],stroke:n[1]}),a.find(".nv-scatterWrap .nv-groups .nv-series-"+r[e]).css({fill:n[e],stroke:n[e]}),a.find(".nv-areaWrap .nv-area-"+r[e]).css({fill:n[e],stroke:n[e]}),a.find(".nv-pie .nv-slice").each(function(t){$(this).css({fill:n[t],stroke:n[t]})});for(e in l)a.find(".nv-linesWrap .nv-groups .nv-series-"+r[e]).css({opacity:l[e]}),a.find(".nv-barsWrap .nv-groups .nv-series-"+r[e]+" rect").css({opacity:l[e]}),0==e&&(a.find(".nv-linePlusBar .nv-barsWrap .nv-bars rect").each(function(t){$(this).css({opacity:l[e]})}),a.find(".nv-linePlusBar .nv-linesWrap .nv-groups .nv-series-0").css({opacity:l[1]})),a.find(".nv-scatterWrap .nv-groups .nv-series-"+r[e]).css({opacity:l[e]}),a.find(".nv-areaWrap .nv-area-"+r[e]).css({opacity:l[e]}),a.find(".nv-pie .nv-slice").each(function(t){$(this).css({opacity:l[t]})});for(e in d)a.find(".nv-linesWrap .nv-groups .nv-series-"+r[e]).css({"stroke-dasharray":d[e]});a.find(".nv-legendWrap .nv-series .nv-legend-symbol").each(function(t){$(this).css({fill:n[t],stroke:n[t]})})})},500),e.forEach(function(t){var e,a,u;e=t,a=o,u=$("#"+e),$(u).mousemove(function(){var t=m(e,a),n=t.legend,r=t.colors,o=t.r,l=t.m,i=t.seriesCount,d=isArea=u.find(".nv-area").length,s=u.find(".nv-bar").length,c=u.find(".nv-line").length,t=($("html").find(".nvtooltip table .legend-color-guide").each(function(t){var e,a;0==n.length&&0==s?$(this).find("div").css({"background-color":r[l[t]]}):0<c&&0<s?(e=u.find(".nv-linePlusBar .nv-linesWrap .nv-groups .nv-series-0").css("fill"),a=u.find(".nv-linePlusBar .nv-barsWrap .nv-bars rect").css("fill"),""==$(this).closest(".nvtooltip").find(".key")[0].innerText?$(this).find("div").css("background-color",a):$(this).find("div").css("background-color",e)):0<s?1==i&&$(this).find("div").css({"background-color":r[o[i-t-1]]}):0<d?$(this).find("div").css({"background-color":r[d-t-1]}):$(this).find("div").css({"background-color":r[t]})}),u.find(".nv-pie .nv-slice.hover").css("fill"));$("html").find(".nvtooltip table .legend-color-guide div").css("background-color",t)}),$(u).mouseleave(function(){$("html").find(".nvtooltip table .legend-color-guide").remove()})})},addTotalsRow:function(t){var n,r,e=t.query_name,o="#"+(t.table_id||""),a=alamode.getColumnsFromQuery(e),l=alamode.getDataFromQuery(e),e=t.columns_with_totals,i=t.fmt||d3.format(","),e=(t=e,numberColumns=_.map(_.filter(a,function(t){return-1!=["number","integer","float"].indexOf(t.type)}),"name"),"all"==t?numberColumns:_.intersection(t,numberColumns)),d=(n=e,r=[],a.forEach(function(t,e){var a;e=-1==n.indexOf(t.name)?{idx:e,name:"",total:""}:(a=_.map(l,t.name),a=d3.sum(a),{idx:e,name:t.name,total:a}),r.push(e)}),r);setTimeout(function(){container="#"==o?(table=$(".main-table"),$(".js-table-content-container")):(table=$(o+" .main-table"),$(o+" .js-table-content-container"));var e,t=table.find("tr:last"),a=(e="<tr><td>TTL</td>",d.forEach(function(t){""!=t.total?e=e+"<td class='cell-type-number'>"+i(t.total)+"</td>":e+="<td></td>"}),e+"</tr>"),n=+container.css("height").match(/\d+/)[0];t.after(a),container.css("height",26+n)},1e3)},addImagesToTables:function(t){var n="#"+t.table,r=t.column,o=t.image_height||100;function e(){var t=$(n+" table"),e=$(n+" .js-header-table"),e=e?$(n+" .js-col-header"):$(e).find("th"),t=t.find("tr"),a=0;e.each(function(){(text=$(this).find(".axel-table-header-label").text())==r&&(a=+$(this).attr("data-axel-column"))}),t.each(function(){$(this).find("td").each(function(t){t==a-1&&(t=$(this).text(),0==$(this).find("img").length)&&($(this).css("text-align","center"),$(this).html("<img style='height: "+o+"px;' src='"+t+"'>"))})})}setTimeout(function(){e()},1e3),$(n).keyup(function(){setTimeout(function(){e()},500)}),$(n).mousemove(function(){e()})},resizeChartHeight:function(t){var e=t.chart,t=t.height;"python"==e.slice(0,6)?($("#"+e+" .mode-python").css("height",t),$("#"+e+" .mode-python").css("max-height",t),$("#"+e+" img").css("max-height",t)):($("#"+e+" .chart").css("height",t),$("#"+e+" .chart-svg").css("height",t)),window.dispatchEvent(new Event("resize"))},retentionHeatmap:function(t){var a,n,r,e=t.query_name,i=t.cohort_column,d=t.pivot_column,s=t.value_column,o=t.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],l=t.gradient_by||"all",c=t.gradient_column||s,u=t.total_column,m=t.html_element||"body",h=t.title||e,p=t.pivot_label||"",f=t.value_is_percent,g=t.precision||0,v=alamode.getDataFromQuery(e),y=alamode.getColumnsFromQuery(e),t=_.uniq(_.map(v,i)),x=_.sortBy(_.uniq(_.map(v,d))),e=alamode.addContainerElement(m),m=("cohort_column"===l?(a={},t.forEach(function(e){var t=v.filter(function(t){return t[i]===e});a[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):"pivot_column"===l?(n={},x.forEach(function(e){var t=v.filter(function(t){return t[d]===e});n[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):r=d3.scale.quantize().domain(d3.extent(v,function(t){return t[c]})).range(o),d3.select(e).append("div").attr("class","mode-graphic-title").text(h),d3.select(e).append("div").attr("class","mode-retention-heatmap-label").text(p),headers=(u?[i,u]:[i]).concat(x),d3.select(e).append("table").attr("class","mode-retention-heatmap-table"));function b(e){return y.filter(function(t){return t.name==e})[0].type}m.selectAll(".mode-retention-heatmap-table-header").data([0]).enter().append("tr").attr("class","mode-retention-heatmap-table-header").selectAll("mode-retention-heatmap-table-header-cell").data(headers).enter().append("td").attr("class",function(t){return isNaN(t)?"mode-retention-heatmap-table-header-cell heatmap-string":"mode-retention-heatmap-table-header-cell heatmap-number"}).text(function(t){return t}),m.selectAll(".mode-retention-heatmap-table-row").data(t).enter().append("tr").attr("class","mode-retention-heatmap-table-row").selectAll(".mode-retention-heatmap-table-cell").data(function(t){var r=v,o=t,l=[{column:i,value:o}];return u&&(t=_.filter(r,function(t){return t[i]==o})[0],t={column:u,value:t[u]},l=l.concat(t)),x.forEach(function(e){var t="",a="",n=_.filter(r,function(t){return t[i]==o&&t[d]==e});0<n.length&&(t=d3.mean(_.map(n,s)),a=d3.mean(_.map(n,c))),l=l.concat({column:s,value:t,cohort:o,pivot:e,gradientValue:a})}),l}).enter().append("td").style("background",function(t){var e;if((e=t).column==s&&""!==e.value)return e=t,"cohort_column"===l?a[e.cohort](e.gradientValue):"pivot_column"===l?n[e.pivot](e.gradientValue):r(e.gradientValue)}).attr("class",function(t){return"float"==(t=b(t.column))||"integer"==t||"number"==t?"heatmap-number":"heatmap-string"}).text(function(t){return e=b((t=t).column),a=d3.format(","),n=d3.format("."+g+"%"),r=d3.time.format("%b %d, %Y"),""==t.value?t.value:"datetime"==e||"timestamp"==e||"date"==e?"function"==typeof moment?moment(t.value).utc().format("ll"):r(new Date(t.value)):t.column==u?a(t.value):t.column==s&&f?n(t.value):t.column==s?a(t.value):t.value;var e,a,n,r})},simpleHeatmap:function(t){var e=t.query_name,o=t.x_column,l=t.y_column,i=t.value_column,a=t.max_value||Number.MAX_VALUE,d=0===t.min_value?0:t.min_value||Number.MIN_VALUE,n=t.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],r=t.html_element||"body",s=t.title||e,c=(t.x_label,t.y_label||""),u=t.value_is_percent,m=t.precision||0,h=alamode.getDataFromQuery(e),p=alamode.getColumnsFromQuery(e),t=_.uniq(_.map(h,o)),f=_.uniq(_.map(h,l)),e=alamode.addContainerElement(r),g=d3.scale.quantize().domain(d3.extent(h,function(t){return Math.max(d,Math.min(a,t[i]))})).range(n),r=(d3.select(e).append("div").attr("class","mode-graphic-title").text(s),d3.select(e).append("div").attr("class","mode-simple-heatmap-label").text(c),headers=[o].concat(f),d3.select(e).append("table").attr("class","mode-simple-heatmap-table"));function v(e){return p.filter(function(t){return t.name==e})[0].type}r.selectAll(".mode-simple-heatmap-table-header").data([0]).enter().append("tr").attr("class","mode-simple-heatmap-table-header").selectAll("mode-simple-heatmap-table-header-cell").data(headers).enter().append("td").attr("class",function(t){return isNaN(t)?"mode-simple-heatmap-table-header-cell heatmap-string":"mode-simple-heatmap-table-header-cell heatmap-number"}).text(function(t){return t}),r.selectAll(".mode-simple-heatmap-table-row").data(t).enter().append("tr").attr("class","mode-simple-heatmap-table-row").selectAll(".mode-simple-heatmap-table-cell").data(function(t){return a=h,r=[{column:o,value:n=t}],f.forEach(function(e){var t=_.filter(a,function(t){return t[o]==n&&t[l]==e});entry=0<t.length?d3.mean(_.map(t,i)):d,r=r.concat({column:i,value:entry})}),r;var a,n,r}).enter().append("td").style("background",function(t){if(function(t){if(""!==t.value&&t.column!=o&&t.column==i)return 1}(t))return g(Math.max(d,Math.min(a,t.value)))}).attr("class",function(t){return"float"==(t=v(t.column))||"integer"==t||"number"==t?"heatmap-number":"heatmap-string"}).text(function(t){return e=v((t=t).column),a=d3.format(","),n=d3.format("."+m+"%"),r=d3.time.format("%b %d, %Y"),""==t.value?t.value:"datetime"==e||"timestamp"==e||"date"==e?"function"==typeof moment?moment(t.value).utc().format("ll"):r(new Date(t.value)):t.column==i&&u?n(t.value):t.column==i?a(t.value):t.value;var e,a,n,r})},googleMap:function(t){var e=alamode.makeId(10),l=t.lat_column,i=t.lng_column,a=t.query_name,n=t.google_maps_api_key,r=t.title||a,d=t.label_column,o=t.html_element||"body",s=t.center_lat||39.5,c=t.center_lng||-98.35,u=t.starting_zoom||4,m=t.map_type||"terrain",t=t.height||600,h=alamode.getDataFromQuery(a),a=alamode.addContainerElement(o);d3.select(a).append("div").attr("class","mode-graphic-title").text(r),d3.select(a).append("div").attr("class","mode-google-map").attr("id",e).style("height",t+"px"),jQuery.getScript("https://maps.googleapis.com/maps/api/js?key="+n,function(){var t,o;t={zoom:u,center:new google.maps.LatLng(s,c),mapTypeId:m},o=new google.maps.Map(document.getElementById(e),t),h.forEach(function(t){var e=t[l],a=t[i],n=(label=d?t[d]:"",new google.maps.Marker({position:{lat:e,lng:a},map:o,title:label})),r=new google.maps.InfoWindow({content:label});n.addListener("click",function(){r.open(o,n)})})})},leafletMap:function(t){var e=alamode.makeId(10),a=t.lat_column,n=t.lng_column,r=t.query_name,o=t.title||r,l=t.height||400,i=t.html_element||"body",d=t.center_lat||39.5,s=t.center_lng||-98.35,c=t.starting_zoom||4,u=t.dot_size||.4,m=t.dot_opacity||.8,t=t.apply_filter||!1,r=alamode.getDataFromQuery(r),h=[],r=(r.forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&h.push(t)}),alamode.addContainerElement(i,t)),i=(d3.select(r).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o),l-$(r+".mode-graphic-title").height()),t=$(r).width(),o=(d3.select(r).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",i+"px").style("width",t+"px"),L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18})),l={max:8,data:h},r={lat:d,lng:s,zoom:c},i=new HeatmapOverlay({radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n});new L.Map(e,{center:new L.LatLng(r.lat,r.lng),zoom:Math.floor(r.zoom),layers:[o,i]});i.setData(l)},wordCloud:function(t){var e=t.query_name,a=t.word_column,n=t.word_count_column,r=t.html_element||"body",o=t.title||e,l=t.height||"400",i=t.width||"800",d=t.colors||["black"],t=alamode.getDataFromQuery(e),s=alamode.addContainerElement(r),c=(d3.select(s).append("div").attr("class","mode-graphic-title").text(o),d3.scale.linear().domain(d3.extent(t,function(t){return t[n]})).range([12,60])),u=d3.layout.cloud().size([i,l]).words(t.map(function(t){return{text:t[a],size:c(t[n])}})).padding(2).rotate(function(){return 360*(~~(6*Math.random())-3)}).font("Impact").fontSize(function(t){return t.size}).on("end",function(t){d3.select(s).append("div").attr("class","mode-wordcloud").append("svg").attr("width",u.size()[0]).attr("height",u.size()[1]).append("g").attr("transform","translate("+u.size()[0]/2+","+u.size()[1]/2+")").selectAll("text").data(t).enter().append("text").style("font-size",function(t){return t.size+"px"}).style("font-family","Impact").style("fill",function(t,e){return d[e%d.length]}).attr("text-anchor","middle").attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).text(function(t){return t.text})});u.start()},funnel:function(t){var e=alamode.makeId(10),a=t.query_name,n=t.stage_column,r=t.value_column,o=t.html_element||"body",l=t.title||a,i=t.height||"300",t=t.width||"500",a=alamode.getDataFromQuery(a),o=alamode.addContainerElement(o),d=(d3.select(o).append("div").attr("class","mode-graphic-title").text(l),d3.select(o).append("div").attr("class","mode-funnel").attr("id",e).style("width",t+"px").style("height",i-20+"px"),[]);a.forEach(function(t){d.push([t[n],t[r]])});new D3Funnel("#"+e).draw(d,{label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100}),d3.select("#"+e).style("height",i+"px")},horizontalBarChart:function(n){var t=n.query_name,e=(n.bar_column,n.series_columns),r=n.colors||["#EE8D24","#43A5DA","#6AB328","#BB60F8","#E14459","#EAD022","#06D0AD","#DB38B7"],o=(stacked=n.stacked||!1,leftpad=n.left_pad||175,htmlElement=n.html_element||"body",title=n.title||t,height=n.chart_height||395,width=n.width||"500",alamode.getDataFromQuery(t)),a=alamode.addContainerElement(htmlElement),l=(d3.select(a).append("div").attr("class","mode-graphic-title").text(title),d3.select(a).append("div").attr("class","mode-horizontal-bar-chart").style("height",height-50+"px").append("svg"),[]);e.forEach(function(e,t){var t={key:e,color:r[t%r.length]},a=[];o.forEach(function(t){a.push({label:t[n.bar_column],value:t[e]})}),t.values=a,l.push(t)}),nv.addGraph(function(){var t=nv.models.multiBarHorizontalChart().x(function(t){return t.label}).y(function(t){return t.value}).margin({top:30,right:20,bottom:50,left:leftpad}).showValues(!0).showControls(!1).stacked(stacked);return t.yAxis.tickFormat(d3.format(",.2f")),d3.select(a+" svg").datum(l).call(t),nv.utils.windowResize(t.update),t})},chartAnnotations:function(t){var c="#"+t.chart_id,n=t.x_axis_column,e=t.query_name,u=t.orientations,m=t.comment_values,r=t.group_by,a=t.comments,o=alamode.getDataFromQuery(e),h=[],l={};function i(){a.forEach(function(t,e){var a,n=h[e],r=u[e],e=m[e],o=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),l=$(c).find("g.nvd3.nv-wrap").attr("transform"),i=l.indexOf("("),d=l.indexOf(")"),s=l.indexOf(","),i=+l.slice(i+1,s),l=+l.slice(s+1,d);-1!=n&&"v"==r?(d=(s=$(c).find(".nv-point.nv-point-"+n).attr("transform")).indexOf("("),n=s.indexOf(")"),a=s.indexOf(","),d=+s.slice(d+1,a),s=+s.slice(a+1,n),$(c).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(c).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width"),(a=d3.select(c+" .nvd3svg")).call(o),a.append("rect").attr("x",d+i).attr("y",l-5).attr("width",1).attr("class","flag").attr("height",5+s).attr("fill","#ff8f53"),a.append("circle").data([t]).attr("cx",d+i).attr("cy",l-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",o.show).on("mouseout",o.hide)):"h"!=r&&"h-left"!=r&&"h-right"!=r||(y="h"==r?"":"1",$(c).find("g.nv-y"+y+".nv-axis").find(".tick").each(function(t){lineLength="h-right"==r?+$(c).find("g.nv-y1.nv-axis").find(".tick").first().find("line").attr("x2"):+$(this).find("line").attr("x2"),tickTrans=$(this).attr("transform"),tickClosePos=tickTrans.indexOf(")"),tickCommaPos=tickTrans.indexOf(","),0==t?(yTrans1=+tickTrans.slice(tickCommaPos+1,tickClosePos),yVal1=+$(this).find("text").text().replace(",","")):1==t&&(yTrans2=+tickTrans.slice(tickCommaPos+1,tickClosePos),yVal2=+$(this).find("text").text().replace(",",""))}),n=(yTrans2-yTrans1)/(yVal2-yVal1),s=yTrans2-yVal2*n+e*n,(a=d3.select(c+" .nvd3svg")).call(o),a.append("rect").attr("x",i).attr("y",s+l).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),a.append("circle").data([t]).attr("cx",lineLength+i+10).attr("cy",s+l).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",o.show).on("mouseout",o.hide))})}r&&(l=_.groupBy(o,function(t){return t[r]})),a.forEach(function(t,e){var a=_.filter(o,function(t){return t[n]==m[e]});pointNumber=0!=a.length?(r?l[a[0][r]]:o).indexOf(a[0]):-1,h.push(pointNumber)}),setTimeout(function(){d3.select(c).selectAll(".flag").remove(),i()},1e3),$(window).resize(function(){d3.select(c).selectAll(".flag").remove(),s(function(){i()},500,"")});d={};var d,s=function(t,e,a){d[a=a||"Don't call this twice without a uniqueId"]&&clearTimeout(d[a]),d[a]=setTimeout(t,e)}},bulletChart:function(l){var i=alamode.makeId(10),t=l.query_name,e=l.html_element||"body",a=l.title||t,d=l.chart_width||"800",s=l.bar_column||"",c=l.marker_column||"",u=l.left_pad||150,m=l.color,t=alamode.getDataFromQuery(t),e=alamode.addContainerElement(e);d3.select(e).append("div").attr("class","mode-graphic-title").text(a),d3.select(e).append("div").attr("class","mode-bullet-chart").style("width",d).attr("id",i),t.forEach(function(t){var e=t[l.title_column]||"",a=t[l.subtitle_column]||"",n=t[l.marker_column]||"",r=t[l.bar_column]||"",o={title:e,subtitle:a,ranges:scale=l.scale_columns&&[t[l.scale_columns[0]],t[l.scale_columns[1]],t[l.scale_columns[2]]],measures:[r],measureLabels:[s],markers:[n],markerLabels:[c],color:m};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(d).margin({left:u,right:15,top:10,bottom:10});d3.select("#"+i).append("svg").style("width",d+"px").style("height","70px").style("display","inline").datum(o).transition().duration(500).call(t);return t})})},sunburstChart:function(t){var o=alamode.makeId(10),e=t.query_name,n=t.event_columns,r=t.event_counts,a=t.title||e,l=t.color_range||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],t=t.html_element||"body",d=alamode.getDataFromQuery(e),e=850,s=Math.min(e,600)/2,c={w:(e-30)/n.length,h:20,s:3,t:10},u=[],m=(n.forEach(function(t){u=u.concat(_.uniq(_.map(d,t)))}),_.uniq(u)),h={},p=(m.forEach(function(t,e){null!=t&&(h[t]=l[e%l.length])}),h.end="#666",0),m=alamode.addContainerElement(t),t=(d3.select(m).append("div").attr("class","mode-graphic-title").text(a),d3.select(m).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+o),d3.select(m).append("div").attr("class","mode-sunburst").attr("id",o),d3.select(m).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+o),(vis=d3.select("#"+o).append("svg:svg").attr("width",e).attr("height",600).append("svg:g").attr("transform","translate("+e/2+",300)")).append("text").attr("x",0).attr("y",-30).attr("text-anchor","middle").attr("class","mode-sunburst-explanation mode-sunburst-percentage").attr("id","percentage-"+o).style("visibility","hidden").text(""),vis.append("text").attr("x",0).attr("y",-10).attr("text-anchor","middle").attr("class","mode-sunburst-explanation").style("visibility","hidden").text("of total sequences."),vis.append("text").attr("x",0).attr("y",20).attr("text-anchor","middle").attr("class","mode-sunburst-explanation mode-sunburst-cond-percentage").attr("id","cond-percentage-"+o).style("visibility","hidden").text(""),vis.append("text").attr("x",0).attr("y",40).attr("text-anchor","middle").attr("class","mode-sunburst-explanation").style("visibility","hidden").text("from previous location."),d3.layout.partition().size([2*Math.PI,s*s]).value(function(t){return t.size})),a=d3.svg.arc().startAngle(function(t){return t.x}).endAngle(function(t){return t.x+t.dx}).innerRadius(function(t){return Math.sqrt(t.y)}).outerRadius(function(t){return Math.sqrt(t.y+t.dy)}),f=[],m=(d.forEach(function(t){var e="";for(i=0;i<n.length;i++){if(prefix=0!=i?"-~-":"",null==t[n[i]]){e=e+prefix+"end";break}e=e+prefix+t[n[i]]}var a={0:e,1:t[r]};f.push(a)}),function(t){for(var e,a={name:"root",children:[]},n=0;n<t.length;n++){var r=t[n][0],o=+t[n][1];if(!isNaN(o))for(var l=r.split("-~-"),i=a,d=0;d<l.length;d++){var s=i.children,c=l[d];if(d+1<l.length){for(var u=!1,m=0;m<s.length;m++)if(s[m].name==c){e=s[m],u=!0;break}u||(e={name:c,children:[]},s.push(e)),i=e}else e={name:c,size:o},s.push(e)}}return a}(f));function g(t){var e=(100*t.value/p).toPrecision(3),a=e+"%",n=(e<.1&&(a="< 0.1%"),y(t)),e=t.parent.value,e=(100*t.value/e).toPrecision(3),r=e+"%",n=(e<1&&(a="< 1%"),d3.select("#cond-percentage-"+o).text(r),d3.select("#percentage-"+o).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility",""),y(t));e=n,e=d3.select("#trail-"+o).selectAll("g").data(e,function(t){return t.name+t.depth}),(r=e.enter().append("svg:g")).append("svg:polygon").attr("points",x).style("fill",function(t){return h[t.name]}),r.append("svg:text").attr("x",(c.w+c.t)/2).attr("y",c.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),e.attr("transform",function(t,e){return 5<e&&e<10?"translate("+(e-=5)*(c.w+c.s)+", 20)":10<e?"translate("+(e-=11)*(c.w+c.s)+", 40)":"translate("+e*(c.w+c.s)+", 0)"}),e.exit().remove(),d3.select("#trail-"+o).style("visibility",""),d3.selectAll("path").style("opacity",.3),vis.selectAll("path").filter(function(t){return 0<=n.indexOf(t)}).style("opacity",1)}function v(t){d3.select("#trail-"+o).style("visibility","hidden"),d3.selectAll("path").on("mouseover",null),4==d3.version.split(".")[0]?d3.selectAll("path").transition().duration(300).style("opacity",1).on("end",function(){d3.select(this).on("mouseover",g)}):d3.selectAll("path").transition().duration(300).style("opacity",1).each("end",function(){d3.select(this).on("mouseover",g)}),d3.selectAll(".mode-sunburst-explanation").style("visibility","hidden")}function y(t){for(var e=[],a=t;a.parent;)e.unshift(a),a=a.parent;return e}function x(t,e){var a=[];return a.push("0,0"),a.push(c.w+",0"),a.push(c.w+c.t+","+c.h/2),a.push(c.w+","+c.h),a.push("0,"+c.h),0<e&&a.push(c.t+","+c.h/2),a.join(" ")}m=m,d3.select("#sequence-"+o).append("svg:svg").attr("width",e).attr("height",60).attr("id","trail-"+o).append("svg:text").attr("id","endlabel").style("fill","#000"),function(){var e=195,a=30,n=3;d3.entries(h).forEach(function(t){divContainer=d3.select("#legend-container-"+o).append("div").attr("class","mode-sunburst-legend").attr("id","legend-"+o),(svg=divContainer.append("svg:svg").attr("width",e).attr("height",a)).append("svg:rect").attr("rx",n).attr("ry",n).attr("width",e).attr("height",a).style("fill",function(){return t.value}),svg.append("svg:text").attr("x",e/2).attr("y",a/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(){return t.key})})}(),vis.append("svg:circle").attr("r",s).style("opacity",0),e=t.nodes(m).filter(function(t){return.005<t.dx}),m=vis.data([m]).selectAll("path").data(e).enter().append("svg:path").attr("display",function(t){return t.depth?null:"none"}).attr("d",a).attr("fill-rule","evenodd").style("fill",function(t){return h[t.name]}).style("opacity",1).on("mouseover",g),vis.on("mouseleave",v),p=m.node().__data__.value},zipcodeChoropleth:function(t){var a=alamode.makeId(10),e=t.query_name,n=t.zipcode_column,r=t.value_column,o=t.width||950,l=t.height||o/1.9,i=t.title||e,d=t.color_range,s=t.color_gradient||["#FFF8CC","#FFF5B2","#FFF299","#E5D87F","#CCBF66","#B2A54C","#998C33","#7F7219","#665900"],t=t.html_element||"body",e=alamode.getDataFromQuery(e),c=d3.map(),u=d3.geoAlbersUsa().scale(o).translate([o/2,l/2]),m=d3.geoPath().projection(u),u=alamode.addContainerElement(t),h=(d3.select(u).append("div").attr("class","mode-graphic-title").text(i),svg=d3.select(u).append("div").attr("class","mode-zipcode-chorolpleth").append("svg").attr("id","mode-zipcode-chorolpleth-"+a).attr("width",o).attr("height",l),e.forEach(function(t){c.set(t[n],+t[r])}),colorDomain=d||d3.extent(e,function(t){return t[r]}),d3.scale.quantize().domain(colorDomain).range(s));queue().defer(d3.json,"https://s3-us-west-2.amazonaws.com/mode-alamode/zips_us_topo.json").await(function(t,e){d3.select("#mode-zipcode-chorolpleth-"+a).append("g").attr("class","zipcodes").selectAll(".mode-zipcode-chorolpleth-zipcodes"+a).data(topojson.feature(e,e.objects.zip_codes_for_the_usa).features).enter().append("path").attr("class","mode-zipcode-chorolpleth-zipcodes-"+a).attr("fill",function(t){return h(c.get(t.properties.zip))}).attr("d",m)})},countyChoropleth:function(t){var a=alamode.makeId(10),e=t.query_name,n=t.county_id_column,r=t.value_column,o=t.width||950,l=t.height||o/1.9,i=t.title||e,d=t.color_range,s=t.color_gradient||["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"],t=t.html_element||"body",e=alamode.getDataFromQuery(e),c=d3.map(),u=d3.geoAlbersUsa().scale(o).translate([o/2,l/2]),m=d3.geoPath().projection(u),u=alamode.addContainerElement(t),h=(d3.select(u).append("div").attr("class","mode-graphic-title").text(i),svg=d3.select(u).append("div").attr("class","mode-county-chorolpleth").append("svg").attr("id","mode-county-chorolpleth-"+a).attr("width",o).attr("height",l),e.forEach(function(t){c.set(t[n],+t[r])}),colorDomain=d||d3.extent(e,function(t){return t[r]}),d3.scale.quantize().domain(colorDomain).range(s));queue().defer(d3.json,"https://s3-us-west-2.amazonaws.com/mode-alamode/counties.json").await(function(t,e){d3.select("#mode-county-chorolpleth-"+a).append("g").attr("class","mode-county-chorolpleth-counties").selectAll(".mode-county-chorolpleth-counties"+a).data(topojson.feature(e,e.objects.counties).features).enter().append("path").attr("class","mode-county-chorolpleth-counties-"+a).attr("fill",function(t){return h(c.get(t.id))}).attr("d",m),d3.select("#mode-county-chorolpleth-"+a).append("path").datum(topojson.mesh(e,e.objects.states,function(t,e){return t!==e})).attr("class","mode-county-chorolpleth-states").attr("d",m)})},stateChoropleth:function(t){var a=alamode.makeId(10),e=t.query_name,n=t.state_column,r=t.value_column,o=t.state_code_type,l=t.width||950,i=t.height||l/1.9,d=t.title||e,s=t.color_range,c=t.color_gradient||["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"],t=t.html_element||"body",e=alamode.getDataFromQuery(e),u=d3.map(),m=d3.geoAlbersUsa().scale(l).translate([l/2,i/2]),h=d3.geoPath().projection(m),m=alamode.addContainerElement(t),p=(d3.select(m).append("div").attr("class","mode-graphic-title").text(d),svg=d3.select(m).append("div").attr("class","mode-state-chorolpleth").append("svg").attr("id","mode-state-chorolpleth-"+a).attr("width",l).attr("height",i),e.forEach(function(t){u.set(t[n],+t[r])}),colorDomain=s||d3.extent(e,function(t){return t[r]}),d3.scale.quantize().domain(colorDomain).range(c));queue().defer(d3.json,"https://s3-us-west-2.amazonaws.com/mode-alamode/states.json").await(function(t,e){d3.select("#mode-state-chorolpleth-"+a).append("g").attr("class","mode-state-chorolpleth-states").selectAll(".mode-state-chorolpleth-states-"+a).data(e.features).enter().append("path").attr("class","mode-state-chorolpleth-states-"+a).attr("fill",function(t){return p(u.get(t.properties[o]))}).attr("d",h)})},worldChoropleth:function(t){var a=alamode.makeId(10),e=t.query_name,n=t.country_column,r=t.value_column,o=t.country_code_type,l=t.width||950,i=t.height||.8*l,d=t.title||e,s=t.color_range,c=t.color_gradient||["#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"],t=t.html_element||"body",e=alamode.getDataFromQuery(e),u=d3.map(),m=d3.geo.mercator().scale((l+1)/2/Math.PI).translate([l/2,i/2+.1*i]).precision(.1),h=d3.geoPath().projection(m),m=alamode.addContainerElement(t),p=(d3.select(m).append("div").attr("class","mode-graphic-title").text(d),d3.select(m).append("div").attr("class","mode-world-chorolpleth-legend").attr("id","mode-world-chorolpleth-legend-"+a).text("Hover over a country to see details"),svg=d3.select(m).append("div").attr("class","mode-world-chorolpleth").append("svg").attr("id","mode-world-chorolpleth-"+a).attr("width",l).attr("height",i),e.forEach(function(t){u.set(t[n],+t[r])}),s?colorDomain=s:(colorDomain=d3.extent(e,function(t){return t[r]}),e.length<=1&&colorDomain.unshift(0)),d3.scale.quantize().domain(colorDomain).range(c));queue().defer(d3.json,"https://s3-us-west-2.amazonaws.com/mode-alamode/world.json").await(function(t,e){d3.select("#mode-world-chorolpleth-"+a).append("g").attr("class","mode-world-chorolpleth-countries-base").selectAll(".mode-world-chorolpleth-countries").data(topojson.feature(e,e.objects.countries).features).enter().append("path").attr("class","mode-world-chorolpleth-countries").attr("fill",function(t){return p(u.get(t.properties[o]))}).attr("d",h).on("mouseover",function(t){var e=t.properties.name;value=u.get(t.properties[o])?u.get(t.properties[o]):"--",d3.select("#mode-world-chorolpleth-legend-"+a).text(e+": "+value)}).on("mouseout",function(t){d3.select("#mode-world-chorolpleth-legend-"+a).text("Hover over a country to see details")}),d3.select("#mode-world-chorolpleth-"+a).append("path").datum(topojson.mesh(e,e.objects.countries,function(t,e){return t!==e})).attr("class","mode-world-chorolpleth-boundaries").attr("d",h)})},pivotTable:function(t){var e=alamode.makeId(10),a=t.query_name,n=t.default_columns,r=t.default_rows,o=t.default_values,l=t.editable,i=t.aggregate_function||"Count",d=t.pivot_table_type||"Table",s=t.title||a,c=t.html_element||"body",u=t.default_exclusions||[],t=t.default_inclusions||[],m=(Array.isArray(o)||(o=[o]),alamode.getDataFromQuery(a)),a=alamode.getColumnsFromQuery(a),h=_.map(a,"name"),a=alamode.addContainerElement(c),p=(d3.select(a).append("div").attr("class","mode-graphic-title").text(s),d3.select(a).append("div").attr("class","mode-pivot-table").attr("id",e),[]);p.push(h),m.forEach(function(e){var a=[];h.forEach(function(t){a.push(e[t])}),p.push(a)}),l?$("#"+e).pivotUI(p,{cols:n,rows:r,aggregatorName:i,vals:o,rendererName:d,exclusions:u,inclusions:t}):(s=(c=$.pivotUtilities).renderers[d],a=c.aggregators[i],$("#"+e).pivot(p,{cols:n,rows:r,aggregator:a(o),renderer:s,exclusions:u,inclusions:t}))},pieChartLabels:function(t){var e=t.show_all_labels,t=t.chart_id,a=$("#"+t),o={};setInterval(function(){var t,r;r=e,(t=a).find(".nv-legendWrap .nv-series text").each(function(a){var n=$(this).text();t.find(".nv-pieWrap .nv-pieLabels text").each(function(t){var e=a+"-"+t;text=$(this).text(),a==t&&""!=text&&text!=o[e]?text=n+" - "+text:a==t&&r&&text!=o[e]&&(text=n),o[e]=text,$(this).text(text)})})},300)},bigNumberSparkline:function(t){var e="#"+t.chart_id,a=t.x_axis_column,n=t.value_column,t=t.query_name,r=alamode.makeId(12),o=alamode.getDataFromQuery(t),t=alamode.getColumnsFromQuery(t),l=(xType=a?(xMatch=_.filter(t,{name:a}))[0].type:"string",[]),t=(o.forEach(function(t){t={x:formattedX="datetime"==xType||"timestamp"==xType||"date"==xType?d3.time.format.utc("%Y-%m-%d")(new Date(Date.parse(t[a]))):t[a],y:t[n]};l.push(t)}),$(e+" .chart-wrapper")),o=$(e+" .chart-big-number"),i=t.height(),t=t.width(),o=o.height(),i=i-o-20;d3.select(e+" .chart-big-number").append("svg").attr("height",i).attr("width",t).attr("id",r).append("g").attr("transform","translate(0,"+o+")"),nv.addGraph(function(){var t=nv.models.sparklinePlus().margin({left:15,right:15}).x(function(t,e){return e}).xTickFormat(function(t){return l[t].x}).showLastValue(!1);return d3.select("#"+r).datum(l).call(t),t}),setTimeout(function(){d3.selectAll(e+" path").style("stroke-width","2px").style("stroke-linejoin","round").style("stroke","#646C6C"),d3.selectAll(e+" .nv-minValue").style("fill","#EE7437").style("stroke","#EE7437").attr("r",3),d3.selectAll(e+" .nv-maxValue").style("fill","#37B067").style("stroke","#37B067").attr("r",3),d3.selectAll(e+" .nv-currentValue").style("fill","#22A3C0").style("stroke","#22A3C0").attr("r",3)},1e3)},addLinkToBigNumber:function(t){window.ALAMODE_CHARTS=window.ALAMODE_CHARTS||{};var e=t.chart_id.split("_")[1];window.ALAMODE_CHARTS[e]=t.url},forceDirectedGraph:function(t){var e=alamode.makeId(10),a=t.node_query,n=t.edge_query,r=t.html_element||"body",o=t.title||queryName,l=t.chart_width||"800",i=t.chart_height||"800",d=t.group_colors||"",t=t.links_to_show||100,s=alamode.getDataFromQuery(a),a=alamode.getDataFromQuery(n),c=[],n=(a.forEach(function(e){var t=c.filter(function(t){return t.target==e.source}).filter(function(t){return t.source==e.target});0!=t.length?t.edge_size+=e.edge_size:c.push(e)}),c=(c=c.sort(function(t,e){return e.edge_size-t.edge_size})).slice(0,t),nameMap={},s.forEach(function(t,e){t.id=e,nameMap[t.node]=e}),c.forEach(function(t){t.source_id=nameMap[t.source],t.target_id=nameMap[t.target]}),alamode.addContainerElement(r)),a=(d3.select(n).append("div").attr("class","mode-graphic-title").text(o),d3.select(n).append("div").attr("class","mode-force-directed-graph").style("width",l).attr("id",e),d3.tip().attr("class","mode-force-directed-graph-tooltip").offset([-10,0]).html(function(t){return t.node})),t=d3.layout.force().linkDistance(40).linkStrength(1).size([l,i]),r=d3.select("#"+e).append("svg").attr("width",l).attr("height",i),o=(r.call(a),{nodes:s,links:c}),u=d3.scale.linear().domain(d3.extent(s,function(t){return t.node_size})).range([2,20]),m=d3.scale.linear().domain(d3.extent(c,function(t){return t.edge_size})).range([1,10]),h=d3.scale.linear().domain(d3.extent(c,function(t){return t.edge_size})).range([.1,.9]),s=o.nodes.slice(),c=[],p=[],f=(o.links.forEach(function(t){var e=s[t.source_id],a=s[t.target_id],n={};n.connections=t.edge_size,s.push(n),c.push({source:e,target:n},{source:n,target:a}),p.push([e,n,a])}),t.nodes(s).links(c).start(),r.selectAll(".mode-force-directed-graph-link ").data(p).enter().append("path").attr("class","mode-force-directed-graph-link").style("stroke-width",function(t){return m(t[1].connections)}).style("opacity",function(t){return h(t[1].connections)})),g=r.selectAll(".mode-force-directed-graph-node").data(o.nodes).enter().append("g").attr("class","mode-force-directed-graph-node").call(t.drag);g.append("circle").attr("r",function(t){return u(t.node_size)}).style("fill",function(t){return d?d[t.node_group]:"#0E819A"}).on("mouseover",a.show).on("mouseout",a.hide),t.on("tick",function(){f.attr("d",function(t){return"M"+t[0].x+","+t[0].y+"S"+t[1].x+","+t[1].y+" "+t[2].x+","+t[2].y}),g.attr("transform",function(t){return"translate("+t.x+","+t.y+")"})})},networkMatrix:function(t){var e=alamode.makeId(10),a=t.node_query,n=t.edge_query,r=t.html_element||"body",o=t.title||queryName,l=t.padding_for_names||"200",i=t.chart_width||"800",d=t.chart_height||"800",s=t.group_colors||"",c=t.left_label||"",t=t.top_label||"",u=l,m=10,h=10,p=alamode.getDataFromQuery(a),a=alamode.getDataFromQuery(n),f=(nameMap={},p.forEach(function(t,e){t.id=e,nameMap[t.node]=e}),a.forEach(function(t){t.source_id=nameMap[t.source],t.target_id=nameMap[t.target]}),d3.scale.ordinal().rangeBands([0,i])),g=d3.scale.linear().domain(d3.extent(a,function(t){return t.edge_size})).clamp(!0),n=alamode.addContainerElement(r),v=(d3.select(n).append("div").attr("class","mode-graphic-title").text(o),d3.select(n).append("div").attr("class","mode-network-matrix-order-picker").html('<p>Order: <select id="mode-network-matrix-order-picker-'+e+'"><option value="name">Name</option><option value="count">Frequency</option><option value="group">Group</option></select>'),d3.select(n).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e),d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(t){return t.z})),r=d3.select("#"+e).append("svg").attr("width",i+l+m).attr("height",d+u+h),y=(r.call(v),r.append("g").attr("transform","translate("+l+","+u+")")),x=(graph={nodes:p,links:a},[]),b=(p=graph.nodes).length,_=(p.forEach(function(t,e){t.index=e,t.count=0,x[e]=d3.range(b).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){void 0!==x[t.source_id][t.target_id]?(x[t.source_id][t.target_id].z+=t.edge_size,p[t.source_id].count+=t.edge_size,p[t.target_id].count+=t.edge_size):(x[t.source_id][t.target_id]={},x[t.source_id][t.target_id].z=0)}),{name:d3.range(b).sort(function(t,e){return d3.ascending(p[t].node,p[e].node)}),count:d3.range(b).sort(function(t,e){return p[e].count-p[t].count}),group:d3.range(b).sort(function(t,e){return d3.ascending(p[t].node_group,p[e].node_group)})});f.domain(_.name),r.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(i+l+m)/2).attr("y",25).attr("text-anchor","middle").text(t),r.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(d+u+h)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(c),y.append("rect").attr("class","mode-network-matrix-background").attr("width",i).attr("height",d);(w=y.selectAll(".mode-network-matrix-row").data(x).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+f(e)+")"}).each(w)).append("line").attr("class","mode-network-matrix-line").attr("x2",i),w.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",f.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(t,e){return p[e].node});var w,o=y.selectAll(".mode-network-matrix-column").data(x).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(t,e){return"translate("+f(e)+")rotate(-90)"});function w(t){d3.select(this).selectAll(".mode-network-matrix-cell").data(t.filter(function(t){return t.z})).enter().append("rect").attr("class","mode-network-matrix-cell").attr("x",function(t){return f(t.x)}).attr("width",f.rangeBand()).attr("height",f.rangeBand()).style("fill-opacity",function(t){return g(t.z)}).style("fill",function(t){return p[t.x].node_group==p[t.y].node_group?s[p[t.x].node_group]:"#2B2B2B"}).on("mouseover",function(t){var a;a=t,d3.selectAll(".mode-network-matrix-row-text").classed("active",function(t,e){return e==a.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(t,e){return e==a.x}),v.show(t)}).on("mouseout",function(t){d3.selectAll("text").classed("active",!1),v.hide(t)})}o.append("line").attr("class","mode-network-matrix-line").attr("x1",-i),o.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",f.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(t,e){return p[e].node}),d3.select("#mode-network-matrix-order-picker-"+e).on("change",function(){var t=this.value;f.domain(_[t]),(t=y.transition().duration(1e3)).selectAll(".mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+f(e)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(t){return f(t.x)}),t.selectAll(".mode-network-matrix-column").attr("transform",function(t,e){return"translate("+f(e)+")rotate(-90)"})})},hive:function(t){d3.hive={},d3.hive.link=function(){function e(t,e){var a=r(o,this,t,e),t=r(l,this,t,e),e=(a.a>t.a&&(e=t,t=a,a=e),t.a-a.a>Math.PI&&(a.a+=2*Math.PI),a.a+(t.a-a.a)/3),n=t.a-(t.a-a.a)/3;return a.r0-a.r1||t.r0-t.r1?"M"+Math.cos(a.a)*a.r0+","+Math.sin(a.a)*a.r0+"L"+Math.cos(a.a)*a.r1+","+Math.sin(a.a)*a.r1+"C"+Math.cos(e)*a.r1+","+Math.sin(e)*a.r1+" "+Math.cos(n)*t.r1+","+Math.sin(n)*t.r1+" "+Math.cos(t.a)*t.r1+","+Math.sin(t.a)*t.r1+"L"+Math.cos(t.a)*t.r0+","+Math.sin(t.a)*t.r0+"C"+Math.cos(n)*t.r0+","+Math.sin(n)*t.r0+" "+Math.cos(e)*a.r0+","+Math.sin(e)*a.r0+" "+Math.cos(a.a)*a.r0+","+Math.sin(a.a)*a.r0:"M"+Math.cos(a.a)*a.r0+","+Math.sin(a.a)*a.r0+"C"+Math.cos(e)*a.r1+","+Math.sin(e)*a.r1+" "+Math.cos(n)*t.r1+","+Math.sin(n)*t.r1+" "+Math.cos(t.a)*t.r1+","+Math.sin(t.a)*t.r1}function r(t,e,a,n){var t=t.call(e,a,n),a=+("function"==typeof i?i.call(e,t,n):i)+c,r=+("function"==typeof d?d.call(e,t,n):d);return{r0:r,r1:d===s?r:+("function"==typeof s?s.call(e,t,n):s),a:a}}var o=function(t){return t.source},l=function(t){return t.target},i=function(t){return t.angle},d=function(t){return t.radius},s=d,c=-Math.PI/2;return e.source=function(t){return arguments.length?(o=t,e):o},e.target=function(t){return arguments.length?(l=t,e):l},e.angle=function(t){return arguments.length?(i=t,e):i},e.radius=function(t){return arguments.length?(d=s=t,e):d},e.startRadius=function(t){return arguments.length?(d=t,e):d},e.endRadius=function(t){return arguments.length?(s=t,e):s},e};var e=alamode.makeId(10),a=t.node_query,n=t.edge_query,r=t.groups_are_numeric,o=t.html_element||"body",l=t.title||queryName,i=t.chart_width||"800",d=t.chart_height||"800",s=t.group_colors||"",t=Math.min(i,d)/2-30,c=.2*t,a=alamode.getDataFromQuery(a),u=alamode.getDataFromQuery(n),m=_.uniq(_.map(a,"node_group")),h={},n=(a.forEach(function(t){t.x=r?t.node_group:m.indexOf(t.node_group),t.y=t.node_size,h[t.node]=t}),u.forEach(function(t){t.source=h[t.source],t.target=h[t.target]}),alamode.addContainerElement(o)),p=(d3.select(n).append("div").attr("class","mode-graphic-title").text(l),d3.select(n).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e),angle=r?d3.scale.linear().domain(d3.extent(a,function(t){return t.node_group})).range([0,2*Math.PI]):d3.scale.ordinal().domain(d3.range(m.length+1)).rangePoints([0,2*Math.PI]),d3.scale.linear().domain(d3.extent(a,function(t){return t.node_size})).range([c,t])),f=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(t){return t.node}),o=d3.select("#"+e).append("svg").attr("width",i).attr("height",d).append("g").attr("transform","translate("+i/2+","+d/2+")");function g(t){return t/Math.PI*180-90}o.call(f),o.selectAll(".mode-hive-axis").data(d3.range(m.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(t){return"rotate("+g(angle(t))+")"}).attr("x1",p.range()[0]).attr("x2",p.range()[1]),o.selectAll(".mode-hive-link").data(u).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(t){return angle(t.x)}).radius(function(t){return p(t.y)})).style("stroke",function(t){return s[t.source.node_group]}),o.selectAll(".mode-hive-node").data(a).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(t){return"rotate("+g(angle(t.x))+")"}).attr("cx",function(t){return p(t.y)}).attr("r",5).style("fill",function(t){return s[t.node_group]}).on("mouseover",function(e){f.show(e),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(u).attr("class",function(t){return t.source.node==e.node||t.target.node==e.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(t){f.hide(t),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(a){var g="#"+a.table_id,t=a.query_name,e=a.column_rules,v=alamode.getDataFromQuery(t),y=(alamode.getColumnsFromQuery(t),{});function n(t){var e,a=$(g+" table"),n=$(g+" .js-header-table"),n=n?$(g+" .js-col-header"):$(n).find("th");a.find("tr");n.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),y[text]=e}),t.forEach(function(f){f.rules.forEach(function(t){var a,n,r,o,l,i,d,s,e,c,u,m,h,p=t.shade_text||!1;"gradient"==t.type?(s=f.column,e=t.color,c=p,u=d3.extent(_.map(v,s)),m=d3.scale.linear().domain(u).interpolate(d3.interpolateHsl).range(e),h=y[s],v.forEach(function(t,e){var e=g+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+h+"']",t=m(t[s]),a=x(t),e=$(e);c?e.css("color",t):e.css({background:t,color:a})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(a=f.column,n=t.type,r=t.value,o=t.color,l=p,i=y[a],d=x(o),v.forEach(function(t,e){e=$(g+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+i+"']");("above"==n&&t[a]>=r||"below"==n&&t[a]<=r||"equal"==n&&t[a]==r)&&(l?e.css("color",o):e.css({background:o,color:d}))}))})})}function x(t){var e=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(a=e?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e=t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){n(e)},1e3),$(g).mousemove(function(){n(e)})},customizeTable:function(t){window.dispatchAction({type:"Embed.AlamodeCustomizeTable",payload:t})},conditionalFormattingByTable:function(a){var u="#"+a.table_id,t=a.query_name,m=a.columns,h=(rules=a.rules,alamode.getDataFromQuery(t)),p=(alamode.getColumnsFromQuery(t),{}),e=[],f=(m.forEach(function(t){t=d3.extent(_.map(h,t));e=e.concat(t)}),d3.extent(e));function n(t){var e,a=$(u+" table"),n=$(u+" .js-header-table"),n=n?$(u+" .js-col-header"):$(n).find("th");a.find("tr");n.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),p[text]=e}),t.forEach(function(t){var r,o,l,i,d,e,s,c,a=t.shade_text||!1;"gradient"==t.type?(e=t.color,s=a,c=d3.scale.linear().domain(f).interpolate(d3.interpolateHsl).range(e),h.forEach(function(n,r){m.forEach(function(t){var e=p[t],e=u+" table [data-axel-rowkey='"+r+"'][data-axel-column='"+e+"']",t=c(n[t]),a=g(t),e=$(e);s?e.css("color",t):e.css({background:t,color:a})})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(r=t.type,o=t.value,l=t.color,i=a,d=g(l),h.forEach(function(a,n){m.forEach(function(t){var e=p[t],e=$(u+" table [data-axel-rowkey='"+n+"'][data-axel-column='"+e+"']");("above"==r&&a[t]>=o||"below"==r&&a[t]<=o||"equal"==r&&a[t]==o)&&(i?e.css("color",l):e.css({background:l,color:d}))})}))})}function g(t){var e=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(a=e?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e=t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){n(rules)},1e3),$(u).mousemove(function(){n(rules)})},addTableOfContents:function(t){var e=(t=void 0===t?"default":t).text_color,a=t.background_color,n=t.hover_color,r=($(".mode-header").addClass("has-nav"),$("<nav class='fixed-nav-bar'></nav>")),t=($(".row").each(function(){$(this).children().each(function(){var t,e=$(this).find("mode-chart").attr("id")||$(this).find("mode-table").attr("id")||$(this).find("mode-python").attr("id");if(!e)return!0;e.includes("chart")||e.includes("table")?(t=document.getElementById(e),t=(0<$(t).find("mode-pivot-table").length?document.getElementById(e).getElementsByClassName("in-place-edit-text"):document.getElementById(e).getElementsByClassName("chart-title"))[0].innerText):e.includes("python")&&(t=document.getElementById(e).getElementsByClassName("in-place-edit-text")[0].innerText);e=$("<a class='scroll-link' href=#"+e+">"+(t.includes("Click to add title")?"Untitled":t)+"</a>");r.append(e)})}),$("<div class='mode-grid container''></div>")),o=($(".mode-content").prepend(t),$("<div class='row'></div>")),t=(t.prepend(o),$("<div class='col-md-12'></div>"));o.prepend(t),t.prepend(r),e&&$(".fixed-nav-bar a").css("color",e),a&&$(".fixed-nav-bar").css("background-color",a),n&&$(".fixed-nav-bar a").hover(function(){$(this).css("color",n)},function(){e?$(this).css("color",e):$(this).css("color","")}),setTimeout(function(){$(".scroll-link").on("click",function(t){t.preventDefault();var t=$(this).attr("href"),e=t,a=750;e=$(t).offset().top-50,$("html,body").animate({scrollTop:e},a)})},100)},xAnnotations:function(t){var a=t.chart_id,r=t.comment_values,o=t.comments,l=t.color||[],d=t.is_date||!1;setTimeout(function(){var e=$("#"+a).find("div.highcharts-container")[0].id,t=Highcharts.charts;if(chart=t.filter(function(t){if(t)return t.container.id==e})[0],data=chart.series[0].data,d)for(i=0;i<r.length;i++)r[i]=new Date(r[i]).getTime();var n=data.filter(function(t){if(t)return 0<=r.indexOf(t.category)});chart.update({chart:{events:{load:function(t){for(i=0;i<n.length;i++){var e=n[i],a=l[i]||e.color||"#FCFCFC";t.renderer.label(o[i],e.plotX+t.plotLeft,10,"callout",e.plotX+t.plotLeft,e.plotY+t.plotTop).attr({fill:"#FCFCFC",stroke:a,"stroke-width":1,radius:10,zIndex:4}).add()}}(chart)}}})},250)},barChartFunnel:function(t){var n=t.chart_id;setTimeout(function(){var e=$("#"+n).find("div.highcharts-container")[0].id,t=Highcharts.charts,a=(chart=t.filter(function(t){if(t)return t.container.id==e})[0],data=chart.series[0].data,d3.format(".1%")),t=chart.series[1].color,t=(chart.update({series:[{color:t,opacity:.6},{dataLabels:{enabled:!0,useHTML:!0,borderRadius:5,padding:20,formatter:function(){return 0==this.point.index?null:a(this.percentage/100)},border:"black",shape:"square",backgroundColor:"rgba(0, 0, 0, 0.75)",style:{fontSize:"11px",color:"#FFFFFF",fontWeight:100,textOutline:"none"}}}],plotOptions:{series:{dataLabels:{x:-210,y:150}}}}),a(chart.yAxis[0].dataMin/chart.yAxis[0].dataMax));chart.renderer.text("Overall Rate<br/><br/>"+t,chart.plotSizeX-20,chart.plotTop+20).attr({zIndex:5}).css({fontSize:"14px",color:"#FFFFFF"}).add(),chart.renderer.rect(chart.plotSizeX-30,chart.plotTop,124,50,2).attr({"stroke-width":2,stroke:"black",fill:"black",zIndex:4}).add()},250)},highChartsSeriesColor:function(t){var a=t.series_Colors;var n=[];n.push(function(){}),(H=Highcharts).Chart.prototype.callbacks.push(function(t){for(var e=0;e<n.length;++e)n[e].call(this,event);t.update({series:function(e,t){for(var a=new Array(e.length),n=0;n<a.length;n++){var r=t.filter(function(t){return t.seriesName===e[n].name});null==r[0]&&(console.log("Jon Color"),r[0]=""),console.log(r[0].color),a[n]={color:r[0].color}}return a}(this.series,a)})})}};