[Update] Positions/calcs finitions

This commit is contained in:
Carl Fuchs 2023-02-20 17:17:32 +01:00
parent 387e103501
commit 174767f22c
4 changed files with 36 additions and 34 deletions

View file

@ -7,7 +7,9 @@ export function ApplySymbol(containers: Map<string, IContainerModel>,
container: IContainerModel, container: IContainerModel,
symbol: ISymbolModel): IContainerModel { symbol: ISymbolModel): IContainerModel {
if (symbol.isVertical) { if (symbol.isVertical) {
container.properties.y = TransformY(symbol.offset, 0, symbol.config.PositionReference); container.properties.y = TransformY(symbol.offset + (symbol.height / 2),
symbol.height,
symbol.config.PositionReference);
container.properties.y = RestoreY(container.properties.y, container.properties.y = RestoreY(container.properties.y,
container.properties.height, container.properties.height,
container.properties.positionReference); container.properties.positionReference);

View file

@ -45,12 +45,15 @@ function ActionByPosition(
switch (position) { switch (position) {
case Position.Left: case Position.Left:
incrementVerticalDepthSymbols = true; incrementVerticalDepthSymbols = true;
verticalAction(dim, false, ...params);
break;
case Position.Right: { case Position.Right: {
const isRight = position === Position.Right; verticalAction(dim, true, ...params);
verticalAction(dim, isRight, ...params);
break; break;
} }
case Position.Down: case Position.Down:
horizontalAction(dim, ...params);
break;
case Position.Up: case Position.Up:
incrementHorizontalDepthSymbols = true; incrementHorizontalDepthSymbols = true;
horizontalAction(dim, ...params); horizontalAction(dim, ...params);
@ -102,7 +105,8 @@ function Dimensions({ containers, symbols, root, scale }: IDimensionLayerProps):
if (incrementVerticalDepthSymbol) { startDepthVerticalSymbols++; } if (incrementVerticalDepthSymbol) { startDepthVerticalSymbols++; }
} }
if (SHOW_SELF_MARGINS_DIMENSIONS && container.properties.dimensionOptions.selfMarginsDimensions.positions.length > 0) { if (SHOW_SELF_MARGINS_DIMENSIONS &&
container.properties.dimensionOptions.selfMarginsDimensions.positions.length > 0) {
const [incrementHorizontalDepthSymbol, incrementVerticalDepthSymbol] = ActionByPosition( const [incrementHorizontalDepthSymbol, incrementVerticalDepthSymbol] = ActionByPosition(
dimMapped, dimMapped,
container.properties.dimensionOptions.selfMarginsDimensions.positions, container.properties.dimensionOptions.selfMarginsDimensions.positions,
@ -139,7 +143,9 @@ function Dimensions({ containers, symbols, root, scale }: IDimensionLayerProps):
if (incrementVerticalDepthSymbol) { startDepthVerticalSymbols++; } if (incrementVerticalDepthSymbol) { startDepthVerticalSymbols++; }
} }
if (SHOW_CHILDREN_DIMENSIONS && container.properties.dimensionOptions.childrenDimensions.positions.length > 0 && container.children.length >= 2) { if (SHOW_CHILDREN_DIMENSIONS &&
container.properties.dimensionOptions.childrenDimensions.positions.length > 0 &&
container.children.length >= 2) {
const [incrementHorizontalDepthSymbol, incrementVerticalDepthSymbol] = ActionByPosition( const [incrementHorizontalDepthSymbol, incrementVerticalDepthSymbol] = ActionByPosition(
dimMapped, dimMapped,
container.properties.dimensionOptions.childrenDimensions.positions, container.properties.dimensionOptions.childrenDimensions.positions,
@ -162,11 +168,11 @@ function Dimensions({ containers, symbols, root, scale }: IDimensionLayerProps):
for (const symbol of symbols) { for (const symbol of symbols) {
if (symbol[1].showDimension) { if (symbol[1].showDimension) {
startDepthHorizontalSymbols++; startDepthHorizontalSymbols++;
startDepthVerticalSymbols++;
if (symbol[1].isVertical) { if (symbol[1].isVertical) {
AddVerticalSymbolDimension(symbol[1], dimensions, scale, 'black', startDepthVerticalSymbols); AddVerticalSymbolDimension(symbol[1], dimensions, scale, startDepthVerticalSymbols);
} else { } else {
AddHorizontalSymbolDimension(symbol[1], dimensions, scale, 'black', startDepthHorizontalSymbols); AddHorizontalSymbolDimension(symbol[1], dimensions, scale, startDepthHorizontalSymbols);
} }
} }
} }
@ -177,7 +183,6 @@ function Dimensions({ containers, symbols, root, scale }: IDimensionLayerProps):
function AddHorizontalSymbolDimension(symbol: ISymbolModel, function AddHorizontalSymbolDimension(symbol: ISymbolModel,
dimensions: React.ReactNode[], dimensions: React.ReactNode[],
scale: number, scale: number,
color: string,
depth: number depth: number
): void { ): void {
const width = symbol.offset + (symbol.width / 2); const width = symbol.offset + (symbol.width / 2);
@ -206,7 +211,6 @@ function AddHorizontalSymbolDimension(symbol: ISymbolModel,
function AddVerticalSymbolDimension(symbol: ISymbolModel, function AddVerticalSymbolDimension(symbol: ISymbolModel,
dimensions: React.ReactNode[], dimensions: React.ReactNode[],
scale: number, scale: number,
color: string,
depth: number depth: number
): void { ): void {
const height = symbol.offset + (symbol.height / 2); const height = symbol.offset + (symbol.height / 2);
@ -265,8 +269,12 @@ function AddHorizontalChildrenDimension(
return; return;
} }
let xChildrenStart = TransformX(lastChild.properties.x, lastChild.properties.width, lastChild.properties.positionReference); let xChildrenStart = TransformX(lastChild.properties.x,
let xChildrenEnd = TransformX(lastChild.properties.x, lastChild.properties.width, lastChild.properties.positionReference); lastChild.properties.width,
lastChild.properties.positionReference);
let xChildrenEnd = TransformX(lastChild.properties.x,
lastChild.properties.width,
lastChild.properties.positionReference);
// Find the min and max // Find the min and max
for (let i = container.children.length - 2; i >= 0; i--) { for (let i = container.children.length - 2; i >= 0; i--) {
@ -328,8 +336,12 @@ function AddVerticalChildrenDimension(
return; return;
} }
let yChildrenStart = TransformY(lastChild.properties.y, lastChild.properties.height, lastChild.properties.positionReference); let yChildrenStart = TransformY(lastChild.properties.y,
let yChildrenEnd = TransformY(lastChild.properties.y, lastChild.properties.height, lastChild.properties.positionReference); lastChild.properties.height,
lastChild.properties.positionReference);
let yChildrenEnd = TransformY(lastChild.properties.y,
lastChild.properties.height,
lastChild.properties.positionReference);
// Find the min and max // Find the min and max
for (let i = container.children.length - 2; i >= 0; i--) { for (let i = container.children.length - 2; i >= 0; i--) {

View file

@ -27,19 +27,14 @@ export function SelectorSymbol(props: ISelectorSymbolProps): JSX.Element {
let x, y: number; let x, y: number;
if (props.selected.isVertical) { if (props.selected.isVertical) {
x = -SYMBOL_MARGIN; x = -SYMBOL_MARGIN / scale - width;
y = (props.selected.offset + props.selected.height / 2) - height; y = (props.selected.offset + props.selected.height / 2) - (props.selected.height / scale / 2);
} else { } else {
[x, y] = [ [x, y] = [
props.selected.offset + props.selected.width / 2, (props.selected.offset + props.selected.width / 2) - (props.selected.width / scale / 2),
-SYMBOL_MARGIN - height]; -SYMBOL_MARGIN / scale - height];
} }
const style: React.CSSProperties = {
transform: 'translateX(-50%)',
transformBox: 'fill-box'
};
return ( return (
<Selector <Selector
text={props.selected.displayedText} text={props.selected.displayedText}
@ -48,7 +43,6 @@ export function SelectorSymbol(props: ISelectorSymbolProps): JSX.Element {
width={width} width={width}
height={height} height={height}
scale={scale} scale={scale}
style={style}
/> />
); );
} }

View file

@ -37,22 +37,16 @@ export function Symbol(props: ISymbolProps): JSX.Element {
); );
} }
if (props.model.isVertical) { if (props.model.isVertical) {
x = -SYMBOL_MARGIN; x = (-SYMBOL_MARGIN - props.model.height) / props.scale;
y = props.model.offset + props.model.height / 2; y = (props.model.offset + props.model.height / 2) - (props.model.height / props.scale / 2);
} else { } else {
x = props.model.offset + props.model.width / 2; x = (props.model.offset + props.model.width / 2) - (props.model.width / props.scale / 2);
y = -SYMBOL_MARGIN; y = (-SYMBOL_MARGIN - props.model.width) / props.scale;
} }
return ( return (
<image <image
href={href} href={href}
preserveAspectRatio="none" preserveAspectRatio="none"
style={{
fill: 'none',
transform: 'translateY(-100%) translateX(-50%)',
transformBox: 'fill-box'
}}
x={x} x={x}
y={y} y={y}
height={props.model.height / props.scale} height={props.model.height / props.scale}