Skip to content

Commit

Permalink
add jshint and clean code to conform to it
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Preusse committed Jul 8, 2014
1 parent ea1ade1 commit c996781
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
22 changes: 22 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"globals": {
"d3": false
}
}
36 changes: 18 additions & 18 deletions src/radar-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var RadarChart = {
radius: 5,
w: 600,
h: 600,
factor: .95,
factor: 0.95,
factorLegend: 1,
levels: 3,
maxValue: 0,
Expand All @@ -17,8 +17,10 @@ var RadarChart = {
cfg[option.key] = option.value;
});

cfg.maxValue = Math.max(cfg.maxValue, d3.max(d, function(i){return d3.max(i.map(function(o){return o.value;}))}));
var allAxis = (d[0].map(function(i, j){return i.axis}));
cfg.maxValue = Math.max(cfg.maxValue, d3.max(d, function(i){
return d3.max(i.map(function(o){return o.value;}));
}));
var allAxis = (d[0].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(id).select("svg").remove();
Expand All @@ -36,18 +38,16 @@ var RadarChart = {
return getPosition(i, range, factor, Math.cos);
}

for(var j=0; j<cfg.levels; j++){
var levelFactor = radius*((j+1)/cfg.levels);
// ToDo: refactor, this query relies on no element being found
// should be switched to an proper selectAll() && data()
g.selectAll(".level404").data(allAxis).enter().append("svg:line")
.attr("x1", function(d, i){return getHorizontalPosition(i, levelFactor);})
.attr("y1", function(d, i){return getVerticalPosition(i, levelFactor);})
.attr("x2", function(d, i){return getHorizontalPosition(i+1, levelFactor);})
.attr("y2", function(d, i){return getVerticalPosition(i+1, levelFactor);})
.attr("class", "level").attr("transform", "translate(" + (cfg.w/2-levelFactor) + ", " + (cfg.h/2-levelFactor) + ")");
d3.range(0, cfg.levels).forEach(function(level) {
var levelFactor = radius * ((level + 1) / cfg.levels);

}
g.selectAll(".level404").data(allAxis).enter().append("svg:line")
.attr("x1", function(d, i){return getHorizontalPosition(i, levelFactor);})
.attr("y1", function(d, i){return getVerticalPosition(i, levelFactor);})
.attr("x2", function(d, i){return getHorizontalPosition(i+1, levelFactor);})
.attr("y2", function(d, i){return getVerticalPosition(i+1, levelFactor);})
.attr("class", "level").attr("transform", "translate(" + (cfg.w/2-levelFactor) + ", " + (cfg.h/2-levelFactor) + ")");
});

series = 0;

Expand Down Expand Up @@ -100,7 +100,7 @@ var RadarChart = {
}
return str;
})
.style("fill", function(j, i){return cfg.color(series)})
.style("fill", function(j, i) { return cfg.color(series); })
.on('mouseover', function (d){
g.classed('focus', 1);
d3.select(this).classed('focused', 1);
Expand All @@ -119,7 +119,7 @@ var RadarChart = {
.data(y).enter()
.append("svg:circle").attr("class", "radar-chart-serie"+series)
.attr('r', cfg.radius)
.attr("alt", function(j){return Math.max(j.value, 0)})
.attr("alt", function(j){ return Math.max(j.value, 0); })
.attr("cx", function(j, i){
dataValues.push([
getHorizontalPosition(i, cfg.w/2, (parseFloat(Math.max(j.value, 0))/cfg.maxValue)*cfg.factor),
Expand All @@ -130,7 +130,7 @@ var RadarChart = {
.attr("cy", function(j, i){
return getVerticalPosition(i, cfg.h/2, (Math.max(j.value, 0)/cfg.maxValue)*cfg.factor);
})
.attr("data-id", function(j){return j.axis})
.attr("data-id", function(j){ return j.axis; })
.style("fill", cfg.color(series))
.on('mouseover', function (d){
newX = parseFloat(d3.select(this).attr('cx')) - 10;
Expand All @@ -149,7 +149,7 @@ var RadarChart = {
d3.select(z).classed('focused', 0);
})
.append("svg:title")
.text(function(j){return Math.max(j.value, 0)});
.text(function(j){ return Math.max(j.value, 0); });

series++;
});
Expand Down

0 comments on commit c996781

Please sign in to comment.