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

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