From c0d312bebe8ba68b842788e4715c5c8a1612bb29 Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Thu, 7 Mar 2013 20:47:04 +0900 Subject: [PATCH] Refactor: Removing a if statement, because the nil value is already removed in the view template. --- app/assets/javascripts/branch-graph.js | 96 +++++++++++++------------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/app/assets/javascripts/branch-graph.js b/app/assets/javascripts/branch-graph.js index 520336ad..525b1795 100644 --- a/app/assets/javascripts/branch-graph.js +++ b/app/assets/javascripts/branch-graph.js @@ -118,58 +118,56 @@ for (var j = 0, jj = this.commits[i].parents.length; j < jj; j++) { c = this.preparedCommits[this.commits[i].parents[j][0]]; ps = this.commits[i].parents[j][1]; - if (c) { - var cx = offsetX + 20 * c.time - , cy = offsetY + 10 * c.space - , psy = offsetY + 10 * ps; - if (c.space == this.commits[i].space && c.space == ps) { - r.path([ - "M", x, y, - "L", cx, cy - ]).attr({ - stroke: this.colors[c.space], - "stroke-width": 2 - }); + var cx = offsetX + 20 * c.time + , cy = offsetY + 10 * c.space + , psy = offsetY + 10 * ps; + if (c.space == this.commits[i].space && c.space == ps) { + r.path([ + "M", x, y, + "L", cx, cy + ]).attr({ + stroke: this.colors[c.space], + "stroke-width": 2 + }); - } else if (c.space < this.commits[i].space) { - if (y == psy) { - r.path([ - "M", x - 5, y, - "l-5,-2,0,4,5,-2", - "L", x - 10, y, - "L", x - 15, psy, - "L", cx + 5, psy, - "L", cx, cy]) - .attr({ - stroke: this.colors[this.commits[i].space], - "stroke-width": 2 - }); - } else { - r.path([ - "M", x - 3, y - 6, - "l-4,-3,4,-2,0,5", - "L", x - 5, y - 10, - "L", x - 10, psy, - "L", cx + 5, psy, - "L", cx, cy]) - .attr({ - stroke: this.colors[this.commits[i].space], - "stroke-width": 2 - }); - } + } else if (c.space < this.commits[i].space) { + if (y == psy) { + r.path([ + "M", x - 5, y, + "l-5,-2,0,4,5,-2", + "L", x - 10, y, + "L", x - 15, psy, + "L", cx + 5, psy, + "L", cx, cy]) + .attr({ + stroke: this.colors[this.commits[i].space], + "stroke-width": 2 + }); } else { - r.path([ - "M", x - 3, y + 6, - "l-4,3,4,2,0,-5", - "L", x - 5, y + 10, - "L", x - 10, psy, - "L", cx + 5, psy, - "L", cx, cy]) - .attr({ - stroke: this.colors[c.space], - "stroke-width": 2 - }); + r.path([ + "M", x - 3, y - 6, + "l-4,-3,4,-2,0,5", + "L", x - 5, y - 10, + "L", x - 10, psy, + "L", cx + 5, psy, + "L", cx, cy]) + .attr({ + stroke: this.colors[this.commits[i].space], + "stroke-width": 2 + }); } + } else { + r.path([ + "M", x - 3, y + 6, + "l-4,3,4,2,0,-5", + "L", x - 5, y + 10, + "L", x - 10, psy, + "L", cx + 5, psy, + "L", cx, cy]) + .attr({ + stroke: this.colors[c.space], + "stroke-width": 2 + }); } }