diff --git a/alamode.js b/alamode.js index 9058552..9032a5f 100644 --- a/alamode.js +++ b/alamode.js @@ -115,12 +115,14 @@ var alamode = { cName = url.substring(start+2,start+end+2), full = url.substring(start,start+end+4), col = colIndex[cName], - content = data[rowKey][cName]; + content = data[rowKey][cName], + escaped = encodeURIComponent(content); - url = url.replace(full,content); + url = url.replace(full, escaped); } - cells.eq(columnToShow).html("" + cellContent + "") + var newCellContent = $("", {href: url}).text(cellContent); + cells.eq(columnToShow).empty().append(newCellContent); }) } }) diff --git a/alamode.min.js b/alamode.min.js index 6633708..df9b576 100644 --- a/alamode.min.js +++ b/alamode.min.js @@ -1,3 +1,2 @@ -var version="0.20";var alamode={reportError:function(msg){$("

").text(msg).prependTo(document.body)},getColumnsFromQuery:function(queryName){var columns=datasets.filter(function(d){if(d){return d.queryName==queryName}})[0];if(!columns){alamode.reportError("No such query: '"+queryName+"'");return[]}return columns.columns},getDataFromQuery:function(queryName){var data=datasets.filter(function(d){if(d){return d.queryName==queryName}})[0];if(!data){alamode.reportError("No such query: '"+queryName+"'");return[]}return data.content},makeId:function(chars){var possible="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",text="";for(var i=0;i").addClass(id).addClass("mode-graphic-container").appendTo(".mode-content")}else if($(el).length===0){alamode.reportError("No such element: '"+el+"'")}else{if(clear){$(el).empty()}$(el).addClass("mode-graphic-container");$(el).addClass(id)}return"."+id},addLinksToTables:function(o){var tableId="#"+o["table_id"],linkColumns=o["link_columns"],linkURLs=o["link_urls"],queryName=o["query_name"];var linkFormat=[];var colIndex={};linkColumns.forEach(function(l,i){linkFormat.push({column:l,link_string:linkURLs[i]})});var data=alamode.getDataFromQuery(queryName),columns=alamode.getColumnsFromQuery(queryName);setTimeout(function(){drawLinks(linkFormat)},1e3);$(tableId).mousemove(function(){drawLinks(linkFormat)});function drawLinks(linkFormat){var tableDiv=$(tableId+" table"),tableHeader=$(tableId+" .js-header-table"),headers=!tableHeader?$(tableHeader).find("th"):$(tableId+" .js-col-header"),rows=tableDiv.find("tr"),columnIndex=0;headers.each(function(){text=$(this).find(".axel-table-header-label").text();columnIndex=$(this).attr("data-axel-column");colIndex[text]=columnIndex-1});rows.each(function(i){if(i>0&&i<=data.length){var cells=$(this).find("td"),rowKey=cells.first().attr("data-axel-rowkey");linkFormat.forEach(function(l){var columnToShow=colIndex[l.column],cellContent=cells.eq(columnToShow).text();url=l.link_string;while(url.indexOf("{{")!=-1){var chars=url.length,start=url.indexOf("{{"),end=url.substring(start+2,chars).indexOf("}}"),cName=url.substring(start+2,start+end+2),full=url.substring(start,start+end+4),col=colIndex[cName],content=data[rowKey][cName];url=url.replace(full,content)}cells.eq(columnToShow).html(""+cellContent+"")})}})}},customChartColors:function(o){var charts=o["charts"],colors=o["colors"],opacities=o["opacity"],lineDashes=o["line_dashes"];if(charts=="all"){charts=[];$("mode-chart").each(function(){charts.push(this.id)})}function prepColors(id,colorList){var chart=$("#"+id),series=chart.find(".nv-bar").length>0?chart.find(".nv-group"):chart.find(".nv-line").length>0||chart.find(".nv-areaWrap").length>0?chart.find(".nv-noninteractive"):chart.find(".nv-pie .nv-slice"),seriesCount=series.length,legend=chart.find(".nv-series .nv-legend-symbol");var colors={};var m={};var r={};var counter=0;if(legend.length==0&&seriesCount<=1){m[0]=counter;r[counter]=0;colors[0]=colorList[0]}else if(legend.length==0&&seriesCount>1){for(i=0;i0&&isBarLength>0){var lineColor=chart.find(".nv-linePlusBar .nv-linesWrap .nv-groups .nv-series-0").css("fill"),barColor=chart.find(".nv-linePlusBar .nv-barsWrap .nv-bars rect").css("fill");if($(this).closest(".nvtooltip").find(".key")[0].innerText==""){$(this).find("div").css("background-color",barColor)}else{$(this).find("div").css("background-color",lineColor)}}else if(isBarLength>0){if(seriesCount==1){$(this).find("div").css({"background-color":colors[r[seriesCount-i-1]]})}}else if(isAreaLength>0){$(this).find("div").css({"background-color":colors[isAreaLength-i-1]})}else{$(this).find("div").css({"background-color":colors[i]})}});var sliceColor=chart.find(".nv-pie .nv-slice.hover").css("fill");$("html").find(".nvtooltip table .legend-color-guide div").css("background-color",sliceColor)});$(chart).mouseleave(function(){$("html").find(".nvtooltip table .legend-color-guide").remove()})}setInterval(function(){charts.forEach(function(c){drawColors(c,colors)})},500);charts.forEach(function(c){onMouseMove(c,colors)})},addTotalsRow:function(o){var queryName=o["query_name"],selectedTable=o["table_id"]||"",tableId="#"+selectedTable,resultColumns=alamode.getColumnsFromQuery(queryName),data=alamode.getDataFromQuery(queryName),selectedColumns=o["columns_with_totals"],userProvidedFmt=o["fmt"];var fmt=userProvidedFmt||d3.format(",");var columnsWithSums=getColumns(selectedColumns),totals=makeSums(columnsWithSums);function getColumns(selectedColumns){numberColumns=_.map(_.filter(resultColumns,function(c){return["number","integer","float"].indexOf(c.type)!=-1}),"name");if(selectedColumns=="all"){return numberColumns}else{return _.intersection(selectedColumns,numberColumns)}}function makeSums(columnsWithSums){var sumObject=[];resultColumns.forEach(function(c,i){if(columnsWithSums.indexOf(c.name)==-1){var obj={idx:i,name:"",total:""}}else{var values=_.map(data,c.name),total=d3.sum(values);var obj={idx:i,name:c.name,total:total}}sumObject.push(obj)});return sumObject}function makeRow(totals){var rowString="TTL";totals.forEach(function(t){if(t.total!=""){rowString=rowString+""+fmt(t.total)+""}else{rowString=rowString+""}});return rowString+""}setTimeout(function(){if(tableId=="#"){table=$(".main-table");container=$(".js-table-content-container")}else{table=$(tableId+" .main-table");container=$(tableId+" .js-table-content-container")}var lastRow=table.find("tr:last");var totalRow=makeRow(totals);var tableHeight=container.css("height");var tableHeightInt=+tableHeight.match(/\d+/)[0];lastRow.after(totalRow);container.css("height",tableHeightInt+26)},1e3)},addImagesToTables:function(o){var tableId="#"+o["table"],imageColumn=o["column"],imgHeight=o["image_height"]||100;setTimeout(function(){drawImages()},1e3);$(tableId).keyup(function(){setTimeout(function(){drawImages()},500)});$(tableId).mousemove(function(){drawImages()});function drawImages(){var tableDiv=$(tableId+" table"),tableHeader=$(tableId+" .js-header-table"),headers=!tableHeader?$(tableHeader).find("th"):$(tableId+" .js-col-header"),rows=tableDiv.find("tr"),columnIndex=0;headers.each(function(){text=$(this).find(".axel-table-header-label").text();if(text==imageColumn){columnIndex=+$(this).attr("data-axel-column")}});rows.each(function(){var cells=$(this).find("td");cells.each(function(i){if(i==columnIndex-1){var content=$(this).text();if($(this).find("img").length==0){$(this).css("text-align","center");$(this).html("")}}})})}},resizeChartHeight:function(o){var chart=o["chart"],height=o["height"];if(chart.slice(0,6)=="python"){$("#"+chart+" .mode-python").css("height",height);$("#"+chart+" .mode-python").css("max-height",height);$("#"+chart+" img").css("max-height",height)}else{$("#"+chart+" .chart").css("height",height);$("#"+chart+" .chart-svg").css("height",height)}window.dispatchEvent(new Event("resize"))},retentionHeatmap:function(o){var queryName=o["query_name"],cohortColumn=o["cohort_column"],pivotColumn=o["pivot_column"],valueColumn=o["value_column"],colors=o["color_gradient"]||["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],totalColumn=o["total_column"],htmlElement=o["html_element"]||"body",title=o["title"]||queryName,pivotLabel=o["pivot_label"]||"",isPercent=o["value_is_percent"],precision=o["precision"]||0;var data=alamode.getDataFromQuery(queryName),columns=alamode.getColumnsFromQuery(queryName),cohorts=_.uniq(_.map(data,cohortColumn)),pivots=_.uniq(_.map(data,pivotColumn));var uniqContainerClass=alamode.addContainerElement(htmlElement);var color=d3.scale.quantize().domain(d3.extent(data,function(d){return d[valueColumn]})).range(colors);d3.select(uniqContainerClass).append("div").attr("class","mode-graphic-title").text(title);d3.select(uniqContainerClass).append("div").attr("class","mode-retention-heatmap-label").text(pivotLabel);if(totalColumn){headers=[cohortColumn,totalColumn].concat(pivots)}else{headers=[cohortColumn].concat(pivots)}var table=d3.select(uniqContainerClass).append("table").attr("class","mode-retention-heatmap-table");table.selectAll(".mode-retention-heatmap-table-header").data([0]).enter().append("tr").attr("class","mode-retention-heatmap-table-header").selectAll("mode-retention-heatmap-table-header-cell").data(headers).enter().append("td").attr("class",function(d){if(isNaN(d)){return"mode-retention-heatmap-table-header-cell heatmap-string"}else{return"mode-retention-heatmap-table-header-cell heatmap-number"}}).text(function(d){return d});table.selectAll(".mode-retention-heatmap-table-row").data(cohorts).enter().append("tr").attr("class","mode-retention-heatmap-table-row").selectAll(".mode-retention-heatmap-table-cell").data(function(d){return makeRow(data,d)}).enter().append("td").style("background",function(d){if(checkShade(d)){return color(d.value)}}).attr("class",function(d){return cellClass(d)}).text(function(d){return fmt(d,o)});function checkShade(entry){if(entry.value==""){return false}else if(entry.column==pivotColumn||entry.column==totalColumn){return false}else if(entry.column==valueColumn){return true}else{return false}}function cellClass(entry){var type=getDataType(entry.column);if(type=="float"||type=="integer"||type=="number"){return"heatmap-number"}else{return"heatmap-string"}}function getDataType(column){return columns.filter(function(d){return d.name==column})[0].type}function makeRow(data,cohort){var row=[{column:cohortColumn,value:cohort}];if(totalColumn){var total=_.filter(data,function(d){return d[cohortColumn]==cohort})[0],totalObject={column:totalColumn,value:total[totalColumn]};row=row.concat(totalObject)}pivots.forEach(function(p){var matches=_.filter(data,function(d){return d[cohortColumn]==cohort&&d[pivotColumn]==p});if(matches.length>0){entry=d3.mean(_.map(matches,valueColumn))}else{entry=""}row=row.concat({column:valueColumn,value:entry})});return row}function fmt(entry){var type=getDataType(entry.column);var c=d3.format(","),p=d3.format("."+precision+"%"),t=d3.time.format("%b %d, %Y");if(entry.value==""){return entry.value}else if(type=="datetime"||type=="timestamp"||type=="date"){if(typeof moment=="function"){return moment(entry.value).utc().format("ll")}else{return t(new Date(entry.value))}}else if(entry.column==totalColumn){return c(entry.value)}else if(entry.column==valueColumn&&isPercent){return p(entry.value)}else if(entry.column==valueColumn){return c(entry.value)}else{return entry.value}}},googleMap:function(o){var id=alamode.makeId(10);var latColumn=o["lat_column"],lngColumn=o["lng_column"],queryName=o["query_name"],apiKey=o["google_maps_api_key"],title=o["title"]||queryName,labelColumn=o["label_column"],htmlElement=o["html_element"]||"body",centerLat=o["center_lat"]||39.5,centerLng=o["center_lng"]||-98.35,zoom=o["starting_zoom"]||4,mapType=o["map_type"]||"terrain",mapHeight=o["height"]||600;var data=alamode.getDataFromQuery(queryName);var uniqContainerClass=alamode.addContainerElement(htmlElement);d3.select(uniqContainerClass).append("div").attr("class","mode-graphic-title").text(title);d3.select(uniqContainerClass).append("div").attr("class","mode-google-map").attr("id",id).style("height",mapHeight+"px");jQuery.getScript("https://maps.googleapis.com/maps/api/js?key="+apiKey,function(){initMap();function initMap(){var myOptions={zoom:zoom,center:new google.maps.LatLng(centerLat,centerLng),mapTypeId:mapType};var map=new google.maps.Map(document.getElementById(id),myOptions);data.forEach(function(d){var lat=d[latColumn],lng=d[lngColumn];if(labelColumn){label=d[labelColumn]}else{label=""}var marker=new google.maps.Marker({position:{lat:lat,lng:lng},map:map,title:label});var infowindow=new google.maps.InfoWindow({content:label});marker.addListener("click",function(){infowindow.open(map,marker)})})}})},leafletMap:function(o){var id=alamode.makeId(10);var latColumn=o["lat_column"],lngColumn=o["lng_column"],queryName=o["query_name"],title=o["title"]||queryName,height=o["height"]||400,htmlElement=o["html_element"]||"body",centerLat=o["center_lat"]||39.5,centerLng=o["center_lng"]||-98.35,zoom=o["starting_zoom"]||4,dotRadius=o["dot_size"]||.4,dotOpacity=o["dot_opacity"]||.8,applyFilter=o["apply_filter"]||false;var data=alamode.getDataFromQuery(queryName),validData=[];data.forEach(function(d){if(typeof d[latColumn]==="number"&&typeof d[lngColumn]==="number"){validData.push(d)}});var uniqContainerClass=alamode.addContainerElement(htmlElement,applyFilter);d3.select(uniqContainerClass).style("height",height+"px").append("div").attr("class","mode-graphic-title").text(title);var mapHeight=height-$(uniqContainerClass+".mode-graphic-title").height(),mapWidth=$(uniqContainerClass).width();d3.select(uniqContainerClass).append("div").attr("class","mode-leaflet-map").attr("id",id).style("height",mapHeight+"px").style("width",mapWidth+"px");var baseLayer=L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{maxZoom:18});var d={max:8,data:validData};var cfg={radius:dotRadius,maxOpacity:dotOpacity,scaleRadius:true,useLocalExtrema:true,latField:latColumn,lngField:lngColumn};var C={lat:centerLat,lng:centerLng,zoom:zoom};var heatmapLayer=new HeatmapOverlay(cfg);var map=new L.Map(id,{center:new L.LatLng(C.lat,C.lng),zoom:Math.floor(C.zoom),layers:[baseLayer,heatmapLayer]});heatmapLayer.setData(d)},wordCloud:function(o){var queryName=o["query_name"],words=o["word_column"],wordCount=o["word_count_column"],htmlElement=o["html_element"]||"body",title=o["title"]||queryName,height=o["height"]||"400",width=o["width"]||"800",colors=o["colors"]||["black"];var data=alamode.getDataFromQuery(queryName);var uniqContainerClass=alamode.addContainerElement(htmlElement);d3.select(uniqContainerClass).append("div").attr("class","mode-graphic-title").text(title);var textScale=d3.scale.linear().domain(d3.extent(data,function(d){return d[wordCount]})).range([12,60]);var layout=d3.layout.cloud().size([width,height]).words(data.map(function(d){return{text:d[words],size:textScale(d[wordCount])}})).padding(2).rotate(function(){return(~~(Math.random()*6)-3)*360}).font("Impact").fontSize(function(d){return d.size}).on("end",draw);layout.start();function draw(words){d3.select(uniqContainerClass).append("div").attr("class","mode-wordcloud").append("svg").attr("width",layout.size()[0]).attr("height",layout.size()[1]).append("g").attr("transform","translate("+layout.size()[0]/2+","+layout.size()[1]/2+")").selectAll("text").data(words).enter().append("text").style("font-size",function(d){return d.size+"px"}).style("font-family","Impact").style("fill",function(d,i){return colors[i%colors.length]}).attr("text-anchor","middle").attr("transform",function(d){return"translate("+[d.x,d.y]+")rotate("+d.rotate+")"}).text(function(d){return d.text})}},funnel:function(o){var id=alamode.makeId(10);var queryName=o["query_name"],stageColumn=o["stage_column"],valueColumn=o["value_column"],htmlElement=o["html_element"]||"body",title=o["title"]||queryName,height=o["height"]||"300",width=o["width"]||"500";var data=alamode.getDataFromQuery(queryName);var uniqContainerClass=alamode.addContainerElement(htmlElement);d3.select(uniqContainerClass).append("div").attr("class","mode-graphic-title").text(title);d3.select(uniqContainerClass).append("div").attr("class","mode-funnel").attr("id",id).style("width",width+"px").style("height",height-20+"px");var funnelData=[];data.forEach(function(d){funnelData.push([d[stageColumn],d[valueColumn]])});var options={label:{format:"{l}: {f}"},block:{dynamicHeight:true},chart:{bottomPinch:1},animation:100};var chart=new D3Funnel("#"+id);chart.draw(funnelData,options);d3.select("#"+id).style("height",height+"px")},horizontalBarChart:function(o){var queryName=o["query_name"],barColumn=o["bar_column"],seriesColumns=o["series_columns"],colors=o["colors"]||["#EE8D24","#43A5DA","#6AB328","#BB60F8","#E14459","#EAD022","#06D0AD","#DB38B7"];stacked=o["stacked"]||false,leftpad=o["left_pad"]||175,htmlElement=o["html_element"]||"body",title=o["title"]||queryName,height=o["chart_height"]||395,width=o["width"]||"500";var data=alamode.getDataFromQuery(queryName);var uniqContainerClass=alamode.addContainerElement(htmlElement);d3.select(uniqContainerClass).append("div").attr("class","mode-graphic-title").text(title);d3.select(uniqContainerClass).append("div").attr("class","mode-horizontal-bar-chart").style("height",height-50+"px").append("svg");var nvData=[];seriesColumns.forEach(function(s,i){var seriesObj={key:s,color:colors[i%colors.length]};var seriesData=[];data.forEach(function(d){seriesData.push({label:d[o["bar_column"]],value:d[s]})});seriesObj["values"]=seriesData;nvData.push(seriesObj)});nv.addGraph(function(){var chart=nv.models.multiBarHorizontalChart().x(function(d){return d.label}).y(function(d){return d.value}).margin({top:30,right:20,bottom:50,left:leftpad}).showValues(true).showControls(false).stacked(stacked);chart.yAxis.tickFormat(d3.format(",.2f"));d3.select(uniqContainerClass+" svg").datum(nvData).call(chart);nv.utils.windowResize(chart.update);return chart})},chartAnnotations:function(o){var chart="#"+o["chart_id"],xAxis=o["x_axis_column"],queryName=o["query_name"],orientations=o["orientations"],values=o["comment_values"],groupBy=o["group_by"],comments=o["comments"];var data=alamode.getDataFromQuery(queryName);var pointNumbers=[];var dataGroups={};if(groupBy){dataGroups=_.groupBy(data,function(d){return d[groupBy]})}comments.forEach(function(c,i){var match=_.filter(data,function(d){return d[xAxis]==values[i]});if(match.length!=0){if(groupBy){pointNumber=dataGroups[match[0][groupBy]].indexOf(match[0])}else{pointNumber=data.indexOf(match[0])}}else{pointNumber=-1}pointNumbers.push(pointNumber)});function drawComments(){comments.forEach(function(c,i){var pointNumber=pointNumbers[i],orientation=orientations[i],value=values[i];var tip=d3.tip().attr("class","d3-tip").style("z-index",100).offset([-10,0]).html(function(d){return d});var translate=$(chart).find("g.nvd3.nv-wrap").attr("transform"),openPos=translate.indexOf("("),closePos=translate.indexOf(")"),commaPos=translate.indexOf(",");var xTrans=+translate.slice(openPos+1,commaPos),yTrans=+translate.slice(commaPos+1,closePos);if(pointNumber!=-1&&orientation=="v"){var pointTranlate=$(chart).find(".nv-point.nv-point-"+pointNumber).attr("transform"),pointOpenPos=pointTranlate.indexOf("("),pointClosePos=pointTranlate.indexOf(")"),pointCommaPos=pointTranlate.indexOf(",");var xPoint=+pointTranlate.slice(pointOpenPos+1,pointCommaPos),yPoint=+pointTranlate.slice(pointCommaPos+1,pointClosePos);var height=$(chart).find("g.nvd3.nv-wrap").first().find("rect").first().attr("height"),width=$(chart).find("g.nvd3.nv-wrap").first().find("rect").first().attr("width");var svg=d3.select(chart+" .nvd3svg");svg.call(tip);svg.append("rect").attr("x",xPoint+xTrans).attr("y",yTrans-5).attr("width",1).attr("class","flag").attr("height",yPoint+5).attr("fill","#ff8f53");svg.append("circle").data([c]).attr("cx",xPoint+xTrans).attr("cy",yTrans-5).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",tip.show).on("mouseout",tip.hide)}else if(orientation=="h"||orientation=="h-left"||orientation=="h-right"){if(orientation=="h"){y=""}else if("h-left"){y="1"}else{y="2"}var ticks=$(chart).find("g.nv-y"+y+".nv-axis").find(".tick");ticks.each(function(t){if(orientation=="h-right"){lineLength=+$(chart).find("g.nv-y1.nv-axis").find(".tick").first().find("line").attr("x2")}else{lineLength=+$(this).find("line").attr("x2")}tickTrans=$(this).attr("transform");tickClosePos=tickTrans.indexOf(")"),tickCommaPos=tickTrans.indexOf(",");if(t==0){yTrans1=+tickTrans.slice(tickCommaPos+1,tickClosePos);yVal1=+$(this).find("text").text().replace(",","")}else if(t==1){yTrans2=+tickTrans.slice(tickCommaPos+1,tickClosePos);yVal2=+$(this).find("text").text().replace(",","")}});var scalar=(yTrans2-yTrans1)/(yVal2-yVal1),intercept=yTrans2-yVal2*scalar;var lineLocation=intercept+value*scalar;var svg=d3.select(chart+" .nvd3svg");svg.call(tip);svg.append("rect").attr("x",xTrans).attr("y",lineLocation+yTrans).attr("width",lineLength+10).attr("height",1).attr("class","flag").attr("fill","#ff8f53");svg.append("circle").data([c]).attr("cx",lineLength+xTrans+10).attr("cy",lineLocation+yTrans).attr("class","flag").attr("r",5).attr("fill","#ff8f53").on("mouseover",tip.show).on("mouseout",tip.hide)}})}setTimeout(function(){d3.select(chart).selectAll(".flag").remove();drawComments()},1e3);$(window).resize(function(){d3.select(chart).selectAll(".flag").remove();waitForFinalEvent(function(){drawComments()},500,"")});var waitForFinalEvent=function(){var timers={};return function(callback,ms,uniqueId){if(!uniqueId){uniqueId="Don't call this twice without a uniqueId"}if(timers[uniqueId]){clearTimeout(timers[uniqueId])}timers[uniqueId]=setTimeout(callback,ms)}}()},bulletChart:function(o){var id=alamode.makeId(10);var queryName=o["query_name"],htmlElement=o["html_element"]||"body",title=o["title"]||queryName,width=o["chart_width"]||"800",barLabel=o["bar_column"]||"",markerLabel=o["marker_column"]||"",leftpad=o["left_pad"]||150,color=o["color"];var data=alamode.getDataFromQuery(queryName);var uniqContainerClass=alamode.addContainerElement(htmlElement);d3.select(uniqContainerClass).append("div").attr("class","mode-graphic-title").text(title);d3.select(uniqContainerClass).append("div").attr("class","mode-bullet-chart").style("width",width).attr("id",id);data.forEach(function(d){var title=d[o["title_column"]]||"",subtitle=d[o["subtitle_column"]]||"",marker=d[o["marker_column"]]||"",bar=d[o["bar_column"]]||"";if(o["scale_columns"]){scale=[d[o["scale_columns"][0]],d[o["scale_columns"][1]],d[o["scale_columns"][2]]]}else{scale=o["scale_columns"]}var bulletData={title:title,subtitle:subtitle,ranges:scale,measures:[bar],measureLabels:[barLabel],markers:[marker],markerLabels:[markerLabel],color:color};nv.addGraph(function(){var chart=nv.models.bulletChart().height(50).width(width).margin({left:leftpad,right:15,top:10,bottom:10});var svg=d3.select("#"+id).append("svg").style("width",width+"px").style("height",70+"px").style("display","inline").datum(bulletData).transition().duration(500).call(chart);return chart})})},sunburstChart:function(o){var id=alamode.makeId(10);var queryName=o["query_name"],eventColumns=o["event_columns"],valueColumn=o["event_counts"],title=o["title"]||queryName,colorRange=o["color_range"]||["#e41a1c","#377eb8","#4daf4a","#984ea3","#ff7f00","#ffff33","#a65628","#f781bf","#999999"],htmlElement=o["html_element"]||"body";var data=alamode.getDataFromQuery(queryName);var height=600,width=850,radius=Math.min(width,height)/2,breadcrumbWidth=(width-30)/eventColumns.length,b={w:breadcrumbWidth,h:20,s:3,t:10};var fullEventList=[];eventColumns.forEach(function(e){fullEventList=fullEventList.concat(_.uniq(_.map(data,e)))});var events=_.uniq(fullEventList);var colors={};events.forEach(function(e,i){if(e!=null){colors[e]=colorRange[i%colorRange.length]}});colors["end"]="#666";var totalSize=0;var uniqContainerClass=alamode.addContainerElement(htmlElement);d3.select(uniqContainerClass).append("div").attr("class","mode-graphic-title").text(title);d3.select(uniqContainerClass).append("div").attr("class","mode-sunburst-sequence").attr("id","sequence-"+id);d3.select(uniqContainerClass).append("div").attr("class","mode-sunburst").attr("id",id);d3.select(uniqContainerClass).append("div").attr("class","mode-sunburst-legend-container").attr("id","legend-container-"+id);vis=d3.select("#"+id).append("svg:svg").attr("width",width).attr("height",height).append("svg:g").attr("transform","translate("+width/2+","+height/2+")");vis.append("text").attr("x",0).attr("y",-30).attr("text-anchor","middle").attr("class","mode-sunburst-explanation mode-sunburst-percentage").attr("id","percentage-"+id).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-"+id).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 partition=d3.layout.partition().size([2*Math.PI,radius*radius]).value(function(d){return d.size});var arc=d3.svg.arc().startAngle(function(d){return d.x}).endAngle(function(d){return d.x+d.dx}).innerRadius(function(d){return Math.sqrt(d.y)}).outerRadius(function(d){return Math.sqrt(d.y+d.dy)});var formattedData=[];data.forEach(function(d){var sequence="";for(i=0;i.005});var path=vis.data([json]).selectAll("path").data(nodes).enter().append("svg:path").attr("display",function(d){return d.depth?null:"none"}).attr("d",arc).attr("fill-rule","evenodd").style("fill",function(d){return colors[d.name]}).style("opacity",1).on("mouseover",mouseover);vis.on("mouseleave",mouseleave);totalSize=path.node().__data__.value}function mouseover(d){var percentage=(100*d.value/totalSize).toPrecision(3);var percentageString=percentage+"%";if(percentage<.1){percentageString="< 0.1%"}var sequenceArray=getAncestors(d);var parent_conditional_value=d.parent.value;var cond_percentage=(100*d.value/parent_conditional_value).toPrecision(3);var cond_percentageString=cond_percentage+"%";if(cond_percentage<1){percentageString="< 1%"}d3.select("#cond-percentage-"+id).text(cond_percentageString);d3.select("#percentage-"+id).text(percentageString);d3.selectAll(".mode-sunburst-explanation").style("visibility","");var sequenceArray=getAncestors(d);updateBreadcrumbs(sequenceArray,percentageString);d3.selectAll("path").style("opacity",.3);vis.selectAll("path").filter(function(node){return sequenceArray.indexOf(node)>=0}).style("opacity",1)}function mouseleave(d){d3.select("#trail-"+id).style("visibility","hidden");d3.selectAll("path").on("mouseover",null);if(d3.version.split(".")[0]==4){d3.selectAll("path").transition().duration(300).style("opacity",1).on("end",function(){d3.select(this).on("mouseover",mouseover)})}else{d3.selectAll("path").transition().duration(300).style("opacity",1).each("end",function(){d3.select(this).on("mouseover",mouseover)})}d3.selectAll(".mode-sunburst-explanation").style("visibility","hidden")}function getAncestors(node){var path=[];var current=node;while(current.parent){path.unshift(current);current=current.parent}return path}function initializeBreadcrumbTrail(){var trail=d3.select("#sequence-"+id).append("svg:svg").attr("width",width).attr("height",60).attr("id","trail-"+id);trail.append("svg:text").attr("id","endlabel").style("fill","#000")}function breadcrumbPoints(d,i){var points=[];points.push("0,0");points.push(b.w+",0");points.push(b.w+b.t+","+b.h/2);points.push(b.w+","+b.h);points.push("0,"+b.h);if(i>0){points.push(b.t+","+b.h/2)}return points.join(" ")}function updateBreadcrumbs(nodeArray,percentageString){var g=d3.select("#trail-"+id).selectAll("g").data(nodeArray,function(d){return d.name+d.depth});var entering=g.enter().append("svg:g");entering.append("svg:polygon").attr("points",breadcrumbPoints).style("fill",function(d){return colors[d.name]});entering.append("svg:text").attr("x",(b.w+b.t)/2).attr("y",b.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(d){return d.name});g.attr("transform",function(d,i){if(i>5&&i<10){i=i-5;return"translate("+i*(b.w+b.s)+", 20)"}else if(i>10){i=i-11;return"translate("+i*(b.w+b.s)+", 40)"}else{return"translate("+i*(b.w+b.s)+", 0)"}});g.exit().remove();d3.select("#trail-"+id).style("visibility","")}function drawLegend(){var li={w:195,h:30,s:3,r:3};d3.entries(colors).forEach(function(c){divContainer=d3.select("#legend-container-"+id).append("div").attr("class","mode-sunburst-legend").attr("id","legend-"+id);svg=divContainer.append("svg:svg").attr("width",li.w).attr("height",li.h);svg.append("svg:rect").attr("rx",li.r).attr("ry",li.r).attr("width",li.w).attr("height",li.h).style("fill",function(){return c.value});svg.append("svg:text").attr("x",li.w/2).attr("y",li.h/2).attr("dy","0.35em").attr("text-anchor","middle").text(function(){return c.key})})}function buildHierarchy(csv){var root={name:"root",children:[]};for(var i=0;i"+text+""})},forceDirectedGraph:function(o){var id=alamode.makeId(10);var nodeQuery=o["node_query"],edgeQuery=o["edge_query"],htmlElement=o["html_element"]||"body",title=o["title"]||queryName,width=o["chart_width"]||"800",height=o["chart_height"]||"800",colors=o["group_colors"]||"",visibleLinks=o["links_to_show"]||100;var nodes=alamode.getDataFromQuery(nodeQuery),initialLinks=alamode.getDataFromQuery(edgeQuery);var links=[];initialLinks.forEach(function(l){var match1=links.filter(function(d){return d.target==l.source}),match2=match1.filter(function(d){return d.source==l.target});if(match2.length!=0){match2["edge_size"]+=l.edge_size}else{links.push(l)}});links=links.sort(function(a,b){return b.edge_size-a.edge_size});links=links.slice(0,visibleLinks);nameMap={};nodes.forEach(function(d,i){d["id"]=i;nameMap[d.node]=i});links.forEach(function(d){d["source_id"]=nameMap[d.source];d["target_id"]=nameMap[d.target]});var uniqContainerClass=alamode.addContainerElement(htmlElement);d3.select(uniqContainerClass).append("div").attr("class","mode-graphic-title").text(title);d3.select(uniqContainerClass).append("div").attr("class","mode-force-directed-graph").style("width",width).attr("id",id);var tip=d3.tip().attr("class","mode-force-directed-graph-tooltip").offset([-10,0]).html(function(d){return d.node});var force=d3.layout.force().linkDistance(40).linkStrength(1).size([width,height]);var svg=d3.select("#"+id).append("svg").attr("width",width).attr("height",height);svg.call(tip);var graph={nodes:nodes,links:links};var nodeSizeScale=d3.scale.linear().domain(d3.extent(nodes,function(d){return d.node_size})).range([2,20]);var edgeSizeScale=d3.scale.linear().domain(d3.extent(links,function(d){return d.edge_size})).range([1,10]);var edgeOpacityScale=d3.scale.linear().domain(d3.extent(links,function(d){return d.edge_size})).range([.1,.9]);var nodes=graph.nodes.slice(),links=[],bilinks=[];graph.links.forEach(function(link){var s=nodes[link.source_id],t=nodes[link.target_id],i={};i["connections"]=link["edge_size"];nodes.push(i);links.push({source:s,target:i},{source:i,target:t});bilinks.push([s,i,t])});force.nodes(nodes).links(links).start();var link=svg.selectAll(".mode-force-directed-graph-link ").data(bilinks).enter().append("path").attr("class","mode-force-directed-graph-link").style("stroke-width",function(d){return edgeSizeScale(d[1]["connections"])}).style("opacity",function(d){return edgeOpacityScale(d[1]["connections"])});var node=svg.selectAll(".mode-force-directed-graph-node").data(graph.nodes).enter().append("g").attr("class","mode-force-directed-graph-node").call(force.drag);node.append("circle").attr("r",function(d){return nodeSizeScale(d.node_size)}).style("fill",function(d){if(colors){return colors[d.node_group]}else{return"#0E819A"}}).on("mouseover",tip.show).on("mouseout",tip.hide);force.on("tick",function(){link.attr("d",function(d){return"M"+d[0].x+","+d[0].y+"S"+d[1].x+","+d[1].y+" "+d[2].x+","+d[2].y});node.attr("transform",function(d){return"translate("+d.x+","+d.y+")"})})},networkMatrix:function(o){var id=alamode.makeId(10);var nodeQuery=o["node_query"],edgeQuery=o["edge_query"],htmlElement=o["html_element"]||"body",title=o["title"]||queryName,padding=o["padding_for_names"]||"200",width=o["chart_width"]||"800",height=o["chart_height"]||"800",colors=o["group_colors"]||"",leftLabel=o["left_label"]||"",topLabel=o["top_label"]||"";var margin={top:padding,right:10,bottom:10,left:padding};var nodes=alamode.getDataFromQuery(nodeQuery),links=alamode.getDataFromQuery(edgeQuery);nameMap={};nodes.forEach(function(d,i){d["id"]=i;nameMap[d.node]=i});links.forEach(function(d){d["source_id"]=nameMap[d.source];d["target_id"]=nameMap[d.target]});var x=d3.scale.ordinal().rangeBands([0,width]);var z=d3.scale.linear().domain(d3.extent(links,function(d){return d.edge_size})).clamp(true);var uniqContainerClass=alamode.addContainerElement(htmlElement);d3.select(uniqContainerClass).append("div").attr("class","mode-graphic-title").text(title);d3.select(uniqContainerClass).append("div").attr("class","mode-network-matrix-order-picker").html('

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

");$(".row").each(function(){var cols=$(this).children();cols.each(function(){var title;var chartId=$(this).find("mode-chart").attr("id")||$(this).find("mode-table").attr("id")||$(this).find("mode-python").attr("id");if(!chartId){return true}if(chartId.includes("chart")||chartId.includes("table")){var element=document.getElementById(chartId);if($(element).find("mode-pivot-table").length>0){title=document.getElementById(chartId).getElementsByClassName("in-place-edit-text")[0].innerText}else{title=document.getElementById(chartId).getElementsByClassName("chart-title")[0].innerText}}else if(chartId.includes("python")){title=document.getElementById(chartId).getElementsByClassName("in-place-edit-text")[0].innerText}var newlink=$(""+(title.includes("Click to add title")?"Untitled":title)+"");nav.append(newlink)})});var newdiv=$("
");$(".mode-content").prepend(newdiv);var newrow=$("
");newdiv.prepend(newrow);var newcol=$("
");newrow.prepend(newcol);newcol.prepend(nav);if(!!textColor){$(".fixed-nav-bar a").css("color",textColor)}if(!!backgroundColor){$(".fixed-nav-bar").css("background-color",backgroundColor)}if(!!hoverColor){$(".fixed-nav-bar a").hover(function(){$(this).css("color",hoverColor)},function(){if(!!textColor){$(this).css("color",textColor)}else{$(this).css("color","")}})}setTimeout(function(){$(".scroll-link").on("click",function(event){event.preventDefault();var sectionID=$(this).attr("href");scrollToID(sectionID,750)});function scrollToID(id,speed){var offSet=50;var targetOffset=$(id).offset().top-offSet;$("html,body").animate({scrollTop:targetOffset},speed)}},100); -}}; +var version="0.20",alamode={reportError:function(e){$("

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

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

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