diff --git a/src/Components/Menu/Menu.tsx b/src/Components/Menu/Menu.tsx
index 76e0549..0a15cc9 100644
--- a/src/Components/Menu/Menu.tsx
+++ b/src/Components/Menu/Menu.tsx
@@ -96,6 +96,7 @@ export function Menu(props: IMenuProps): JSX.Element {
};
}
+ // TODO: Fix css
const visible = isOpen ? 'visible opacity-1' : 'invisible opacity-0';
return (
1 && SHOW_CHILDREN_DIMENSIONS) {
+ let childrenDimensions: JSX.Element | null = null;
+ if (props.model.properties.showChildrenDimensions && props.model.children.length > 1 && SHOW_CHILDREN_DIMENSIONS) {
const {
childrenId, xChildrenStart, xChildrenEnd, yChildren, textChildren
} = GetChildrenDimensionProps(props, dimensionMargin);
- dimensionChildren = ;
}
+ const borrowerDimensions: JSX.Element[] = [];
+ if (props.model.properties.isDimensionBorrower && SHOW_BORROWER_DIMENSIONS) {
+ const it = MakeIterator(props.model);
+ const marks = [];
+ for (const container of it) {
+ if (!container.properties.markPositionToDimensionBorrower) {
+ continue;
+ }
+
+ const x = TransformX(
+ container.properties.x,
+ container.properties.width,
+ container.properties.xPositionReference
+ );
+ const [restoredX] = CancelParentTransform(container.parent, x, 0, props.model);
+ marks.push(
+ restoredX
+ );
+ }
+ marks.push(0);
+ marks.push(props.model.properties.width);
+ marks.sort((a, b) => a - b);
+ let count = 0;
+ for (const { cur, next } of Pairwise(marks)) {
+ const id = `dim-borrow-${props.model.properties.id}-{${count}}`;
+ borrowerDimensions.push();
+ count++;
+ }
+ }
+
return (
- {SHOW_PARENT_DIMENSION
+ {(props.model.properties.showSelfDimensions && SHOW_SELF_DIMENSIONS)
?
: null}
- {dimensionChildren}
+ {childrenDimensions}
+ {borrowerDimensions}
{svg}
{SHOW_TEXT
? by a customized "SVG". It is not really an svg but it at least allows
diff --git a/src/utils/default.ts b/src/utils/default.ts
index 74f1512..cc4b68a 100644
--- a/src/utils/default.ts
+++ b/src/utils/default.ts
@@ -16,9 +16,10 @@ export const DEFAULTCHILDTYPE_MAX_DEPTH = 10;
/// DIMENSIONS DEFAULTS ///
-export const SHOW_PARENT_DIMENSION = true;
+export const SHOW_SELF_DIMENSIONS = true;
export const SHOW_CHILDREN_DIMENSIONS = false;
-export const SHOW_DIMENSIONS_PER_DEPTH = true;
+export const SHOW_BORROWER_DIMENSIONS = true;
+export const SHOW_DIMENSIONS_PER_DEPTH = false;
export const DIMENSION_MARGIN = 50;
export const NOTCHES_LENGTH = 4;
@@ -51,7 +52,7 @@ export function GetDefaultEditorState(configuration: IConfiguration): IEditorSta
history: [
{
lastAction: '',
- mainContainer: mainContainer,
+ mainContainer,
selectedContainerId: mainContainer.properties.id,
typeCounters: {},
symbols: new Map(),
@@ -110,6 +111,10 @@ export const DEFAULT_MAINCONTAINER_PROPS: IContainerProperties = {
isAnchor: false,
isFlex: false,
xPositionReference: XPositionReference.Left,
+ showChildrenDimensions: true, // TODO: put the dimension at the top (see pdf)
+ showSelfDimensions: true, // TODO: put the dimension at the bottom (see pdf)
+ isDimensionBorrower: true, // second dimensions from the bottom
+ markPositionToDimensionBorrower: false,
style: {
stroke: 'black',
fillOpacity: 0
@@ -150,6 +155,10 @@ export function GetDefaultContainerProps(type: string,
xPositionReference: containerConfig.XPositionReference ?? XPositionReference.Left,
minWidth: containerConfig.MinWidth ?? 1,
maxWidth: containerConfig.MaxWidth ?? Number.MAX_SAFE_INTEGER,
+ showChildrenDimensions: containerConfig.ShowChildrenDimensions ?? false,
+ showSelfDimensions: containerConfig.ShowSelfDimensions ?? false,
+ markPositionToDimensionBorrower: containerConfig.MarkPositionToDimensionBorrower ?? false,
+ isDimensionBorrower: containerConfig.IsDimensionBorrower ?? false,
customSVG: containerConfig.CustomSVG,
style: structuredClone(containerConfig.Style),
userData: structuredClone(containerConfig.UserData)
diff --git a/src/utils/itertools.ts b/src/utils/itertools.ts
index c4bb188..b664ca7 100644
--- a/src/utils/itertools.ts
+++ b/src/utils/itertools.ts
@@ -83,9 +83,14 @@ export function GetAbsolutePosition(container: IContainerModel): [number, number
* @param y value to be restored
* @returns x and y such that the transformations of the parent are cancelled
*/
-export function CancelParentTransform(parent: IContainerModel | null, x: number, y: number): [number, number] {
+export function CancelParentTransform(
+ parent: IContainerModel | null,
+ x: number,
+ y: number,
+ stop?: IContainerModel
+): [number, number] {
let current = parent;
- while (current != null) {
+ while (current !== stop && current != null) {
x += current.properties.x;
y += current.properties.y;
current = current.parent;
diff --git a/test-server/http.js b/test-server/http.js
index 465e6f9..4e8d2eb 100644
--- a/test-server/http.js
+++ b/test-server/http.js
@@ -61,7 +61,9 @@ const GetSVGLayoutConfiguration = () => {
strokeWidth: 2,
stroke: 'red',
fill: '#d3c9b7',
- }
+ },
+ ShowSelfDimensions: true,
+ IsDimensionBorrower: true
},
{
Type: 'Trou',
@@ -117,6 +119,19 @@ const GetSVGLayoutConfiguration = () => {
Type: 'Montant',
Width: 10,
XPositionReference: 1,
+ MarkPositionToDimensionBorrower: true,
+ Style: {
+ fillOpacity: 0,
+ strokeWidth: 2,
+ stroke: '#713f12',
+ fill: '#713f12',
+ }
+ },
+ {
+ Type: 'Dilatation',
+ Width: 2,
+ XPositionReference: 1,
+ MarkPositionToDimensionBorrower: true,
Style: {
fillOpacity: 0,
strokeWidth: 2,