diff --git a/gulliver/js/pmchart/pmCharts.js b/gulliver/js/pmchart/pmCharts.js index 3a47c3150..7051904f2 100644 --- a/gulliver/js/pmchart/pmCharts.js +++ b/gulliver/js/pmchart/pmCharts.js @@ -1 +1 @@ -function drawAxisX(e,b,c,h){if(!h.graph.axisX.showAxis){return}var i=new GraphDim(h);var a=d3.svg.axis().scale(c).orient("bottom").tickSize(h.graph.axisX.ticks);var g=b.append("g").attr("class","axis").attr("transform","translate(0,"+i.bottom+")").call(a).selectAll("text").style("text-anchor","end").attr("class","x-ticks-label").attr("transform","rotate(-45)");if(h.graph.axisX.showLabel){var f=i.left+i.width/2;var d=i.bottom+55;b.append("text").attr("transform","translate("+f+" ,"+d+")").attr("class","axis-label").style("text-anchor","middle").text(h.graph.axisX.label)}}function drawAxisY(e,c,f,g){if(!g.graph.axisY.showAxis){return}var b=new GraphDim(g);var a=d3.svg.axis().scale(f).orient("left").ticks(g.graph.axisY.ticks);var d=c.append("g").attr("class","axis").attr("transform","translate("+b.top+",0)").call(a).selectAll("text").attr("class","y-ticks-label");if(g.graph.axisY.showLabel){c.append("text").attr("class","axis-label").attr("transform","rotate(-90)").attr("y",0).attr("x",-(b.left+b.height/2)).attr("dy","1.5em").style("text-anchor","end").text(g.graph.axisY.label)}}var BarChart=function(b,d,c,a){this.originalData=b;this.previousDataPoint=c;this.params=d;this.$container=$("#"+this.params.canvas.containerId);this.breadCrumbStack=(a==null)?[]:a;pushToStack(c,this)};BarChart.prototype.drawChart=function(){var a=$("#"+this.params.canvas.containerId);a.empty();$(".tooltipdiv").remove();stretchCanvas(null,this.$container,this.params);this.canvas=createCanvas(this.params.canvas.containerId,this.params.canvas);this.drawBars(this.originalData,this.canvas,this.params);refreshBreadCrumbs(this)};BarChart.prototype.addBarTransition=function(b,c,a){b.attr("stroke-width",4).transition().duration(300).attr("width",c.rangeBand()).attr("y",function(e){return a(e.value)});b.exit().transition().duration(300).ease("exp").attr("width",0).remove()};BarChart.prototype.drawBars=function(g,c,f){var k=createDefaultParamsForGraph(f);var a=createDefaultParamsForLineChart(f.graph);k.graph=a;var n=new GraphDim(f);var o=new ToolTip();var h=this;if(g==null||g.length==0){c.append("text").attr("class","pm-charts-no-draw").attr("y",n.height/2).attr("x",n.left*2+n.width/2).attr("dy","1.5em").style("text-anchor","end").text(f.canvas.noDataText);g=[{value:"0",datalabel:"None"}]}var d=g.map(function(p){return p.datalabel});var i=d3.max(g,function(p){return p.value*1});var m=d3.scale.ordinal().domain(d).rangeRoundBands([n.left,n.right],0.15);var b=d3.scale.linear().domain([0,i]).range([n.bottom,n.top]).nice();var j=c.append("g");var n=new GraphDim(k);drawAxisX(g,j,m,k);drawAxisY(g,j,b,k);drawLinesX(g,j,m,k);drawLinesY(g,j,b,k);var l=j.selectAll("rect").data(g);if(k.graph.allowZoom){addZoomToCanvas(j)}addGradient(j,"gradientForBars");l.enter().append("rect").attr({x:function(q,p){return m(q.datalabel)},y:function(p){return(k.graph.allowTransition)?0:b(p.value)},width:(k.graph.allowTransition)?0:m.rangeBand(),height:function(p){return n.bottom-b(p.value)},fill:"url(#gradientForBars)"}).attr("clip-path","url(#rectClip)").on("mouseover",function(q,p){d3.select(this).attr("fill",h.params.graph.colorPalette[p%h.params.graph.colorPalette.length]);if(f.graph.showTip){o.show(function(){return o.valuesToUse(q)})}}).on("mouseout",function(p){d3.select(this).attr("fill","url(#gradientForBars)");o.hide()});if(k.graph.allowTransition){this.addBarTransition(l,m,b)}if(k.graph.useShadows){addShadow(c,"110%",2);j.selectAll("rect").attr("filter","url(#drop-shadow)")}if(this.params.graph.allowDrillDown){this.addOnClick(g,c);if(this.breadCrumbStack.length>0){var e=j.append("defs").append("svg:clipPath").attr("id","clip").append("svg:rect").attr("id","clip-rect").attr("x","0").attr("y","0").attr("width",50).attr("height",50).transition().duration(2000).attr("width",500).attr("height",500);d3.select("svg g").attr("clip-path","url(#clip)")}}};BarChart.prototype.addOnClick=function(arrayData,canvas){var currObj=this;canvas.selectAll("rect").data(arrayData).on("click",function(pointData){if(pointData.callBack!=null&&pointData.callBack.length!=""){var $container=$(canvas[0]).parent();$container.empty();$(".tooltipdiv").remove();var funCallBack=eval(pointData.callBack);funCallBack(pointData,currObj)}})};var DEFAULT_PADDING=50;function defaultAxis(b){var a={};addValueForProperty(a,b,"showLabel",true);addValueForProperty(a,b,"showAxis",true);addValueForProperty(a,b,"label","X");addValueForProperty(a,b,"ticks",10);return a}function addValueForProperty(b,c,d,a){if(d in c){b[d]=c[d]}else{b[d]=a}}function createDefaultParamsForGraph(b){if(b.canvas==null){throw new Error("You need specify canvas configuration parameters.")}if(b.graph==null){throw new Error("You need specify graph configuration parameters.")}if(b.canvas.width==null){throw new Error("No canvas width specified.")}if(b.canvas.height==null){throw new Error("No canvas height specified.")}var a={canvas:{width:("width" in b.canvas)?b.canvas.width:100,height:("height" in b.canvas)?b.canvas.height:100,exportTo:("exportTo" in b.canvas)?b.canvas.exportTo:[],stretch:("stretch" in b.canvas)?b.canvas.stretch:true},graph:{allowTransition:("allowTransition" in b.graph)?b.graph.allowTransition:false,allowZoom:("allowZoom" in b.graph)?b.graph.allowZoom:false,useShadows:("useShadows" in b.graph)?b.graph.useShadows:false,showTip:("showTip" in b.graph)?b.graph.showTip:false,paddingTop:("paddingTop" in b.graph)?b.graph.paddingTop:50,axisX:("axisX" in b.graph)?defaultAxis(b.graph.axisX):defaultAxis({}),axisY:("axisY" in b.graph)?defaultAxis(b.graph.axisY):defaultAxis({}),colorPalette:("colorPalette" in b.graph)?b.graph.colorPalette:["#62C1A3","#FB906B","#8DA1CB","#E88AC2","#E4C18F","#B3B3B3","#3180BA","#50B14D","#9A51A4","#F87709","#A35920","#A6D954","#FED92F","#ED2617"]},linesx:true,linesy:true};return a}function createDefaultParamsForGraphRign(b){if(b.canvas==null){throw new Error("You need specify canvas configuration parameters.")}if(b.graph==null){throw new Error("You need specify graph configuration parameters.")}if(b.canvas.width==null){throw new Error("No canvas width specified.")}if(b.canvas.height==null){throw new Error("No canvas height specified.")}var a={canvas:{width:("width" in b.canvas)?b.canvas.width:200,height:("width" in b.canvas)?b.canvas.height:200,exportTo:("exportTo" in b.canvas)?b.canvas.exportTo:[],stretch:("stretch" in b.canvas)?b.canvas.stretch:true},graph:{ringColor:("ringColor" in b.graph)?b.graph.ringColor:"#74cc84",labelColor:("labelColor" in b.graph)?b.graph.labelColor:"red",diameter:("diameter" in b.graph)?b.graph.diameter:200,gapWidth:("gapWidth" in b.graph)?b.graph.gapWidth:50,useShadows:("useShadows" in b.graph)?b.graph.useShadows:false,allowTransition:("allowTransition" in b.graph)?b.graph.allowTransition:false,allowZoom:("allowZoom" in b.graph)?b.graph.allowZoom:false}};return a}function createDefaultParamsForGraphVelocimeter(b){if(b.canvas==null){throw new Error("You need specify canvas configuration parameters.")}if(b.graph==null){throw new Error("You need specify graph configuration parameters.")}if(b.canvas.width==null){throw new Error("No canvas width specified.")}if(b.canvas.height==null){throw new Error("No canvas height specified.")}var a={canvas:{width:("width" in b.canvas)?b.canvas.width:700,height:("width" in b.canvas)?b.canvas.height:200,exportTo:("exportTo" in b.canvas)?b.canvas.exportTo:[],stretch:("stretch" in b.canvas)?b.canvas.stretch:true},graph:{useShadows:("useShadows" in b.graph)?b.graph.useShadows:false,allowZoom:("allowZoom" in b.graph)?b.graph.allowZoom:false}};return a}function createDefaultParamsForGraphPie(b){if(b.canvas==null){throw new Error("You need specify canvas configuration parameters.")}if(b.graph==null){throw new Error("You need specify graph configuration parameters.")}if(b.canvas.width==null){throw new Error("No canvas width specified.")}if(b.canvas.height==null){throw new Error("No canvas height specified.")}var a={canvas:{width:("width" in b.canvas)?b.canvas.width:100,height:("height" in b.canvas)?b.canvas.height:100,exportTo:("exportTo" in b.canvas)?b.canvas.exportTo:[],stretch:("stretch" in b.canvas)?b.canvas.stretch:true},graph:{allowTransition:("allowTransition" in b.graph)?b.graph.allowTransition:false,allowDrillDown:("allowDrillDown" in b.graph)?b.graph.allowDrillDown:false,allowZoom:("allowZoom" in b.graph)?b.graph.allowZoom:false,useShadows:("useShadows" in b.graph)?b.graph.useShadows:false,showTip:("showTip" in b.graph)?b.graph.showTip:false,thickness:("thickness" in b.graph)?b.graph.thickness:50,showLabels:("showLabels" in b.graph)?b.graph.showLabels:false,colorPalette:("colorPalette" in b.graph)?b.graph.colorPalette:["#62C1A3","#FB906B","#8DA1CB","#E88AC2","#E4C18F","#B3B3B3","#3180BA","#50B14D","#9A51A4","#F87709","#A35920","#A6D954","#FED92F","#ED2617"]}};return a}function createDefaultParamsForLineChart(b){var a={axisX:("axisX" in b)?defaultAxis(b.axisX):defaultAxis({}),axisY:("axisY" in b)?defaultAxis(b.axisY):defaultAxis({})};addValueForProperty(a,b,"allowTransition",false);addValueForProperty(a,b,"allowZoom",false);addValueForProperty(a,b,"useShadows",false);addValueForProperty(a,b,"showTip",false);addValueForProperty(a,b,"paddingTop",0);addValueForProperty(a,b,"area",{visible:false,css:"area"});addValueForProperty(a,b,"marker",{visible:true,ratio:5,css:"default"});addValueForProperty(a,b,"line",{visible:true,css:"line1"});addValueForProperty(a,b,"gridLinesX",true);addValueForProperty(a,b,"gridLinesY",true);addValueForProperty(a,b,"showErrorBars",false);return a}function stretchCanvas(a,f,e){if(e.canvas.stretch){if(f.width()==null||f.height()==null){throw new Error("stretchCanvas: The container "+f.attr("id")+" must have a width and height assigned.")}var d=(f.width()==null||f.width()==0)?e.canvas.width:f.width();var b=(f.height()==null||f.height()==0)?e.canvas.height:f.height();var c=d3.min([d,b],function(g){return g});e.canvas.width=d;e.canvas.height=b;e.graph.diameter=c}if(a==null){return}a.attr("width","100%").attr("height","98%").attr("viewBox","0 0 "+d+" "+b).attr("preserveAspectRatio","xMidYMid meet").attr("pointer-events","all");return a}function redrawChart(a){a.attr("transform","translate("+d3.event.translate+") scale("+d3.event.scale+")")}function createCanvas(b,c){d3.select("#"+b).select("svg").remove();var a=d3.select("#"+b).append("svg").attr("width",c.width).attr("height",c.height);return a}function addZoomToCanvas(a){var b=d3.behavior.zoom().scaleExtent([1,3]).on("zoom",function(){a.attr("transform","translate("+d3.event.translate+")scale("+d3.event.scale+")")});a.call(b)}function addExportOptions(b,d){var a=[];$(d).each(function(){a.push({val:this.toLowerCase(),text:this})});var c=$("").appendTo(b);c.append($("