From 13f3f685d991e1f89a68b408d788100709858eeb Mon Sep 17 00:00:00 2001 From: Chinmay Date: Thu, 23 Jan 2014 10:11:34 +0530 Subject: [PATCH] fix for #12, added an error message if height/width is not set. --- dist/angular-charts.js | 3 +++ dist/angular-charts.min.js | 2 +- src/angular-charts.js | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dist/angular-charts.js b/dist/angular-charts.js index bd03eff..5514aa4 100644 --- a/dist/angular-charts.js +++ b/dist/angular-charts.js @@ -47,6 +47,9 @@ angular.module('angularCharts').directive('acChart', [ }; var totalWidth = element.width(), totalHeight = element.height(); 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'); + } function init() { prepareData(); setHeightWidth(); diff --git a/dist/angular-charts.min.js b/dist/angular-charts.min.js index 1c21f70..8a4c74b 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",function(a,b,c){function d(){for(var a="0123456789ABCDEF".split(""),b="#",c=0;6>c;c++)b+=a[Math.round(15*Math.random())];return b}function e(e,g){function h(){k(),i(),j();var a=l(D);a(),u()}function i(){if(!E.legend.display)return z=G,A=F,void 0;switch(E.legend.position){case"top":case"bottom":z=.75*G,A=F;break;case"left":case"right":z=G,A=.75*F}}function j(){var c=a.get(E.legend.position);g.html(b(c)(e)),B=g.find(".ac-chart"),C=g.find(".ac-legend"),z-=g.find(".ac-title").height()}function k(){w=e.acData,D=e.acChart,x=w.series,y=w.data,e.acConfig&&(angular.extend(E,e.acConfig),E.colors=E.colors.concat(H))}function l(a){var b={pie:p,bar:m,line:n,area:o,point:q};return b[a]}function m(){var a={top:0,right:20,bottom:30,left:40};A-=a.left+a.right,z-=a.top+a.bottom;var b=d3.scale.ordinal().rangeRoundBands([0,A],.1),c=d3.scale.linear().range([z,10]),d=d3.scale.ordinal().rangeRoundBands([0,A],.1),f=[0];y.forEach(function(a){a.nicedata=a.y.map(function(b,c){return f.push(b),{x:a.x,y:b,s:c}})});var g=d3.max(y.map(function(a){return a.y.length}));e.yMaxData=g,b.domain(y.map(function(a){return a.x}));var h=.2*d3.max(f);c.domain([d3.min(f),d3.max(f)+h]),d.domain(d3.range(g)).rangeRoundBands([0,b.rangeBand()]);var i=d3.svg.axis().scale(b).orient("bottom"),j=d3.svg.axis().scale(c).orient("left").ticks(10).tickFormat(d3.format("s")),k=d3.select(B[0]).append("svg").attr("width",A+a.left+a.right).attr("height",z+a.top+a.bottom).append("g").attr("transform","translate("+a.left+","+a.top+")");k.append("g").attr("class","x axis").attr("transform","translate(0,"+z+")").call(i),k.append("g").attr("class","y axis").call(j);var l=k.selectAll(".state").data(y).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",z).style("fill",function(a){return v(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){r(a.tooltip||a.y,d3.event),E.mouseover(a,d3.event),e.$apply()}).on("mouseleave",function(a){s(),E.mouseout(a,d3.event),e.$apply()}).on("mousemove",function(){t(d3.event)}).on("click",function(a){E.click.call(a,d3.event),e.$apply()}),E.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 z-Math.abs(c(a.y)-c(0))}).text(function(a){return a.y}),k.append("line").attr("x1",A).attr("y1",c(0)).attr("y2",c(0)).style("stroke","silver")}function n(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};A-=b.left+b.right,z-=b.top+b.bottom;var c=d3.scale.ordinal().domain(y.map(function(a){return a.x})).rangeRoundBands([0,A]),d=d3.scale.linear().range([z,10]),f=d3.svg.axis().scale(c).orient("bottom"),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=[];y.forEach(function(a){a.y.map(function(a){i.push(a)})});var k=d3.max(y.map(function(a){return a.y.length}));x.slice(0,k).forEach(function(a,b){var c={};c.series=a,c.values=y.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:y[b].x,y:0}}),j.push(c)});var l=d3.select(B[0]).append("svg").attr("width",A+b.left+b.right).attr("height",z+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,"+z+")").call(f),l.append("g").attr("class","y axis").call(g);var n=l.selectAll(".points").data(j).enter().append("g");path=n.attr("points","points").append("path").attr("class","ac-line").style("stroke",function(a,b){return v(b)}).attr("d",function(a){return h(a.values)}).attr("stroke-width","2").attr("fill","none");var o=j[j.length-1].values,p=path.node().getTotalLength()+a(o[o.length-1].x);return path.attr("stroke-dasharray",p+" "+p).attr("stroke-dashoffset",p).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",v(j.indexOf(b))).style("stroke",v(j.indexOf(b))).on("mouseover",function(a){r(a.tooltip||a.y,d3.event),E.mouseover(a,d3.event),e.$apply()}).on("mouseleave",function(a){s(),E.mouseout(a,d3.event),e.$apply()}).on("mousemove",function(){t(d3.event)}).on("click",function(a){E.click(a,d3.event),e.$apply()}),E.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})}),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 o(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};A-=b.left+b.right,z-=b.top+b.bottom;var c=d3.scale.ordinal().domain(y.map(function(a){return a.x})).rangeRoundBands([0,A]),d=d3.scale.linear().range([z,10]),f=d3.svg.axis().scale(c).orient("bottom"),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=[];y.forEach(function(a){a.y.map(function(a){h.push(a)})});var j=d3.max(y.map(function(a){return a.y.length}));e.yMaxData=j,x.slice(0,j).forEach(function(a,b){var c={};c.series=a,c.values=y.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:y[b].x,y:0}}),i.push(c)});var k=d3.select(B[0]).append("svg").attr("width",A+b.left+b.right).attr("height",z+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,"+z+")").call(f),k.append("g").attr("class","y axis").call(g);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 v(b)}).style("opacity","0.7")}function p(){function a(a){a.innerRadius=0;var b=d3.interpolate({startAngle:0,endAngle:0},a);return function(a){return d(b(a))}}var b=Math.min(A,z)/2,c=d3.select(B[0]).append("svg").attr("width",A).attr("height",z).append("g").attr("transform","translate("+A/2+","+z/2+")");e.yMaxData=y.length;{var d=d3.svg.arc().outerRadius(b-10).innerRadius(0),f=(d3.svg.arc().outerRadius(b+5).innerRadius(0),d3.layout.pie().sort(null).value(function(a){return a.y[0]})),g=c.selectAll(".arc").data(f(y)).enter().append("g");g.append("path").style("fill",function(a,b){return v(b)}).transition().ease("linear").duration(500).attrTween("d",a).attr("class","arc")}g.on("mouseover",function(a){r(a.data.tooltip||a.data.y[0]),d3.select(this).select("path").transition().duration(200).style("stroke","white").style("stroke-width","2px"),E.mouseover(a,d3.event),e.$apply()}).on("mouseleave",function(a){d3.select(this).select("path").transition().duration(200).style("stroke","").style("stroke-width",""),s(),E.mouseout(a,d3.event),e.$apply()}).on("mousemove",function(){t(d3.event)}).on("click",function(a){E.click(a,d3.event),e.$apply()}),E.labels&&g.append("text").attr("transform",function(a){return"translate("+d.centroid(a)+")"}).attr("dy",".35em").style("text-anchor","middle").text(function(a){return a.data.y[0]})}function q(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};A-=b.left-b.right,z-=b.top-b.bottom;var c=d3.scale.ordinal().domain(y.map(function(a){return a.x})).rangeRoundBands([0,A]),d=d3.scale.linear().range([z,10]),f=d3.svg.axis().scale(c).orient("bottom"),g=d3.svg.axis().scale(d).orient("left").ticks(5).tickFormat(d3.format("s")),h=[0],i=[];y.forEach(function(a){a.y.map(function(a){h.push(a)})});var j=d3.max(y.map(function(a){return a.y.length}));e.yMaxPoints=j,x.slice(0,j).forEach(function(a,b){var c={};c.series=a,c.values=y.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:y[b].x,y:0}}),i.push(c)});var k=d3.select(B[0]).append("svg").attr("width",A+b.left+b.right).attr("height",z+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,"+z+")").call(f),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",v(i.indexOf(b))).style("stroke",v(i.indexOf(b))).on("mouseover",function(a){r(a.tooltip||a.y,d3.event),E.mouseover(a,d3.event),e.$apply()}).on("mouseleave",function(a){s(),E.mouseout(a,d3.event),e.$apply()}).on("mousemove",function(){t(d3.event)}).on("click",function(a){E.click(a,d3.event),e.$apply()}),E.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 r(a,b){E.tooltips&&angular.element('

').html(a).appendTo("body").fadeIn("slow").css({left:b.pageX+20,top:b.pageY-30})}function s(){angular.element(".ac-tooltip").remove()}function t(a){angular.element(".ac-tooltip").css({left:a.pageX+20,top:a.pageY-30})}function u(){e.legends=[],"pie"==D&&angular.forEach(y,function(a,b){e.legends.push({color:E.colors[b],title:a.x})}),("bar"==D||"area"==D||"point"==D)&&angular.forEach(x,function(a,b){e.legends.push({color:E.colors[b],title:a})})}function v(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","$window",function(a,b,c){function d(){for(var a="0123456789ABCDEF".split(""),b="#",c=0;6>c;c++)b+=a[Math.round(15*Math.random())];return b}function e(e,g){function h(){k(),i(),j();var a=l(D);a(),u()}function i(){if(!E.legend.display)return z=G,A=F,void 0;switch(E.legend.position){case"top":case"bottom":z=.75*G,A=F;break;case"left":case"right":z=G,A=.75*F}}function j(){var c=a.get(E.legend.position);g.html(b(c)(e)),B=g.find(".ac-chart"),C=g.find(".ac-legend"),z-=g.find(".ac-title").height()}function k(){w=e.acData,D=e.acChart,x=w.series,y=w.data,e.acConfig&&(angular.extend(E,e.acConfig),E.colors=E.colors.concat(H))}function l(a){var b={pie:p,bar:m,line:n,area:o,point:q};return b[a]}function m(){var a={top:0,right:20,bottom:30,left:40};A-=a.left+a.right,z-=a.top+a.bottom;var b=d3.scale.ordinal().rangeRoundBands([0,A],.1),c=d3.scale.linear().range([z,10]),d=d3.scale.ordinal().rangeRoundBands([0,A],.1),f=[0];y.forEach(function(a){a.nicedata=a.y.map(function(b,c){return f.push(b),{x:a.x,y:b,s:c}})});var g=d3.max(y.map(function(a){return a.y.length}));e.yMaxData=g,b.domain(y.map(function(a){return a.x}));var h=.2*d3.max(f);c.domain([d3.min(f),d3.max(f)+h]),d.domain(d3.range(g)).rangeRoundBands([0,b.rangeBand()]);var i=d3.svg.axis().scale(b).orient("bottom"),j=d3.svg.axis().scale(c).orient("left").ticks(10).tickFormat(d3.format("s")),k=d3.select(B[0]).append("svg").attr("width",A+a.left+a.right).attr("height",z+a.top+a.bottom).append("g").attr("transform","translate("+a.left+","+a.top+")");k.append("g").attr("class","x axis").attr("transform","translate(0,"+z+")").call(i),k.append("g").attr("class","y axis").call(j);var l=k.selectAll(".state").data(y).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",z).style("fill",function(a){return v(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){r(a.tooltip||a.y,d3.event),E.mouseover(a,d3.event),e.$apply()}).on("mouseleave",function(a){s(),E.mouseout(a,d3.event),e.$apply()}).on("mousemove",function(){t(d3.event)}).on("click",function(a){E.click.call(a,d3.event),e.$apply()}),E.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 z-Math.abs(c(a.y)-c(0))}).text(function(a){return a.y}),k.append("line").attr("x1",A).attr("y1",c(0)).attr("y2",c(0)).style("stroke","silver")}function n(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};A-=b.left+b.right,z-=b.top+b.bottom;var c=d3.scale.ordinal().domain(y.map(function(a){return a.x})).rangeRoundBands([0,A]),d=d3.scale.linear().range([z,10]),f=d3.svg.axis().scale(c).orient("bottom"),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=[];y.forEach(function(a){a.y.map(function(a){i.push(a)})});var k=d3.max(y.map(function(a){return a.y.length}));x.slice(0,k).forEach(function(a,b){var c={};c.series=a,c.values=y.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:y[b].x,y:0}}),j.push(c)});var l=d3.select(B[0]).append("svg").attr("width",A+b.left+b.right).attr("height",z+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,"+z+")").call(f),l.append("g").attr("class","y axis").call(g);var n=l.selectAll(".points").data(j).enter().append("g");path=n.attr("points","points").append("path").attr("class","ac-line").style("stroke",function(a,b){return v(b)}).attr("d",function(a){return h(a.values)}).attr("stroke-width","2").attr("fill","none");var o=j[j.length-1].values,p=path.node().getTotalLength()+a(o[o.length-1].x);return path.attr("stroke-dasharray",p+" "+p).attr("stroke-dashoffset",p).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",v(j.indexOf(b))).style("stroke",v(j.indexOf(b))).on("mouseover",function(a){r(a.tooltip||a.y,d3.event),E.mouseover(a,d3.event),e.$apply()}).on("mouseleave",function(a){s(),E.mouseout(a,d3.event),e.$apply()}).on("mousemove",function(){t(d3.event)}).on("click",function(a){E.click(a,d3.event),e.$apply()}),E.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})}),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 o(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};A-=b.left+b.right,z-=b.top+b.bottom;var c=d3.scale.ordinal().domain(y.map(function(a){return a.x})).rangeRoundBands([0,A]),d=d3.scale.linear().range([z,10]),f=d3.svg.axis().scale(c).orient("bottom"),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=[];y.forEach(function(a){a.y.map(function(a){h.push(a)})});var j=d3.max(y.map(function(a){return a.y.length}));e.yMaxData=j,x.slice(0,j).forEach(function(a,b){var c={};c.series=a,c.values=y.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:y[b].x,y:0}}),i.push(c)});var k=d3.select(B[0]).append("svg").attr("width",A+b.left+b.right).attr("height",z+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,"+z+")").call(f),k.append("g").attr("class","y axis").call(g);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 v(b)}).style("opacity","0.7")}function p(){function a(a){a.innerRadius=0;var b=d3.interpolate({startAngle:0,endAngle:0},a);return function(a){return d(b(a))}}var b=Math.min(A,z)/2,c=d3.select(B[0]).append("svg").attr("width",A).attr("height",z).append("g").attr("transform","translate("+A/2+","+z/2+")");e.yMaxData=y.length;{var d=d3.svg.arc().outerRadius(b-10).innerRadius(0),f=(d3.svg.arc().outerRadius(b+5).innerRadius(0),d3.layout.pie().sort(null).value(function(a){return a.y[0]})),g=c.selectAll(".arc").data(f(y)).enter().append("g");g.append("path").style("fill",function(a,b){return v(b)}).transition().ease("linear").duration(500).attrTween("d",a).attr("class","arc")}g.on("mouseover",function(a){r(a.data.tooltip||a.data.y[0]),d3.select(this).select("path").transition().duration(200).style("stroke","white").style("stroke-width","2px"),E.mouseover(a,d3.event),e.$apply()}).on("mouseleave",function(a){d3.select(this).select("path").transition().duration(200).style("stroke","").style("stroke-width",""),s(),E.mouseout(a,d3.event),e.$apply()}).on("mousemove",function(){t(d3.event)}).on("click",function(a){E.click(a,d3.event),e.$apply()}),E.labels&&g.append("text").attr("transform",function(a){return"translate("+d.centroid(a)+")"}).attr("dy",".35em").style("text-anchor","middle").text(function(a){return a.data.y[0]})}function q(){function a(a){return Math.round(c(a))+c.rangeBand()/2}var b={top:0,right:40,bottom:20,left:40};A-=b.left-b.right,z-=b.top-b.bottom;var c=d3.scale.ordinal().domain(y.map(function(a){return a.x})).rangeRoundBands([0,A]),d=d3.scale.linear().range([z,10]),f=d3.svg.axis().scale(c).orient("bottom"),g=d3.svg.axis().scale(d).orient("left").ticks(5).tickFormat(d3.format("s")),h=[0],i=[];y.forEach(function(a){a.y.map(function(a){h.push(a)})});var j=d3.max(y.map(function(a){return a.y.length}));e.yMaxPoints=j,x.slice(0,j).forEach(function(a,b){var c={};c.series=a,c.values=y.map(function(a){return a.y.map(function(b){return{x:a.x,y:b}})[b]||{x:y[b].x,y:0}}),i.push(c)});var k=d3.select(B[0]).append("svg").attr("width",A+b.left+b.right).attr("height",z+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,"+z+")").call(f),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",v(i.indexOf(b))).style("stroke",v(i.indexOf(b))).on("mouseover",function(a){r(a.tooltip||a.y,d3.event),E.mouseover(a,d3.event),e.$apply()}).on("mouseleave",function(a){s(),E.mouseout(a,d3.event),e.$apply()}).on("mousemove",function(){t(d3.event)}).on("click",function(a){E.click(a,d3.event),e.$apply()}),E.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 r(a,b){E.tooltips&&angular.element('

').html(a).appendTo("body").fadeIn("slow").css({left:b.pageX+20,top:b.pageY-30})}function s(){angular.element(".ac-tooltip").remove()}function t(a){angular.element(".ac-tooltip").css({left:a.pageX+20,top:a.pageY-30})}function u(){e.legends=[],"pie"==D&&angular.forEach(y,function(a,b){e.legends.push({color:E.colors[b],title:a.x})}),("bar"==D||"area"==D||"point"==D)&&angular.forEach(x,function(a,b){e.legends.push({color:E.colors[b],title:a})})}function v(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 diff --git a/src/angular-charts.js b/src/angular-charts.js index 19190ec..d3323a0 100644 --- a/src/angular-charts.js +++ b/src/angular-charts.js @@ -71,6 +71,9 @@ angular.module('angularCharts').directive('acChart', function($templateCache, $c isAnimate =true, defaultColors = config.colors; + if(totalHeight === 0 || totalWidth === 0) { + throw new Error('Please set height and width for the chart element') + } /** * All the magic happens here * handles extracting chart type