Merged PR 228: Implement left cotation and fix borrower cotation when length = 0

Implement left cotation and fix borrower cotation when length = 0

Related work items: #7575
This commit is contained in:
Eric Nguyen 2022-11-08 15:51:42 +00:00
parent a8723ffd27
commit 96c3fbdf4e
2 changed files with 83 additions and 25 deletions

View file

@ -79,18 +79,20 @@ function ActionByPosition(
dimMapped: number[], dimMapped: number[],
positions: Position[], positions: Position[],
horizontalAction: (ctx: CanvasRenderingContext2D, dim: number, ...params: any[]) => void, horizontalAction: (ctx: CanvasRenderingContext2D, dim: number, ...params: any[]) => void,
verticalAction: (ctx: CanvasRenderingContext2D, dim: number, ...params: any[]) => void, verticalAction: (ctx: CanvasRenderingContext2D, dim: number, isRight: boolean, ...params: any[]) => void,
params: any[] params: any[]
): void { ): void {
positions.forEach((position: Position) => { positions.forEach((position: Position) => {
const dim = dimMapped[position]; const dim = dimMapped[position];
switch (position) { switch (position) {
case Position.Left: case Position.Left:
case Position.Right: case Position.Right: {
verticalAction(ctx, dim, ...params); const isRight = position === Position.Right;
verticalAction(ctx, dim, isRight, ...params);
}
break; break;
case Position.Down:
case Position.Up: case Position.Up:
case Position.Down:
horizontalAction(ctx, dim, ...params); horizontalAction(ctx, dim, ...params);
break; break;
} }
@ -140,10 +142,10 @@ function AddHorizontalChildrenDimension(
} }
const textChildren = (xChildrenEnd - xChildrenStart) const textChildren = (xChildrenEnd - xChildrenStart)
.toFixed(2) .toFixed(0);
.toString();
const offset = currentTransform[0] + container.properties.x; const offset = currentTransform[0] + container.properties.x;
RenderDimension(ctx, { RenderDimension(ctx, {
id: childrenId, id: childrenId,
xStart: xChildrenStart + offset, xStart: xChildrenStart + offset,
@ -159,6 +161,7 @@ function AddHorizontalChildrenDimension(
function AddVerticalChildrenDimension( function AddVerticalChildrenDimension(
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
xDim: number, xDim: number,
isRight: boolean,
containers: Map<string, IContainerModel>, containers: Map<string, IContainerModel>,
container: IContainerModel, container: IContainerModel,
currentTransform: [number, number], currentTransform: [number, number],
@ -174,7 +177,7 @@ function AddVerticalChildrenDimension(
} }
let yChildrenStart = TransformY(lastChild.properties.y, lastChild.properties.height, lastChild.properties.positionReference); let yChildrenStart = TransformY(lastChild.properties.y, lastChild.properties.height, lastChild.properties.positionReference);
let yChildrenEnd = TransformY(lastChild.properties.y, lastChild.properties.height, lastChild.properties.positionReference); let yChildrenEnd = yChildrenStart;
// Find the min and max // Find the min and max
for (let i = container.children.length - 2; i >= 0; i--) { for (let i = container.children.length - 2; i >= 0; i--) {
@ -201,11 +204,14 @@ function AddVerticalChildrenDimension(
} }
const textChildren = (yChildrenEnd - yChildrenStart) const textChildren = (yChildrenEnd - yChildrenStart)
.toFixed(2) .toFixed(0);
.toString();
const offset = currentTransform[0] + container.properties.x; const offset = currentTransform[0] + container.properties.x;
if (!isRight) {
[yChildrenStart, yChildrenEnd] = [yChildrenEnd, yChildrenStart];
}
RenderDimension(ctx, { RenderDimension(ctx, {
id: childrenId, id: childrenId,
xStart: xDim, xStart: xDim,
@ -257,6 +263,11 @@ function AddHorizontalBorrowerDimension(
let count = 0; let count = 0;
for (const { cur, next } of Pairwise(marks)) { for (const { cur, next } of Pairwise(marks)) {
const id = `dim-y${yDim.toFixed(0)}-borrow-${container.properties.id}-{${count}}`; const id = `dim-y${yDim.toFixed(0)}-borrow-${container.properties.id}-{${count}}`;
const value = next - cur;
if (value === 0) {
return;
}
RenderDimension(ctx, { RenderDimension(ctx, {
id, id,
xStart: cur, xStart: cur,
@ -264,7 +275,7 @@ function AddHorizontalBorrowerDimension(
yStart: yDim, yStart: yDim,
yEnd: yDim, yEnd: yDim,
strokeWidth: MODULE_STROKE_WIDTH, strokeWidth: MODULE_STROKE_WIDTH,
text: (next - cur).toFixed(0).toString(), text: value.toFixed(0),
scale scale
}); });
count++; count++;
@ -274,6 +285,7 @@ function AddHorizontalBorrowerDimension(
function AddVerticalBorrowerDimension( function AddVerticalBorrowerDimension(
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
xDim: number, xDim: number,
isRight: boolean,
containers: Map<string, IContainerModel>, containers: Map<string, IContainerModel>,
container: IContainerModel, container: IContainerModel,
depth: number, depth: number,
@ -307,9 +319,19 @@ function AddVerticalBorrowerDimension(
marks.push(restoredY); marks.push(restoredY);
marks.push(restoredY + container.properties.height); marks.push(restoredY + container.properties.height);
marks.sort((a, b) => a - b); marks.sort((a, b) => a - b);
let count = 0; let count = 0;
for (const { cur, next } of Pairwise(marks)) { for (let { cur, next } of Pairwise(marks)) {
const id = `dim-x${xDim.toFixed(0)}-borrow-${container.properties.id}-{${count}}`; const id = `dim-x${xDim.toFixed(0)}-borrow-${container.properties.id}-{${count}}`;
const value = next - cur;
if (value === 0) {
return;
}
if (!isRight) {
[cur, next] = [next, cur];
}
RenderDimension(ctx, { RenderDimension(ctx, {
id, id,
xStart: xDim, xStart: xDim,
@ -317,7 +339,7 @@ function AddVerticalBorrowerDimension(
yStart: cur, yStart: cur,
yEnd: next, yEnd: next,
strokeWidth: MODULE_STROKE_WIDTH, strokeWidth: MODULE_STROKE_WIDTH,
text: (next - cur).toFixed(0).toString(), text: value.toFixed(0),
scale scale
}); });
count++; count++;
@ -327,22 +349,28 @@ function AddVerticalBorrowerDimension(
function AddVerticalSelfDimension( function AddVerticalSelfDimension(
ctx: CanvasRenderingContext2D, ctx: CanvasRenderingContext2D,
xDim: number, xDim: number,
isRight: boolean,
container: IContainerModel, container: IContainerModel,
currentTransform: [number, number], currentTransform: [number, number],
scale: number scale: number
): void { ): void {
const height = container.properties.height; const height = container.properties.height;
const idVert = `dim-x${xDim.toFixed(0)}-${container.properties.id}`; const idVert = `dim-x${xDim.toFixed(0)}-${container.properties.id}`;
const yStart = container.properties.y + currentTransform[1]; let yStart = container.properties.y + currentTransform[1] + height;
const yEnd = yStart + height; let yEnd = container.properties.y + currentTransform[1];
const textVert = height const textVert = height
.toFixed(0) .toFixed(0)
.toString(); .toString();
if (isRight) {
[yStart, yEnd] = [yEnd, yStart];
}
RenderDimension(ctx, { RenderDimension(ctx, {
id: idVert, id: idVert,
xStart: xDim, xStart: xDim,
yStart,
xEnd: xDim, xEnd: xDim,
yStart,
yEnd, yEnd,
strokeWidth: MODULE_STROKE_WIDTH, strokeWidth: MODULE_STROKE_WIDTH,
text: textVert, text: textVert,

View file

@ -29,16 +29,18 @@ function ActionByPosition(
dimMapped: number[], dimMapped: number[],
positions: Position[], positions: Position[],
horizontalAction: (dim: number, ...params: any[]) => void, horizontalAction: (dim: number, ...params: any[]) => void,
verticalAction: (dim: number, ...params: any[]) => void, verticalAction: (dim: number, isRight: boolean, ...params: any[]) => void,
params: any[] params: any[]
): void { ): void {
positions.forEach((position: Position) => { positions.forEach((position: Position) => {
const dim = dimMapped[position]; const dim = dimMapped[position];
switch (position) { switch (position) {
case Position.Left: case Position.Left:
case Position.Right: case Position.Right: {
verticalAction(dim, ...params); const isRight = position === Position.Right;
verticalAction(dim, isRight, ...params);
break; break;
}
case Position.Down: case Position.Down:
case Position.Up: case Position.Up:
horizontalAction(dim, ...params); horizontalAction(dim, ...params);
@ -179,7 +181,7 @@ function AddHorizontalChildrenDimension(
} }
const textChildren = (xChildrenEnd - xChildrenStart) const textChildren = (xChildrenEnd - xChildrenStart)
.toFixed(2) .toFixed(0)
.toString(); .toString();
const offset = currentTransform[0] + container.properties.x; const offset = currentTransform[0] + container.properties.x;
@ -197,6 +199,7 @@ function AddHorizontalChildrenDimension(
function AddVerticalChildrenDimension( function AddVerticalChildrenDimension(
xDim: number, xDim: number,
isRight: boolean,
containers: Map<string, IContainerModel>, containers: Map<string, IContainerModel>,
container: IContainerModel, container: IContainerModel,
currentTransform: [number, number], currentTransform: [number, number],
@ -240,10 +243,15 @@ function AddVerticalChildrenDimension(
} }
const textChildren = (yChildrenEnd - yChildrenStart) const textChildren = (yChildrenEnd - yChildrenStart)
.toFixed(2) .toFixed(0)
.toString(); .toString();
const offset = currentTransform[0] + container.properties.x; const offset = currentTransform[0] + container.properties.x;
if (!isRight) {
[yChildrenStart, yChildrenEnd] = [yChildrenEnd, yChildrenStart];
}
dimensions.push(<Dimension dimensions.push(<Dimension
key={childrenId} key={childrenId}
id={childrenId} id={childrenId}
@ -296,6 +304,11 @@ function AddHorizontalBorrowerDimension(
let count = 0; let count = 0;
for (const { cur, next } of Pairwise(marks)) { for (const { cur, next } of Pairwise(marks)) {
const id = `dim-y${yDim.toFixed(0)}-borrow-${container.properties.id}-{${count}}`; const id = `dim-y${yDim.toFixed(0)}-borrow-${container.properties.id}-{${count}}`;
const value = next - cur;
if (value === 0) {
return;
}
dimensions.push(<Dimension dimensions.push(<Dimension
key={id} key={id}
id={id} id={id}
@ -304,7 +317,7 @@ function AddHorizontalBorrowerDimension(
yStart={yDim} yStart={yDim}
yEnd={yDim} yEnd={yDim}
strokeWidth={MODULE_STROKE_WIDTH} strokeWidth={MODULE_STROKE_WIDTH}
text={(next - cur).toFixed(0).toString()} text={value.toFixed(0)}
scale={scale} />); scale={scale} />);
count++; count++;
} }
@ -312,6 +325,7 @@ function AddHorizontalBorrowerDimension(
function AddVerticalBorrowerDimension( function AddVerticalBorrowerDimension(
xDim: number, xDim: number,
isRight: boolean,
containers: Map<string, IContainerModel>, containers: Map<string, IContainerModel>,
container: IContainerModel, container: IContainerModel,
depth: number, depth: number,
@ -346,9 +360,19 @@ function AddVerticalBorrowerDimension(
marks.push(restoredY); marks.push(restoredY);
marks.push(restoredY + container.properties.height); marks.push(restoredY + container.properties.height);
marks.sort((a, b) => a - b); marks.sort((a, b) => a - b);
let count = 0; let count = 0;
for (const { cur, next } of Pairwise(marks)) { for (let { cur, next } of Pairwise(marks)) {
const id = `dim-x${xDim.toFixed(0)}-borrow-${container.properties.id}-{${count}}`; const id = `dim-x${xDim.toFixed(0)}-borrow-${container.properties.id}-{${count}}`;
const value = next - cur;
if (value === 0) {
return;
}
if (!isRight) {
[cur, next] = [next, cur];
}
dimensions.push(<Dimension dimensions.push(<Dimension
key={id} key={id}
id={id} id={id}
@ -357,7 +381,7 @@ function AddVerticalBorrowerDimension(
yStart={cur} yStart={cur}
yEnd={next} yEnd={next}
strokeWidth={MODULE_STROKE_WIDTH} strokeWidth={MODULE_STROKE_WIDTH}
text={(next - cur).toFixed(0).toString()} text={value.toFixed(0)}
scale={scale} />); scale={scale} />);
count++; count++;
} }
@ -365,6 +389,7 @@ function AddVerticalBorrowerDimension(
function AddVerticalSelfDimension( function AddVerticalSelfDimension(
xDim: number, xDim: number,
isRight: boolean,
container: IContainerModel, container: IContainerModel,
currentTransform: [number, number], currentTransform: [number, number],
dimensions: React.ReactNode[], dimensions: React.ReactNode[],
@ -372,11 +397,16 @@ function AddVerticalSelfDimension(
): void { ): void {
const height = container.properties.height; const height = container.properties.height;
const idVert = `dim-x${xDim.toFixed(0)}-${container.properties.id}`; const idVert = `dim-x${xDim.toFixed(0)}-${container.properties.id}`;
const yStart = container.properties.y + currentTransform[1]; let yStart = container.properties.y + currentTransform[1] + height;
const yEnd = yStart + height; let yEnd = container.properties.y + currentTransform[1];
const textVert = height const textVert = height
.toFixed(0) .toFixed(0)
.toString(); .toString();
if (isRight) {
[yStart, yEnd] = [yEnd, yStart];
}
dimensions.push( dimensions.push(
<Dimension <Dimension
key={idVert} key={idVert}