Path: blob/master/webroot/rsrc/js/application/diffusion/behavior-commit-graph.js
12241 views
/**1* @provides javelin-behavior-diffusion-commit-graph2* @requires javelin-behavior3* javelin-dom4* javelin-stratcom5*/67JX.behavior('diffusion-commit-graph', function(config) {89var nodes = JX.DOM.scry(document.body, 'div', 'commit-graph');10var cxt;1112// Pick the color for column 'c'.13function color(c) {14var colors = [15'#cc0000',16'#cc0099',17'#6600cc',18'#0033cc',19'#00cccc',20'#00cc33',21'#66cc00',22'#cc9900'23];24return colors[c % colors.length];25}2627// Stroke a line (for lines between commits).28function lstroke(c) {29cxt.lineWidth = 3;30cxt.strokeStyle = '#ffffff';31cxt.stroke();32cxt.lineWidth = 1;33cxt.strokeStyle = color(c);34cxt.stroke();35}3637// Stroke with fill (for commit circles).38function fstroke(c) {39cxt.lineWidth = 1;40cxt.fillStyle = color(c);41cxt.strokeStyle = '#ffffff';42cxt.fill();43cxt.stroke();44}4546// If the graph is going to be wide, squish it a bit so it doesn't take up47// quite as much space.48var default_width;49if (config.count >= 8) {50default_width = 6;51} else {52default_width = 12;53}5455for (var ii = 0; ii < nodes.length; ii++) {56var data = JX.Stratcom.getData(nodes[ii]);5758var cell = default_width;59var xpos = function(col) {60return (col * cell) + (cell / 2);61};6263var h;64if (config.height) {65h = config.height;66} else {67h = JX.Vector.getDim(nodes[ii].parentNode).y;68}6970var w = cell * config.count;7172var canvas = JX.$N('canvas', {width: w, height: h});73cxt = canvas.getContext('2d');7475cxt.lineWidth = 3;76// This gives us sharper lines, since lines drawn on an integer (like 5)77// are drawn from 4.5 to 5.5.78cxt.translate(0.5, 0.5);7980cxt.strokeStyle = '#ffffff';81cxt.fillStyle = '#ffffff';8283// First, figure out which column this commit appears in. It is marked by84// "o" (if it has a commit after it) or "^" (if no other commit has it as85// a parent). We use this to figure out where to draw the join/split lines.8687var origin = null;88var jj;89var x;90var c;91for (jj = 0; jj < data.line.length; jj++) {92c = data.line.charAt(jj);93switch (c) {94case 'o':95case 'x':96case '^':97origin = xpos(jj);98break;99}100}101102// Draw all the join lines. These start at some column at the top of the103// canvas and join the commit's column. They indicate branching.104105for (jj = 0; jj < data.join.length; jj++) {106var join = data.join[jj];107x = xpos(join);108109cxt.beginPath();110cxt.moveTo(x, 0);111cxt.bezierCurveTo(x, h/4, origin, h/4, origin, h/2);112lstroke(join);113}114115// Draw all the split lines. These start at the commit and end at some116// column on the bottom of the canvas. They indicate merging.117118for (jj = 0; jj < data.split.length; jj++) {119var split = data.split[jj];120x = xpos(split);121cxt.beginPath();122cxt.moveTo(origin, h/2);123cxt.bezierCurveTo(origin, 3*h/4, x, 3*h/4, x, h);124lstroke(split);125}126127// Draw the vertical lines (a branch with no activity at this commit) and128// the commit circles.129130for (jj = 0; jj < data.line.length; jj++) {131c = data.line.charAt(jj);132switch (c) {133case 'o':134case '^':135case '|':136case 'x':137case 'X':138139if (c !== 'X') {140cxt.beginPath();141cxt.moveTo(xpos(jj), (c == '^' ? h/2 : 0));142cxt.lineTo(xpos(jj), (c == 'x' ? h/2 : h));143lstroke(jj);144}145146if (c == 'o' || c == '^' || c == 'x' || c == 'X') {147cxt.beginPath();148cxt.arc(xpos(jj), h/2, 3, 0, 2 * Math.PI, true);149fstroke(jj);150}151break;152}153}154155JX.DOM.replace(nodes[ii], canvas);156}157158159});160161162