Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/webroot/rsrc/js/application/diffusion/behavior-commit-graph.js
12241 views
1
/**
2
* @provides javelin-behavior-diffusion-commit-graph
3
* @requires javelin-behavior
4
* javelin-dom
5
* javelin-stratcom
6
*/
7
8
JX.behavior('diffusion-commit-graph', function(config) {
9
10
var nodes = JX.DOM.scry(document.body, 'div', 'commit-graph');
11
var cxt;
12
13
// Pick the color for column 'c'.
14
function color(c) {
15
var colors = [
16
'#cc0000',
17
'#cc0099',
18
'#6600cc',
19
'#0033cc',
20
'#00cccc',
21
'#00cc33',
22
'#66cc00',
23
'#cc9900'
24
];
25
return colors[c % colors.length];
26
}
27
28
// Stroke a line (for lines between commits).
29
function lstroke(c) {
30
cxt.lineWidth = 3;
31
cxt.strokeStyle = '#ffffff';
32
cxt.stroke();
33
cxt.lineWidth = 1;
34
cxt.strokeStyle = color(c);
35
cxt.stroke();
36
}
37
38
// Stroke with fill (for commit circles).
39
function fstroke(c) {
40
cxt.lineWidth = 1;
41
cxt.fillStyle = color(c);
42
cxt.strokeStyle = '#ffffff';
43
cxt.fill();
44
cxt.stroke();
45
}
46
47
// If the graph is going to be wide, squish it a bit so it doesn't take up
48
// quite as much space.
49
var default_width;
50
if (config.count >= 8) {
51
default_width = 6;
52
} else {
53
default_width = 12;
54
}
55
56
for (var ii = 0; ii < nodes.length; ii++) {
57
var data = JX.Stratcom.getData(nodes[ii]);
58
59
var cell = default_width;
60
var xpos = function(col) {
61
return (col * cell) + (cell / 2);
62
};
63
64
var h;
65
if (config.height) {
66
h = config.height;
67
} else {
68
h = JX.Vector.getDim(nodes[ii].parentNode).y;
69
}
70
71
var w = cell * config.count;
72
73
var canvas = JX.$N('canvas', {width: w, height: h});
74
cxt = canvas.getContext('2d');
75
76
cxt.lineWidth = 3;
77
// This gives us sharper lines, since lines drawn on an integer (like 5)
78
// are drawn from 4.5 to 5.5.
79
cxt.translate(0.5, 0.5);
80
81
cxt.strokeStyle = '#ffffff';
82
cxt.fillStyle = '#ffffff';
83
84
// First, figure out which column this commit appears in. It is marked by
85
// "o" (if it has a commit after it) or "^" (if no other commit has it as
86
// a parent). We use this to figure out where to draw the join/split lines.
87
88
var origin = null;
89
var jj;
90
var x;
91
var c;
92
for (jj = 0; jj < data.line.length; jj++) {
93
c = data.line.charAt(jj);
94
switch (c) {
95
case 'o':
96
case 'x':
97
case '^':
98
origin = xpos(jj);
99
break;
100
}
101
}
102
103
// Draw all the join lines. These start at some column at the top of the
104
// canvas and join the commit's column. They indicate branching.
105
106
for (jj = 0; jj < data.join.length; jj++) {
107
var join = data.join[jj];
108
x = xpos(join);
109
110
cxt.beginPath();
111
cxt.moveTo(x, 0);
112
cxt.bezierCurveTo(x, h/4, origin, h/4, origin, h/2);
113
lstroke(join);
114
}
115
116
// Draw all the split lines. These start at the commit and end at some
117
// column on the bottom of the canvas. They indicate merging.
118
119
for (jj = 0; jj < data.split.length; jj++) {
120
var split = data.split[jj];
121
x = xpos(split);
122
cxt.beginPath();
123
cxt.moveTo(origin, h/2);
124
cxt.bezierCurveTo(origin, 3*h/4, x, 3*h/4, x, h);
125
lstroke(split);
126
}
127
128
// Draw the vertical lines (a branch with no activity at this commit) and
129
// the commit circles.
130
131
for (jj = 0; jj < data.line.length; jj++) {
132
c = data.line.charAt(jj);
133
switch (c) {
134
case 'o':
135
case '^':
136
case '|':
137
case 'x':
138
case 'X':
139
140
if (c !== 'X') {
141
cxt.beginPath();
142
cxt.moveTo(xpos(jj), (c == '^' ? h/2 : 0));
143
cxt.lineTo(xpos(jj), (c == 'x' ? h/2 : h));
144
lstroke(jj);
145
}
146
147
if (c == 'o' || c == '^' || c == 'x' || c == 'X') {
148
cxt.beginPath();
149
cxt.arc(xpos(jj), h/2, 3, 0, 2 * Math.PI, true);
150
fstroke(jj);
151
}
152
break;
153
}
154
}
155
156
JX.DOM.replace(nodes[ii], canvas);
157
}
158
159
160
});
161
162