sprotty
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -37,2 +37,3 @@ "use strict"; | ||
const types_1 = require("../../base/types"); | ||
const model_3 = require("../move/model"); | ||
let EdgeLayoutPostprocessor = class EdgeLayoutPostprocessor { | ||
@@ -46,3 +47,3 @@ /** | ||
decorate(vnode, element) { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
if ((0, model_2.isEdgeLayoutable)(element) && element.parent instanceof sgraph_1.SEdgeImpl) { | ||
@@ -59,30 +60,29 @@ if (element.bounds !== geometry_1.Bounds.EMPTY) { | ||
let transform = ''; | ||
// Calculation of potential free movement. Just add the actual bounds to the point on edge. | ||
const freeTransform = `translate(${((_a = pointOnEdge === null || pointOnEdge === void 0 ? void 0 : pointOnEdge.x) !== null && _a !== void 0 ? _a : 0) + actualBounds.x}, ${((_b = pointOnEdge === null || pointOnEdge === void 0 ? void 0 : pointOnEdge.y) !== null && _b !== void 0 ? _b : 0) + actualBounds.y})`; | ||
// get the relative position on segment. This can be later changed if the moveMode is set to 'edge'. | ||
let derivativeOnEdge = router.derivativeAt(edge, position); | ||
; | ||
// Check if edgeplacement is set. If not the label is freely movable if movefeature is enabled for such labels. | ||
if (hasOwnPlacement) { | ||
if (pointOnEdge) { | ||
let derivativeOnEdge; | ||
// handle different move modes | ||
if (placement.moveMode && placement.moveMode !== 'edge') { | ||
// get the relative position on segment | ||
derivativeOnEdge = router.derivativeAt(edge, position); | ||
// handle free move mode | ||
if (placement.moveMode === 'free') { | ||
transform += freeTransform; | ||
} | ||
else { | ||
// The moveMode is neither 'edge' nor 'free' so it is 'none'. Hence the label is not movable and gets the fixed point on edge. | ||
if (pointOnEdge) { | ||
if (hasOwnPlacement) { | ||
switch (placement.moveMode) { | ||
case 'edge': | ||
// Find orthogonal intersection point on edge and use it as the label's position | ||
const orthogonalPoint = router.findOrthogonalIntersection(edge, geometry_1.Point.add(pointOnEdge, actualBounds)); | ||
if (orthogonalPoint) { | ||
derivativeOnEdge = orthogonalPoint.derivative; | ||
transform += `translate(${orthogonalPoint.point.x}, ${orthogonalPoint.point.y})`; | ||
} | ||
break; | ||
case 'free': | ||
// Calculation of potential free movement. Just add the actual bounds to the point on edge. | ||
transform += `translate(${((_a = pointOnEdge === null || pointOnEdge === void 0 ? void 0 : pointOnEdge.x) !== null && _a !== void 0 ? _a : 0) + actualBounds.x}, ${((_b = pointOnEdge === null || pointOnEdge === void 0 ? void 0 : pointOnEdge.y) !== null && _b !== void 0 ? _b : 0) + actualBounds.y})`; | ||
; | ||
break; | ||
case 'none': | ||
transform += `translate(${pointOnEdge.x}, ${pointOnEdge.y})`; | ||
} | ||
break; | ||
default: | ||
this.logger.error({}, 'No moveMode set for edge label. Skipping edge placement.'); | ||
break; | ||
} | ||
else { | ||
// no movemode was set or set to 'edge': label movement is constrained to the edge | ||
// Find orthogonal intersection point on edge and use it as the label's position | ||
const orthogonalPoint = router.findOrthogonalIntersection(edge, geometry_1.Point.add(pointOnEdge, actualBounds)); | ||
if (orthogonalPoint) { | ||
derivativeOnEdge = orthogonalPoint.derivative; | ||
transform += `translate(${orthogonalPoint.point.x}, ${orthogonalPoint.point.y})`; | ||
} | ||
} | ||
if (derivativeOnEdge) { | ||
@@ -111,6 +111,14 @@ const angle = (0, geometry_1.toDegrees)(Math.atan2(derivativeOnEdge.y, derivativeOnEdge.x)); | ||
} | ||
else { | ||
// if the element is moveable and no placement is specified, the label is freely movable (i.e. moveMode = 'free'). | ||
// Otherwise it is fixed to its position (i.e. moveMode = 'none'). | ||
if ((0, model_3.isMoveable)(element)) { | ||
transform += `translate(${((_c = pointOnEdge === null || pointOnEdge === void 0 ? void 0 : pointOnEdge.x) !== null && _c !== void 0 ? _c : 0) + actualBounds.x}, ${((_d = pointOnEdge === null || pointOnEdge === void 0 ? void 0 : pointOnEdge.y) !== null && _d !== void 0 ? _d : 0) + actualBounds.y})`; | ||
; | ||
} | ||
else { | ||
transform += `translate(${pointOnEdge.x}, ${pointOnEdge.y})`; | ||
} | ||
} | ||
} | ||
else { | ||
transform += freeTransform; | ||
} | ||
(0, vnode_utils_1.setAttr)(vnode, 'transform', transform); | ||
@@ -175,3 +183,7 @@ } | ||
} | ||
return allPlacements.reverse().reduce((a, b) => { return Object.assign(Object.assign({}, a), b); }, model_2.DEFAULT_EDGE_PLACEMENT); | ||
const edgePlacement = allPlacements.reverse().reduce((a, b) => { return Object.assign(Object.assign({}, a), b); }, model_2.DEFAULT_EDGE_PLACEMENT); | ||
if (!edgePlacement.moveMode) { | ||
edgePlacement.moveMode = (0, model_3.isMoveable)(element) ? 'edge' : 'none'; | ||
} | ||
return edgePlacement; | ||
} | ||
@@ -178,0 +190,0 @@ getAlignment(label, placement, angle) { |
/******************************************************************************** | ||
* Copyright (c) 2017-2018 TypeFox and others. | ||
* Copyright (c) 2017-2024 TypeFox and others. | ||
* | ||
@@ -4,0 +4,0 @@ * This program and the accompanying materials are made available under the |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2017-2018 TypeFox and others. | ||
* Copyright (c) 2017-2024 TypeFox and others. | ||
* | ||
@@ -44,5 +44,4 @@ * This program and the accompanying materials are made available under the | ||
position: 0.5, | ||
offset: 7, | ||
moveMode: 'edge' | ||
offset: 7 | ||
}; | ||
//# sourceMappingURL=model.js.map |
{ | ||
"name": "sprotty", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A next-gen framework for graphical views", | ||
@@ -5,0 +5,0 @@ "license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)", |
@@ -31,2 +31,3 @@ /******************************************************************************** | ||
import { ILogger } from '../../utils/logging'; | ||
import { isMoveable } from '../move/model'; | ||
@@ -57,27 +58,26 @@ @injectable() | ||
let transform = ''; | ||
// Calculation of potential free movement. Just add the actual bounds to the point on edge. | ||
const freeTransform = `translate(${(pointOnEdge?.x ?? 0) + actualBounds.x}, ${(pointOnEdge?.y ?? 0) + actualBounds.y})`; | ||
// get the relative position on segment. This can be later changed if the moveMode is set to 'edge'. | ||
let derivativeOnEdge = router.derivativeAt(edge, position);; | ||
// Check if edgeplacement is set. If not the label is freely movable if movefeature is enabled for such labels. | ||
if (hasOwnPlacement) { | ||
if (pointOnEdge) { | ||
let derivativeOnEdge: Point | undefined; | ||
// handle different move modes | ||
if (placement.moveMode && placement.moveMode !== 'edge') { | ||
// get the relative position on segment | ||
derivativeOnEdge = router.derivativeAt(edge, position); | ||
// handle free move mode | ||
if (placement.moveMode === 'free') { | ||
transform += freeTransform; | ||
} else { | ||
// The moveMode is neither 'edge' nor 'free' so it is 'none'. Hence the label is not movable and gets the fixed point on edge. | ||
if (pointOnEdge) { | ||
if (hasOwnPlacement) { | ||
switch (placement.moveMode) { | ||
case 'edge': | ||
// Find orthogonal intersection point on edge and use it as the label's position | ||
const orthogonalPoint = router.findOrthogonalIntersection(edge, Point.add(pointOnEdge, actualBounds)); | ||
if (orthogonalPoint) { | ||
derivativeOnEdge = orthogonalPoint.derivative; | ||
transform += `translate(${orthogonalPoint.point.x}, ${orthogonalPoint.point.y})`; | ||
} | ||
break; | ||
case 'free': | ||
// Calculation of potential free movement. Just add the actual bounds to the point on edge. | ||
transform += `translate(${(pointOnEdge?.x ?? 0) + actualBounds.x}, ${(pointOnEdge?.y ?? 0) + actualBounds.y})`;; | ||
break; | ||
case 'none': | ||
transform += `translate(${pointOnEdge.x}, ${pointOnEdge.y})`; | ||
} | ||
} else { | ||
// no movemode was set or set to 'edge': label movement is constrained to the edge | ||
// Find orthogonal intersection point on edge and use it as the label's position | ||
const orthogonalPoint = router.findOrthogonalIntersection(edge, Point.add(pointOnEdge, actualBounds)); | ||
if (orthogonalPoint) { | ||
derivativeOnEdge = orthogonalPoint.derivative; | ||
transform += `translate(${orthogonalPoint.point.x}, ${orthogonalPoint.point.y})`; | ||
} | ||
break; | ||
default: | ||
this.logger.error({}, 'No moveMode set for edge label. Skipping edge placement.'); | ||
break; | ||
} | ||
@@ -105,5 +105,11 @@ if (derivativeOnEdge) { | ||
} | ||
} else { | ||
// if the element is moveable and no placement is specified, the label is freely movable (i.e. moveMode = 'free'). | ||
// Otherwise it is fixed to its position (i.e. moveMode = 'none'). | ||
if (isMoveable(element)) { | ||
transform += `translate(${(pointOnEdge?.x ?? 0) + actualBounds.x}, ${(pointOnEdge?.y ?? 0) + actualBounds.y})`;; | ||
} else { | ||
transform += `translate(${pointOnEdge.x}, ${pointOnEdge.y})`; | ||
} | ||
} | ||
} else { | ||
transform += freeTransform; | ||
} | ||
@@ -170,4 +176,10 @@ setAttr(vnode, 'transform', transform); | ||
} | ||
return allPlacements.reverse().reduce( | ||
const edgePlacement = allPlacements.reverse().reduce( | ||
(a, b) => { return {...a, ...b}; }, DEFAULT_EDGE_PLACEMENT); | ||
if (!edgePlacement.moveMode) { | ||
edgePlacement.moveMode = isMoveable(element) ? 'edge' : 'none'; | ||
} | ||
return edgePlacement; | ||
} | ||
@@ -174,0 +186,0 @@ |
/******************************************************************************** | ||
* Copyright (c) 2017-2018 TypeFox and others. | ||
* Copyright (c) 2017-2024 TypeFox and others. | ||
* | ||
@@ -85,4 +85,3 @@ * This program and the accompanying materials are made available under the | ||
position: 0.5, | ||
offset: 7, | ||
moveMode: 'edge' | ||
offset: 7 | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2743457
44837