This commit is contained in:
parent
dd2079b975
commit
3c164581ce
7 changed files with 34 additions and 34 deletions
|
@ -49,7 +49,7 @@ function getOverlappingContainers(
|
||||||
containers: IContainerModel[]
|
containers: IContainerModel[]
|
||||||
): IContainerModel[] {
|
): IContainerModel[] {
|
||||||
const min1 = container.properties.x;
|
const min1 = container.properties.x;
|
||||||
const max1 = container.properties.x + Number(container.properties.width);
|
const max1 = container.properties.x + container.properties.width;
|
||||||
const overlappingContainers: IContainerModel[] = [];
|
const overlappingContainers: IContainerModel[] = [];
|
||||||
for (const other of containers) {
|
for (const other of containers) {
|
||||||
if (other === container) {
|
if (other === container) {
|
||||||
|
@ -57,7 +57,7 @@ function getOverlappingContainers(
|
||||||
}
|
}
|
||||||
|
|
||||||
const min2 = other.properties.x;
|
const min2 = other.properties.x;
|
||||||
const max2 = other.properties.x + Number(other.properties.width);
|
const max2 = other.properties.x + other.properties.width;
|
||||||
const isOverlapping = Math.min(max1, max2) - Math.max(min1, min2) > 0;
|
const isOverlapping = Math.min(max1, max2) - Math.max(min1, min2) > 0;
|
||||||
|
|
||||||
if (!isOverlapping) {
|
if (!isOverlapping) {
|
||||||
|
|
|
@ -42,8 +42,8 @@ function constraintBodyInsideParent(
|
||||||
}
|
}
|
||||||
|
|
||||||
const parentProperties = container.parent.properties;
|
const parentProperties = container.parent.properties;
|
||||||
const parentWidth = Number(parentProperties.width);
|
const parentWidth = parentProperties.width;
|
||||||
const parentHeight = Number(parentProperties.height);
|
const parentHeight = parentProperties.height;
|
||||||
|
|
||||||
return constraintBodyInsideSpace(container, 0, 0, parentWidth, parentHeight);
|
return constraintBodyInsideSpace(container, 0, 0, parentWidth, parentHeight);
|
||||||
}
|
}
|
||||||
|
@ -66,10 +66,10 @@ function constraintBodyInsideSpace(
|
||||||
height: number
|
height: number
|
||||||
): IContainerModel {
|
): IContainerModel {
|
||||||
const containerProperties = container.properties;
|
const containerProperties = container.properties;
|
||||||
const containerX = Number(containerProperties.x);
|
const containerX = containerProperties.x;
|
||||||
const containerY = Number(containerProperties.y);
|
const containerY = containerProperties.y;
|
||||||
const containerWidth = Number(containerProperties.width);
|
const containerWidth = containerProperties.width;
|
||||||
const containerHeight = Number(containerProperties.height);
|
const containerHeight = containerProperties.height;
|
||||||
|
|
||||||
// Check size bigger than parent
|
// Check size bigger than parent
|
||||||
const isBodyLargerThanParent = containerWidth > width;
|
const isBodyLargerThanParent = containerWidth > width;
|
||||||
|
@ -121,8 +121,8 @@ export function constraintBodyInsideUnallocatedWidth(
|
||||||
|
|
||||||
// Get the available spaces of the parent
|
// Get the available spaces of the parent
|
||||||
const availableWidths = getAvailableWidths(container.parent, container);
|
const availableWidths = getAvailableWidths(container.parent, container);
|
||||||
const containerX = Number(container.properties.x);
|
const containerX = container.properties.x;
|
||||||
const containerWidth = Number(container.properties.width);
|
const containerWidth = container.properties.width;
|
||||||
|
|
||||||
// Check if there is still some space
|
// Check if there is still some space
|
||||||
if (availableWidths.length === 0) {
|
if (availableWidths.length === 0) {
|
||||||
|
@ -177,7 +177,7 @@ export function constraintBodyInsideUnallocatedWidth(
|
||||||
availableWidthFound.x,
|
availableWidthFound.x,
|
||||||
0,
|
0,
|
||||||
availableWidthFound.width,
|
availableWidthFound.width,
|
||||||
Number(container.parent.properties.height)
|
container.parent.properties.height
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ function getAvailableWidths(
|
||||||
// Initialize the first size pointer
|
// Initialize the first size pointer
|
||||||
// which takes full width of the available space
|
// which takes full width of the available space
|
||||||
const x = 0;
|
const x = 0;
|
||||||
const width = Number(container.properties.width);
|
const width = container.properties.width;
|
||||||
let unallocatedSpaces: ISizePointer[] = [{ x, width }];
|
let unallocatedSpaces: ISizePointer[] = [{ x, width }];
|
||||||
|
|
||||||
// We will only uses containers that also are rigid or are anchors
|
// We will only uses containers that also are rigid or are anchors
|
||||||
|
@ -211,7 +211,7 @@ function getAvailableWidths(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const childX = child.properties.x;
|
const childX = child.properties.x;
|
||||||
const childWidth = Number(child.properties.width);
|
const childWidth = child.properties.width;
|
||||||
|
|
||||||
// get the space of the child that is inside the parent
|
// get the space of the child that is inside the parent
|
||||||
let newUnallocatedSpace: ISizePointer[] = [];
|
let newUnallocatedSpace: ISizePointer[] = [];
|
||||||
|
@ -309,4 +309,4 @@ function getAvailableWidthsTwoLines(
|
||||||
const isFitting = (
|
const isFitting = (
|
||||||
container: IContainerModel,
|
container: IContainerModel,
|
||||||
sizePointer: ISizePointer
|
sizePointer: ISizePointer
|
||||||
): boolean => Number(container.properties.width) <= sizePointer.width;
|
): boolean => container.properties.width <= sizePointer.width;
|
||||||
|
|
|
@ -266,13 +266,13 @@ function ApplyAddMethod(index: number, containerConfig: IAvailableContainer, par
|
||||||
|
|
||||||
if (lastChild !== undefined) {
|
if (lastChild !== undefined) {
|
||||||
const [transformedX] = transformPosition(
|
const [transformedX] = transformPosition(
|
||||||
Number(lastChild.properties.x),
|
lastChild.properties.x,
|
||||||
Number(lastChild.properties.y),
|
lastChild.properties.y,
|
||||||
Number(lastChild.properties.width),
|
lastChild.properties.width,
|
||||||
lastChild.properties.XPositionReference
|
lastChild.properties.XPositionReference
|
||||||
);
|
);
|
||||||
|
|
||||||
x += transformedX + Number(lastChild.properties.width);
|
x += transformedX + lastChild.properties.width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
|
|
|
@ -133,8 +133,8 @@ const Editor: React.FunctionComponent<IEditorProps> = (props) => {
|
||||||
LoadState={(move) => setHistoryCurrentStep(move)}
|
LoadState={(move) => setHistoryCurrentStep(move)}
|
||||||
/>
|
/>
|
||||||
<SVG
|
<SVG
|
||||||
width={Number(current.MainContainer?.properties.width)}
|
width={current.MainContainer?.properties.width}
|
||||||
height={Number(current.MainContainer?.properties.height)}
|
height={current.MainContainer?.properties.height}
|
||||||
selected={current.SelectedContainer}
|
selected={current.SelectedContainer}
|
||||||
>
|
>
|
||||||
{ current.MainContainer }
|
{ current.MainContainer }
|
||||||
|
|
|
@ -15,13 +15,13 @@ interface IContainerProps {
|
||||||
*/
|
*/
|
||||||
export const Container: React.FC<IContainerProps> = (props: IContainerProps) => {
|
export const Container: React.FC<IContainerProps> = (props: IContainerProps) => {
|
||||||
const containersElements = props.model.children.map(child => <Container key={`container-${child.properties.id}`} model={child} />);
|
const containersElements = props.model.children.map(child => <Container key={`container-${child.properties.id}`} model={child} />);
|
||||||
const xText = Number(props.model.properties.width) / 2;
|
const xText = props.model.properties.width / 2;
|
||||||
const yText = Number(props.model.properties.height) / 2;
|
const yText = props.model.properties.height / 2;
|
||||||
|
|
||||||
const [transformedX, transformedY] = transformPosition(
|
const [transformedX, transformedY] = transformPosition(
|
||||||
Number(props.model.properties.x),
|
props.model.properties.x,
|
||||||
Number(props.model.properties.y),
|
props.model.properties.y,
|
||||||
Number(props.model.properties.width),
|
props.model.properties.width,
|
||||||
props.model.properties.XPositionReference
|
props.model.properties.XPositionReference
|
||||||
);
|
);
|
||||||
const transform = `translate(${transformedX}, ${transformedY})`;
|
const transform = `translate(${transformedX}, ${transformedY})`;
|
||||||
|
@ -48,7 +48,7 @@ export const Container: React.FC<IContainerProps> = (props: IContainerProps) =>
|
||||||
const dimensionMargin = DIMENSION_MARGIN * (depth + 1);
|
const dimensionMargin = DIMENSION_MARGIN * (depth + 1);
|
||||||
const id = `dim-${props.model.properties.id}`;
|
const id = `dim-${props.model.properties.id}`;
|
||||||
const xStart: number = 0;
|
const xStart: number = 0;
|
||||||
const xEnd = Number(props.model.properties.width);
|
const xEnd = props.model.properties.width;
|
||||||
const y = -dimensionMargin;
|
const y = -dimensionMargin;
|
||||||
const strokeWidth = 1;
|
const strokeWidth = 1;
|
||||||
const text = (props.model.properties.width ?? 0).toString();
|
const text = (props.model.properties.width ?? 0).toString();
|
||||||
|
@ -112,20 +112,20 @@ function GetChildrenDimensionProps(props: IContainerProps, dimensionMargin: numb
|
||||||
|
|
||||||
const lastChild = props.model.children[props.model.children.length - 1];
|
const lastChild = props.model.children[props.model.children.length - 1];
|
||||||
let xChildrenStart = lastChild.properties.x;
|
let xChildrenStart = lastChild.properties.x;
|
||||||
let xChildrenEnd = lastChild.properties.x + Number(lastChild.properties.width);
|
let xChildrenEnd = lastChild.properties.x + lastChild.properties.width;
|
||||||
for (let i = props.model.children.length - 2; i >= 0; i--) {
|
for (let i = props.model.children.length - 2; i >= 0; i--) {
|
||||||
const child = props.model.children[i];
|
const child = props.model.children[i];
|
||||||
const left = child.properties.x;
|
const left = child.properties.x;
|
||||||
if (left < xChildrenStart) {
|
if (left < xChildrenStart) {
|
||||||
xChildrenStart = left;
|
xChildrenStart = left;
|
||||||
}
|
}
|
||||||
const right = child.properties.x + Number(child.properties.width);
|
const right = child.properties.x + child.properties.width;
|
||||||
if (right > xChildrenEnd) {
|
if (right > xChildrenEnd) {
|
||||||
xChildrenEnd = right;
|
xChildrenEnd = right;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const yChildren = Number(props.model.properties.height) + dimensionMargin;
|
const yChildren = props.model.properties.height + dimensionMargin;
|
||||||
const textChildren = (xChildrenEnd - xChildrenStart).toString();
|
const textChildren = (xChildrenEnd - xChildrenStart).toString();
|
||||||
return { childrenId, xChildrenStart, xChildrenEnd, yChildren, textChildren };
|
return { childrenId, xChildrenStart, xChildrenEnd, yChildren, textChildren };
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ export const Selector: React.FC<ISelectorProps> = (props) => {
|
||||||
const [transformedX, transformedY] = transformPosition(
|
const [transformedX, transformedY] = transformPosition(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
Number(props.selected.properties.width),
|
props.selected.properties.width,
|
||||||
props.selected.properties.XPositionReference
|
props.selected.properties.XPositionReference
|
||||||
);
|
);
|
||||||
const [width, height] = [
|
const [width, height] = [
|
||||||
|
|
|
@ -43,12 +43,12 @@ export function getDepth(parent: IContainerModel): number {
|
||||||
* @returns The absolute position of the container
|
* @returns The absolute position of the container
|
||||||
*/
|
*/
|
||||||
export function getAbsolutePosition(container: IContainerModel): [number, number] {
|
export function getAbsolutePosition(container: IContainerModel): [number, number] {
|
||||||
let x = Number(container.properties.x);
|
let x = container.properties.x;
|
||||||
let y = Number(container.properties.y);
|
let y = container.properties.y;
|
||||||
let current = container.parent;
|
let current = container.parent;
|
||||||
while (current != null) {
|
while (current != null) {
|
||||||
x += Number(current.properties.x);
|
x += current.properties.x;
|
||||||
y += Number(current.properties.y);
|
y += current.properties.y;
|
||||||
current = current.parent;
|
current = current.parent;
|
||||||
}
|
}
|
||||||
return [x, y];
|
return [x, y];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue