From b75e33f2ca3841df449bc749a575fbcc88d8af5d Mon Sep 17 00:00:00 2001 From: Felipe Amorim Date: Sat, 10 May 2014 22:48:37 -0300 Subject: [PATCH] 0.2.0 release --- .gitignore | 2 + bower.json | 3 +- dist/angular-charts.js | 183 +++++++++++++++++++++++-------------- dist/angular-charts.min.js | 2 +- 4 files changed, 116 insertions(+), 74 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e501e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bower_components +node_modules \ No newline at end of file diff --git a/bower.json b/bower.json index 4416f50..f6423b7 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-charts", - "version": "0.1.1", + "version": "0.2.0", "authors": [ "chinmaymk" ], @@ -23,7 +23,6 @@ "dependencies": { "d3": "~3.3.10", "angular": "latest", - "jquery": "~2.0.3" }, "repository": { "type": "git", diff --git a/dist/angular-charts.js b/dist/angular-charts.js index 3e840f7..2c72024 100644 --- a/dist/angular-charts.js +++ b/dist/angular-charts.js @@ -8,15 +8,16 @@ angular.module('angularCharts', ['angularChartsTemplates']); angular.module('angularCharts').directive('acChart', [ '$templateCache', '$compile', + '$rootElement', '$window', '$timeout', - function ($templateCache, $compile, $window, $timeout) { + function ($templateCache, $compile, $rootElement, $window, $timeout) { /** * Initialize some constants * @type Array */ var tooltip = [ - 'display:none;', + 'display:block;', 'position:absolute;', 'border:1px solid #333;', 'background-color:#161616;', @@ -26,7 +27,7 @@ angular.module('angularCharts').directive('acChart', [ ].join(''); /** * Utility function to call when we run out of colors! - * @return {[type]} [description] + * @return {String} Hexadecimal color */ function getRandomColor() { var letters = '0123456789ABCDEF'.split(''); @@ -37,6 +38,25 @@ angular.module('angularCharts').directive('acChart', [ return color; } /** + * Utility function that gets the child that matches the classname + * because Angular.element.children() doesn't take selectors + * it's still better than a whole jQuery implementation + * @param {Array} childrens An array of childrens - element.children() or element.find('div') + * @param {String} className Class name + * @return {Angular.element|null} The founded child or null + */ + function getChildrenByClassname(childrens, className) { + var child = null; + for (var i in childrens) { + if (angular.isElement(childrens[i])) { + child = angular.element(childrens[i]); + if (child.hasClass(className)) + return child; + } + } + return child; + } + /** * Main link function * @param {[type]} scope [description] * @param {[type]} element [description] @@ -69,7 +89,11 @@ angular.module('angularCharts').directive('acChart', [ innerRadius: 0, lineLegend: 'lineEnd' }; - var totalWidth = element.width(), totalHeight = element.height(); + var totalWidth = element[0].clientWidth; + var totalHeight = element[0].clientHeight; + if (totalHeight === 0 || totalWidth === 0) { + throw new Error('Please set height and width for the chart element'); + } var data, series, points, height, width, chartContainer, legendContainer, chartType, isAnimate = true, defaultColors = config.colors; if (totalHeight === 0 || totalWidth === 0) { throw new Error('Please set height and width for the chart element'); @@ -118,10 +142,14 @@ angular.module('angularCharts').directive('acChart', [ */ function setContainers() { var container = $templateCache.get(config.legend.position); - element.html($compile(container)(scope)); - chartContainer = element.find('.ac-chart'); - legendContainer = element.find('.ac-legend'); - height -= element.find('.ac-title').height(); + element.html(container); + //http://stackoverflow.com/a/17883151 + $compile(element.contents())(scope); + //getting children divs + var childrens = element.find('div'); + chartContainer = getChildrenByClassname(childrens, 'ac-chart'); + legendContainer = getChildrenByClassname(childrens, 'ac-legend'); + height -= getChildrenByClassname(childrens, 'ac-title')[0].clientHeight; } /** * Parses data from attributes @@ -373,11 +401,15 @@ angular.module('angularCharts').directive('acChart', [ * [last description] * @type {[type]} */ - var last = linedata[linedata.length - 1].values; - var totalLength = path.node().getTotalLength() + getX(last[last.length - 1].x); - path.attr('stroke-dasharray', totalLength + ' ' + totalLength).attr('stroke-dashoffset', totalLength).transition().duration(1500).ease('linear').attr('stroke-dashoffset', 0).attr('d', function (d) { - return line(d.values); - }); + if (linedata.length > 0) { + var last = linedata[linedata.length - 1].values; + if (last.length > 0) { + var totalLength = path.node().getTotalLength() + getX(last[last.length - 1].x); + path.attr('stroke-dasharray', totalLength + ' ' + totalLength).attr('stroke-dashoffset', totalLength).transition().duration(1500).ease('linear').attr('stroke-dashoffset', 0).attr('d', function (d) { + return line(d.values); + }); + } + } /** * Add points * @param {[type]} value [description] @@ -558,25 +590,32 @@ angular.module('angularCharts').directive('acChart', [ return d.y[0]; }); var path = svg.selectAll('.arc').data(pie(points)).enter().append('g'); + var complete = false; var arcs = path.append('path').style('fill', function (d, i) { return getColor(i); - }).transition().ease('linear').duration(500).attrTween('d', tweenPie).attr('class', 'arc'); - path.on('mouseover', function (d) { - makeToolTip({ value: d.data.y[0] }, d3.event); - d3.select(this).select('path').transition().duration(200).style('stroke', 'white').style('stroke-width', '2px'); - config.mouseover(d, d3.event); - scope.$apply(); - }).on('mouseleave', function (d) { - d3.select(this).select('path').transition().duration(200).style('stroke', '').style('stroke-width', ''); - removeToolTip(); - config.mouseout(d, d3.event); - scope.$apply(); - }).on('mousemove', function (d) { - updateToolTip(d3.event); - }).on('click', function (d) { - config.click(d, d3.event); - scope.$apply(); - }); + }).transition().ease('linear').duration(500).attrTween('d', tweenPie).attr('class', 'arc').each('end', function () { + //avoid firing multiple times + if (!complete) { + complete = true; + //Add listeners when transition is done + path.on('mouseover', function (d) { + makeToolTip({ value: d.data.y[0] }, d3.event); + d3.select(this).select('path').transition().duration(200).style('stroke', 'white').style('stroke-width', '2px'); + config.mouseover(d, d3.event); + scope.$apply(); + }).on('mouseleave', function (d) { + d3.select(this).select('path').transition().duration(200).style('stroke', '').style('stroke-width', ''); + removeToolTip(); + config.mouseout(d, d3.event); + scope.$apply(); + }).on('mousemove', function (d) { + updateToolTip(d3.event); + }).on('click', function (d) { + config.click(d, d3.event); + scope.$apply(); + }); + } + }); if (!!config.labels) { path.append('text').attr('transform', function (d) { return 'translate(' + arc.centroid(d) + ')'; @@ -713,25 +752,27 @@ angular.module('angularCharts').directive('acChart', [ if (!config.tooltips) { return; } - if (Object.prototype.toString.call(config.tooltips) == '[object Function]') { + if (typeof config.tooltips == 'function') { data = config.tooltips(data); } else { data = data.value; } - angular.element('

