diff --git a/build/d3-ez.js b/build/d3-ez.js index 8ccae03f..fcc0456f 100644 --- a/build/d3-ez.js +++ b/build/d3-ez.js @@ -1278,7 +1278,7 @@ d3.ez.component.heatMap = function module() { var yScale = undefined; var transition = { ease: d3.easeBounce, - duration: 500 + duration: 1e3 }; var dispatch = d3.dispatch("customMouseOver", "customMouseOut", "customClick"); function my(selection) { @@ -1290,21 +1290,18 @@ d3.ez.component.heatMap = function module() { }).enter().append("g").classed("series", true).on("click", function(d) { dispatch.call("customClick", this, d); }); - series = selection.selectAll(".series").merge(series); + selection.selectAll(".series").merge(series); var cells = series.selectAll(".cell").data(function(d) { return d.values; }); cells.enter().append("rect").attr("x", function(d) { return xScale(d.key); - }).attr("y", 0).attr("rx", 2).attr("ry", 2).attr("class", "cell").attr("width", cellWidth).attr("height", cellHeight).on("click", dispatch.customClick).on("mouseover", function(d) { + }).attr("y", 0).attr("rx", 2).attr("ry", 2).attr("fill", "black").attr("class", "cell").attr("width", cellWidth).attr("height", cellHeight).on("click", dispatch.customClick).on("mouseover", function(d) { dispatch.call("customMouseOver", this, d); - }).merge(cells).transition().duration(1e3).attr("fill", function(d) { + }).merge(cells).transition().duration(transition.duration).attr("fill", function(d) { return colorScale(d.value); }); cells.exit().remove(); - cells.select("title").text(function(d) { - return d.value; - }); }); } // Configuration Getters & Setters @@ -1481,12 +1478,12 @@ d3.ez.component.punchCard = function module() { }); spots.enter().append("circle").attr("class", "punchSpot").attr("cx", function(d) { return cellWidth / 2 + xScale(d.key); - }).attr("cy", 0).attr("r", function(d) { - return sizeScale(d["value"]); - }).attr("width", cellWidth).attr("height", cellHeight).on("click", dispatch.customClick).on("mouseover", function(d) { + }).attr("cy", 0).attr("r", 0).attr("width", cellWidth).attr("height", cellHeight).on("click", dispatch.customClick).on("mouseover", function(d) { dispatch.call("customMouseOver", this, d); - }).merge(spots).transition().duration(1e3).attr("fill", function(d) { + }).merge(spots).transition().duration(transition.duration).attr("fill", function(d) { return colorScale(d.value); + }).attr("r", function(d) { + return sizeScale(d["value"]); }); spots.exit().remove(); }); @@ -2640,7 +2637,6 @@ d3.ez.chart.tabularHeat = function module() { minValue = slicedData.minValue; categoryNames = slicedData.categoryNames; groupNames = slicedData.groupNames; - console.log(groupNames); // If thresholds values are not already set // attempt to auto-calculate some thresholds. if (!thresholds) { @@ -2653,8 +2649,8 @@ d3.ez.chart.tabularHeat = function module() { colorScale = d3.scaleThreshold().domain(thresholds).range(colors); } // X & Y Scales - xScale = d3.scaleBand().domain(categoryNames).range([ 0, chartW ]).padding(.05); - yScale = d3.scaleBand().domain(groupNames).range([ 0, chartH ]).padding(.05); + xScale = d3.scaleBand().domain(categoryNames).range([ 0, chartW ]).padding(.1); + yScale = d3.scaleBand().domain(groupNames).range([ 0, chartH ]).padding(.1); // X & Y Axis xAxis = d3.axisTop(xScale); yAxis = d3.axisLeft(yScale); @@ -2933,8 +2929,8 @@ d3.ez.chart.punchCard = function module() { colorScale = d3.scaleLinear().domain(valDomain).range(colors); } // X & Y Scales - xScale = d3.scaleBand().domain(categoryNames).rangeRound([ 0, chartW ]).padding(.05); - yScale = d3.scaleBand().domain(groupNames).rangeRound([ 0, chartH ]).padding(.05); + xScale = d3.scaleBand().domain(categoryNames).range([ 0, chartW ]).padding(.05); + yScale = d3.scaleBand().domain(groupNames).range([ 0, chartH ]).padding(.05); // X & Y Axis xAxis = d3.axisTop(xScale); yAxis = d3.axisLeft(yScale); diff --git a/build/d3-ez.min.js b/build/d3-ez.min.js index f7d15e0f..46f1c5cd 100644 --- a/build/d3-ez.min.js +++ b/build/d3-ez.min.js @@ -1 +1 @@ -d3.ez={version:"2.1.9",author:"James Saunders",copyright:"Copyright (C) 2017 James Saunders",license:"GPL-3.0"};d3.ez.component={description:"Reusable Components"};d3.ez.dataParse=function module(data){var levels=function(){if(data["key"]!=undefined){return 1}else{return 2}}();var groupName=function(){if(1==levels){var ret=d3.values(data)[0]}else{var ret=undefined}return ret}();var groupNames=function(){if(1==levels){ret=undefined}else{var ret=data.map(function(d){return d.key})}return ret}();var groupTotals=function(){if(1==levels){var ret=undefined}else{var ret={};d3.map(data).values().forEach(function(d,i){var groupName=d.key;d.values.forEach(function(d,i){var categoryValue=+d.value;ret[groupName]=typeof ret[groupName]==="undefined"?0:ret[groupName];ret[groupName]+=categoryValue})})}return ret}();var groupTotalsMax=function(){if(1==levels){var ret=undefined}else{var ret=d3.max(d3.values(groupTotals))}return ret}();var union=function(array1,array2){var ret=[];var arr=array1.concat(array2);var len=arr.length;var assoc={};while(len--){var item=arr[len];if(!assoc[item]){ret.unshift(item);assoc[item]=true}}return ret};var categoryNames=function(){var ret=[];if(1==levels){ret=d3.values(data)[1].map(function(d){return d.key})}else{d3.map(data).values().forEach(function(d,i){var tmp=[];var groupName=d.key;d.values.forEach(function(d,i){categoryName=d.key;tmp[i]=categoryName});ret=union(tmp,ret)})}return ret}();var categoryTotal=function(){if(1==levels){var ret=d3.sum(data.values,function(d){return d.value})}else{var ret=undefined}return ret}();var categoryTotals=function(){if(1==levels){var ret=undefined}else{var ret={};d3.map(data).values().forEach(function(d,i){var groupName=d.key;d.values.forEach(function(d,i){var categoryName=d.key;var categoryValue=+d.value;ret[categoryName]=typeof ret[categoryName]==="undefined"?0:ret[categoryName];ret[categoryName]+=categoryValue})})}return ret}();var categoryTotalsMax=function(){if(1==levels){var ret=undefined}else{var ret=d3.max(d3.values(categoryTotals))}return ret}();var minValue=function(){if(1==levels){var ret=d3.min(data.values,function(d){return d.value})}else{var ret=undefined;d3.map(data).values().forEach(function(d,i){d.values.forEach(function(d,i){ret=typeof ret==="undefined"?d.value:d3.min([ret,d.value])})})}return+ret}();var maxValue=function(){if(1==levels){var ret=d3.max(data.values,function(d){return d.value})}else{var ret=undefined;d3.map(data).values().forEach(function(d,i){d.values.forEach(function(d,i){ret=typeof ret==="undefined"?d.value:d3.max([ret,d.value])})})}return+ret}();var decimalPlaces=function(num){var match=(""+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);if(!match){return 0}ret=Math.max(0,(match[1]?match[1].length:0)-(match[2]?+match[2]:0));return ret};var maxDecimalPlace=function(){if(1==levels){var ret=undefined}else{var ret=0;d3.map(data).values().forEach(function(d){d.values.forEach(function(d){ret=d3.max([ret,decimalPlaces(d.value)])})})}return ret}();var thresholds=function(){var distance=maxValue-minValue;var ret=[(minValue+.15*distance).toFixed(maxDecimalPlace),(minValue+.4*distance).toFixed(maxDecimalPlace),(minValue+.55*distance).toFixed(maxDecimalPlace),(minValue+.9*distance).toFixed(maxDecimalPlace)];return ret}();var my={levels:levels,groupName:groupName,groupNames:groupNames,groupTotals:groupTotals,groupTotalsMax:groupTotalsMax,categoryNames:categoryNames,categoryTotal:categoryTotal,categoryTotals:categoryTotals,categoryTotalsMax:categoryTotalsMax,minValue:minValue,maxValue:maxValue,maxDecimalPlace:maxDecimalPlace,thresholds:thresholds};return my};d3.ez.chart=function module(){var svg;var canvas;var width=600;var height=400;var margin={top:15,right:15,bottom:15,left:15};var canvasW=580;var canvasH=380;var chartTop=0;var classed="d3ez";var chart=undefined;var legend=undefined;var title=undefined;var creditTag=d3.ez.component.creditTag();var description="";var yAxisLabel="";var colorScale=undefined;var dispatch=d3.dispatch("customMouseOver","customMouseOut","customClick");function init(data){canvasW=width-(margin.left+margin.right);canvasH=height-(margin.top+margin.bottom);chart.dispatch(dispatch).width(canvasW).height(canvasH);if(legend){legend.width(150).height(200);chart.width(chart.width()-legend.width())}if(title){chartTop=title.height();chart.height(chart.height()-title.height())}creditTag.text("d3-ez.net").href("http://d3-ez.net")}function my(selection){selection.each(function(data){init(data);if(!svg){svg=d3.select(this).append("svg").classed(classed,true).attr("width",width).attr("height",height);canvas=svg.append("g").classed("canvas",true);canvas.append("g").classed("chartbox",true);canvas.append("g").classed("legendbox",true);canvas.append("g").classed("titlebox",true);canvas.append("g").classed("creditbox",true)}else{canvas=svg.select(".canvas")}canvas.attr("transform","translate("+margin.left+","+margin.top+")").attr("width",canvasW).attr("height",canvasH);canvas.select(".chartbox").datum(data).attr("transform","translate("+0+","+chartTop+")").call(chart);if(legend&&(typeof chart.colorScale==="function"||typeof chart.sizeScale==="function")){if(typeof chart.colorScale==="function"){legend.colorScale(chart.colorScale())}if(typeof chart.sizeScale==="function"){legend.sizeScale(chart.sizeScale())}canvas.select(".legendbox").attr("transform","translate("+(canvasW-legend.width())+","+title.height()+")").call(legend)}if(title){canvas.select(".titlebox").attr("transform","translate("+width/2+","+0+")").call(title)}canvas.select(".creditbox").attr("transform","translate("+(width-20)+","+(height-20)+")").call(creditTag)})}my.width=function(_){if(!arguments.length)return width;width=_;return this};my.height=function(_){if(!arguments.length)return height;height=_;return this};my.chart=function(_){if(!arguments.length)return chart;chart=_;return this};my.legend=function(_){if(!arguments.length)return legend;legend=_;return this};my.title=function(_){if(!arguments.length)return title;if(typeof _==="string"){title=d3.ez.title().mainText(_).subText("")}else{title=_}return this};my.yAxisLabel=function(_){if(!arguments.length)return yAxisLabel;yAxisLabel=_;return this};my.on=function(){var value=dispatch.on.apply(dispatch,arguments);return value===dispatch?my:value};return my};d3.ez.colors={categorical:function(scheme){switch(scheme){case 1:return["#5da5da","#faa43a","#60bd68","#f17cb0","#b2912f","#b276b2","#decf3f","#f15854","#4d4d4d"];case 2:return["#fbb4ae","#b3cde3","#ccebc5","#decbe4","#fed9a6","#ffffcc","#e5d8bd","#fddaec","#f2f2f2"];case 3:return["#3f51b5","#ff9800","#8bc34a","#9c27b0","#ffeb3b","#03a9f4","#f44336","#009688","#795548"];case 4:return d3.ez.colors.lumShift(d3.ez.colors.lumShift(d3.ez.colors.categorical(3),-.8),5.5)}},diverging:function(scheme){switch(scheme){case 1:return["#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e"];case 2:return["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"];case 3:return["#0000ff","#8052fe","#b58bfb","#ddc5f7","#fffff0","#ffcfb4","#ff9e7a","#ff6842","#ff0000"]}},sequential:function(origHex,count){var lumStep=.1;var lumMax=lumStep*count/2;var lumMin=0-lumMax;var lumScale=d3.scale.linear().domain([1,count]).range([lumMin,lumMax]);var result=[];for(var i=1;i<=count;i++){lum=lumScale(i);origHex=String(origHex).replace(/[^0-9a-f]/gi,"");if(origHex.length<6){origHex=origHex[0]+origHex[0]+origHex[1]+origHex[1]+origHex[2]+origHex[2]}var newHex="#";var c;for(var j=0;j<3;j++){c=parseInt(origHex.substr(j*2,2),16);c=Math.round(Math.min(Math.max(0,c+c*lum),255)).toString(16);newHex+=("00"+c).substr(c.length)}result.push(newHex)}return result},lumShift:function(colors,lum){var result=[];colors.forEach(function addNumber(origHex,index){origHex=String(origHex).replace(/[^0-9a-f]/gi,"");if(origHex.length<6){origHex=origHex[0]+origHex[0]+origHex[1]+origHex[1]+origHex[2]+origHex[2]}lum=lum||0;var newHex="#",c,i;for(i=0;i<3;i++){c=parseInt(origHex.substr(i*2,2),16);c=Math.round(Math.min(Math.max(0,c+c*lum),255)).toString(16);newHex+=("00"+c).substr(c.length)}result[index]=newHex});return result}};d3.ez.component.barGrouped=function module(){var height=100;var width=300;var colorScale=undefined;var xScale=undefined;var yScale=undefined;var transition={ease:d3.easeBounce,duration:500};var dispatch=d3.dispatch("customMouseOver","customMouseOut","customClick");function my(selection){selection.each(function(data){var series=selection.selectAll(".series").data(function(d){return[d]}).enter().append("g").classed("series",true).on("click",function(d){dispatch.call("customClick",this,d)});series=selection.selectAll(".series").merge(series);var bars=series.selectAll(".bar").data(function(d){return d.values});bars.enter().append("rect").classed("bar",true).attr("fill",function(d){return colorScale(d.key)}).attr("width",xScale.bandwidth()).attr("x",function(d){return xScale(d.key)}).attr("y",height).attr("rx",0).attr("ry",0).attr("height",0).on("mouseover",function(d){dispatch.call("customMouseOver",this,d)}).merge(bars).transition().ease(transition.ease).duration(transition.duration).attr("x",function(d){return xScale(d.key)}).attr("y",function(d){return yScale(d.value)}).attr("height",function(d){return height-yScale(d.value)});bars.exit().transition().style("opacity",0).remove()})}my.height=function(_){if(!arguments.length)return height;height=_;return this};my.width=function(_){if(!arguments.length)return width;width=_;return this};my.colorScale=function(_){if(!arguments.length)return colorScale;colorScale=_;return my};my.xScale=function(_){if(!arguments.length)return xScale;xScale=_;return my};my.yScale=function(_){if(!arguments.length)return yScale;yScale=_;return my};my.dispatch=function(_){if(!arguments.length)return dispatch();dispatch=_;return this};my.on=function(){var value=dispatch.on.apply(dispatch,arguments);return value===dispatch?my:value};return my};d3.ez.component.barStacked=function module(){var height=100;var width=50;var colorScale=undefined;var xScale=undefined;var yScale=undefined;var transition={ease:d3.easeBounce,duration:500};var dispatch=d3.dispatch("customMouseOver","customMouseOut","customClick");function my(selection){selection.each(function(data){selection.selectAll(".series").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});data={key:data.key,values:series};return[data]}).enter().append("g").classed("series",true).attr("width",width).attr("height",height).on("click",function(d){dispatch.call("customClick",this,d)});var series=selection.selectAll(".series");var bars=series.selectAll(".bar").data(function(d){return d.values});bars.enter().append("rect").classed("bar",true).attr("width",width).attr("x",0).attr("y",height).attr("rx",0).attr("ry",0).attr("height",0).attr("fill",function(d){return colorScale(d.name)}).on("mouseover",function(d){dispatch.call("customMouseOver",this,d)}).merge(bars).transition().ease(transition.ease).duration(transition.duration).attr("width",width).attr("x",0).attr("y",function(d){return yScale(d.y1)}).attr("height",function(d){return yScale(d.y0)-yScale(d.y1)});bars.exit().transition().style("opacity",0).remove()})}my.height=function(_){if(!arguments.length)return height;height=_;return this};my.width=function(_){if(!arguments.length)return width;width=_;return this};my.colorScale=function(_){if(!arguments.length)return colorScale;colorScale=_;return my};my.xScale=function(_){if(!arguments.length)return xScale;xScale=_;return my};my.yScale=function(_){if(!arguments.length)return yScale;yScale=_;return my};my.dispatch=function(_){if(!arguments.length)return dispatch();dispatch=_;return this};my.on=function(){var value=dispatch.on.apply(dispatch,arguments);return value===dispatch?my:value};return my};d3.ez.component.barRadial=function module(){var width=400;var height=300;var colorScale=undefined;var yScale=undefined;var transition={ease:d3.easeBounce,duration:500};var dispatch=d3.dispatch("customMouseOver","customMouseOut","customClick");var radius=undefined;var capitalizeLabels=false;var colorLabels=false;function my(selection){selection.each(function(data){var defaultRadius=Math.min(width,height)/2;radius=typeof radius==="undefined"?defaultRadius:radius;var yDomain=yScale.domain();var barScale=d3.scaleLinear().domain(yDomain).range([0,radius]);var pie=d3.pie().value(function(d){return 1}).sort(null).padAngle(0);var arc=d3.arc().outerRadius(function(d){return barScale(d.data.value)}).innerRadius(0).cornerRadius(2);var series=selection.selectAll(".series").data(function(d){return[d]}).enter().append("g").classed("series",true).on("click",function(d){dispatch.call("customClick",this,d)});series=selection.selectAll(".series").merge(series);var segments=series.selectAll(".segment").data(function(d){return pie(d.values)});segments.enter().append("path").classed("segment",true).style("fill",function(d){return colorScale(d.data.key)}).on("mouseover",function(d){dispatch.call("customMouseOver",this,d.data)}).merge(segments).transition().ease(transition.ease).duration(transition.duration).attr("d",arc);segments.exit().transition().style("opacity",0).remove()})}my.height=function(_){if(!arguments.length)return height;height=_;return this};my.width=function(_){if(!arguments.length)return width;width=_;return this};my.radius=function(_){if(!arguments.length)return radius;radius=_;return this};my.colorScale=function(_){if(!arguments.length)return colorScale;colorScale=_;return my};my.yScale=function(_){if(!arguments.length)return yScale;yScale=_;return my};my.dispatch=function(_){if(!arguments.length)return dispatch();dispatch=_;return this};my.on=function(){var value=dispatch.on.apply(dispatch,arguments);return value===dispatch?my:value};return my};d3.ez.component.donut=function module(){var height=100;var width=300;var colorScale=undefined;var transition={ease:d3.easeBounce,duration:500};var dispatch=d3.dispatch("customMouseOver","customMouseOut","customClick");var radius=undefined;var innerRadius=undefined;function my(selection){selection.each(function(data){var defaultRadius=Math.min(width,height)/2;radius=typeof radius==="undefined"?defaultRadius:radius;innerRadius=typeof innerRadius==="undefined"?defaultRadius/2:innerRadius;var pie=d3.pie().value(function(d){return d.value}).sort(null).padAngle(.015);var arc=d3.arc().innerRadius(innerRadius).outerRadius(radius).cornerRadius(2);var outerArc=d3.arc().innerRadius(radius*.9).outerRadius(radius*.9);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}var series=selection.selectAll(".series").data(function(d){return[d]}).enter().append("g").classed("series",true).on("click",function(d){dispatch.call("customClick",this,d)});series.append("g").attr("class","slices");series.append("g").attr("class","labels");series.append("g").attr("class","lines");series=selection.selectAll(".series").merge(series);var slices=series.select(".slices").selectAll("path.slice").data(function(d){return pie(d.values)});slices.enter().append("path").attr("class","slice").attr("fill",function(d){return colorScale(d.data.key)}).attr("d",arc).on("mouseover",function(d){dispatch.call("customMouseOver",this,d)}).merge(slices).transition().duration(transition.duration).ease(transition.ease).attrTween("d",arcTween);slices.exit().remove();var labels=series.select(".labels").selectAll("text.label").data(function(d){return pie(d.values)});labels.enter().append("text").attr("class","label").attr("dy",".35em").merge(labels).transition().duration(transition.duration).text(function(d,i){return d.data.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) "+min:min+" - "+max;return rangeStr;break}var rangeIncrement=domainSize/rangeLength;var ranges=[];var range=[];var rangeStart=domainMin;var rangeEnd=domainMin+rangeIncrement;for(i=0;i "+min:min+" - "+max;return rangeStr;break}var rangeIncrement=domainSize/rangeLength;var ranges=[];var range=[];var rangeStart=domainMin;var rangeEnd=domainMin+rangeIncrement;for(i=0;i