MCPcopy Create free account
hub / github.com/GCWing/BitFun / computeFallbackLayout

Function computeFallbackLayout

MiniApp/Demo/git-graph/source/ui.js:283–342  ·  view source on GitHub ↗
(commits)

Source from the content-addressed store, hash-verified

281 }
282
283 function computeFallbackLayout(commits) {
284 const idx = {};
285 commits.forEach(function (c, i) { idx[c.hash] = i; });
286
287 const commitLane = new Array(commits.length);
288 const rowDrawInfo = [];
289 const activeLanes = [];
290 let maxLane = 0;
291
292 for (let i = 0; i < commits.length; i++) {
293 const c = commits[i];
294 const lanesBefore = activeLanes.slice();
295
296 let lane = lanesBefore.indexOf(c.hash);
297 if (lane === -1) {
298 lane = activeLanes.indexOf(null);
299 if (lane === -1) {
300 lane = activeLanes.length;
301 activeLanes.push(null);
302 }
303 }
304
305 commitLane[i] = lane;
306 while (activeLanes.length <= lane) activeLanes.push(null);
307 activeLanes[lane] = null;
308
309 const raw = c.parentHashes || c.parents || (c.parent != null ? [c.parent] : []);
310 const parents = Array.isArray(raw) ? raw : [raw];
311 const parentLanes = [];
312 for (let p = 0; p < parents.length; p++) {
313 const ph = parents[p];
314 if (idx[ph] === undefined) continue;
315
316 const existing = activeLanes.indexOf(ph);
317 if (existing >= 0) {
318 parentLanes.push({ lane: existing });
319 } else if (p === 0) {
320 activeLanes[lane] = ph;
321 parentLanes.push({ lane: lane });
322 } else {
323 let sl = activeLanes.indexOf(null);
324 if (sl === -1) {
325 sl = activeLanes.length;
326 activeLanes.push(null);
327 }
328 activeLanes[sl] = ph;
329 parentLanes.push({ lane: sl });
330 }
331 }
332
333 maxLane = Math.max(
334 maxLane,
335 lane,
336 parentLanes.length ? Math.max.apply(null, parentLanes.map(function (pl) { return pl.lane; })) : 0
337 );
338 rowDrawInfo.push({ lane: lane, lanesBefore: lanesBefore, parentLanes: parentLanes });
339 }
340

Callers 1

ui.jsFile · 0.70

Calls 3

sliceMethod · 0.80
pushMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected