Moved usage of Dimension directly inside the Container class and disable DimensionLayer
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8cee366484
commit
c5171caaaa
3 changed files with 35 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import Properties from '../../../Interfaces/Properties';
|
import Properties from '../../../Interfaces/Properties';
|
||||||
|
import { Dimension } from './Dimension';
|
||||||
|
|
||||||
interface IContainerProps {
|
interface IContainerProps {
|
||||||
// eslint-disable-next-line no-use-before-define
|
// eslint-disable-next-line no-use-before-define
|
||||||
|
@ -10,6 +11,8 @@ interface IContainerProps {
|
||||||
userData?: Record<string, string | number>
|
userData?: Record<string, string | number>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GAP = 50;
|
||||||
|
|
||||||
export class Container extends React.Component<IContainerProps> {
|
export class Container extends React.Component<IContainerProps> {
|
||||||
componentWillUnMount() {
|
componentWillUnMount() {
|
||||||
}
|
}
|
||||||
|
@ -59,18 +62,37 @@ export class Container extends React.Component<IContainerProps> {
|
||||||
transitionTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1)',
|
transitionTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1)',
|
||||||
transitionDuration: '150ms'
|
transitionDuration: '150ms'
|
||||||
} as React.CSSProperties;
|
} as React.CSSProperties;
|
||||||
const style = Object.assign(defaultStyle, this.props.properties);
|
|
||||||
|
const style = Object.assign(
|
||||||
|
JSON.parse(JSON.stringify(defaultStyle)),
|
||||||
|
this.props.properties
|
||||||
|
);
|
||||||
style.x = 0;
|
style.x = 0;
|
||||||
style.y = 0;
|
style.y = 0;
|
||||||
delete style.height;
|
delete style.height;
|
||||||
delete style.width;
|
delete style.width;
|
||||||
|
|
||||||
|
const id = `dim-${this.props.properties.id}`;
|
||||||
|
const xStart: number = 0;
|
||||||
|
const xEnd = Number(this.props.properties.width);
|
||||||
|
const y = -(GAP * (this.getDepth() + 1));
|
||||||
|
const strokeWidth = 1;
|
||||||
|
const text = (this.props.properties.width ?? 0).toString();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<g
|
<g
|
||||||
style={defaultStyle}
|
style={defaultStyle}
|
||||||
transform={`translate(${this.props.properties.x}, ${this.props.properties.y})`}
|
transform={`translate(${this.props.properties.x}, ${this.props.properties.y})`}
|
||||||
key={`container-${this.props.properties.id}`}
|
key={`container-${this.props.properties.id}`}
|
||||||
>
|
>
|
||||||
|
<Dimension
|
||||||
|
id={id}
|
||||||
|
xStart={xStart}
|
||||||
|
xEnd={xEnd}
|
||||||
|
y={y}
|
||||||
|
strokeWidth={strokeWidth}
|
||||||
|
text={text}
|
||||||
|
/>
|
||||||
<rect
|
<rect
|
||||||
width={this.props.properties.width}
|
width={this.props.properties.width}
|
||||||
height={this.props.properties.height}
|
height={this.props.properties.height}
|
||||||
|
|
|
@ -35,6 +35,18 @@ const getDimensionsNodes = (root: Container): React.ReactNode[] => {
|
||||||
return dimensions;
|
return dimensions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A layer containing all dimension
|
||||||
|
*
|
||||||
|
* @deprecated In order to avoid adding complexity
|
||||||
|
* with computing the position in a group hierarchy,
|
||||||
|
* use Dimension directly inside the Container,
|
||||||
|
* Currently it is glitched as
|
||||||
|
* it does not take parents into account,
|
||||||
|
* and will not work correctly
|
||||||
|
* @param props
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
export const DimensionLayer: React.FC<IDimensionLayerProps> = (props: IDimensionLayerProps) => {
|
export const DimensionLayer: React.FC<IDimensionLayerProps> = (props: IDimensionLayerProps) => {
|
||||||
let dimensions: React.ReactNode[] = [];
|
let dimensions: React.ReactNode[] = [];
|
||||||
if (Array.isArray(props.roots)) {
|
if (Array.isArray(props.roots)) {
|
||||||
|
|
|
@ -80,7 +80,6 @@ export class SVG extends React.Component<ISVGProps> {
|
||||||
>
|
>
|
||||||
<svg ref={this.svg} {...properties}>
|
<svg ref={this.svg} {...properties}>
|
||||||
{ children }
|
{ children }
|
||||||
<DimensionLayer isHidden={false} roots={this.props.children} />
|
|
||||||
</svg>
|
</svg>
|
||||||
</ReactSVGPanZoom>
|
</ReactSVGPanZoom>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue