From d854218c9d0db9f6f7eba9035cbbec8334b195dc Mon Sep 17 00:00:00 2001 From: Siklos Date: Thu, 18 Aug 2022 13:05:47 +0200 Subject: [PATCH 1/3] Added new defaults settings --- src/Components/SVG/Elements/Container.tsx | 25 +++++++++++++---------- src/utils/default.ts | 16 ++++++++++----- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/Components/SVG/Elements/Container.tsx b/src/Components/SVG/Elements/Container.tsx index b6431fb..b6c42a9 100644 --- a/src/Components/SVG/Elements/Container.tsx +++ b/src/Components/SVG/Elements/Container.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { Interweave, Node } from 'interweave'; import { XPositionReference } from '../../../Enums/XPositionReference'; import { IContainerModel } from '../../../Interfaces/IContainerModel'; -import { DIMENSION_MARGIN } from '../../../utils/default'; +import { DIMENSION_MARGIN, SHOW_CHILDREN_DIMENSIONS, SHOW_PARENT_DIMENSION } from '../../../utils/default'; import { getDepth } from '../../../utils/itertools'; import { Dimension } from './Dimension'; import IProperties from '../../../Interfaces/IProperties'; @@ -54,7 +54,7 @@ export const Container: React.FC = (props: IContainerProps) => const text = (props.model.properties.width ?? 0).toString(); let dimensionChildren: JSX.Element | null = null; - if (props.model.children.length > 1) { + if (props.model.children.length > 1 && SHOW_CHILDREN_DIMENSIONS) { const { childrenId, xChildrenStart, @@ -79,15 +79,18 @@ export const Container: React.FC = (props: IContainerProps) => transform={transform} key={`container-${props.model.properties.id}`} > - + { SHOW_PARENT_DIMENSION + ? + : null + } { dimensionChildren } { svg } Date: Thu, 18 Aug 2022 13:06:01 +0200 Subject: [PATCH 2/3] itertools: Added bfs iterator --- src/utils/itertools.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/utils/itertools.ts b/src/utils/itertools.ts index 221d6c0..e52e034 100644 --- a/src/utils/itertools.ts +++ b/src/utils/itertools.ts @@ -22,6 +22,34 @@ export function * MakeIterator(root: IContainerModel): Generator { + const queue: IContainerModel[] = [root]; + let depth = 0; + while (queue.length > 0) { + let levelSize = queue.length; + while (levelSize-- !== 0) { + const container = queue.shift() as IContainerModel; + yield { + container, + depth + }; + + for (let i = container.children.length - 1; i >= 0; i--) { + const child = container.children[i]; + queue.push(child); + } + } + depth++; + } +} + /** * Returns the depth of the container * @returns The depth of the container From c8d73c4fcd4450f05616fb0ab93a66e6c02fcde0 Mon Sep 17 00:00:00 2001 From: Siklos Date: Thu, 18 Aug 2022 13:07:00 +0200 Subject: [PATCH 3/3] Restore DimensionLayer with BFS algorithm and usage of getAbsolutePosition --- .../SVG/Elements/DimensionLayer.tsx | 57 +++++++++++++++++++ src/Components/SVG/SVG.tsx | 2 + 2 files changed, 59 insertions(+) create mode 100644 src/Components/SVG/Elements/DimensionLayer.tsx diff --git a/src/Components/SVG/Elements/DimensionLayer.tsx b/src/Components/SVG/Elements/DimensionLayer.tsx new file mode 100644 index 0000000..e787bc1 --- /dev/null +++ b/src/Components/SVG/Elements/DimensionLayer.tsx @@ -0,0 +1,57 @@ +import * as React from 'react'; +import { ContainerModel } from '../../../Interfaces/IContainerModel'; +import { DIMENSION_MARGIN } from '../../../utils/default'; +import { getAbsolutePosition, MakeBFSIterator } from '../../../utils/itertools'; +import { transformX } from './Container'; +import { Dimension } from './Dimension'; + +interface IDimensionLayerProps { + roots: ContainerModel | ContainerModel[] | null +} + +const getDimensionsNodes = (root: ContainerModel): React.ReactNode[] => { + const it = MakeBFSIterator(root); + const dimensions: React.ReactNode[] = []; + for (const { container, depth } of it) { + const width = container.properties.width; + const id = `dim-${container.properties.id}`; + const xStart = getAbsolutePosition(container)[0]; + const xEnd = xStart + width; + const y = (container.properties.y + container.properties.height) + (DIMENSION_MARGIN * (depth + 1)); + const strokeWidth = 1; + const text = width.toString(); + dimensions.push( + + ); + } + return dimensions; +}; + +/** + * A layer containing all dimension + * @param props + * @returns + */ +export const DimensionLayer: React.FC = (props: IDimensionLayerProps) => { + let dimensions: React.ReactNode[] = []; + if (Array.isArray(props.roots)) { + props.roots.forEach(child => { + dimensions.concat(getDimensionsNodes(child)); + }); + } else if (props.roots !== null) { + dimensions = getDimensionsNodes(props.roots); + } + return ( + + { dimensions } + + ); +}; diff --git a/src/Components/SVG/SVG.tsx b/src/Components/SVG/SVG.tsx index 652258f..56e629d 100644 --- a/src/Components/SVG/SVG.tsx +++ b/src/Components/SVG/SVG.tsx @@ -4,6 +4,7 @@ import { Container } from './Elements/Container'; import { ContainerModel } from '../../Interfaces/IContainerModel'; import { Selector } from './Elements/Selector'; import { BAR_WIDTH } from '../Bar/Bar'; +import { DimensionLayer } from './Elements/DimensionLayer'; interface ISVGProps { width: number @@ -74,6 +75,7 @@ export const SVG: React.FC = (props: ISVGProps) => { { children } +