-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource-control.html
216 lines (195 loc) · 7.82 KB
/
source-control.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Branching Timeline</title>
<style>
body {
background-color: #181818;
color: #cccccc;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 13px;
}
.timeline {
list-style-type: none;
position: relative;
padding: 0;
margin: 0;
max-width: max-content;
}
.timeline::before {
content: '';
position: absolute;
left: 5px;
top: 0;
width: 2px;
height: 100%;
background-color: #3587e5;
z-index: 3;
}
.timeline li {
position: relative;
padding-left: 30px;
cursor: pointer;
height: 25px;
display: flex;
align-items: center;
padding-right: 10px;
border-top-right-radius: 12px;
border-bottom-right-radius: 12px;
white-space: nowrap;
}
.main-commit::before {
content: '';
position: absolute;
left: 1.6px;
width: 9px;
height: 9px;
background-color: #3587e5;
border-radius: 50%;
top: 50%;
transform: translateY(-50%);
z-index: 6;
outline: solid 1px #181818;
}
.inner-circle {
position: absolute;
width: 3.2px;
height: 3px;
outline: solid 2px #181818;
background-color: #3587e5;
border-radius: 50%;
top: 50%;
left: 6px;
transform: translate(-50%, -50%);
z-index: 99999;
}
.curve {
position: absolute;
width: 9px;
height: 50px;
border-top-right-radius: 9px;
border-bottom-right-radius: 9px;
top: 50%;
left: 5px;
z-index: 1;
translate: 2px -25px;
}
.branch-commit {
content: '';
position: absolute;
width: 6px;
height: 6px;
border-radius: 50%;
translate: -16.4px 0px;
z-index: 1;
outline: solid 1px #181818;
}
li:hover {
background-color: #2a2d2e;
}
</style>
</head>
<body>
<ul id="timeline" class="timeline"></ul>
<script>
const timeline = document.getElementById('timeline');
const branches = {}; // Track branches and their commits
const branchColors = {}; // Map of branch to color
let branchCounter = 0;
// Function to generate a unique color for each branch
function generateBranchColor() {
const hue = (branchCounter * 137.5) % 360; // Use golden angle to ensure even distribution
branchCounter++;
return `hsl(${hue}, 70%, 60%)`;
}
function commit(branch, message) {
const li = document.createElement('li');
const span = document.createElement('span');
span.textContent = message;
li.appendChild(span);
li.setAttribute('data-branch', branch);
if (branch === 'main') {
// Main branch commits
li.classList.add('main-commit');
// Add inner circle
const innerCircle = document.createElement('div');
innerCircle.className = 'inner-circle';
li.appendChild(innerCircle);
timeline.appendChild(li);
} else {
// Assign a unique color to the branch if not already assigned
if (!branchColors[branch]) {
branchColors[branch] = generateBranchColor();
}
const branchColor = branchColors[branch];
if (!branches[branch]) {
// Initialize new branch
branches[branch] = { count: 1, lastElement: li };
// Create curve to connect to the main branch
const curve = document.createElement('div');
curve.className = 'curve';
curve.style.outline = `1px solid ${branchColor}`; // Correct shorthand property
li.appendChild(curve);
// Create vertical branch line
const branchCommit = document.createElement('div');
branchCommit.className = 'branch-commit';
branchCommit.style.backgroundColor = branchColor; // Background color for the commit
li.appendChild(branchCommit);
timeline.appendChild(li);
// Store the curve for future commits
branches[branch].curve = curve;
// Base curve height for the first branch commit
curve.style.height = '50px';
} else {
// Update branch for subsequent commits
const branchData = branches[branch];
const curve = branchData.curve;
// Adjust curve height dynamically
const newHeight = 50 + 25 * branchData.count; // Base height + incremental height
curve.style.height = `${newHeight}px`;
branchData.count++;
// Create vertical branch line
const branchCommit = document.createElement('div');
branchCommit.className = 'branch-commit';
branchCommit.style.backgroundColor = branchColor;
li.appendChild(branchCommit);
timeline.appendChild(li);
// Update last element reference
branches[branch].lastElement = li;
}
}
}
// Manual Usage Example:
commit('main', 'Final main commit');
commit('main', 'Merge branch-1 with main');
commit('branch-1', 'Branch-1 fourth commit');
commit('branch-1', 'Branch-1 third commit');
commit('branch-1', 'Branch-1 second commit');
commit('branch-1', 'Branch-1 first commit');
commit('main', 'Second commit');
commit('main', 'Initial commit');
// Load commits from commits.txt generated by git.sh script to populate the source control timeline
// async function loadCommits() {
// try {
// const response = await fetch('commits.txt');
// const text = await response.text();
// const commits = text.trim().split('\n').map(line => {
// const [hash, ...messageParts] = line.split(' - ');
// const message = messageParts.join(' - ');
// const branchMatch = message.match(/\((.*?)\)$/);
// const branch = branchMatch ? branchMatch[1].split(', ')[0] : 'main'; // Use first branch listed
// return { hash, message: message.replace(/\s*\(.*?\)$/, ''), branch };
// });
// commits.forEach(commitData => {
// commit(commitData.branch, commitData.message);
// });
// } catch (error) {
// console.error('Error loading commits:', error);
// }
// }
// loadCommits();
</script>
</body>
</html>