//Options for the Radar chart, other than default var cfg = { w: 675, h: 675, maxValue: 10, levels: 10, opacityArea: 0.20, radius:5, radians: 2 * Math.PI, factor:1, factorLegend: 0.85, ToRight: 5, TranslateX: 100, TranslateY:60, ExtraWidthX: 700, ExtraWidthY: 200, duration:200 }; //Will need this for the drag update, not sure how to pass it back and forth var maxAxisValues = []; function init(){ cfg.maxValue = Math.max(cfg.maxValue, d3.max(d, function(i){return d3.max(i.skills.map(function(o){return o.value;}));})); var allAxis = (d[0].skills.map(function(i, j){return i.axis;})); var total = allAxis.length; var radius = cfg.factor*Math.min(cfg.w/2, cfg.h/2); d3.select("#chart").select("svg").remove(); var g = d3.select("#chart") .append("svg") .attr("width", cfg.w+cfg.ExtraWidthX) .attr("height", cfg.h+cfg.ExtraWidthY) .append("g") .attr("transform", "translate(" + cfg.TranslateX + "," + cfg.TranslateY + ")") .attr("id","chartArea"); for(var j=0; j Math.abs(maxY)) { newY = maxY; } newValue = ((newY/oldY) * oldData.value).toFixed(2); } else { var slope = oldY / oldX; newX = d3.event.dx + parseFloat(dragTarget.attr("cx")) - cfg.w/2; if(Math.abs(newX) > Math.abs(maxX)) { newX = maxX; } newY = newX * slope; var ratio = newX / oldX; newValue = (ratio * oldData.value).toFixed(2); } //Bound the drag behavior to the max and min of the axis, not by pixels but by value calc (easier) if(newValue >=1 && newValue<= cfg.levels){ dragTarget .attr("cx", function(){return newX + cfg.w/2 ;}) .attr("cy", function(){return cfg.h/2 - newY;}); //Updating the data set with the new value (dragTarget.data()[0]).value = newValue; //center display for value d3.select(".updatevalue.skill").text((dragTarget.data()[0]).axis) .style("display","block") .style("font-size","12px") .style("text-align","center") .style("margin","20px 0 5px 0"); d3.select(".updatevalue.value").text(newValue) .style("display","block") .style("text-align","center") .style("visibility","visible"); //reCalculatePoints(); //drawPoly();' updatePoly(); } //Release the drag listener on the node if you hit the min/max values //https://github.com/mbostock/d3/wiki/Drag-Behavior else{ if(newValue <=0){newValue =0;} else if(newValue >=cfg.levels){newValue = cfg.levels;} dragTarget.on("drag",null); } } function updatePoly(){ d.forEach(function(y, x){ dataValues = []; g.selectAll(".nodes") .data(y.skills, function(j, i){ dataValues.push([ cfg.w/2*(1-(parseFloat(Math.max(j.value, 0))/cfg.maxValue)*cfg.factor*Math.sin(i*cfg.radians/total)), cfg.h/2*(1-(parseFloat(Math.max(j.value, 0))/cfg.maxValue)*cfg.factor*Math.cos(i*cfg.radians/total)) ]); }); dataValues = [dataValues]; g.selectAll("#radar-chart-area-Data-Set") .data(dataValues) .attr("points",function(d) { console.log(d); var str=""; for(var pti=0;pti