This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
spider.js
1 lines (1 loc) · 19 KB
/
spider.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.spider=t():e.spider=t()}(window,(function(){return function(e){var t={};function a(n){if(t[n])return t[n].exports;var l=t[n]={i:n,l:!1,exports:{}};return e[n].call(l.exports,l,l.exports,a),l.l=!0,l.exports}return a.m=e,a.c=t,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(a.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var l in e)a.d(n,l,function(t){return e[t]}.bind(null,l));return n},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(e,t){function a(e,t,a,n,l,i,o,d){var c={w:600,h:600,margin:{top:20,right:20,bottom:20,left:20},levels:3,maxValue:0,labelFactor:1.325,wrapWidth:60,opacityArea:.15,dotRadius:5,opacityCircles:.15,strokeWidth:2,roundStrokes:!0,color:d3.scale.category10(),legendSide:"left",glow:2,negatives:!0,axisColor:"#CDCDCD",backgroundColor:"#CDCDCD",negativeR:.81,independent:!0,axisFont:2,scaleFont:1,legendPad:10,legendFont:.8,domainMax:null,labelScale:!0};if(void 0!==a)for(var u in a)void 0!==a[u]&&(c[u]=a[u]);var p=c.domainMax?Math.max(c.domainMax,d3.max(t,(function(e){return d3.max(e.map((function(e){return e.value})))}))):d3.max(t,(function(e){return d3.max(e.map((function(e){return e.value})))})),f=Math.min(c.w,c.h),g=t[0].map((function(e,t){return e.axis})),y=g.length,v=Math.min(.35*f,"center"===c.legendSide?.3*f:.45*f),h=d3.format(",.0f"),m=2*Math.PI/y;if(c.independent)axesMax=[],t.forEach((function(e){e.forEach((function(e){e.axis in axesMax?Math.abs(e.value)>axesMax[e.axis]&&(axesMax[e.axis]=Math.abs(e.value)):axesMax[e.axis]=Math.abs(e.value)}))})),rScale=[],g.map((function(e){rScale.push(d3.scale.linear().range([0,v]).domain([0,axesMax[e]]))})),p=[],g.map((function(e){p.push(axesMax[e])}));else{var x=c.domainMax?Math.max(c.domainMax,d3.max(t,(function(e){return d3.max(e.map((function(e){return e.value})))}))):d3.max(t,(function(e){return d3.max(e.map((function(e){return e.value})))}));rScale=[],g.map((function(e){rScale.push(d3.scale.linear().range([0,v]).domain([0,p]))})),p=[],g.map((function(e){p.push(x)}))}d3.select(e).select("svg").remove();var b=d3.select(e).append("svg").attr("font-family",'"Open Sans", "Noto Sans JP", "Noto Sans CJK KR", sans-serif').attr("width",c.w).attr("height",c.h+c.margin.bottom).attr("class","radar"+e),_="center"===c.legendSide?c.h/2-c.margin.top:c.h/2+c.margin.top,M=b.append("g").attr("transform","translate("+c.w/2+","+_+")"),S=M.append("defs").append("filter").attr("id","glow"),A=(S.append("feGaussianBlur").attr("stdDeviation",""+c.glow).attr("result","coloredBlur"),S.append("feMerge")),C=(A.append("feMergeNode").attr("in","coloredBlur"),A.append("feMergeNode").attr("in","SourceGraphic"),M.append("g").attr("class","axisWrapper"));c.independent?g.forEach((function(e,t){d3.range(1,c.levels+1).reverse().forEach((function(e,a){C.append("text").attr("class","axisLabel").attr("x",e/c.levels*v*Math.cos(m*t-Math.PI/2)).attr("y",e/c.levels*v*Math.sin(m*t-Math.PI/2)).attr("dy","0.35em").attr("dy","0.35em").style("font-size",(c.labelScale?c.scaleFont:0)+"px").style("font-weight","900").style("z-index",10).attr("fill",c.axisColor).text(h(p[t]*e/c.levels))}))})):C.selectAll(".axisLabel").data(d3.range(1,c.levels+1).reverse()).enter().append("text").attr("class","axisLabel").attr("x",4).attr("y",(function(e){return-e*v/c.levels})).attr("dy","0.4em").style("font-size",(c.labelScale?c.scaleFont:0)+"px").style("font-weight","900").style("z-index",10).attr("fill",c.axisColor).text((function(e){return h(p[0]*e/c.levels)}));var P=1;c.roundStrokes?P=1:3==y?P=.5:5==y?P=.81:7==y?P=.9:9==y?P=.94:11==y&&(P=.96);var k=C.selectAll(".axis").data(g).enter().append("g").attr("class","axis");k.append("line").attr("x1",(function(e,t){return c.roundStrokes?c.negatives?rScale[t](-1*p[t])*Math.cos(m*t-Math.PI/2):0:c.negatives?rScale[t](p[t]*-P)*Math.cos(m*t-Math.PI/2):0})).attr("y1",(function(e,t){return c.roundStrokes?c.negatives?rScale[t](-1*p[t])*Math.sin(m*t-Math.PI/2):0:c.negatives?rScale[t](p[t]*-P)*Math.sin(m*t-Math.PI/2):0})).attr("x2",(function(e,t){return rScale[t](1*p[t])*Math.cos(m*t-Math.PI/2)})).attr("y2",(function(e,t){return rScale[t](1*p[t])*Math.sin(m*t-Math.PI/2)})).attr("class","line").style("stroke",(function(e,t){return c.axisColor})).style("stroke-width","2px"),k.append("text").attr("class","legend").style("font-size",c.axisFont+"px").style("font-weight","549").attr("text-anchor","middle").style("fill","rgb(102, 102, 102)").attr("dy","1em").attr("x",(function(e,t){return rScale[t](p[t]*c.labelFactor)*Math.cos(m*t-Math.PI/2)})).attr("y",(function(e,t){return rScale[t](p[t]*c.labelFactor)*Math.sin(m*t-Math.PI/2)-c.labelFine})).text((function(e){return e})).call((function(e,t){e.each((function(){for(var e,a=d3.select(this),n=a.text().split(/\s+/).reverse(),l=[],r=0,i=a.attr("y"),s=a.attr("x"),o=parseFloat(a.attr("dy")),d=a.text(null).append("tspan").attr("x",s).attr("y",i).attr("dy",o+"em");e=n.pop();)l.push(e),d.text(l.join(" ")),d.node().getComputedTextLength()>t&&(l.pop(),d.text(l.join(" ")),l=[e],d=a.append("tspan").attr("x",s).attr("y",i).attr("dy",1.4*++r+o+"em").text(e))}))}),c.wrapWidth),c.roundStrokes?C.selectAll(".levels").data(d3.range(1,c.levels+1).reverse()).enter().append("circle").attr("class","gridCircle").attr("r",(function(e,t){return v/c.levels*e})).style("fill",(function(e,t){return c.backgroundColor})).style("stroke",(function(e,t){return c.axisColor})).style("fill-opacity",c.opacityCircles).style("filter","url(#glow)"):c.independent?(levels=[],C.selectAll(".axisLabel").forEach((function(e){s=e.length;var t=s/y;e.slice(0,t).forEach((function(e){set=[],r=parseInt(e.getAttribute("y")),k[0].forEach((function(e,t){tempx=r*Math.cos(m*t-3*Math.PI/2),tempy=r*Math.sin(m*t-3*Math.PI/2),set.push({x:tempx,y:tempy})})),levels.push(set)}))})),levels.forEach((function(e){C.selectAll(".levels").data([e]).enter().append("polygon").attr("points",(function(e){return e.map((function(e){return[e.x,e.y].join(",")})).join(" ")})).attr("class","gridCircle").style("fill",(function(e,t){return c.backgroundColor})).style("stroke",(function(e,t){return c.axisColor})).style("fill-opacity",c.opacityCircles).style("filter","url(#glow)")}))):(levels=[],C.selectAll(".axisLabel").forEach((function(e){s=e.length,e.forEach((function(e){set=[],r=parseInt(e.getAttribute("y")),k[0].forEach((function(e,t){tempx=r*Math.cos(m*t-3*Math.PI/2),tempy=r*Math.sin(m*t-3*Math.PI/2),set.push({x:tempx,y:tempy})})),levels.push(set)}))})),levels.forEach((function(e){C.selectAll(".levels").data([e]).enter().append("polygon").attr("points",(function(e){return e.map((function(e){return[e.x,e.y].join(",")})).join(" ")})).attr("class","gridCircle").style("fill",(function(e,t){return c.backgroundColor})).style("stroke",(function(e,t){return c.axisColor})).style("fill-opacity",c.opacityCircles).style("filter","url(#glow)")})));var w=d3.svg.line.radial().interpolate("linear-closed").radius((function(e,t){return rScale[t](c.negatives?e.value<0?.8*e.value:e.value:e.value<0?0:e.value)})).angle((function(e,t){return t*m}));c.roundStrokes&&w.interpolate("cardinal-closed");var D=M.selectAll(".radarWrapper").data(t).enter().append("g").attr("class","radarWrapper").attr("id",(function(e,t){return"v"+n[t].label.replace(/[^A-Z0-9]+/gi,"")}));D.append("path").attr("class","radarArea").attr("id",(function(e,t){return"v"+n[t].label.replace(/[^A-Z0-9]+/gi,"")})).attr("d",(function(e,t){return w(e)})).style("fill",(function(e,t){return c.color(t)})).style("fill-opacity",c.opacityArea).on("mouseover",(function(e,t){d3.selectAll(".radarArea").transition().duration(200).style("fill-opacity",.1),d3.select(this).transition().duration(200).style("fill-opacity",.7)})).on("mouseout",(function(){d3.selectAll(".radarArea").transition().duration(200).style("fill-opacity",c.opacityArea)})),D.append("path").attr("class","radarStroke").attr("d",(function(e,t){return w(e)})).style("stroke-width",c.strokeWidth+"px").style("stroke",(function(e,t){return c.color(t)})).style("fill","none").style("filter","url(#glow)"),D.selectAll(".radarCircle").data((function(e,t){return e})).enter().append("circle").attr("class","radarCircle").attr("r",c.dotRadius).attr("cx",(function(e,t){return rScale[t](c.negatives?e.value<0?e.value*c.negativeR:e.value:e.value<0?0:e.value)*Math.cos(m*t-Math.PI/2)})).attr("cy",(function(e,t){return rScale[t](c.negatives?e.value<0?e.value*c.negativeR:e.value:e.value<0?0:e.value)*Math.sin(m*t-Math.PI/2)})).style("fill",(function(e,t,a){return c.color(a)})).style("fill-opacity",1),M.selectAll(".radarCircleWrapper").data(t).enter().append("g").attr("class","radarCircleWrapper").attr("child_id",(function(e,t){return"v"+n[t].label.replace(/[^A-Z0-9]+/gi,"")})).selectAll(".radarInvisibleCircle").data((function(e,t){return e})).enter().append("circle").attr("class","radarInvisibleCircle").attr("series_id",(function(e,t){return this.parentNode.getAttribute("child_id")})).attr("r",3*c.dotRadius).attr("cx",(function(e,t){return rScale[t](c.negatives?e.value<0?e.value*c.negativeR:e.value:e.value<0?0:e.value)*Math.cos(m*t-Math.PI/2)})).attr("cy",(function(e,t){return rScale[t](c.negatives?e.value<0?e.value*c.negativeR:e.value:e.value<0?0:e.value)*Math.sin(m*t-Math.PI/2)})).style("fill","none").style("pointer-events","all").on("mouseover",(function(e,t){newX=parseFloat(d3.select(this).attr("cx"))-10,newY=parseFloat(d3.select(this).attr("cy"))-10,d3.selectAll(".radarArea").transition().duration(200).style("fill-opacity",.1),d3.select(".radarArea#"+this.parentNode.getAttribute("child_id")).transition().duration(200).style("fill-opacity",.7);var a={value:e.rendered};E.attr("x",newX).attr("y",newY).text(LookerCharts.Utils.textForCell(a)).transition().duration(200).style("pointer-events","none").style("opacity",1)})).on("click",(function(e,t){LookerCharts.Utils.openDrillMenu({links:e.links,event:event})})).on("mouseout",(function(){E.transition().duration(200).style("opacity",0),d3.selectAll(".radarArea").transition().duration(200).style("fill-opacity",c.opacityArea)}));var E=M.append("text").attr("class","tooltip").style("opacity",0),I=document.createElement("style");I.type="text/css",I.innerHTML="g.radarWrapper.hidden { opacity: 0.0; } .legendCells .hidden { opacity: 0.2;text-align:center }";var F=d3.scale.ordinal().domain(n.map(e=>e.label)).range(n.map((e,t)=>c.color(t)));b=d3.select("svg"),"left"===c.legendSide?(legx=20,legy=10,leg_orient="vertical",leg_pad=c.legendPad+0):"right"===c.legendSide?(legx=1.25*c.w,legy=20,leg_orient="vertical",leg_pad=c.legendPad+0):"center"===c.legendSide?(legy=window.innerHeight-60,leg_orient="horizontal",leg_pad=c.legendPad+50):"none"===c.legendSide&&(legx=-100,legy=-150,leg_orient="vertical",leg_pad=c.legendPad+70),b.append("g").attr("class","legendOrdinal").style("font-size",c.legendFont+"px").style("fill","rgb(102, 102, 102)");var L=d3.legend.color().shape("path",d3.svg.symbol().type("circle").size(120)()).shapePadding(leg_pad).scale(F).orient(leg_orient).on("cellclick",(function(e){!function(e){d3.selectAll("#v"+e).classed("hidden",(function(){return!d3.select(this).classed("hidden")}))}(e=e.replace(/[^A-Z0-9]+/gi,""));const t=d3.select(this);t.classed("hidden",!t.classed("hidden")),series_sel=d3.select("#v"+e)[0][0].classList.contains("hidden"),series_sel?(d3.select("#v"+e).style("opacity","0").style("pointer-events","none"),d3.selectAll(`[child_id=v${e}]`).style("pointer-events","none"),d3.selectAll(`[series_id=v${e}]`).style("pointer-events","none")):(d3.select("#v"+e).style("opacity","1").style("pointer-events",null),d3.selectAll(`[child_id=v${e}]`).style("pointer-events","all"),d3.selectAll(`[series_id=v${e}]`).style("pointer-events","all")),legend_tru=t[0][0].classList.contains("hidden"),legend_tru?d3.select(this).style("opacity",".2"):d3.select(this).style("opacity","1")}));b.select(".legendOrdinal").call(L),"center"==c.legendSide?(wid=window.innerWidth/2-d3.select(".legendCells").node().getBBox().width/2+c.margin.left,d3.select(".legendOrdinal").attr("transform",(function(e){return`translate(${wid},${legy})`}))):"right"==c.legendSide?(wid=window.innerWidth-1.25*d3.select(".legendCells").node().getBBox().width,d3.select(".legendOrdinal").attr("transform",(function(e){return`translate(${wid},${legy})`}))):d3.select(".legendOrdinal").attr("transform",(function(e){return`translate(${legx},${legy})`})),d()}const n={levels:{type:"number",label:"Levels",default:4,section:"Plot"},label_factor:{type:"number",label:"Axis Label Padding",default:85,section:"Plot - Advanced",display:"range",order:4},label_fine:{type:"number",label:"Axis Label Positioning",default:6,section:"Plot - Advanced",display:"range",order:5},levels:{type:"number",label:"Plot Levels",default:3,section:"Plot"},domain_max:{type:"number",label:"Axis Max Override",section:"Plot"},rounded_strokes:{type:"string",label:"Rounded Strokes?",display:"select",values:[{true:!0},{false:!1}],default:!0,section:"Plot"},independent:{type:"string",label:"Normalize Axes?",display:"select",values:[{true:!0},{false:!1}],default:!1,section:"Plot"},labelScale:{type:"string",label:"Label Scale?",display:"select",values:[{true:!0},{false:!1}],default:!0,section:"Plot"},negatives:{type:"string",label:"Allow Negatives?",display:"select",values:[{true:!0},{false:!1}],default:!1,section:"Plot"},wrap_width:{type:"number",label:"Axis Label Wrapping",default:100,section:"Plot - Advanced",order:6},opacity_area:{type:"number",label:"Area Darkness",display:"range",default:15,section:"Series",order:0},dot_radius:{type:"number",label:"Point Radius",default:30,display:"range",section:"Series",order:1},opacity_circles:{type:"number",label:"Background Darkness",display:"range",default:15,section:"Plot - Advanced",order:2},backgroundColor:{type:"string",label:"Background Color",display:"color",section:"Plot - Advanced",default:"#CDCDCD",order:1},axisColor:{type:"string",label:"Axis Color",display:"color",section:"Plot - Advanced",default:"#CDCDCD",order:0},stroke_width:{type:"number",label:"Stroke Width",default:15,display:"range",section:"Series",order:2},glow:{type:"number",label:"Glow Range",default:2,display:"range",section:"Plot - Advanced"},axis_label_font:{type:"number",label:"Axis Label Font Size (px)",default:12,section:"Plot - Advanced"},axis_scale_font:{type:"number",label:"Scale Font Size (px)",default:12,section:"Plot - Advanced"},legend_font:{type:"number",label:"Legend Font Size (px)",default:12,section:"Plot - Advanced"},legend_padding:{type:"number",label:"Legend Item Padding",default:20,display:"range",section:"Plot - Advanced"},legend_side:{type:"string",label:"Legend",display:"select",values:[{none:"none"},{left:"left"},{right:"right"},{center:"center"}],default:"left",section:"Plot"}},l={create:function(e,t){e.innerHTML='<div style=\'font-family: "Open Sans", "Noto Sans JP", "Noto Sans", "Noto Sans CJK KR", Helvetica, Arial, sans-serif;\'/>'},updateAsync:function(e,t,l,r,i,s){const o=function(e,t){let a=parseInt(e,16)+t,n=a>255?255:a;return n.toString(16).length>1?n.toString(16):"0"+n.toString(16)},d=(e,t)=>(e=e.indexOf("#")>=0?e.substring(1,e.length):e,t=parseInt(255*t/100),`#${o(e.substring(0,2),t)}${o(e.substring(2,4),t)}${o(e.substring(4,6),t)}`);var c={top:20,right:20,bottom:20,left:20},u=t.clientWidth,p=t.clientHeight;t.innerHTML="";var f=d3.select("#vis").append("svg").attr("width",u).attr("height",p).append("g").attr("transform","translate("+c.left+","+c.top+")"),g=["#4A80BC","#615894","#F0C733","#D13452","#E48522","#B977A9","#7bc739","#92b3d7","#e38597"];if(r.pivots){if(series=[],!(r.fields.measure_like.length%2)&&l.negatives)return void this.addError({title:"Can't display negatives with symmetric axes.",message:"Negatives can only be plotted on odd number of axes."});if(r.fields.measure_like.length<3)return void this.addError({title:"Multiple measures only.",message:"This chart requires at least 3 measures."});if(r.fields.dimensions.length>0)return void this.addError({title:"Single dimension only.",message:"This chart accepts only 1, pivoted or unpivoted dimension."});r.pivots.forEach((function(e){series.push(e.key)})),originalData=e,axes=[],r.fields.measure_like.forEach((function(e){axes.push({name:e.name,label:e.label_short})})),formattedData=[],moreData=[],series.forEach((function(t,a){values=[],axes.forEach((function(a){values.push({axis:a.label,name:a.name,value:e[0][a.name][t].value,rendered:e[0][a.name][t].rendered?e[0][a.name][t].rendered:e[0][a.name][t].value,links:e[0][a.name][t].links})})),set=[],values.forEach((function(e){set.push(e)})),moreData.push({label:t,data:set,color:a<9?g[a]:d("#D13452",1.7*a)}),formattedData.push(set)}))}else{if(series=[],!(r.fields.measure_like.length%2)&&l.negatives)return console.log("troof"),void this.addError({title:"Can't display negatives with symmetric axes.",message:"Negatives can only be plotted on odd number of axes."});if(r.fields.measure_like.length<3)return void this.addError({title:"Multiple measures only.",message:"This chart requires at least 3 measures."});if(r.fields.dimension_like.length>1)return void this.addError({title:"Single dimension only.",message:"This chart accepts only 1, pivoted or unpivoted dimension."});originalData=e,qrn=r.fields.dimensions[0].name,axes=[],r.fields.measure_like.forEach((function(e){axes.push({name:e.name,label:e.label_short?e.label_short:e.label})})),formattedData=[],moreData=[],e.forEach((function(e,t){values=[],axes.forEach((function(t){values.push({axis:t.label,name:t.name,value:e[t.name].value,rendered:e[t.name].rendered?e[t.name].rendered:e[t.name].value,links:e[t.name].links})})),set=[],values.forEach((function(e){set.push(e)})),moreData.push({label:String(e[qrn].value),data:set,color:t<9?g[t]:d("#D13452",1.7*t)}),formattedData.push(set)})),series=moreData.map(e=>e.label)}opt=Object.assign({},n),moreData.forEach((function(e,t){opt[e.label+"_color"]={type:"string",label:e.label+" - Color",display:"color",section:"Series",default:""+e.color}})),this.trigger("registerOptions",opt);var y=d3.scale.ordinal().range(Object.keys(l).filter((function(e){return-1!==e.indexOf("_color")})).map((function(e){return l[e]}))),v={w:u,h:p,margin:c,maxValue:.5,levels:l.levels,roundStrokes:l.rounded_strokes,color:y,axisFont:l.axis_label_font,scaleFont:l.axis_scale_font,labelFactor:1.5*l.label_factor/100,labelFine:1.2*l.label_fine,wrapWidth:l.wrap_width,opacityArea:l.opacity_area/100,dotRadius:l.dot_radius/5,opacityCircles:l.opacity_circles/200,backgroundColor:l.backgroundColor,axisColor:l.axis_color,strokeWidth:l.stroke_width/5,legendSide:l.legend_side,glow:l.glow/20,negatives:l.negatives,axisColor:l.axisColor,negativeR:l.negative_r,independent:l.independent,legendPad:l.legend_padding,legendFont:l.legend_font,domainMax:l.domain_max,labelScale:l.labelScale};f.append("g").call(a("#vis",formattedData,v,moreData,0,originalData,axes,s))}};looker.plugins.visualizations.add(l)}])}));