').html(data).appendTo('body').fadeIn('slow').css({ - left: event.pageX + 20, - top: event.pageY - 30 - }); + var el = angular.element('

').html(data).css({ + left: event.pageX + 20, + top: event.pageY - 30 + }); + $rootElement.find('body').append(el); + scope.$tooltip = el; } /** * Clears the tooltip from body * @return {[type]} [description] */ function removeToolTip() { - angular.element('.ac-tooltip').remove(); + scope.$tooltip.remove(); } function updateToolTip(event) { - angular.element('.ac-tooltip').css({ + scope.$tooltip.css({ left: event.pageX + 20, top: event.pageY - 30 }); @@ -779,15 +820,15 @@ angular.module('angularCharts').directive('acChart', [ w.bind('resize', function (ev) { resizePromise && $timeout.cancel(resizePromise); resizePromise = $timeout(function () { - totalWidth = element.width(); - totalHeight = element.height(); + totalWidth = element[0].clientWidth; + totalHeight = element[0].clientHeight; init(); }, 100); }); scope.getWindowDimensions = function () { return { - 'h': w.height(), - 'w': w.width() + 'h': w[0].clientHeight, + 'w': w[0].clientWidth }; }; //let the party begin! @@ -820,25 +861,25 @@ angular.module("left", []).run(["$templateCache", function($templateCache) { $templateCache.put("left", "\n" + "\n" + "\n" + "
{{acConfig.title}}
\n" + "
\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + "
\n" + "
\n" + "
"); @@ -847,26 +888,26 @@ angular.module("left", []).run(["$templateCache", function($templateCache) { angular.module("right", []).run(["$templateCache", function($templateCache) { $templateCache.put("right", "\n" + "\n" + "
{{acConfig.title}}
\n" + "
\n" + "
\n" + "
\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + "
"); }]); diff --git a/dist/angular-charts.min.js b/dist/angular-charts.min.js index a9c853a..218b10c 100644 --- a/dist/angular-charts.min.js +++ b/dist/angular-charts.min.js @@ -1 +1 @@ -angular.module("angularCharts",["angularChartsTemplates"]),angular.module("angularCharts").directive("acChart",["$templateCache","$compile","$window","$timeout",function(a,b,c,d){function e(){for(var a="0123456789ABCDEF".split(""),b="#",c=0;6>c;c++)b+=a[Math.round(15*Math.random())];return b}function f(f,h){function i(){l(),j(),k();var a=m(F);a(),w()}function j(){if(!G.legend.display)return B=I,void(C=H);switch(G.legend.position){case"top":case"bottom":B=.75*I,C=H;break;case"left":case"right":B=I,C=.75*H}}function k(){var c=a.get(G.legend.position);h.html(b(c)(f)),D=h.find(".ac-chart"),E=h.find(".ac-legend"),B-=h.find(".ac-title").height()}function l(){y=f.acData,F=f.acChart,z=y?y.series||[]:[],A=y?y.data||[]:[],f.acConfig&&(angular.extend(G,f.acConfig),G.colors=G.colors.concat(J))}function m(a){var b={pie:r,bar:o,line:p,area:q,point:s};return b[a]}function n(a,b){var c=b.domain();if(G.xAxisMaxTicks&&c.length>G.xAxisMaxTicks){var d=Math.ceil(c.length/G.xAxisMaxTicks);a.tickValues(c.filter(function(a,b){return b%d==0}))}}function o(){var a={top:0,right:20,bottom:30,left:40};C-=a.left+a.right,B-=a.top+a.bottom;var b=d3.scale.ordinal().rangeRoundBands([0,C],.1),c=d3.scale.linear().range([B,10]),d=d3.scale.ordinal().rangeRoundBands([0,C],.1),e=[0];A.forEach(function(a){a.nicedata=a.y.map(function(b,c){return e.push(b),{x:a.x,y:b,s:c,tooltip:angular.isArray(a.tooltip)?a.tooltip[c]:a.tooltip}})});var g=d3.max(A.map(function(a){return a.y.length}));f.yMaxData=g,b.domain(A.map(function(a){return a.x}));var h=.2*d3.max(e);c.domain([d3.min(e),d3.max(e)+h]),d.domain(d3.range(g)).rangeRoundBands([0,b.rangeBand()]);var i=d3.svg.axis().scale(b).orient("bottom");n(i,b);var j=d3.svg.axis().scale(c).orient("left").ticks(10).tickFormat(d3.format("s")),k=d3.select(D[0]).append("svg").attr("width",C+a.left+a.right).attr("height",B+a.top+a.bottom).append("g").attr("transform","translate("+a.left+","+a.top+")");k.append("g").attr("class","x axis").attr("transform","translate(0,"+B+")").call(i),k.append("g").attr("class","y axis").call(j);var l=k.selectAll(".state").data(A).enter().append("g").attr("class","g").attr("transform",function(a){return"translate("+b(a.x)+",0)"}),m=l.selectAll("rect").data(function(a){return a.nicedata}).enter().append("rect");m.attr("width",d.rangeBand()),m.attr("x",function(a,b){return d(b)}).attr("y",B).style("fill",function(a){return x(a.s)}).attr("height",0).transition().ease("cubic-in-out").duration(1e3).attr("y",function(a){return c(Math.max(0,a.y))}).attr("height",function(a){return Math.abs(c(a.y)-c(0))}),m.on("mouseover",function(a){t({value:a.y,series:z[a.s],index:a.x},d3.event),G.mouseover(a,d3.event),f.$apply()}).on("mouseleave",function(a){u(),G.mouseout(a,d3.event),f.$apply()}).on("mousemove",function(){v(d3.event)}).on("click",function(a){G.click.call(a,d3.event),f.$apply()}),G.labels&&l.selectAll("not-a-class").data(function(a){return a.nicedata}).enter().append("text").attr("x",function(a,b){return d(b)}).attr("y",function(a){return B-Math.abs(c(a.y)-c(0))}).text(function(a){return a.y}),k.append("line").attr("x1",C).attr("y1",c(0)).attr("y2",c(0)).style("stroke","silver")}function p(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};C-=b.left+b.right,B-=b.top+b.bottom;var c=d3.scale.ordinal().domain(A.map(function(a){return a.x})).rangeRoundBands([0,C]),d=d3.scale.linear().range([B,10]),e=d3.svg.axis().scale(c).orient("bottom");n(e,c);var g=d3.svg.axis().scale(d).orient("left").ticks(5).tickFormat(d3.format("s")),h=d3.svg.line().interpolate("cardinal").x(function(b){return a(b.x)}).y(function(a){return d(a.y)}),i=[0],j=[];A.forEach(function(a){a.y.map(function(a){i.push(a)})});var k=d3.max(A.map(function(a){return a.y.length}));f.yMaxData=k,z.slice(0,k).forEach(function(a,b){var c={};c.series=a,c.values=A.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:A[b].x,y:0}}),j.push(c)});var l=d3.select(D[0]).append("svg").attr("width",C+b.left+b.right).attr("height",B+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")"),m=.2*d3.max(i);d.domain([d3.min(i),d3.max(i)+m]),l.append("g").attr("class","x axis").attr("transform","translate(0,"+B+")").call(e),l.append("g").attr("class","y axis").call(g);var o=l.selectAll(".points").data(j).enter().append("g");path=o.attr("points","points").append("path").attr("class","ac-line").style("stroke",function(a,b){return x(b)}).attr("d",function(a){return h(a.values)}).attr("stroke-width","2").attr("fill","none");var p=j[j.length-1].values,q=path.node().getTotalLength()+a(p[p.length-1].x);return path.attr("stroke-dasharray",q+" "+q).attr("stroke-dashoffset",q).transition().duration(1500).ease("linear").attr("stroke-dashoffset",0).attr("d",function(a){return h(a.values)}),angular.forEach(j,function(b){var c=l.selectAll(".circle").data(b.values).enter();c.append("circle").attr("cx",function(b){return a(b.x)}).attr("cy",function(a){return d(a.y)}).attr("r",3).style("fill",x(j.indexOf(b))).style("stroke",x(j.indexOf(b))).on("mouseover",function(a){return function(b){t({index:b.x,value:b.y,series:a},d3.event),G.mouseover(b,d3.event),f.$apply()}}(b.series)).on("mouseleave",function(a){u(),G.mouseout(a,d3.event),f.$apply()}).on("mousemove",function(){v(d3.event)}).on("click",function(a){G.click(a,d3.event),f.$apply()}),G.labels&&c.append("text").attr("x",function(b){return a(b.x)}).attr("y",function(a){return d(a.y)}).text(function(a){return a.y})}),"lineEnd"===G.lineLegend&&o.append("text").datum(function(a){return{name:a.series,value:a.values[a.values.length-1]}}).attr("transform",function(b){return"translate("+a(b.value.x)+","+d(b.value.y)+")"}).attr("x",3).text(function(a){return a.name}),j}function q(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};C-=b.left+b.right,B-=b.top+b.bottom;var c=d3.scale.ordinal().domain(A.map(function(a){return a.x})).rangeRoundBands([0,C]),d=d3.scale.linear().range([B,10]),e=d3.svg.axis().scale(c).orient("bottom");n(e,c);var g=d3.svg.axis().scale(d).orient("left").ticks(5).tickFormat(d3.format("s")),h=(d3.svg.line().interpolate("cardinal").x(function(b){return a(b.x)}).y(function(a){return d(a.y)}),[0]),i=[];A.forEach(function(a){a.y.map(function(a){h.push(a)})});var j=d3.max(A.map(function(a){return a.y.length}));f.yMaxData=j,z.slice(0,j).forEach(function(a,b){var c={};c.series=a,c.values=A.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:A[b].x,y:0}}),i.push(c)});var k=d3.select(D[0]).append("svg").attr("width",C+b.left+b.right).attr("height",B+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")"),l=.2*d3.max(h);d.domain([d3.min(h),d3.max(h)+l]),k.append("g").attr("class","x axis").attr("transform","translate(0,"+B+")").call(e),k.append("g").attr("class","y axis").call(g);var m=k.selectAll(".points").data(i).enter().append("g"),o=d3.svg.area().interpolate("basis").x(function(b){return a(b.x)}).y0(function(){return d(0)}).y1(function(a){return d(0+a.y)});m.append("path").attr("class","area").attr("d",function(a){return o(a.values)}).style("fill",function(a,b){return x(b)}).style("opacity","0.7")}function r(){function a(a){a.innerRadius=0;var b=d3.interpolate({startAngle:0,endAngle:0},a);return function(a){return g(b(a))}}var b=Math.min(C,B)/2,c=d3.select(D[0]).append("svg").attr("width",C).attr("height",B).append("g").attr("transform","translate("+C/2+","+B/2+")"),d=0;if(G.innerRadius){var e=G.innerRadius;"string"==typeof e&&e.indexOf("%")>0&&(e=b*(1-.01*parseFloat(e))),e&&(d=b-Number(e))}f.yMaxData=A.length;{var g=d3.svg.arc().outerRadius(b-10).innerRadius(d),h=(d3.svg.arc().outerRadius(b+5).innerRadius(0),d3.layout.pie().sort(null).value(function(a){return a.y[0]})),i=c.selectAll(".arc").data(h(A)).enter().append("g");i.append("path").style("fill",function(a,b){return x(b)}).transition().ease("linear").duration(500).attrTween("d",a).attr("class","arc")}i.on("mouseover",function(a){t({value:a.data.y[0]},d3.event),d3.select(this).select("path").transition().duration(200).style("stroke","white").style("stroke-width","2px"),G.mouseover(a,d3.event),f.$apply()}).on("mouseleave",function(a){d3.select(this).select("path").transition().duration(200).style("stroke","").style("stroke-width",""),u(),G.mouseout(a,d3.event),f.$apply()}).on("mousemove",function(){v(d3.event)}).on("click",function(a){G.click(a,d3.event),f.$apply()}),G.labels&&i.append("text").attr("transform",function(a){return"translate("+g.centroid(a)+")"}).attr("dy",".35em").style("text-anchor","middle").text(function(a){return a.data.y[0]})}function s(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};C-=b.left-b.right,B-=b.top-b.bottom;var c=d3.scale.ordinal().domain(A.map(function(a){return a.x})).rangeRoundBands([0,C]),d=d3.scale.linear().range([B,10]),e=d3.svg.axis().scale(c).orient("bottom");n(e,c);var g=d3.svg.axis().scale(d).orient("left").ticks(5).tickFormat(d3.format("s")),h=[0],i=[];A.forEach(function(a){a.y.map(function(a){h.push(a)})});var j=d3.max(A.map(function(a){return a.y.length}));f.yMaxPoints=j,z.slice(0,j).forEach(function(a,b){var c={};c.series=a,c.values=A.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:A[b].x,y:0}}),i.push(c)});var k=d3.select(D[0]).append("svg").attr("width",C+b.left+b.right).attr("height",B+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")"),l=.2*d3.max(h);d.domain([d3.min(h),d3.max(h)+l]),k.append("g").attr("class","x axis").attr("transform","translate(0,"+B+")").call(e),k.append("g").attr("class","y axis").call(g);k.selectAll(".points").data(i).enter().append("g");angular.forEach(i,function(b){var c=k.selectAll(".circle").data(b.values).enter();c.append("circle").attr("cx",function(b){return a(b.x)}).attr("cy",function(a){return d(a.y)}).attr("r",3).style("fill",x(i.indexOf(b))).style("stroke",x(i.indexOf(b))).on("mouseover",function(a){return function(b){t({index:b.x,value:b.y,series:a},d3.event),G.mouseover(b,d3.event),f.$apply()}}(b.series)).on("mouseleave",function(a){u(),G.mouseout(a,d3.event),f.$apply()}).on("mousemove",function(){v(d3.event)}).on("click",function(a){G.click(a,d3.event),f.$apply()}),G.labels&&c.append("text").attr("x",function(b){return a(b.x)}).attr("y",function(a){return d(a.y)}).text(function(a){return a.y})})}function t(a,b){G.tooltips&&(a="[object Function]"==Object.prototype.toString.call(G.tooltips)?G.tooltips(a):a.value,angular.element('

