diff --git a/d3.ez.js b/d3.ez.js index e544e04f..15429a6d 100644 --- a/d3.ez.js +++ b/d3.ez.js @@ -6,7 +6,7 @@ * @license GPLv3 */ d3.ez = { - version: "1.5.8", + version: "1.5.9", author: "James Saunders", copyright: "Copyright (C) 2015 James Saunders", license: "GPL-3.0" @@ -791,15 +791,21 @@ d3.ez.circularHeatChart = function module() { d3.ez.tabularHeatChart = function module() { // SVG container (Populated by 'my' function) var svg; - // Default Options (Configurable via setters) var width = 600; var height = 600; - var margin = {top: 40, right: 40, bottom: 40, left: 40}; - var transition = {ease: "bounce", duration: 500}; + var margin = { + top: 40, + right: 40, + bottom: 40, + left: 40 + }; + var transition = { + ease: "bounce", + duration: 500 + }; var classed = "tabularHeatChart"; - var colors = ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"]; - + var colors = [ "#ffffd9", "#edf8b1", "#c7e9b4", "#7fcdbb", "#41b6c4", "#1d91c0", "#225ea8", "#253494", "#081d58" ]; // Data Options (Populated by 'init' function) var domain = null; var minValue = 0; @@ -808,18 +814,16 @@ d3.ez.tabularHeatChart = function module() { var numRows = 0; var gridSize = 0; var colNames = []; - var rowNames = []; var colorScale = undefined; - // Dispatch (Custom events) var dispatch = d3.dispatch("customHover"); - function init(data) { // Group and Category Names - colNames = data.map(function(d) { return d.key; }); + colNames = data.map(function(d) { + return d.key; + }); numCols = colNames.length; - /* The following bit of code is a little dirty! Its purpose is to identify the complete list of row names. In some cases the first (index 0) set of values may not contain the complete list of key names. @@ -828,21 +832,23 @@ d3.ez.tabularHeatChart = function module() { The code therefore takes the list of keys from the first (index 0) set of values and then concatenates it with the last (index max) set of values, finally removing duplicates. */ - var a =[]; - var b =[]; - data.map(function(d) { return d.values; })[0].forEach(function(d, i) { + var a = []; + var b = []; + data.map(function(d) { + return d.values; + })[0].forEach(function(d, i) { a[i] = d.key; }); - data.map(function(d) { return d.values; })[numCols-1].forEach(function(d, i) { + data.map(function(d) { + return d.values; + })[numCols - 1].forEach(function(d, i) { b[i] = d.key; }); - rowNames = b.concat(a.filter(function (element) { + rowNames = b.concat(a.filter(function(element) { return b.indexOf(element) < 0; })); numRows = rowNames.length; - - gridSize = Math.floor((width - (margin.left + margin.right)) / d3.max([numCols, numRows])); - + gridSize = Math.floor((width - (margin.left + margin.right)) / d3.max([ numCols, numRows ])); // Calculate the Max Value var values = []; d3.map(data).values().forEach(function(d) { @@ -853,145 +859,111 @@ d3.ez.tabularHeatChart = function module() { // maxValue = d3.quantile(values, 0.95) + 5; minValue = d3.min(values); maxValue = d3.max(values); - domain = [ minValue, maxValue ]; - // Colour Scale - colorScale = d3.scale.quantile() - .domain(domain) - .range(colors); + colorScale = d3.scale.quantile().domain(domain).range(colors); } - function my(selection) { selection.each(function(data) { // Initialise Data init(data); - // Create SVG element (if it does not exist already) if (!svg) { - svg = d3.select(this) - .append("svg") - .classed("d3ez", true) - .classed(classed, true); - + svg = d3.select(this).append("svg").classed("d3ez", true).classed(classed, true); var container = svg.append("g").classed("container", true); container.append("g").classed("x-axis axis", true); container.append("g").classed("y-axis axis", true); container.append("g").classed("cards", true); } - // Update the outer dimensions - svg.transition().attr({width: width, height: height}); - + svg.transition().attr({ + width: width, + height: height + }); // Update the inner dimensions - svg.select(".container") - .attr({transform: "translate(" + margin.left + "," + margin.top + ")"}); - - var deck = svg.select(".cards").selectAll(".deck") - .data(data); - - deck.enter().append("g") - .attr("class", "deck") - .attr("transform", function(d, i) { - return "translate(0, " + ((colNames.indexOf(d.key)) * gridSize) + ")"; - }); - deck.transition() - .attr("class", "deck"); - - var cards = deck.selectAll(".card") - .data(function(d) { - // Map row, column and value to new data array - var ret = []; - d3.map(d.values).values().forEach(function(v, i) { ret[i] = {row: d.key, column: v.key, value: v.value} }); - return ret; + svg.select(".container").attr({ + transform: "translate(" + margin.left + "," + margin.top + ")" + }); + var deck = svg.select(".cards").selectAll(".deck").data(data); + deck.enter().append("g").attr("class", "deck").attr("transform", function(d, i) { + return "translate(0, " + colNames.indexOf(d.key) * gridSize + ")"; + }); + deck.transition().attr("class", "deck"); + var cards = deck.selectAll(".card").data(function(d) { + // Map row, column and value to new data array + var ret = []; + d3.map(d.values).values().forEach(function(v, i) { + ret[i] = { + row: d.key, + column: v.key, + value: v.value + }; }); - - cards.enter().append("rect") - .attr("x", function(d) { return (rowNames.indexOf(d.column)) * gridSize; }) - .attr("y", 0) - .attr("rx", 5) - .attr("ry", 5) - .attr("class", "card") - .attr("width", gridSize) - .attr("height", gridSize) - .on("click", dispatch.customHover); - - cards.transition() - .duration(1000) - .style("fill", function(d) { return colorScale(d.value); }); - - cards.select("title").text(function(d) { return d.value; }); - + return ret; + }); + cards.enter().append("rect").attr("x", function(d) { + return rowNames.indexOf(d.column) * gridSize; + }).attr("y", 0).attr("rx", 5).attr("ry", 5).attr("class", "card").attr("width", gridSize).attr("height", gridSize).on("click", dispatch.customHover); + cards.transition().duration(1e3).style("fill", function(d) { + return colorScale(d.value); + }); + cards.select("title").text(function(d) { + return d.value; + }); cards.exit().remove(); - - var colLabels = svg.select(".x-axis").selectAll(".colLabel") - .data(colNames) - .enter().append("text") - .text(function (d) { return d; }) - .attr("x", 0) - .attr("y", function (d, i) { return i * gridSize; }) - .style("text-anchor", "end") - .attr("transform", "translate(-6," + gridSize / 2 + ")") - .attr("class", function (d, i) { return ((i >= 0 && i <= 4) ? "colLabel mono axis axis-workweek" : "colLabel mono axis"); }); - - var rowLabels = svg.select(".y-axis").selectAll(".rowLabel") - .data(rowNames) - .enter() - .append("g") - .attr("transform", function(d, i) { - return "translate(" + ((i * gridSize) + (gridSize / 2)) + ", -6)"; - }) - .append("text") - .text(function(d) { return d; }) - .style("text-anchor", "start") - .attr("class", function(d, i) { return ((i >= 7 && i <= 16) ? "rowLabel mono axis axis-worktime" : "rowLabel mono axis"); }) - .attr("transform", function(d) { - return "rotate(-90)" - }); + var colLabels = svg.select(".x-axis").selectAll(".colLabel").data(colNames).enter().append("text").text(function(d) { + return d; + }).attr("x", 0).attr("y", function(d, i) { + return i * gridSize; + }).style("text-anchor", "end").attr("transform", "translate(-6," + gridSize / 2 + ")").attr("class", function(d, i) { + return i >= 0 && i <= 4 ? "colLabel mono axis axis-workweek" : "colLabel mono axis"; + }); + var rowLabels = svg.select(".y-axis").selectAll(".rowLabel").data(rowNames).enter().append("g").attr("transform", function(d, i) { + return "translate(" + (i * gridSize + gridSize / 2) + ", -6)"; + }).append("text").text(function(d) { + return d; + }).style("text-anchor", "start").attr("class", function(d, i) { + return i >= 7 && i <= 16 ? "rowLabel mono axis axis-worktime" : "rowLabel mono axis"; + }).attr("transform", function(d) { + return "rotate(-90)"; + }); }); } - // Configuration Getters & Setters my.width = function(_) { if (!arguments.length) return width; width = _; return this; }; - my.height = function(_) { if (!arguments.length) return height; height = _; return this; }; - my.margin = function(_) { if (!arguments.length) return margin; margin = _; return this; }; - my.colors = function(_) { if (!arguments.length) return colors; colors = _; return this; }; - my.domain = function(_) { if (!arguments.length) return domain; domain = _; return this; }; - my.accessor = function(_) { if (!arguments.length) return accessor; accessor = _; return this; }; - d3.rebind(my, dispatch, "on"); - return my; }; + /** * Donut Chart * diff --git a/d3.ez.min.js b/d3.ez.min.js index 97a5961a..98630c61 100644 --- a/d3.ez.min.js +++ b/d3.ez.min.js @@ -1,2 +1,2 @@ -d3.ez={version:"1.5.8",author:"James Saunders",copyright:"Copyright (C) 2015 James Saunders",license:"GPL-3.0"};d3.ez.discreteBarChart=function module(){var svg;var width=400;var height=300;var margin={top:40,right:40,bottom:40,left:40};var transition={ease:"bounce",duration:500};var classed="discreteBarChart";var colors=d3.ez.colors.categorical(4);var gap=0;var chartW=0;var chartH=0;var maxValue=0;var categories=[];var xScale=undefined;var yScale=undefined;var yAxisLabel=undefined;var xAxis=undefined;var yAxis=undefined;var colorScale=undefined;var dispatch=d3.dispatch("customHover");function init(data){chartW=width-margin.left-margin.right;chartH=height-margin.top-margin.bottom;yAxisLabel=d3.values(data)[0];maxValue=d3.max(data.values,function(d){return d.value});categories=d3.values(data)[1].map(function(d){return d.key});xScale=d3.scale.ordinal().domain(categories).rangeRoundBands([0,chartW],.1);yScale=d3.scale.linear().domain([0,maxValue]).range([chartH,0]);xAxis=d3.svg.axis().scale(xScale).orient("bottom");yAxis=d3.svg.axis().scale(yScale).orient("left");colorScale=d3.scale.ordinal().domain(categories).range(colors)}function my(selection){selection.each(function(data){init(data);if(!svg){svg=d3.select(this).append("svg").classed("d3ez",true).classed(classed,true);var container=svg.append("g").classed("container",true);container.append("g").classed("chart",true);container.append("g").classed("x-axis axis",true);container.append("g").classed("y-axis axis",true)}svg.attr({width:width,height:height});var creditTag=d3.ez.creditTag();svg.call(creditTag);svg.select(".container").attr({transform:"translate("+margin.left+","+margin.top+")"});svg.select(".x-axis").attr({transform:"translate(0,"+chartH+")"}).call(xAxis);svg.select(".y-axis").call(yAxis);ylabel=svg.select(".y-axis").selectAll(".y-label").data([data.key]);ylabel.enter().append("text").classed("y-label",true).attr("transform","rotate(-90)").attr("y",-35).attr("dy",".71em").style("text-anchor","end");ylabel.transition().text(function(d){return d});var gapSize=xScale.rangeBand()/100*gap;var barW=xScale.rangeBand()-gapSize;var bars=svg.select(".chart").selectAll(".bar").data(data.values);bars.enter().append("rect").attr("class",function(d){return d.key+" bar"}).attr("fill",function(d){return colorScale(d.key)}).attr({width:barW,x:function(d,i){return xScale(d.key)+gapSize/2},y:chartH,height:0}).on("mouseover",dispatch.customHover);bars.transition().ease(transition.ease).duration(transition.duration).attr({width:barW,x:function(d,i){return xScale(d.key)+gapSize/2},y:function(d,i){return yScale(d.value)},height:function(d,i){return chartH-yScale(d.value)}});bars.exit().transition().style({opacity:0}).remove()})}my.width=function(_){if(!arguments.length)return width;width=_;return this};my.height=function(_){if(!arguments.length)return height;height=_;return this};my.colors=function(_){if(!arguments.length)return colors;colors=_;return this};my.transition=function(_){if(!arguments.length)return transition;transition=_;return this};d3.rebind(my,dispatch,"on");return my};d3.ez.groupedBarChart=function module(){var svg;var width=400;var height=300;var margin={top:40,right:40,bottom:40,left:40};var transition={ease:"bounce",duration:500};var classed="groupedBarChart";var colors=d3.ez.colors.categorical(4);var gap=0;var yAxisLabel=null;var groupType="clustered";var chartW=0;var chartH=0;var groupNames=undefined;var categoryNames=[];var categoryTotals=[];var groupTotals=[];var maxValue=0;var maxGroupTotal=undefined;var xScale=undefined;var yScale=undefined;var xAxis=undefined;var yAxis=undefined;var colorScale=undefined;var dispatch=d3.dispatch("customHover");function init(data){chartW=width-margin.left-margin.right;chartH=height-margin.top-margin.bottom;groupNames=data.map(function(d){return d.key});categoryNames=[];data.map(function(d){return d.values})[0].forEach(function(d,i){categoryNames[i]=d.key});categoryTotals=[];groupTotals=[];maxValue=0;d3.map(data).values().forEach(function(d){grp=d.key;d.values.forEach(function(d){categoryTotals[d.key]=typeof categoryTotals[d.key]==="undefined"?0:categoryTotals[d.key];categoryTotals[d.key]+=d.value;groupTotals[grp]=typeof groupTotals[grp]==="undefined"?0:groupTotals[grp];groupTotals[grp]+=d.value;maxValue=d.value>maxValue?d.value:maxValue})});maxGroupTotal=d3.max(d3.values(groupTotals));xScale=d3.scale.ordinal().rangeRoundBands([0,chartW],.1).domain(groupNames);yScale=d3.scale.linear().range([chartH,0]).domain([0,groupType=="stacked"?maxGroupTotal:maxValue]);xAxis=d3.svg.axis().scale(xScale).orient("bottom");yAxis=d3.svg.axis().scale(yScale).orient("left");colorScale=d3.scale.ordinal().range(colors).domain(categoryNames)}function my(selection){selection.each(function(data){init(data);if(!svg){svg=d3.select(this).append("svg").classed("d3ez",true).classed(classed,true);var container=svg.append("g").classed("container",true);container.append("g").classed("chart",true);container.append("g").classed("x-axis axis",true);container.append("g").classed("y-axis axis",true).append("text").attr("transform","rotate(-90)").attr("y",-35).attr("dy",".71em").style("text-anchor","end").text(yAxisLabel)}svg.attr({width:width,height:height});var creditTag=d3.ez.creditTag();svg.call(creditTag);svg.select(".container").attr({transform:"translate("+margin.left+","+margin.top+")"});svg.select(".x-axis").attr({transform:"translate(0,"+chartH+")"}).call(xAxis);svg.select(".y-axis").call(yAxis);var barGroup=svg.select(".chart").selectAll(".barGroup").data(data);barGroup.enter().append("g").attr("class","barGroup").attr("transform",function(d,i){return"translate("+xScale(d.key)+", 0)"}).on("mouseover",dispatch.customHover);var bars=barGroup.selectAll(".bar").data(function(d){series=[];var y0=0;d3.map(d.values).values().forEach(function(d,i){series[i]={name:d.key,value:d.value,y0:y0,y1:y0+d.value};y0+=d.value});return series});if(groupType=="stacked"){var gapSize=xScale.rangeBand()/100*gap;var barW=xScale.rangeBand()-gapSize;bars.enter().append("rect").classed("bar",true).attr("class",function(d){return d.name+" bar"}).attr({width:barW,x:0,y:chartH,height:0}).attr("fill",function(d){return colorScale(d.name)});bars.transition().ease(transition.ease).duration(transition.duration).attr({width:barW,x:0,y:function(d){return yScale(d.y1)},height:function(d){return yScale(d.y0)-yScale(d.y1)}}).attr("fill",function(d){return colorScale(d.name)});bars.exit().transition().style({opacity:0}).remove()}else if(groupType=="clustered"){var x1=d3.scale.ordinal().rangeRoundBands([0,xScale.rangeBand()]).domain(categoryNames);bars.enter().append("rect").classed("bar",true).attr({width:x1.rangeBand(),x:function(d){return x1(d.name)},y:chartH,height:0}).attr("fill",function(d){return colorScale(d.name)});bars.transition().ease(transition.ease).duration(transition.duration).attr({width:x1.rangeBand(),x:function(d){return x1(d.name)},y:function(d){return yScale(d.value)},height:function(d){return chartH-yScale(d.value)}}).attr("fill",function(d){return colorScale(d.name)});bars.exit().transition().style({opacity:0}).remove()}var legend=svg.selectAll(".legend").data(categoryNames.slice().reverse()).enter().append("g").attr("class","legend").attr("transform",function(d,i){return"translate(0,"+i*20+")"});legend.append("rect").attr("x",width-18).attr("width",18).attr("height",18).style("fill",colorScale);legend.append("text").attr("x",width-24).attr("y",9).attr("dy",".35em").style("text-anchor","end").text(function(d){return d})})}my.width=function(_){if(!arguments.length)return width;width=_;return this};my.height=function(_){if(!arguments.length)return height;height=_;return this};my.margin=function(_){if(!arguments.length)return margin;margin=_;return this};my.yAxisLabel=function(_){if(!arguments.length)return yAxisLabel;yAxisLabel=_;return this};my.groupType=function(_){if(!arguments.length)return groupType;groupType=_;return this};my.transition=function(_){if(!arguments.length)return transition;transition=_;return this};my.colors=function(_){if(!arguments.length)return colors;colors=_;return this};d3.rebind(my,dispatch,"on");return my};d3.ez.radialBarChart=function module(){var svg;var width=400;var height=300;var margin={top:20,right:20,bottom:20,left:20};var transition={ease:"bounce",duration:500};var classed="radialBarChart";var colors=d3.ez.colors.categorical(4);var radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;var capitalizeLabels=false;var colorLabels=false;var tickValues=[];var tickCircleValues=[];var domain=[];var numBars=undefined;var barScale=undefined;var keys=undefined;var labelRadius=0;var categoryTotals=[];var groupTotals=[];var maxValue=0;var dispatch=d3.dispatch("customHover");function init(data){keys=d3.values(data)[1].map(function(d){return d.key});numBars=keys.length;labelRadius=radius*1.025;maxValue=d3.max(data.values,function(d){return d.value});tickCircleValues=[];for(var i=0;i<=maxValue;i++){tickCircleValues.push(i)}tickValues=tickCircleValues;tickValues.push(maxValue+1);domain=[0,maxValue+1];barScale=d3.scale.linear().domain(domain).range([0,radius])}function my(selection){selection.each(function(data){init(data);if(!svg){svg=d3.select(this).append("svg").classed("d3ez",true).classed(classed,true);var container=svg.append("g").classed("container",true);container.append("g").classed("tickCircles",true);container.append("g").classed("segments",true);container.append("g").classed("spokes",true);container.append("g").classed("axis",true);container.append("circle").classed("outerCircle",true);container.append("g").classed("labels",true)}svg.attr({width:width,height:height});var creditTag=d3.ez.creditTag();svg.call(creditTag);svg.select(".container").attr("transform","translate("+width/2+","+height/2+")");tickCircles=d3.select(".tickCircles").selectAll("circle").data(tickCircleValues);tickCircles.enter().append("circle").style("fill","none");tickCircles.transition().attr("r",function(d){return barScale(d)}).ease(transition.ease).duration(transition.duration);tickCircles.exit().remove();var arc=d3.svg.arc().innerRadius(0).outerRadius(function(d,i){return barScale(d.value)}).startAngle(function(d,i){return i*2*Math.PI/numBars}).endAngle(function(d,i){return(i+1)*2*Math.PI/numBars});var segments=d3.select(".segments").selectAll("path").data(data.values);segments.enter().append("path").style("fill",function(d,i){if(!colors)return;return colors[i%colors.length]}).classed("segment",true).on("mouseover",dispatch.customHover);segments.exit().remove();segments.transition().ease(transition.ease).duration(transition.duration).attr("d",arc);spokes=d3.select(".spokes").selectAll("line").data(keys).enter().append("line").attr("y2",-radius).attr("transform",function(d,i){return"rotate("+i*360/numBars+")"});var axisScale=d3.scale.linear().domain(domain).range([0,-radius]);var axis=d3.svg.axis().scale(axisScale).orient("right");if(tickValues)axis.tickValues(tickValues);axis=d3.select(".axis").call(axis);outerCircle=d3.select(".outerCircle").attr("r",radius).style("fill","none");var labels=d3.select(".labels");labels.append("def").append("path").attr("id","label-path").attr("d","m0 "+-labelRadius+" a"+labelRadius+" "+labelRadius+" 0 1,1 -0.01 0");labels.selectAll("text").data(keys).enter().append("text").style("text-anchor","middle").style("fill",function(d,i){return colorLabels?colors[i%colors.length]:null}).append("textPath").attr("xlink:href","#label-path").attr("startOffset",function(d,i){return i*100/numBars+50/numBars+"%"}).text(function(d){return capitalizeLabels?d.toUpperCase():d})})}my.width=function(_){if(!arguments.length)return width;width=_;radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;return this};my.height=function(_){if(!arguments.length)return height;height=_;radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;return this};my.margin=function(_){if(!arguments.length)return margin;margin=_;radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;return this};my.radius=function(_){if(!arguments.length)return radius;radius=_;return this};my.colors=function(_){if(!arguments.length)return colors;colors=_;return this};my.transition=function(_){if(!arguments.length)return transition;transition=_;return this};my.capitalizeLabels=function(_){if(!arguments.length)return capitalizeLabels;capitalizeLabels=_;return this};my.colorLabels=function(_){if(!arguments.length)return colorLabels;colorLabels=_;return this};d3.rebind(my,dispatch,"on");return my};d3.ez.circularHeatChart=function module(){var svg;var width=400;var height=300;var margin={top:20,right:20,bottom:20,left:20};var transition={ease:"bounce",duration:500};var classed="circularHeatChart";var colors=["white","orange"];var radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;var innerRadius=50;var domain=undefined;var radialLabels=[];var numRadials=24;var segmentLabels=[];var numSegments=24;var segmentHeight=0;var maxValue=0;var dispatch=d3.dispatch("customHover");function init(data){radialLabels=data.map(function(d){return d.key});numRadials=radialLabels.length;segmentLabels=d3.values(data[0].values).map(function(d){return d.key});numSegments=segmentLabels.length;segmentHeight=(radius-innerRadius)/numRadials;d3.map(data).values().forEach(function(d){d.values.forEach(function(d){maxValue=d.value>maxValue?d.value:maxValue})});domain=[0,maxValue]}function my(selection){selection.each(function(data){init(data);if(!svg){svg=d3.select(this).append("svg").classed("d3ez",true).classed(classed,true);var container=svg.append("g").classed("container",true);container.append("g").classed("rings",true);container.append("g").classed("radialLabels",true);container.append("g").classed("segmentLabels",true)}svg.attr({width:width,height:height});var creditTag=d3.ez.creditTag();svg.call(creditTag);svg.select(".container").attr("transform","translate("+width/2+","+height/2+")");var color=d3.scale.linear().domain(domain).range(colors);var arc=d3.svg.arc().innerRadius(function(d,i){return innerRadius+d.ring*segmentHeight}).outerRadius(function(d,i){return innerRadius+segmentHeight+d.ring*segmentHeight}).startAngle(function(d,i){return i*2*Math.PI/numSegments}).endAngle(function(d,i){return(i+1)*2*Math.PI/numSegments});d3.select(".rings").selectAll("g").data(data).enter().append("g").classed("ring",true).on("mouseover",dispatch.customHover);d3.selectAll(".ring").selectAll("path").data(function(d,i){for(j=0;j=0&&i<=4?"colLabel mono axis axis-workweek":"colLabel mono axis"});var rowLabels=svg.select(".y-axis").selectAll(".rowLabel").data(rowNames).enter().append("g").attr("transform",function(d,i){return"translate("+(i*gridSize+gridSize/2)+", -6)"}).append("text").text(function(d){return d}).style("text-anchor","start").attr("class",function(d,i){return i>=7&&i<=16?"rowLabel mono axis axis-worktime":"rowLabel mono axis"}).attr("transform",function(d){return"rotate(-90)"})})}my.width=function(_){if(!arguments.length)return width;width=_;return this};my.height=function(_){if(!arguments.length)return height;height=_;return this};my.margin=function(_){if(!arguments.length)return margin;margin=_;return this};my.colors=function(_){if(!arguments.length)return colors;colors=_;return this};my.domain=function(_){if(!arguments.length)return domain;domain=_;return this};my.accessor=function(_){if(!arguments.length)return accessor;accessor=_;return this};d3.rebind(my,dispatch,"on");return my};d3.ez.donutChart=function module(){var svg;var width=400;var height=300;var margin={top:20,right:20,bottom:20,left:20};var transition={ease:"cubic",duration:300};var classed="donutChart";var colors=d3.ez.colors.categorical(4);var radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;var innerRadius=70;var values=[];var categoryNames=[];var colorScale=undefined;var pie=undefined;var arc=undefined;var outerArc=undefined;var key=undefined;var dispatch=d3.dispatch("customHover");function init(data){values=d3.values(data)[1].map(function(d){return d.value});categoryNames=d3.values(data)[1].map(function(d){return d.key});colorScale=d3.scale.ordinal().range(colors).domain(categoryNames);pie=d3.layout.pie().sort(null);arc=d3.svg.arc().innerRadius(innerRadius).outerRadius(radius);outerArc=d3.svg.arc().innerRadius(radius*.9).outerRadius(radius*.9)}function key(d,i){return data.values[i].key}function arcTween(d){var i=d3.interpolate(this._current,d);this._current=i(0);return function(t){return arc(i(t))}}function midAngle(d){return d.startAngle+(d.endAngle-d.startAngle)/2}function my(selection){selection.each(function(data){init(data);svg=d3.select(this).select("svg > g");if(svg.empty()){var svg=d3.select(this).append("svg").classed("d3ez",true).classed(classed,true);svg.append("g").attr("class","slices").attr("transform","translate("+width/2+","+height/2+")");svg.append("g").attr("class","labels").attr("transform","translate("+width/2+","+height/2+")");svg.append("g").attr("class","lines").attr("transform","translate("+width/2+","+height/2+")")}svg.attr({width:width,height:height});var creditTag=d3.ez.creditTag();svg.call(creditTag);var slices=d3.select(".slices").selectAll("path.slice").data(pie(values));slices.enter().append("path").attr("class","slice").attr("fill",function(d,i){return colorScale(data.values[i].key)}).attr("d",arc).each(function(d){this._current=d}).on("mouseover",dispatch.customHover);slices.transition().ease(transition.ease).duration(transition.duration).attrTween("d",arcTween);slices.exit().remove();var labels=d3.select(".labels").selectAll("text.label").data(pie(values),key);labels.enter().append("text").attr("class","label").attr("dy",".35em");labels.transition().duration(transition.duration).text(function(d,i){return data.values[i].key}).attrTween("transform",function(d){this._current=this._current||d;var interpolate=d3.interpolate(this._current,d);this._current=interpolate(0);return function(t){var d2=interpolate(t);var pos=outerArc.centroid(d2);pos[0]=radius*(midAngle(d2)maxValue?d.value:maxValue})});maxGroupTotal=d3.max(d3.values(groupTotals));xScale=d3.scale.ordinal().rangeRoundBands([0,chartW],.1).domain(groupNames);yScale=d3.scale.linear().range([chartH,0]).domain([0,groupType=="stacked"?maxGroupTotal:maxValue]);xAxis=d3.svg.axis().scale(xScale).orient("bottom");yAxis=d3.svg.axis().scale(yScale).orient("left");colorScale=d3.scale.ordinal().range(colors).domain(categoryNames)}function my(selection){selection.each(function(data){init(data);if(!svg){svg=d3.select(this).append("svg").classed("d3ez",true).classed(classed,true);var container=svg.append("g").classed("container",true);container.append("g").classed("chart",true);container.append("g").classed("x-axis axis",true);container.append("g").classed("y-axis axis",true).append("text").attr("transform","rotate(-90)").attr("y",-35).attr("dy",".71em").style("text-anchor","end").text(yAxisLabel)}svg.attr({width:width,height:height});var creditTag=d3.ez.creditTag();svg.call(creditTag);svg.select(".container").attr({transform:"translate("+margin.left+","+margin.top+")"});svg.select(".x-axis").attr({transform:"translate(0,"+chartH+")"}).call(xAxis);svg.select(".y-axis").call(yAxis);var barGroup=svg.select(".chart").selectAll(".barGroup").data(data);barGroup.enter().append("g").attr("class","barGroup").attr("transform",function(d,i){return"translate("+xScale(d.key)+", 0)"}).on("mouseover",dispatch.customHover);var bars=barGroup.selectAll(".bar").data(function(d){series=[];var y0=0;d3.map(d.values).values().forEach(function(d,i){series[i]={name:d.key,value:d.value,y0:y0,y1:y0+d.value};y0+=d.value});return series});if(groupType=="stacked"){var gapSize=xScale.rangeBand()/100*gap;var barW=xScale.rangeBand()-gapSize;bars.enter().append("rect").classed("bar",true).attr("class",function(d){return d.name+" bar"}).attr({width:barW,x:0,y:chartH,height:0}).attr("fill",function(d){return colorScale(d.name)});bars.transition().ease(transition.ease).duration(transition.duration).attr({width:barW,x:0,y:function(d){return yScale(d.y1)},height:function(d){return yScale(d.y0)-yScale(d.y1)}}).attr("fill",function(d){return colorScale(d.name)});bars.exit().transition().style({opacity:0}).remove()}else if(groupType=="clustered"){var x1=d3.scale.ordinal().rangeRoundBands([0,xScale.rangeBand()]).domain(categoryNames);bars.enter().append("rect").classed("bar",true).attr({width:x1.rangeBand(),x:function(d){return x1(d.name)},y:chartH,height:0}).attr("fill",function(d){return colorScale(d.name)});bars.transition().ease(transition.ease).duration(transition.duration).attr({width:x1.rangeBand(),x:function(d){return x1(d.name)},y:function(d){return yScale(d.value)},height:function(d){return chartH-yScale(d.value)}}).attr("fill",function(d){return colorScale(d.name)});bars.exit().transition().style({opacity:0}).remove()}var legend=svg.selectAll(".legend").data(categoryNames.slice().reverse()).enter().append("g").attr("class","legend").attr("transform",function(d,i){return"translate(0,"+i*20+")"});legend.append("rect").attr("x",width-18).attr("width",18).attr("height",18).style("fill",colorScale);legend.append("text").attr("x",width-24).attr("y",9).attr("dy",".35em").style("text-anchor","end").text(function(d){return d})})}my.width=function(_){if(!arguments.length)return width;width=_;return this};my.height=function(_){if(!arguments.length)return height;height=_;return this};my.margin=function(_){if(!arguments.length)return margin;margin=_;return this};my.yAxisLabel=function(_){if(!arguments.length)return yAxisLabel;yAxisLabel=_;return this};my.groupType=function(_){if(!arguments.length)return groupType;groupType=_;return this};my.transition=function(_){if(!arguments.length)return transition;transition=_;return this};my.colors=function(_){if(!arguments.length)return colors;colors=_;return this};d3.rebind(my,dispatch,"on");return my};d3.ez.radialBarChart=function module(){var svg;var width=400;var height=300;var margin={top:20,right:20,bottom:20,left:20};var transition={ease:"bounce",duration:500};var classed="radialBarChart";var colors=d3.ez.colors.categorical(4);var radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;var capitalizeLabels=false;var colorLabels=false;var tickValues=[];var tickCircleValues=[];var domain=[];var numBars=undefined;var barScale=undefined;var keys=undefined;var labelRadius=0;var categoryTotals=[];var groupTotals=[];var maxValue=0;var dispatch=d3.dispatch("customHover");function init(data){keys=d3.values(data)[1].map(function(d){return d.key});numBars=keys.length;labelRadius=radius*1.025;maxValue=d3.max(data.values,function(d){return d.value});tickCircleValues=[];for(var i=0;i<=maxValue;i++){tickCircleValues.push(i)}tickValues=tickCircleValues;tickValues.push(maxValue+1);domain=[0,maxValue+1];barScale=d3.scale.linear().domain(domain).range([0,radius])}function my(selection){selection.each(function(data){init(data);if(!svg){svg=d3.select(this).append("svg").classed("d3ez",true).classed(classed,true);var container=svg.append("g").classed("container",true);container.append("g").classed("tickCircles",true);container.append("g").classed("segments",true);container.append("g").classed("spokes",true);container.append("g").classed("axis",true);container.append("circle").classed("outerCircle",true);container.append("g").classed("labels",true)}svg.attr({width:width,height:height});var creditTag=d3.ez.creditTag();svg.call(creditTag);svg.select(".container").attr("transform","translate("+width/2+","+height/2+")");tickCircles=d3.select(".tickCircles").selectAll("circle").data(tickCircleValues);tickCircles.enter().append("circle").style("fill","none");tickCircles.transition().attr("r",function(d){return barScale(d)}).ease(transition.ease).duration(transition.duration);tickCircles.exit().remove();var arc=d3.svg.arc().innerRadius(0).outerRadius(function(d,i){return barScale(d.value)}).startAngle(function(d,i){return i*2*Math.PI/numBars}).endAngle(function(d,i){return(i+1)*2*Math.PI/numBars});var segments=d3.select(".segments").selectAll("path").data(data.values);segments.enter().append("path").style("fill",function(d,i){if(!colors)return;return colors[i%colors.length]}).classed("segment",true).on("mouseover",dispatch.customHover);segments.exit().remove();segments.transition().ease(transition.ease).duration(transition.duration).attr("d",arc);spokes=d3.select(".spokes").selectAll("line").data(keys).enter().append("line").attr("y2",-radius).attr("transform",function(d,i){return"rotate("+i*360/numBars+")"});var axisScale=d3.scale.linear().domain(domain).range([0,-radius]);var axis=d3.svg.axis().scale(axisScale).orient("right");if(tickValues)axis.tickValues(tickValues);axis=d3.select(".axis").call(axis);outerCircle=d3.select(".outerCircle").attr("r",radius).style("fill","none");var labels=d3.select(".labels");labels.append("def").append("path").attr("id","label-path").attr("d","m0 "+-labelRadius+" a"+labelRadius+" "+labelRadius+" 0 1,1 -0.01 0");labels.selectAll("text").data(keys).enter().append("text").style("text-anchor","middle").style("fill",function(d,i){return colorLabels?colors[i%colors.length]:null}).append("textPath").attr("xlink:href","#label-path").attr("startOffset",function(d,i){return i*100/numBars+50/numBars+"%"}).text(function(d){return capitalizeLabels?d.toUpperCase():d})})}my.width=function(_){if(!arguments.length)return width;width=_;radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;return this};my.height=function(_){if(!arguments.length)return height;height=_;radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;return this};my.margin=function(_){if(!arguments.length)return margin;margin=_;radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;return this};my.radius=function(_){if(!arguments.length)return radius;radius=_;return this};my.colors=function(_){if(!arguments.length)return colors;colors=_;return this};my.transition=function(_){if(!arguments.length)return transition;transition=_;return this};my.capitalizeLabels=function(_){if(!arguments.length)return capitalizeLabels;capitalizeLabels=_;return this};my.colorLabels=function(_){if(!arguments.length)return colorLabels;colorLabels=_;return this};d3.rebind(my,dispatch,"on");return my};d3.ez.circularHeatChart=function module(){var svg;var width=400;var height=300;var margin={top:20,right:20,bottom:20,left:20};var transition={ease:"bounce",duration:500};var classed="circularHeatChart";var colors=["white","orange"];var radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;var innerRadius=50;var domain=undefined;var radialLabels=[];var numRadials=24;var segmentLabels=[];var numSegments=24;var segmentHeight=0;var maxValue=0;var dispatch=d3.dispatch("customHover");function init(data){radialLabels=data.map(function(d){return d.key});numRadials=radialLabels.length;segmentLabels=d3.values(data[0].values).map(function(d){return d.key});numSegments=segmentLabels.length;segmentHeight=(radius-innerRadius)/numRadials;d3.map(data).values().forEach(function(d){d.values.forEach(function(d){maxValue=d.value>maxValue?d.value:maxValue})});domain=[0,maxValue]}function my(selection){selection.each(function(data){init(data);if(!svg){svg=d3.select(this).append("svg").classed("d3ez",true).classed(classed,true);var container=svg.append("g").classed("container",true);container.append("g").classed("rings",true);container.append("g").classed("radialLabels",true);container.append("g").classed("segmentLabels",true)}svg.attr({width:width,height:height});var creditTag=d3.ez.creditTag();svg.call(creditTag);svg.select(".container").attr("transform","translate("+width/2+","+height/2+")");var color=d3.scale.linear().domain(domain).range(colors);var arc=d3.svg.arc().innerRadius(function(d,i){return innerRadius+d.ring*segmentHeight}).outerRadius(function(d,i){return innerRadius+segmentHeight+d.ring*segmentHeight}).startAngle(function(d,i){return i*2*Math.PI/numSegments}).endAngle(function(d,i){return(i+1)*2*Math.PI/numSegments});d3.select(".rings").selectAll("g").data(data).enter().append("g").classed("ring",true).on("mouseover",dispatch.customHover);d3.selectAll(".ring").selectAll("path").data(function(d,i){for(j=0;j=0&&i<=4?"colLabel mono axis axis-workweek":"colLabel mono axis"});var rowLabels=svg.select(".y-axis").selectAll(".rowLabel").data(rowNames).enter().append("g").attr("transform",function(d,i){return"translate("+(i*gridSize+gridSize/2)+", -6)"}).append("text").text(function(d){return d}).style("text-anchor","start").attr("class",function(d,i){return i>=7&&i<=16?"rowLabel mono axis axis-worktime":"rowLabel mono axis"}).attr("transform",function(d){return"rotate(-90)"})})}my.width=function(_){if(!arguments.length)return width;width=_;return this};my.height=function(_){if(!arguments.length)return height;height=_;return this};my.margin=function(_){if(!arguments.length)return margin;margin=_;return this};my.colors=function(_){if(!arguments.length)return colors;colors=_;return this};my.domain=function(_){if(!arguments.length)return domain;domain=_;return this};my.accessor=function(_){if(!arguments.length)return accessor;accessor=_;return this};d3.rebind(my,dispatch,"on");return my};d3.ez.donutChart=function module(){var svg;var width=400;var height=300;var margin={top:20,right:20,bottom:20,left:20};var transition={ease:"cubic",duration:300};var classed="donutChart";var colors=d3.ez.colors.categorical(4);var radius=d3.min([width-(margin.right+margin.left),height-(margin.top+margin.bottom)])/2;var innerRadius=70;var values=[];var categoryNames=[];var colorScale=undefined;var pie=undefined;var arc=undefined;var outerArc=undefined;var key=undefined;var dispatch=d3.dispatch("customHover");function init(data){values=d3.values(data)[1].map(function(d){return d.value});categoryNames=d3.values(data)[1].map(function(d){return d.key});colorScale=d3.scale.ordinal().range(colors).domain(categoryNames);pie=d3.layout.pie().sort(null);arc=d3.svg.arc().innerRadius(innerRadius).outerRadius(radius);outerArc=d3.svg.arc().innerRadius(radius*.9).outerRadius(radius*.9)}function key(d,i){return data.values[i].key}function arcTween(d){var i=d3.interpolate(this._current,d);this._current=i(0);return function(t){return arc(i(t))}}function midAngle(d){return d.startAngle+(d.endAngle-d.startAngle)/2}function my(selection){selection.each(function(data){init(data);svg=d3.select(this).select("svg > g");if(svg.empty()){var svg=d3.select(this).append("svg").classed("d3ez",true).classed(classed,true);svg.append("g").attr("class","slices").attr("transform","translate("+width/2+","+height/2+")");svg.append("g").attr("class","labels").attr("transform","translate("+width/2+","+height/2+")");svg.append("g").attr("class","lines").attr("transform","translate("+width/2+","+height/2+")")}svg.attr({width:width,height:height});var creditTag=d3.ez.creditTag();svg.call(creditTag);var slices=d3.select(".slices").selectAll("path.slice").data(pie(values));slices.enter().append("path").attr("class","slice").attr("fill",function(d,i){return colorScale(data.values[i].key)}).attr("d",arc).each(function(d){this._current=d}).on("mouseover",dispatch.customHover);slices.transition().ease(transition.ease).duration(transition.duration).attrTween("d",arcTween);slices.exit().remove();var labels=d3.select(".labels").selectAll("text.label").data(pie(values),key);labels.enter().append("text").attr("class","label").attr("dy",".35em");labels.transition().duration(transition.duration).text(function(d,i){return data.values[i].key}).attrTween("transform",function(d){this._current=this._current||d;var interpolate=d3.interpolate(this._current,d);this._current=interpolate(0);return function(t){var d2=interpolate(t);var pos=outerArc.centroid(d2);pos[0]=radius*(midAngle(d2)