mirror of
https://github.com/facebook/sapling.git
synced 2024-09-11 18:47:10 +03:00
RenderDag: force "You are here" to be rendered at the last column
Summary: Since "You are here" have a different width, it cannot be followed by edges like "|". So it must be rendered at the last column. Reviewed By: muirdm Differential Revision: D52647445 fbshipit-source-id: ec3531662ca9f41a08f280187a050650dad243f3
This commit is contained in:
parent
8e96ef6c09
commit
9f5724c482
@ -95,7 +95,8 @@ export function RenderDag(props: RenderDagProps) {
|
||||
renderer.reserve(item);
|
||||
} else {
|
||||
const [info, typedParents] = item;
|
||||
const row = renderer.nextRow(info.hash, typedParents);
|
||||
const forceLastColumn = info.isYouAreHere;
|
||||
const row = renderer.nextRow(info.hash, typedParents, {forceLastColumn});
|
||||
// Layout per row:
|
||||
//
|
||||
// +-node--+ +-commit--------------+
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
import type {Hash} from '../types';
|
||||
|
||||
import {assert} from '../utils';
|
||||
|
||||
/* eslint no-bitwise: 0 */
|
||||
/* Translated from fbcode/eden/scm/lib/renderdag/src/render.rs */
|
||||
|
||||
@ -419,6 +421,14 @@ export type GraphRow = {
|
||||
linkLineFromNode?: Array<LinkLine>;
|
||||
};
|
||||
|
||||
type NextRowOptions = {
|
||||
/**
|
||||
* Ensure this node uses the last (right-most) column.
|
||||
* Only works for heads, i.e. nodes without children.
|
||||
*/
|
||||
forceLastColumn?: boolean;
|
||||
};
|
||||
|
||||
export class Renderer {
|
||||
private columns: Columns = new Columns();
|
||||
|
||||
@ -443,10 +453,21 @@ export class Renderer {
|
||||
* Render the next row.
|
||||
* Main logic of the renderer.
|
||||
*/
|
||||
nextRow(hash: Hash, parents: Array<Ancestor>): GraphRow {
|
||||
nextRow(hash: Hash, parents: Array<Ancestor>, opts?: NextRowOptions): GraphRow {
|
||||
const {forceLastColumn = false} = opts ?? {};
|
||||
|
||||
// Find a column for this node.
|
||||
const existingColumn = this.columns.find(hash);
|
||||
const column: number = existingColumn ?? this.columns.firstEmpty() ?? this.columns.newEmpty();
|
||||
let column: number;
|
||||
if (forceLastColumn) {
|
||||
assert(
|
||||
existingColumn == null,
|
||||
'requireLastColumn should only apply to heads (ex. "You are here")',
|
||||
);
|
||||
column = this.columns.newEmpty();
|
||||
} else {
|
||||
column = existingColumn ?? this.columns.firstEmpty() ?? this.columns.newEmpty();
|
||||
}
|
||||
const isHead = existingColumn == null;
|
||||
const isRoot = parents.length === 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user