diff --git a/alamode.css b/alamode.css index 5ef38d2..681ede4 100644 --- a/alamode.css +++ b/alamode.css @@ -154,6 +154,18 @@ h1.mode-error { fill: none; } +.mode-zipcode-chorolpleth-legend{ + text-align: center; + font-size: 12px; + line-height: 24px; + height: 24px; +} + +.mode-zipcode-chorolpleth-zipcodes:hover { + fill: red; +} + + /*County choropleth*/ .mode-county-chorolpleth{ text-align: center; @@ -180,6 +192,30 @@ h1.mode-error { stroke-linejoin: round; } +.mode-state-chorolpleth-legend{ + text-align: center; + font-size: 12px; + line-height: 24px; + height: 24px; +} + +.mode-state-chorolpleth-states-base { + fill: #C3CBCB; +} + +.mode-state-chorolpleth-states:hover { + fill: red; +} + +.mode-state-chorolpleth-tooltip { + line-height: 1; + font-weight: normal; + padding: 12px; + background: rgba(0, 0, 0, 0.8); + color: #fff; + border-radius: 2px; +} + /*World choropleth*/ .mode-world-chorolpleth { text-align: center; diff --git a/alamode.js b/alamode.js index 51cd0f6..c37afa2 100644 --- a/alamode.js +++ b/alamode.js @@ -1581,7 +1581,9 @@ var alamode = { d3.select(uniqContainerClass) .append("div") .attr("class","mode-graphic-title") - .text(title) + .attr("class","mode-zipcode-chorolpleth-legend") + .attr("id","mode-zipcode-chorolpleth-legend-" + id) + .text("Hover over a Zipcode area to see details") svg = d3.select(uniqContainerClass) .append("div") @@ -1619,13 +1621,23 @@ var alamode = { .enter().append("path") .attr("class","mode-zipcode-chorolpleth-zipcodes-" + id) .attr("fill", function(d) { return quantize(rateById.get(d.properties.zip)); }) - .attr("d", path); + .attr("d", path) + .on("mouseover",function(d) { + d3.select(this).attr("class", "mode-zipcode-chorolpleth-zipcodes") + var zipcode = d.properties.zip; - // d3.select("#mode-county-chorolpleth-" + id) - // .append("path") - // .datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; })) - // .attr("class", "mode-county-chorolpleth-states") - // .attr("d", path); + if (rateById.get(d.properties.zip)) { + value = rateById.get(d.properties.zip); + } else { + value = "--" + } + + d3.select("#mode-zipcode-chorolpleth-legend-" + id).text(zipcode + ": " + value) + }) + .on("mouseout",function(d) { + d3.select(this).classed("mode-zipcode-chorolpleth-zipcodes", false); + d3.select("#mode-zipcode-chorolpleth-legend-" + id).text("Hover over a state to see details") + }) } }, @@ -1742,7 +1754,9 @@ var alamode = { d3.select(uniqContainerClass) .append("div") .attr("class","mode-graphic-title") - .text(title) + .attr("class","mode-state-chorolpleth-legend") + .attr("id","mode-state-chorolpleth-legend-" + id) + .text("Hover over a State to see details") svg = d3.select(uniqContainerClass) .append("div") @@ -1774,13 +1788,29 @@ var alamode = { d3.select("#mode-state-chorolpleth-" + id) .append("g") - .attr("class","mode-state-chorolpleth-states") + .attr("class","mode-state-chorolpleth-states-base") .selectAll(".mode-state-chorolpleth-states-" + id) .data(us.features) .enter().append("path") .attr("class","mode-state-chorolpleth-states-" + id) .attr("fill", function(d) { return quantize(rateById.get(d.properties[code]))}) - .attr("d", path); + .attr("d", path) + .on("mouseover",function(d) { + d3.select(this).attr("class", "mode-state-chorolpleth-states") + var state = d.properties.name; + + if (rateById.get(d.properties[code])) { + value = rateById.get(d.properties[code]); + } else { + value = "--" + } + + d3.select("#mode-state-chorolpleth-legend-" + id).text(state + ": " + value) + }) + .on("mouseout",function(d) { + d3.select(this).classed("mode-state-chorolpleth-states", false); + d3.select("#mode-state-chorolpleth-legend-" + id).text("Hover over a state to see details") + }) } }, diff --git a/alamode.min.css b/alamode.min.css index e52eb94..0c636ec 100644 --- a/alamode.min.css +++ b/alamode.min.css @@ -1 +1 @@ -.mode-graphic-container{border:1px solid #f2f3f3;max-width:1162px;margin:15px auto;overflow:scroll}.mode-graphic-title{font-size:14px;line-height:48px;height:48px;padding-left:16px;font-weight:500}h1.mode-error{padding:.2em 2em;background:#da364a;color:#fcfcfc;font-size:20px;font-weight:500}.mode-retention-heatmap-pivot-label{font-size:12px;text-align:center;margin:10px}.mode-retention-heatmap-table{table-layout:fixed;border-collapse:separate;font-size:10px;border-spacing:1px;margin:5px auto 10px}.mode-retention-heatmap-table-header-cell{overflow:hidden;font-size:12px;padding:4px;color:#fff;background:gray}.heatmap-string{text-align:left}.heatmap-number{text-align:center}.mode-retention-heatmap-table td{overflow:hidden;padding:6px 6px 4px}.mode-retention-heatmap-label{text-align:center;color:#8d9d9f}.mode-google-map{height:100%;width:100%;max-width:1162px;position:absolute}.mode-leaflet-map{width:95%;max-width:1162px}.mode-wordcloud{text-align:center}.mode-funnel{margin:0 auto}.mode-bullet-chart,.mode-funnel,.mode-sunburst,.mode-sunburst-sequence{text-align:center}.mode-sunburst path{stroke:#fff}.mode-sunburst-legend-container{display:block;margin:0 auto;text-align:center;max-width:600px}.mode-sunburst-legend-container text,.mode-sunburst-sequence text{fill:#fff}.mode-sunburst-legend{position:relative;vertical-align:middle;display:inline-block;margin-left:5px;margin-top:5px;width:195px;padding:5px}.mode-sunburst-explanation{margin:0 auto;fill:#666;padding:10px}.mode-sunburst-percentage{font-size:2.5em;color:#666}.mode-sunburst-cond-percentage{font-size:1.8em;color:#666}.mode-zipcode-chorolpleth{text-align:center}.zipcodes{fill:none}.mode-county-chorolpleth{text-align:center}.mode-county-chorolpleth-counties{fill:#666}.mode-county-chorolpleth-states{fill:none;stroke:#fff;stroke-linejoin:round}.mode-state-chorolpleth{text-align:center}.mode-state-chorolpleth-states{fill:#666;stroke:#fff;stroke-linejoin:round}.mode-world-chorolpleth{text-align:center}.mode-world-chorolpleth-legend{text-align:center;font-size:12px;line-height:24px;height:24px}.mode-world-chorolpleth-countries-base{fill:#c3cbcb}.mode-network-matrix-column-text.active,.mode-network-matrix-row-text.active,.mode-world-chorolpleth-countries:hover{fill:red}.mode-world-chorolpleth-boundaries{fill:none;stroke:#fff;stroke-linejoin:round}.mode-world-chorolpleth-tooltip{line-height:1;font-weight:400;padding:12px;background:rgba(0,0,0,.8);color:#fff;border-radius:2px}.mode-pivot-table{padding:10px}.mode-force-directed-graph{text-align:center;margin:0 auto}.mode-force-directed-graph-node{stroke:#394242;stroke-width:1px}.mode-force-directed-graph-link{fill:none;stroke:#a4a5a9}.mode-force-directed-graph-tooltip,.mode-hive-tooltip,.mode-network-matrix-tooltip{line-height:1;font-weight:400;padding:12px;background:rgba(0,0,0,.8);color:#fff;border-radius:2px}.mode-network-matrix{text-align:center;margin:0 auto}.mode-network-matrix-background{fill:#eee}.mode-network-matrix-line{stroke:#fff}.mode-network-matrix-order-picker{text-align:left;padding-left:16px}.mode-hive-link{fill:none;stroke-width:1px;stroke-opacity:.4}.mode-hive-link-selected{fill:none;stroke-width:3px;stroke-opacity:.6}.mode-hive-axis,.mode-hive-node{stroke:#394242;stroke-width:1px}.mode-hive-axis{stroke-opacity:.2}.mode-hive-node-selected{stroke-width:3px}.fixed-nav-bar{position:fixed;top:4px;z-index:9999;background-color:#fff;padding:0;box-shadow:0 2px 2px rgba(0,0,0,.1);border-radius:3px;font-size:0}.fixed-nav-bar a{padding:6px 10px;display:inline-block;font-weight:500;font-size:13px;color:#4e4d4d;border-right:1px solid rgba(0,0,0,.05)}.fixed-nav-bar a:hover{color:#f27802;text-decoration:none}.fixed-nav-bar a:last-child{border-radius:0 3px 3px 0;border-right:none}.fixed-nav-bar a:first-child{border-radius:3px 0 0 3px}.has-nav{padding-top:3em} +.mode-graphic-container{border:1px solid #f2f3f3;max-width:1162px;margin:15px auto;overflow:scroll}.mode-graphic-title{font-size:14px;line-height:48px;height:48px;padding-left:16px;font-weight:500}h1.mode-error{padding:.2em 2em;background:#da364a;color:#fcfcfc;font-size:20px;font-weight:500}.mode-retention-heatmap-pivot-label{font-size:12px;text-align:center;margin:10px}.mode-retention-heatmap-table{table-layout:fixed;border-collapse:separate;font-size:10px;border-spacing:1px;margin:5px auto 10px}.mode-retention-heatmap-table-header-cell{overflow:hidden;font-size:12px;padding:4px;color:#fff;background:gray}.heatmap-string{text-align:left}.heatmap-number{text-align:center}.mode-retention-heatmap-table td{overflow:hidden;padding:6px 6px 4px}.mode-retention-heatmap-label{text-align:center;color:#8d9d9f}.mode-google-map{height:100%;width:100%;max-width:1162px;position:absolute}.mode-leaflet-map{width:95%;max-width:1162px}.mode-wordcloud{text-align:center}.mode-funnel{margin:0 auto}.mode-bullet-chart,.mode-funnel,.mode-sunburst,.mode-sunburst-sequence{text-align:center}.mode-sunburst path{stroke:#fff}.mode-sunburst-legend-container{display:block;margin:0 auto;text-align:center;max-width:600px}.mode-sunburst-legend-container text,.mode-sunburst-sequence text{fill:#fff}.mode-sunburst-legend{position:relative;vertical-align:middle;display:inline-block;margin-left:5px;margin-top:5px;width:195px;padding:5px}.mode-sunburst-explanation{margin:0 auto;fill:#666;padding:10px}.mode-sunburst-percentage{font-size:2.5em;color:#666}.mode-sunburst-cond-percentage{font-size:1.8em;color:#666}.mode-zipcode-chorolpleth{text-align:center}.zipcodes{fill:none}.mode-zipcode-chorolpleth-legend{text-align:center;font-size:12px;line-height:24px;height:24px}.mode-network-matrix-column-text.active,.mode-network-matrix-row-text.active,.mode-state-chorolpleth-states:hover,.mode-world-chorolpleth-countries:hover,.mode-zipcode-chorolpleth-zipcodes:hover{fill:red}.mode-county-chorolpleth{text-align:center}.mode-county-chorolpleth-counties{fill:#666}.mode-county-chorolpleth-states{fill:none;stroke:#fff;stroke-linejoin:round}.mode-state-chorolpleth{text-align:center}.mode-state-chorolpleth-states{fill:#666;stroke:#fff;stroke-linejoin:round}.mode-state-chorolpleth-legend{text-align:center;font-size:12px;line-height:24px;height:24px}.mode-state-chorolpleth-states-base{fill:#c3cbcb}.mode-state-chorolpleth-tooltip{line-height:1;font-weight:400;padding:12px;background:rgba(0,0,0,.8);color:#fff;border-radius:2px}.mode-world-chorolpleth{text-align:center}.mode-world-chorolpleth-legend{text-align:center;font-size:12px;line-height:24px;height:24px}.mode-world-chorolpleth-countries-base{fill:#c3cbcb}.mode-world-chorolpleth-boundaries{fill:none;stroke:#fff;stroke-linejoin:round}.mode-world-chorolpleth-tooltip{line-height:1;font-weight:400;padding:12px;background:rgba(0,0,0,.8);color:#fff;border-radius:2px}.mode-pivot-table{padding:10px}.mode-force-directed-graph{text-align:center;margin:0 auto}.mode-force-directed-graph-node{stroke:#394242;stroke-width:1px}.mode-force-directed-graph-link{fill:none;stroke:#a4a5a9}.mode-force-directed-graph-tooltip,.mode-hive-tooltip,.mode-network-matrix-tooltip{line-height:1;font-weight:400;padding:12px;background:rgba(0,0,0,.8);color:#fff;border-radius:2px}.mode-network-matrix{text-align:center;margin:0 auto}.mode-network-matrix-background{fill:#eee}.mode-network-matrix-line{stroke:#fff}.mode-network-matrix-order-picker{text-align:left;padding-left:16px}.mode-hive-link{fill:none;stroke-width:1px;stroke-opacity:.4}.mode-hive-link-selected{fill:none;stroke-width:3px;stroke-opacity:.6}.mode-hive-axis,.mode-hive-node{stroke:#394242;stroke-width:1px}.mode-hive-axis{stroke-opacity:.2}.mode-hive-node-selected{stroke-width:3px}.fixed-nav-bar{position:fixed;top:4px;z-index:9999;background-color:#fff;padding:0;box-shadow:0 2px 2px rgba(0,0,0,.1);border-radius:3px;font-size:0}.fixed-nav-bar a{padding:6px 10px;display:inline-block;font-weight:500;font-size:13px;color:#4e4d4d;border-right:1px solid rgba(0,0,0,.05)}.fixed-nav-bar a:hover{color:#f27802;text-decoration:none}.fixed-nav-bar a:last-child{border-radius:0 3px 3px 0;border-right:none}.fixed-nav-bar a:first-child{border-radius:3px 0 0 3px}.has-nav{padding-top:3em} \ No newline at end of file diff --git a/alamode.min.js b/alamode.min.js index 95fbf80..8395889 100644 --- a/alamode.min.js +++ b/alamode.min.js @@ -1 +1 @@ -var version="0.15",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?$(a+" .js-col-header"):$(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<=s.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;-1!=url.indexOf("{{");){var o=url.length,l=url.indexOf("{{"),d=url.substring(l+2,o).indexOf("}}"),c=url.substring(l+2,l+d+2),u=url.substring(l,l+d+4),m=(i[c],s[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 s=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(".nv-bar").length>0?a.find(".nv-group"):a.find(".nv-line").length>0||a.find(".nv-areaWrap").length>0?a.find(".nv-noninteractive"):a.find(".nv-pie .nv-slice")).length,r=a.find(".nv-series .nv-legend-symbol"),o={},l={},s={},d=0;if(0==r.length&&n<=1)l[0]=d,s[d]=0,o[0]=e[0];else if(0==r.length&&n>1)for(i=0;i0&&u>0){var e=n.find(".nv-linePlusBar .nv-linesWrap .nv-groups .nv-series-0").css("fill"),a=n.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)}else u>0?1==d&&$(this).find("div").css({"background-color":l[i[d-t-1]]}):c>0?$(this).find("div").css({"background-color":l[c-t-1]}):$(this).find("div").css({"background-color":l[t]})});var h=n.find(".nv-pie .nv-slice.hover").css("fill");$("html").find(".nvtooltip table .legend-color-guide div").css("background-color",h)}),$(n).mouseleave(function(){$("html").find(".nvtooltip table .legend-color-guide").remove()})}var r=t.charts,o=t.colors,l=t.opacity,s=t.line_dashes;"all"==r&&(r=[],$("mode-chart").each(function(){r.push(this.id)})),setInterval(function(){r.forEach(function(t){a(t,o)})},500),r.forEach(function(t){n(t,o)})},addTotalsRow:function(t){function e(t){var e="TTL";return t.forEach(function(t){""!=t.total?e=e+""+s(t.total)+"":e+=""}),e+""}var a=t.query_name,n="#"+(t.table_id||""),r=alamode.getColumnsFromQuery(a),o=alamode.getDataFromQuery(a),l=t.columns_with_totals,s=d3.format(","),d=function(t){var e=[],a={idx:i,name:"",total:""};return r.forEach(function(n,r){if(-1==t.indexOf(n.name))s=a;else var l=_.map(o,n.name),i=d3.sum(l),s={idx:r,name:n.name,total:i};e.push(s)}),e}(function(t){return numberColumns=_.map(_.filter(r,function(t){return-1!=["number","integer"].indexOf(t.type)}),"name"),"all"==t?numberColumns:_.intersection(t,numberColumns)}(l));setTimeout(function(){table="#"==n?$(".main-table"):$(n+" .main-table");var t=table.find("tr:last"),a=e(d);t.after(a)},1e3)},addImagesToTables:function(t){function e(){var t=$(a+" table"),e=$(a+" .js-header-table"),o=e?$(a+" .js-col-header"):$(e).find("th"),l=t.find("tr"),i=0;o.each(function(){text=$(this).find(".axel-table-header-label").text(),text==n&&(i=+$(this).attr("data-axel-column"))}),l.each(function(){$(this).find("td").each(function(t){if(t==i-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!=s&&t.column!=u&&t.column==d)}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[s]==n});r.length>0?entry=d3.mean(_.map(r,d)):entry="",a=a.concat({column:d,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==d&&p?r(t.value):t.column==d?a(t.value):t.value}var l=t.query_name,i=t.cohort_column,s=t.pivot_column,d=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,f=t.pivot_label||"",p=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,s)),w=alamode.addContainerElement(m),k=d3.scale.quantize().domain(d3.extent(v,function(t){return t[d]})).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(f),headers=u?[i,u].concat(b):[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(t){return o(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,s=t.html_element||"body",d=t.center_lat||39.5,c=t.center_lng||-98.35,u=t.starting_zoom||4,m=t.map_type||"terrain",h=t.height||600,f=alamode.getDataFromQuery(r),p=alamode.addContainerElement(s);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).style("height",h+"px"),jQuery.getScript("https://maps.googleapis.com/maps/api/js?key="+o,function(){!function(){var t={zoom:u,center:new google.maps.LatLng(d,c),mapTypeId:m},r=new google.maps.Map(document.getElementById(e),t);f.forEach(function(t){var e=t[a],o=t[n];label=i?t[i]:"";var l=new google.maps.Marker({position:{lat:e,lng:o},map:r,title:label}),s=new google.maps.InfoWindow({content:label});l.addListener("click",function(){s.open(r,l)})})}()})},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",s=t.center_lat||39.5,d=t.center_lng||-98.35,c=t.starting_zoom||4,u=t.dot_size||.4,m=t.dot_opacity||.8,h=[];alamode.getDataFromQuery(r).forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&h.push(t)});var f=alamode.addContainerElement(i);d3.select(f).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o);var p=l-$(f+".mode-graphic-title").height(),g=$(f).width();d3.select(f).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",p+"px").style("width",g+"px");var v=L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18}),y={max:8,data:h},x={radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n},b={lat:s,lng:d,zoom:c},_=new HeatmapOverlay(x);new L.Map(e,{center:new L.LatLng(b.lat,b.lng),zoom:Math.floor(b.zoom),layers:[v,_]});_.setData(y)},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",s=t.colors||["black"],d=alamode.getDataFromQuery(e),c=alamode.addContainerElement(r);d3.select(c).append("div").attr("class","mode-graphic-title").text(o);var u=d3.scale.linear().domain(d3.extent(d,function(t){return t[n]})).range([12,60]),m=d3.layout.cloud().size([i,l]).words(d.map(function(t){return{text:t[a],size:u(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(c).append("div").attr("class","mode-wordcloud").append("svg").attr("width",m.size()[0]).attr("height",m.size()[1]).append("g").attr("transform","translate("+m.size()[0]/2+","+m.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})});m.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",s=t.width||"500",d=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",s+"px").style("height",i-20+"px");var u=[];d.forEach(function(t){u.push([t[n],t[r]])});var m={label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100};new D3Funnel("#"+e).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(){s.forEach(function(t,e){var n=c[e],r=o[e],i=l[e],s=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),d=$(a).find("g.nvd3.nv-wrap").attr("transform"),u=d.indexOf("("),m=d.indexOf(")"),h=d.indexOf(","),f=+d.slice(u+1,h),p=+d.slice(h+1,m);if(-1!=n&&"v"==r){var g=$(a).find(".nv-point.nv-point-"+n).attr("transform"),v=g.indexOf("("),x=g.indexOf(")"),b=g.indexOf(","),_=+g.slice(v+1,b),w=+g.slice(b+1,x);$(a).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(a).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width");(C=d3.select(a+" .nvd3svg")).call(s),C.append("rect").attr("x",_+f).attr("y",p-5).attr("width",1).attr("class","flag").attr("height",w+5).attr("fill","#ff8f53"),C.append("circle").data([t]).attr("cx",_+f).attr("cy",p-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",s.show).on("mouseout",s.hide)}else if("h"==r||"h-left"==r||"h-right"==r){y="h"==r?"":"1",$(a).find("g.nv-y"+y+".nv-axis").find(".tick").each(function(t){lineLength="h-right"==r?+$(a).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(",",""))});var k=(yTrans2-yTrans1)/(yVal2-yVal1),E=yTrans2-yVal2*k+i*k,C=d3.select(a+" .nvd3svg");C.call(s),C.append("rect").attr("x",f).attr("y",E+p).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),C.append("circle").data([t]).attr("cx",lineLength+f+10).attr("cy",E+p).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",s.show).on("mouseout",s.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,s=t.comments,d=alamode.getDataFromQuery(r),c=[],u={};i&&(u=_.groupBy(d,function(t){return t[i]})),s.forEach(function(t,e){var a=_.filter(d,function(t){return t[n]==l[e]});0!=a.length?pointNumber=i?u[a[0][i]].indexOf(a[0]):d.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||"",s=t.left_pad||150,d=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),d.forEach(function(a){var n=a[t.title_column]||"",r=a[t.subtitle_column]||"",d=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:[d],markerLabels:[i]};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(o).margin({left:s,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){var e=(100*t.value/k).toPrecision(3),a=e+"%";e<.1&&(a="< 0.1%");var r=n(t),o=t.parent.value,i=(100*t.value/o).toPrecision(3),s=i+"%";i<1&&(a="< 1%"),d3.select("#cond-percentage-"+d).text(s),d3.select("#percentage-"+d).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility",""),l(r=n(t),a),d3.selectAll("path").style("opacity",.3),vis.selectAll("path").filter(function(t){return r.indexOf(t)>=0}).style("opacity",1)}function a(t){d3.select("#trail-"+d).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",e)}):d3.selectAll("path").transition().duration(300).style("opacity",1).each("end",function(){d3.select(this).on("mouseover",e)}),d3.selectAll(".mode-sunburst-explanation").style("visibility","hidden")}function n(t){for(var e=[],a=t;a.parent;)e.unshift(a),a=a.parent;return e}function r(){d3.select("#sequence-"+d).append("svg:svg").attr("width",v).attr("height",60).attr("id","trail-"+d).append("svg:text").attr("id","endlabel").style("fill","#000")}function o(t,e){var a=[];return a.push("0,0"),a.push(x.w+",0"),a.push(x.w+x.t+","+x.h/2),a.push(x.w+","+x.h),a.push("0,"+x.h),e>0&&a.push(x.t+","+x.h/2),a.join(" ")}function l(t,e){var a=d3.select("#trail-"+d).selectAll("g").data(t,function(t){return t.name+t.depth}),n=a.enter().append("svg:g");n.append("svg:polygon").attr("points",o).style("fill",function(t){return w[t.name]}),n.append("svg:text").attr("x",(x.w+x.t)/2).attr("y",x.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),a.attr("transform",function(t,e){return e>5&&e<10?"translate("+(e-=5)*(x.w+x.s)+", 20)":e>10?"translate("+(e-=11)*(x.w+x.s)+", 40)":"translate("+e*(x.w+x.s)+", 0)"}),a.exit().remove(),d3.select("#trail-"+d).style("visibility","")}function s(){var t={w:195,h:30,s:3,r:3};d3.entries(w).forEach(function(e){divContainer=d3.select("#legend-container-"+d).append("div").attr("class","mode-sunburst-legend").attr("id","legend-"+d),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})})}var d=alamode.makeId(10),c=t.query_name,u=t.event_columns,m=t.event_counts,h=t.title||c,f=t.color_range||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],p=t.html_element||"body",g=alamode.getDataFromQuery(c),v=850,y=Math.min(v,600)/2,x={w:(v-30)/u.length,h:20,s:3,t:10},b=[];u.forEach(function(t){b=b.concat(_.uniq(_.map(g,t)))});var w={};_.uniq(b).forEach(function(t,e){null!=t&&(w[t]=f[e%f.length])}),w.end="#666";var k=0,$=alamode.addContainerElement(p);d3.select($).append("div").attr("class","mode-graphic-title").text(h),d3.select($).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+d),d3.select($).append("div").attr("class","mode-sunburst").attr("id",d),d3.select($).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+d),vis=d3.select("#"+d).append("svg:svg").attr("width",v).attr("height",600).append("svg:g").attr("transform","translate("+v/2+",300)"),vis.append("text").attr("x",0).attr("y",-30).attr("text-anchor","middle").attr("class","mode-sunburst-explanation mode-sunburst-percentage").attr("id","percentage-"+d).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-"+d).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.");var E=d3.layout.partition().size([2*Math.PI,y*y]).value(function(t){return t.size}),C=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)}),z=[];g.forEach(function(t){var e="";for(i=0;i.005}),o=vis.data([t]).selectAll("path").data(n).enter().append("svg:path").attr("display",function(t){return t.depth?null:"none"}).attr("d",C).attr("fill-rule","evenodd").style("fill",function(t){return w[t.name]}).style("opacity",1).on("mouseover",e);vis.on("mouseleave",a),k=o.node().__data__.value}(function(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",s=t.group_colors||"",d=t.links_to_show||100,c=alamode.getDataFromQuery(a),u=[];alamode.getDataFromQuery(n).forEach(function(t){var e=u.filter(function(e){return e.target==t.source}).filter(function(e){return e.source==t.target});0!=e.length?e.edge_size+=t.edge_size:u.push(t)}),u=u.sort(function(t,e){return e.edge_size-t.edge_size}),u=u.slice(0,d),nameMap={},c.forEach(function(t,e){t.id=e,nameMap[t.node]=e}),u.forEach(function(t){t.source_id=nameMap[t.source],t.target_id=nameMap[t.target]});var m=alamode.addContainerElement(r);d3.select(m).append("div").attr("class","mode-graphic-title").text(o),d3.select(m).append("div").attr("class","mode-force-directed-graph").style("width",l).attr("id",e);var h=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]),p=d3.select("#"+e).append("svg").attr("width",l).attr("height",i);p.call(h);var g={nodes:c,links:u},v=d3.scale.linear().domain(d3.extent(c,function(t){return t.node_size})).range([2,20]),y=d3.scale.linear().domain(d3.extent(u,function(t){return t.edge_size})).range([1,10]),x=d3.scale.linear().domain(d3.extent(u,function(t){return t.edge_size})).range([.1,.9]),c=g.nodes.slice(),u=[],b=[];g.links.forEach(function(t){var e=c[t.source_id],a=c[t.target_id],n={};n.connections=t.edge_size,c.push(n),u.push({source:e,target:n},{source:n,target:a}),b.push([e,n,a])}),f.nodes(c).links(u).start();var _=p.selectAll(".mode-force-directed-graph-link ").data(b).enter().append("path").attr("class","mode-force-directed-graph-link").style("stroke-width",function(t){return y(t[1].connections)}).style("opacity",function(t){return x(t[1].connections)}),w=p.selectAll(".mode-force-directed-graph-node").data(g.nodes).enter().append("g").attr("class","mode-force-directed-graph-node").call(f.drag);w.append("circle").attr("r",function(t){return v(t.node_size)}).style("fill",function(t){return s?s[t.node_group]:"#0E819A"}).on("mouseover",h.show).on("mouseout",h.hide),f.on("tick",function(){_.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}),w.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 b(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(),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,s=t.html_element||"body",d=t.title||queryName,c=t.padding_for_names||"200",u=t.chart_width||"800",m=t.chart_height||"800",h=t.group_colors||"",f=t.left_label||"",p=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]),b=d3.scale.linear().domain(d3.extent(y,function(t){return t.edge_size})).clamp(!0),_=alamode.addContainerElement(s);d3.select(_).append("div").attr("class","mode-graphic-title").text(d),d3.select(_).append("div").attr("class","mode-network-matrix-order-picker").html('

Order: '),d3.select(_).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=[],C=(v=graph.nodes).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){void 0!==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(p),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(f),$.append("rect").attr("class","mode-network-matrix-background").attr("width",u).attr("height",m),(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)).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 s=l.a+(i.a-l.a)/3,d=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(s)*l.r1+","+Math.sin(s)*l.r1+" "+Math.cos(d)*i.r1+","+Math.sin(d)*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(d)*i.r0+","+Math.sin(d)*i.r0+" "+Math.cos(s)*l.r0+","+Math.sin(s)*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(s)*l.r1+","+Math.sin(s)*l.r1+" "+Math.cos(d)*i.r1+","+Math.sin(d)*i.r1+" "+Math.cos(i.a)*i.r1+","+Math.sin(i.a)*i.r1}function e(t,e,a,n){var s=t.call(e,a,n),d=+("function"==typeof r?r.call(e,s,n):r)+i,c=+("function"==typeof o?o.call(e,s,n):o);return{r0:c,r1:o===l?c:+("function"==typeof l?l.call(e,s,n):l),a:d}}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,s=t.chart_width||"800",d=t.chart_height||"800",c=t.group_colors||"",u=Math.min(s,d)/2-30,m=.2*u,h=alamode.getDataFromQuery(n),f=alamode.getDataFromQuery(r),p=_.uniq(_.map(h,"node_group")),g={};h.forEach(function(t){t.x=o?t.node_group:p.indexOf(t.node_group),t.y=t.node_size,g[t.node]=t}),f.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",s).attr("id",a),angle=o?d3.scale.linear().domain(d3.extent(h,function(t){return t.node_group})).range([0,2*Math.PI]):d3.scale.ordinal().domain(d3.range(p.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",s).attr("height",d).append("g").attr("transform","translate("+s/2+","+d/2+")");b.call(x),b.selectAll(".mode-hive-axis").data(d3.range(p.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(f).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(f).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){var e=$(l+" table"),r=$(l+" .js-header-table"),o=r?$(l+" .js-col-header"):$(r).find("th"),i=(e.find("tr"),0);o.each(function(){text=$(this).find(".axel-table-header-label").text(),i=$(this).attr("data-axel-column"),c[text]=i}),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(d,t)),r=d3.scale.linear().domain(n).interpolate(d3.interpolateHsl).range(e),i=c[t];d.forEach(function(e,n){var s=l+" table [data-axel-rowkey='"+n+"'][data-axel-column='"+i+"']",d=r(e[t]),c=o(d),u=$(s);a?u.css("color",d):u.css({background:d,color:c})})}function n(t,e,a,n,r){var i=c[t],s=o(n);d.forEach(function(o,d){var c=l+" table [data-axel-rowkey='"+d+"'][data-axel-column='"+i+"']",u=$(c);"above"==e&&o[t]>=a?r?u.css("color",n):u.css({background:n,color:s}):"below"==e&&o[t]<=a?r?u.css("color",n):u.css({background:n,color:s}):"equal"==e&&o[t]==a&&(r?u.css("color",n):u.css({background:n,color:s}))})}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){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e)?(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,s=t.column_rules,d=alamode.getDataFromQuery(i),c=(alamode.getColumnsFromQuery(i),{});setTimeout(function(){e(s)},1e3),$(l).mousemove(function(){e(s)})},conditionalFormattingByTable:function(t){function e(t){var e=$(l+" table"),r=$(l+" .js-header-table"),o=r?$(l+" .js-col-header"):$(r).find("th"),i=(e.find("tr"),0);o.each(function(){text=$(this).find(".axel-table-header-label").text(),i=$(this).attr("data-axel-column"),c[text]=i}),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(m).interpolate(d3.interpolateHsl).range(t);d.forEach(function(t,n){s.forEach(function(r){var i=c[r],s=l+" table [data-axel-rowkey='"+n+"'][data-axel-column='"+i+"']",d=a(t[r]),u=o(d),m=$(s);e?m.css("color",d):m.css({background:d,color:u})})})}function n(t,e,a,n){var r=o(a);d.forEach(function(o,i){s.forEach(function(s){var d=c[s],u=l+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+d+"']",m=$(u);"above"==t&&o[s]>=e?n?m.css("color",a):m.css({background:a,color:r}):"below"==t&&o[s]<=e?n?m.css("color",a):m.css({background:a,color:r}):"equal"==t&&o[s]==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){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e)?(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,s=t.columns;rules=t.rules;var d=alamode.getDataFromQuery(i),c=(alamode.getColumnsFromQuery(i),{}),u=[];s.forEach(function(t){var e=d3.extent(_.map(d,t));u=u.concat(e)});var m=d3.extent(u);setTimeout(function(){e(rules)},1e3),$(l).mousemove(function(){e(rules)})},addTableOfContents:function(t){void 0===t&&(t="default");var e=t.text_color,a=t.background_color,n=t.hover_color;$(".mode-header").addClass("has-nav");var r=$("

");$(".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;if(e.includes("chart")||e.includes("table")){var a=document.getElementById(e);t=$(a).find("mode-pivot-table").length>0?document.getElementById(e).getElementsByClassName("in-place-edit-text")[0].innerText:document.getElementById(e).getElementsByClassName("chart-title")[0].innerText}else e.includes("python")&&(t=document.getElementById(e).getElementsByClassName("in-place-edit-text")[0].innerText);var n=$(""+(t.includes("Click to add title")?"Untitled":t)+"");r.append(n)})});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=$(t).offset().top-50;$("html,body").animate({scrollTop:a},e)}$(".scroll-link").on("click",function(e){e.preventDefault(),t($(this).attr("href"),750)})},100)}}; \ No newline at end of file +var version="0.15",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?$(a+" .js-col-header"):$(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<=s.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;-1!=url.indexOf("{{");){var o=url.length,l=url.indexOf("{{"),d=url.substring(l+2,o).indexOf("}}"),c=url.substring(l+2,l+d+2),u=url.substring(l,l+d+4),m=(i[c],s[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 s=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(".nv-bar").length>0?a.find(".nv-group"):a.find(".nv-line").length>0||a.find(".nv-areaWrap").length>0?a.find(".nv-noninteractive"):a.find(".nv-pie .nv-slice")).length,r=a.find(".nv-series .nv-legend-symbol"),o={},l={},s={},d=0;if(0==r.length&&n<=1)l[0]=d,s[d]=0,o[0]=e[0];else if(0==r.length&&n>1)for(i=0;i0&&u>0){var e=n.find(".nv-linePlusBar .nv-linesWrap .nv-groups .nv-series-0").css("fill"),a=n.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)}else u>0?1==d&&$(this).find("div").css({"background-color":l[i[d-t-1]]}):c>0?$(this).find("div").css({"background-color":l[c-t-1]}):$(this).find("div").css({"background-color":l[t]})});var h=n.find(".nv-pie .nv-slice.hover").css("fill");$("html").find(".nvtooltip table .legend-color-guide div").css("background-color",h)}),$(n).mouseleave(function(){$("html").find(".nvtooltip table .legend-color-guide").remove()})}var r=t.charts,o=t.colors,l=t.opacity,s=t.line_dashes;"all"==r&&(r=[],$("mode-chart").each(function(){r.push(this.id)})),setInterval(function(){r.forEach(function(t){a(t,o)})},500),r.forEach(function(t){n(t,o)})},addTotalsRow:function(t){function e(t){var e="TTL";return t.forEach(function(t){""!=t.total?e=e+""+s(t.total)+"":e+=""}),e+""}var a=t.query_name,n="#"+(t.table_id||""),r=alamode.getColumnsFromQuery(a),o=alamode.getDataFromQuery(a),l=t.columns_with_totals,s=d3.format(","),d=function(t){var e=[],a={idx:i,name:"",total:""};return r.forEach(function(n,r){if(-1==t.indexOf(n.name))s=a;else var l=_.map(o,n.name),i=d3.sum(l),s={idx:r,name:n.name,total:i};e.push(s)}),e}(function(t){return numberColumns=_.map(_.filter(r,function(t){return-1!=["number","integer"].indexOf(t.type)}),"name"),"all"==t?numberColumns:_.intersection(t,numberColumns)}(l));setTimeout(function(){table="#"==n?$(".main-table"):$(n+" .main-table");var t=table.find("tr:last"),a=e(d);t.after(a)},1e3)},addImagesToTables:function(t){function e(){var t=$(a+" table"),e=$(a+" .js-header-table"),o=e?$(a+" .js-col-header"):$(e).find("th"),l=t.find("tr"),i=0;o.each(function(){text=$(this).find(".axel-table-header-label").text(),text==n&&(i=+$(this).attr("data-axel-column"))}),l.each(function(){$(this).find("td").each(function(t){if(t==i-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!=s&&t.column!=u&&t.column==d)}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[s]==n});r.length>0?entry=d3.mean(_.map(r,d)):entry="",a=a.concat({column:d,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==d&&f?r(t.value):t.column==d?a(t.value):t.value}var l=t.query_name,i=t.cohort_column,s=t.pivot_column,d=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,s)),w=alamode.addContainerElement(m),k=d3.scale.quantize().domain(d3.extent(v,function(t){return t[d]})).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),headers=u?[i,u].concat(b):[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(t){return o(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,s=t.html_element||"body",d=t.center_lat||39.5,c=t.center_lng||-98.35,u=t.starting_zoom||4,m=t.map_type||"terrain",h=t.height||600,p=alamode.getDataFromQuery(r),f=alamode.addContainerElement(s);d3.select(f).append("div").attr("class","mode-graphic-title").text(l),d3.select(f).append("div").attr("class","mode-google-map").attr("id",e).style("height",h+"px"),jQuery.getScript("https://maps.googleapis.com/maps/api/js?key="+o,function(){!function(){var t={zoom:u,center:new google.maps.LatLng(d,c),mapTypeId:m},r=new google.maps.Map(document.getElementById(e),t);p.forEach(function(t){var e=t[a],o=t[n];label=i?t[i]:"";var l=new google.maps.Marker({position:{lat:e,lng:o},map:r,title:label}),s=new google.maps.InfoWindow({content:label});l.addListener("click",function(){s.open(r,l)})})}()})},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",s=t.center_lat||39.5,d=t.center_lng||-98.35,c=t.starting_zoom||4,u=t.dot_size||.4,m=t.dot_opacity||.8,h=[];alamode.getDataFromQuery(r).forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&h.push(t)});var p=alamode.addContainerElement(i);d3.select(p).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o);var f=l-$(p+".mode-graphic-title").height(),g=$(p).width();d3.select(p).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",f+"px").style("width",g+"px");var v=L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18}),y={max:8,data:h},x={radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n},b={lat:s,lng:d,zoom:c},_=new HeatmapOverlay(x);new L.Map(e,{center:new L.LatLng(b.lat,b.lng),zoom:Math.floor(b.zoom),layers:[v,_]});_.setData(y)},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",s=t.colors||["black"],d=alamode.getDataFromQuery(e),c=alamode.addContainerElement(r);d3.select(c).append("div").attr("class","mode-graphic-title").text(o);var u=d3.scale.linear().domain(d3.extent(d,function(t){return t[n]})).range([12,60]),m=d3.layout.cloud().size([i,l]).words(d.map(function(t){return{text:t[a],size:u(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(c).append("div").attr("class","mode-wordcloud").append("svg").attr("width",m.size()[0]).attr("height",m.size()[1]).append("g").attr("transform","translate("+m.size()[0]/2+","+m.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})});m.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",s=t.width||"500",d=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",s+"px").style("height",i-20+"px");var u=[];d.forEach(function(t){u.push([t[n],t[r]])});var m={label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100};new D3Funnel("#"+e).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(){s.forEach(function(t,e){var n=c[e],r=o[e],i=l[e],s=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),d=$(a).find("g.nvd3.nv-wrap").attr("transform"),u=d.indexOf("("),m=d.indexOf(")"),h=d.indexOf(","),p=+d.slice(u+1,h),f=+d.slice(h+1,m);if(-1!=n&&"v"==r){var g=$(a).find(".nv-point.nv-point-"+n).attr("transform"),v=g.indexOf("("),x=g.indexOf(")"),b=g.indexOf(","),_=+g.slice(v+1,b),w=+g.slice(b+1,x);$(a).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(a).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width");(z=d3.select(a+" .nvd3svg")).call(s),z.append("rect").attr("x",_+p).attr("y",f-5).attr("width",1).attr("class","flag").attr("height",w+5).attr("fill","#ff8f53"),z.append("circle").data([t]).attr("cx",_+p).attr("cy",f-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",s.show).on("mouseout",s.hide)}else if("h"==r||"h-left"==r||"h-right"==r){y="h"==r?"":"1",$(a).find("g.nv-y"+y+".nv-axis").find(".tick").each(function(t){lineLength="h-right"==r?+$(a).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(",",""))});var k=(yTrans2-yTrans1)/(yVal2-yVal1),E=yTrans2-yVal2*k+i*k,z=d3.select(a+" .nvd3svg");z.call(s),z.append("rect").attr("x",p).attr("y",E+f).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),z.append("circle").data([t]).attr("cx",lineLength+p+10).attr("cy",E+f).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",s.show).on("mouseout",s.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,s=t.comments,d=alamode.getDataFromQuery(r),c=[],u={};i&&(u=_.groupBy(d,function(t){return t[i]})),s.forEach(function(t,e){var a=_.filter(d,function(t){return t[n]==l[e]});0!=a.length?pointNumber=i?u[a[0][i]].indexOf(a[0]):d.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||"",s=t.left_pad||150,d=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),d.forEach(function(a){var n=a[t.title_column]||"",r=a[t.subtitle_column]||"",d=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:[d],markerLabels:[i]};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(o).margin({left:s,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){var e=(100*t.value/k).toPrecision(3),a=e+"%";e<.1&&(a="< 0.1%");var r=n(t),o=t.parent.value,i=(100*t.value/o).toPrecision(3),s=i+"%";i<1&&(a="< 1%"),d3.select("#cond-percentage-"+d).text(s),d3.select("#percentage-"+d).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility",""),l(r=n(t),a),d3.selectAll("path").style("opacity",.3),vis.selectAll("path").filter(function(t){return r.indexOf(t)>=0}).style("opacity",1)}function a(t){d3.select("#trail-"+d).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",e)}):d3.selectAll("path").transition().duration(300).style("opacity",1).each("end",function(){d3.select(this).on("mouseover",e)}),d3.selectAll(".mode-sunburst-explanation").style("visibility","hidden")}function n(t){for(var e=[],a=t;a.parent;)e.unshift(a),a=a.parent;return e}function r(){d3.select("#sequence-"+d).append("svg:svg").attr("width",v).attr("height",60).attr("id","trail-"+d).append("svg:text").attr("id","endlabel").style("fill","#000")}function o(t,e){var a=[];return a.push("0,0"),a.push(x.w+",0"),a.push(x.w+x.t+","+x.h/2),a.push(x.w+","+x.h),a.push("0,"+x.h),e>0&&a.push(x.t+","+x.h/2),a.join(" ")}function l(t,e){var a=d3.select("#trail-"+d).selectAll("g").data(t,function(t){return t.name+t.depth}),n=a.enter().append("svg:g");n.append("svg:polygon").attr("points",o).style("fill",function(t){return w[t.name]}),n.append("svg:text").attr("x",(x.w+x.t)/2).attr("y",x.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),a.attr("transform",function(t,e){return e>5&&e<10?"translate("+(e-=5)*(x.w+x.s)+", 20)":e>10?"translate("+(e-=11)*(x.w+x.s)+", 40)":"translate("+e*(x.w+x.s)+", 0)"}),a.exit().remove(),d3.select("#trail-"+d).style("visibility","")}function s(){var t={w:195,h:30,s:3,r:3};d3.entries(w).forEach(function(e){divContainer=d3.select("#legend-container-"+d).append("div").attr("class","mode-sunburst-legend").attr("id","legend-"+d),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})})}var d=alamode.makeId(10),c=t.query_name,u=t.event_columns,m=t.event_counts,h=t.title||c,p=t.color_range||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],f=t.html_element||"body",g=alamode.getDataFromQuery(c),v=850,y=Math.min(v,600)/2,x={w:(v-30)/u.length,h:20,s:3,t:10},b=[];u.forEach(function(t){b=b.concat(_.uniq(_.map(g,t)))});var w={};_.uniq(b).forEach(function(t,e){null!=t&&(w[t]=p[e%p.length])}),w.end="#666";var k=0,$=alamode.addContainerElement(f);d3.select($).append("div").attr("class","mode-graphic-title").text(h),d3.select($).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+d),d3.select($).append("div").attr("class","mode-sunburst").attr("id",d),d3.select($).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+d),vis=d3.select("#"+d).append("svg:svg").attr("width",v).attr("height",600).append("svg:g").attr("transform","translate("+v/2+",300)"),vis.append("text").attr("x",0).attr("y",-30).attr("text-anchor","middle").attr("class","mode-sunburst-explanation mode-sunburst-percentage").attr("id","percentage-"+d).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-"+d).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.");var E=d3.layout.partition().size([2*Math.PI,y*y]).value(function(t){return t.size}),z=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)}),C=[];g.forEach(function(t){var e="";for(i=0;i.005}),o=vis.data([t]).selectAll("path").data(n).enter().append("svg:path").attr("display",function(t){return t.depth?null:"none"}).attr("d",z).attr("fill-rule","evenodd").style("fill",function(t){return w[t.name]}).style("opacity",1).on("mouseover",e);vis.on("mouseleave",a),k=o.node().__data__.value}(function(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",s=t.group_colors||"",d=t.links_to_show||100,c=alamode.getDataFromQuery(a),u=[];alamode.getDataFromQuery(n).forEach(function(t){var e=u.filter(function(e){return e.target==t.source}).filter(function(e){return e.source==t.target});0!=e.length?e.edge_size+=t.edge_size:u.push(t)}),u=u.sort(function(t,e){return e.edge_size-t.edge_size}),u=u.slice(0,d),nameMap={},c.forEach(function(t,e){t.id=e,nameMap[t.node]=e}),u.forEach(function(t){t.source_id=nameMap[t.source],t.target_id=nameMap[t.target]});var m=alamode.addContainerElement(r);d3.select(m).append("div").attr("class","mode-graphic-title").text(o),d3.select(m).append("div").attr("class","mode-force-directed-graph").style("width",l).attr("id",e);var h=d3.tip().attr("class","mode-force-directed-graph-tooltip").offset([-10,0]).html(function(t){return t.node}),p=d3.layout.force().linkDistance(40).linkStrength(1).size([l,i]),f=d3.select("#"+e).append("svg").attr("width",l).attr("height",i);f.call(h);var g={nodes:c,links:u},v=d3.scale.linear().domain(d3.extent(c,function(t){return t.node_size})).range([2,20]),y=d3.scale.linear().domain(d3.extent(u,function(t){return t.edge_size})).range([1,10]),x=d3.scale.linear().domain(d3.extent(u,function(t){return t.edge_size})).range([.1,.9]),c=g.nodes.slice(),u=[],b=[];g.links.forEach(function(t){var e=c[t.source_id],a=c[t.target_id],n={};n.connections=t.edge_size,c.push(n),u.push({source:e,target:n},{source:n,target:a}),b.push([e,n,a])}),p.nodes(c).links(u).start();var _=f.selectAll(".mode-force-directed-graph-link ").data(b).enter().append("path").attr("class","mode-force-directed-graph-link").style("stroke-width",function(t){return y(t[1].connections)}).style("opacity",function(t){return x(t[1].connections)}),w=f.selectAll(".mode-force-directed-graph-node").data(g.nodes).enter().append("g").attr("class","mode-force-directed-graph-node").call(p.drag);w.append("circle").attr("r",function(t){return v(t.node_size)}).style("fill",function(t){return s?s[t.node_group]:"#0E819A"}).on("mouseover",h.show).on("mouseout",h.hide),p.on("tick",function(){_.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}),w.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 b(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(),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(C[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,s=t.html_element||"body",d=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]),b=d3.scale.linear().domain(d3.extent(y,function(t){return t.edge_size})).clamp(!0),_=alamode.addContainerElement(s);d3.select(_).append("div").attr("class","mode-graphic-title").text(d),d3.select(_).append("div").attr("class","mode-network-matrix-order-picker").html('

Order: '),d3.select(_).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=[],z=(v=graph.nodes).length;v.forEach(function(t,e){t.index=e,t.count=0,E[e]=d3.range(z).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){void 0!==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 C={name:d3.range(z).sort(function(t,e){return d3.ascending(v[t].node,v[e].node)}),count:d3.range(z).sort(function(t,e){return v[e].count-v[t].count}),group:d3.range(z).sort(function(t,e){return d3.ascending(v[t].node_group,v[e].node_group)})};x.domain(C.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),(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)).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 s=l.a+(i.a-l.a)/3,d=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(s)*l.r1+","+Math.sin(s)*l.r1+" "+Math.cos(d)*i.r1+","+Math.sin(d)*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(d)*i.r0+","+Math.sin(d)*i.r0+" "+Math.cos(s)*l.r0+","+Math.sin(s)*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(s)*l.r1+","+Math.sin(s)*l.r1+" "+Math.cos(d)*i.r1+","+Math.sin(d)*i.r1+" "+Math.cos(i.a)*i.r1+","+Math.sin(i.a)*i.r1}function e(t,e,a,n){var s=t.call(e,a,n),d=+("function"==typeof r?r.call(e,s,n):r)+i,c=+("function"==typeof o?o.call(e,s,n):o);return{r0:c,r1:o===l?c:+("function"==typeof l?l.call(e,s,n):l),a:d}}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,s=t.chart_width||"800",d=t.chart_height||"800",c=t.group_colors||"",u=Math.min(s,d)/2-30,m=.2*u,h=alamode.getDataFromQuery(n),p=alamode.getDataFromQuery(r),f=_.uniq(_.map(h,"node_group")),g={};h.forEach(function(t){t.x=o?t.node_group: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",s).attr("id",a),angle=o?d3.scale.linear().domain(d3.extent(h,function(t){return t.node_group})).range([0,2*Math.PI]):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",s).attr("height",d).append("g").attr("transform","translate("+s/2+","+d/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){var e=$(l+" table"),r=$(l+" .js-header-table"),o=r?$(l+" .js-col-header"):$(r).find("th"),i=(e.find("tr"),0);o.each(function(){text=$(this).find(".axel-table-header-label").text(),i=$(this).attr("data-axel-column"),c[text]=i}),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(d,t)),r=d3.scale.linear().domain(n).interpolate(d3.interpolateHsl).range(e),i=c[t];d.forEach(function(e,n){var s=l+" table [data-axel-rowkey='"+n+"'][data-axel-column='"+i+"']",d=r(e[t]),c=o(d),u=$(s);a?u.css("color",d):u.css({background:d,color:c})})}function n(t,e,a,n,r){var i=c[t],s=o(n);d.forEach(function(o,d){var c=l+" table [data-axel-rowkey='"+d+"'][data-axel-column='"+i+"']",u=$(c);"above"==e&&o[t]>=a?r?u.css("color",n):u.css({background:n,color:s}):"below"==e&&o[t]<=a?r?u.css("color",n):u.css({background:n,color:s}):"equal"==e&&o[t]==a&&(r?u.css("color",n):u.css({background:n,color:s}))})}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){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e)?(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,s=t.column_rules,d=alamode.getDataFromQuery(i),c=(alamode.getColumnsFromQuery(i),{});setTimeout(function(){e(s)},1e3),$(l).mousemove(function(){e(s)})},conditionalFormattingByTable:function(t){function e(t){var e=$(l+" table"),r=$(l+" .js-header-table"),o=r?$(l+" .js-col-header"):$(r).find("th"),i=(e.find("tr"),0);o.each(function(){text=$(this).find(".axel-table-header-label").text(),i=$(this).attr("data-axel-column"),c[text]=i}),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(m).interpolate(d3.interpolateHsl).range(t);d.forEach(function(t,n){s.forEach(function(r){var i=c[r],s=l+" table [data-axel-rowkey='"+n+"'][data-axel-column='"+i+"']",d=a(t[r]),u=o(d),m=$(s);e?m.css("color",d):m.css({background:d,color:u})})})}function n(t,e,a,n){var r=o(a);d.forEach(function(o,i){s.forEach(function(s){var d=c[s],u=l+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+d+"']",m=$(u);"above"==t&&o[s]>=e?n?m.css("color",a):m.css({background:a,color:r}):"below"==t&&o[s]<=e?n?m.css("color",a):m.css({background:a,color:r}):"equal"==t&&o[s]==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){return/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e)?(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,s=t.columns;rules=t.rules;var d=alamode.getDataFromQuery(i),c=(alamode.getColumnsFromQuery(i),{}),u=[];s.forEach(function(t){var e=d3.extent(_.map(d,t));u=u.concat(e)});var m=d3.extent(u);setTimeout(function(){e(rules)},1e3),$(l).mousemove(function(){e(rules)})},addTableOfContents:function(t){void 0===t&&(t="default");var e=t.text_color,a=t.background_color,n=t.hover_color;$(".mode-header").addClass("has-nav");var r=$("

");$(".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;if(e.includes("chart")||e.includes("table")){var a=document.getElementById(e);t=$(a).find("mode-pivot-table").length>0?document.getElementById(e).getElementsByClassName("in-place-edit-text")[0].innerText:document.getElementById(e).getElementsByClassName("chart-title")[0].innerText}else e.includes("python")&&(t=document.getElementById(e).getElementsByClassName("in-place-edit-text")[0].innerText);var n=$(""+(t.includes("Click to add title")?"Untitled":t)+"");r.append(n)})});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=$(t).offset().top-50;$("html,body").animate({scrollTop:a},e)}$(".scroll-link").on("click",function(e){e.preventDefault(),t($(this).attr("href"),750)})},100)}}; \ No newline at end of file