From 2395d143cd7fcda2ec3246041223bbb6fc77b8ba Mon Sep 17 00:00:00 2001 From: Nima Gardideh Date: Tue, 21 Jul 2020 14:35:14 -0700 Subject: [PATCH 1/4] Added alamode.heatmapOverlay. --- alamode.js | 84 +++++++++++++++++++++++++++++++++++++++++++++++--- alamode.min.js | 2 +- 2 files changed, 80 insertions(+), 6 deletions(-) diff --git a/alamode.js b/alamode.js index 5f71b41..95618fc 100644 --- a/alamode.js +++ b/alamode.js @@ -457,7 +457,7 @@ var alamode = { pivots = _.sortBy(_.uniq( _.map(data, pivotColumn) ) ); var uniqContainerClass = alamode.addContainerElement(htmlElement); - + if (gradientBy === "cohort_column") { var colorsByCohort = {}; cohorts.forEach(function (cohort) { @@ -608,7 +608,6 @@ var alamode = { } }, - // A simple heatmap to use for any 2-labeled data // Parameters: @@ -637,7 +636,7 @@ var alamode = { // Optional colors = o["color_gradient"] || ["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"], - + htmlElement = o["html_element"] || "body", title = o["title"] || queryName, xLabel = o["x_label"] || "", @@ -654,7 +653,7 @@ var alamode = { var uniqContainerClass = alamode.addContainerElement(htmlElement); var color = d3.scale.quantize() - .domain(d3.extent(data, function(d) { + .domain(d3.extent(data, function(d) { return Math.max(minValue, Math.min(maxValue, d[valueColumn])); })) .range(colors) @@ -725,7 +724,7 @@ var alamode = { } function makeRow(data,xVal) { - + var row = [ {column: xColumn, value: xVal } ]; yVals.forEach(function(p) { @@ -769,6 +768,81 @@ var alamode = { } }, + // A simple way to draw a heatmap on an existing table. + // It claculates averages automatically and supports multiple columns. + // Parameters: + + // - queryToken: the name of the query that has the source data + // - vizId: table's id + // - columns: the columns to overlay a heatmap for + // - color_gradient: if present, overrides the green/red gradient. Should be an array of strings, where each value is a hex color string + // - inverse: if present, it reverses the color order (i.e. lower is better, higher is worse) + heatmapOverlay: function(o) { + var colors = o.color_gradient || ["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"] + var dataset = datasets.filter(function(data) { return data.query_token === o.queryToken }) + + if (o.inverse) { + colors = colors.reverse() + } + + // Used to convert rgb(x, x, x) color format from d3 to #hex format. + function componentFromStr(numStr, percent) { + var num = Math.max(0, parseInt(numStr, 10)); + return percent ? Math.floor(255 * Math.min(100, num) / 100) : Math.min(255, num); + } + function rgbToHex(rgb) { + var rgbRegex = /^rgb\(\s*(-?\d+)(%?)\s*,\s*(-?\d+)(%?)\s*,\s*(-?\d+)(%?)\s*\)$/; + var result, r, g, b, hex = ""; + if ((result = rgbRegex.exec(rgb))) { + r = componentFromStr(result[1], result[2]); + g = componentFromStr(result[3], result[4]); + b = componentFromStr(result[5], result[6]); + + hex = "#" + (0x1000000 + (r << 16) + (g << 8) + b).toString(16).slice(1); + } + return hex; + } + + function heatmapColumnRules(columnName, dataset, valueFunc) { + + var avg = d3.mean(dataset.content.map(valueFunc)); + var maxVal = d3.max(dataset.content.map(valueFunc)); + var minVal = d3.min(dataset.content.map(valueFunc)); + var buckets = d3.range(0, dataset.content.length) + var color = d3.scaleSequential() + .domain([minVal, maxVal]) + .interpolator(d3.interpolateRgbBasis(colors)); + + var scale = d3.scaleThreshold() + .domain(buckets) + .range(dataset.content.map(valueFunc).sort()) + + return { + name: columnName, + rules: buckets.map(function (index) { + return { + type: '<=', + value: scale(index), + color: rgbToHex(color(scale(index))) + } + }).concat({ + type: '>=', + value: maxVal, + color: colors[colors.length - 1] + }) + } + } + + alamode.customizeTable([{ + vizId: o.vizId, + formatByColumn: { + columns: (o.columns || []).map(function (column) { + return heatmapColumnRules(column, dataset[0], function (row) { return row[column] }) + }) + } + }]) + }, + // Built with Google Maps Javascript API // https://developers.google.com/maps/documentation/javascript/ googleMap: function(o) { diff --git a/alamode.min.js b/alamode.min.js index 561531e..6122d5b 100644 --- a/alamode.min.js +++ b/alamode.min.js @@ -1 +1 @@ -var version="0.23",alamode={reportError:function(e){$("

").text(e).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(e){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",a="",n=0;n").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content"):0===$(e).length?alamode.reportError("No such element: '"+e+"'"):(t&&$(e).empty(),$(e).addClass("mode-graphic-container"),$(e).addClass(id)),"."+id},addLinksToTables:function(e){var l="#"+e.table_id,t=e.link_columns,a=e.link_urls,n=e.query_name,m=e.open_in_new_tab||!1,r=[],h={};t.forEach(function(e,t){r.push({column:e,link_string:a[t]})});var p=alamode.getDataFromQuery(n);alamode.getColumnsFromQuery(n);function o(t){var e=$(l+" table"),a=$(l+" .js-header-table"),n=a?$(l+" .js-col-header"):$(a).find("th"),r=e.find("tr"),o=0;n.each(function(){text=$(this).find(".axel-table-header-label").text(),o=$(this).attr("data-axel-column"),h[text]=o-1}),r.each(function(e){if(0"+a+"";c.eq(t).html(s)})}})}setTimeout(function(){o(r)},1e3),$(l).mousemove(function(){o(r)})},customChartColors:function(e){var t=e.charts,n=e.colors,d=e.opacity,s=e.line_dashes;function h(e,t){var a=$("#"+e),n=(0TTL",u.forEach(function(e){""!=e.total?t=t+""+s(e.total)+"":t+=""}),t+""),n=+container.css("height").match(/\d+/)[0];e.after(a),container.css("height",26+n)},1e3)},addImagesToTables:function(e){var o="#"+e.table,l=e.column,i=e.image_height||100;function t(){var e=$(o+" table"),t=$(o+" .js-header-table"),a=t?$(o+" .js-col-header"):$(t).find("th"),n=e.find("tr"),r=0;a.each(function(){text=$(this).find(".axel-table-header-label").text(),text==l&&(r=+$(this).attr("data-axel-column"))}),n.each(function(){$(this).find("td").each(function(e){if(e==r-1){var t=$(this).text();0==$(this).find("img").length&&($(this).css("text-align","center"),$(this).html(""))}})})}setTimeout(function(){t()},1e3),$(o).keyup(function(){setTimeout(function(){t()},500)}),$(o).mousemove(function(){t()})},resizeChartHeight:function(e){var t=e.chart,a=e.height;"python"==t.slice(0,6)?($("#"+t+" .mode-python").css("height",a),$("#"+t+" .mode-python").css("max-height",a),$("#"+t+" img").css("max-height",a)):($("#"+t+" .chart").css("height",a),$("#"+t+" .chart-svg").css("height",a)),window.dispatchEvent(new Event("resize"))},retentionHeatmap:function(e){var t=e.query_name,o=e.cohort_column,l=e.pivot_column,i=e.value_column,a=e.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],n=e.gradient_by||"all",d=e.gradient_column||i,s=e.total_column,r=e.html_element||"body",c=e.title||t,u=e.pivot_label||"",m=e.value_is_percent,h=e.precision||0,p=alamode.getDataFromQuery(t),f=alamode.getColumnsFromQuery(t),v=_.uniq(_.map(p,o)),g=_.sortBy(_.uniq(_.map(p,l))),y=alamode.addContainerElement(r);if("cohort_column"===n){var x={};v.forEach(function(t){var e=p.filter(function(e){return e[o]===t});x[t]=d3.scale.quantize().domain(d3.extent(e,function(e){return e[d]})).range(a)})}else if("pivot_column"===n){var b={};g.forEach(function(t){var e=p.filter(function(e){return e[l]===t});b[t]=d3.scale.quantize().domain(d3.extent(e,function(e){return e[d]})).range(a)})}else var w=d3.scale.quantize().domain(d3.extent(p,function(e){return e[d]})).range(a);d3.select(y).append("div").attr("class","mode-graphic-title").text(c),d3.select(y).append("div").attr("class","mode-retention-heatmap-label").text(u),headers=s?[o,s].concat(g):[o].concat(g);var k=d3.select(y).append("table").attr("class","mode-retention-heatmap-table");function $(t){return f.filter(function(e){return e.name==t})[0].type}k.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(e){return isNaN(e)?"mode-retention-heatmap-table-header-cell heatmap-string":"mode-retention-heatmap-table-header-cell heatmap-number"}).text(function(e){return e}),k.selectAll(".mode-retention-heatmap-table-row").data(v).enter().append("tr").attr("class","mode-retention-heatmap-table-row").selectAll(".mode-retention-heatmap-table-cell").data(function(e){return function(a,n){var r=[{column:o,value:n}];if(s){var e=_.filter(a,function(e){return e[o]==n})[0],t={column:s,value:e[s]};r=r.concat(t)}return g.forEach(function(t){var e=_.filter(a,function(e){return e[o]==n&&e[l]==t});0Order: '),d3.select(_).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",t);var b=d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(e){return e.z}),w=d3.select("#"+t).append("svg").attr("width",i+f+h).attr("height",d+m+p);w.call(b);var k=w.append("g").attr("transform","translate("+f+","+m+")");graph={nodes:v,links:g};var $=[],E=(v=graph.nodes).length;v.forEach(function(e,t){e.index=t,e.count=0,$[t]=d3.range(E).map(function(e){return{x:e,y:t,z:0}})}),graph.links.forEach(function(e){void 0!==$[e.source_id][e.target_id]?($[e.source_id][e.target_id].z+=e.edge_size,v[e.source_id].count+=e.edge_size,v[e.target_id].count+=e.edge_size):($[e.source_id][e.target_id]={},$[e.source_id][e.target_id].z=0)});var C,A={name:d3.range(E).sort(function(e,t){return d3.ascending(v[e].node,v[t].node)}),count:d3.range(E).sort(function(e,t){return v[t].count-v[e].count}),group:d3.range(E).sort(function(e,t){return d3.ascending(v[e].node_group,v[t].node_group)})};y.domain(A.name),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(i+f+h)/2).attr("y",25).attr("text-anchor","middle").text(u),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(d+m+p)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(c),k.append("rect").attr("class","mode-network-matrix-background").attr("width",i).attr("height",d),(C=k.selectAll(".mode-network-matrix-row").data($).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(e,t){return"translate(0,"+y(t)+")"}).each(C)).append("line").attr("class","mode-network-matrix-line").attr("x2",i),C.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(e,t){return v[t].node});var z=k.selectAll(".mode-network-matrix-column").data($).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(e,t){return"translate("+y(t)+")rotate(-90)"});function C(e){d3.select(this).selectAll(".mode-network-matrix-cell").data(e.filter(function(e){return e.z})).enter().append("rect").attr("class","mode-network-matrix-cell").attr("x",function(e){return y(e.x)}).attr("width",y.rangeBand()).attr("height",y.rangeBand()).style("fill-opacity",function(e){return x(e.z)}).style("fill",function(e){return v[e.x].node_group==v[e.y].node_group?s[v[e.x].node_group]:"#2B2B2B"}).on("mouseover",function(e){var a;a=e,d3.selectAll(".mode-network-matrix-row-text").classed("active",function(e,t){return t==a.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(e,t){return t==a.x}),b.show(e)}).on("mouseout",function(e){d3.selectAll("text").classed("active",!1),b.hide(e)})}z.append("line").attr("class","mode-network-matrix-line").attr("x1",-i),z.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(e,t){return v[t].node}),d3.select("#mode-network-matrix-order-picker-"+t).on("change",function(){!function(e){y.domain(A[e]);var t=k.transition().duration(1e3);t.selectAll(".mode-network-matrix-row").attr("transform",function(e,t){return"translate(0,"+y(t)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(e){return y(e.x)}),t.selectAll(".mode-network-matrix-column").attr("transform",function(e,t){return"translate("+y(t)+")rotate(-90)"})}(this.value)})},hive:function(e){d3.hive={},d3.hive.link=function(){function t(e,t){var a,n=i(d,this,e,t),r=i(s,this,e,t);n.a>r.a&&(a=r,r=n,n=a),r.a-n.a>Math.PI&&(n.a+=2*Math.PI);var o=n.a+(r.a-n.a)/3,l=r.a-(r.a-n.a)/3;return n.r0-n.r1||r.r0-r.r1?"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"L"+Math.cos(n.a)*n.r1+","+Math.sin(n.a)*n.r1+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1+"L"+Math.cos(r.a)*r.r0+","+Math.sin(r.a)*r.r0+"C"+Math.cos(l)*r.r0+","+Math.sin(l)*r.r0+" "+Math.cos(o)*n.r0+","+Math.sin(o)*n.r0+" "+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0:"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1}function i(e,t,a,n){var r=e.call(t,a,n),o=+("function"==typeof c?c.call(t,r,n):c)+h,l=+("function"==typeof u?u.call(t,r,n):u);return{r0:l,r1:u===m?l:+("function"==typeof m?m.call(t,r,n):m),a:o}}var d=function(e){return e.source},s=function(e){return e.target},c=function(e){return e.angle},u=function(e){return e.radius},m=u,h=-Math.PI/2;return t.source=function(e){return arguments.length?(d=e,t):d},t.target=function(e){return arguments.length?(s=e,t):s},t.angle=function(e){return arguments.length?(c=e,t):c},t.radius=function(e){return arguments.length?(u=m=e,t):u},t.startRadius=function(e){return arguments.length?(u=e,t):u},t.endRadius=function(e){return arguments.length?(m=e,t):m},t};var t=alamode.makeId(10),a=e.node_query,n=e.edge_query,r=e.groups_are_numeric,o=e.html_element||"body",l=e.title||queryName,i=e.chart_width||"800",d=e.chart_height||"800",s=e.group_colors||"",c=Math.min(i,d)/2-30,u=.2*c,m=alamode.getDataFromQuery(a),h=alamode.getDataFromQuery(n),p=_.uniq(_.map(m,"node_group")),f={};m.forEach(function(e){e.x=r?e.node_group:p.indexOf(e.node_group),e.y=e.node_size,f[e.node]=e}),h.forEach(function(e){e.source=f[e.source],e.target=f[e.target]});var v=alamode.addContainerElement(o);d3.select(v).append("div").attr("class","mode-graphic-title").text(l),d3.select(v).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",t),angle=r?d3.scale.linear().domain(d3.extent(m,function(e){return e.node_group})).range([0,2*Math.PI]):d3.scale.ordinal().domain(d3.range(p.length+1)).rangePoints([0,2*Math.PI]);var g=d3.scale.linear().domain(d3.extent(m,function(e){return e.node_size})).range([u,c]),y=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(e){return e.node}),x=d3.select("#"+t).append("svg").attr("width",i).attr("height",d).append("g").attr("transform","translate("+i/2+","+d/2+")");function b(e){return e/Math.PI*180-90}x.call(y),x.selectAll(".mode-hive-axis").data(d3.range(p.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(e){return"rotate("+b(angle(e))+")"}).attr("x1",g.range()[0]).attr("x2",g.range()[1]),x.selectAll(".mode-hive-link").data(h).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(e){return angle(e.x)}).radius(function(e){return g(e.y)})).style("stroke",function(e){return s[e.source.node_group]}),x.selectAll(".mode-hive-node").data(m).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(e){return"rotate("+b(angle(e.x))+")"}).attr("cx",function(e){return g(e.y)}).attr("r",5).style("fill",function(e){return s[e.node_group]}).on("mouseover",function(t){y.show(t),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(h).attr("class",function(e){return e.source.node==t.node||e.target.node==t.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(e){y.hide(e),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(n){var v="#"+n.table_id,e=n.query_name,t=n.column_rules,g=alamode.getDataFromQuery(e),y=(alamode.getColumnsFromQuery(e),{});function a(e){var t=$(v+" table"),a=$(v+" .js-header-table"),n=a?$(v+" .js-col-header"):$(a).find("th"),r=(t.find("tr"),0);n.each(function(){text=$(this).find(".axel-table-header-label").text(),r=$(this).attr("data-axel-column"),y[text]=r}),e.forEach(function(f){f.rules.forEach(function(e){var n,r,o,l,i,d,s,c,t,u,a,m,h,p=e.shade_text||!1;"gradient"==e.type?(c=f.column,t=e.color,u=p,a=d3.extent(_.map(g,c)),m=d3.scale.linear().domain(a).interpolate(d3.interpolateHsl).range(t),h=y[c],g.forEach(function(e,t){var a=v+" table [data-axel-rowkey='"+t+"'][data-axel-column='"+h+"']",n=m(e[c]),r=x(n),o=$(a);u?o.css("color",n):o.css({background:n,color:r})})):"above"!=e.type&&"below"!=e.type&&"equal"!=e.type||(n=f.column,r=e.type,o=e.value,l=e.color,i=p,d=y[n],s=x(l),g.forEach(function(e,t){var a=$(v+" table [data-axel-rowkey='"+t+"'][data-axel-column='"+d+"']");("above"==r&&e[n]>=o||"below"==r&&e[n]<=o||"equal"==r&&e[n]==o)&&(i?a.css("color",l):a.css({background:l,color:s}))}))})})}function x(e){var t,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e);return 125<(n=a?(rgb=(t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e))?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){a(t)},1e3),$(v).mousemove(function(){a(t)})},customizeTable:function(e){window.dispatchAction({type:"Embed.AlamodeCustomizeTable",payload:e})},conditionalFormattingByTable:function(n){var m="#"+n.table_id,e=n.query_name,h=n.columns;rules=n.rules;var p=alamode.getDataFromQuery(e),f=(alamode.getColumnsFromQuery(e),{}),a=[];h.forEach(function(e){var t=d3.extent(_.map(p,e));a=a.concat(t)});var v=d3.extent(a);function t(e){var t=$(m+" table"),a=$(m+" .js-header-table"),n=a?$(m+" .js-col-header"):$(a).find("th"),r=(t.find("tr"),0);n.each(function(){text=$(this).find(".axel-table-header-label").text(),r=$(this).attr("data-axel-column"),f[text]=r}),e.forEach(function(e){var o,l,i,d,s,t,c,u,a=e.shade_text||!1;"gradient"==e.type?(t=e.color,c=a,u=d3.scale.linear().domain(v).interpolate(d3.interpolateHsl).range(t),p.forEach(function(l,i){h.forEach(function(e){var t=f[e],a=m+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+t+"']",n=u(l[e]),r=g(n),o=$(a);c?o.css("color",n):o.css({background:n,color:r})})})):"above"!=e.type&&"below"!=e.type&&"equal"!=e.type||(o=e.type,l=e.value,i=e.color,d=a,s=g(i),p.forEach(function(n,r){h.forEach(function(e){var t=f[e],a=$(m+" table [data-axel-rowkey='"+r+"'][data-axel-column='"+t+"']");("above"==o&&n[e]>=l||"below"==o&&n[e]<=l||"equal"==o&&n[e]==l)&&(d?a.css("color",i):a.css({background:i,color:s}))})}))})}function g(e){var t,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e);return 125<(n=a?(rgb=(t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e))?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){t(rules)},1e3),$(m).mousemove(function(){t(rules)})},addTableOfContents:function(e){void 0===e&&(e="default");var t=e.text_color,a=e.background_color,n=e.hover_color;$(".mode-header").addClass("has-nav");var r=$("");$(".row").each(function(){$(this).children().each(function(){var e,t=$(this).find("mode-chart").attr("id")||$(this).find("mode-table").attr("id")||$(this).find("mode-python").attr("id");if(!t)return!0;if(t.includes("chart")||t.includes("table")){var a=document.getElementById(t);e=0<$(a).find("mode-pivot-table").length?document.getElementById(t).getElementsByClassName("in-place-edit-text")[0].innerText:document.getElementById(t).getElementsByClassName("chart-title")[0].innerText}else t.includes("python")&&(e=document.getElementById(t).getElementsByClassName("in-place-edit-text")[0].innerText);var n=$(""+(e.includes("Click to add title")?"Untitled":e)+"");r.append(n)})});var o=$("
");$(".mode-content").prepend(o);var l=$("
");o.prepend(l);var i=$("
");l.prepend(i),i.prepend(r),t&&$(".fixed-nav-bar a").css("color",t),a&&$(".fixed-nav-bar").css("background-color",a),n&&$(".fixed-nav-bar a").hover(function(){$(this).css("color",n)},function(){t?$(this).css("color",t):$(this).css("color","")}),setTimeout(function(){$(".scroll-link").on("click",function(e){e.preventDefault();var t,a,n=$(this).attr("href");t=750,a=$(n).offset().top-50,$("html,body").animate({scrollTop:a},t)})},100)},xAnnotations:function(e){var a=e.chart_id,r=e.comment_values,o=e.comments,l=e.color||[],d=e.is_date||!1;setTimeout(function(){var t=$("#"+a).find("div.highcharts-container")[0].id,e=Highcharts.charts;if(chart=e.filter(function(e){if(e)return e.container.id==t})[0],data=chart.series[0].data,d)for(i=0;i").text(t).prependTo(document.body)},getColumnsFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.columns:(alamode.reportError("No such query: '"+e+"'"),[])},getDataFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.content:(alamode.reportError("No such query: '"+e+"'"),[])},makeId:function(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",a="",n=0;n").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content"):0===$(t).length?alamode.reportError("No such element: '"+t+"'"):(e&&$(t).empty(),$(t).addClass("mode-graphic-container"),$(t).addClass(id)),"."+id},addLinksToTables:function(t){var l="#"+t.table_id,e=t.link_columns,a=t.link_urls,n=t.query_name,m=t.open_in_new_tab||!1,r=[],h={};e.forEach(function(t,e){r.push({column:t,link_string:a[e]})});var p=alamode.getDataFromQuery(n);alamode.getColumnsFromQuery(n);function o(e){var t,a=$(l+" table"),n=$(l+" .js-header-table"),r=n?$(l+" .js-col-header"):$(n).find("th"),o=a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),t=$(this).attr("data-axel-column"),h[text]=t-1}),o.each(function(t){var c,u;0"+a+"";c.eq(e).html(s)}))})}setTimeout(function(){o(r)},1e3),$(l).mousemove(function(){o(r)})},customChartColors:function(t){var e=t.charts,n=t.colors,d=t.opacity,s=t.line_dashes;function h(t,e){var a=$("#"+t),n=(0TTL",u.forEach(function(t){""!=t.total?e=e+""+s(t.total)+"":e+=""}),e+""),n=+container.css("height").match(/\d+/)[0];t.after(a),container.css("height",26+n)},1e3)},addImagesToTables:function(t){var o="#"+t.table,l=t.column,i=t.image_height||100;function e(){var t=$(o+" table"),e=$(o+" .js-header-table"),a=e?$(o+" .js-col-header"):$(e).find("th"),n=t.find("tr"),r=0;a.each(function(){text=$(this).find(".axel-table-header-label").text(),text==l&&(r=+$(this).attr("data-axel-column"))}),n.each(function(){$(this).find("td").each(function(t){var e;t==r-1&&(e=$(this).text(),0==$(this).find("img").length&&($(this).css("text-align","center"),$(this).html("")))})})}setTimeout(function(){e()},1e3),$(o).keyup(function(){setTimeout(function(){e()},500)}),$(o).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){var a,n,r,e=t.query_name,o=t.cohort_column,l=t.pivot_column,i=t.value_column,d=t.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],s=t.gradient_by||"all",c=t.gradient_column||i,u=t.total_column,m=t.html_element||"body",h=t.title||e,p=t.pivot_label||"",f=t.value_is_percent,v=t.precision||0,g=alamode.getDataFromQuery(e),y=alamode.getColumnsFromQuery(e),x=_.uniq(_.map(g,o)),b=_.sortBy(_.uniq(_.map(g,l))),w=alamode.addContainerElement(m);"cohort_column"===s?(a={},x.forEach(function(e){var t=g.filter(function(t){return t[o]===e});a[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(d)})):"pivot_column"===s?(n={},b.forEach(function(e){var t=g.filter(function(t){return t[l]===e});n[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(d)})):r=d3.scale.quantize().domain(d3.extent(g,function(t){return t[c]})).range(d),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?[o,u].concat(b):[o].concat(b);var k=d3.select(w).append("table").attr("class","mode-retention-heatmap-table");function $(e){return y.filter(function(t){return t.name==e})[0].type}k.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}),k.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 function(a,n){var r=[{column:o,value:n}];{var t,e;u&&(t=_.filter(a,function(t){return t[o]==n})[0],e={column:u,value:t[u]},r=r.concat(e))}return b.forEach(function(e){var t=_.filter(a,function(t){return t[o]==n&&t[l]==e});0=",value:n,color:d[d.length-1]})}}e.inverse&&(d=d.reverse()),alamode.customizeTable([{vizId:e.vizId,formatByColumn:{columns:(e.columns||[]).map(function(e){return a(e,t[0],function(t){return t[e]})})}}])},googleMap:function(t){var e=alamode.makeId(10),l=t.lat_column,i=t.lng_column,a=t.query_name,n=t.google_maps_api_key,r=t.title||a,d=t.label_column,o=t.html_element||"body",s=t.center_lat||39.5,c=t.center_lng||-98.35,u=t.starting_zoom||4,m=t.map_type||"terrain",h=t.height||600,p=alamode.getDataFromQuery(a),f=alamode.addContainerElement(o);d3.select(f).append("div").attr("class","mode-graphic-title").text(r),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="+n,function(){var t,o;t={zoom:u,center:new google.maps.LatLng(s,c),mapTypeId:m},o=new google.maps.Map(document.getElementById(e),t),p.forEach(function(t){var e=t[l],a=t[i];label=d?t[d]:"";var n=new google.maps.Marker({position:{lat:e,lng:a},map:o,title:label}),r=new google.maps.InfoWindow({content:label});n.addListener("click",function(){r.open(o,n)})})})},leafletMap:function(t){var e=alamode.makeId(10),a=t.lat_column,n=t.lng_column,r=t.query_name,o=t.title||r,l=t.height||400,i=t.html_element||"body",d=t.center_lat||39.5,s=t.center_lng||-98.35,c=t.starting_zoom||4,u=t.dot_size||.4,m=t.dot_opacity||.8,h=t.apply_filter||!1,p=alamode.getDataFromQuery(r),f=[];p.forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&f.push(t)});var v=alamode.addContainerElement(i,h);d3.select(v).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o);var g=l-$(v+".mode-graphic-title").height(),y=$(v).width();d3.select(v).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",g+"px").style("width",y+"px");var x=L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18}),_={max:8,data:f},b={lat:d,lng:s,zoom:c},w=new HeatmapOverlay({radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n});new L.Map(e,{center:new L.LatLng(b.lat,b.lng),zoom:Math.floor(b.zoom),layers:[x,w]});w.setData(_)},wordCloud:function(t){var e=t.query_name,a=t.word_column,n=t.word_count_column,r=t.html_element||"body",o=t.title||e,l=t.height||"400",i=t.width||"800",d=t.colors||["black"],s=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(s,function(t){return t[n]})).range([12,60]),m=d3.layout.cloud().size([i,l]).words(s.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 d[e%d.length]}).attr("text-anchor","middle").attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).text(function(t){return t.text})});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",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]])});new D3Funnel("#"+e).draw(u,{label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100}),d3.select("#"+e).style("height",i+"px")},horizontalBarChart:function(r){var t=r.query_name,e=(r.bar_column,r.series_columns),o=r.colors||["#EE8D24","#43A5DA","#6AB328","#BB60F8","#E14459","#EAD022","#06D0AD","#DB38B7"];stacked=r.stacked||!1,leftpad=r.left_pad||175,htmlElement=r.html_element||"body",title=r.title||t,height=r.chart_height||395,width=r.width||"500";var l=alamode.getDataFromQuery(t),a=alamode.addContainerElement(htmlElement);d3.select(a).append("div").attr("class","mode-graphic-title").text(title),d3.select(a).append("div").attr("class","mode-horizontal-bar-chart").style("height",height-50+"px").append("svg");var i=[];e.forEach(function(e,t){var a={key:e,color:o[t%o.length]},n=[];l.forEach(function(t){n.push({label:t[r.bar_column],value:t[e]})}),a.values=n,i.push(a)}),nv.addGraph(function(){var t=nv.models.multiBarHorizontalChart().x(function(t){return t.label}).y(function(t){return t.value}).margin({top:30,right:20,bottom:50,left:leftpad}).showValues(!0).showControls(!1).stacked(stacked);return t.yAxis.tickFormat(d3.format(",.2f")),d3.select(a+" svg").datum(i).call(t),nv.utils.windowResize(t.update),t})},chartAnnotations:function(t){var w="#"+t.chart_id,n=t.x_axis_column,e=t.query_name,k=t.orientations,E=t.comment_values,r=t.group_by,a=t.comments,o=alamode.getDataFromQuery(e),C=[],l={};function i(){a.forEach(function(t,e){var a,n,r,o,l,i,d,s,c,u=C[e],m=k[e],h=E[e],p=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),f=$(w).find("g.nvd3.nv-wrap").attr("transform"),v=f.indexOf("("),g=f.indexOf(")"),x=f.indexOf(","),_=+f.slice(v+1,x),b=+f.slice(x+1,g);-1!=u&&"v"==m?(n=(a=$(w).find(".nv-point.nv-point-"+u).attr("transform")).indexOf("("),r=a.indexOf(")"),o=a.indexOf(","),l=+a.slice(n+1,o),i=+a.slice(o+1,r),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width"),(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",l+_).attr("y",b-5).attr("width",1).attr("class","flag").attr("height",5+i).attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",l+_).attr("cy",b-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide)):"h"!=m&&"h-left"!=m&&"h-right"!=m||(y="h"==m?"":"1",$(w).find("g.nv-y"+y+".nv-axis").find(".tick").each(function(t){lineLength="h-right"==m?+$(w).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(",",""))}),d=(yTrans2-yTrans1)/(yVal2-yVal1),s=yTrans2-yVal2*d+h*d,(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",_).attr("y",s+b).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",lineLength+_+10).attr("cy",s+b).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide))})}r&&(l=_.groupBy(o,function(t){return t[r]})),a.forEach(function(t,e){var a=_.filter(o,function(t){return t[n]==E[e]});pointNumber=0!=a.length?r?l[a[0][r]].indexOf(a[0]):o.indexOf(a[0]):-1,C.push(pointNumber)}),setTimeout(function(){d3.select(w).selectAll(".flag").remove(),i()},1e3),$(window).resize(function(){d3.select(w).selectAll(".flag").remove(),s(function(){i()},500,"")});var d,s=(d={},function(t,e,a){d[a=a||"Don't call this twice without a uniqueId"]&&clearTimeout(d[a]),d[a]=setTimeout(t,e)})},bulletChart:function(l){var i=alamode.makeId(10),t=l.query_name,e=l.html_element||"body",a=l.title||t,d=l.chart_width||"800",s=l.bar_column||"",c=l.marker_column||"",u=l.left_pad||150,m=l.color,n=alamode.getDataFromQuery(t),r=alamode.addContainerElement(e);d3.select(r).append("div").attr("class","mode-graphic-title").text(a),d3.select(r).append("div").attr("class","mode-bullet-chart").style("width",d).attr("id",i),n.forEach(function(t){var e=t[l.title_column]||"",a=t[l.subtitle_column]||"",n=t[l.marker_column]||"",r=t[l.bar_column]||"";scale=l.scale_columns?[t[l.scale_columns[0]],t[l.scale_columns[1]],t[l.scale_columns[2]]]:l.scale_columns;var o={title:e,subtitle:a,ranges:scale,measures:[r],measureLabels:[s],markers:[n],markerLabels:[c],color:m};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(d).margin({left:u,right:15,top:10,bottom:10});d3.select("#"+i).append("svg").style("width",d+"px").style("height","70px").style("display","inline").datum(o).transition().duration(500).call(t);return t})})},sunburstChart:function(t){var c=alamode.makeId(10),e=t.query_name,n=t.event_columns,r=t.event_counts,a=t.title||e,o=t.color_range||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],l=t.html_element||"body",d=alamode.getDataFromQuery(e),s=850,u=Math.min(s,600)/2,m={w:(s-30)/n.length,h:20,s:3,t:10},h=[];n.forEach(function(t){h=h.concat(_.uniq(_.map(d,t)))});var p=_.uniq(h),f={};p.forEach(function(t,e){null!=t&&(f[t]=o[e%o.length])}),f.end="#666";var v=0,g=alamode.addContainerElement(l);d3.select(g).append("div").attr("class","mode-graphic-title").text(a),d3.select(g).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+c),d3.select(g).append("div").attr("class","mode-sunburst").attr("id",c),d3.select(g).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+c),vis=d3.select("#"+c).append("svg:svg").attr("width",s).attr("height",600).append("svg:g").attr("transform","translate("+s/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-"+c).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-"+c).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 y=d3.layout.partition().size([2*Math.PI,u*u]).value(function(t){return t.size}),x=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)}),b=[];function w(t){var e=(100*t.value/v).toPrecision(3),a=e+"%";e<.1&&(a="< 0.1%");var n=$(t),r=t.parent.value,o=(100*t.value/r).toPrecision(3),l=o+"%";o<1&&(a="< 1%"),d3.select("#cond-percentage-"+c).text(l),d3.select("#percentage-"+c).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility","");var i,d,s,n=$(t);i=n,d=d3.select("#trail-"+c).selectAll("g").data(i,function(t){return t.name+t.depth}),(s=d.enter().append("svg:g")).append("svg:polygon").attr("points",E).style("fill",function(t){return f[t.name]}),s.append("svg:text").attr("x",(m.w+m.t)/2).attr("y",m.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),d.attr("transform",function(t,e){return 5Order: '),d3.select(_).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e);var b=d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(t){return t.z}),w=d3.select("#"+e).append("svg").attr("width",i+f+h).attr("height",d+m+p);w.call(b);var k=w.append("g").attr("transform","translate("+f+","+m+")");graph={nodes:v,links:g};var $=[],E=(v=graph.nodes).length;v.forEach(function(t,e){t.index=e,t.count=0,$[e]=d3.range(E).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){void 0!==$[t.source_id][t.target_id]?($[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):($[t.source_id][t.target_id]={},$[t.source_id][t.target_id].z=0)});var C,A={name:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node,v[e].node)}),count:d3.range(E).sort(function(t,e){return v[e].count-v[t].count}),group:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node_group,v[e].node_group)})};y.domain(A.name),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(i+f+h)/2).attr("y",25).attr("text-anchor","middle").text(u),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(d+m+p)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(c),k.append("rect").attr("class","mode-network-matrix-background").attr("width",i).attr("height",d),(C=k.selectAll(".mode-network-matrix-row").data($).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).each(C)).append("line").attr("class","mode-network-matrix-line").attr("x2",i),C.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(t,e){return v[e].node});var z=k.selectAll(".mode-network-matrix-column").data($).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"});function C(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 y(t.x)}).attr("width",y.rangeBand()).attr("height",y.rangeBand()).style("fill-opacity",function(t){return x(t.z)}).style("fill",function(t){return v[t.x].node_group==v[t.y].node_group?s[v[t.x].node_group]:"#2B2B2B"}).on("mouseover",function(t){var a;a=t,d3.selectAll(".mode-network-matrix-row-text").classed("active",function(t,e){return e==a.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(t,e){return e==a.x}),b.show(t)}).on("mouseout",function(t){d3.selectAll("text").classed("active",!1),b.hide(t)})}z.append("line").attr("class","mode-network-matrix-line").attr("x1",-i),z.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(t,e){return v[e].node}),d3.select("#mode-network-matrix-order-picker-"+e).on("change",function(){!function(t){y.domain(A[t]);var e=k.transition().duration(1e3);e.selectAll(".mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(t){return y(t.x)}),e.selectAll(".mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"})}(this.value)})},hive:function(t){d3.hive={},d3.hive.link=function(){function e(t,e){var a,n=i(d,this,t,e),r=i(s,this,t,e);n.a>r.a&&(a=r,r=n,n=a),r.a-n.a>Math.PI&&(n.a+=2*Math.PI);var o=n.a+(r.a-n.a)/3,l=r.a-(r.a-n.a)/3;return n.r0-n.r1||r.r0-r.r1?"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"L"+Math.cos(n.a)*n.r1+","+Math.sin(n.a)*n.r1+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1+"L"+Math.cos(r.a)*r.r0+","+Math.sin(r.a)*r.r0+"C"+Math.cos(l)*r.r0+","+Math.sin(l)*r.r0+" "+Math.cos(o)*n.r0+","+Math.sin(o)*n.r0+" "+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0:"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1}function i(t,e,a,n){var r=t.call(e,a,n),o=+("function"==typeof c?c.call(e,r,n):c)+h,l=+("function"==typeof u?u.call(e,r,n):u);return{r0:l,r1:u===m?l:+("function"==typeof m?m.call(e,r,n):m),a:o}}var d=function(t){return t.source},s=function(t){return t.target},c=function(t){return t.angle},u=function(t){return t.radius},m=u,h=-Math.PI/2;return e.source=function(t){return arguments.length?(d=t,e):d},e.target=function(t){return arguments.length?(s=t,e):s},e.angle=function(t){return arguments.length?(c=t,e):c},e.radius=function(t){return arguments.length?(u=m=t,e):u},e.startRadius=function(t){return arguments.length?(u=t,e):u},e.endRadius=function(t){return arguments.length?(m=t,e):m},e};var e=alamode.makeId(10),a=t.node_query,n=t.edge_query,r=t.groups_are_numeric,o=t.html_element||"body",l=t.title||queryName,i=t.chart_width||"800",d=t.chart_height||"800",s=t.group_colors||"",c=Math.min(i,d)/2-30,u=.2*c,m=alamode.getDataFromQuery(a),h=alamode.getDataFromQuery(n),p=_.uniq(_.map(m,"node_group")),f={};m.forEach(function(t){t.x=r?t.node_group:p.indexOf(t.node_group),t.y=t.node_size,f[t.node]=t}),h.forEach(function(t){t.source=f[t.source],t.target=f[t.target]});var v=alamode.addContainerElement(o);d3.select(v).append("div").attr("class","mode-graphic-title").text(l),d3.select(v).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e),angle=r?d3.scale.linear().domain(d3.extent(m,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 g=d3.scale.linear().domain(d3.extent(m,function(t){return t.node_size})).range([u,c]),y=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(t){return t.node}),x=d3.select("#"+e).append("svg").attr("width",i).attr("height",d).append("g").attr("transform","translate("+i/2+","+d/2+")");function b(t){return t/Math.PI*180-90}x.call(y),x.selectAll(".mode-hive-axis").data(d3.range(p.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(t){return"rotate("+b(angle(t))+")"}).attr("x1",g.range()[0]).attr("x2",g.range()[1]),x.selectAll(".mode-hive-link").data(h).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(t){return angle(t.x)}).radius(function(t){return g(t.y)})).style("stroke",function(t){return s[t.source.node_group]}),x.selectAll(".mode-hive-node").data(m).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(t){return"rotate("+b(angle(t.x))+")"}).attr("cx",function(t){return g(t.y)}).attr("r",5).style("fill",function(t){return s[t.node_group]}).on("mouseover",function(e){y.show(e),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(h).attr("class",function(t){return t.source.node==e.node||t.target.node==e.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(t){y.hide(t),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(n){var v="#"+n.table_id,t=n.query_name,e=n.column_rules,g=alamode.getDataFromQuery(t),y=(alamode.getColumnsFromQuery(t),{});function a(t){var e,a=$(v+" table"),n=$(v+" .js-header-table"),r=n?$(v+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),y[text]=e}),t.forEach(function(f){f.rules.forEach(function(t){var n,r,o,l,i,d,s,c,e,u,a,m,h,p=t.shade_text||!1;"gradient"==t.type?(c=f.column,e=t.color,u=p,a=d3.extent(_.map(g,c)),m=d3.scale.linear().domain(a).interpolate(d3.interpolateHsl).range(e),h=y[c],g.forEach(function(t,e){var a=v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+h+"']",n=m(t[c]),r=x(n),o=$(a);u?o.css("color",n):o.css({background:n,color:r})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(n=f.column,r=t.type,o=t.value,l=t.color,i=p,d=y[n],s=x(l),g.forEach(function(t,e){var a=$(v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+d+"']");("above"==r&&t[n]>=o||"below"==r&&t[n]<=o||"equal"==r&&t[n]==o)&&(i?a.css("color",l):a.css({background:l,color:s}))}))})})}function x(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){a(e)},1e3),$(v).mousemove(function(){a(e)})},customizeTable:function(t){window.dispatchAction({type:"Embed.AlamodeCustomizeTable",payload:t})},conditionalFormattingByTable:function(n){var m="#"+n.table_id,t=n.query_name,h=n.columns;rules=n.rules;var p=alamode.getDataFromQuery(t),f=(alamode.getColumnsFromQuery(t),{}),a=[];h.forEach(function(t){var e=d3.extent(_.map(p,t));a=a.concat(e)});var v=d3.extent(a);function e(t){var e,a=$(m+" table"),n=$(m+" .js-header-table"),r=n?$(m+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),f[text]=e}),t.forEach(function(t){var o,l,i,d,s,e,c,u,a=t.shade_text||!1;"gradient"==t.type?(e=t.color,c=a,u=d3.scale.linear().domain(v).interpolate(d3.interpolateHsl).range(e),p.forEach(function(l,i){h.forEach(function(t){var e=f[t],a=m+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+e+"']",n=u(l[t]),r=g(n),o=$(a);c?o.css("color",n):o.css({background:n,color:r})})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(o=t.type,l=t.value,i=t.color,d=a,s=g(i),p.forEach(function(n,r){h.forEach(function(t){var e=f[t],a=$(m+" table [data-axel-rowkey='"+r+"'][data-axel-column='"+e+"']");("above"==o&&n[t]>=l||"below"==o&&n[t]<=l||"equal"==o&&n[t]==l)&&(d?a.css("color",i):a.css({background:i,color:s}))})}))})}function g(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){e(rules)},1e3),$(m).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,a=$(this).find("mode-chart").attr("id")||$(this).find("mode-table").attr("id")||$(this).find("mode-python").attr("id");if(!a)return!0;a.includes("chart")||a.includes("table")?(t=document.getElementById(a),e=0<$(t).find("mode-pivot-table").length?document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText:document.getElementById(a).getElementsByClassName("chart-title")[0].innerText):a.includes("python")&&(e=document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText);var n=$(""+(e.includes("Click to add title")?"Untitled":e)+"");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(){$(".scroll-link").on("click",function(t){t.preventDefault();var e,a,n=$(this).attr("href");e=750,a=$(n).offset().top-50,$("html,body").animate({scrollTop:a},e)})},100)},xAnnotations:function(t){var a=t.chart_id,r=t.comment_values,o=t.comments,l=t.color||[],d=t.is_date||!1;setTimeout(function(){var e=$("#"+a).find("div.highcharts-container")[0].id,t=Highcharts.charts;if(chart=t.filter(function(t){if(t)return t.container.id==e})[0],data=chart.series[0].data,d)for(i=0;i Date: Tue, 24 Nov 2020 15:35:02 -0500 Subject: [PATCH 2/4] Fixed bug. --- alamode.js | 2 +- alamode.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/alamode.js b/alamode.js index 0fdb732..9ad4528 100644 --- a/alamode.js +++ b/alamode.js @@ -847,7 +847,7 @@ var alamode = { if (!column) throw new Error("Colum data isn't passed properly."); return heatmapColumnRules({ name: typeof column === 'string' ? column : (column || {}).name, - color_gradient: columnData.color_gradient || defaultColorGradients[index % defaultColorGradients.length], + color_gradient: column.color_gradient || defaultColorGradients[index % defaultColorGradients.length], inverse: column.inverse }, dataset[0], function (row) { return row[column] }) }) diff --git a/alamode.min.js b/alamode.min.js index db64cab..e45b718 100644 --- a/alamode.min.js +++ b/alamode.min.js @@ -1 +1 @@ -var version="0.23",alamode={reportError:function(t){$("

").text(t).prependTo(document.body)},getColumnsFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.columns:(alamode.reportError("No such query: '"+e+"'"),[])},getDataFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.content:(alamode.reportError("No such query: '"+e+"'"),[])},makeId:function(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",a="",n=0;n").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content"):0===$(t).length?alamode.reportError("No such element: '"+t+"'"):(e&&$(t).empty(),$(t).addClass("mode-graphic-container"),$(t).addClass(id)),"."+id},addLinksToTables:function(t){var l="#"+t.table_id,e=t.link_columns,a=t.link_urls,n=t.query_name,m=t.open_in_new_tab||!1,r=[],h={};e.forEach(function(t,e){r.push({column:t,link_string:a[e]})});var p=alamode.getDataFromQuery(n);alamode.getColumnsFromQuery(n);function o(e){var t,a=$(l+" table"),n=$(l+" .js-header-table"),r=n?$(l+" .js-col-header"):$(n).find("th"),o=a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),t=$(this).attr("data-axel-column"),h[text]=t-1}),o.each(function(t){var c,u;0"+a+"";c.eq(e).html(s)}))})}setTimeout(function(){o(r)},1e3),$(l).mousemove(function(){o(r)})},customChartColors:function(t){var e=t.charts,n=t.colors,d=t.opacity,s=t.line_dashes;function h(t,e){var a=$("#"+t),n=(0TTL",u.forEach(function(t){""!=t.total?e=e+""+s(t.total)+"":e+=""}),e+""),n=+container.css("height").match(/\d+/)[0];t.after(a),container.css("height",26+n)},1e3)},addImagesToTables:function(t){var o="#"+t.table,l=t.column,i=t.image_height||100;function e(){var t=$(o+" table"),e=$(o+" .js-header-table"),a=e?$(o+" .js-col-header"):$(e).find("th"),n=t.find("tr"),r=0;a.each(function(){text=$(this).find(".axel-table-header-label").text(),text==l&&(r=+$(this).attr("data-axel-column"))}),n.each(function(){$(this).find("td").each(function(t){var e;t==r-1&&(e=$(this).text(),0==$(this).find("img").length&&($(this).css("text-align","center"),$(this).html("")))})})}setTimeout(function(){e()},1e3),$(o).keyup(function(){setTimeout(function(){e()},500)}),$(o).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){var a,n,r,e=t.query_name,i=t.cohort_column,d=t.pivot_column,s=t.value_column,o=t.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],l=t.gradient_by||"all",c=t.gradient_column||s,u=t.total_column,m=t.html_element||"body",h=t.title||e,p=t.pivot_label||"",f=t.value_is_percent,v=t.precision||0,g=alamode.getDataFromQuery(e),y=alamode.getColumnsFromQuery(e),x=_.uniq(_.map(g,i)),b=_.sortBy(_.uniq(_.map(g,d))),w=alamode.addContainerElement(m);"cohort_column"===l?(a={},x.forEach(function(e){var t=g.filter(function(t){return t[i]===e});a[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):"pivot_column"===l?(n={},b.forEach(function(e){var t=g.filter(function(t){return t[d]===e});n[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):r=d3.scale.quantize().domain(d3.extent(g,function(t){return t[c]})).range(o),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 k=d3.select(w).append("table").attr("class","mode-retention-heatmap-table");function $(e){return y.filter(function(t){return t.name==e})[0].type}k.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}),k.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 function(r,o){var l=[{column:i,value:o}];{var t,e;u&&(t=_.filter(r,function(t){return t[i]==o})[0],e={column:u,value:t[u]},l=l.concat(e))}return b.forEach(function(e){var t="",a="",n=_.filter(r,function(t){return t[i]==o&&t[d]==e});0=",value:o,color:r[r.length-1]})}}alamode.customizeTable([{vizId:e.vizId,formatByColumn:{columns:(e.columns||[]).map(function(e,t){if(!e)throw new Error("Colum data isn't passed properly.");return r({name:"string"==typeof e?e:(e||{}).name,color_gradient:columnData.color_gradient||n[t%n.length],inverse:e.inverse},a[0],function(t){return t[e]})})}}])},googleMap:function(t){var e=alamode.makeId(10),l=t.lat_column,i=t.lng_column,a=t.query_name,n=t.google_maps_api_key,r=t.title||a,d=t.label_column,o=t.html_element||"body",s=t.center_lat||39.5,c=t.center_lng||-98.35,u=t.starting_zoom||4,m=t.map_type||"terrain",h=t.height||600,p=alamode.getDataFromQuery(a),f=alamode.addContainerElement(o);d3.select(f).append("div").attr("class","mode-graphic-title").text(r),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="+n,function(){var t,o;t={zoom:u,center:new google.maps.LatLng(s,c),mapTypeId:m},o=new google.maps.Map(document.getElementById(e),t),p.forEach(function(t){var e=t[l],a=t[i];label=d?t[d]:"";var n=new google.maps.Marker({position:{lat:e,lng:a},map:o,title:label}),r=new google.maps.InfoWindow({content:label});n.addListener("click",function(){r.open(o,n)})})})},leafletMap:function(t){var e=alamode.makeId(10),a=t.lat_column,n=t.lng_column,r=t.query_name,o=t.title||r,l=t.height||400,i=t.html_element||"body",d=t.center_lat||39.5,s=t.center_lng||-98.35,c=t.starting_zoom||4,u=t.dot_size||.4,m=t.dot_opacity||.8,h=t.apply_filter||!1,p=alamode.getDataFromQuery(r),f=[];p.forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&f.push(t)});var v=alamode.addContainerElement(i,h);d3.select(v).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o);var g=l-$(v+".mode-graphic-title").height(),y=$(v).width();d3.select(v).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",g+"px").style("width",y+"px");var x=L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18}),_={max:8,data:f},b={lat:d,lng:s,zoom:c},w=new HeatmapOverlay({radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n});new L.Map(e,{center:new L.LatLng(b.lat,b.lng),zoom:Math.floor(b.zoom),layers:[x,w]});w.setData(_)},wordCloud:function(t){var e=t.query_name,a=t.word_column,n=t.word_count_column,r=t.html_element||"body",o=t.title||e,l=t.height||"400",i=t.width||"800",d=t.colors||["black"],s=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(s,function(t){return t[n]})).range([12,60]),m=d3.layout.cloud().size([i,l]).words(s.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 d[e%d.length]}).attr("text-anchor","middle").attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).text(function(t){return t.text})});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",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]])});new D3Funnel("#"+e).draw(u,{label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100}),d3.select("#"+e).style("height",i+"px")},horizontalBarChart:function(r){var t=r.query_name,e=(r.bar_column,r.series_columns),o=r.colors||["#EE8D24","#43A5DA","#6AB328","#BB60F8","#E14459","#EAD022","#06D0AD","#DB38B7"];stacked=r.stacked||!1,leftpad=r.left_pad||175,htmlElement=r.html_element||"body",title=r.title||t,height=r.chart_height||395,width=r.width||"500";var l=alamode.getDataFromQuery(t),a=alamode.addContainerElement(htmlElement);d3.select(a).append("div").attr("class","mode-graphic-title").text(title),d3.select(a).append("div").attr("class","mode-horizontal-bar-chart").style("height",height-50+"px").append("svg");var i=[];e.forEach(function(e,t){var a={key:e,color:o[t%o.length]},n=[];l.forEach(function(t){n.push({label:t[r.bar_column],value:t[e]})}),a.values=n,i.push(a)}),nv.addGraph(function(){var t=nv.models.multiBarHorizontalChart().x(function(t){return t.label}).y(function(t){return t.value}).margin({top:30,right:20,bottom:50,left:leftpad}).showValues(!0).showControls(!1).stacked(stacked);return t.yAxis.tickFormat(d3.format(",.2f")),d3.select(a+" svg").datum(i).call(t),nv.utils.windowResize(t.update),t})},chartAnnotations:function(t){var w="#"+t.chart_id,n=t.x_axis_column,e=t.query_name,k=t.orientations,E=t.comment_values,r=t.group_by,a=t.comments,o=alamode.getDataFromQuery(e),C=[],l={};function i(){a.forEach(function(t,e){var a,n,r,o,l,i,d,s,c,u=C[e],m=k[e],h=E[e],p=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),f=$(w).find("g.nvd3.nv-wrap").attr("transform"),v=f.indexOf("("),g=f.indexOf(")"),x=f.indexOf(","),_=+f.slice(v+1,x),b=+f.slice(x+1,g);-1!=u&&"v"==m?(n=(a=$(w).find(".nv-point.nv-point-"+u).attr("transform")).indexOf("("),r=a.indexOf(")"),o=a.indexOf(","),l=+a.slice(n+1,o),i=+a.slice(o+1,r),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width"),(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",l+_).attr("y",b-5).attr("width",1).attr("class","flag").attr("height",5+i).attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",l+_).attr("cy",b-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide)):"h"!=m&&"h-left"!=m&&"h-right"!=m||(y="h"==m?"":"1",$(w).find("g.nv-y"+y+".nv-axis").find(".tick").each(function(t){lineLength="h-right"==m?+$(w).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(",",""))}),d=(yTrans2-yTrans1)/(yVal2-yVal1),s=yTrans2-yVal2*d+h*d,(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",_).attr("y",s+b).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",lineLength+_+10).attr("cy",s+b).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide))})}r&&(l=_.groupBy(o,function(t){return t[r]})),a.forEach(function(t,e){var a=_.filter(o,function(t){return t[n]==E[e]});pointNumber=0!=a.length?r?l[a[0][r]].indexOf(a[0]):o.indexOf(a[0]):-1,C.push(pointNumber)}),setTimeout(function(){d3.select(w).selectAll(".flag").remove(),i()},1e3),$(window).resize(function(){d3.select(w).selectAll(".flag").remove(),s(function(){i()},500,"")});var d,s=(d={},function(t,e,a){d[a=a||"Don't call this twice without a uniqueId"]&&clearTimeout(d[a]),d[a]=setTimeout(t,e)})},bulletChart:function(l){var i=alamode.makeId(10),t=l.query_name,e=l.html_element||"body",a=l.title||t,d=l.chart_width||"800",s=l.bar_column||"",c=l.marker_column||"",u=l.left_pad||150,m=l.color,n=alamode.getDataFromQuery(t),r=alamode.addContainerElement(e);d3.select(r).append("div").attr("class","mode-graphic-title").text(a),d3.select(r).append("div").attr("class","mode-bullet-chart").style("width",d).attr("id",i),n.forEach(function(t){var e=t[l.title_column]||"",a=t[l.subtitle_column]||"",n=t[l.marker_column]||"",r=t[l.bar_column]||"";scale=l.scale_columns?[t[l.scale_columns[0]],t[l.scale_columns[1]],t[l.scale_columns[2]]]:l.scale_columns;var o={title:e,subtitle:a,ranges:scale,measures:[r],measureLabels:[s],markers:[n],markerLabels:[c],color:m};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(d).margin({left:u,right:15,top:10,bottom:10});d3.select("#"+i).append("svg").style("width",d+"px").style("height","70px").style("display","inline").datum(o).transition().duration(500).call(t);return t})})},sunburstChart:function(t){var c=alamode.makeId(10),e=t.query_name,n=t.event_columns,r=t.event_counts,a=t.title||e,o=t.color_range||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],l=t.html_element||"body",d=alamode.getDataFromQuery(e),s=850,u=Math.min(s,600)/2,m={w:(s-30)/n.length,h:20,s:3,t:10},h=[];n.forEach(function(t){h=h.concat(_.uniq(_.map(d,t)))});var p=_.uniq(h),f={};p.forEach(function(t,e){null!=t&&(f[t]=o[e%o.length])}),f.end="#666";var v=0,g=alamode.addContainerElement(l);d3.select(g).append("div").attr("class","mode-graphic-title").text(a),d3.select(g).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+c),d3.select(g).append("div").attr("class","mode-sunburst").attr("id",c),d3.select(g).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+c),vis=d3.select("#"+c).append("svg:svg").attr("width",s).attr("height",600).append("svg:g").attr("transform","translate("+s/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-"+c).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-"+c).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 y=d3.layout.partition().size([2*Math.PI,u*u]).value(function(t){return t.size}),x=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)}),b=[];function w(t){var e=(100*t.value/v).toPrecision(3),a=e+"%";e<.1&&(a="< 0.1%");var n=$(t),r=t.parent.value,o=(100*t.value/r).toPrecision(3),l=o+"%";o<1&&(a="< 1%"),d3.select("#cond-percentage-"+c).text(l),d3.select("#percentage-"+c).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility","");var i,d,s,n=$(t);i=n,d=d3.select("#trail-"+c).selectAll("g").data(i,function(t){return t.name+t.depth}),(s=d.enter().append("svg:g")).append("svg:polygon").attr("points",E).style("fill",function(t){return f[t.name]}),s.append("svg:text").attr("x",(m.w+m.t)/2).attr("y",m.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),d.attr("transform",function(t,e){return 5Order: '),d3.select(_).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e);var b=d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(t){return t.z}),w=d3.select("#"+e).append("svg").attr("width",i+f+h).attr("height",d+m+p);w.call(b);var k=w.append("g").attr("transform","translate("+f+","+m+")");graph={nodes:v,links:g};var $=[],E=(v=graph.nodes).length;v.forEach(function(t,e){t.index=e,t.count=0,$[e]=d3.range(E).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){void 0!==$[t.source_id][t.target_id]?($[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):($[t.source_id][t.target_id]={},$[t.source_id][t.target_id].z=0)});var C,A={name:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node,v[e].node)}),count:d3.range(E).sort(function(t,e){return v[e].count-v[t].count}),group:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node_group,v[e].node_group)})};y.domain(A.name),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(i+f+h)/2).attr("y",25).attr("text-anchor","middle").text(u),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(d+m+p)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(c),k.append("rect").attr("class","mode-network-matrix-background").attr("width",i).attr("height",d),(C=k.selectAll(".mode-network-matrix-row").data($).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).each(C)).append("line").attr("class","mode-network-matrix-line").attr("x2",i),C.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(t,e){return v[e].node});var F=k.selectAll(".mode-network-matrix-column").data($).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"});function C(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 y(t.x)}).attr("width",y.rangeBand()).attr("height",y.rangeBand()).style("fill-opacity",function(t){return x(t.z)}).style("fill",function(t){return v[t.x].node_group==v[t.y].node_group?s[v[t.x].node_group]:"#2B2B2B"}).on("mouseover",function(t){var a;a=t,d3.selectAll(".mode-network-matrix-row-text").classed("active",function(t,e){return e==a.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(t,e){return e==a.x}),b.show(t)}).on("mouseout",function(t){d3.selectAll("text").classed("active",!1),b.hide(t)})}F.append("line").attr("class","mode-network-matrix-line").attr("x1",-i),F.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(t,e){return v[e].node}),d3.select("#mode-network-matrix-order-picker-"+e).on("change",function(){!function(t){y.domain(A[t]);var e=k.transition().duration(1e3);e.selectAll(".mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(t){return y(t.x)}),e.selectAll(".mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"})}(this.value)})},hive:function(t){d3.hive={},d3.hive.link=function(){function e(t,e){var a,n=i(d,this,t,e),r=i(s,this,t,e);n.a>r.a&&(a=r,r=n,n=a),r.a-n.a>Math.PI&&(n.a+=2*Math.PI);var o=n.a+(r.a-n.a)/3,l=r.a-(r.a-n.a)/3;return n.r0-n.r1||r.r0-r.r1?"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"L"+Math.cos(n.a)*n.r1+","+Math.sin(n.a)*n.r1+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1+"L"+Math.cos(r.a)*r.r0+","+Math.sin(r.a)*r.r0+"C"+Math.cos(l)*r.r0+","+Math.sin(l)*r.r0+" "+Math.cos(o)*n.r0+","+Math.sin(o)*n.r0+" "+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0:"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1}function i(t,e,a,n){var r=t.call(e,a,n),o=+("function"==typeof c?c.call(e,r,n):c)+h,l=+("function"==typeof u?u.call(e,r,n):u);return{r0:l,r1:u===m?l:+("function"==typeof m?m.call(e,r,n):m),a:o}}var d=function(t){return t.source},s=function(t){return t.target},c=function(t){return t.angle},u=function(t){return t.radius},m=u,h=-Math.PI/2;return e.source=function(t){return arguments.length?(d=t,e):d},e.target=function(t){return arguments.length?(s=t,e):s},e.angle=function(t){return arguments.length?(c=t,e):c},e.radius=function(t){return arguments.length?(u=m=t,e):u},e.startRadius=function(t){return arguments.length?(u=t,e):u},e.endRadius=function(t){return arguments.length?(m=t,e):m},e};var e=alamode.makeId(10),a=t.node_query,n=t.edge_query,r=t.groups_are_numeric,o=t.html_element||"body",l=t.title||queryName,i=t.chart_width||"800",d=t.chart_height||"800",s=t.group_colors||"",c=Math.min(i,d)/2-30,u=.2*c,m=alamode.getDataFromQuery(a),h=alamode.getDataFromQuery(n),p=_.uniq(_.map(m,"node_group")),f={};m.forEach(function(t){t.x=r?t.node_group:p.indexOf(t.node_group),t.y=t.node_size,f[t.node]=t}),h.forEach(function(t){t.source=f[t.source],t.target=f[t.target]});var v=alamode.addContainerElement(o);d3.select(v).append("div").attr("class","mode-graphic-title").text(l),d3.select(v).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e),angle=r?d3.scale.linear().domain(d3.extent(m,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 g=d3.scale.linear().domain(d3.extent(m,function(t){return t.node_size})).range([u,c]),y=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(t){return t.node}),x=d3.select("#"+e).append("svg").attr("width",i).attr("height",d).append("g").attr("transform","translate("+i/2+","+d/2+")");function b(t){return t/Math.PI*180-90}x.call(y),x.selectAll(".mode-hive-axis").data(d3.range(p.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(t){return"rotate("+b(angle(t))+")"}).attr("x1",g.range()[0]).attr("x2",g.range()[1]),x.selectAll(".mode-hive-link").data(h).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(t){return angle(t.x)}).radius(function(t){return g(t.y)})).style("stroke",function(t){return s[t.source.node_group]}),x.selectAll(".mode-hive-node").data(m).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(t){return"rotate("+b(angle(t.x))+")"}).attr("cx",function(t){return g(t.y)}).attr("r",5).style("fill",function(t){return s[t.node_group]}).on("mouseover",function(e){y.show(e),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(h).attr("class",function(t){return t.source.node==e.node||t.target.node==e.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(t){y.hide(t),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(n){var v="#"+n.table_id,t=n.query_name,e=n.column_rules,g=alamode.getDataFromQuery(t),y=(alamode.getColumnsFromQuery(t),{});function a(t){var e,a=$(v+" table"),n=$(v+" .js-header-table"),r=n?$(v+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),y[text]=e}),t.forEach(function(f){f.rules.forEach(function(t){var n,r,o,l,i,d,s,c,e,u,a,m,h,p=t.shade_text||!1;"gradient"==t.type?(c=f.column,e=t.color,u=p,a=d3.extent(_.map(g,c)),m=d3.scale.linear().domain(a).interpolate(d3.interpolateHsl).range(e),h=y[c],g.forEach(function(t,e){var a=v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+h+"']",n=m(t[c]),r=x(n),o=$(a);u?o.css("color",n):o.css({background:n,color:r})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(n=f.column,r=t.type,o=t.value,l=t.color,i=p,d=y[n],s=x(l),g.forEach(function(t,e){var a=$(v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+d+"']");("above"==r&&t[n]>=o||"below"==r&&t[n]<=o||"equal"==r&&t[n]==o)&&(i?a.css("color",l):a.css({background:l,color:s}))}))})})}function x(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){a(e)},1e3),$(v).mousemove(function(){a(e)})},customizeTable:function(t){window.dispatchAction({type:"Embed.AlamodeCustomizeTable",payload:t})},conditionalFormattingByTable:function(n){var m="#"+n.table_id,t=n.query_name,h=n.columns;rules=n.rules;var p=alamode.getDataFromQuery(t),f=(alamode.getColumnsFromQuery(t),{}),a=[];h.forEach(function(t){var e=d3.extent(_.map(p,t));a=a.concat(e)});var v=d3.extent(a);function e(t){var e,a=$(m+" table"),n=$(m+" .js-header-table"),r=n?$(m+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),f[text]=e}),t.forEach(function(t){var o,l,i,d,s,e,c,u,a=t.shade_text||!1;"gradient"==t.type?(e=t.color,c=a,u=d3.scale.linear().domain(v).interpolate(d3.interpolateHsl).range(e),p.forEach(function(l,i){h.forEach(function(t){var e=f[t],a=m+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+e+"']",n=u(l[t]),r=g(n),o=$(a);c?o.css("color",n):o.css({background:n,color:r})})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(o=t.type,l=t.value,i=t.color,d=a,s=g(i),p.forEach(function(n,r){h.forEach(function(t){var e=f[t],a=$(m+" table [data-axel-rowkey='"+r+"'][data-axel-column='"+e+"']");("above"==o&&n[t]>=l||"below"==o&&n[t]<=l||"equal"==o&&n[t]==l)&&(d?a.css("color",i):a.css({background:i,color:s}))})}))})}function g(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){e(rules)},1e3),$(m).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,a=$(this).find("mode-chart").attr("id")||$(this).find("mode-table").attr("id")||$(this).find("mode-python").attr("id");if(!a)return!0;a.includes("chart")||a.includes("table")?(t=document.getElementById(a),e=0<$(t).find("mode-pivot-table").length?document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText:document.getElementById(a).getElementsByClassName("chart-title")[0].innerText):a.includes("python")&&(e=document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText);var n=$(""+(e.includes("Click to add title")?"Untitled":e)+"");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(){$(".scroll-link").on("click",function(t){t.preventDefault();var e,a,n=$(this).attr("href");e=750,a=$(n).offset().top-50,$("html,body").animate({scrollTop:a},e)})},100)},xAnnotations:function(t){var a=t.chart_id,r=t.comment_values,o=t.comments,l=t.color||[],d=t.is_date||!1;setTimeout(function(){var e=$("#"+a).find("div.highcharts-container")[0].id,t=Highcharts.charts;if(chart=t.filter(function(t){if(t)return t.container.id==e})[0],data=chart.series[0].data,d)for(i=0;i").text(t).prependTo(document.body)},getColumnsFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.columns:(alamode.reportError("No such query: '"+e+"'"),[])},getDataFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.content:(alamode.reportError("No such query: '"+e+"'"),[])},makeId:function(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",a="",n=0;n").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content"):0===$(t).length?alamode.reportError("No such element: '"+t+"'"):(e&&$(t).empty(),$(t).addClass("mode-graphic-container"),$(t).addClass(id)),"."+id},addLinksToTables:function(t){var l="#"+t.table_id,e=t.link_columns,a=t.link_urls,n=t.query_name,m=t.open_in_new_tab||!1,r=[],h={};e.forEach(function(t,e){r.push({column:t,link_string:a[e]})});var p=alamode.getDataFromQuery(n);alamode.getColumnsFromQuery(n);function o(e){var t,a=$(l+" table"),n=$(l+" .js-header-table"),r=n?$(l+" .js-col-header"):$(n).find("th"),o=a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),t=$(this).attr("data-axel-column"),h[text]=t-1}),o.each(function(t){var c,u;0"+a+"";c.eq(e).html(s)}))})}setTimeout(function(){o(r)},1e3),$(l).mousemove(function(){o(r)})},customChartColors:function(t){var e=t.charts,n=t.colors,d=t.opacity,s=t.line_dashes;function h(t,e){var a=$("#"+t),n=(0TTL",u.forEach(function(t){""!=t.total?e=e+""+s(t.total)+"":e+=""}),e+""),n=+container.css("height").match(/\d+/)[0];t.after(a),container.css("height",26+n)},1e3)},addImagesToTables:function(t){var o="#"+t.table,l=t.column,i=t.image_height||100;function e(){var t=$(o+" table"),e=$(o+" .js-header-table"),a=e?$(o+" .js-col-header"):$(e).find("th"),n=t.find("tr"),r=0;a.each(function(){text=$(this).find(".axel-table-header-label").text(),text==l&&(r=+$(this).attr("data-axel-column"))}),n.each(function(){$(this).find("td").each(function(t){var e;t==r-1&&(e=$(this).text(),0==$(this).find("img").length&&($(this).css("text-align","center"),$(this).html("")))})})}setTimeout(function(){e()},1e3),$(o).keyup(function(){setTimeout(function(){e()},500)}),$(o).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){var a,n,r,e=t.query_name,i=t.cohort_column,d=t.pivot_column,s=t.value_column,o=t.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],l=t.gradient_by||"all",c=t.gradient_column||s,u=t.total_column,m=t.html_element||"body",h=t.title||e,p=t.pivot_label||"",f=t.value_is_percent,v=t.precision||0,g=alamode.getDataFromQuery(e),y=alamode.getColumnsFromQuery(e),x=_.uniq(_.map(g,i)),b=_.sortBy(_.uniq(_.map(g,d))),w=alamode.addContainerElement(m);"cohort_column"===l?(a={},x.forEach(function(e){var t=g.filter(function(t){return t[i]===e});a[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):"pivot_column"===l?(n={},b.forEach(function(e){var t=g.filter(function(t){return t[d]===e});n[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):r=d3.scale.quantize().domain(d3.extent(g,function(t){return t[c]})).range(o),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 k=d3.select(w).append("table").attr("class","mode-retention-heatmap-table");function $(e){return y.filter(function(t){return t.name==e})[0].type}k.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}),k.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 function(r,o){var l=[{column:i,value:o}];{var t,e;u&&(t=_.filter(r,function(t){return t[i]==o})[0],e={column:u,value:t[u]},l=l.concat(e))}return b.forEach(function(e){var t="",a="",n=_.filter(r,function(t){return t[i]==o&&t[d]==e});0=",value:o,color:r[r.length-1]})}}alamode.customizeTable([{vizId:e.vizId,formatByColumn:{columns:(e.columns||[]).map(function(e,t){if(!e)throw new Error("Colum data isn't passed properly.");return r({name:"string"==typeof e?e:(e||{}).name,color_gradient:e.color_gradient||n[t%n.length],inverse:e.inverse},a[0],function(t){return t[e]})})}}])},googleMap:function(t){var e=alamode.makeId(10),l=t.lat_column,i=t.lng_column,a=t.query_name,n=t.google_maps_api_key,r=t.title||a,d=t.label_column,o=t.html_element||"body",s=t.center_lat||39.5,c=t.center_lng||-98.35,u=t.starting_zoom||4,m=t.map_type||"terrain",h=t.height||600,p=alamode.getDataFromQuery(a),f=alamode.addContainerElement(o);d3.select(f).append("div").attr("class","mode-graphic-title").text(r),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="+n,function(){var t,o;t={zoom:u,center:new google.maps.LatLng(s,c),mapTypeId:m},o=new google.maps.Map(document.getElementById(e),t),p.forEach(function(t){var e=t[l],a=t[i];label=d?t[d]:"";var n=new google.maps.Marker({position:{lat:e,lng:a},map:o,title:label}),r=new google.maps.InfoWindow({content:label});n.addListener("click",function(){r.open(o,n)})})})},leafletMap:function(t){var e=alamode.makeId(10),a=t.lat_column,n=t.lng_column,r=t.query_name,o=t.title||r,l=t.height||400,i=t.html_element||"body",d=t.center_lat||39.5,s=t.center_lng||-98.35,c=t.starting_zoom||4,u=t.dot_size||.4,m=t.dot_opacity||.8,h=t.apply_filter||!1,p=alamode.getDataFromQuery(r),f=[];p.forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&f.push(t)});var v=alamode.addContainerElement(i,h);d3.select(v).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o);var g=l-$(v+".mode-graphic-title").height(),y=$(v).width();d3.select(v).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",g+"px").style("width",y+"px");var x=L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18}),_={max:8,data:f},b={lat:d,lng:s,zoom:c},w=new HeatmapOverlay({radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n});new L.Map(e,{center:new L.LatLng(b.lat,b.lng),zoom:Math.floor(b.zoom),layers:[x,w]});w.setData(_)},wordCloud:function(t){var e=t.query_name,a=t.word_column,n=t.word_count_column,r=t.html_element||"body",o=t.title||e,l=t.height||"400",i=t.width||"800",d=t.colors||["black"],s=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(s,function(t){return t[n]})).range([12,60]),m=d3.layout.cloud().size([i,l]).words(s.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 d[e%d.length]}).attr("text-anchor","middle").attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).text(function(t){return t.text})});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",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]])});new D3Funnel("#"+e).draw(u,{label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100}),d3.select("#"+e).style("height",i+"px")},horizontalBarChart:function(r){var t=r.query_name,e=(r.bar_column,r.series_columns),o=r.colors||["#EE8D24","#43A5DA","#6AB328","#BB60F8","#E14459","#EAD022","#06D0AD","#DB38B7"];stacked=r.stacked||!1,leftpad=r.left_pad||175,htmlElement=r.html_element||"body",title=r.title||t,height=r.chart_height||395,width=r.width||"500";var l=alamode.getDataFromQuery(t),a=alamode.addContainerElement(htmlElement);d3.select(a).append("div").attr("class","mode-graphic-title").text(title),d3.select(a).append("div").attr("class","mode-horizontal-bar-chart").style("height",height-50+"px").append("svg");var i=[];e.forEach(function(e,t){var a={key:e,color:o[t%o.length]},n=[];l.forEach(function(t){n.push({label:t[r.bar_column],value:t[e]})}),a.values=n,i.push(a)}),nv.addGraph(function(){var t=nv.models.multiBarHorizontalChart().x(function(t){return t.label}).y(function(t){return t.value}).margin({top:30,right:20,bottom:50,left:leftpad}).showValues(!0).showControls(!1).stacked(stacked);return t.yAxis.tickFormat(d3.format(",.2f")),d3.select(a+" svg").datum(i).call(t),nv.utils.windowResize(t.update),t})},chartAnnotations:function(t){var w="#"+t.chart_id,n=t.x_axis_column,e=t.query_name,k=t.orientations,E=t.comment_values,r=t.group_by,a=t.comments,o=alamode.getDataFromQuery(e),C=[],l={};function i(){a.forEach(function(t,e){var a,n,r,o,l,i,d,s,c,u=C[e],m=k[e],h=E[e],p=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),f=$(w).find("g.nvd3.nv-wrap").attr("transform"),v=f.indexOf("("),g=f.indexOf(")"),x=f.indexOf(","),_=+f.slice(v+1,x),b=+f.slice(x+1,g);-1!=u&&"v"==m?(n=(a=$(w).find(".nv-point.nv-point-"+u).attr("transform")).indexOf("("),r=a.indexOf(")"),o=a.indexOf(","),l=+a.slice(n+1,o),i=+a.slice(o+1,r),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width"),(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",l+_).attr("y",b-5).attr("width",1).attr("class","flag").attr("height",5+i).attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",l+_).attr("cy",b-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide)):"h"!=m&&"h-left"!=m&&"h-right"!=m||(y="h"==m?"":"1",$(w).find("g.nv-y"+y+".nv-axis").find(".tick").each(function(t){lineLength="h-right"==m?+$(w).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(",",""))}),d=(yTrans2-yTrans1)/(yVal2-yVal1),s=yTrans2-yVal2*d+h*d,(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",_).attr("y",s+b).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",lineLength+_+10).attr("cy",s+b).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide))})}r&&(l=_.groupBy(o,function(t){return t[r]})),a.forEach(function(t,e){var a=_.filter(o,function(t){return t[n]==E[e]});pointNumber=0!=a.length?r?l[a[0][r]].indexOf(a[0]):o.indexOf(a[0]):-1,C.push(pointNumber)}),setTimeout(function(){d3.select(w).selectAll(".flag").remove(),i()},1e3),$(window).resize(function(){d3.select(w).selectAll(".flag").remove(),s(function(){i()},500,"")});var d,s=(d={},function(t,e,a){d[a=a||"Don't call this twice without a uniqueId"]&&clearTimeout(d[a]),d[a]=setTimeout(t,e)})},bulletChart:function(l){var i=alamode.makeId(10),t=l.query_name,e=l.html_element||"body",a=l.title||t,d=l.chart_width||"800",s=l.bar_column||"",c=l.marker_column||"",u=l.left_pad||150,m=l.color,n=alamode.getDataFromQuery(t),r=alamode.addContainerElement(e);d3.select(r).append("div").attr("class","mode-graphic-title").text(a),d3.select(r).append("div").attr("class","mode-bullet-chart").style("width",d).attr("id",i),n.forEach(function(t){var e=t[l.title_column]||"",a=t[l.subtitle_column]||"",n=t[l.marker_column]||"",r=t[l.bar_column]||"";scale=l.scale_columns?[t[l.scale_columns[0]],t[l.scale_columns[1]],t[l.scale_columns[2]]]:l.scale_columns;var o={title:e,subtitle:a,ranges:scale,measures:[r],measureLabels:[s],markers:[n],markerLabels:[c],color:m};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(d).margin({left:u,right:15,top:10,bottom:10});d3.select("#"+i).append("svg").style("width",d+"px").style("height","70px").style("display","inline").datum(o).transition().duration(500).call(t);return t})})},sunburstChart:function(t){var c=alamode.makeId(10),e=t.query_name,n=t.event_columns,r=t.event_counts,a=t.title||e,o=t.color_range||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],l=t.html_element||"body",d=alamode.getDataFromQuery(e),s=850,u=Math.min(s,600)/2,m={w:(s-30)/n.length,h:20,s:3,t:10},h=[];n.forEach(function(t){h=h.concat(_.uniq(_.map(d,t)))});var p=_.uniq(h),f={};p.forEach(function(t,e){null!=t&&(f[t]=o[e%o.length])}),f.end="#666";var v=0,g=alamode.addContainerElement(l);d3.select(g).append("div").attr("class","mode-graphic-title").text(a),d3.select(g).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+c),d3.select(g).append("div").attr("class","mode-sunburst").attr("id",c),d3.select(g).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+c),vis=d3.select("#"+c).append("svg:svg").attr("width",s).attr("height",600).append("svg:g").attr("transform","translate("+s/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-"+c).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-"+c).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 y=d3.layout.partition().size([2*Math.PI,u*u]).value(function(t){return t.size}),x=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)}),b=[];function w(t){var e=(100*t.value/v).toPrecision(3),a=e+"%";e<.1&&(a="< 0.1%");var n=$(t),r=t.parent.value,o=(100*t.value/r).toPrecision(3),l=o+"%";o<1&&(a="< 1%"),d3.select("#cond-percentage-"+c).text(l),d3.select("#percentage-"+c).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility","");var i,d,s,n=$(t);i=n,d=d3.select("#trail-"+c).selectAll("g").data(i,function(t){return t.name+t.depth}),(s=d.enter().append("svg:g")).append("svg:polygon").attr("points",E).style("fill",function(t){return f[t.name]}),s.append("svg:text").attr("x",(m.w+m.t)/2).attr("y",m.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),d.attr("transform",function(t,e){return 5Order: '),d3.select(_).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e);var b=d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(t){return t.z}),w=d3.select("#"+e).append("svg").attr("width",i+f+h).attr("height",d+m+p);w.call(b);var k=w.append("g").attr("transform","translate("+f+","+m+")");graph={nodes:v,links:g};var $=[],E=(v=graph.nodes).length;v.forEach(function(t,e){t.index=e,t.count=0,$[e]=d3.range(E).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){void 0!==$[t.source_id][t.target_id]?($[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):($[t.source_id][t.target_id]={},$[t.source_id][t.target_id].z=0)});var C,A={name:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node,v[e].node)}),count:d3.range(E).sort(function(t,e){return v[e].count-v[t].count}),group:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node_group,v[e].node_group)})};y.domain(A.name),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(i+f+h)/2).attr("y",25).attr("text-anchor","middle").text(u),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(d+m+p)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(c),k.append("rect").attr("class","mode-network-matrix-background").attr("width",i).attr("height",d),(C=k.selectAll(".mode-network-matrix-row").data($).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).each(C)).append("line").attr("class","mode-network-matrix-line").attr("x2",i),C.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(t,e){return v[e].node});var F=k.selectAll(".mode-network-matrix-column").data($).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"});function C(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 y(t.x)}).attr("width",y.rangeBand()).attr("height",y.rangeBand()).style("fill-opacity",function(t){return x(t.z)}).style("fill",function(t){return v[t.x].node_group==v[t.y].node_group?s[v[t.x].node_group]:"#2B2B2B"}).on("mouseover",function(t){var a;a=t,d3.selectAll(".mode-network-matrix-row-text").classed("active",function(t,e){return e==a.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(t,e){return e==a.x}),b.show(t)}).on("mouseout",function(t){d3.selectAll("text").classed("active",!1),b.hide(t)})}F.append("line").attr("class","mode-network-matrix-line").attr("x1",-i),F.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(t,e){return v[e].node}),d3.select("#mode-network-matrix-order-picker-"+e).on("change",function(){!function(t){y.domain(A[t]);var e=k.transition().duration(1e3);e.selectAll(".mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(t){return y(t.x)}),e.selectAll(".mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"})}(this.value)})},hive:function(t){d3.hive={},d3.hive.link=function(){function e(t,e){var a,n=i(d,this,t,e),r=i(s,this,t,e);n.a>r.a&&(a=r,r=n,n=a),r.a-n.a>Math.PI&&(n.a+=2*Math.PI);var o=n.a+(r.a-n.a)/3,l=r.a-(r.a-n.a)/3;return n.r0-n.r1||r.r0-r.r1?"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"L"+Math.cos(n.a)*n.r1+","+Math.sin(n.a)*n.r1+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1+"L"+Math.cos(r.a)*r.r0+","+Math.sin(r.a)*r.r0+"C"+Math.cos(l)*r.r0+","+Math.sin(l)*r.r0+" "+Math.cos(o)*n.r0+","+Math.sin(o)*n.r0+" "+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0:"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1}function i(t,e,a,n){var r=t.call(e,a,n),o=+("function"==typeof c?c.call(e,r,n):c)+h,l=+("function"==typeof u?u.call(e,r,n):u);return{r0:l,r1:u===m?l:+("function"==typeof m?m.call(e,r,n):m),a:o}}var d=function(t){return t.source},s=function(t){return t.target},c=function(t){return t.angle},u=function(t){return t.radius},m=u,h=-Math.PI/2;return e.source=function(t){return arguments.length?(d=t,e):d},e.target=function(t){return arguments.length?(s=t,e):s},e.angle=function(t){return arguments.length?(c=t,e):c},e.radius=function(t){return arguments.length?(u=m=t,e):u},e.startRadius=function(t){return arguments.length?(u=t,e):u},e.endRadius=function(t){return arguments.length?(m=t,e):m},e};var e=alamode.makeId(10),a=t.node_query,n=t.edge_query,r=t.groups_are_numeric,o=t.html_element||"body",l=t.title||queryName,i=t.chart_width||"800",d=t.chart_height||"800",s=t.group_colors||"",c=Math.min(i,d)/2-30,u=.2*c,m=alamode.getDataFromQuery(a),h=alamode.getDataFromQuery(n),p=_.uniq(_.map(m,"node_group")),f={};m.forEach(function(t){t.x=r?t.node_group:p.indexOf(t.node_group),t.y=t.node_size,f[t.node]=t}),h.forEach(function(t){t.source=f[t.source],t.target=f[t.target]});var v=alamode.addContainerElement(o);d3.select(v).append("div").attr("class","mode-graphic-title").text(l),d3.select(v).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e),angle=r?d3.scale.linear().domain(d3.extent(m,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 g=d3.scale.linear().domain(d3.extent(m,function(t){return t.node_size})).range([u,c]),y=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(t){return t.node}),x=d3.select("#"+e).append("svg").attr("width",i).attr("height",d).append("g").attr("transform","translate("+i/2+","+d/2+")");function b(t){return t/Math.PI*180-90}x.call(y),x.selectAll(".mode-hive-axis").data(d3.range(p.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(t){return"rotate("+b(angle(t))+")"}).attr("x1",g.range()[0]).attr("x2",g.range()[1]),x.selectAll(".mode-hive-link").data(h).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(t){return angle(t.x)}).radius(function(t){return g(t.y)})).style("stroke",function(t){return s[t.source.node_group]}),x.selectAll(".mode-hive-node").data(m).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(t){return"rotate("+b(angle(t.x))+")"}).attr("cx",function(t){return g(t.y)}).attr("r",5).style("fill",function(t){return s[t.node_group]}).on("mouseover",function(e){y.show(e),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(h).attr("class",function(t){return t.source.node==e.node||t.target.node==e.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(t){y.hide(t),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(n){var v="#"+n.table_id,t=n.query_name,e=n.column_rules,g=alamode.getDataFromQuery(t),y=(alamode.getColumnsFromQuery(t),{});function a(t){var e,a=$(v+" table"),n=$(v+" .js-header-table"),r=n?$(v+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),y[text]=e}),t.forEach(function(f){f.rules.forEach(function(t){var n,r,o,l,i,d,s,c,e,u,a,m,h,p=t.shade_text||!1;"gradient"==t.type?(c=f.column,e=t.color,u=p,a=d3.extent(_.map(g,c)),m=d3.scale.linear().domain(a).interpolate(d3.interpolateHsl).range(e),h=y[c],g.forEach(function(t,e){var a=v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+h+"']",n=m(t[c]),r=x(n),o=$(a);u?o.css("color",n):o.css({background:n,color:r})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(n=f.column,r=t.type,o=t.value,l=t.color,i=p,d=y[n],s=x(l),g.forEach(function(t,e){var a=$(v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+d+"']");("above"==r&&t[n]>=o||"below"==r&&t[n]<=o||"equal"==r&&t[n]==o)&&(i?a.css("color",l):a.css({background:l,color:s}))}))})})}function x(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){a(e)},1e3),$(v).mousemove(function(){a(e)})},customizeTable:function(t){window.dispatchAction({type:"Embed.AlamodeCustomizeTable",payload:t})},conditionalFormattingByTable:function(n){var m="#"+n.table_id,t=n.query_name,h=n.columns;rules=n.rules;var p=alamode.getDataFromQuery(t),f=(alamode.getColumnsFromQuery(t),{}),a=[];h.forEach(function(t){var e=d3.extent(_.map(p,t));a=a.concat(e)});var v=d3.extent(a);function e(t){var e,a=$(m+" table"),n=$(m+" .js-header-table"),r=n?$(m+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),f[text]=e}),t.forEach(function(t){var o,l,i,d,s,e,c,u,a=t.shade_text||!1;"gradient"==t.type?(e=t.color,c=a,u=d3.scale.linear().domain(v).interpolate(d3.interpolateHsl).range(e),p.forEach(function(l,i){h.forEach(function(t){var e=f[t],a=m+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+e+"']",n=u(l[t]),r=g(n),o=$(a);c?o.css("color",n):o.css({background:n,color:r})})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(o=t.type,l=t.value,i=t.color,d=a,s=g(i),p.forEach(function(n,r){h.forEach(function(t){var e=f[t],a=$(m+" table [data-axel-rowkey='"+r+"'][data-axel-column='"+e+"']");("above"==o&&n[t]>=l||"below"==o&&n[t]<=l||"equal"==o&&n[t]==l)&&(d?a.css("color",i):a.css({background:i,color:s}))})}))})}function g(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){e(rules)},1e3),$(m).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,a=$(this).find("mode-chart").attr("id")||$(this).find("mode-table").attr("id")||$(this).find("mode-python").attr("id");if(!a)return!0;a.includes("chart")||a.includes("table")?(t=document.getElementById(a),e=0<$(t).find("mode-pivot-table").length?document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText:document.getElementById(a).getElementsByClassName("chart-title")[0].innerText):a.includes("python")&&(e=document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText);var n=$(""+(e.includes("Click to add title")?"Untitled":e)+"");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(){$(".scroll-link").on("click",function(t){t.preventDefault();var e,a,n=$(this).attr("href");e=750,a=$(n).offset().top-50,$("html,body").animate({scrollTop:a},e)})},100)},xAnnotations:function(t){var a=t.chart_id,r=t.comment_values,o=t.comments,l=t.color||[],d=t.is_date||!1;setTimeout(function(){var e=$("#"+a).find("div.highcharts-container")[0].id,t=Highcharts.charts;if(chart=t.filter(function(t){if(t)return t.container.id==e})[0],data=chart.series[0].data,d)for(i=0;i Date: Tue, 24 Nov 2020 15:44:05 -0500 Subject: [PATCH 3/4] adding backward compatilbility. --- alamode.js | 7 +++++-- alamode.min.js | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/alamode.js b/alamode.js index 9ad4528..5630686 100644 --- a/alamode.js +++ b/alamode.js @@ -820,10 +820,12 @@ var alamode = { .domain([minVal, maxVal]) .interpolator(d3.interpolateRgbBasis(colors)); + console.log('buckets', buckets, dataset.content.map(valueFunc).sort()) var scale = d3.scaleThreshold() .domain(buckets) .range(dataset.content.map(valueFunc).sort()) + return { name: columnName, rules: buckets.map(function (index) { @@ -845,11 +847,12 @@ var alamode = { formatByColumn: { columns: (o.columns || []).map(function (column, index) { if (!column) throw new Error("Colum data isn't passed properly."); + var colName = typeof column === 'string' ? column : (column || {}).name return heatmapColumnRules({ - name: typeof column === 'string' ? column : (column || {}).name, + name: colName, color_gradient: column.color_gradient || defaultColorGradients[index % defaultColorGradients.length], inverse: column.inverse - }, dataset[0], function (row) { return row[column] }) + }, dataset[0], function (row) { return row[colName] }) }) } }]) diff --git a/alamode.min.js b/alamode.min.js index e45b718..223503d 100644 --- a/alamode.min.js +++ b/alamode.min.js @@ -1 +1 @@ -var version="0.23",alamode={reportError:function(t){$("

").text(t).prependTo(document.body)},getColumnsFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.columns:(alamode.reportError("No such query: '"+e+"'"),[])},getDataFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.content:(alamode.reportError("No such query: '"+e+"'"),[])},makeId:function(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",a="",n=0;n").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content"):0===$(t).length?alamode.reportError("No such element: '"+t+"'"):(e&&$(t).empty(),$(t).addClass("mode-graphic-container"),$(t).addClass(id)),"."+id},addLinksToTables:function(t){var l="#"+t.table_id,e=t.link_columns,a=t.link_urls,n=t.query_name,m=t.open_in_new_tab||!1,r=[],h={};e.forEach(function(t,e){r.push({column:t,link_string:a[e]})});var p=alamode.getDataFromQuery(n);alamode.getColumnsFromQuery(n);function o(e){var t,a=$(l+" table"),n=$(l+" .js-header-table"),r=n?$(l+" .js-col-header"):$(n).find("th"),o=a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),t=$(this).attr("data-axel-column"),h[text]=t-1}),o.each(function(t){var c,u;0"+a+"";c.eq(e).html(s)}))})}setTimeout(function(){o(r)},1e3),$(l).mousemove(function(){o(r)})},customChartColors:function(t){var e=t.charts,n=t.colors,d=t.opacity,s=t.line_dashes;function h(t,e){var a=$("#"+t),n=(0TTL",u.forEach(function(t){""!=t.total?e=e+""+s(t.total)+"":e+=""}),e+""),n=+container.css("height").match(/\d+/)[0];t.after(a),container.css("height",26+n)},1e3)},addImagesToTables:function(t){var o="#"+t.table,l=t.column,i=t.image_height||100;function e(){var t=$(o+" table"),e=$(o+" .js-header-table"),a=e?$(o+" .js-col-header"):$(e).find("th"),n=t.find("tr"),r=0;a.each(function(){text=$(this).find(".axel-table-header-label").text(),text==l&&(r=+$(this).attr("data-axel-column"))}),n.each(function(){$(this).find("td").each(function(t){var e;t==r-1&&(e=$(this).text(),0==$(this).find("img").length&&($(this).css("text-align","center"),$(this).html("")))})})}setTimeout(function(){e()},1e3),$(o).keyup(function(){setTimeout(function(){e()},500)}),$(o).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){var a,n,r,e=t.query_name,i=t.cohort_column,d=t.pivot_column,s=t.value_column,o=t.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],l=t.gradient_by||"all",c=t.gradient_column||s,u=t.total_column,m=t.html_element||"body",h=t.title||e,p=t.pivot_label||"",f=t.value_is_percent,v=t.precision||0,g=alamode.getDataFromQuery(e),y=alamode.getColumnsFromQuery(e),x=_.uniq(_.map(g,i)),b=_.sortBy(_.uniq(_.map(g,d))),w=alamode.addContainerElement(m);"cohort_column"===l?(a={},x.forEach(function(e){var t=g.filter(function(t){return t[i]===e});a[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):"pivot_column"===l?(n={},b.forEach(function(e){var t=g.filter(function(t){return t[d]===e});n[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):r=d3.scale.quantize().domain(d3.extent(g,function(t){return t[c]})).range(o),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 k=d3.select(w).append("table").attr("class","mode-retention-heatmap-table");function $(e){return y.filter(function(t){return t.name==e})[0].type}k.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}),k.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 function(r,o){var l=[{column:i,value:o}];{var t,e;u&&(t=_.filter(r,function(t){return t[i]==o})[0],e={column:u,value:t[u]},l=l.concat(e))}return b.forEach(function(e){var t="",a="",n=_.filter(r,function(t){return t[i]==o&&t[d]==e});0=",value:o,color:r[r.length-1]})}}alamode.customizeTable([{vizId:e.vizId,formatByColumn:{columns:(e.columns||[]).map(function(e,t){if(!e)throw new Error("Colum data isn't passed properly.");return r({name:"string"==typeof e?e:(e||{}).name,color_gradient:e.color_gradient||n[t%n.length],inverse:e.inverse},a[0],function(t){return t[e]})})}}])},googleMap:function(t){var e=alamode.makeId(10),l=t.lat_column,i=t.lng_column,a=t.query_name,n=t.google_maps_api_key,r=t.title||a,d=t.label_column,o=t.html_element||"body",s=t.center_lat||39.5,c=t.center_lng||-98.35,u=t.starting_zoom||4,m=t.map_type||"terrain",h=t.height||600,p=alamode.getDataFromQuery(a),f=alamode.addContainerElement(o);d3.select(f).append("div").attr("class","mode-graphic-title").text(r),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="+n,function(){var t,o;t={zoom:u,center:new google.maps.LatLng(s,c),mapTypeId:m},o=new google.maps.Map(document.getElementById(e),t),p.forEach(function(t){var e=t[l],a=t[i];label=d?t[d]:"";var n=new google.maps.Marker({position:{lat:e,lng:a},map:o,title:label}),r=new google.maps.InfoWindow({content:label});n.addListener("click",function(){r.open(o,n)})})})},leafletMap:function(t){var e=alamode.makeId(10),a=t.lat_column,n=t.lng_column,r=t.query_name,o=t.title||r,l=t.height||400,i=t.html_element||"body",d=t.center_lat||39.5,s=t.center_lng||-98.35,c=t.starting_zoom||4,u=t.dot_size||.4,m=t.dot_opacity||.8,h=t.apply_filter||!1,p=alamode.getDataFromQuery(r),f=[];p.forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&f.push(t)});var v=alamode.addContainerElement(i,h);d3.select(v).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o);var g=l-$(v+".mode-graphic-title").height(),y=$(v).width();d3.select(v).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",g+"px").style("width",y+"px");var x=L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18}),_={max:8,data:f},b={lat:d,lng:s,zoom:c},w=new HeatmapOverlay({radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n});new L.Map(e,{center:new L.LatLng(b.lat,b.lng),zoom:Math.floor(b.zoom),layers:[x,w]});w.setData(_)},wordCloud:function(t){var e=t.query_name,a=t.word_column,n=t.word_count_column,r=t.html_element||"body",o=t.title||e,l=t.height||"400",i=t.width||"800",d=t.colors||["black"],s=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(s,function(t){return t[n]})).range([12,60]),m=d3.layout.cloud().size([i,l]).words(s.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 d[e%d.length]}).attr("text-anchor","middle").attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).text(function(t){return t.text})});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",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]])});new D3Funnel("#"+e).draw(u,{label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100}),d3.select("#"+e).style("height",i+"px")},horizontalBarChart:function(r){var t=r.query_name,e=(r.bar_column,r.series_columns),o=r.colors||["#EE8D24","#43A5DA","#6AB328","#BB60F8","#E14459","#EAD022","#06D0AD","#DB38B7"];stacked=r.stacked||!1,leftpad=r.left_pad||175,htmlElement=r.html_element||"body",title=r.title||t,height=r.chart_height||395,width=r.width||"500";var l=alamode.getDataFromQuery(t),a=alamode.addContainerElement(htmlElement);d3.select(a).append("div").attr("class","mode-graphic-title").text(title),d3.select(a).append("div").attr("class","mode-horizontal-bar-chart").style("height",height-50+"px").append("svg");var i=[];e.forEach(function(e,t){var a={key:e,color:o[t%o.length]},n=[];l.forEach(function(t){n.push({label:t[r.bar_column],value:t[e]})}),a.values=n,i.push(a)}),nv.addGraph(function(){var t=nv.models.multiBarHorizontalChart().x(function(t){return t.label}).y(function(t){return t.value}).margin({top:30,right:20,bottom:50,left:leftpad}).showValues(!0).showControls(!1).stacked(stacked);return t.yAxis.tickFormat(d3.format(",.2f")),d3.select(a+" svg").datum(i).call(t),nv.utils.windowResize(t.update),t})},chartAnnotations:function(t){var w="#"+t.chart_id,n=t.x_axis_column,e=t.query_name,k=t.orientations,E=t.comment_values,r=t.group_by,a=t.comments,o=alamode.getDataFromQuery(e),C=[],l={};function i(){a.forEach(function(t,e){var a,n,r,o,l,i,d,s,c,u=C[e],m=k[e],h=E[e],p=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),f=$(w).find("g.nvd3.nv-wrap").attr("transform"),v=f.indexOf("("),g=f.indexOf(")"),x=f.indexOf(","),_=+f.slice(v+1,x),b=+f.slice(x+1,g);-1!=u&&"v"==m?(n=(a=$(w).find(".nv-point.nv-point-"+u).attr("transform")).indexOf("("),r=a.indexOf(")"),o=a.indexOf(","),l=+a.slice(n+1,o),i=+a.slice(o+1,r),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width"),(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",l+_).attr("y",b-5).attr("width",1).attr("class","flag").attr("height",5+i).attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",l+_).attr("cy",b-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide)):"h"!=m&&"h-left"!=m&&"h-right"!=m||(y="h"==m?"":"1",$(w).find("g.nv-y"+y+".nv-axis").find(".tick").each(function(t){lineLength="h-right"==m?+$(w).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(",",""))}),d=(yTrans2-yTrans1)/(yVal2-yVal1),s=yTrans2-yVal2*d+h*d,(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",_).attr("y",s+b).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",lineLength+_+10).attr("cy",s+b).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide))})}r&&(l=_.groupBy(o,function(t){return t[r]})),a.forEach(function(t,e){var a=_.filter(o,function(t){return t[n]==E[e]});pointNumber=0!=a.length?r?l[a[0][r]].indexOf(a[0]):o.indexOf(a[0]):-1,C.push(pointNumber)}),setTimeout(function(){d3.select(w).selectAll(".flag").remove(),i()},1e3),$(window).resize(function(){d3.select(w).selectAll(".flag").remove(),s(function(){i()},500,"")});var d,s=(d={},function(t,e,a){d[a=a||"Don't call this twice without a uniqueId"]&&clearTimeout(d[a]),d[a]=setTimeout(t,e)})},bulletChart:function(l){var i=alamode.makeId(10),t=l.query_name,e=l.html_element||"body",a=l.title||t,d=l.chart_width||"800",s=l.bar_column||"",c=l.marker_column||"",u=l.left_pad||150,m=l.color,n=alamode.getDataFromQuery(t),r=alamode.addContainerElement(e);d3.select(r).append("div").attr("class","mode-graphic-title").text(a),d3.select(r).append("div").attr("class","mode-bullet-chart").style("width",d).attr("id",i),n.forEach(function(t){var e=t[l.title_column]||"",a=t[l.subtitle_column]||"",n=t[l.marker_column]||"",r=t[l.bar_column]||"";scale=l.scale_columns?[t[l.scale_columns[0]],t[l.scale_columns[1]],t[l.scale_columns[2]]]:l.scale_columns;var o={title:e,subtitle:a,ranges:scale,measures:[r],measureLabels:[s],markers:[n],markerLabels:[c],color:m};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(d).margin({left:u,right:15,top:10,bottom:10});d3.select("#"+i).append("svg").style("width",d+"px").style("height","70px").style("display","inline").datum(o).transition().duration(500).call(t);return t})})},sunburstChart:function(t){var c=alamode.makeId(10),e=t.query_name,n=t.event_columns,r=t.event_counts,a=t.title||e,o=t.color_range||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],l=t.html_element||"body",d=alamode.getDataFromQuery(e),s=850,u=Math.min(s,600)/2,m={w:(s-30)/n.length,h:20,s:3,t:10},h=[];n.forEach(function(t){h=h.concat(_.uniq(_.map(d,t)))});var p=_.uniq(h),f={};p.forEach(function(t,e){null!=t&&(f[t]=o[e%o.length])}),f.end="#666";var v=0,g=alamode.addContainerElement(l);d3.select(g).append("div").attr("class","mode-graphic-title").text(a),d3.select(g).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+c),d3.select(g).append("div").attr("class","mode-sunburst").attr("id",c),d3.select(g).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+c),vis=d3.select("#"+c).append("svg:svg").attr("width",s).attr("height",600).append("svg:g").attr("transform","translate("+s/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-"+c).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-"+c).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 y=d3.layout.partition().size([2*Math.PI,u*u]).value(function(t){return t.size}),x=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)}),b=[];function w(t){var e=(100*t.value/v).toPrecision(3),a=e+"%";e<.1&&(a="< 0.1%");var n=$(t),r=t.parent.value,o=(100*t.value/r).toPrecision(3),l=o+"%";o<1&&(a="< 1%"),d3.select("#cond-percentage-"+c).text(l),d3.select("#percentage-"+c).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility","");var i,d,s,n=$(t);i=n,d=d3.select("#trail-"+c).selectAll("g").data(i,function(t){return t.name+t.depth}),(s=d.enter().append("svg:g")).append("svg:polygon").attr("points",E).style("fill",function(t){return f[t.name]}),s.append("svg:text").attr("x",(m.w+m.t)/2).attr("y",m.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),d.attr("transform",function(t,e){return 5Order: '),d3.select(_).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e);var b=d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(t){return t.z}),w=d3.select("#"+e).append("svg").attr("width",i+f+h).attr("height",d+m+p);w.call(b);var k=w.append("g").attr("transform","translate("+f+","+m+")");graph={nodes:v,links:g};var $=[],E=(v=graph.nodes).length;v.forEach(function(t,e){t.index=e,t.count=0,$[e]=d3.range(E).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){void 0!==$[t.source_id][t.target_id]?($[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):($[t.source_id][t.target_id]={},$[t.source_id][t.target_id].z=0)});var C,A={name:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node,v[e].node)}),count:d3.range(E).sort(function(t,e){return v[e].count-v[t].count}),group:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node_group,v[e].node_group)})};y.domain(A.name),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(i+f+h)/2).attr("y",25).attr("text-anchor","middle").text(u),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(d+m+p)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(c),k.append("rect").attr("class","mode-network-matrix-background").attr("width",i).attr("height",d),(C=k.selectAll(".mode-network-matrix-row").data($).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).each(C)).append("line").attr("class","mode-network-matrix-line").attr("x2",i),C.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(t,e){return v[e].node});var F=k.selectAll(".mode-network-matrix-column").data($).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"});function C(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 y(t.x)}).attr("width",y.rangeBand()).attr("height",y.rangeBand()).style("fill-opacity",function(t){return x(t.z)}).style("fill",function(t){return v[t.x].node_group==v[t.y].node_group?s[v[t.x].node_group]:"#2B2B2B"}).on("mouseover",function(t){var a;a=t,d3.selectAll(".mode-network-matrix-row-text").classed("active",function(t,e){return e==a.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(t,e){return e==a.x}),b.show(t)}).on("mouseout",function(t){d3.selectAll("text").classed("active",!1),b.hide(t)})}F.append("line").attr("class","mode-network-matrix-line").attr("x1",-i),F.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(t,e){return v[e].node}),d3.select("#mode-network-matrix-order-picker-"+e).on("change",function(){!function(t){y.domain(A[t]);var e=k.transition().duration(1e3);e.selectAll(".mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(t){return y(t.x)}),e.selectAll(".mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"})}(this.value)})},hive:function(t){d3.hive={},d3.hive.link=function(){function e(t,e){var a,n=i(d,this,t,e),r=i(s,this,t,e);n.a>r.a&&(a=r,r=n,n=a),r.a-n.a>Math.PI&&(n.a+=2*Math.PI);var o=n.a+(r.a-n.a)/3,l=r.a-(r.a-n.a)/3;return n.r0-n.r1||r.r0-r.r1?"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"L"+Math.cos(n.a)*n.r1+","+Math.sin(n.a)*n.r1+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1+"L"+Math.cos(r.a)*r.r0+","+Math.sin(r.a)*r.r0+"C"+Math.cos(l)*r.r0+","+Math.sin(l)*r.r0+" "+Math.cos(o)*n.r0+","+Math.sin(o)*n.r0+" "+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0:"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1}function i(t,e,a,n){var r=t.call(e,a,n),o=+("function"==typeof c?c.call(e,r,n):c)+h,l=+("function"==typeof u?u.call(e,r,n):u);return{r0:l,r1:u===m?l:+("function"==typeof m?m.call(e,r,n):m),a:o}}var d=function(t){return t.source},s=function(t){return t.target},c=function(t){return t.angle},u=function(t){return t.radius},m=u,h=-Math.PI/2;return e.source=function(t){return arguments.length?(d=t,e):d},e.target=function(t){return arguments.length?(s=t,e):s},e.angle=function(t){return arguments.length?(c=t,e):c},e.radius=function(t){return arguments.length?(u=m=t,e):u},e.startRadius=function(t){return arguments.length?(u=t,e):u},e.endRadius=function(t){return arguments.length?(m=t,e):m},e};var e=alamode.makeId(10),a=t.node_query,n=t.edge_query,r=t.groups_are_numeric,o=t.html_element||"body",l=t.title||queryName,i=t.chart_width||"800",d=t.chart_height||"800",s=t.group_colors||"",c=Math.min(i,d)/2-30,u=.2*c,m=alamode.getDataFromQuery(a),h=alamode.getDataFromQuery(n),p=_.uniq(_.map(m,"node_group")),f={};m.forEach(function(t){t.x=r?t.node_group:p.indexOf(t.node_group),t.y=t.node_size,f[t.node]=t}),h.forEach(function(t){t.source=f[t.source],t.target=f[t.target]});var v=alamode.addContainerElement(o);d3.select(v).append("div").attr("class","mode-graphic-title").text(l),d3.select(v).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e),angle=r?d3.scale.linear().domain(d3.extent(m,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 g=d3.scale.linear().domain(d3.extent(m,function(t){return t.node_size})).range([u,c]),y=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(t){return t.node}),x=d3.select("#"+e).append("svg").attr("width",i).attr("height",d).append("g").attr("transform","translate("+i/2+","+d/2+")");function b(t){return t/Math.PI*180-90}x.call(y),x.selectAll(".mode-hive-axis").data(d3.range(p.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(t){return"rotate("+b(angle(t))+")"}).attr("x1",g.range()[0]).attr("x2",g.range()[1]),x.selectAll(".mode-hive-link").data(h).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(t){return angle(t.x)}).radius(function(t){return g(t.y)})).style("stroke",function(t){return s[t.source.node_group]}),x.selectAll(".mode-hive-node").data(m).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(t){return"rotate("+b(angle(t.x))+")"}).attr("cx",function(t){return g(t.y)}).attr("r",5).style("fill",function(t){return s[t.node_group]}).on("mouseover",function(e){y.show(e),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(h).attr("class",function(t){return t.source.node==e.node||t.target.node==e.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(t){y.hide(t),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(n){var v="#"+n.table_id,t=n.query_name,e=n.column_rules,g=alamode.getDataFromQuery(t),y=(alamode.getColumnsFromQuery(t),{});function a(t){var e,a=$(v+" table"),n=$(v+" .js-header-table"),r=n?$(v+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),y[text]=e}),t.forEach(function(f){f.rules.forEach(function(t){var n,r,o,l,i,d,s,c,e,u,a,m,h,p=t.shade_text||!1;"gradient"==t.type?(c=f.column,e=t.color,u=p,a=d3.extent(_.map(g,c)),m=d3.scale.linear().domain(a).interpolate(d3.interpolateHsl).range(e),h=y[c],g.forEach(function(t,e){var a=v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+h+"']",n=m(t[c]),r=x(n),o=$(a);u?o.css("color",n):o.css({background:n,color:r})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(n=f.column,r=t.type,o=t.value,l=t.color,i=p,d=y[n],s=x(l),g.forEach(function(t,e){var a=$(v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+d+"']");("above"==r&&t[n]>=o||"below"==r&&t[n]<=o||"equal"==r&&t[n]==o)&&(i?a.css("color",l):a.css({background:l,color:s}))}))})})}function x(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){a(e)},1e3),$(v).mousemove(function(){a(e)})},customizeTable:function(t){window.dispatchAction({type:"Embed.AlamodeCustomizeTable",payload:t})},conditionalFormattingByTable:function(n){var m="#"+n.table_id,t=n.query_name,h=n.columns;rules=n.rules;var p=alamode.getDataFromQuery(t),f=(alamode.getColumnsFromQuery(t),{}),a=[];h.forEach(function(t){var e=d3.extent(_.map(p,t));a=a.concat(e)});var v=d3.extent(a);function e(t){var e,a=$(m+" table"),n=$(m+" .js-header-table"),r=n?$(m+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),f[text]=e}),t.forEach(function(t){var o,l,i,d,s,e,c,u,a=t.shade_text||!1;"gradient"==t.type?(e=t.color,c=a,u=d3.scale.linear().domain(v).interpolate(d3.interpolateHsl).range(e),p.forEach(function(l,i){h.forEach(function(t){var e=f[t],a=m+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+e+"']",n=u(l[t]),r=g(n),o=$(a);c?o.css("color",n):o.css({background:n,color:r})})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(o=t.type,l=t.value,i=t.color,d=a,s=g(i),p.forEach(function(n,r){h.forEach(function(t){var e=f[t],a=$(m+" table [data-axel-rowkey='"+r+"'][data-axel-column='"+e+"']");("above"==o&&n[t]>=l||"below"==o&&n[t]<=l||"equal"==o&&n[t]==l)&&(d?a.css("color",i):a.css({background:i,color:s}))})}))})}function g(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){e(rules)},1e3),$(m).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,a=$(this).find("mode-chart").attr("id")||$(this).find("mode-table").attr("id")||$(this).find("mode-python").attr("id");if(!a)return!0;a.includes("chart")||a.includes("table")?(t=document.getElementById(a),e=0<$(t).find("mode-pivot-table").length?document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText:document.getElementById(a).getElementsByClassName("chart-title")[0].innerText):a.includes("python")&&(e=document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText);var n=$(""+(e.includes("Click to add title")?"Untitled":e)+"");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(){$(".scroll-link").on("click",function(t){t.preventDefault();var e,a,n=$(this).attr("href");e=750,a=$(n).offset().top-50,$("html,body").animate({scrollTop:a},e)})},100)},xAnnotations:function(t){var a=t.chart_id,r=t.comment_values,o=t.comments,l=t.color||[],d=t.is_date||!1;setTimeout(function(){var e=$("#"+a).find("div.highcharts-container")[0].id,t=Highcharts.charts;if(chart=t.filter(function(t){if(t)return t.container.id==e})[0],data=chart.series[0].data,d)for(i=0;i").text(t).prependTo(document.body)},getColumnsFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.columns:(alamode.reportError("No such query: '"+e+"'"),[])},getDataFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.content:(alamode.reportError("No such query: '"+e+"'"),[])},makeId:function(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",a="",n=0;n").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content"):0===$(t).length?alamode.reportError("No such element: '"+t+"'"):(e&&$(t).empty(),$(t).addClass("mode-graphic-container"),$(t).addClass(id)),"."+id},addLinksToTables:function(t){var l="#"+t.table_id,e=t.link_columns,a=t.link_urls,n=t.query_name,m=t.open_in_new_tab||!1,r=[],h={};e.forEach(function(t,e){r.push({column:t,link_string:a[e]})});var p=alamode.getDataFromQuery(n);alamode.getColumnsFromQuery(n);function o(e){var t,a=$(l+" table"),n=$(l+" .js-header-table"),r=n?$(l+" .js-col-header"):$(n).find("th"),o=a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),t=$(this).attr("data-axel-column"),h[text]=t-1}),o.each(function(t){var c,u;0"+a+"";c.eq(e).html(s)}))})}setTimeout(function(){o(r)},1e3),$(l).mousemove(function(){o(r)})},customChartColors:function(t){var e=t.charts,n=t.colors,d=t.opacity,s=t.line_dashes;function h(t,e){var a=$("#"+t),n=(0TTL",u.forEach(function(t){""!=t.total?e=e+""+s(t.total)+"":e+=""}),e+""),n=+container.css("height").match(/\d+/)[0];t.after(a),container.css("height",26+n)},1e3)},addImagesToTables:function(t){var o="#"+t.table,l=t.column,i=t.image_height||100;function e(){var t=$(o+" table"),e=$(o+" .js-header-table"),a=e?$(o+" .js-col-header"):$(e).find("th"),n=t.find("tr"),r=0;a.each(function(){text=$(this).find(".axel-table-header-label").text(),text==l&&(r=+$(this).attr("data-axel-column"))}),n.each(function(){$(this).find("td").each(function(t){var e;t==r-1&&(e=$(this).text(),0==$(this).find("img").length&&($(this).css("text-align","center"),$(this).html("")))})})}setTimeout(function(){e()},1e3),$(o).keyup(function(){setTimeout(function(){e()},500)}),$(o).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){var a,n,r,e=t.query_name,i=t.cohort_column,d=t.pivot_column,s=t.value_column,o=t.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],l=t.gradient_by||"all",c=t.gradient_column||s,u=t.total_column,m=t.html_element||"body",h=t.title||e,p=t.pivot_label||"",f=t.value_is_percent,v=t.precision||0,g=alamode.getDataFromQuery(e),y=alamode.getColumnsFromQuery(e),x=_.uniq(_.map(g,i)),b=_.sortBy(_.uniq(_.map(g,d))),w=alamode.addContainerElement(m);"cohort_column"===l?(a={},x.forEach(function(e){var t=g.filter(function(t){return t[i]===e});a[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):"pivot_column"===l?(n={},b.forEach(function(e){var t=g.filter(function(t){return t[d]===e});n[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):r=d3.scale.quantize().domain(d3.extent(g,function(t){return t[c]})).range(o),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 k=d3.select(w).append("table").attr("class","mode-retention-heatmap-table");function $(e){return y.filter(function(t){return t.name==e})[0].type}k.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}),k.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 function(r,o){var l=[{column:i,value:o}];{var t,e;u&&(t=_.filter(r,function(t){return t[i]==o})[0],e={column:u,value:t[u]},l=l.concat(e))}return b.forEach(function(e){var t="",a="",n=_.filter(r,function(t){return t[i]==o&&t[d]==e});0=",value:o,color:r[r.length-1]})}}alamode.customizeTable([{vizId:e.vizId,formatByColumn:{columns:(e.columns||[]).map(function(t,e){if(!t)throw new Error("Colum data isn't passed properly.");var a="string"==typeof t?t:(t||{}).name;return o({name:a,color_gradient:t.color_gradient||r[e%r.length],inverse:t.inverse},n[0],function(t){return t[a]})})}}])},googleMap:function(t){var e=alamode.makeId(10),l=t.lat_column,i=t.lng_column,a=t.query_name,n=t.google_maps_api_key,r=t.title||a,d=t.label_column,o=t.html_element||"body",s=t.center_lat||39.5,c=t.center_lng||-98.35,u=t.starting_zoom||4,m=t.map_type||"terrain",h=t.height||600,p=alamode.getDataFromQuery(a),f=alamode.addContainerElement(o);d3.select(f).append("div").attr("class","mode-graphic-title").text(r),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="+n,function(){var t,o;t={zoom:u,center:new google.maps.LatLng(s,c),mapTypeId:m},o=new google.maps.Map(document.getElementById(e),t),p.forEach(function(t){var e=t[l],a=t[i];label=d?t[d]:"";var n=new google.maps.Marker({position:{lat:e,lng:a},map:o,title:label}),r=new google.maps.InfoWindow({content:label});n.addListener("click",function(){r.open(o,n)})})})},leafletMap:function(t){var e=alamode.makeId(10),a=t.lat_column,n=t.lng_column,r=t.query_name,o=t.title||r,l=t.height||400,i=t.html_element||"body",d=t.center_lat||39.5,s=t.center_lng||-98.35,c=t.starting_zoom||4,u=t.dot_size||.4,m=t.dot_opacity||.8,h=t.apply_filter||!1,p=alamode.getDataFromQuery(r),f=[];p.forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&f.push(t)});var v=alamode.addContainerElement(i,h);d3.select(v).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o);var g=l-$(v+".mode-graphic-title").height(),y=$(v).width();d3.select(v).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",g+"px").style("width",y+"px");var x=L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18}),_={max:8,data:f},b={lat:d,lng:s,zoom:c},w=new HeatmapOverlay({radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n});new L.Map(e,{center:new L.LatLng(b.lat,b.lng),zoom:Math.floor(b.zoom),layers:[x,w]});w.setData(_)},wordCloud:function(t){var e=t.query_name,a=t.word_column,n=t.word_count_column,r=t.html_element||"body",o=t.title||e,l=t.height||"400",i=t.width||"800",d=t.colors||["black"],s=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(s,function(t){return t[n]})).range([12,60]),m=d3.layout.cloud().size([i,l]).words(s.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 d[e%d.length]}).attr("text-anchor","middle").attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).text(function(t){return t.text})});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",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]])});new D3Funnel("#"+e).draw(u,{label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100}),d3.select("#"+e).style("height",i+"px")},horizontalBarChart:function(r){var t=r.query_name,e=(r.bar_column,r.series_columns),o=r.colors||["#EE8D24","#43A5DA","#6AB328","#BB60F8","#E14459","#EAD022","#06D0AD","#DB38B7"];stacked=r.stacked||!1,leftpad=r.left_pad||175,htmlElement=r.html_element||"body",title=r.title||t,height=r.chart_height||395,width=r.width||"500";var l=alamode.getDataFromQuery(t),a=alamode.addContainerElement(htmlElement);d3.select(a).append("div").attr("class","mode-graphic-title").text(title),d3.select(a).append("div").attr("class","mode-horizontal-bar-chart").style("height",height-50+"px").append("svg");var i=[];e.forEach(function(e,t){var a={key:e,color:o[t%o.length]},n=[];l.forEach(function(t){n.push({label:t[r.bar_column],value:t[e]})}),a.values=n,i.push(a)}),nv.addGraph(function(){var t=nv.models.multiBarHorizontalChart().x(function(t){return t.label}).y(function(t){return t.value}).margin({top:30,right:20,bottom:50,left:leftpad}).showValues(!0).showControls(!1).stacked(stacked);return t.yAxis.tickFormat(d3.format(",.2f")),d3.select(a+" svg").datum(i).call(t),nv.utils.windowResize(t.update),t})},chartAnnotations:function(t){var w="#"+t.chart_id,n=t.x_axis_column,e=t.query_name,k=t.orientations,E=t.comment_values,r=t.group_by,a=t.comments,o=alamode.getDataFromQuery(e),C=[],l={};function i(){a.forEach(function(t,e){var a,n,r,o,l,i,d,s,c,u=C[e],m=k[e],h=E[e],p=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),f=$(w).find("g.nvd3.nv-wrap").attr("transform"),v=f.indexOf("("),g=f.indexOf(")"),x=f.indexOf(","),_=+f.slice(v+1,x),b=+f.slice(x+1,g);-1!=u&&"v"==m?(n=(a=$(w).find(".nv-point.nv-point-"+u).attr("transform")).indexOf("("),r=a.indexOf(")"),o=a.indexOf(","),l=+a.slice(n+1,o),i=+a.slice(o+1,r),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width"),(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",l+_).attr("y",b-5).attr("width",1).attr("class","flag").attr("height",5+i).attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",l+_).attr("cy",b-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide)):"h"!=m&&"h-left"!=m&&"h-right"!=m||(y="h"==m?"":"1",$(w).find("g.nv-y"+y+".nv-axis").find(".tick").each(function(t){lineLength="h-right"==m?+$(w).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(",",""))}),d=(yTrans2-yTrans1)/(yVal2-yVal1),s=yTrans2-yVal2*d+h*d,(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",_).attr("y",s+b).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",lineLength+_+10).attr("cy",s+b).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide))})}r&&(l=_.groupBy(o,function(t){return t[r]})),a.forEach(function(t,e){var a=_.filter(o,function(t){return t[n]==E[e]});pointNumber=0!=a.length?r?l[a[0][r]].indexOf(a[0]):o.indexOf(a[0]):-1,C.push(pointNumber)}),setTimeout(function(){d3.select(w).selectAll(".flag").remove(),i()},1e3),$(window).resize(function(){d3.select(w).selectAll(".flag").remove(),s(function(){i()},500,"")});var d,s=(d={},function(t,e,a){d[a=a||"Don't call this twice without a uniqueId"]&&clearTimeout(d[a]),d[a]=setTimeout(t,e)})},bulletChart:function(l){var i=alamode.makeId(10),t=l.query_name,e=l.html_element||"body",a=l.title||t,d=l.chart_width||"800",s=l.bar_column||"",c=l.marker_column||"",u=l.left_pad||150,m=l.color,n=alamode.getDataFromQuery(t),r=alamode.addContainerElement(e);d3.select(r).append("div").attr("class","mode-graphic-title").text(a),d3.select(r).append("div").attr("class","mode-bullet-chart").style("width",d).attr("id",i),n.forEach(function(t){var e=t[l.title_column]||"",a=t[l.subtitle_column]||"",n=t[l.marker_column]||"",r=t[l.bar_column]||"";scale=l.scale_columns?[t[l.scale_columns[0]],t[l.scale_columns[1]],t[l.scale_columns[2]]]:l.scale_columns;var o={title:e,subtitle:a,ranges:scale,measures:[r],measureLabels:[s],markers:[n],markerLabels:[c],color:m};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(d).margin({left:u,right:15,top:10,bottom:10});d3.select("#"+i).append("svg").style("width",d+"px").style("height","70px").style("display","inline").datum(o).transition().duration(500).call(t);return t})})},sunburstChart:function(t){var c=alamode.makeId(10),e=t.query_name,n=t.event_columns,r=t.event_counts,a=t.title||e,o=t.color_range||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],l=t.html_element||"body",d=alamode.getDataFromQuery(e),s=850,u=Math.min(s,600)/2,m={w:(s-30)/n.length,h:20,s:3,t:10},h=[];n.forEach(function(t){h=h.concat(_.uniq(_.map(d,t)))});var p=_.uniq(h),f={};p.forEach(function(t,e){null!=t&&(f[t]=o[e%o.length])}),f.end="#666";var v=0,g=alamode.addContainerElement(l);d3.select(g).append("div").attr("class","mode-graphic-title").text(a),d3.select(g).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+c),d3.select(g).append("div").attr("class","mode-sunburst").attr("id",c),d3.select(g).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+c),vis=d3.select("#"+c).append("svg:svg").attr("width",s).attr("height",600).append("svg:g").attr("transform","translate("+s/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-"+c).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-"+c).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 y=d3.layout.partition().size([2*Math.PI,u*u]).value(function(t){return t.size}),x=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)}),b=[];function w(t){var e=(100*t.value/v).toPrecision(3),a=e+"%";e<.1&&(a="< 0.1%");var n=$(t),r=t.parent.value,o=(100*t.value/r).toPrecision(3),l=o+"%";o<1&&(a="< 1%"),d3.select("#cond-percentage-"+c).text(l),d3.select("#percentage-"+c).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility","");var i,d,s,n=$(t);i=n,d=d3.select("#trail-"+c).selectAll("g").data(i,function(t){return t.name+t.depth}),(s=d.enter().append("svg:g")).append("svg:polygon").attr("points",E).style("fill",function(t){return f[t.name]}),s.append("svg:text").attr("x",(m.w+m.t)/2).attr("y",m.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),d.attr("transform",function(t,e){return 5Order: '),d3.select(_).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e);var b=d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(t){return t.z}),w=d3.select("#"+e).append("svg").attr("width",i+f+h).attr("height",d+m+p);w.call(b);var k=w.append("g").attr("transform","translate("+f+","+m+")");graph={nodes:v,links:g};var $=[],E=(v=graph.nodes).length;v.forEach(function(t,e){t.index=e,t.count=0,$[e]=d3.range(E).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){void 0!==$[t.source_id][t.target_id]?($[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):($[t.source_id][t.target_id]={},$[t.source_id][t.target_id].z=0)});var C,A={name:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node,v[e].node)}),count:d3.range(E).sort(function(t,e){return v[e].count-v[t].count}),group:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node_group,v[e].node_group)})};y.domain(A.name),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(i+f+h)/2).attr("y",25).attr("text-anchor","middle").text(u),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(d+m+p)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(c),k.append("rect").attr("class","mode-network-matrix-background").attr("width",i).attr("height",d),(C=k.selectAll(".mode-network-matrix-row").data($).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).each(C)).append("line").attr("class","mode-network-matrix-line").attr("x2",i),C.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(t,e){return v[e].node});var F=k.selectAll(".mode-network-matrix-column").data($).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"});function C(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 y(t.x)}).attr("width",y.rangeBand()).attr("height",y.rangeBand()).style("fill-opacity",function(t){return x(t.z)}).style("fill",function(t){return v[t.x].node_group==v[t.y].node_group?s[v[t.x].node_group]:"#2B2B2B"}).on("mouseover",function(t){var a;a=t,d3.selectAll(".mode-network-matrix-row-text").classed("active",function(t,e){return e==a.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(t,e){return e==a.x}),b.show(t)}).on("mouseout",function(t){d3.selectAll("text").classed("active",!1),b.hide(t)})}F.append("line").attr("class","mode-network-matrix-line").attr("x1",-i),F.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(t,e){return v[e].node}),d3.select("#mode-network-matrix-order-picker-"+e).on("change",function(){!function(t){y.domain(A[t]);var e=k.transition().duration(1e3);e.selectAll(".mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(t){return y(t.x)}),e.selectAll(".mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"})}(this.value)})},hive:function(t){d3.hive={},d3.hive.link=function(){function e(t,e){var a,n=i(d,this,t,e),r=i(s,this,t,e);n.a>r.a&&(a=r,r=n,n=a),r.a-n.a>Math.PI&&(n.a+=2*Math.PI);var o=n.a+(r.a-n.a)/3,l=r.a-(r.a-n.a)/3;return n.r0-n.r1||r.r0-r.r1?"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"L"+Math.cos(n.a)*n.r1+","+Math.sin(n.a)*n.r1+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1+"L"+Math.cos(r.a)*r.r0+","+Math.sin(r.a)*r.r0+"C"+Math.cos(l)*r.r0+","+Math.sin(l)*r.r0+" "+Math.cos(o)*n.r0+","+Math.sin(o)*n.r0+" "+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0:"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1}function i(t,e,a,n){var r=t.call(e,a,n),o=+("function"==typeof c?c.call(e,r,n):c)+h,l=+("function"==typeof u?u.call(e,r,n):u);return{r0:l,r1:u===m?l:+("function"==typeof m?m.call(e,r,n):m),a:o}}var d=function(t){return t.source},s=function(t){return t.target},c=function(t){return t.angle},u=function(t){return t.radius},m=u,h=-Math.PI/2;return e.source=function(t){return arguments.length?(d=t,e):d},e.target=function(t){return arguments.length?(s=t,e):s},e.angle=function(t){return arguments.length?(c=t,e):c},e.radius=function(t){return arguments.length?(u=m=t,e):u},e.startRadius=function(t){return arguments.length?(u=t,e):u},e.endRadius=function(t){return arguments.length?(m=t,e):m},e};var e=alamode.makeId(10),a=t.node_query,n=t.edge_query,r=t.groups_are_numeric,o=t.html_element||"body",l=t.title||queryName,i=t.chart_width||"800",d=t.chart_height||"800",s=t.group_colors||"",c=Math.min(i,d)/2-30,u=.2*c,m=alamode.getDataFromQuery(a),h=alamode.getDataFromQuery(n),p=_.uniq(_.map(m,"node_group")),f={};m.forEach(function(t){t.x=r?t.node_group:p.indexOf(t.node_group),t.y=t.node_size,f[t.node]=t}),h.forEach(function(t){t.source=f[t.source],t.target=f[t.target]});var v=alamode.addContainerElement(o);d3.select(v).append("div").attr("class","mode-graphic-title").text(l),d3.select(v).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e),angle=r?d3.scale.linear().domain(d3.extent(m,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 g=d3.scale.linear().domain(d3.extent(m,function(t){return t.node_size})).range([u,c]),y=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(t){return t.node}),x=d3.select("#"+e).append("svg").attr("width",i).attr("height",d).append("g").attr("transform","translate("+i/2+","+d/2+")");function b(t){return t/Math.PI*180-90}x.call(y),x.selectAll(".mode-hive-axis").data(d3.range(p.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(t){return"rotate("+b(angle(t))+")"}).attr("x1",g.range()[0]).attr("x2",g.range()[1]),x.selectAll(".mode-hive-link").data(h).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(t){return angle(t.x)}).radius(function(t){return g(t.y)})).style("stroke",function(t){return s[t.source.node_group]}),x.selectAll(".mode-hive-node").data(m).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(t){return"rotate("+b(angle(t.x))+")"}).attr("cx",function(t){return g(t.y)}).attr("r",5).style("fill",function(t){return s[t.node_group]}).on("mouseover",function(e){y.show(e),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(h).attr("class",function(t){return t.source.node==e.node||t.target.node==e.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(t){y.hide(t),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(n){var v="#"+n.table_id,t=n.query_name,e=n.column_rules,g=alamode.getDataFromQuery(t),y=(alamode.getColumnsFromQuery(t),{});function a(t){var e,a=$(v+" table"),n=$(v+" .js-header-table"),r=n?$(v+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),y[text]=e}),t.forEach(function(f){f.rules.forEach(function(t){var n,r,o,l,i,d,s,c,e,u,a,m,h,p=t.shade_text||!1;"gradient"==t.type?(c=f.column,e=t.color,u=p,a=d3.extent(_.map(g,c)),m=d3.scale.linear().domain(a).interpolate(d3.interpolateHsl).range(e),h=y[c],g.forEach(function(t,e){var a=v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+h+"']",n=m(t[c]),r=x(n),o=$(a);u?o.css("color",n):o.css({background:n,color:r})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(n=f.column,r=t.type,o=t.value,l=t.color,i=p,d=y[n],s=x(l),g.forEach(function(t,e){var a=$(v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+d+"']");("above"==r&&t[n]>=o||"below"==r&&t[n]<=o||"equal"==r&&t[n]==o)&&(i?a.css("color",l):a.css({background:l,color:s}))}))})})}function x(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){a(e)},1e3),$(v).mousemove(function(){a(e)})},customizeTable:function(t){window.dispatchAction({type:"Embed.AlamodeCustomizeTable",payload:t})},conditionalFormattingByTable:function(n){var m="#"+n.table_id,t=n.query_name,h=n.columns;rules=n.rules;var p=alamode.getDataFromQuery(t),f=(alamode.getColumnsFromQuery(t),{}),a=[];h.forEach(function(t){var e=d3.extent(_.map(p,t));a=a.concat(e)});var v=d3.extent(a);function e(t){var e,a=$(m+" table"),n=$(m+" .js-header-table"),r=n?$(m+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),f[text]=e}),t.forEach(function(t){var o,l,i,d,s,e,c,u,a=t.shade_text||!1;"gradient"==t.type?(e=t.color,c=a,u=d3.scale.linear().domain(v).interpolate(d3.interpolateHsl).range(e),p.forEach(function(l,i){h.forEach(function(t){var e=f[t],a=m+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+e+"']",n=u(l[t]),r=g(n),o=$(a);c?o.css("color",n):o.css({background:n,color:r})})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(o=t.type,l=t.value,i=t.color,d=a,s=g(i),p.forEach(function(n,r){h.forEach(function(t){var e=f[t],a=$(m+" table [data-axel-rowkey='"+r+"'][data-axel-column='"+e+"']");("above"==o&&n[t]>=l||"below"==o&&n[t]<=l||"equal"==o&&n[t]==l)&&(d?a.css("color",i):a.css({background:i,color:s}))})}))})}function g(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){e(rules)},1e3),$(m).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,a=$(this).find("mode-chart").attr("id")||$(this).find("mode-table").attr("id")||$(this).find("mode-python").attr("id");if(!a)return!0;a.includes("chart")||a.includes("table")?(t=document.getElementById(a),e=0<$(t).find("mode-pivot-table").length?document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText:document.getElementById(a).getElementsByClassName("chart-title")[0].innerText):a.includes("python")&&(e=document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText);var n=$(""+(e.includes("Click to add title")?"Untitled":e)+"");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(){$(".scroll-link").on("click",function(t){t.preventDefault();var e,a,n=$(this).attr("href");e=750,a=$(n).offset().top-50,$("html,body").animate({scrollTop:a},e)})},100)},xAnnotations:function(t){var a=t.chart_id,r=t.comment_values,o=t.comments,l=t.color||[],d=t.is_date||!1;setTimeout(function(){var e=$("#"+a).find("div.highcharts-container")[0].id,t=Highcharts.charts;if(chart=t.filter(function(t){if(t)return t.container.id==e})[0],data=chart.series[0].data,d)for(i=0;i Date: Tue, 24 Nov 2020 15:56:59 -0500 Subject: [PATCH 4/4] better formatting. --- alamode.js | 1 - alamode.min.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/alamode.js b/alamode.js index 5630686..137dd1a 100644 --- a/alamode.js +++ b/alamode.js @@ -820,7 +820,6 @@ var alamode = { .domain([minVal, maxVal]) .interpolator(d3.interpolateRgbBasis(colors)); - console.log('buckets', buckets, dataset.content.map(valueFunc).sort()) var scale = d3.scaleThreshold() .domain(buckets) .range(dataset.content.map(valueFunc).sort()) diff --git a/alamode.min.js b/alamode.min.js index 223503d..357510f 100644 --- a/alamode.min.js +++ b/alamode.min.js @@ -1 +1 @@ -var version="0.23",alamode={reportError:function(t){$("

").text(t).prependTo(document.body)},getColumnsFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.columns:(alamode.reportError("No such query: '"+e+"'"),[])},getDataFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.content:(alamode.reportError("No such query: '"+e+"'"),[])},makeId:function(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",a="",n=0;n").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content"):0===$(t).length?alamode.reportError("No such element: '"+t+"'"):(e&&$(t).empty(),$(t).addClass("mode-graphic-container"),$(t).addClass(id)),"."+id},addLinksToTables:function(t){var l="#"+t.table_id,e=t.link_columns,a=t.link_urls,n=t.query_name,m=t.open_in_new_tab||!1,r=[],h={};e.forEach(function(t,e){r.push({column:t,link_string:a[e]})});var p=alamode.getDataFromQuery(n);alamode.getColumnsFromQuery(n);function o(e){var t,a=$(l+" table"),n=$(l+" .js-header-table"),r=n?$(l+" .js-col-header"):$(n).find("th"),o=a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),t=$(this).attr("data-axel-column"),h[text]=t-1}),o.each(function(t){var c,u;0"+a+"";c.eq(e).html(s)}))})}setTimeout(function(){o(r)},1e3),$(l).mousemove(function(){o(r)})},customChartColors:function(t){var e=t.charts,n=t.colors,d=t.opacity,s=t.line_dashes;function h(t,e){var a=$("#"+t),n=(0TTL",u.forEach(function(t){""!=t.total?e=e+""+s(t.total)+"":e+=""}),e+""),n=+container.css("height").match(/\d+/)[0];t.after(a),container.css("height",26+n)},1e3)},addImagesToTables:function(t){var o="#"+t.table,l=t.column,i=t.image_height||100;function e(){var t=$(o+" table"),e=$(o+" .js-header-table"),a=e?$(o+" .js-col-header"):$(e).find("th"),n=t.find("tr"),r=0;a.each(function(){text=$(this).find(".axel-table-header-label").text(),text==l&&(r=+$(this).attr("data-axel-column"))}),n.each(function(){$(this).find("td").each(function(t){var e;t==r-1&&(e=$(this).text(),0==$(this).find("img").length&&($(this).css("text-align","center"),$(this).html("")))})})}setTimeout(function(){e()},1e3),$(o).keyup(function(){setTimeout(function(){e()},500)}),$(o).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){var a,n,r,e=t.query_name,i=t.cohort_column,d=t.pivot_column,s=t.value_column,o=t.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],l=t.gradient_by||"all",c=t.gradient_column||s,u=t.total_column,m=t.html_element||"body",h=t.title||e,p=t.pivot_label||"",f=t.value_is_percent,v=t.precision||0,g=alamode.getDataFromQuery(e),y=alamode.getColumnsFromQuery(e),x=_.uniq(_.map(g,i)),b=_.sortBy(_.uniq(_.map(g,d))),w=alamode.addContainerElement(m);"cohort_column"===l?(a={},x.forEach(function(e){var t=g.filter(function(t){return t[i]===e});a[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):"pivot_column"===l?(n={},b.forEach(function(e){var t=g.filter(function(t){return t[d]===e});n[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):r=d3.scale.quantize().domain(d3.extent(g,function(t){return t[c]})).range(o),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 k=d3.select(w).append("table").attr("class","mode-retention-heatmap-table");function $(e){return y.filter(function(t){return t.name==e})[0].type}k.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}),k.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 function(r,o){var l=[{column:i,value:o}];{var t,e;u&&(t=_.filter(r,function(t){return t[i]==o})[0],e={column:u,value:t[u]},l=l.concat(e))}return b.forEach(function(e){var t="",a="",n=_.filter(r,function(t){return t[i]==o&&t[d]==e});0=",value:o,color:r[r.length-1]})}}alamode.customizeTable([{vizId:e.vizId,formatByColumn:{columns:(e.columns||[]).map(function(t,e){if(!t)throw new Error("Colum data isn't passed properly.");var a="string"==typeof t?t:(t||{}).name;return o({name:a,color_gradient:t.color_gradient||r[e%r.length],inverse:t.inverse},n[0],function(t){return t[a]})})}}])},googleMap:function(t){var e=alamode.makeId(10),l=t.lat_column,i=t.lng_column,a=t.query_name,n=t.google_maps_api_key,r=t.title||a,d=t.label_column,o=t.html_element||"body",s=t.center_lat||39.5,c=t.center_lng||-98.35,u=t.starting_zoom||4,m=t.map_type||"terrain",h=t.height||600,p=alamode.getDataFromQuery(a),f=alamode.addContainerElement(o);d3.select(f).append("div").attr("class","mode-graphic-title").text(r),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="+n,function(){var t,o;t={zoom:u,center:new google.maps.LatLng(s,c),mapTypeId:m},o=new google.maps.Map(document.getElementById(e),t),p.forEach(function(t){var e=t[l],a=t[i];label=d?t[d]:"";var n=new google.maps.Marker({position:{lat:e,lng:a},map:o,title:label}),r=new google.maps.InfoWindow({content:label});n.addListener("click",function(){r.open(o,n)})})})},leafletMap:function(t){var e=alamode.makeId(10),a=t.lat_column,n=t.lng_column,r=t.query_name,o=t.title||r,l=t.height||400,i=t.html_element||"body",d=t.center_lat||39.5,s=t.center_lng||-98.35,c=t.starting_zoom||4,u=t.dot_size||.4,m=t.dot_opacity||.8,h=t.apply_filter||!1,p=alamode.getDataFromQuery(r),f=[];p.forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&f.push(t)});var v=alamode.addContainerElement(i,h);d3.select(v).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o);var g=l-$(v+".mode-graphic-title").height(),y=$(v).width();d3.select(v).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",g+"px").style("width",y+"px");var x=L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18}),_={max:8,data:f},b={lat:d,lng:s,zoom:c},w=new HeatmapOverlay({radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n});new L.Map(e,{center:new L.LatLng(b.lat,b.lng),zoom:Math.floor(b.zoom),layers:[x,w]});w.setData(_)},wordCloud:function(t){var e=t.query_name,a=t.word_column,n=t.word_count_column,r=t.html_element||"body",o=t.title||e,l=t.height||"400",i=t.width||"800",d=t.colors||["black"],s=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(s,function(t){return t[n]})).range([12,60]),m=d3.layout.cloud().size([i,l]).words(s.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 d[e%d.length]}).attr("text-anchor","middle").attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).text(function(t){return t.text})});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",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]])});new D3Funnel("#"+e).draw(u,{label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100}),d3.select("#"+e).style("height",i+"px")},horizontalBarChart:function(r){var t=r.query_name,e=(r.bar_column,r.series_columns),o=r.colors||["#EE8D24","#43A5DA","#6AB328","#BB60F8","#E14459","#EAD022","#06D0AD","#DB38B7"];stacked=r.stacked||!1,leftpad=r.left_pad||175,htmlElement=r.html_element||"body",title=r.title||t,height=r.chart_height||395,width=r.width||"500";var l=alamode.getDataFromQuery(t),a=alamode.addContainerElement(htmlElement);d3.select(a).append("div").attr("class","mode-graphic-title").text(title),d3.select(a).append("div").attr("class","mode-horizontal-bar-chart").style("height",height-50+"px").append("svg");var i=[];e.forEach(function(e,t){var a={key:e,color:o[t%o.length]},n=[];l.forEach(function(t){n.push({label:t[r.bar_column],value:t[e]})}),a.values=n,i.push(a)}),nv.addGraph(function(){var t=nv.models.multiBarHorizontalChart().x(function(t){return t.label}).y(function(t){return t.value}).margin({top:30,right:20,bottom:50,left:leftpad}).showValues(!0).showControls(!1).stacked(stacked);return t.yAxis.tickFormat(d3.format(",.2f")),d3.select(a+" svg").datum(i).call(t),nv.utils.windowResize(t.update),t})},chartAnnotations:function(t){var w="#"+t.chart_id,n=t.x_axis_column,e=t.query_name,k=t.orientations,E=t.comment_values,r=t.group_by,a=t.comments,o=alamode.getDataFromQuery(e),C=[],l={};function i(){a.forEach(function(t,e){var a,n,r,o,l,i,d,s,c,u=C[e],m=k[e],h=E[e],p=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),f=$(w).find("g.nvd3.nv-wrap").attr("transform"),v=f.indexOf("("),g=f.indexOf(")"),x=f.indexOf(","),_=+f.slice(v+1,x),b=+f.slice(x+1,g);-1!=u&&"v"==m?(n=(a=$(w).find(".nv-point.nv-point-"+u).attr("transform")).indexOf("("),r=a.indexOf(")"),o=a.indexOf(","),l=+a.slice(n+1,o),i=+a.slice(o+1,r),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width"),(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",l+_).attr("y",b-5).attr("width",1).attr("class","flag").attr("height",5+i).attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",l+_).attr("cy",b-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide)):"h"!=m&&"h-left"!=m&&"h-right"!=m||(y="h"==m?"":"1",$(w).find("g.nv-y"+y+".nv-axis").find(".tick").each(function(t){lineLength="h-right"==m?+$(w).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(",",""))}),d=(yTrans2-yTrans1)/(yVal2-yVal1),s=yTrans2-yVal2*d+h*d,(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",_).attr("y",s+b).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",lineLength+_+10).attr("cy",s+b).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide))})}r&&(l=_.groupBy(o,function(t){return t[r]})),a.forEach(function(t,e){var a=_.filter(o,function(t){return t[n]==E[e]});pointNumber=0!=a.length?r?l[a[0][r]].indexOf(a[0]):o.indexOf(a[0]):-1,C.push(pointNumber)}),setTimeout(function(){d3.select(w).selectAll(".flag").remove(),i()},1e3),$(window).resize(function(){d3.select(w).selectAll(".flag").remove(),s(function(){i()},500,"")});var d,s=(d={},function(t,e,a){d[a=a||"Don't call this twice without a uniqueId"]&&clearTimeout(d[a]),d[a]=setTimeout(t,e)})},bulletChart:function(l){var i=alamode.makeId(10),t=l.query_name,e=l.html_element||"body",a=l.title||t,d=l.chart_width||"800",s=l.bar_column||"",c=l.marker_column||"",u=l.left_pad||150,m=l.color,n=alamode.getDataFromQuery(t),r=alamode.addContainerElement(e);d3.select(r).append("div").attr("class","mode-graphic-title").text(a),d3.select(r).append("div").attr("class","mode-bullet-chart").style("width",d).attr("id",i),n.forEach(function(t){var e=t[l.title_column]||"",a=t[l.subtitle_column]||"",n=t[l.marker_column]||"",r=t[l.bar_column]||"";scale=l.scale_columns?[t[l.scale_columns[0]],t[l.scale_columns[1]],t[l.scale_columns[2]]]:l.scale_columns;var o={title:e,subtitle:a,ranges:scale,measures:[r],measureLabels:[s],markers:[n],markerLabels:[c],color:m};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(d).margin({left:u,right:15,top:10,bottom:10});d3.select("#"+i).append("svg").style("width",d+"px").style("height","70px").style("display","inline").datum(o).transition().duration(500).call(t);return t})})},sunburstChart:function(t){var c=alamode.makeId(10),e=t.query_name,n=t.event_columns,r=t.event_counts,a=t.title||e,o=t.color_range||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],l=t.html_element||"body",d=alamode.getDataFromQuery(e),s=850,u=Math.min(s,600)/2,m={w:(s-30)/n.length,h:20,s:3,t:10},h=[];n.forEach(function(t){h=h.concat(_.uniq(_.map(d,t)))});var p=_.uniq(h),f={};p.forEach(function(t,e){null!=t&&(f[t]=o[e%o.length])}),f.end="#666";var v=0,g=alamode.addContainerElement(l);d3.select(g).append("div").attr("class","mode-graphic-title").text(a),d3.select(g).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+c),d3.select(g).append("div").attr("class","mode-sunburst").attr("id",c),d3.select(g).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+c),vis=d3.select("#"+c).append("svg:svg").attr("width",s).attr("height",600).append("svg:g").attr("transform","translate("+s/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-"+c).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-"+c).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 y=d3.layout.partition().size([2*Math.PI,u*u]).value(function(t){return t.size}),x=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)}),b=[];function w(t){var e=(100*t.value/v).toPrecision(3),a=e+"%";e<.1&&(a="< 0.1%");var n=$(t),r=t.parent.value,o=(100*t.value/r).toPrecision(3),l=o+"%";o<1&&(a="< 1%"),d3.select("#cond-percentage-"+c).text(l),d3.select("#percentage-"+c).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility","");var i,d,s,n=$(t);i=n,d=d3.select("#trail-"+c).selectAll("g").data(i,function(t){return t.name+t.depth}),(s=d.enter().append("svg:g")).append("svg:polygon").attr("points",E).style("fill",function(t){return f[t.name]}),s.append("svg:text").attr("x",(m.w+m.t)/2).attr("y",m.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),d.attr("transform",function(t,e){return 5Order: '),d3.select(_).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e);var b=d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(t){return t.z}),w=d3.select("#"+e).append("svg").attr("width",i+f+h).attr("height",d+m+p);w.call(b);var k=w.append("g").attr("transform","translate("+f+","+m+")");graph={nodes:v,links:g};var $=[],E=(v=graph.nodes).length;v.forEach(function(t,e){t.index=e,t.count=0,$[e]=d3.range(E).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){void 0!==$[t.source_id][t.target_id]?($[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):($[t.source_id][t.target_id]={},$[t.source_id][t.target_id].z=0)});var C,A={name:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node,v[e].node)}),count:d3.range(E).sort(function(t,e){return v[e].count-v[t].count}),group:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node_group,v[e].node_group)})};y.domain(A.name),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(i+f+h)/2).attr("y",25).attr("text-anchor","middle").text(u),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(d+m+p)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(c),k.append("rect").attr("class","mode-network-matrix-background").attr("width",i).attr("height",d),(C=k.selectAll(".mode-network-matrix-row").data($).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).each(C)).append("line").attr("class","mode-network-matrix-line").attr("x2",i),C.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(t,e){return v[e].node});var F=k.selectAll(".mode-network-matrix-column").data($).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"});function C(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 y(t.x)}).attr("width",y.rangeBand()).attr("height",y.rangeBand()).style("fill-opacity",function(t){return x(t.z)}).style("fill",function(t){return v[t.x].node_group==v[t.y].node_group?s[v[t.x].node_group]:"#2B2B2B"}).on("mouseover",function(t){var a;a=t,d3.selectAll(".mode-network-matrix-row-text").classed("active",function(t,e){return e==a.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(t,e){return e==a.x}),b.show(t)}).on("mouseout",function(t){d3.selectAll("text").classed("active",!1),b.hide(t)})}F.append("line").attr("class","mode-network-matrix-line").attr("x1",-i),F.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(t,e){return v[e].node}),d3.select("#mode-network-matrix-order-picker-"+e).on("change",function(){!function(t){y.domain(A[t]);var e=k.transition().duration(1e3);e.selectAll(".mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(t){return y(t.x)}),e.selectAll(".mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"})}(this.value)})},hive:function(t){d3.hive={},d3.hive.link=function(){function e(t,e){var a,n=i(d,this,t,e),r=i(s,this,t,e);n.a>r.a&&(a=r,r=n,n=a),r.a-n.a>Math.PI&&(n.a+=2*Math.PI);var o=n.a+(r.a-n.a)/3,l=r.a-(r.a-n.a)/3;return n.r0-n.r1||r.r0-r.r1?"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"L"+Math.cos(n.a)*n.r1+","+Math.sin(n.a)*n.r1+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1+"L"+Math.cos(r.a)*r.r0+","+Math.sin(r.a)*r.r0+"C"+Math.cos(l)*r.r0+","+Math.sin(l)*r.r0+" "+Math.cos(o)*n.r0+","+Math.sin(o)*n.r0+" "+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0:"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1}function i(t,e,a,n){var r=t.call(e,a,n),o=+("function"==typeof c?c.call(e,r,n):c)+h,l=+("function"==typeof u?u.call(e,r,n):u);return{r0:l,r1:u===m?l:+("function"==typeof m?m.call(e,r,n):m),a:o}}var d=function(t){return t.source},s=function(t){return t.target},c=function(t){return t.angle},u=function(t){return t.radius},m=u,h=-Math.PI/2;return e.source=function(t){return arguments.length?(d=t,e):d},e.target=function(t){return arguments.length?(s=t,e):s},e.angle=function(t){return arguments.length?(c=t,e):c},e.radius=function(t){return arguments.length?(u=m=t,e):u},e.startRadius=function(t){return arguments.length?(u=t,e):u},e.endRadius=function(t){return arguments.length?(m=t,e):m},e};var e=alamode.makeId(10),a=t.node_query,n=t.edge_query,r=t.groups_are_numeric,o=t.html_element||"body",l=t.title||queryName,i=t.chart_width||"800",d=t.chart_height||"800",s=t.group_colors||"",c=Math.min(i,d)/2-30,u=.2*c,m=alamode.getDataFromQuery(a),h=alamode.getDataFromQuery(n),p=_.uniq(_.map(m,"node_group")),f={};m.forEach(function(t){t.x=r?t.node_group:p.indexOf(t.node_group),t.y=t.node_size,f[t.node]=t}),h.forEach(function(t){t.source=f[t.source],t.target=f[t.target]});var v=alamode.addContainerElement(o);d3.select(v).append("div").attr("class","mode-graphic-title").text(l),d3.select(v).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e),angle=r?d3.scale.linear().domain(d3.extent(m,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 g=d3.scale.linear().domain(d3.extent(m,function(t){return t.node_size})).range([u,c]),y=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(t){return t.node}),x=d3.select("#"+e).append("svg").attr("width",i).attr("height",d).append("g").attr("transform","translate("+i/2+","+d/2+")");function b(t){return t/Math.PI*180-90}x.call(y),x.selectAll(".mode-hive-axis").data(d3.range(p.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(t){return"rotate("+b(angle(t))+")"}).attr("x1",g.range()[0]).attr("x2",g.range()[1]),x.selectAll(".mode-hive-link").data(h).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(t){return angle(t.x)}).radius(function(t){return g(t.y)})).style("stroke",function(t){return s[t.source.node_group]}),x.selectAll(".mode-hive-node").data(m).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(t){return"rotate("+b(angle(t.x))+")"}).attr("cx",function(t){return g(t.y)}).attr("r",5).style("fill",function(t){return s[t.node_group]}).on("mouseover",function(e){y.show(e),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(h).attr("class",function(t){return t.source.node==e.node||t.target.node==e.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(t){y.hide(t),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(n){var v="#"+n.table_id,t=n.query_name,e=n.column_rules,g=alamode.getDataFromQuery(t),y=(alamode.getColumnsFromQuery(t),{});function a(t){var e,a=$(v+" table"),n=$(v+" .js-header-table"),r=n?$(v+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),y[text]=e}),t.forEach(function(f){f.rules.forEach(function(t){var n,r,o,l,i,d,s,c,e,u,a,m,h,p=t.shade_text||!1;"gradient"==t.type?(c=f.column,e=t.color,u=p,a=d3.extent(_.map(g,c)),m=d3.scale.linear().domain(a).interpolate(d3.interpolateHsl).range(e),h=y[c],g.forEach(function(t,e){var a=v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+h+"']",n=m(t[c]),r=x(n),o=$(a);u?o.css("color",n):o.css({background:n,color:r})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(n=f.column,r=t.type,o=t.value,l=t.color,i=p,d=y[n],s=x(l),g.forEach(function(t,e){var a=$(v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+d+"']");("above"==r&&t[n]>=o||"below"==r&&t[n]<=o||"equal"==r&&t[n]==o)&&(i?a.css("color",l):a.css({background:l,color:s}))}))})})}function x(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){a(e)},1e3),$(v).mousemove(function(){a(e)})},customizeTable:function(t){window.dispatchAction({type:"Embed.AlamodeCustomizeTable",payload:t})},conditionalFormattingByTable:function(n){var m="#"+n.table_id,t=n.query_name,h=n.columns;rules=n.rules;var p=alamode.getDataFromQuery(t),f=(alamode.getColumnsFromQuery(t),{}),a=[];h.forEach(function(t){var e=d3.extent(_.map(p,t));a=a.concat(e)});var v=d3.extent(a);function e(t){var e,a=$(m+" table"),n=$(m+" .js-header-table"),r=n?$(m+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),f[text]=e}),t.forEach(function(t){var o,l,i,d,s,e,c,u,a=t.shade_text||!1;"gradient"==t.type?(e=t.color,c=a,u=d3.scale.linear().domain(v).interpolate(d3.interpolateHsl).range(e),p.forEach(function(l,i){h.forEach(function(t){var e=f[t],a=m+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+e+"']",n=u(l[t]),r=g(n),o=$(a);c?o.css("color",n):o.css({background:n,color:r})})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(o=t.type,l=t.value,i=t.color,d=a,s=g(i),p.forEach(function(n,r){h.forEach(function(t){var e=f[t],a=$(m+" table [data-axel-rowkey='"+r+"'][data-axel-column='"+e+"']");("above"==o&&n[t]>=l||"below"==o&&n[t]<=l||"equal"==o&&n[t]==l)&&(d?a.css("color",i):a.css({background:i,color:s}))})}))})}function g(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){e(rules)},1e3),$(m).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,a=$(this).find("mode-chart").attr("id")||$(this).find("mode-table").attr("id")||$(this).find("mode-python").attr("id");if(!a)return!0;a.includes("chart")||a.includes("table")?(t=document.getElementById(a),e=0<$(t).find("mode-pivot-table").length?document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText:document.getElementById(a).getElementsByClassName("chart-title")[0].innerText):a.includes("python")&&(e=document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText);var n=$(""+(e.includes("Click to add title")?"Untitled":e)+"");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(){$(".scroll-link").on("click",function(t){t.preventDefault();var e,a,n=$(this).attr("href");e=750,a=$(n).offset().top-50,$("html,body").animate({scrollTop:a},e)})},100)},xAnnotations:function(t){var a=t.chart_id,r=t.comment_values,o=t.comments,l=t.color||[],d=t.is_date||!1;setTimeout(function(){var e=$("#"+a).find("div.highcharts-container")[0].id,t=Highcharts.charts;if(chart=t.filter(function(t){if(t)return t.container.id==e})[0],data=chart.series[0].data,d)for(i=0;i").text(t).prependTo(document.body)},getColumnsFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.columns:(alamode.reportError("No such query: '"+e+"'"),[])},getDataFromQuery:function(e){var t=datasets.filter(function(t){if(t)return t.queryName==e})[0];return t?t.content:(alamode.reportError("No such query: '"+e+"'"),[])},makeId:function(t){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",a="",n=0;n").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content"):0===$(t).length?alamode.reportError("No such element: '"+t+"'"):(e&&$(t).empty(),$(t).addClass("mode-graphic-container"),$(t).addClass(id)),"."+id},addLinksToTables:function(t){var l="#"+t.table_id,e=t.link_columns,a=t.link_urls,n=t.query_name,m=t.open_in_new_tab||!1,r=[],h={};e.forEach(function(t,e){r.push({column:t,link_string:a[e]})});var p=alamode.getDataFromQuery(n);alamode.getColumnsFromQuery(n);function o(e){var t,a=$(l+" table"),n=$(l+" .js-header-table"),r=n?$(l+" .js-col-header"):$(n).find("th"),o=a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),t=$(this).attr("data-axel-column"),h[text]=t-1}),o.each(function(t){var c,u;0"+a+"";c.eq(e).html(s)}))})}setTimeout(function(){o(r)},1e3),$(l).mousemove(function(){o(r)})},customChartColors:function(t){var e=t.charts,n=t.colors,d=t.opacity,s=t.line_dashes;function h(t,e){var a=$("#"+t),n=(0TTL",u.forEach(function(t){""!=t.total?e=e+""+s(t.total)+"":e+=""}),e+""),n=+container.css("height").match(/\d+/)[0];t.after(a),container.css("height",26+n)},1e3)},addImagesToTables:function(t){var o="#"+t.table,l=t.column,i=t.image_height||100;function e(){var t=$(o+" table"),e=$(o+" .js-header-table"),a=e?$(o+" .js-col-header"):$(e).find("th"),n=t.find("tr"),r=0;a.each(function(){text=$(this).find(".axel-table-header-label").text(),text==l&&(r=+$(this).attr("data-axel-column"))}),n.each(function(){$(this).find("td").each(function(t){var e;t==r-1&&(e=$(this).text(),0==$(this).find("img").length&&($(this).css("text-align","center"),$(this).html("")))})})}setTimeout(function(){e()},1e3),$(o).keyup(function(){setTimeout(function(){e()},500)}),$(o).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){var a,n,r,e=t.query_name,i=t.cohort_column,d=t.pivot_column,s=t.value_column,o=t.color_gradient||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],l=t.gradient_by||"all",c=t.gradient_column||s,u=t.total_column,m=t.html_element||"body",h=t.title||e,p=t.pivot_label||"",f=t.value_is_percent,v=t.precision||0,g=alamode.getDataFromQuery(e),y=alamode.getColumnsFromQuery(e),x=_.uniq(_.map(g,i)),b=_.sortBy(_.uniq(_.map(g,d))),w=alamode.addContainerElement(m);"cohort_column"===l?(a={},x.forEach(function(e){var t=g.filter(function(t){return t[i]===e});a[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):"pivot_column"===l?(n={},b.forEach(function(e){var t=g.filter(function(t){return t[d]===e});n[e]=d3.scale.quantize().domain(d3.extent(t,function(t){return t[c]})).range(o)})):r=d3.scale.quantize().domain(d3.extent(g,function(t){return t[c]})).range(o),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 k=d3.select(w).append("table").attr("class","mode-retention-heatmap-table");function $(e){return y.filter(function(t){return t.name==e})[0].type}k.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}),k.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 function(r,o){var l=[{column:i,value:o}];{var t,e;u&&(t=_.filter(r,function(t){return t[i]==o})[0],e={column:u,value:t[u]},l=l.concat(e))}return b.forEach(function(e){var t="",a="",n=_.filter(r,function(t){return t[i]==o&&t[d]==e});0=",value:o,color:r[r.length-1]})}}alamode.customizeTable([{vizId:e.vizId,formatByColumn:{columns:(e.columns||[]).map(function(t,e){if(!t)throw new Error("Colum data isn't passed properly.");var a="string"==typeof t?t:(t||{}).name;return o({name:a,color_gradient:t.color_gradient||r[e%r.length],inverse:t.inverse},n[0],function(t){return t[a]})})}}])},googleMap:function(t){var e=alamode.makeId(10),l=t.lat_column,i=t.lng_column,a=t.query_name,n=t.google_maps_api_key,r=t.title||a,d=t.label_column,o=t.html_element||"body",s=t.center_lat||39.5,c=t.center_lng||-98.35,u=t.starting_zoom||4,m=t.map_type||"terrain",h=t.height||600,p=alamode.getDataFromQuery(a),f=alamode.addContainerElement(o);d3.select(f).append("div").attr("class","mode-graphic-title").text(r),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="+n,function(){var t,o;t={zoom:u,center:new google.maps.LatLng(s,c),mapTypeId:m},o=new google.maps.Map(document.getElementById(e),t),p.forEach(function(t){var e=t[l],a=t[i];label=d?t[d]:"";var n=new google.maps.Marker({position:{lat:e,lng:a},map:o,title:label}),r=new google.maps.InfoWindow({content:label});n.addListener("click",function(){r.open(o,n)})})})},leafletMap:function(t){var e=alamode.makeId(10),a=t.lat_column,n=t.lng_column,r=t.query_name,o=t.title||r,l=t.height||400,i=t.html_element||"body",d=t.center_lat||39.5,s=t.center_lng||-98.35,c=t.starting_zoom||4,u=t.dot_size||.4,m=t.dot_opacity||.8,h=t.apply_filter||!1,p=alamode.getDataFromQuery(r),f=[];p.forEach(function(t){"number"==typeof t[a]&&"number"==typeof t[n]&&f.push(t)});var v=alamode.addContainerElement(i,h);d3.select(v).style("height",l+"px").append("div").attr("class","mode-graphic-title").text(o);var g=l-$(v+".mode-graphic-title").height(),y=$(v).width();d3.select(v).append("div").attr("class","mode-leaflet-map").attr("id",e).style("height",g+"px").style("width",y+"px");var x=L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18}),_={max:8,data:f},b={lat:d,lng:s,zoom:c},w=new HeatmapOverlay({radius:u,maxOpacity:m,scaleRadius:!0,useLocalExtrema:!0,latField:a,lngField:n});new L.Map(e,{center:new L.LatLng(b.lat,b.lng),zoom:Math.floor(b.zoom),layers:[x,w]});w.setData(_)},wordCloud:function(t){var e=t.query_name,a=t.word_column,n=t.word_count_column,r=t.html_element||"body",o=t.title||e,l=t.height||"400",i=t.width||"800",d=t.colors||["black"],s=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(s,function(t){return t[n]})).range([12,60]),m=d3.layout.cloud().size([i,l]).words(s.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 d[e%d.length]}).attr("text-anchor","middle").attr("transform",function(t){return"translate("+[t.x,t.y]+")rotate("+t.rotate+")"}).text(function(t){return t.text})});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",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]])});new D3Funnel("#"+e).draw(u,{label:{format:"{l}: {f}"},block:{dynamicHeight:!0},chart:{bottomPinch:1},animation:100}),d3.select("#"+e).style("height",i+"px")},horizontalBarChart:function(r){var t=r.query_name,e=(r.bar_column,r.series_columns),o=r.colors||["#EE8D24","#43A5DA","#6AB328","#BB60F8","#E14459","#EAD022","#06D0AD","#DB38B7"];stacked=r.stacked||!1,leftpad=r.left_pad||175,htmlElement=r.html_element||"body",title=r.title||t,height=r.chart_height||395,width=r.width||"500";var l=alamode.getDataFromQuery(t),a=alamode.addContainerElement(htmlElement);d3.select(a).append("div").attr("class","mode-graphic-title").text(title),d3.select(a).append("div").attr("class","mode-horizontal-bar-chart").style("height",height-50+"px").append("svg");var i=[];e.forEach(function(e,t){var a={key:e,color:o[t%o.length]},n=[];l.forEach(function(t){n.push({label:t[r.bar_column],value:t[e]})}),a.values=n,i.push(a)}),nv.addGraph(function(){var t=nv.models.multiBarHorizontalChart().x(function(t){return t.label}).y(function(t){return t.value}).margin({top:30,right:20,bottom:50,left:leftpad}).showValues(!0).showControls(!1).stacked(stacked);return t.yAxis.tickFormat(d3.format(",.2f")),d3.select(a+" svg").datum(i).call(t),nv.utils.windowResize(t.update),t})},chartAnnotations:function(t){var w="#"+t.chart_id,n=t.x_axis_column,e=t.query_name,k=t.orientations,E=t.comment_values,r=t.group_by,a=t.comments,o=alamode.getDataFromQuery(e),C=[],l={};function i(){a.forEach(function(t,e){var a,n,r,o,l,i,d,s,c,u=C[e],m=k[e],h=E[e],p=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(t){return t}),f=$(w).find("g.nvd3.nv-wrap").attr("transform"),v=f.indexOf("("),g=f.indexOf(")"),x=f.indexOf(","),_=+f.slice(v+1,x),b=+f.slice(x+1,g);-1!=u&&"v"==m?(n=(a=$(w).find(".nv-point.nv-point-"+u).attr("transform")).indexOf("("),r=a.indexOf(")"),o=a.indexOf(","),l=+a.slice(n+1,o),i=+a.slice(o+1,r),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),$(w).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width"),(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",l+_).attr("y",b-5).attr("width",1).attr("class","flag").attr("height",5+i).attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",l+_).attr("cy",b-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide)):"h"!=m&&"h-left"!=m&&"h-right"!=m||(y="h"==m?"":"1",$(w).find("g.nv-y"+y+".nv-axis").find(".tick").each(function(t){lineLength="h-right"==m?+$(w).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(",",""))}),d=(yTrans2-yTrans1)/(yVal2-yVal1),s=yTrans2-yVal2*d+h*d,(c=d3.select(w+" .nvd3svg")).call(p),c.append("rect").attr("x",_).attr("y",s+b).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53"),c.append("circle").data([t]).attr("cx",lineLength+_+10).attr("cy",s+b).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",p.show).on("mouseout",p.hide))})}r&&(l=_.groupBy(o,function(t){return t[r]})),a.forEach(function(t,e){var a=_.filter(o,function(t){return t[n]==E[e]});pointNumber=0!=a.length?r?l[a[0][r]].indexOf(a[0]):o.indexOf(a[0]):-1,C.push(pointNumber)}),setTimeout(function(){d3.select(w).selectAll(".flag").remove(),i()},1e3),$(window).resize(function(){d3.select(w).selectAll(".flag").remove(),s(function(){i()},500,"")});var d,s=(d={},function(t,e,a){d[a=a||"Don't call this twice without a uniqueId"]&&clearTimeout(d[a]),d[a]=setTimeout(t,e)})},bulletChart:function(l){var i=alamode.makeId(10),t=l.query_name,e=l.html_element||"body",a=l.title||t,d=l.chart_width||"800",s=l.bar_column||"",c=l.marker_column||"",u=l.left_pad||150,m=l.color,n=alamode.getDataFromQuery(t),r=alamode.addContainerElement(e);d3.select(r).append("div").attr("class","mode-graphic-title").text(a),d3.select(r).append("div").attr("class","mode-bullet-chart").style("width",d).attr("id",i),n.forEach(function(t){var e=t[l.title_column]||"",a=t[l.subtitle_column]||"",n=t[l.marker_column]||"",r=t[l.bar_column]||"";scale=l.scale_columns?[t[l.scale_columns[0]],t[l.scale_columns[1]],t[l.scale_columns[2]]]:l.scale_columns;var o={title:e,subtitle:a,ranges:scale,measures:[r],measureLabels:[s],markers:[n],markerLabels:[c],color:m};nv.addGraph(function(){var t=nv.models.bulletChart().height(50).width(d).margin({left:u,right:15,top:10,bottom:10});d3.select("#"+i).append("svg").style("width",d+"px").style("height","70px").style("display","inline").datum(o).transition().duration(500).call(t);return t})})},sunburstChart:function(t){var c=alamode.makeId(10),e=t.query_name,n=t.event_columns,r=t.event_counts,a=t.title||e,o=t.color_range||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],l=t.html_element||"body",d=alamode.getDataFromQuery(e),s=850,u=Math.min(s,600)/2,m={w:(s-30)/n.length,h:20,s:3,t:10},h=[];n.forEach(function(t){h=h.concat(_.uniq(_.map(d,t)))});var p=_.uniq(h),f={};p.forEach(function(t,e){null!=t&&(f[t]=o[e%o.length])}),f.end="#666";var v=0,g=alamode.addContainerElement(l);d3.select(g).append("div").attr("class","mode-graphic-title").text(a),d3.select(g).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+c),d3.select(g).append("div").attr("class","mode-sunburst").attr("id",c),d3.select(g).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+c),vis=d3.select("#"+c).append("svg:svg").attr("width",s).attr("height",600).append("svg:g").attr("transform","translate("+s/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-"+c).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-"+c).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 y=d3.layout.partition().size([2*Math.PI,u*u]).value(function(t){return t.size}),x=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)}),b=[];function w(t){var e=(100*t.value/v).toPrecision(3),a=e+"%";e<.1&&(a="< 0.1%");var n=$(t),r=t.parent.value,o=(100*t.value/r).toPrecision(3),l=o+"%";o<1&&(a="< 1%"),d3.select("#cond-percentage-"+c).text(l),d3.select("#percentage-"+c).text(a),d3.selectAll(".mode-sunburst-explanation").style("visibility","");var i,d,s,n=$(t);i=n,d=d3.select("#trail-"+c).selectAll("g").data(i,function(t){return t.name+t.depth}),(s=d.enter().append("svg:g")).append("svg:polygon").attr("points",E).style("fill",function(t){return f[t.name]}),s.append("svg:text").attr("x",(m.w+m.t)/2).attr("y",m.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(t){return t.name}),d.attr("transform",function(t,e){return 5Order: '),d3.select(_).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e);var b=d3.tip().attr("class","mode-network-matrix-tooltip").offset([-10,0]).html(function(t){return t.z}),w=d3.select("#"+e).append("svg").attr("width",i+f+h).attr("height",d+m+p);w.call(b);var k=w.append("g").attr("transform","translate("+f+","+m+")");graph={nodes:v,links:g};var $=[],E=(v=graph.nodes).length;v.forEach(function(t,e){t.index=e,t.count=0,$[e]=d3.range(E).map(function(t){return{x:t,y:e,z:0}})}),graph.links.forEach(function(t){void 0!==$[t.source_id][t.target_id]?($[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):($[t.source_id][t.target_id]={},$[t.source_id][t.target_id].z=0)});var C,A={name:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node,v[e].node)}),count:d3.range(E).sort(function(t,e){return v[e].count-v[t].count}),group:d3.range(E).sort(function(t,e){return d3.ascending(v[t].node_group,v[e].node_group)})};y.domain(A.name),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(i+f+h)/2).attr("y",25).attr("text-anchor","middle").text(u),w.append("text").attr("class","mode-network-matrix-axis-label").attr("x",(d+m+p)/-2).attr("y",25).attr("transform","rotate(-90)").attr("text-anchor","middle").text(c),k.append("rect").attr("class","mode-network-matrix-background").attr("width",i).attr("height",d),(C=k.selectAll(".mode-network-matrix-row").data($).enter().append("g").attr("class","mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).each(C)).append("line").attr("class","mode-network-matrix-line").attr("x2",i),C.append("text").attr("class","mode-network-matrix-row-text").attr("x",-6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","end").text(function(t,e){return v[e].node});var F=k.selectAll(".mode-network-matrix-column").data($).enter().append("g").attr("class","mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"});function C(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 y(t.x)}).attr("width",y.rangeBand()).attr("height",y.rangeBand()).style("fill-opacity",function(t){return x(t.z)}).style("fill",function(t){return v[t.x].node_group==v[t.y].node_group?s[v[t.x].node_group]:"#2B2B2B"}).on("mouseover",function(t){var a;a=t,d3.selectAll(".mode-network-matrix-row-text").classed("active",function(t,e){return e==a.y}),d3.selectAll(".mode-network-matrix-column-text").classed("active",function(t,e){return e==a.x}),b.show(t)}).on("mouseout",function(t){d3.selectAll("text").classed("active",!1),b.hide(t)})}F.append("line").attr("class","mode-network-matrix-line").attr("x1",-i),F.append("text").attr("class","mode-network-matrix-column-text").attr("x",6).attr("y",y.rangeBand()/2).attr("dy",".32em").attr("text-anchor","start").text(function(t,e){return v[e].node}),d3.select("#mode-network-matrix-order-picker-"+e).on("change",function(){!function(t){y.domain(A[t]);var e=k.transition().duration(1e3);e.selectAll(".mode-network-matrix-row").attr("transform",function(t,e){return"translate(0,"+y(e)+")"}).selectAll(".mode-network-matrix-cell").attr("x",function(t){return y(t.x)}),e.selectAll(".mode-network-matrix-column").attr("transform",function(t,e){return"translate("+y(e)+")rotate(-90)"})}(this.value)})},hive:function(t){d3.hive={},d3.hive.link=function(){function e(t,e){var a,n=i(d,this,t,e),r=i(s,this,t,e);n.a>r.a&&(a=r,r=n,n=a),r.a-n.a>Math.PI&&(n.a+=2*Math.PI);var o=n.a+(r.a-n.a)/3,l=r.a-(r.a-n.a)/3;return n.r0-n.r1||r.r0-r.r1?"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"L"+Math.cos(n.a)*n.r1+","+Math.sin(n.a)*n.r1+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1+"L"+Math.cos(r.a)*r.r0+","+Math.sin(r.a)*r.r0+"C"+Math.cos(l)*r.r0+","+Math.sin(l)*r.r0+" "+Math.cos(o)*n.r0+","+Math.sin(o)*n.r0+" "+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0:"M"+Math.cos(n.a)*n.r0+","+Math.sin(n.a)*n.r0+"C"+Math.cos(o)*n.r1+","+Math.sin(o)*n.r1+" "+Math.cos(l)*r.r1+","+Math.sin(l)*r.r1+" "+Math.cos(r.a)*r.r1+","+Math.sin(r.a)*r.r1}function i(t,e,a,n){var r=t.call(e,a,n),o=+("function"==typeof c?c.call(e,r,n):c)+h,l=+("function"==typeof u?u.call(e,r,n):u);return{r0:l,r1:u===m?l:+("function"==typeof m?m.call(e,r,n):m),a:o}}var d=function(t){return t.source},s=function(t){return t.target},c=function(t){return t.angle},u=function(t){return t.radius},m=u,h=-Math.PI/2;return e.source=function(t){return arguments.length?(d=t,e):d},e.target=function(t){return arguments.length?(s=t,e):s},e.angle=function(t){return arguments.length?(c=t,e):c},e.radius=function(t){return arguments.length?(u=m=t,e):u},e.startRadius=function(t){return arguments.length?(u=t,e):u},e.endRadius=function(t){return arguments.length?(m=t,e):m},e};var e=alamode.makeId(10),a=t.node_query,n=t.edge_query,r=t.groups_are_numeric,o=t.html_element||"body",l=t.title||queryName,i=t.chart_width||"800",d=t.chart_height||"800",s=t.group_colors||"",c=Math.min(i,d)/2-30,u=.2*c,m=alamode.getDataFromQuery(a),h=alamode.getDataFromQuery(n),p=_.uniq(_.map(m,"node_group")),f={};m.forEach(function(t){t.x=r?t.node_group:p.indexOf(t.node_group),t.y=t.node_size,f[t.node]=t}),h.forEach(function(t){t.source=f[t.source],t.target=f[t.target]});var v=alamode.addContainerElement(o);d3.select(v).append("div").attr("class","mode-graphic-title").text(l),d3.select(v).append("div").attr("class","mode-network-matrix").style("width",i).attr("id",e),angle=r?d3.scale.linear().domain(d3.extent(m,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 g=d3.scale.linear().domain(d3.extent(m,function(t){return t.node_size})).range([u,c]),y=d3.tip().attr("class","mode-hive-tooltip").offset([-10,0]).html(function(t){return t.node}),x=d3.select("#"+e).append("svg").attr("width",i).attr("height",d).append("g").attr("transform","translate("+i/2+","+d/2+")");function b(t){return t/Math.PI*180-90}x.call(y),x.selectAll(".mode-hive-axis").data(d3.range(p.length)).enter().append("line").attr("class","mode-hive-axis").attr("transform",function(t){return"rotate("+b(angle(t))+")"}).attr("x1",g.range()[0]).attr("x2",g.range()[1]),x.selectAll(".mode-hive-link").data(h).enter().append("path").attr("class","mode-hive-link").attr("d",d3.hive.link().angle(function(t){return angle(t.x)}).radius(function(t){return g(t.y)})).style("stroke",function(t){return s[t.source.node_group]}),x.selectAll(".mode-hive-node").data(m).enter().append("circle").attr("class","mode-hive-node").attr("transform",function(t){return"rotate("+b(angle(t.x))+")"}).attr("cx",function(t){return g(t.y)}).attr("r",5).style("fill",function(t){return s[t.node_group]}).on("mouseover",function(e){y.show(e),d3.select(this).attr("class","mode-hive-node mode-hive-node-selected"),d3.selectAll(".mode-hive-link").data(h).attr("class",function(t){return t.source.node==e.node||t.target.node==e.node?"mode-hive-link-selected":"mode-hive-link"})}).on("mouseout",function(t){y.hide(t),d3.select(this).attr("class","mode-hive-node"),d3.selectAll(".mode-hive-link-selected").attr("class","mode-hive-link")})},conditionalFormattingByColumn:function(n){var v="#"+n.table_id,t=n.query_name,e=n.column_rules,g=alamode.getDataFromQuery(t),y=(alamode.getColumnsFromQuery(t),{});function a(t){var e,a=$(v+" table"),n=$(v+" .js-header-table"),r=n?$(v+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),y[text]=e}),t.forEach(function(f){f.rules.forEach(function(t){var n,r,o,l,i,d,s,c,e,u,a,m,h,p=t.shade_text||!1;"gradient"==t.type?(c=f.column,e=t.color,u=p,a=d3.extent(_.map(g,c)),m=d3.scale.linear().domain(a).interpolate(d3.interpolateHsl).range(e),h=y[c],g.forEach(function(t,e){var a=v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+h+"']",n=m(t[c]),r=x(n),o=$(a);u?o.css("color",n):o.css({background:n,color:r})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(n=f.column,r=t.type,o=t.value,l=t.color,i=p,d=y[n],s=x(l),g.forEach(function(t,e){var a=$(v+" table [data-axel-rowkey='"+e+"'][data-axel-column='"+d+"']");("above"==r&&t[n]>=o||"below"==r&&t[n]<=o||"equal"==r&&t[n]==o)&&(i?a.css("color",l):a.css({background:l,color:s}))}))})})}function x(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){a(e)},1e3),$(v).mousemove(function(){a(e)})},customizeTable:function(t){window.dispatchAction({type:"Embed.AlamodeCustomizeTable",payload:t})},conditionalFormattingByTable:function(n){var m="#"+n.table_id,t=n.query_name,h=n.columns;rules=n.rules;var p=alamode.getDataFromQuery(t),f=(alamode.getColumnsFromQuery(t),{}),a=[];h.forEach(function(t){var e=d3.extent(_.map(p,t));a=a.concat(e)});var v=d3.extent(a);function e(t){var e,a=$(m+" table"),n=$(m+" .js-header-table"),r=n?$(m+" .js-col-header"):$(n).find("th");a.find("tr");r.each(function(){text=$(this).find(".axel-table-header-label").text(),e=$(this).attr("data-axel-column"),f[text]=e}),t.forEach(function(t){var o,l,i,d,s,e,c,u,a=t.shade_text||!1;"gradient"==t.type?(e=t.color,c=a,u=d3.scale.linear().domain(v).interpolate(d3.interpolateHsl).range(e),p.forEach(function(l,i){h.forEach(function(t){var e=f[t],a=m+" table [data-axel-rowkey='"+i+"'][data-axel-column='"+e+"']",n=u(l[t]),r=g(n),o=$(a);c?o.css("color",n):o.css({background:n,color:r})})})):"above"!=t.type&&"below"!=t.type&&"equal"!=t.type||(o=t.type,l=t.value,i=t.color,d=a,s=g(i),p.forEach(function(n,r){h.forEach(function(t){var e=f[t],a=$(m+" table [data-axel-rowkey='"+r+"'][data-axel-column='"+e+"']");("above"==o&&n[t]>=l||"below"==o&&n[t]<=l||"equal"==o&&n[t]==l)&&(d?a.css("color",i):a.css({background:i,color:s}))})}))})}function g(t){var e,a=/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(t);return 125<(n=a?(rgb=(e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t))?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:null,Math.round((299*parseInt(rgb.r)+587*parseInt(rgb.g)+114*parseInt(rgb.b))/1e3)):255)?"#2B2B2B":"#FCFCFC"}setTimeout(function(){e(rules)},1e3),$(m).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,a=$(this).find("mode-chart").attr("id")||$(this).find("mode-table").attr("id")||$(this).find("mode-python").attr("id");if(!a)return!0;a.includes("chart")||a.includes("table")?(t=document.getElementById(a),e=0<$(t).find("mode-pivot-table").length?document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText:document.getElementById(a).getElementsByClassName("chart-title")[0].innerText):a.includes("python")&&(e=document.getElementById(a).getElementsByClassName("in-place-edit-text")[0].innerText);var n=$(""+(e.includes("Click to add title")?"Untitled":e)+"");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(){$(".scroll-link").on("click",function(t){t.preventDefault();var e,a,n=$(this).attr("href");e=750,a=$(n).offset().top-50,$("html,body").animate({scrollTop:a},e)})},100)},xAnnotations:function(t){var a=t.chart_id,r=t.comment_values,o=t.comments,l=t.color||[],d=t.is_date||!1;setTimeout(function(){var e=$("#"+a).find("div.highcharts-container")[0].id,t=Highcharts.charts;if(chart=t.filter(function(t){if(t)return t.container.id==e})[0],data=chart.series[0].data,d)for(i=0;i