Refactor DimensionLayer for more readability
This commit is contained in:
parent
fe72768142
commit
b2fa591f14
1 changed files with 49 additions and 44 deletions
|
@ -145,55 +145,23 @@ function Dimensions({ containers, symbols, root, scale }: IDimensionLayerProps):
|
||||||
}
|
}
|
||||||
|
|
||||||
let startDepthSymbols: number = 0;
|
let startDepthSymbols: number = 0;
|
||||||
for (const symbol of symbols) {
|
symbols.forEach((symbol: ISymbolModel) => {
|
||||||
if (symbol[1].showDimension) {
|
if (!symbol.showDimension) {
|
||||||
startDepthSymbols++;
|
return;
|
||||||
AddHorizontalSymbolDimension(
|
|
||||||
symbol[1],
|
|
||||||
dimensions,
|
|
||||||
scale,
|
|
||||||
startDepthSymbols
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
startDepthSymbols++;
|
||||||
|
AddHorizontalSymbolDimension(
|
||||||
|
symbol,
|
||||||
|
dimensions,
|
||||||
|
scale,
|
||||||
|
startDepthSymbols
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return dimensions;
|
return dimensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
function AddHorizontalSymbolDimension(
|
|
||||||
symbol: ISymbolModel,
|
|
||||||
dimensions: React.ReactNode[],
|
|
||||||
scale: number,
|
|
||||||
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();
|
|
||||||
|
|
||||||
// TODO: Put this in default.ts
|
|
||||||
const defaultDimensionSymbolStyle: IDimensionStyle = {
|
|
||||||
color: 'black'
|
|
||||||
};
|
|
||||||
dimensions.push(
|
|
||||||
<Dimension
|
|
||||||
key={id}
|
|
||||||
id={id}
|
|
||||||
xStart={0}
|
|
||||||
yStart={-offset}
|
|
||||||
xEnd={width}
|
|
||||||
yEnd={-offset}
|
|
||||||
text={text}
|
|
||||||
scale={scale}
|
|
||||||
style={defaultDimensionSymbolStyle}/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A layer containing all dimension
|
* A layer containing all dimension
|
||||||
* @param props
|
* @param props
|
||||||
|
@ -643,3 +611,40 @@ function AddVerticalSelfMarginDimension(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function AddHorizontalSymbolDimension(
|
||||||
|
symbol: ISymbolModel,
|
||||||
|
dimensions: React.ReactNode[],
|
||||||
|
scale: number,
|
||||||
|
depth: number
|
||||||
|
): void {
|
||||||
|
const width = symbol.x + (symbol.width / 2);
|
||||||
|
|
||||||
|
if (width == null || width <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
// TODO: Put this in default.ts
|
||||||
|
const defaultDimensionSymbolStyle: IDimensionStyle = {
|
||||||
|
color: 'black'
|
||||||
|
};
|
||||||
|
dimensions.push(
|
||||||
|
<Dimension
|
||||||
|
key={id}
|
||||||
|
id={id}
|
||||||
|
xStart={0}
|
||||||
|
yStart={-offset}
|
||||||
|
xEnd={width}
|
||||||
|
yEnd={-offset}
|
||||||
|
text={text}
|
||||||
|
scale={scale}
|
||||||
|
style={defaultDimensionSymbolStyle}/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue