From 5db42a8589755bda50a6b2aa482655c64866373c Mon Sep 17 00:00:00 2001 From: Leqi Long Date: Wed, 15 Feb 2017 22:49:08 -0800 Subject: [PATCH] Added addLinksToBarCharts method --- alamode.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ alamode.min.js | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/alamode.js b/alamode.js index 2126f89..2b07a94 100644 --- a/alamode.js +++ b/alamode.js @@ -2814,5 +2814,64 @@ var alamode = { }, speed); } }, 100); + }, + + addLinksToBarCharts: function(o) { + + var data = alamode.getDataFromQuery(queryName); + + var chartId = o["bar_chart_id"], + linkColumn = o["link_column"], + linkURLs = o["link_urls"], + seriesCount = linkURLs.length, + barsCount = 0, + urlArray = [], + colCount = data.length; + + + setTimeout(function() { + var chart = document.getElementById(chartId); + d3.select(chart).selectAll(".nv-groups rect").attr("id", function(d, i){ + barsCount++; + return i; + }); + + for (i = 0; i < seriesCount; i++) { + for (j = 0; j < barsCount / seriesCount; j++) { + urlArray.push(linkURLs[i]); + } + } + + $(chart).find(".nv-groups rect").hover(function() { + $(this).css("cursor", "pointer"); + }); + + $(".nv-groups rect").click(function() { + var rowIndex; + if (this.id >= colCount) { + rowIndex = this.id % colCount; + } else { + rowIndex = this.id; + } + + var column = data[rowIndex][linkColumn]; + + while (urlArray[this.id].indexOf("{{") != -1) { + var chars = urlArray[this.id].length, + start = urlArray[this.id].indexOf("{{"), + end = urlArray[this.id].substring(start + 2, chars).indexOf("}}"), + cName = urlArray[this.id].substring(start + 2, start + end + 2), + full = urlArray[this.id].substring(start, start + end + 4), + content = column; + + urlArray[this.id] = urlArray[this.id].replace(full, content); + } + + var link = document.createElement('a'); + link.href = urlArray[this.id]; + $(this).append(link); + link.click(); + }); + }, 100); } } diff --git a/alamode.min.js b/alamode.min.js index 4b63133..91be033 100644 --- a/alamode.min.js +++ b/alamode.min.js @@ -1,2 +1,2 @@ var version="0.11",alamode={reportError:function(t){$("

").text(t).prependTo(document.body)},getColumnsFromQuery:function(t){var e=datasets.filter(function(e){if(e)return e.queryName==t})[0];return e?e.columns:(alamode.reportError("No such query: '"+t+"'"),[])},getDataFromQuery:function(t){var e=datasets.filter(function(e){if(e)return e.queryName==t})[0];return e?e.content:(alamode.reportError("No such query: '"+t+"'"),[])},makeId:function(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",a="",n=0;n").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content"):0===$(t).length?alamode.reportError("No such element: '"+t+"'"):($(t).addClass("mode-graphic-container"),$(t).addClass(id)),"."+id},addLinksToTables:function(t){function e(t){var e=$(a+" table"),n=$(a+" .js-header-table"),r=n.find("th"),o=e.find("tr"),l=0;r.each(function(){text=$(this).find(".axel-table-header-label").text(),l=$(this).attr("data-axel-column"),i[text]=l-1}),o.each(function(e){if(e>0&&e<=d.length){var a=$(this).find("td"),n=a.first().attr("data-axel-rowkey");t.forEach(function(t){var e=i[t.column],r=a.eq(e).text();for(url=t.link_string;url.indexOf("{{")!=-1;){var o=url.length,l=url.indexOf("{{"),s=url.substring(l+2,o).indexOf("}}"),c=url.substring(l+2,l+s+2),u=url.substring(l,l+s+4),m=(i[c],d[n][c]);url=url.replace(u,m)}a.eq(e).html(""+r+"")})}})}var a="#"+t.table_id,n=t.link_columns,r=t.link_urls,o=t.query_name,l=[],i={};n.forEach(function(t,e){l.push({column:t,link_string:r[e]})});var d=alamode.getDataFromQuery(o);alamode.getColumnsFromQuery(o);setTimeout(function(){e(l)},1e3),$(a).mousemove(function(){e(l)})},customChartColors:function(t){function e(t,e){var a=$("#"+t),n=a.find(".nvtooltip table .legend-color-guide"),l=a.find(".nv-groups g"),i=l.length,d=a.find(".nv-areaWrap"),s=a.find(".nv-barsWrap"),c=a.find(".nv-series .nv-legend-symbol"),u=n.length-1,m=d.length,h=s.length,p={},f={},g={},v=0;if(0==c.length&&i<=1)f[0]=v,g[v]=0,p[0]=e[0];else if(0==c.length&&i>1)for(y=0;y0||h>0?$(this).find("div").css({"background-color":p[g[u-t-1]]}):$(this).find("div").css({"background-color":p[g[t]]})}),sliceColor=a.find(".nv-pie .nv-slice.hover").css("fill"),a.find(".nvtooltip table .legend-color-guide div").css("background-color",sliceColor)}),a.find(".nv-legendWrap .nv-series .nv-legend-symbol").each(function(t){$(this).css({fill:p[t],stroke:p[t]})})}var a=t.charts,n=t.colors,r=t.opacity,o=t.line_dashes;"all"==a&&(a=[],$("mode-chart").each(function(){a.push(this.id)})),setInterval(function(){a.forEach(function(t){e(t,n)})},500)},addTotalsRow:function(t){function e(t){return numberColumns=_.map(_.filter(d,function(t){return["number","integer"].indexOf(t.type)!=-1}),"name"),"all"==t?numberColumns:_.intersection(t,numberColumns)}function a(t){var e=[],a={idx:i,name:"",total:""};return d.forEach(function(n,r){if(t.indexOf(n.name)==-1)var o=a;else var l=_.map(s,n.name),i=d3.sum(l),o={idx:r,name:n.name,total:i};e.push(o)}),e}function n(t){var e="TTL";return t.forEach(function(t){""!=t.total?e=e+""+u(t.total)+"":e+=""}),e+""}var r=t.query_name,o=t.table_id||"",l="#"+o,d=alamode.getColumnsFromQuery(r),s=alamode.getDataFromQuery(r),c=t.columns_with_totals,u=d3.format(","),m=e(c),h=a(m);setTimeout(function(){"#"==l?table=$(".main-table"):table=$(l+" .main-table");var t=table.find("tr:last"),e=n(h);t.after(e)},1e3)},addImagesToTables:function(t){function e(){var t=$(a+" table"),e=$(a+" .js-header-table"),o=e.find("th"),l=t.find("tr");o.each(function(){text=$(this).find(".axel-table-header-label").text(),text==n&&(columnIndex=+$(this).attr("data-axel-column"))}),l.each(function(){var t=$(this).find("td");t.each(function(t){if(t==columnIndex-1){var e=$(this).text();0==$(this).find("img").length&&($(this).css("text-align","center"),$(this).html(""))}})})}var a="#"+t.table,n=t.column,r=t.image_height||100;setTimeout(function(){e()},1e3),$(a).keyup(function(){setTimeout(function(){e()},500)}),$(a).mousemove(function(){e()})},resizeChartHeight:function(t){var e=t.chart,a=t.height;"python"==e.slice(0,6)?($("#"+e+" .mode-python").css("height",a),$("#"+e+" .mode-python").css("max-height",a),$("#"+e+" img").css("max-height",a)):($("#"+e+" .chart").css("height",a),$("#"+e+" .chart-svg").css("height",a)),window.dispatchEvent(new Event("resize"))},retentionHeatmap:function(t){function e(t){return""!=t.value&&(t.column!=d&&t.column!=u&&t.column==s)}function a(t){var e=n(t.column);return"float"==e||"integer"==e||"number"==e?"heatmap-number":"heatmap-string"}function n(t){return y.filter(function(e){return e.name==t})[0].type}function r(t,e){var a=[{column:i,value:e}];if(u){var n=_.filter(t,function(t){return t[i]==e})[0],r={column:u,value:n[u]};a=a.concat(r)}return b.forEach(function(n){var r=_.filter(t,function(t){return t[i]==e&&t[d]==n});r.length>0?entry=d3.mean(_.map(r,s)):entry="",a=a.concat({column:s,value:entry})}),a}function o(t){var e=n(t.column),a=d3.format(","),r=d3.format("."+g+"%"),o=d3.time.format("%b %d, %Y");return""==t.value?t.value:"datetime"==e||"timestamp"==e||"date"==e?"function"==typeof moment?moment(t.value).utc().format("ll"):o(new Date(t.value)):t.column==u?a(t.value):t.column==s&&f?r(t.value):t.column==s?a(t.value):t.value}var l=t.query_name,i=t.cohort_column,d=t.pivot_column,s=t.value_column,c=t.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],u=t.total_column,m=t.html_element||"body",h=t.title||l,p=t.pivot_label||"",f=t.value_is_percent,g=t.precision||0,v=alamode.getDataFromQuery(l),y=alamode.getColumnsFromQuery(l),x=_.uniq(_.map(v,i)),b=_.uniq(_.map(v,d)),w=alamode.addContainerElement(m),k=d3.scale.quantize().domain(d3.extent(v,function(t){return t[s]})).range(c);d3.select(w).append("div").attr("class","mode-graphic-title").text(h),d3.select(w).append("div").attr("class","mode-retention-heatmap-label").text(p),u?headers=[i,u].concat(b):headers=[i].concat(b);var $=d3.select(w).append("table").attr("class","mode-retention-heatmap-table");$.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}),$.selectAll(".mode-retention-heatmap-table-row").data(x).enter().append("tr").attr("class","mode-retention-heatmap-table-row").selectAll(".mode-retention-heatmap-table-cell").data(function(t){return r(v,t)}).enter().append("td").style("background",function(t){if(e(t))return k(t.value)}).attr("class",function(t){return a(t)}).text(function(e){return o(e,t)})},googleMap:function(t){var e=alamode.makeId(10),a=t.lat_column,n=t.lng_column,r=t.query_name,o=t.google_maps_api_key,l=t.title||r,i=t.label_column,d=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",h=alamode.getDataFromQuery(r),p=alamode.addContainerElement(d);d3.select(p).append("div").attr("class","mode-graphic-title").text(l),d3.select(p).append("div").attr("class","mode-google-map").attr("id",e),jQuery.getScript("https://maps.googleapis.com/maps/api/js?key="+o,function(){function t(){var t={zoom:u,center:new google.maps.LatLng(s,c),mapTypeId:m},r=new google.maps.Map(document.getElementById(e),t);h.forEach(function(t){var e=t[a],o=t[n];i?label=t[i]:label="";var l=new google.maps.Marker({position:{lat:e,lng:o},map:r,title:label}),d=new google.maps.InfoWindow({content:label});l.addListener("click",function(){d.open(r,l)})})}t()})},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,h=alamode.getDataFromQuery(r),p=[];h.forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&p.push(t)});var f=alamode.addContainerElement(i);d3.select(f).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o);var g=l-$(f+".mode-graphic-title").height(),v=$(f).width();d3.select(f).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",g+"px").style("width",v+"px");var y=L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18}),x={max:8,data:p},_={radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n},b={lat:d,lng:s,zoom:c},w=new HeatmapOverlay(_);new L.Map(e,{center:new L.LatLng(b.lat,b.lng),zoom:Math.floor(b.zoom),layers:[y,w]});w.setData(x)},wordCloud:function(t){function e(t){d3.select(u).append("div").attr("class","mode-wordcloud").append("svg").attr("width",h.size()[0]).attr("height",h.size()[1]).append("g").attr("transform","translate("+h.size()[0]/2+","+h.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 s[e%s.length]}).attr("text-anchor","middle").attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).text(function(t){return t.text})}var a=t.query_name,n=t.word_column,r=t.word_count_column,o=t.html_element||"body",l=t.title||a,i=t.height||"400",d=t.width||"800",s=t.colors||["black"],c=alamode.getDataFromQuery(a),u=alamode.addContainerElement(o);d3.select(u).append("div").attr("class","mode-graphic-title").text(l);var m=d3.scale.linear().domain(d3.extent(c,function(t){return t[r]})).range([12,60]),h=d3.layout.cloud().size([d,i]).words(c.map(function(t){return{text:t[n],size:m(t[r])}})).padding(2).rotate(function(){return 360*(~~(6*Math.random())-3)}).font("Impact").fontSize(function(t){return t.size}).on("end",e);h.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",d=t.width||"500",s=alamode.getDataFromQuery(a),c=alamode.addContainerElement(o);d3.select(c).append("div").attr("class","mode-graphic-title").text(l),d3.select(c).append("div").attr("class","mode-funnel").attr("id",e).style("width",d+"px").style("height",i-20+"px");var u=[];s.forEach(function(t){u.push([t[n],t[r]])});var m={label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100},h=new D3Funnel("#"+e);h.draw(u,m),d3.select("#"+e).style("height",i+"px")},horizontalBarChart:function(t){var e=t.query_name,a=(t.bar_column,t.series_columns),n=t.colors||["#EE8D24","#43A5DA","#6AB328","#BB60F8","#E14459","#EAD022","#06D0AD","#DB38B7"];stacked=t.stacked||!1,leftpad=t.left_pad||175,htmlElement=t.html_element||"body",title=t.title||e,height=t.chart_height||395,width=t.width||"500";var r=alamode.getDataFromQuery(e),o=alamode.addContainerElement(htmlElement);d3.select(o).append("div").attr("class","mode-graphic-title").text(title),d3.select(o).append("div").attr("class","mode-horizontal-bar-chart").style("height",height-50+"px").append("svg");var l=[];a.forEach(function(e,a){var o={key:e,color:n[a%n.length]},i=[];r.forEach(function(a){i.push({label:a[t.bar_column],value:a[e]})}),o.values=i,l.push(o)}),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(o+" svg").datum(l).call(t),nv.utils.windowResize(t.update),t})},chartAnnotations:function(t){function e(){d.forEach(function(t,e){var n=c[e],r=o[e],i=l[e],d=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),s=$(a).find("g.nvd3.nv-wrap").attr("transform"),u=s.indexOf("("),m=s.indexOf(")"),h=s.indexOf(","),p=+s.slice(u+1,h),f=+s.slice(h+1,m);if(n!=-1&&"v"==r){var g=$(a).find(".nv-point.nv-point-"+n).attr("transform"),v=g.indexOf("("),x=g.indexOf(")"),_=g.indexOf(","),b=+g.slice(v+1,_),w=+g.slice(_+1,x),k=($(a).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(a).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width"),d3.select(a+" .nvd3svg"));k.call(d),k.append("rect").attr("x",b+p).attr("y",f-5).attr("width",1).attr("class","flag").attr("height",w+5).attr("fill","#ff8f53"),k.append("circle").data([t]).attr("cx",b+p).attr("cy",f-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",d.show).on("mouseout",d.hide)}else if("h"==r||"h-left"==r||"h-right"==r){"h"==r?y="":y="1";var E=$(a).find("g.nv-y"+y+".nv-axis").find(".tick");E.each(function(t){"h-right"==r?lineLength=+$(a).find("g.nv-y1.nv-axis").find(".tick").first().find("line").attr("x2"):lineLength=+$(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(",",""))});var C=(yTrans2-yTrans1)/(yVal2-yVal1),z=yTrans2-yVal2*C,F=z+i*C,k=d3.select(a+" .nvd3svg");k.call(d),k.append("rect").attr("x",p).attr("y",F+f).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),k.append("circle").data([t]).attr("cx",lineLength+p+10).attr("cy",F+f).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",d.show).on("mouseout",d.hide)}})}var a="#"+t.chart_id,n=t.x_axis_column,r=t.query_name,o=t.orientations,l=t.comment_values,i=t.group_by,d=t.comments,s=alamode.getDataFromQuery(r),c=[],u={};i&&(u=_.groupBy(s,function(t){return t[i]})),d.forEach(function(t,e){var a=_.filter(s,function(t){return t[n]==l[e]});0!=a.length?i?pointNumber=u[a[0][i]].indexOf(a[0]):pointNumber=s.indexOf(a[0]):pointNumber=-1,c.push(pointNumber)}),setTimeout(function(){d3.select(a).selectAll(".flag").remove(),e()},1e3),$(window).resize(function(){d3.select(a).selectAll(".flag").remove(),m(function(){e()},500,"")});var m=function(){var t={};return function(e,a,n){n||(n="Don't call this twice without a uniqueId"),t[n]&&clearTimeout(t[n]),t[n]=setTimeout(e,a)}}()},bulletChart:function(t){var e=alamode.makeId(10),a=t.query_name,n=t.html_element||"body",r=t.title||a,o=t.chart_width||"800",l=t.bar_column||"",i=t.marker_column||"",d=t.left_pad||150,s=alamode.getDataFromQuery(a),c=alamode.addContainerElement(n);d3.select(c).append("div").attr("class","mode-graphic-title").text(r),d3.select(c).append("div").attr("class","mode-bullet-chart").style("width",o).attr("id",e),s.forEach(function(a){var n=a[t.title_column]||"",r=a[t.subtitle_column]||"",s=a[t.marker_column]||"",c=a[t.bar_column]||"";t.scale_columns?scale=[a[t.scale_columns[0]],a[t.scale_columns[1]],a[t.scale_columns[2]]]:scale=t.scale_columns;var u={title:n,subtitle:r,ranges:scale,measures:[c],measureLabels:[l],markers:[s],markerLabels:[i]};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(o).margin({left:d,right:15,top:10,bottom:10});d3.select("#"+e).append("svg").style("width",o+"px").style("height","70px").style("display","inline").datum(u).transition().duration(500).call(t);return t})})},sunburstChart:function(t){function e(t){o(),s(),vis.append("svg:circle").attr("r",w).style("opacity",0);var e=A.nodes(t).filter(function(t){return t.dx>.005}),r=vis.data([t]).selectAll("path").data(e).enter().append("svg:path").attr("display",function(t){return t.depth?null:"none"}).attr("d",q).attr("fill-rule","evenodd").style("fill",function(t){return z[t.name]}).style("opacity",1).on("mouseover",a);vis.on("mouseleave",n),F=r.node().__data__.value}function a(t){var e=(100*t.value/F).toPrecision(3),a=e+"%";e<.1&&(a="< 0.1%");var n=r(t),o=t.parent.value,l=(100*t.value/o).toPrecision(3),i=l+"%";l<1&&(a="< 1%"),d3.select("#cond-percentage-"+u).text(i),d3.select("#percentage-"+u).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility","");var n=r(t);d(n,a),d3.selectAll("path").style("opacity",.3),vis.selectAll("path").filter(function(t){return n.indexOf(t)>=0}).style("opacity",1)}function n(t){d3.select("#trail-"+u).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",a)}):d3.selectAll("path").transition().duration(300).style("opacity",1).each("end",function(){d3.select(this).on("mouseover",a)}),d3.selectAll(".mode-sunburst-explanation").style("visibility","hidden")}function r(t){for(var e=[],a=t;a.parent;)e.unshift(a),a=a.parent;return e}function o(){var t=d3.select("#sequence-"+u).append("svg:svg").attr("width",b).attr("height",50).attr("id","trail-"+u);t.append("svg:text").attr("id","endlabel").style("fill","#000")}function l(t,e){var a=[];return a.push("0,0"),a.push($.w+",0"),a.push($.w+$.t+","+$.h/2),a.push($.w+","+$.h),a.push("0,"+$.h),e>0&&a.push($.t+","+$.h/2),a.join(" ")}function d(t,e){var a=d3.select("#trail-"+u).selectAll("g").data(t,function(t){return t.name+t.depth}),n=a.enter().append("svg:g");n.append("svg:polygon").attr("points",l).style("fill",function(t){return z[t.name]}),n.append("svg:text").attr("x",($.w+$.t)/2).attr("y",$.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),a.attr("transform",function(t,e){return"translate("+e*($.w+$.s)+", 0)"}),a.exit().remove(),d3.select("#trail-"+u).style("visibility","")}function s(){var t={w:195,h:30,s:3,r:3};d3.entries(z).forEach(function(e){divContainer=d3.select("#legend-container-"+u).append("div").attr("class","mode-sunburst-legend").attr("id","legend-"+u),svg=divContainer.append("svg:svg").attr("width",t.w).attr("height",t.h),svg.append("svg:rect").attr("rx",t.r).attr("ry",t.r).attr("width",t.w).attr("height",t.h).style("fill",function(){return e.value}),svg.append("svg:text").attr("x",t.w/2).attr("y",t.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(){return e.key})})}function c(t){for(var e={name:"root",children:[]},a=0;a"+t+""})},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||"",s=t.links_to_show||100,c=alamode.getDataFromQuery(a),u=alamode.getDataFromQuery(n),m=[];u.forEach(function(t){var e=m.filter(function(e){return e.target==t.source}),a=e.filter(function(e){return e.source==t.target});0!=a.length?a.edge_size+=t.edge_size:m.push(t)}),m=m.sort(function(t,e){return e.edge_size-t.edge_size}),m=m.slice(0,s),nameMap={},c.forEach(function(t,e){t.id=e,nameMap[t.node]=e}),m.forEach(function(t){t.source_id=nameMap[t.source],t.target_id=nameMap[t.target]});var h=alamode.addContainerElement(r);d3.select(h).append("div").attr("class","mode-graphic-title").text(o),d3.select(h).append("div").attr("class","mode-force-directed-graph").style("width",l).attr("id",e);var p=d3.tip().attr("class","mode-force-directed-graph-tooltip").offset([-10,0]).html(function(t){ -return t.node}),f=d3.layout.force().linkDistance(40).linkStrength(1).size([l,i]),g=d3.select("#"+e).append("svg").attr("width",l).attr("height",i);g.call(p);var v={nodes:c,links:m},y=d3.scale.linear().domain(d3.extent(c,function(t){return t.node_size})).range([2,20]),x=d3.scale.linear().domain(d3.extent(m,function(t){return t.edge_size})).range([1,10]),_=d3.scale.linear().domain(d3.extent(m,function(t){return t.edge_size})).range([.1,.9]),c=v.nodes.slice(),m=[],b=[];v.links.forEach(function(t){var e=c[t.source_id],a=c[t.target_id],n={};n.connections=t.edge_size,c.push(n),m.push({source:e,target:n},{source:n,target:a}),b.push([e,n,a])}),f.nodes(c).links(m).start();var w=g.selectAll(".mode-force-directed-graph-link ").data(b).enter().append("path").attr("class","mode-force-directed-graph-link").style("stroke-width",function(t){return x(t[1].connections)}).style("opacity",function(t){return _(t[1].connections)}),k=g.selectAll(".mode-force-directed-graph-node").data(v.nodes).enter().append("g").attr("class","mode-force-directed-graph-node").call(f.drag);k.append("circle").attr("r",function(t){return y(t.node_size)}).style("fill",function(t){return d?d[t.node_group]:"#0E819A"}).on("mouseover",p.show).on("mouseout",p.hide),f.on("tick",function(){w.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}),k.attr("transform",function(t){return"translate("+t.x+","+t.y+")"})})},networkMatrix:function(t){function e(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 x(t.x)}).attr("width",x.rangeBand()).attr("height",x.rangeBand()).style("fill-opacity",function(t){return _(t.z)}).style("fill",function(t){return v[t.x].node_group==v[t.y].node_group?h[v[t.x].node_group]:"#2B2B2B"}).on("mouseover",function(t){a(t),w.show(t)}).on("mouseout",function(t){n(t),w.hide(t)})}function a(t){d3.selectAll(".mode-network-matrix-row-text").classed("active",function(e,a){return a==t.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(e,a){return a==t.x})}function n(){d3.selectAll("text").classed("active",!1)}function r(t){x.domain(z[t]);var e=$.transition().duration(1e3);e.selectAll(".mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+x(e)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(t){return x(t.x)}),e.selectAll(".mode-network-matrix-column").attr("transform",function(t,e){return"translate("+x(e)+")rotate(-90)"})}var o=alamode.makeId(10),l=t.node_query,i=t.edge_query,d=t.html_element||"body",s=t.title||queryName,c=t.padding_for_names||"200",u=t.chart_width||"800",m=t.chart_height||"800",h=t.group_colors||"",p=t.left_label||"",f=t.top_label||"",g={top:c,right:10,bottom:10,left:c},v=alamode.getDataFromQuery(l),y=alamode.getDataFromQuery(i);nameMap={},v.forEach(function(t,e){t.id=e,nameMap[t.node]=e}),y.forEach(function(t){t.source_id=nameMap[t.source],t.target_id=nameMap[t.target]});var x=d3.scale.ordinal().rangeBands([0,u]),_=d3.scale.linear().domain(d3.extent(y,function(t){return t.edge_size})).clamp(!0),b=alamode.addContainerElement(d);d3.select(b).append("div").attr("class","mode-graphic-title").text(s),d3.select(b).append("div").attr("class","mode-network-matrix-order-picker").html('

Order: '),d3.select(b).append("div").attr("class","mode-network-matrix").style("width",u).attr("id",o);var w=d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(t){return t.z}),k=d3.select("#"+o).append("svg").attr("width",u+g.left+g.right).attr("height",m+g.top+g.bottom);k.call(w);var $=k.append("g").attr("transform","translate("+g.left+","+g.top+")");graph={nodes:v,links:y};var E=[],v=graph.nodes,C=v.length;v.forEach(function(t,e){t.index=e,t.count=0,E[e]=d3.range(C).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){"undefined"!=typeof E[t.source_id][t.target_id]?(E[t.source_id][t.target_id].z+=t.edge_size,v[t.source_id].count+=t.edge_size,v[t.target_id].count+=t.edge_size):(E[t.source_id][t.target_id]={},E[t.source_id][t.target_id].z=0)});var z={name:d3.range(C).sort(function(t,e){return d3.ascending(v[t].node,v[e].node)}),count:d3.range(C).sort(function(t,e){return v[e].count-v[t].count}),group:d3.range(C).sort(function(t,e){return d3.ascending(v[t].node_group,v[e].node_group)})};x.domain(z.name),k.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(u+g.left+g.right)/2).attr("y",25).attr("text-anchor","middle").text(f),k.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(m+g.top+g.bottom)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(p),$.append("rect").attr("class","mode-network-matrix-background").attr("width",u).attr("height",m);var e=$.selectAll(".mode-network-matrix-row").data(E).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+x(e)+")"}).each(e);e.append("line").attr("class","mode-network-matrix-line").attr("x2",u),e.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",x.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(t,e){return v[e].node});var F=$.selectAll(".mode-network-matrix-column").data(E).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(t,e){return"translate("+x(e)+")rotate(-90)"});F.append("line").attr("class","mode-network-matrix-line").attr("x1",-u),F.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",x.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(t,e){return v[e].node}),d3.select("#mode-network-matrix-order-picker-"+o).on("change",function(){r(this.value)})},hive:function(t){function e(t){return t/Math.PI*180-90}d3.hive={},d3.hive.link=function(){function t(t,r){var o,l=e(a,this,t,r),i=e(n,this,t,r);l.a>i.a&&(o=i,i=l,l=o),i.a-l.a>Math.PI&&(l.a+=2*Math.PI);var d=l.a+(i.a-l.a)/3,s=i.a-(i.a-l.a)/3;return l.r0-l.r1||i.r0-i.r1?"M"+Math.cos(l.a)*l.r0+","+Math.sin(l.a)*l.r0+"L"+Math.cos(l.a)*l.r1+","+Math.sin(l.a)*l.r1+"C"+Math.cos(d)*l.r1+","+Math.sin(d)*l.r1+" "+Math.cos(s)*i.r1+","+Math.sin(s)*i.r1+" "+Math.cos(i.a)*i.r1+","+Math.sin(i.a)*i.r1+"L"+Math.cos(i.a)*i.r0+","+Math.sin(i.a)*i.r0+"C"+Math.cos(s)*i.r0+","+Math.sin(s)*i.r0+" "+Math.cos(d)*l.r0+","+Math.sin(d)*l.r0+" "+Math.cos(l.a)*l.r0+","+Math.sin(l.a)*l.r0:"M"+Math.cos(l.a)*l.r0+","+Math.sin(l.a)*l.r0+"C"+Math.cos(d)*l.r1+","+Math.sin(d)*l.r1+" "+Math.cos(s)*i.r1+","+Math.sin(s)*i.r1+" "+Math.cos(i.a)*i.r1+","+Math.sin(i.a)*i.r1}function e(t,e,a,n){var d=t.call(e,a,n),s=+("function"==typeof r?r.call(e,d,n):r)+i,c=+("function"==typeof o?o.call(e,d,n):o),u=o===l?c:+("function"==typeof l?l.call(e,d,n):l);return{r0:c,r1:u,a:s}}var a=function(t){return t.source},n=function(t){return t.target},r=function(t){return t.angle},o=function(t){return t.radius},l=o,i=-Math.PI/2;return t.source=function(e){return arguments.length?(a=e,t):a},t.target=function(e){return arguments.length?(n=e,t):n},t.angle=function(e){return arguments.length?(r=e,t):r},t.radius=function(e){return arguments.length?(o=l=e,t):o},t.startRadius=function(e){return arguments.length?(o=e,t):o},t.endRadius=function(e){return arguments.length?(l=e,t):l},t};var a=alamode.makeId(10),n=t.node_query,r=t.edge_query,o=t.groups_are_numeric,l=t.html_element||"body",i=t.title||queryName,d=t.chart_width||"800",s=t.chart_height||"800",c=t.group_colors||"",u=Math.min(d,s)/2-30,m=.2*u,h=alamode.getDataFromQuery(n),p=alamode.getDataFromQuery(r),f=_.uniq(_.map(h,"node_group")),g={};h.forEach(function(t){o?t.x=t.node_group:t.x=f.indexOf(t.node_group),t.y=t.node_size,g[t.node]=t}),p.forEach(function(t){t.source=g[t.source],t.target=g[t.target]});var v=alamode.addContainerElement(l);d3.select(v).append("div").attr("class","mode-graphic-title").text(i),d3.select(v).append("div").attr("class","mode-network-matrix").style("width",d).attr("id",a),o?angle=d3.scale.linear().domain(d3.extent(h,function(t){return t.node_group})).range([0,2*Math.PI]):angle=d3.scale.ordinal().domain(d3.range(f.length+1)).rangePoints([0,2*Math.PI]);var y=d3.scale.linear().domain(d3.extent(h,function(t){return t.node_size})).range([m,u]),x=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(t){return t.node}),b=d3.select("#"+a).append("svg").attr("width",d).attr("height",s).append("g").attr("transform","translate("+d/2+","+s/2+")");b.call(x),b.selectAll(".mode-hive-axis").data(d3.range(f.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(t){return"rotate("+e(angle(t))+")"}).attr("x1",y.range()[0]).attr("x2",y.range()[1]),b.selectAll(".mode-hive-link").data(p).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(t){return angle(t.x)}).radius(function(t){return y(t.y)})).style("stroke",function(t){return c[t.source.node_group]}),b.selectAll(".mode-hive-node").data(h).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(t){return"rotate("+e(angle(t.x))+")"}).attr("cx",function(t){return y(t.y)}).attr("r",5).style("fill",function(t){return c[t.node_group]}).on("mouseover",function(t){x.show(t),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(p).attr("class",function(e){return e.source.node==t.node?"mode-hive-link-selected":e.target.node==t.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(t){x.hide(t),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(t){function e(t){t.forEach(function(t){t.rules.forEach(function(e){var r=e.shade_text||!1;"gradient"==e.type?a(t.column,e.color,r):"above"!=e.type&&"below"!=e.type&&"equal"!=e.type||n(t.column,e.type,e.value,e.color,r)})})}function a(t,e,a){var n=d3.extent(_.map(s,t)),r=d3.scale.linear().domain(n).interpolate(d3.interpolateHsl).range(e),i=c[t];s.forEach(function(e,n){var d=l+" table [data-axel-rowkey='"+n+"'][data-axel-column='"+i+"']",s=r(e[t]),c=o(s),u=$(d);a?u.css("color",s):u.css({background:s,color:c})})}function n(t,e,a,n,r){var i=c[t],d=o(n);s.forEach(function(o,s){var c=l+" table [data-axel-rowkey='"+s+"'][data-axel-column='"+i+"']",u=$(c);"above"==e&&o[t]>=a?r?u.css("color",n):u.css({background:n,color:d}):"below"==e&&o[t]<=a?r?u.css("color",n):u.css({background:n,color:d}):"equal"==e&&o[t]==a&&(r?u.css("color",n):u.css({background:n,color:d}))})}function r(t){var e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null}function o(e){var a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e);return a?(rgb=r(e),t=Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):t=255,t>125?"#2B2B2B":"#FCFCFC"}var l="#"+t.table_id,i=t.query_name,d=t.column_rules,s=alamode.getDataFromQuery(i),c=(alamode.getColumnsFromQuery(i),{}),u=$(l+" table"),m=$(l+" .js-header-table"),h=m.find("th"),p=(u.find("tr"),0);h.each(function(){text=$(this).find(".axel-table-header-label").text(),p=$(this).attr("data-axel-column"),c[text]=p}),setTimeout(function(){e(d)},1e3),$(l).mousemove(function(){e(d)})},conditionalFormattingByTable:function(t){function e(t){t.forEach(function(t){var e=t.shade_text||!1;"gradient"==t.type?a(t.color,e):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||n(t.type,t.value,t.color,e)})}function a(t,e){var a=d3.scale.linear().domain(g).interpolate(d3.interpolateHsl).range(t);s.forEach(function(t,n){d.forEach(function(r){var i=c[r],d=l+" table [data-axel-rowkey='"+n+"'][data-axel-column='"+i+"']",s=a(t[r]),u=o(s),m=$(d);e?m.css("color",s):m.css({background:s,color:u})})})}function n(t,e,a,n){var r=o(a);s.forEach(function(o,i){d.forEach(function(d){var s=c[d],u=l+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+s+"']",m=$(u);"above"==t&&o[d]>=e?n?m.css("color",a):m.css({background:a,color:r}):"below"==t&&o[d]<=e?n?m.css("color",a):m.css({background:a,color:r}):"equal"==t&&o[d]==e&&(n?m.css("color",a):m.css({background:a,color:r}))})})}function r(t){var e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null}function o(e){var a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e);return a?(rgb=r(e),t=Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):t=255,t>125?"#2B2B2B":"#FCFCFC"}var l="#"+t.table_id,i=t.query_name,d=t.columns;rules=t.rules;var s=alamode.getDataFromQuery(i),c=(alamode.getColumnsFromQuery(i),{}),u=$(l+" table"),m=$(l+" .js-header-table"),h=m.find("th"),p=(u.find("tr"),0);h.each(function(){text=$(this).find(".axel-table-header-label").text(),p=$(this).attr("data-axel-column"),c[text]=p});var f=[];d.forEach(function(t){var e=d3.extent(_.map(s,t));f=f.concat(e)});var g=d3.extent(f);setTimeout(function(){e(rules)},1e3),$(l).mousemove(function(){e(rules)})},addTableOfContents:function(t){var e=t.text_color,a=t.background_color,n=t.hover_color;$(".mode-header").addClass("has-nav");var r=$("

");$(".row").each(function(){var t=$(this).children();t.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).getElementsByClassName("chart-title")[0].innerText:e.includes("python")&&(t=document.getElementById(e).getElementsByClassName("in-place-edit-text")[0].innerText);var a=$(""+(t.includes("Click to add title")?"Untitled":t)+"");r.append(a)})});var o=$("
");$(".mode-content").prepend(o);var l=$("
");o.prepend(l);var i=$("
");l.prepend(i),i.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(){function t(t,e){var a=50,n=$(t).offset().top-a;$("html,body").animate({scrollTop:n},e)}$(".scroll-link").on("click",function(e){e.preventDefault();var a=$(this).attr("href");t(a,750)})},100)}}; \ No newline at end of file +return t.node}),f=d3.layout.force().linkDistance(40).linkStrength(1).size([l,i]),g=d3.select("#"+e).append("svg").attr("width",l).attr("height",i);g.call(p);var v={nodes:c,links:m},y=d3.scale.linear().domain(d3.extent(c,function(t){return t.node_size})).range([2,20]),x=d3.scale.linear().domain(d3.extent(m,function(t){return t.edge_size})).range([1,10]),_=d3.scale.linear().domain(d3.extent(m,function(t){return t.edge_size})).range([.1,.9]),c=v.nodes.slice(),m=[],b=[];v.links.forEach(function(t){var e=c[t.source_id],a=c[t.target_id],n={};n.connections=t.edge_size,c.push(n),m.push({source:e,target:n},{source:n,target:a}),b.push([e,n,a])}),f.nodes(c).links(m).start();var w=g.selectAll(".mode-force-directed-graph-link ").data(b).enter().append("path").attr("class","mode-force-directed-graph-link").style("stroke-width",function(t){return x(t[1].connections)}).style("opacity",function(t){return _(t[1].connections)}),k=g.selectAll(".mode-force-directed-graph-node").data(v.nodes).enter().append("g").attr("class","mode-force-directed-graph-node").call(f.drag);k.append("circle").attr("r",function(t){return y(t.node_size)}).style("fill",function(t){return d?d[t.node_group]:"#0E819A"}).on("mouseover",p.show).on("mouseout",p.hide),f.on("tick",function(){w.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}),k.attr("transform",function(t){return"translate("+t.x+","+t.y+")"})})},networkMatrix:function(t){function e(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 x(t.x)}).attr("width",x.rangeBand()).attr("height",x.rangeBand()).style("fill-opacity",function(t){return _(t.z)}).style("fill",function(t){return v[t.x].node_group==v[t.y].node_group?h[v[t.x].node_group]:"#2B2B2B"}).on("mouseover",function(t){a(t),w.show(t)}).on("mouseout",function(t){n(t),w.hide(t)})}function a(t){d3.selectAll(".mode-network-matrix-row-text").classed("active",function(e,a){return a==t.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(e,a){return a==t.x})}function n(){d3.selectAll("text").classed("active",!1)}function r(t){x.domain(z[t]);var e=$.transition().duration(1e3);e.selectAll(".mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+x(e)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(t){return x(t.x)}),e.selectAll(".mode-network-matrix-column").attr("transform",function(t,e){return"translate("+x(e)+")rotate(-90)"})}var o=alamode.makeId(10),l=t.node_query,i=t.edge_query,d=t.html_element||"body",s=t.title||queryName,c=t.padding_for_names||"200",u=t.chart_width||"800",m=t.chart_height||"800",h=t.group_colors||"",p=t.left_label||"",f=t.top_label||"",g={top:c,right:10,bottom:10,left:c},v=alamode.getDataFromQuery(l),y=alamode.getDataFromQuery(i);nameMap={},v.forEach(function(t,e){t.id=e,nameMap[t.node]=e}),y.forEach(function(t){t.source_id=nameMap[t.source],t.target_id=nameMap[t.target]});var x=d3.scale.ordinal().rangeBands([0,u]),_=d3.scale.linear().domain(d3.extent(y,function(t){return t.edge_size})).clamp(!0),b=alamode.addContainerElement(d);d3.select(b).append("div").attr("class","mode-graphic-title").text(s),d3.select(b).append("div").attr("class","mode-network-matrix-order-picker").html('

Order: '),d3.select(b).append("div").attr("class","mode-network-matrix").style("width",u).attr("id",o);var w=d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(t){return t.z}),k=d3.select("#"+o).append("svg").attr("width",u+g.left+g.right).attr("height",m+g.top+g.bottom);k.call(w);var $=k.append("g").attr("transform","translate("+g.left+","+g.top+")");graph={nodes:v,links:y};var E=[],v=graph.nodes,C=v.length;v.forEach(function(t,e){t.index=e,t.count=0,E[e]=d3.range(C).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){"undefined"!=typeof E[t.source_id][t.target_id]?(E[t.source_id][t.target_id].z+=t.edge_size,v[t.source_id].count+=t.edge_size,v[t.target_id].count+=t.edge_size):(E[t.source_id][t.target_id]={},E[t.source_id][t.target_id].z=0)});var z={name:d3.range(C).sort(function(t,e){return d3.ascending(v[t].node,v[e].node)}),count:d3.range(C).sort(function(t,e){return v[e].count-v[t].count}),group:d3.range(C).sort(function(t,e){return d3.ascending(v[t].node_group,v[e].node_group)})};x.domain(z.name),k.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(u+g.left+g.right)/2).attr("y",25).attr("text-anchor","middle").text(f),k.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(m+g.top+g.bottom)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(p),$.append("rect").attr("class","mode-network-matrix-background").attr("width",u).attr("height",m);var e=$.selectAll(".mode-network-matrix-row").data(E).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+x(e)+")"}).each(e);e.append("line").attr("class","mode-network-matrix-line").attr("x2",u),e.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",x.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(t,e){return v[e].node});var F=$.selectAll(".mode-network-matrix-column").data(E).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(t,e){return"translate("+x(e)+")rotate(-90)"});F.append("line").attr("class","mode-network-matrix-line").attr("x1",-u),F.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",x.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(t,e){return v[e].node}),d3.select("#mode-network-matrix-order-picker-"+o).on("change",function(){r(this.value)})},hive:function(t){function e(t){return t/Math.PI*180-90}d3.hive={},d3.hive.link=function(){function t(t,r){var o,l=e(a,this,t,r),i=e(n,this,t,r);l.a>i.a&&(o=i,i=l,l=o),i.a-l.a>Math.PI&&(l.a+=2*Math.PI);var d=l.a+(i.a-l.a)/3,s=i.a-(i.a-l.a)/3;return l.r0-l.r1||i.r0-i.r1?"M"+Math.cos(l.a)*l.r0+","+Math.sin(l.a)*l.r0+"L"+Math.cos(l.a)*l.r1+","+Math.sin(l.a)*l.r1+"C"+Math.cos(d)*l.r1+","+Math.sin(d)*l.r1+" "+Math.cos(s)*i.r1+","+Math.sin(s)*i.r1+" "+Math.cos(i.a)*i.r1+","+Math.sin(i.a)*i.r1+"L"+Math.cos(i.a)*i.r0+","+Math.sin(i.a)*i.r0+"C"+Math.cos(s)*i.r0+","+Math.sin(s)*i.r0+" "+Math.cos(d)*l.r0+","+Math.sin(d)*l.r0+" "+Math.cos(l.a)*l.r0+","+Math.sin(l.a)*l.r0:"M"+Math.cos(l.a)*l.r0+","+Math.sin(l.a)*l.r0+"C"+Math.cos(d)*l.r1+","+Math.sin(d)*l.r1+" "+Math.cos(s)*i.r1+","+Math.sin(s)*i.r1+" "+Math.cos(i.a)*i.r1+","+Math.sin(i.a)*i.r1}function e(t,e,a,n){var d=t.call(e,a,n),s=+("function"==typeof r?r.call(e,d,n):r)+i,c=+("function"==typeof o?o.call(e,d,n):o),u=o===l?c:+("function"==typeof l?l.call(e,d,n):l);return{r0:c,r1:u,a:s}}var a=function(t){return t.source},n=function(t){return t.target},r=function(t){return t.angle},o=function(t){return t.radius},l=o,i=-Math.PI/2;return t.source=function(e){return arguments.length?(a=e,t):a},t.target=function(e){return arguments.length?(n=e,t):n},t.angle=function(e){return arguments.length?(r=e,t):r},t.radius=function(e){return arguments.length?(o=l=e,t):o},t.startRadius=function(e){return arguments.length?(o=e,t):o},t.endRadius=function(e){return arguments.length?(l=e,t):l},t};var a=alamode.makeId(10),n=t.node_query,r=t.edge_query,o=t.groups_are_numeric,l=t.html_element||"body",i=t.title||queryName,d=t.chart_width||"800",s=t.chart_height||"800",c=t.group_colors||"",u=Math.min(d,s)/2-30,m=.2*u,h=alamode.getDataFromQuery(n),p=alamode.getDataFromQuery(r),f=_.uniq(_.map(h,"node_group")),g={};h.forEach(function(t){o?t.x=t.node_group:t.x=f.indexOf(t.node_group),t.y=t.node_size,g[t.node]=t}),p.forEach(function(t){t.source=g[t.source],t.target=g[t.target]});var v=alamode.addContainerElement(l);d3.select(v).append("div").attr("class","mode-graphic-title").text(i),d3.select(v).append("div").attr("class","mode-network-matrix").style("width",d).attr("id",a),o?angle=d3.scale.linear().domain(d3.extent(h,function(t){return t.node_group})).range([0,2*Math.PI]):angle=d3.scale.ordinal().domain(d3.range(f.length+1)).rangePoints([0,2*Math.PI]);var y=d3.scale.linear().domain(d3.extent(h,function(t){return t.node_size})).range([m,u]),x=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(t){return t.node}),b=d3.select("#"+a).append("svg").attr("width",d).attr("height",s).append("g").attr("transform","translate("+d/2+","+s/2+")");b.call(x),b.selectAll(".mode-hive-axis").data(d3.range(f.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(t){return"rotate("+e(angle(t))+")"}).attr("x1",y.range()[0]).attr("x2",y.range()[1]),b.selectAll(".mode-hive-link").data(p).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(t){return angle(t.x)}).radius(function(t){return y(t.y)})).style("stroke",function(t){return c[t.source.node_group]}),b.selectAll(".mode-hive-node").data(h).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(t){return"rotate("+e(angle(t.x))+")"}).attr("cx",function(t){return y(t.y)}).attr("r",5).style("fill",function(t){return c[t.node_group]}).on("mouseover",function(t){x.show(t),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(p).attr("class",function(e){return e.source.node==t.node?"mode-hive-link-selected":e.target.node==t.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(t){x.hide(t),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(t){function e(t){t.forEach(function(t){t.rules.forEach(function(e){var r=e.shade_text||!1;"gradient"==e.type?a(t.column,e.color,r):"above"!=e.type&&"below"!=e.type&&"equal"!=e.type||n(t.column,e.type,e.value,e.color,r)})})}function a(t,e,a){var n=d3.extent(_.map(s,t)),r=d3.scale.linear().domain(n).interpolate(d3.interpolateHsl).range(e),i=c[t];s.forEach(function(e,n){var d=l+" table [data-axel-rowkey='"+n+"'][data-axel-column='"+i+"']",s=r(e[t]),c=o(s),u=$(d);a?u.css("color",s):u.css({background:s,color:c})})}function n(t,e,a,n,r){var i=c[t],d=o(n);s.forEach(function(o,s){var c=l+" table [data-axel-rowkey='"+s+"'][data-axel-column='"+i+"']",u=$(c);"above"==e&&o[t]>=a?r?u.css("color",n):u.css({background:n,color:d}):"below"==e&&o[t]<=a?r?u.css("color",n):u.css({background:n,color:d}):"equal"==e&&o[t]==a&&(r?u.css("color",n):u.css({background:n,color:d}))})}function r(t){var e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null}function o(e){var a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e);return a?(rgb=r(e),t=Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):t=255,t>125?"#2B2B2B":"#FCFCFC"}var l="#"+t.table_id,i=t.query_name,d=t.column_rules,s=alamode.getDataFromQuery(i),c=(alamode.getColumnsFromQuery(i),{}),u=$(l+" table"),m=$(l+" .js-header-table"),h=m.find("th"),p=(u.find("tr"),0);h.each(function(){text=$(this).find(".axel-table-header-label").text(),p=$(this).attr("data-axel-column"),c[text]=p}),setTimeout(function(){e(d)},1e3),$(l).mousemove(function(){e(d)})},conditionalFormattingByTable:function(t){function e(t){t.forEach(function(t){var e=t.shade_text||!1;"gradient"==t.type?a(t.color,e):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||n(t.type,t.value,t.color,e)})}function a(t,e){var a=d3.scale.linear().domain(g).interpolate(d3.interpolateHsl).range(t);s.forEach(function(t,n){d.forEach(function(r){var i=c[r],d=l+" table [data-axel-rowkey='"+n+"'][data-axel-column='"+i+"']",s=a(t[r]),u=o(s),m=$(d);e?m.css("color",s):m.css({background:s,color:u})})})}function n(t,e,a,n){var r=o(a);s.forEach(function(o,i){d.forEach(function(d){var s=c[d],u=l+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+s+"']",m=$(u);"above"==t&&o[d]>=e?n?m.css("color",a):m.css({background:a,color:r}):"below"==t&&o[d]<=e?n?m.css("color",a):m.css({background:a,color:r}):"equal"==t&&o[d]==e&&(n?m.css("color",a):m.css({background:a,color:r}))})})}function r(t){var e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null}function o(e){var a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e);return a?(rgb=r(e),t=Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):t=255,t>125?"#2B2B2B":"#FCFCFC"}var l="#"+t.table_id,i=t.query_name,d=t.columns;rules=t.rules;var s=alamode.getDataFromQuery(i),c=(alamode.getColumnsFromQuery(i),{}),u=$(l+" table"),m=$(l+" .js-header-table"),h=m.find("th"),p=(u.find("tr"),0);h.each(function(){text=$(this).find(".axel-table-header-label").text(),p=$(this).attr("data-axel-column"),c[text]=p});var f=[];d.forEach(function(t){var e=d3.extent(_.map(s,t));f=f.concat(e)});var g=d3.extent(f);setTimeout(function(){e(rules)},1e3),$(l).mousemove(function(){e(rules)})},addTableOfContents:function(t){var e=t.text_color,a=t.background_color,n=t.hover_color;$(".mode-header").addClass("has-nav");var r=$("

