2012-03-24 01:11:15 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-diffusion-commit-graph
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-dom
|
|
|
|
* javelin-stratcom
|
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('diffusion-commit-graph', function(config) {
|
|
|
|
|
|
|
|
var nodes = JX.DOM.scry(document.body, 'div', 'commit-graph');
|
|
|
|
var cxt;
|
|
|
|
|
|
|
|
// Pick the color for column 'c'.
|
|
|
|
function color(c) {
|
|
|
|
var colors = [
|
|
|
|
'#cc0000',
|
|
|
|
'#cc0099',
|
|
|
|
'#6600cc',
|
|
|
|
'#0033cc',
|
|
|
|
'#00cccc',
|
|
|
|
'#00cc33',
|
|
|
|
'#66cc00',
|
2013-05-19 02:04:22 +02:00
|
|
|
'#cc9900'
|
2012-03-24 01:11:15 +01:00
|
|
|
];
|
|
|
|
return colors[c % colors.length];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stroke a line (for lines between commits).
|
|
|
|
function lstroke(c) {
|
|
|
|
cxt.lineWidth = 3;
|
|
|
|
cxt.strokeStyle = '#ffffff';
|
|
|
|
cxt.stroke();
|
|
|
|
cxt.lineWidth = 1;
|
|
|
|
cxt.strokeStyle = color(c);
|
|
|
|
cxt.stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stroke with fill (for commit circles).
|
|
|
|
function fstroke(c) {
|
2016-01-08 20:41:49 +01:00
|
|
|
cxt.lineWidth = 1;
|
2012-03-24 01:11:15 +01:00
|
|
|
cxt.fillStyle = color(c);
|
|
|
|
cxt.strokeStyle = '#ffffff';
|
|
|
|
cxt.fill();
|
|
|
|
cxt.stroke();
|
|
|
|
}
|
|
|
|
|
2019-03-29 01:49:00 +01:00
|
|
|
// If the graph is going to be wide, squish it a bit so it doesn't take up
|
|
|
|
// quite as much space.
|
|
|
|
var default_width;
|
|
|
|
if (config.count >= 8) {
|
|
|
|
default_width = 6;
|
|
|
|
} else {
|
|
|
|
default_width = 12;
|
|
|
|
}
|
2012-03-24 01:11:15 +01:00
|
|
|
|
|
|
|
for (var ii = 0; ii < nodes.length; ii++) {
|
|
|
|
var data = JX.Stratcom.getData(nodes[ii]);
|
|
|
|
|
2019-03-29 01:49:00 +01:00
|
|
|
var cell = default_width;
|
2013-05-19 02:04:22 +02:00
|
|
|
var xpos = function(col) {
|
2012-03-24 01:11:15 +01:00
|
|
|
return (col * cell) + (cell / 2);
|
2013-05-19 02:04:22 +02:00
|
|
|
};
|
2012-03-24 01:11:15 +01:00
|
|
|
|
2017-06-07 00:47:47 +02:00
|
|
|
var h = 34;
|
2012-03-24 01:11:15 +01:00
|
|
|
var w = cell * config.count;
|
|
|
|
|
|
|
|
var canvas = JX.$N('canvas', {width: w, height: h});
|
|
|
|
cxt = canvas.getContext('2d');
|
|
|
|
|
|
|
|
cxt.lineWidth = 3;
|
|
|
|
// This gives us sharper lines, since lines drawn on an integer (like 5)
|
|
|
|
// are drawn from 4.5 to 5.5.
|
|
|
|
cxt.translate(0.5, 0.5);
|
|
|
|
|
|
|
|
cxt.strokeStyle = '#ffffff';
|
|
|
|
cxt.fillStyle = '#ffffff';
|
|
|
|
|
|
|
|
// First, figure out which column this commit appears in. It is marked by
|
|
|
|
// "o" (if it has a commit after it) or "^" (if no other commit has it as
|
|
|
|
// a parent). We use this to figure out where to draw the join/split lines.
|
|
|
|
|
|
|
|
var origin = null;
|
2013-05-19 02:04:22 +02:00
|
|
|
var jj;
|
|
|
|
var x;
|
|
|
|
var c;
|
|
|
|
for (jj = 0; jj < data.line.length; jj++) {
|
|
|
|
c = data.line.charAt(jj);
|
2012-03-24 01:11:15 +01:00
|
|
|
switch (c) {
|
|
|
|
case 'o':
|
2016-07-01 18:22:00 +02:00
|
|
|
case 'x':
|
2012-03-24 01:11:15 +01:00
|
|
|
case '^':
|
|
|
|
origin = xpos(jj);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw all the join lines. These start at some column at the top of the
|
|
|
|
// canvas and join the commit's column. They indicate branching.
|
|
|
|
|
2013-05-19 02:04:22 +02:00
|
|
|
for (jj = 0; jj < data.join.length; jj++) {
|
2012-03-24 01:11:15 +01:00
|
|
|
var join = data.join[jj];
|
2013-05-19 02:04:22 +02:00
|
|
|
x = xpos(join);
|
2016-07-01 18:22:00 +02:00
|
|
|
|
2012-03-24 01:11:15 +01:00
|
|
|
cxt.beginPath();
|
|
|
|
cxt.moveTo(x, 0);
|
|
|
|
cxt.bezierCurveTo(x, h/4, origin, h/4, origin, h/2);
|
|
|
|
lstroke(join);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw all the split lines. These start at the commit and end at some
|
|
|
|
// column on the bottom of the canvas. They indicate merging.
|
|
|
|
|
2013-05-19 02:04:22 +02:00
|
|
|
for (jj = 0; jj < data.split.length; jj++) {
|
2012-03-24 01:11:15 +01:00
|
|
|
var split = data.split[jj];
|
2013-05-19 02:04:22 +02:00
|
|
|
x = xpos(split);
|
2012-03-24 01:11:15 +01:00
|
|
|
cxt.beginPath();
|
|
|
|
cxt.moveTo(origin, h/2);
|
|
|
|
cxt.bezierCurveTo(origin, 3*h/4, x, 3*h/4, x, h);
|
|
|
|
lstroke(split);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the vertical lines (a branch with no activity at this commit) and
|
|
|
|
// the commit circles.
|
|
|
|
|
2013-05-19 02:04:22 +02:00
|
|
|
for (jj = 0; jj < data.line.length; jj++) {
|
|
|
|
c = data.line.charAt(jj);
|
2012-03-24 01:11:15 +01:00
|
|
|
switch (c) {
|
|
|
|
case 'o':
|
|
|
|
case '^':
|
|
|
|
case '|':
|
2016-01-08 20:41:49 +01:00
|
|
|
case 'x':
|
|
|
|
case 'X':
|
2013-05-19 02:04:22 +02:00
|
|
|
|
2016-01-08 20:41:49 +01:00
|
|
|
if (c !== 'X') {
|
|
|
|
cxt.beginPath();
|
|
|
|
cxt.moveTo(xpos(jj), (c == '^' ? h/2 : 0));
|
|
|
|
cxt.lineTo(xpos(jj), (c == 'x' ? h/2 : h));
|
|
|
|
lstroke(jj);
|
|
|
|
}
|
2012-03-24 01:11:15 +01:00
|
|
|
|
2016-01-08 20:41:49 +01:00
|
|
|
if (c == 'o' || c == '^' || c == 'x' || c == 'X') {
|
2012-03-24 01:11:15 +01:00
|
|
|
cxt.beginPath();
|
|
|
|
cxt.arc(xpos(jj), h/2, 3, 0, 2 * Math.PI, true);
|
|
|
|
fstroke(jj);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JX.DOM.setContent(nodes[ii], canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|