diff --git a/csharp/SVGLDLibs/SVGLDLibs/Models/SymbolModel.cs b/csharp/SVGLDLibs/SVGLDLibs/Models/SymbolModel.cs index 5e16bdf..4218a42 100644 --- a/csharp/SVGLDLibs/SVGLDLibs/Models/SymbolModel.cs +++ b/csharp/SVGLDLibs/SVGLDLibs/Models/SymbolModel.cs @@ -1,4 +1,4 @@ -using System.Runtime.Serialization; +using System.Runtime.Serialization; using System.Collections.Generic; namespace SVGLDLibs.Models @@ -26,5 +26,8 @@ namespace SVGLDLibs.Models [DataMember(EmitDefaultValue = false)] public List linkedContainers { get; set; } + + [DataMember(EmitDefaultValue = false)] + public List showDimension { get; set; } } } \ No newline at end of file diff --git a/src/Components/ContainerProperties/ContainerForm.tsx b/src/Components/ContainerProperties/ContainerForm.tsx index 55c8224..4bdc262 100644 --- a/src/Components/ContainerProperties/ContainerForm.tsx +++ b/src/Components/ContainerProperties/ContainerForm.tsx @@ -5,10 +5,18 @@ import { ISymbolModel } from '../../Interfaces/ISymbolModel'; import { SHOW_BORROWER_DIMENSIONS, SHOW_CHILDREN_DIMENSIONS, - SHOW_SELF_DIMENSIONS, - SHOW_SELF_MARGINS_DIMENSIONS + SHOW_SELF_DIMENSIONS, SHOW_SELF_MARGINS_DIMENSIONS } from '../../utils/default'; -import { ApplyWidthMargin, ApplyXMargin, RemoveWidthMargin, RemoveXMargin, RestoreX, RestoreY, TransformX, TransformY } from '../../utils/svg'; +import { + ApplyWidthMargin, + ApplyXMargin, + RemoveWidthMargin, + RemoveXMargin, + RestoreX, + RestoreY, + TransformX, + TransformY +} from '../../utils/svg'; import { Text } from '../Text/Text'; import { InputGroup } from '../InputGroup/InputGroup'; import { TextInputGroup } from '../InputGroup/TextInputGroup'; @@ -38,7 +46,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element { inputClassName='' type='string' value={props.properties.displayedText?.toString()} - onChange={(value) => props.onChange('displayedText', value)} /> + onChange={(value) => props.onChange('displayedText', value)}/> + isDisabled={true}/>
+ isDisabled={true}/>
+ isDisabled={true}/>
@@ -119,7 +127,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element { ), props.properties.margin.left ) - )} /> + )}/> + )}/> @@ -163,7 +171,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element { type='number' min={1} value={props.properties.minWidth.toString()} - onChange={(value) => props.onChange('minWidth', Number(value))} /> + onChange={(value) => props.onChange('minWidth', Number(value))}/> props.onChange('width', ApplyWidthMargin(Number(value), props.properties.margin.left, props.properties.margin.right))} - isDisabled={props.properties.isFlex} /> + isDisabled={props.properties.isFlex}/> props.onChange('maxWidth', Number(value))} /> + onChange={(value) => props.onChange('maxWidth', Number(value))}/>
props.onChange('minHeight', Number(value))} /> + onChange={(value) => props.onChange('minHeight', Number(value))}/> props.onChange('maxHeight', Number(value))} /> + onChange={(value) => props.onChange('maxHeight', Number(value))}/> @@ -239,7 +247,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element { type='number' min={0} value={(props.properties.margin.left ?? 0).toString()} - onChange={(value) => props.onChange('left', Number(value), PropertyType.Margin)} /> + onChange={(value) => props.onChange('left', Number(value), PropertyType.Margin)}/> props.onChange('bottom', Number(value), PropertyType.Margin)} /> + onChange={(value) => props.onChange('bottom', Number(value), PropertyType.Margin)}/> props.onChange('top', Number(value), PropertyType.Margin)} /> + onChange={(value) => props.onChange('top', Number(value), PropertyType.Margin)}/> props.onChange('right', Number(value), PropertyType.Margin)} /> + onChange={(value) => props.onChange('right', Number(value), PropertyType.Margin)}/> @@ -296,7 +304,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element { inputClassName='ml-auto mr-auto block' type={ToggleType.Full} checked={props.properties.isAnchor} - onChange={(event) => props.onChange('isAnchor', event.target.checked)} /> + onChange={(event) => props.onChange('isAnchor', event.target.checked)}/> @@ -326,7 +334,7 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element { value: symbol.id }))} value={props.properties.linkedSymbolId ?? ''} - onChange={(event) => props.onChange('linkedSymbolId', event.target.value)} /> + onChange={(event) => props.onChange('linkedSymbolId', event.target.value)}/> @@ -339,168 +347,168 @@ export function ContainerForm(props: IContainerFormProps): JSX.Element {
{ SHOW_SELF_DIMENSIONS && -
- props.onChange(key, value, PropertyType.SelfDimension)} - /> - props.onChange('color', e.target.value, PropertyType.SelfDimension)}/> -
+
+ props.onChange(key, value, PropertyType.SelfDimension)} + /> + props.onChange('color', e.target.value, PropertyType.SelfDimension)}/> +
} { SHOW_SELF_MARGINS_DIMENSIONS && -
- props.onChange(key, value, PropertyType.SelfMarginDimension)} - /> - props.onChange('color', e.target.value, PropertyType.SelfMarginDimension)}/> -
+
+ props.onChange(key, value, PropertyType.SelfMarginDimension)} + /> + props.onChange('color', e.target.value, PropertyType.SelfMarginDimension)}/> +
} { SHOW_CHILDREN_DIMENSIONS && -
- props.onChange(key, value, PropertyType.ChildrenDimensions)} - /> - props.onChange('color', e.target.value, PropertyType.ChildrenDimensions)}/> -
+
+ props.onChange(key, value, PropertyType.ChildrenDimensions)} + /> + props.onChange('color', e.target.value, PropertyType.ChildrenDimensions)}/> +
} { SHOW_BORROWER_DIMENSIONS && - <> -
- props.onChange(key, value, PropertyType.DimensionOptions)} - /> -
-
- props.onChange(key, value, PropertyType.DimensionWithMarks)} - /> - props.onChange('color', e.target.value, PropertyType.DimensionWithMarks)}/> -
- + <> +
+ props.onChange(key, value, PropertyType.DimensionOptions)} + /> +
+
+ props.onChange(key, value, PropertyType.DimensionWithMarks)} + /> + props.onChange('color', e.target.value, PropertyType.DimensionWithMarks)}/> +
+ }
- { props.properties.style !== undefined && - -
- props.onChange('stroke', value, PropertyType.Style)} - /> - props.onChange('strokeOpacity', Number(event.target.value), PropertyType.Style)} - /> - props.onChange('strokeWidth', Number(value), PropertyType.Style)} - /> - props.onChange('fill', value, PropertyType.Style)} - /> - props.onChange('fillOpacity', Number(event.target.value), PropertyType.Style)} - /> -
-
+ {props.properties.style !== undefined && + +
+ props.onChange('stroke', value, PropertyType.Style)} + /> + props.onChange('strokeOpacity', Number(event.target.value), PropertyType.Style)} + /> + props.onChange('strokeWidth', Number(value), PropertyType.Style)} + /> + props.onChange('fill', value, PropertyType.Style)} + /> + props.onChange('fillOpacity', Number(event.target.value), PropertyType.Style)} + /> +
+
} ); diff --git a/src/Components/SVG/Elements/DimensionLayer.tsx b/src/Components/SVG/Elements/DimensionLayer.tsx index c705909..62d8bef 100644 --- a/src/Components/SVG/Elements/DimensionLayer.tsx +++ b/src/Components/SVG/Elements/DimensionLayer.tsx @@ -12,9 +12,11 @@ import { import { FindContainerById, MakeRecursionDFSIterator, Pairwise } from '../../../utils/itertools'; import { TransformX, TransformY } from '../../../utils/svg'; import { Dimension } from './Dimension'; +import { ISymbolModel } from '../../../Interfaces/ISymbolModel'; interface IDimensionLayerProps { containers: Map + symbols: Map root: IContainerModel scale: number } @@ -35,7 +37,8 @@ function ActionByPosition( horizontalAction: (dim: number, ...params: any[]) => void, verticalAction: (dim: number, isRight: boolean, ...params: any[]) => void, params: any[] -): void { +): boolean { + let incrementDepthSymbols = false; positions.forEach((position: Position) => { const dim = dimMapped[position]; switch (position) { @@ -47,10 +50,12 @@ function ActionByPosition( } case Position.Down: case Position.Up: + incrementDepthSymbols = true; horizontalAction(dim, ...params); break; } }); + return incrementDepthSymbols; } /** @@ -58,7 +63,7 @@ function ActionByPosition( * @param param0 Object with the root container and the scale of the svg * @returns A list of dimensions */ -function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.ReactNode[] { +function Dimensions({ containers, symbols, root, scale }: IDimensionLayerProps): React.ReactNode[] { const it = MakeRecursionDFSIterator(root, containers, 0, [0, 0]); const dimensions: React.ReactNode[] = []; const topDim = root.properties.y; @@ -69,6 +74,7 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re if (!SHOW_SELF_DIMENSIONS) { return []; } + let startDepthSymbols: number = 0; for (const { container, depth, currentTransform } of it) { const offset = (DIMENSION_MARGIN * (depth + 1)) / scale; @@ -78,7 +84,7 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re const containerRightDim = rightDim + offset; const dimMapped = [containerLeftDim, containerBottomDim, containerTopDim, containerRightDim]; if (SHOW_SELF_DIMENSIONS && container.properties.dimensionOptions.selfDimensions.positions.length > 0) { - ActionByPosition( + const incrementDepthSymbol = ActionByPosition( dimMapped, container.properties.dimensionOptions.selfDimensions.positions, AddHorizontalSelfDimension, @@ -90,10 +96,11 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re scale, container.properties.dimensionOptions.selfDimensions.color] ); + if (incrementDepthSymbol) { startDepthSymbols++; } } if (SHOW_SELF_MARGINS_DIMENSIONS && container.properties.dimensionOptions.selfMarginsDimensions.positions.length > 0) { - ActionByPosition( + const incrementDepthSymbol = ActionByPosition( dimMapped, container.properties.dimensionOptions.selfMarginsDimensions.positions, AddHorizontalSelfMarginsDimension, @@ -105,12 +112,14 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re scale, container.properties.dimensionOptions.selfMarginsDimensions.color] ); + if (incrementDepthSymbol) { startDepthSymbols++; } } if (SHOW_BORROWER_DIMENSIONS && container.properties.dimensionOptions.dimensionWithMarks.positions.length > 0) { - ActionByPosition( + const incrementDepthSymbol = ActionByPosition( dimMapped, container.properties.dimensionOptions.dimensionWithMarks.positions, + AddHorizontalBorrowerDimension, AddVerticalBorrowerDimension, [ @@ -122,10 +131,11 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re scale, container.properties.dimensionOptions.dimensionWithMarks.color] ); + if (incrementDepthSymbol) { startDepthSymbols++; } } if (SHOW_CHILDREN_DIMENSIONS && container.properties.dimensionOptions.childrenDimensions.positions.length > 0 && container.children.length >= 2) { - ActionByPosition( + const incrementDepthSymbol = ActionByPosition( dimMapped, container.properties.dimensionOptions.childrenDimensions.positions, AddHorizontalChildrenDimension, @@ -138,12 +148,50 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re scale, container.properties.dimensionOptions.childrenDimensions.color] ); + + if (incrementDepthSymbol) { startDepthSymbols++; } + } + } + + for (const symbol of symbols) { + if (symbol[1].showDimension) { + startDepthSymbols++; + AddHorizontalSymbolDimension(symbol[1], dimensions, scale, 'black', startDepthSymbols); } } return dimensions; } +function AddHorizontalSymbolDimension(symbol: ISymbolModel, + dimensions: React.ReactNode[], + scale: number, + color: string, + depth: number +): void { + const width = symbol.x + (symbol.width / 2); + if (width != null && width > 0) { + const id = `dim-y-margin-left${symbol.width.toFixed(0)}-${symbol.id}`; + + const offset = (DIMENSION_MARGIN * (depth + 1)) / scale; + const text = width + .toFixed(0) + .toString(); + dimensions.push( + + ); + } +} + /** * A layer containing all dimension * @param props @@ -152,7 +200,7 @@ function Dimensions({ containers, root, scale }: IDimensionLayerProps): React.Re export function DimensionLayer(props: IDimensionLayerProps): JSX.Element { return ( - { Dimensions(props) } + {Dimensions(props)} ); } @@ -230,7 +278,6 @@ function AddVerticalChildrenDimension( dimensions: React.ReactNode[], scale: number, color: string - ): void { const childrenId = `dim-x${xDim.toFixed(0)}-children-${container.properties.id}`; @@ -451,7 +498,6 @@ function AddVerticalSelfDimension( } function AddHorizontalSelfDimension( - yDim: number, container: IContainerModel, currentTransform: [number, number], @@ -481,7 +527,6 @@ function AddHorizontalSelfDimension( } function AddHorizontalSelfMarginsDimension( - yDim: number, container: IContainerModel, currentTransform: [number, number], diff --git a/src/Components/SVG/SVG.tsx b/src/Components/SVG/SVG.tsx index 92d4095..cdb11de 100644 --- a/src/Components/SVG/SVG.tsx +++ b/src/Components/SVG/SVG.tsx @@ -97,7 +97,7 @@ export function SVG(props: ISVGProps): JSX.Element { {SHOW_DIMENSIONS_PER_DEPTH ? : null} - + {/* leave this at the end so it can be removed during the svg export */} diff --git a/src/Components/SymbolProperties/SymbolForm.tsx b/src/Components/SymbolProperties/SymbolForm.tsx index 0c9877d..9ffc727 100644 --- a/src/Components/SymbolProperties/SymbolForm.tsx +++ b/src/Components/SymbolProperties/SymbolForm.tsx @@ -4,6 +4,8 @@ import { RestoreX, TransformX } from '../../utils/svg'; import { InputGroup } from '../InputGroup/InputGroup'; import { TextInputGroup } from '../InputGroup/TextInputGroup'; import { Text } from '../Text/Text'; +import { PropertyType } from '../../Enums/PropertyType'; +import { ToggleButton } from '../ToggleButton/ToggleButton'; interface ISymbolFormProps { symbol: ISymbolModel @@ -60,6 +62,13 @@ export function SymbolForm(props: ISymbolFormProps): JSX.Element { min={0} value={props.symbol.width.toString()} onChange={(value) => props.onChange('width', Number(value))} /> + props.onChange('showDimension', e.target.checked)}/> ); } diff --git a/src/Interfaces/ISymbolModel.ts b/src/Interfaces/ISymbolModel.ts index f58af29..3a71290 100644 --- a/src/Interfaces/ISymbolModel.ts +++ b/src/Interfaces/ISymbolModel.ts @@ -26,4 +26,7 @@ export interface ISymbolModel { /** List of linked container id */ linkedContainers: Set + + /** Dimensions options */ + showDimension: boolean } diff --git a/src/utils/default.ts b/src/utils/default.ts index b0648b1..632c12a 100644 --- a/src/utils/default.ts +++ b/src/utils/default.ts @@ -313,6 +313,7 @@ export function GetDefaultSymbolModel(name: string, x: 0, width: symbolConfig.Width ?? DEFAULT_SYMBOL_WIDTH, height: symbolConfig.Height ?? DEFAULT_SYMBOL_HEIGHT, - linkedContainers: new Set() + linkedContainers: new Set(), + showDimension: false }; }