");$(".row").each(function(){var t=$(this).children();t.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).getElementsByClassName("chart-title")[0].innerText:e.includes("python")&&(t=document.getElementById(e).getElementsByClassName("in-place-edit-text")[0].innerText);var a=$(""+(t.includes("Click to add title")?"Untitled":t)+"");r.append(a)})});var o=$("
");$(".mode-content").prepend(o);var l=$("
");o.prepend(l);var i=$("
");l.prepend(i),i.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(){function t(t,e){var a=50,n=$(t).offset().top-a;$("html,body").animate({scrollTop:n},e)}$(".scroll-link").on("click",function(e){e.preventDefault();var a=$(this).attr("href");t(a,750)})},100)},addLinksToBarCharts:function(t){var e=alamode.getDataFromQuery(queryName),a=t.bar_chart_id,n=t.link_column,r=t.link_urls,o=r.length,l=0,d=[],s=e.length;setTimeout(function(){var t=document.getElementById(a);for(d3.select(t).selectAll(".nv-groups rect").attr("id",function(t,e){return l++,e}),i=0;i=s?this.id%s:this.id;for(var a=e[t][n];d[this.id].indexOf("{{")!=-1;){var r=d[this.id].length,o=d[this.id].indexOf("{{"),l=d[this.id].substring(o+2,r).indexOf("}}"),i=(d[this.id].substring(o+2,o+l+2),d[this.id].substring(o,o+l+4)),c=a;d[this.id]=d[this.id].replace(i,c)}var u=document.createElement("a");u.href=d[this.id],$(this).append(u),u.click()})},100)}}; \ No newline at end of file