').html(a).appendTo("body").fadeIn("slow").css({left:b.pageX+20,top:b.pageY-30}))}function u(){angular.element(".ac-tooltip").remove()}function v(a){angular.element(".ac-tooltip").css({left:a.pageX+20,top:a.pageY-30})}function w(){f.legends=[],"pie"==F&&angular.forEach(A,function(a,b){f.legends.push({color:G.colors[b],title:a.x})}),("bar"==F||"area"==F||"point"==F||"line"==F&&"traditional"===G.lineLegend)&&angular.forEach(z,function(a,b){f.legends.push({color:G.colors[b],title:a})})}function x(a){if(a\n .axis path,\n .axis line {\n fill: none;\n stroke: #333;\n }\n .ac-line {\n fill:none;\n stroke-width:2px;\n }\n\n\n
{{acConfig.title}}
\n
\n \n \n \n \n \n
\n
\n
\n
")}]),angular.module("right",[]).run(["$templateCache",function(a){a.put("right","\n\n
{{acConfig.title}}
\n
\n
\n
\n \n \n \n \n \n
\n
")}]); \ No newline at end of file +angular.module("angularCharts",["angularChartsTemplates"]),angular.module("angularCharts").directive("acChart",["$templateCache","$compile","$rootElement","$window","$timeout",function(a,b,c,d,e){function f(){for(var a="0123456789ABCDEF".split(""),b="#",c=0;6>c;c++)b+=a[Math.round(15*Math.random())];return b}function g(a,b){var c=null;for(var d in a)if(angular.isElement(a[d])&&(c=angular.element(a[d]),c.hasClass(b)))return c;return c}function h(h,j){function k(){n(),l(),m();var a=o(K);a(),y()}function l(){if(!A.legend.display)return G=C,void(H=B);switch(A.legend.position){case"top":case"bottom":G=.75*C,H=B;break;case"left":case"right":G=C,H=.75*B}}function m(){var c=a.get(A.legend.position);j.html(c),b(j.contents())(h);var d=j.find("div");I=g(d,"ac-chart"),J=g(d,"ac-legend"),G-=g(d,"ac-title")[0].clientHeight}function n(){D=h.acData,K=h.acChart,E=D?D.series||[]:[],F=D?D.data||[]:[],h.acConfig&&(angular.extend(A,h.acConfig),A.colors=A.colors.concat(L))}function o(a){var b={pie:t,bar:q,line:r,area:s,point:u};return b[a]}function p(a,b){var c=b.domain();if(A.xAxisMaxTicks&&c.length>A.xAxisMaxTicks){var d=Math.ceil(c.length/A.xAxisMaxTicks);a.tickValues(c.filter(function(a,b){return b%d==0}))}}function q(){var a={top:0,right:20,bottom:30,left:40};H-=a.left+a.right,G-=a.top+a.bottom;var b=d3.scale.ordinal().rangeRoundBands([0,H],.1),c=d3.scale.linear().range([G,10]),d=d3.scale.ordinal().rangeRoundBands([0,H],.1),e=[0];F.forEach(function(a){a.nicedata=a.y.map(function(b,c){return e.push(b),{x:a.x,y:b,s:c,tooltip:angular.isArray(a.tooltip)?a.tooltip[c]:a.tooltip}})});var f=d3.max(F.map(function(a){return a.y.length}));h.yMaxData=f,b.domain(F.map(function(a){return a.x}));var g=.2*d3.max(e);c.domain([d3.min(e),d3.max(e)+g]),d.domain(d3.range(f)).rangeRoundBands([0,b.rangeBand()]);var i=d3.svg.axis().scale(b).orient("bottom");p(i,b);var j=d3.svg.axis().scale(c).orient("left").ticks(10).tickFormat(d3.format("s")),k=d3.select(I[0]).append("svg").attr("width",H+a.left+a.right).attr("height",G+a.top+a.bottom).append("g").attr("transform","translate("+a.left+","+a.top+")");k.append("g").attr("class","x axis").attr("transform","translate(0,"+G+")").call(i),k.append("g").attr("class","y axis").call(j);var l=k.selectAll(".state").data(F).enter().append("g").attr("class","g").attr("transform",function(a){return"translate("+b(a.x)+",0)"}),m=l.selectAll("rect").data(function(a){return a.nicedata}).enter().append("rect");m.attr("width",d.rangeBand()),m.attr("x",function(a,b){return d(b)}).attr("y",G).style("fill",function(a){return z(a.s)}).attr("height",0).transition().ease("cubic-in-out").duration(1e3).attr("y",function(a){return c(Math.max(0,a.y))}).attr("height",function(a){return Math.abs(c(a.y)-c(0))}),m.on("mouseover",function(a){v({value:a.y,series:E[a.s],index:a.x},d3.event),A.mouseover(a,d3.event),h.$apply()}).on("mouseleave",function(a){w(),A.mouseout(a,d3.event),h.$apply()}).on("mousemove",function(){x(d3.event)}).on("click",function(a){A.click.call(a,d3.event),h.$apply()}),A.labels&&l.selectAll("not-a-class").data(function(a){return a.nicedata}).enter().append("text").attr("x",function(a,b){return d(b)}).attr("y",function(a){return G-Math.abs(c(a.y)-c(0))}).text(function(a){return a.y}),k.append("line").attr("x1",H).attr("y1",c(0)).attr("y2",c(0)).style("stroke","silver")}function r(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};H-=b.left+b.right,G-=b.top+b.bottom;var c=d3.scale.ordinal().domain(F.map(function(a){return a.x})).rangeRoundBands([0,H]),d=d3.scale.linear().range([G,10]),e=d3.svg.axis().scale(c).orient("bottom");p(e,c);var f=d3.svg.axis().scale(d).orient("left").ticks(5).tickFormat(d3.format("s")),g=d3.svg.line().interpolate("cardinal").x(function(b){return a(b.x)}).y(function(a){return d(a.y)}),i=[0],j=[];F.forEach(function(a){a.y.map(function(a){i.push(a)})});var k=d3.max(F.map(function(a){return a.y.length}));h.yMaxData=k,E.slice(0,k).forEach(function(a,b){var c={};c.series=a,c.values=F.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:F[b].x,y:0}}),j.push(c)});var l=d3.select(I[0]).append("svg").attr("width",H+b.left+b.right).attr("height",G+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")"),m=.2*d3.max(i);d.domain([d3.min(i),d3.max(i)+m]),l.append("g").attr("class","x axis").attr("transform","translate(0,"+G+")").call(e),l.append("g").attr("class","y axis").call(f);var n=l.selectAll(".points").data(j).enter().append("g");if(path=n.attr("points","points").append("path").attr("class","ac-line").style("stroke",function(a,b){return z(b)}).attr("d",function(a){return g(a.values)}).attr("stroke-width","2").attr("fill","none"),j.length>0){var o=j[j.length-1].values;if(o.length>0){var q=path.node().getTotalLength()+a(o[o.length-1].x);path.attr("stroke-dasharray",q+" "+q).attr("stroke-dashoffset",q).transition().duration(1500).ease("linear").attr("stroke-dashoffset",0).attr("d",function(a){return g(a.values)})}}return angular.forEach(j,function(b){var c=l.selectAll(".circle").data(b.values).enter();c.append("circle").attr("cx",function(b){return a(b.x)}).attr("cy",function(a){return d(a.y)}).attr("r",3).style("fill",z(j.indexOf(b))).style("stroke",z(j.indexOf(b))).on("mouseover",function(a){return function(b){v({index:b.x,value:b.y,series:a},d3.event),A.mouseover(b,d3.event),h.$apply()}}(b.series)).on("mouseleave",function(a){w(),A.mouseout(a,d3.event),h.$apply()}).on("mousemove",function(){x(d3.event)}).on("click",function(a){A.click(a,d3.event),h.$apply()}),A.labels&&c.append("text").attr("x",function(b){return a(b.x)}).attr("y",function(a){return d(a.y)}).text(function(a){return a.y})}),"lineEnd"===A.lineLegend&&n.append("text").datum(function(a){return{name:a.series,value:a.values[a.values.length-1]}}).attr("transform",function(b){return"translate("+a(b.value.x)+","+d(b.value.y)+")"}).attr("x",3).text(function(a){return a.name}),j}function s(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};H-=b.left+b.right,G-=b.top+b.bottom;var c=d3.scale.ordinal().domain(F.map(function(a){return a.x})).rangeRoundBands([0,H]),d=d3.scale.linear().range([G,10]),e=d3.svg.axis().scale(c).orient("bottom");p(e,c);var f=d3.svg.axis().scale(d).orient("left").ticks(5).tickFormat(d3.format("s")),g=(d3.svg.line().interpolate("cardinal").x(function(b){return a(b.x)}).y(function(a){return d(a.y)}),[0]),i=[];F.forEach(function(a){a.y.map(function(a){g.push(a)})});var j=d3.max(F.map(function(a){return a.y.length}));h.yMaxData=j,E.slice(0,j).forEach(function(a,b){var c={};c.series=a,c.values=F.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:F[b].x,y:0}}),i.push(c)});var k=d3.select(I[0]).append("svg").attr("width",H+b.left+b.right).attr("height",G+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")"),l=.2*d3.max(g);d.domain([d3.min(g),d3.max(g)+l]),k.append("g").attr("class","x axis").attr("transform","translate(0,"+G+")").call(e),k.append("g").attr("class","y axis").call(f);var m=k.selectAll(".points").data(i).enter().append("g"),n=d3.svg.area().interpolate("basis").x(function(b){return a(b.x)}).y0(function(){return d(0)}).y1(function(a){return d(0+a.y)});m.append("path").attr("class","area").attr("d",function(a){return n(a.values)}).style("fill",function(a,b){return z(b)}).style("opacity","0.7")}function t(){function a(a){a.innerRadius=0;var b=d3.interpolate({startAngle:0,endAngle:0},a);return function(a){return f(b(a))}}var b=Math.min(H,G)/2,c=d3.select(I[0]).append("svg").attr("width",H).attr("height",G).append("g").attr("transform","translate("+H/2+","+G/2+")"),d=0;if(A.innerRadius){var e=A.innerRadius;"string"==typeof e&&e.indexOf("%")>0&&(e=b*(1-.01*parseFloat(e))),e&&(d=b-Number(e))}h.yMaxData=F.length;{var f=d3.svg.arc().outerRadius(b-10).innerRadius(d),g=(d3.svg.arc().outerRadius(b+5).innerRadius(0),d3.layout.pie().sort(null).value(function(a){return a.y[0]})),i=c.selectAll(".arc").data(g(F)).enter().append("g"),j=!1;i.append("path").style("fill",function(a,b){return z(b)}).transition().ease("linear").duration(500).attrTween("d",a).attr("class","arc").each("end",function(){j||(j=!0,i.on("mouseover",function(a){v({value:a.data.y[0]},d3.event),d3.select(this).select("path").transition().duration(200).style("stroke","white").style("stroke-width","2px"),A.mouseover(a,d3.event),h.$apply()}).on("mouseleave",function(a){d3.select(this).select("path").transition().duration(200).style("stroke","").style("stroke-width",""),w(),A.mouseout(a,d3.event),h.$apply()}).on("mousemove",function(){x(d3.event)}).on("click",function(a){A.click(a,d3.event),h.$apply()}))})}A.labels&&i.append("text").attr("transform",function(a){return"translate("+f.centroid(a)+")"}).attr("dy",".35em").style("text-anchor","middle").text(function(a){return a.data.y[0]})}function u(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};H-=b.left-b.right,G-=b.top-b.bottom;var c=d3.scale.ordinal().domain(F.map(function(a){return a.x})).rangeRoundBands([0,H]),d=d3.scale.linear().range([G,10]),e=d3.svg.axis().scale(c).orient("bottom");p(e,c);var f=d3.svg.axis().scale(d).orient("left").ticks(5).tickFormat(d3.format("s")),g=[0],i=[];F.forEach(function(a){a.y.map(function(a){g.push(a)})});var j=d3.max(F.map(function(a){return a.y.length}));h.yMaxPoints=j,E.slice(0,j).forEach(function(a,b){var c={};c.series=a,c.values=F.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:F[b].x,y:0}}),i.push(c)});var k=d3.select(I[0]).append("svg").attr("width",H+b.left+b.right).attr("height",G+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")"),l=.2*d3.max(g);d.domain([d3.min(g),d3.max(g)+l]),k.append("g").attr("class","x axis").attr("transform","translate(0,"+G+")").call(e),k.append("g").attr("class","y axis").call(f);k.selectAll(".points").data(i).enter().append("g");angular.forEach(i,function(b){var c=k.selectAll(".circle").data(b.values).enter();c.append("circle").attr("cx",function(b){return a(b.x)}).attr("cy",function(a){return d(a.y)}).attr("r",3).style("fill",z(i.indexOf(b))).style("stroke",z(i.indexOf(b))).on("mouseover",function(a){return function(b){v({index:b.x,value:b.y,series:a},d3.event),A.mouseover(b,d3.event),h.$apply()}}(b.series)).on("mouseleave",function(a){w(),A.mouseout(a,d3.event),h.$apply()}).on("mousemove",function(){x(d3.event)}).on("click",function(a){A.click(a,d3.event),h.$apply()}),A.labels&&c.append("text").attr("x",function(b){return a(b.x)}).attr("y",function(a){return d(a.y)}).text(function(a){return a.y})})}function v(a,b){if(A.tooltips){a="function"==typeof A.tooltips?A.tooltips(a):a.value;var d=angular.element('

').html(a).css({left:b.pageX+20,top:b.pageY-30});c.find("body").append(d),h.$tooltip=d}}function w(){h.$tooltip.remove()}function x(a){h.$tooltip.css({left:a.pageX+20,top:a.pageY-30})}function y(){h.legends=[],"pie"==K&&angular.forEach(F,function(a,b){h.legends.push({color:A.colors[b],title:a.x})}),("bar"==K||"area"==K||"point"==K||"line"==K&&"traditional"===A.lineLegend)&&angular.forEach(E,function(a,b){h.legends.push({color:A.colors[b],title:a})})}function z(a){if(a\n .axis path,\n .axis line {\n fill: none;\n stroke: #333;\n }\n .ac-line {\n fill:none;\n stroke-width:2px;\n }\n\n\n
{{acConfig.title}}
\n
\n \n \n \n \n \n
\n
\n
\n
")}]),angular.module("right",[]).run(["$templateCache",function(a){a.put("right","\n\n
{{acConfig.title}}
\n
\n
\n
\n \n \n \n \n \n
\n
")}]); \ No newline at end of file