Skip to content

Commit

Permalink
Fixed codacy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
andrefreitas committed Jun 17, 2015
1 parent bebae73 commit 70aa459
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 119 deletions.
231 changes: 115 additions & 116 deletions schwa/web/static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,74 @@ var arc = d3.svg.arc()
.outerRadius(function(d) { return Math.sqrt(d.y + d.dy); });


// Given a node in a partition layout, return an array of all of its ancestor
// nodes, highest first, but excluding the root.
function getAncestors(node) {
var path = [];
var current = node;
while (current.parent) {
path.unshift(current);
current = current.parent;
}
return path;
}

// Update the breadcrumb trail to show the current sequence and percentage.
function updateBreadcrumbs(nodeArray, percentageString) {

// Main function to draw and set up the visualization, once we have the data.
function createVisualization(json) {
// Data join; key function combines name and depth (= position in sequence).
var g = d3.select("#trail")
.selectAll("g")
.data(nodeArray, function(d) { return d.name + d.depth; });

// Basic setup of page elements.
initializeBreadcrumbTrail();
drawLegend();
d3.select("#togglelegend").on("click", toggleLegend);
// Add breadcrumb and label for entering nodes.
var entering = g.enter().append("svg:g");

// Bounding circle underneath the sunburst, to make it easier to detect
// when the mouse leaves the parent g.
vis.append("svg:circle")
.attr("r", radius)
.style("opacity", 0);
entering.append("svg:polygon")
.attr("points", breadcrumbPoints)
.style("fill", function(d) { return colors[d.type]; });

// For efficiency, filter nodes to keep only those large enough to see.
var nodes = partition.nodes(json)
.filter(function(d) {
return (d.dx > 0.005); // 0.005 radians = 0.29 degrees
});

var path = vis.data([json]).selectAll("path")
.data(nodes)
.enter().append("svg:path")
.attr("display", function(d) { return d.depth ? null : "none"; })
.attr("d", arc)
.attr("fill-rule", "evenodd")
.style("fill", function(d) { return colors[d.type]; })
.style("opacity", 1)
.on("mouseover", mouseover);
entering.append("svg:text")
.attr("x", (b.w + b.t) / 2)
.attr("y", b.h / 2)
.attr("dy", "0.35em")
.attr("text-anchor", "middle")
.text(function(d) { return d.name; });

// Add the mouseleave handler to the bounding circle.
d3.select("#container").on("mouseleave", mouseleave);
// Set position for entering and updating nodes.
g.attr("transform", function(d, i) {
return "translate(" + i * (b.w + b.s) + ", 0)";
});

// Get total size of the tree = value of root node from partition.
totalSize = path.node().__data__.value;
};
// Remove exiting nodes.
g.exit().remove();

// Now move and update the percentage at the end.
d3.select("#trail").select("#endlabel")
.attr("x", (nodeArray.length + 0.5) * (b.w + b.s))
.attr("y", b.h / 2)
.attr("dy", "0.35em")
.attr("text-anchor", "middle")
.text(percentageString);

// Make the breadcrumb trail visible, if it's hidden.
d3.select("#trail")
.style("visibility", "");

}

function format_metric(number, metric){
if (number !== 1){
if (metric === "fix"){
metric = "fixes";
} else {
metric = metric + "s";
}
}

return number + " " + metric;
}

// Fade all but the current sequence, and show it in the breadcrumb trail.
function mouseover(d) {
Expand All @@ -90,7 +120,7 @@ function mouseover(d) {


d3.select(".path").style("visibility", "");
if(d.type =="file"){
if(d.type === "file"){
d3.select("#path").text(d.path);
}

Expand Down Expand Up @@ -140,18 +170,6 @@ function mouseleave(d) {
.style("visibility", "hidden");
}

// Given a node in a partition layout, return an array of all of its ancestor
// nodes, highest first, but excluding the root.
function getAncestors(node) {
var path = [];
var current = node;
while (current.parent) {
path.unshift(current);
current = current.parent;
}
return path;
}

function initializeBreadcrumbTrail() {
// Add the svg area.
var trail = d3.select("#sequence").append("svg:svg")
Expand All @@ -164,65 +182,6 @@ function initializeBreadcrumbTrail() {
.style("fill", "#000");
}

// Generate a string that describes the points of a breadcrumb polygon.
function breadcrumbPoints(d, i) {
var points = [];
points.push("0,0");
points.push(b.w + ",0");
points.push(b.w + b.t + "," + (b.h / 2));
points.push(b.w + "," + b.h);
points.push("0," + b.h);
if (i > 0) { // Leftmost breadcrumb; don't include 6th vertex.
points.push(b.t + "," + (b.h / 2));
}
return points.join(" ");
}

// Update the breadcrumb trail to show the current sequence and percentage.
function updateBreadcrumbs(nodeArray, percentageString) {

// Data join; key function combines name and depth (= position in sequence).
var g = d3.select("#trail")
.selectAll("g")
.data(nodeArray, function(d) { return d.name + d.depth; });

// Add breadcrumb and label for entering nodes.
var entering = g.enter().append("svg:g");

entering.append("svg:polygon")
.attr("points", breadcrumbPoints)
.style("fill", function(d) { return colors[d.type]; });


entering.append("svg:text")
.attr("x", (b.w + b.t) / 2)
.attr("y", b.h / 2)
.attr("dy", "0.35em")
.attr("text-anchor", "middle")
.text(function(d) { return d.name; });

// Set position for entering and updating nodes.
g.attr("transform", function(d, i) {
return "translate(" + i * (b.w + b.s) + ", 0)";
});

// Remove exiting nodes.
g.exit().remove();

// Now move and update the percentage at the end.
d3.select("#trail").select("#endlabel")
.attr("x", (nodeArray.length + 0.5) * (b.w + b.s))
.attr("y", b.h / 2)
.attr("dy", "0.35em")
.attr("text-anchor", "middle")
.text(percentageString);

// Make the breadcrumb trail visible, if it's hidden.
d3.select("#trail")
.style("visibility", "");

}

function drawLegend() {

// Dimensions of legend item: width, height, spacing, radius of rounded rect.
Expand Down Expand Up @@ -258,35 +217,75 @@ function drawLegend() {

function toggleLegend() {
var legend = d3.select("#legend");
if (legend.style("visibility") == "hidden") {
if (legend.style("visibility") === "hidden") {
legend.style("visibility", "");
} else {
legend.style("visibility", "hidden");
}
}

// Main function to draw and set up the visualization, once we have the data.
function createVisualization(json) {

// Basic setup of page elements.
initializeBreadcrumbTrail();
drawLegend();
d3.select("#togglelegend").on("click", toggleLegend);

// Bounding circle underneath the sunburst, to make it easier to detect
// when the mouse leaves the parent g.
vis.append("svg:circle")
.attr("r", radius)
.style("opacity", 0);

// For efficiency, filter nodes to keep only those large enough to see.
var nodes = partition.nodes(json)
.filter(function(d) {
return (d.dx > 0.005); // 0.005 radians = 0.29 degrees
});

var path = vis.data([json]).selectAll("path")
.data(nodes)
.enter().append("svg:path")
.attr("display", function(d) { return d.depth ? null : "none"; })
.attr("d", arc)
.attr("fill-rule", "evenodd")
.style("fill", function(d) { return colors[d.type]; })
.style("opacity", 1)
.on("mouseover", mouseover);

// Add the mouseleave handler to the bounding circle.
d3.select("#container").on("mouseleave", mouseleave);

// Get total size of the tree = value of root node from partition.
totalSize = path.node().__data__.value;
};

// Generate a string that describes the points of a breadcrumb polygon.
function breadcrumbPoints(d, i) {
var points = [];
points.push("0,0");
points.push(b.w + ",0");
points.push(b.w + b.t + "," + (b.h / 2));
points.push(b.w + "," + b.h);
points.push("0," + b.h);
if (i > 0) { // Leftmost breadcrumb; don't include 6th vertex.
points.push(b.t + "," + (b.h / 2));
}
return points.join(" ");
}




d3.json("analytics", function(error, root) {
console.log(root);
createVisualization(root);
});


function strip_path(path){
var pat = /[^/]*\.java/;
var re = new RegExp(pat);
var res = re.exec(path);
return res[0];
}

function format_metric(number, metric){
if (number != 1){
if (metric == "fix"){
metric = "fixes";
} else {
metric = metric + "s";
}
}

return number + " " + metric;
}
6 changes: 4 additions & 2 deletions schwa/web/static/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions schwa/web/static/styles.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion schwa/web/static/styles.sass
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ body

text
font-weight: 600
fill: #fff
fill: white

#chart
position: relative
Expand Down

0 comments on commit 70aa459

Please sign in to comment.