Compare commits

...

3 commits

Author SHA1 Message Date
c8d73c4fcd Restore DimensionLayer with BFS algorithm and usage of getAbsolutePosition
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-18 13:07:00 +02:00
d3e4a25ae0 itertools: Added bfs iterator 2022-08-18 13:06:01 +02:00
d854218c9d Added new defaults settings 2022-08-18 13:05:47 +02:00
5 changed files with 112 additions and 16 deletions

View file

@ -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<IContainerProps> = (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<IContainerProps> = (props: IContainerProps) =>
transform={transform}
key={`container-${props.model.properties.id}`}
>
<Dimension
id={id}
xStart={xStart}
xEnd={xEnd}
yStart={y}
yEnd={y}
strokeWidth={strokeWidth}
text={text}
/>
{ SHOW_PARENT_DIMENSION
? <Dimension
id={id}
xStart={xStart}
xEnd={xEnd}
yStart={y}
yEnd={y}
strokeWidth={strokeWidth}
text={text}
/>
: null
}
{ dimensionChildren }
{ svg }
<text

View file

@ -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(
<Dimension
id={id}
xStart={xStart}
yStart={y}
xEnd={xEnd}
yEnd={y}
strokeWidth={strokeWidth}
text={text}
/>
);
}
return dimensions;
};
/**
* A layer containing all dimension
* @param props
* @returns
*/
export const DimensionLayer: React.FC<IDimensionLayerProps> = (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 (
<g>
{ dimensions }
</g>
);
};

View file

@ -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<ISVGProps> = (props: ISVGProps) => {
<svg {...properties}>
{ children }
<Selector selected={props.selected} />
<DimensionLayer roots={props.children}/>
</svg>
</UncontrolledReactSVGPanZoom>
</div>

View file

@ -4,6 +4,17 @@ import { IConfiguration } from '../Interfaces/IConfiguration';
import { IContainerModel } from '../Interfaces/IContainerModel';
import IProperties from '../Interfaces/IProperties';
/// DIMENSIONS DEFAULTS ///
export const SHOW_PARENT_DIMENSION = true;
export const SHOW_CHILDREN_DIMENSIONS = true;
export const DIMENSION_MARGIN = 50;
export const NOTCHES_LENGTH = 4;
/// EDITOR DEFAULTS ///
export const MAX_HISTORY = 200;
export const DEFAULT_CONFIG: IConfiguration = {
AvailableContainers: [
{
@ -67,8 +78,3 @@ export const GetDefaultContainerProps = (
style: containerConfig.Style,
userData: containerConfig.UserData
});
export const DIMENSION_MARGIN = 50;
export const NOTCHES_LENGTH = 4;
export const MAX_HISTORY = 200;

View file

@ -22,6 +22,34 @@ export function * MakeIterator(root: IContainerModel): Generator<IContainerModel
}
}
export interface ContainerAndDepth {
container: IContainerModel
depth: number
}
/**
* Returns a Generator iterating of over the children depth-first
*/
export function * MakeBFSIterator(root: IContainerModel): Generator<ContainerAndDepth, void, unknown> {
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