@kieler/klighd-interactive
Advanced tools
Comparing version 0.5.0-next.c9365de to 0.5.0-next.c96847b
@@ -18,2 +18,4 @@ "use strict"; | ||
*/ | ||
// We follow Sprotty's way of redeclaring the interface and its create function, so disable this lint check for this file. | ||
/* eslint-disable no-redeclare */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,0 +22,0 @@ exports.DeleteConstraintAction = exports.RefreshDiagramAction = void 0; |
@@ -9,3 +9,3 @@ import { RectangularNode, SEdgeImpl, SParentElementImpl } from 'sprotty'; | ||
*/ | ||
export interface KGraphElement extends SParentElementImpl { | ||
export interface SKGraphElement extends SParentElementImpl { | ||
/** | ||
@@ -27,2 +27,6 @@ * May contain a trace that points back to the server instance where this element was created. | ||
opacity: number; | ||
/** | ||
* The properties of this element. | ||
*/ | ||
properties: Record<string, unknown>; | ||
} | ||
@@ -32,3 +36,3 @@ /** | ||
*/ | ||
export declare class KNode extends RectangularNode implements KGraphElement { | ||
export declare class KNode extends RectangularNode implements SKGraphElement { | ||
trace?: string; | ||
@@ -63,3 +67,3 @@ data: KGraphData[]; | ||
*/ | ||
export declare class KEdge extends SEdgeImpl implements KGraphElement { | ||
export declare class KEdge extends SEdgeImpl implements SKGraphElement { | ||
trace?: string; | ||
@@ -71,3 +75,4 @@ data: KGraphData[]; | ||
hasFeature(feature: symbol): boolean; | ||
properties: Record<string, unknown>; | ||
moved: boolean; | ||
} |
@@ -31,3 +31,5 @@ "use strict"; | ||
hasFeature(feature) { | ||
return feature === sprotty_1.selectFeature || (feature === sprotty_1.moveFeature && this.parent.properties['org.eclipse.elk.interactiveLayout']); | ||
return (feature === sprotty_1.selectFeature || | ||
(feature === sprotty_1.moveFeature && | ||
this.parent.properties['org.eclipse.elk.interactiveLayout'])); | ||
} | ||
@@ -34,0 +36,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { KNode } from "./constraint-classes"; | ||
import { KNode } from './constraint-classes'; | ||
/** | ||
@@ -14,5 +14,5 @@ * Filters the KNodes out of graphElements. | ||
/** | ||
* Determines whether one of the children is selected. | ||
* @param root Node which children should be checked. | ||
*/ | ||
* Determines whether one of the children is selected. | ||
* @param root Node which children should be checked. | ||
*/ | ||
export declare function isChildSelected(root: KNode): boolean; |
@@ -26,2 +26,3 @@ "use strict"; | ||
function filterKNodes(graphElements) { | ||
// eslint-disable-line | ||
const nodes = []; | ||
@@ -51,5 +52,5 @@ for (const elem of graphElements) { | ||
/** | ||
* Determines whether one of the children is selected. | ||
* @param root Node which children should be checked. | ||
*/ | ||
* Determines whether one of the children is selected. | ||
* @param root Node which children should be checked. | ||
*/ | ||
function isChildSelected(root) { | ||
@@ -56,0 +57,0 @@ const nodes = root.children; |
@@ -21,6 +21,17 @@ "use strict"; | ||
const backgroundColor = selected ? 'grey' : 'lightgrey'; | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", null, | ||
" ", | ||
(0, sprotty_1.svg)("rect", { x: (direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.UNDEFINED) ? begin : direction === constraint_classes_1.Direction.LEFT ? end : top, y: (direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.LEFT) ? top : direction === constraint_classes_1.Direction.UP ? end : begin, width: (direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.LEFT) ? Math.abs(begin - end) : bottom - top, height: (direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.LEFT) ? bottom - top : Math.abs(begin - end), fill: forbidden ? forbiddenColor : backgroundColor, stroke: forbidden ? forbiddenColor : 'grey', style: { 'stroke-dasharray': "4" } })); | ||
return ((0, sprotty_1.svg)("g", null, | ||
' ', | ||
(0, sprotty_1.svg)("rect", { x: direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.UNDEFINED | ||
? begin | ||
: direction === constraint_classes_1.Direction.LEFT | ||
? end | ||
: top, y: direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.LEFT | ||
? top | ||
: direction === constraint_classes_1.Direction.UP | ||
? end | ||
: begin, width: direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.LEFT | ||
? Math.abs(begin - end) | ||
: bottom - top, height: direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.LEFT | ||
? bottom - top | ||
: Math.abs(begin - end), fill: forbidden ? forbiddenColor : backgroundColor, stroke: forbidden ? forbiddenColor : 'grey', style: { 'stroke-dasharray': '4' } }))); | ||
} | ||
@@ -36,6 +47,13 @@ exports.createRect = createRect; | ||
function createVerticalLine(mid, top, bot, direction) { | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", null, | ||
" ", | ||
(0, sprotty_1.svg)("line", { x1: (direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT || direction === constraint_classes_1.Direction.UNDEFINED) ? mid : top, y1: (direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT || direction === constraint_classes_1.Direction.UNDEFINED) ? top : mid, x2: (direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT || direction === constraint_classes_1.Direction.UNDEFINED) ? mid : bot, y2: (direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT || direction === constraint_classes_1.Direction.UNDEFINED) ? bot : mid, fill: 'none', stroke: 'grey', style: { 'stroke-dasharray': '4' } })); | ||
return ((0, sprotty_1.svg)("g", null, | ||
' ', | ||
(0, sprotty_1.svg)("line", { x1: direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT || direction === constraint_classes_1.Direction.UNDEFINED | ||
? mid | ||
: top, y1: direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT || direction === constraint_classes_1.Direction.UNDEFINED | ||
? top | ||
: mid, x2: direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT || direction === constraint_classes_1.Direction.UNDEFINED | ||
? mid | ||
: bot, y2: direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT || direction === constraint_classes_1.Direction.UNDEFINED | ||
? bot | ||
: mid, fill: "none", stroke: "grey", style: { 'stroke-dasharray': '4' } }))); | ||
} | ||
@@ -53,6 +71,5 @@ exports.createVerticalLine = createVerticalLine; | ||
const color = forbidden ? forbiddenColor : 'grey'; | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", null, | ||
" ", | ||
(0, sprotty_1.svg)("circle", { cx: x, cy: y, r: "2", stroke: color, fill: fill ? color : "none", style: { 'stroke-width': '0.5' } })); | ||
return ((0, sprotty_1.svg)("g", null, | ||
' ', | ||
(0, sprotty_1.svg)("circle", { cx: x, cy: y, r: "2", stroke: color, fill: fill ? color : 'none', style: { 'stroke-width': '0.5' } }))); | ||
} | ||
@@ -67,7 +84,5 @@ exports.renderCircle = renderCircle; | ||
const generalYOffset = 5; | ||
const s = "translate(" + xTranslate + "," | ||
+ (yTranslate - generalYOffset) + ") scale(" + iconScale + ", " + iconScale + ")"; | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", { transform: s, fill: "grey", stroke: "none" }, | ||
(0, sprotty_1.svg)("path", { d: svg_path_1.lockPath })); | ||
const s = `translate(${xTranslate},${yTranslate - generalYOffset}) scale(${iconScale}, ${iconScale})`; | ||
return ((0, sprotty_1.svg)("g", { transform: s, fill: "grey", stroke: "none" }, | ||
(0, sprotty_1.svg)("path", { d: svg_path_1.lockPath }))); | ||
} | ||
@@ -82,17 +97,12 @@ exports.renderLock = renderLock; | ||
function renderArrow(xTranslate, yTranslate, vertical) { | ||
let s = "translate(" + xTranslate + "," | ||
+ yTranslate + ")"; | ||
s += " scale(" + iconScale + ", " + iconScale + ")"; | ||
let s = `translate(${xTranslate},${yTranslate})`; | ||
s += ` scale(${iconScale}, ${iconScale})`; | ||
if (vertical) { | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", { transform: s, fill: "grey", stroke: "none" }, | ||
(0, sprotty_1.svg)("path", { d: svg_path_1.arrowVertical })); | ||
return ((0, sprotty_1.svg)("g", { transform: s, fill: "grey", stroke: "none" }, | ||
(0, sprotty_1.svg)("path", { d: svg_path_1.arrowVertical }))); | ||
} | ||
else { | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", { transform: s, fill: "grey", stroke: "none" }, | ||
(0, sprotty_1.svg)("path", { d: svg_path_1.arrowHorizontal })); | ||
} | ||
return ((0, sprotty_1.svg)("g", { transform: s, fill: "grey", stroke: "none" }, | ||
(0, sprotty_1.svg)("path", { d: svg_path_1.arrowHorizontal }))); | ||
} | ||
exports.renderArrow = renderArrow; | ||
//# sourceMappingURL=interactive-view-objects.js.map |
/** @jsx svg */ | ||
import { VNode } from "snabbdom"; | ||
import { VNode } from 'snabbdom'; | ||
import { KNode } from './constraint-classes'; | ||
@@ -4,0 +4,0 @@ /** |
@@ -15,4 +15,5 @@ "use strict"; | ||
const nodes = (0, helper_methods_1.filterKNodes)(root.children); | ||
let result = undefined; | ||
if (root.properties['org.eclipse.elk.algorithm'] === undefined || root.properties['org.eclipse.elk.algorithm'].endsWith('layered')) { | ||
let result; | ||
if (root.properties['org.eclipse.elk.algorithm'] === undefined || | ||
root.properties['org.eclipse.elk.algorithm'].endsWith('layered')) { | ||
result = (0, layered_interactive_view_1.renderHierarchyLevel)(nodes); | ||
@@ -26,3 +27,2 @@ } | ||
} | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", null, result); | ||
@@ -49,3 +49,2 @@ } | ||
} | ||
// @ts-ignore | ||
return result; | ||
@@ -52,0 +51,0 @@ } |
import { MoveMouseListener, SModelElementImpl } from 'sprotty'; | ||
import { Action } from "sprotty-protocol"; | ||
import { Action } from 'sprotty-protocol'; | ||
export declare class KlighdInteractiveMouseListener extends MoveMouseListener { | ||
@@ -4,0 +4,0 @@ /** |
@@ -35,2 +35,3 @@ "use strict"; | ||
const constraint_util_1 = require("./rect-packing/constraint-util"); | ||
/* global MouseEvent */ | ||
let KlighdInteractiveMouseListener = class KlighdInteractiveMouseListener extends sprotty_1.MoveMouseListener { | ||
@@ -42,3 +43,3 @@ constructor() { | ||
*/ | ||
this.data = new Map; | ||
this.data = new Map(); | ||
/** | ||
@@ -104,10 +105,14 @@ * The nodes. | ||
if (algorithm === undefined || algorithm.endsWith('layered')) { | ||
return [actions_2.DeleteStaticConstraintAction.create({ | ||
id: this.target.id | ||
})]; | ||
return [ | ||
actions_2.DeleteStaticConstraintAction.create({ | ||
id: this.target.id, | ||
}), | ||
]; | ||
} | ||
else if (algorithm.endsWith('rectpacking')) { | ||
return [actions_3.RectPackDeletePositionConstraintAction.create({ | ||
id: this.target.id | ||
})]; | ||
if (algorithm.endsWith('rectpacking')) { | ||
return [ | ||
actions_3.RectPackDeletePositionConstraintAction.create({ | ||
id: this.target.id, | ||
}), | ||
]; | ||
} | ||
@@ -146,10 +151,8 @@ } | ||
// Refresh the diagram according to the moved elements. | ||
if (result.some(action => (0, sprotty_protocol_1.isAction)(action) && action.kind === actions_1.RefreshDiagramAction.KIND)) { | ||
if (result.some((action) => (0, sprotty_protocol_1.isAction)(action) && action.kind === actions_1.RefreshDiagramAction.KIND)) { | ||
return result; | ||
} | ||
else { | ||
return result.concat([actions_1.RefreshDiagramAction.create()]); | ||
} | ||
return result.concat([actions_1.RefreshDiagramAction.create()]); | ||
} | ||
else if (this.target) { | ||
if (this.target) { | ||
this.target.selected = false; | ||
@@ -156,0 +159,0 @@ const result = super.mouseUp(this.target, event); |
@@ -18,2 +18,4 @@ "use strict"; | ||
*/ | ||
// We follow Sprotty's way of redeclaring the interface and its create function, so disable this lint check for this file. | ||
/* eslint-disable no-redeclare */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,0 +22,0 @@ exports.SetPositionConstraintAction = exports.SetLayerConstraintAction = exports.DeleteLayerConstraintAction = exports.DeletePositionConstraintAction = exports.DeleteStaticConstraintAction = exports.SetStaticConstraintAction = void 0; |
@@ -1,2 +0,2 @@ | ||
import { Direction } from "../constraint-classes"; | ||
import { Direction } from '../constraint-classes'; | ||
/** | ||
@@ -3,0 +3,0 @@ * A layer visualization data class for the interactive layered approach. |
@@ -39,10 +39,11 @@ "use strict"; | ||
function getLayerOfNode(node, nodes, layers, direction) { | ||
const coordinateInLayoutDirection = (direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT) | ||
? node.position.x + node.size.width / 2 : node.position.y + node.size.height / 2; | ||
const coordinateInLayoutDirection = direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT | ||
? node.position.x + node.size.width / 2 | ||
: node.position.y + node.size.height / 2; | ||
// check for all layers if the node is in the layer | ||
for (let i = 0; i < layers.length; i++) { | ||
const layer = layers[i]; | ||
if (coordinateInLayoutDirection < layer.end && | ||
(direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN) || | ||
coordinateInLayoutDirection > layer.end && (direction === constraint_classes_1.Direction.LEFT || direction === constraint_classes_1.Direction.UP)) { | ||
if ((coordinateInLayoutDirection < layer.end && | ||
(direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN)) || | ||
(coordinateInLayoutDirection > layer.end && (direction === constraint_classes_1.Direction.LEFT || direction === constraint_classes_1.Direction.UP))) { | ||
return i; | ||
@@ -69,4 +70,5 @@ } | ||
// Examine all nodes that have a layer Id left or equal to the layerCandidate and that have a layerCons > their layerId | ||
const layerConstraintLeftOfCandidate = nodes.filter(n => n.properties['org.eclipse.elk.layered.layering.layerId'] <= layerCandidate | ||
&& n.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] > n.properties['org.eclipse.elk.layered.layering.layerId']); | ||
const layerConstraintLeftOfCandidate = nodes.filter((n) => n.properties['org.eclipse.elk.layered.layering.layerId'] <= layerCandidate && | ||
n.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] > | ||
n.properties['org.eclipse.elk.layered.layering.layerId']); | ||
// In case that there are no such nodes return the layerCandidate | ||
@@ -110,3 +112,4 @@ if (layerConstraintLeftOfCandidate.length === 0) { | ||
if (posConsOfUpper > upperIndex) { | ||
if (alreadyInLayer && upperNeighbor.properties['org.eclipse.elk.layered.crossingMinimization.positionId'] === localTargetIndex) { | ||
if (alreadyInLayer && | ||
upperNeighbor.properties['org.eclipse.elk.layered.crossingMinimization.positionId'] === localTargetIndex) { | ||
localTargetIndex = posConsOfUpper; | ||
@@ -128,9 +131,14 @@ } | ||
// All nodes within one hierarchy level have the same direction | ||
nodes.sort((a, b) => a.properties['org.eclipse.elk.layered.layering.layerId'] - b.properties['org.eclipse.elk.layered.layering.layerId']); | ||
nodes.sort((a, b) => a.properties['org.eclipse.elk.layered.layering.layerId'] - | ||
b.properties['org.eclipse.elk.layered.layering.layerId']); | ||
const layers = []; | ||
let layer = 0; | ||
// Begin coordinate of layer, depending of on the layout direction this might be a x or y coordinate | ||
let beginCoordinate = (direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN) ? Number.MAX_VALUE : Number.MIN_VALUE; | ||
let beginCoordinate = direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN | ||
? Number.MAX_VALUE | ||
: Number.MIN_VALUE; | ||
// End coordinate of layer, depending of on the layout direction this might be a x or y coordinate | ||
let endCoordinate = (direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN) ? Number.MIN_VALUE : Number.MAX_VALUE; | ||
let endCoordinate = direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN | ||
? Number.MIN_VALUE | ||
: Number.MAX_VALUE; | ||
let topBorder = Number.MAX_VALUE; // naming fits to the RIGHT direction (1) | ||
@@ -144,4 +152,10 @@ let bottomBorder = Number.MIN_VALUE; | ||
layers[layer] = new constraint_types_1.Layer(beginCoordinate, endCoordinate, beginCoordinate + (endCoordinate - beginCoordinate) / 2, direction); | ||
beginCoordinate = (direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN) ? Number.MAX_VALUE : Number.MIN_VALUE; | ||
endCoordinate = (direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN) ? Number.MIN_VALUE : Number.MAX_VALUE; | ||
beginCoordinate = | ||
direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN | ||
? Number.MAX_VALUE | ||
: Number.MIN_VALUE; | ||
endCoordinate = | ||
direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN | ||
? Number.MIN_VALUE | ||
: Number.MAX_VALUE; | ||
layer++; | ||
@@ -184,8 +198,15 @@ } | ||
} | ||
default: { | ||
console.error('error in constraint-utils.ts, unexpected direction in switch'); | ||
} | ||
} | ||
// update coordinates of the current layer | ||
beginCoordinate = (direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN) ? | ||
Math.min(currentBegin, beginCoordinate) : Math.max(currentBegin, beginCoordinate); | ||
endCoordinate = (direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN) ? | ||
Math.max(currentEnd, endCoordinate) : Math.min(currentEnd, endCoordinate); | ||
beginCoordinate = | ||
direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN | ||
? Math.min(currentBegin, beginCoordinate) | ||
: Math.max(currentBegin, beginCoordinate); | ||
endCoordinate = | ||
direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.DOWN | ||
? Math.max(currentEnd, endCoordinate) | ||
: Math.min(currentEnd, endCoordinate); | ||
topBorder = Math.min(currentTopBorder, topBorder); | ||
@@ -195,6 +216,6 @@ bottomBorder = Math.max(currentBottomBorder, bottomBorder); | ||
// add last layer | ||
layers[layer] = new constraint_types_1.Layer(beginCoordinate, endCoordinate, beginCoordinate + ((endCoordinate - beginCoordinate) / 2), direction); | ||
layers[layer] = new constraint_types_1.Layer(beginCoordinate, endCoordinate, beginCoordinate + (endCoordinate - beginCoordinate) / 2, direction); | ||
// offset above & below the layers | ||
topBorder = topBorder - exports.PLACEMENT_TOP_BOTTOM_OFFSET; | ||
bottomBorder = bottomBorder + exports.PLACEMENT_TOP_BOTTOM_OFFSET; | ||
topBorder -= exports.PLACEMENT_TOP_BOTTOM_OFFSET; | ||
bottomBorder += exports.PLACEMENT_TOP_BOTTOM_OFFSET; | ||
// update left and right bounds of the layers and set y bounds | ||
@@ -220,4 +241,4 @@ for (let i = 0; i < layers.length - 1; i++) { | ||
case constraint_classes_1.Direction.RIGHT: { | ||
firstLayer.begin = firstLayer.begin - exports.ONE_LAYER_PADDING; | ||
firstLayer.end = firstLayer.end + exports.ONE_LAYER_PADDING; | ||
firstLayer.begin -= exports.ONE_LAYER_PADDING; | ||
firstLayer.end += exports.ONE_LAYER_PADDING; | ||
firstLayer.topBorder = topBorder; | ||
@@ -228,4 +249,4 @@ firstLayer.bottomBorder = bottomBorder; | ||
case constraint_classes_1.Direction.LEFT: { | ||
firstLayer.begin = firstLayer.begin + exports.ONE_LAYER_PADDING; | ||
firstLayer.end = firstLayer.end - exports.ONE_LAYER_PADDING; | ||
firstLayer.begin += exports.ONE_LAYER_PADDING; | ||
firstLayer.end -= exports.ONE_LAYER_PADDING; | ||
firstLayer.topBorder = topBorder; | ||
@@ -236,4 +257,4 @@ firstLayer.bottomBorder = bottomBorder; | ||
case constraint_classes_1.Direction.DOWN: { | ||
firstLayer.begin = firstLayer.begin - exports.ONE_LAYER_PADDING; | ||
firstLayer.end = firstLayer.end + exports.ONE_LAYER_PADDING; | ||
firstLayer.begin -= exports.ONE_LAYER_PADDING; | ||
firstLayer.end += exports.ONE_LAYER_PADDING; | ||
firstLayer.topBorder = topBorder; | ||
@@ -244,4 +265,4 @@ firstLayer.bottomBorder = bottomBorder; | ||
case constraint_classes_1.Direction.UP: { | ||
firstLayer.begin = firstLayer.begin + exports.ONE_LAYER_PADDING; | ||
firstLayer.end = firstLayer.end - exports.ONE_LAYER_PADDING; | ||
firstLayer.begin += exports.ONE_LAYER_PADDING; | ||
firstLayer.end -= exports.ONE_LAYER_PADDING; | ||
firstLayer.topBorder = topBorder; | ||
@@ -251,2 +272,5 @@ firstLayer.bottomBorder = bottomBorder; | ||
} | ||
default: { | ||
console.error('error in constraint-utils.ts, unexpected direction in switch'); | ||
} | ||
} | ||
@@ -328,6 +352,6 @@ } | ||
// check the connected nodes for layer constraints | ||
for (const node of connectedNodes) { | ||
if (node.properties['org.eclipse.elk.layered.layering.layerId'] === layer | ||
&& node.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] !== -1 | ||
&& node.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] !== undefined) { | ||
for (const connectedNode of connectedNodes) { | ||
if (connectedNode.properties['org.eclipse.elk.layered.layering.layerId'] === layer && | ||
connectedNode.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] !== -1 && | ||
connectedNode.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] !== undefined) { | ||
// layer is forbidden for the given node | ||
@@ -347,4 +371,5 @@ return true; | ||
function shouldOnlyLCBeSet(node, layers, direction) { | ||
const coordinateToCheck = (direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT) ? | ||
node.position.y : node.position.x; | ||
const coordinateToCheck = direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT | ||
? node.position.y | ||
: node.position.x; | ||
if (layers.length !== 0) { | ||
@@ -365,3 +390,3 @@ const layerTop = layers[0].topBorder; | ||
const targetNode = target; | ||
const direction = targetNode.direction; | ||
const { direction } = targetNode; | ||
// calculate layer and position the target has in the graph at the new position | ||
@@ -378,3 +403,3 @@ const layerOfTarget = getLayerOfNode(targetNode, nodes, layers, direction); | ||
} | ||
else if (targetNode.properties['org.eclipse.elk.layered.layering.layerId'] !== layerOfTarget) { | ||
if (targetNode.properties['org.eclipse.elk.layered.layering.layerId'] !== layerOfTarget) { | ||
// layer constraint should only be set if the layer index changed | ||
@@ -386,26 +411,22 @@ if (shouldOnlyLCBeSet(targetNode, layers, direction)) { | ||
layer: layerOfTarget, | ||
layerCons: newLayerCons | ||
}); | ||
} | ||
else { | ||
// If layer and position constraint should be set - send them both in one StaticConstraint | ||
return actions_2.SetStaticConstraintAction.create({ | ||
id: targetNode.id, | ||
layer: layerOfTarget, | ||
layerCons: newLayerCons, | ||
position: positionOfTarget, | ||
posCons: newPositionCons | ||
}); | ||
} | ||
// If layer and position constraint should be set - send them both in one StaticConstraint | ||
return actions_2.SetStaticConstraintAction.create({ | ||
id: targetNode.id, | ||
layer: layerOfTarget, | ||
layerCons: newLayerCons, | ||
position: positionOfTarget, | ||
posCons: newPositionCons, | ||
}); | ||
} | ||
else { | ||
// position constraint should only be set if the position of the node changed | ||
if (targetNode.properties['org.eclipse.elk.layered.crossingMinimization.positionId'] !== positionOfTarget) { | ||
// set the position Constraint | ||
return actions_2.SetPositionConstraintAction.create({ | ||
id: targetNode.id, | ||
position: positionOfTarget, | ||
posCons: newPositionCons | ||
}); | ||
} | ||
// position constraint should only be set if the position of the node changed | ||
if (targetNode.properties['org.eclipse.elk.layered.crossingMinimization.positionId'] !== positionOfTarget) { | ||
// set the position Constraint | ||
return actions_2.SetPositionConstraintAction.create({ | ||
id: targetNode.id, | ||
position: positionOfTarget, | ||
posCons: newPositionCons, | ||
}); | ||
} | ||
@@ -412,0 +433,0 @@ // If the node was moved without setting a constraint - let it snap back |
/** @jsx svg */ | ||
import { VNode } from "snabbdom"; | ||
import { VNode } from 'snabbdom'; | ||
import { Direction, KNode } from '../constraint-classes'; | ||
@@ -4,0 +4,0 @@ import { Layer } from './constraint-types'; |
@@ -16,3 +16,3 @@ "use strict"; | ||
function renderHierarchyLevel(nodes) { | ||
const direction = nodes[0].direction; | ||
const { direction } = nodes[0]; | ||
const selNode = (0, helper_methods_1.getSelectedNode)(nodes); | ||
@@ -24,7 +24,8 @@ if (selNode !== undefined) { | ||
// y coordinates of the layers | ||
const topBorder = layers[0].topBorder; | ||
const bottomBorder = layers[0].bottomBorder; | ||
const { topBorder } = layers[0]; | ||
const { bottomBorder } = layers[0]; | ||
// let globalEndCoordinate = layers[layers.length - 1].end | ||
// determines whether only the layer constraint will be set when the node is released | ||
const onlyLC = (0, constraint_utils_1.shouldOnlyLCBeSet)(selNode, layers, direction) && selNode.properties['org.eclipse.elk.layered.layering.layerId'] !== currentLayer; | ||
const onlyLC = (0, constraint_utils_1.shouldOnlyLCBeSet)(selNode, layers, direction) && | ||
selNode.properties['org.eclipse.elk.layered.layering.layerId'] !== currentLayer; | ||
// create layers | ||
@@ -35,12 +36,10 @@ let result = (0, sprotty_1.svg)("g", null); | ||
if (i === currentLayer) { | ||
result = (0, sprotty_1.svg)("g", null, | ||
result = ((0, sprotty_1.svg)("g", null, | ||
result, | ||
(0, interactive_view_objects_1.createRect)(layer.begin, layer.end, topBorder, bottomBorder, forbidden, onlyLC, direction)); | ||
(0, interactive_view_objects_1.createRect)(layer.begin, layer.end, topBorder, bottomBorder, forbidden, onlyLC, direction))); | ||
} | ||
else { | ||
if (!(0, constraint_utils_1.isLayerForbidden)(selNode, i)) { | ||
result = (0, sprotty_1.svg)("g", null, | ||
result, | ||
(0, interactive_view_objects_1.createVerticalLine)(layer.mid, topBorder, bottomBorder, direction)); | ||
} | ||
else if (!(0, constraint_utils_1.isLayerForbidden)(selNode, i)) { | ||
result = ((0, sprotty_1.svg)("g", null, | ||
result, | ||
(0, interactive_view_objects_1.createVerticalLine)(layer.mid, topBorder, bottomBorder, direction))); | ||
} | ||
@@ -55,10 +54,10 @@ } | ||
if (currentLayer === layers.length) { | ||
result = (0, sprotty_1.svg)("g", null, | ||
result = ((0, sprotty_1.svg)("g", null, | ||
result, | ||
(0, interactive_view_objects_1.createRect)(lastLayer.end, lastLayer.end + (lastLayer.end - lastLayer.begin), topBorder, bottomBorder, forbidden, onlyLC, direction)); | ||
(0, interactive_view_objects_1.createRect)(lastLayer.end, lastLayer.end + (lastLayer.end - lastLayer.begin), topBorder, bottomBorder, forbidden, onlyLC, direction))); | ||
} | ||
else { | ||
result = (0, sprotty_1.svg)("g", null, | ||
result = ((0, sprotty_1.svg)("g", null, | ||
result, | ||
(0, interactive_view_objects_1.createVerticalLine)(lastLayer.mid + (lastLayer.end - lastLayer.begin), topBorder, bottomBorder, direction)); | ||
(0, interactive_view_objects_1.createVerticalLine)(lastLayer.mid + (lastLayer.end - lastLayer.begin), topBorder, bottomBorder, direction))); | ||
} | ||
@@ -68,14 +67,9 @@ } | ||
if (!onlyLC) { | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", null, | ||
return ((0, sprotty_1.svg)("g", null, | ||
result, | ||
renderPositions(currentLayer, nodes, layers, forbidden, direction)); | ||
renderPositions(currentLayer, nodes, layers, forbidden, direction))); | ||
} | ||
else { | ||
// Add available positions | ||
// @ts-ignore | ||
return result; | ||
} | ||
// Add available positions | ||
return result; | ||
} | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", null); | ||
@@ -103,3 +97,4 @@ } | ||
const curPos = (0, constraint_utils_1.getPositionInLayer)(layerNodes, target); | ||
layerNodes.sort((a, b) => a.properties['org.eclipse.elk.layered.crossingMinimization.positionId'] - b.properties['org.eclipse.elk.layered.crossingMinimization.positionId']); | ||
layerNodes.sort((a, b) => a.properties['org.eclipse.elk.layered.crossingMinimization.positionId'] - | ||
b.properties['org.eclipse.elk.layered.crossingMinimization.positionId']); | ||
if (layerNodes.length > 0) { | ||
@@ -109,3 +104,4 @@ let result = (0, sprotty_1.svg)("g", null); | ||
let shift = 1; | ||
let x = 0, y = 0; | ||
let x = 0; | ||
let y = 0; | ||
// calculate positions between nodes | ||
@@ -147,6 +143,9 @@ for (let i = 0; i < layerNodes.length - 1; i++) { | ||
} | ||
default: { | ||
console.error('error in layered-interactive.view.tsx, unexpected direction in switch'); | ||
} | ||
} | ||
result = (0, sprotty_1.svg)("g", null, | ||
result = ((0, sprotty_1.svg)("g", null, | ||
result, | ||
(0, interactive_view_objects_1.renderCircle)(curPos === i + shift, x, y, forbidden)); | ||
(0, interactive_view_objects_1.renderCircle)(curPos === i + shift, x, y, forbidden))); | ||
} | ||
@@ -182,6 +181,9 @@ else { | ||
} | ||
default: { | ||
console.error('error in layered.interactive-view.tsx, unexpected direction in switch'); | ||
} | ||
} | ||
result = (0, sprotty_1.svg)("g", null, | ||
result = ((0, sprotty_1.svg)("g", null, | ||
result, | ||
(0, interactive_view_objects_1.renderCircle)(curPos === 0, x, y, forbidden)); | ||
(0, interactive_view_objects_1.renderCircle)(curPos === 0, x, y, forbidden))); | ||
} | ||
@@ -195,3 +197,5 @@ // position below the last node is available if the last node is not the selected one | ||
x = layers[current].mid; | ||
y = layers[current].bottomBorder - (layers[current].bottomBorder - (last.position.y + last.size.height)) / 2; | ||
y = | ||
layers[current].bottomBorder - | ||
(layers[current].bottomBorder - (last.position.y + last.size.height)) / 2; | ||
break; | ||
@@ -201,3 +205,5 @@ } | ||
x = layers[current].mid; | ||
y = layers[current].bottomBorder - (layers[current].bottomBorder - (last.position.y + last.size.height)) / 2; | ||
y = | ||
layers[current].bottomBorder - | ||
(layers[current].bottomBorder - (last.position.y + last.size.height)) / 2; | ||
break; | ||
@@ -207,3 +213,5 @@ } | ||
y = layers[current].mid; | ||
x = layers[current].bottomBorder - (layers[current].bottomBorder - (last.position.x + last.size.width)) / 2; | ||
x = | ||
layers[current].bottomBorder - | ||
(layers[current].bottomBorder - (last.position.x + last.size.width)) / 2; | ||
break; | ||
@@ -213,47 +221,52 @@ } | ||
y = layers[current].mid; | ||
x = layers[current].bottomBorder - (layers[current].bottomBorder - (last.position.x + last.size.width)) / 2; | ||
x = | ||
layers[current].bottomBorder - | ||
(layers[current].bottomBorder - (last.position.x + last.size.width)) / 2; | ||
break; | ||
} | ||
default: { | ||
console.error('error in layered.interactive-view.tsx, unexpected direction in switch'); | ||
} | ||
} | ||
result = (0, sprotty_1.svg)("g", null, | ||
result = ((0, sprotty_1.svg)("g", null, | ||
result, | ||
(0, interactive_view_objects_1.renderCircle)(curPos === layerNodes.length - 1 + shift, x, y, forbidden)); | ||
(0, interactive_view_objects_1.renderCircle)(curPos === layerNodes.length - 1 + shift, x, y, forbidden))); | ||
} | ||
// @ts-ignore | ||
return result; | ||
} | ||
else { | ||
// there are no nodes in the layer | ||
// show a circle in the middle of the layer | ||
let x = 0, y = 0; | ||
switch (direction) { | ||
case constraint_classes_1.Direction.UNDEFINED: | ||
case constraint_classes_1.Direction.RIGHT: { | ||
const lastLayer = layers[layers.length - 1]; | ||
x = lastLayer.mid + (lastLayer.end - lastLayer.begin); | ||
y = lastLayer.topBorder + (lastLayer.bottomBorder - lastLayer.topBorder) / 2; | ||
break; | ||
} | ||
case constraint_classes_1.Direction.LEFT: { | ||
const lastLayer = layers[layers.length - 1]; | ||
x = lastLayer.mid + (lastLayer.end - lastLayer.begin); | ||
y = lastLayer.topBorder + (lastLayer.bottomBorder - lastLayer.topBorder) / 2; | ||
break; | ||
} | ||
case constraint_classes_1.Direction.DOWN: { | ||
const lastLayer = layers[layers.length - 1]; | ||
y = lastLayer.mid + (lastLayer.end - lastLayer.begin); | ||
x = lastLayer.topBorder + (lastLayer.bottomBorder - lastLayer.topBorder) / 2; | ||
break; | ||
} | ||
case constraint_classes_1.Direction.UP: { | ||
const lastLayer = layers[layers.length - 1]; | ||
y = lastLayer.mid + (lastLayer.end - lastLayer.begin); | ||
x = lastLayer.topBorder + (lastLayer.bottomBorder - lastLayer.topBorder) / 2; | ||
break; | ||
} | ||
// there are no nodes in the layer | ||
// show a circle in the middle of the layer | ||
let x = 0; | ||
let y = 0; | ||
switch (direction) { | ||
case constraint_classes_1.Direction.UNDEFINED: | ||
case constraint_classes_1.Direction.RIGHT: { | ||
const lastLayer = layers[layers.length - 1]; | ||
x = lastLayer.mid + (lastLayer.end - lastLayer.begin); | ||
y = lastLayer.topBorder + (lastLayer.bottomBorder - lastLayer.topBorder) / 2; | ||
break; | ||
} | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", null, (0, interactive_view_objects_1.renderCircle)(true, x, y, forbidden)); | ||
case constraint_classes_1.Direction.LEFT: { | ||
const lastLayer = layers[layers.length - 1]; | ||
x = lastLayer.mid + (lastLayer.end - lastLayer.begin); | ||
y = lastLayer.topBorder + (lastLayer.bottomBorder - lastLayer.topBorder) / 2; | ||
break; | ||
} | ||
case constraint_classes_1.Direction.DOWN: { | ||
const lastLayer = layers[layers.length - 1]; | ||
y = lastLayer.mid + (lastLayer.end - lastLayer.begin); | ||
x = lastLayer.topBorder + (lastLayer.bottomBorder - lastLayer.topBorder) / 2; | ||
break; | ||
} | ||
case constraint_classes_1.Direction.UP: { | ||
const lastLayer = layers[layers.length - 1]; | ||
y = lastLayer.mid + (lastLayer.end - lastLayer.begin); | ||
x = lastLayer.topBorder + (lastLayer.bottomBorder - lastLayer.topBorder) / 2; | ||
break; | ||
} | ||
default: { | ||
console.error('error in layered.interactive-view.tsx, unexpected direction in switch'); | ||
} | ||
} | ||
return (0, sprotty_1.svg)("g", null, (0, interactive_view_objects_1.renderCircle)(true, x, y, forbidden)); | ||
} | ||
@@ -272,3 +285,6 @@ exports.renderPositions = renderPositions; | ||
const layerConstraint = node.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint']; | ||
if (layerConstraint !== -1 && positionConstraint !== -1 && layerConstraint !== undefined && positionConstraint !== undefined) { | ||
if (layerConstraint !== -1 && | ||
positionConstraint !== -1 && | ||
layerConstraint !== undefined && | ||
positionConstraint !== undefined) { | ||
// layer and position Constraint are set | ||
@@ -285,3 +301,2 @@ result = (0, sprotty_1.svg)("g", null, (0, interactive_view_objects_1.renderLock)(x, y)); | ||
} | ||
// @ts-ignore | ||
return result; | ||
@@ -300,10 +315,11 @@ } | ||
function renderLayerConstraint(x, y, direction) { | ||
const vertical = !(direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT); | ||
const vertical = !(direction === constraint_classes_1.Direction.UNDEFINED || | ||
direction === constraint_classes_1.Direction.RIGHT || | ||
direction === constraint_classes_1.Direction.LEFT); | ||
const xOffset = vertical ? verticalArrowXOffset : horizontalArrowXOffset; | ||
const yOffset = vertical ? verticalArrowYOffset : horizontalArrowYOffset; | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", null, | ||
" ", | ||
return ((0, sprotty_1.svg)("g", null, | ||
' ', | ||
(0, interactive_view_objects_1.renderLock)(x, y), | ||
(0, interactive_view_objects_1.renderArrow)(x + xOffset, y + yOffset, vertical)); | ||
(0, interactive_view_objects_1.renderArrow)(x + xOffset, y + yOffset, vertical))); | ||
} | ||
@@ -316,11 +332,10 @@ /** | ||
function renderPositionConstraint(x, y, direction) { | ||
const vertical = (direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT); | ||
const vertical = direction === constraint_classes_1.Direction.UNDEFINED || direction === constraint_classes_1.Direction.RIGHT || direction === constraint_classes_1.Direction.LEFT; | ||
const xOffset = vertical ? verticalArrowXOffset : horizontalArrowXOffset; | ||
const yOffset = vertical ? verticalArrowYOffset : horizontalArrowYOffset; | ||
// @ts-ignore | ||
return (0, sprotty_1.svg)("g", null, | ||
" ", | ||
return ((0, sprotty_1.svg)("g", null, | ||
' ', | ||
(0, interactive_view_objects_1.renderLock)(x, y), | ||
(0, interactive_view_objects_1.renderArrow)(x + xOffset, y + yOffset, vertical)); | ||
(0, interactive_view_objects_1.renderArrow)(x + xOffset, y + yOffset, vertical))); | ||
} | ||
//# sourceMappingURL=layered-interactive-view.js.map |
@@ -18,2 +18,4 @@ "use strict"; | ||
*/ | ||
// We follow Sprotty's way of redeclaring the interface and its create function, so disable this lint check for this file. | ||
/* eslint-disable no-redeclare */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,0 +22,0 @@ exports.RectPackSetPositionConstraintAction = exports.RectPackDeletePositionConstraintAction = exports.SetAspectRatioAction = void 0; |
@@ -24,2 +24,3 @@ "use strict"; | ||
const actions_2 = require("../actions"); | ||
/* global MouseEvent */ | ||
/** | ||
@@ -36,6 +37,6 @@ * Generate the correct action for the target node released at the specific position. | ||
// If the node is moved on top of another node it takes its place. | ||
nodes.forEach(node => { | ||
nodes.forEach((node) => { | ||
if (node.id !== target.id) { | ||
const targetBounds = (0, sprotty_1.getAbsoluteBounds)(node); | ||
const canvasBounds = target.root.canvasBounds; | ||
const { canvasBounds } = target.root; | ||
const boundsInWindow = sprotty_protocol_1.Bounds.translate(targetBounds, canvasBounds); | ||
@@ -46,4 +47,3 @@ const lowX = boundsInWindow.x; | ||
const highY = boundsInWindow.y + boundsInWindow.height; | ||
if (event.pageX > lowX && event.pageX < highX | ||
&& event.pageY > lowY && event.pageY < highY) { | ||
if (event.pageX > lowX && event.pageX < highX && event.pageY > lowY && event.pageY < highY) { | ||
let actualPosition = node.properties['org.eclipse.elk.rectPacking.currentPosition']; | ||
@@ -59,3 +59,4 @@ if (node.properties['org.eclipse.elk.alg.rectpacking.desiredPosition'] !== -1) { | ||
result = actions_1.RectPackSetPositionConstraintAction.create({ | ||
id: target.id, order: actualPosition | ||
id: target.id, | ||
order: actualPosition, | ||
}); | ||
@@ -73,3 +74,3 @@ } | ||
let maxY = Number.MIN_VALUE; | ||
nodes.forEach(node => { | ||
nodes.forEach((node) => { | ||
if (node.position.x < x) { | ||
@@ -93,3 +94,3 @@ x = node.position.x; | ||
id: parent.id, | ||
aspectRatio: aspectRatio | ||
aspectRatio, | ||
}); | ||
@@ -96,0 +97,0 @@ } |
/** @jsx svg */ | ||
import { VNode } from "snabbdom"; | ||
import { VNode } from 'snabbdom'; | ||
import { KNode } from '../constraint-classes'; | ||
/** | ||
* Visualize the layer the selected node is in as a rectangle and all other layers as a vertical line. | ||
* The rectangle contains circles indicating the available positions. | ||
* @param node All nodes in the hierarchical level for which the layers should be visualized. | ||
* @param root Root of the hierarchical level. | ||
*/ | ||
* Visualize the layer the selected node is in as a rectangle and all other layers as a vertical line. | ||
* The rectangle contains circles indicating the available positions. | ||
* @param node All nodes in the hierarchical level for which the layers should be visualized. | ||
* @param root Root of the hierarchical level. | ||
*/ | ||
export declare function renderHierarchyLevel(nodes: KNode[]): VNode; | ||
@@ -11,0 +11,0 @@ /** |
@@ -9,7 +9,7 @@ "use strict"; | ||
/** | ||
* Visualize the layer the selected node is in as a rectangle and all other layers as a vertical line. | ||
* The rectangle contains circles indicating the available positions. | ||
* @param node All nodes in the hierarchical level for which the layers should be visualized. | ||
* @param root Root of the hierarchical level. | ||
*/ | ||
* Visualize the layer the selected node is in as a rectangle and all other layers as a vertical line. | ||
* The rectangle contains circles indicating the available positions. | ||
* @param node All nodes in the hierarchical level for which the layers should be visualized. | ||
* @param root Root of the hierarchical level. | ||
*/ | ||
function renderHierarchyLevel(nodes) { | ||
@@ -22,3 +22,3 @@ // Draw rect around all child nodes | ||
let maxY = Number.MIN_VALUE; | ||
nodes.forEach(node => { | ||
nodes.forEach((node) => { | ||
if (node.position.x < x) { | ||
@@ -37,4 +37,4 @@ x = node.position.x; | ||
}); | ||
return (0, sprotty_1.svg)("g", null, | ||
(0, sprotty_1.svg)("rect", { x: x - boundingBoxMargin, y: y - boundingBoxMargin, width: maxX - x + 2 * boundingBoxMargin, height: maxY - y + 2 * boundingBoxMargin, stroke: color, fill: 'rgba(0,0,0,0)', strokeWidth: 2 * boundingBoxMargin, style: { 'stroke-dasharray': '4' } })); | ||
return ((0, sprotty_1.svg)("g", null, | ||
(0, sprotty_1.svg)("rect", { x: x - boundingBoxMargin, y: y - boundingBoxMargin, width: maxX - x + 2 * boundingBoxMargin, height: maxY - y + 2 * boundingBoxMargin, stroke: color, fill: "rgba(0,0,0,0)", strokeWidth: 2 * boundingBoxMargin, style: { 'stroke-dasharray': '4' } }))); | ||
} | ||
@@ -41,0 +41,0 @@ exports.renderHierarchyLevel = renderHierarchyLevel; |
@@ -25,5 +25,5 @@ "use strict"; | ||
*/ | ||
exports.lockPath = "M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 " + | ||
"152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 " + | ||
"0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z"; | ||
exports.lockPath = 'M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 ' + | ||
'152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 ' + | ||
'0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z'; | ||
/** | ||
@@ -34,5 +34,5 @@ * Font Awesome arrows-alt-v icon. | ||
*/ | ||
exports.arrowVertical = "M214.059 377.941H168V134.059h46.059c21.382 0 32.09-25.851 16.971-40.971L144.971 " + | ||
"7.029c-9.373-9.373-24.568-9.373-33.941 0L24.971 93.088c-15.119 15.119-4.411 40.971 16.971 40.971H88v243.882H41.941c-21.382 " + | ||
"0-32.09 25.851-16.971 40.971l86.059 86.059c9.373 9.373 24.568 9.373 33.941 0l86.059-86.059c15.12-15.119 4.412-40.971-16.97-40.971z"; | ||
exports.arrowVertical = 'M214.059 377.941H168V134.059h46.059c21.382 0 32.09-25.851 16.971-40.971L144.971 ' + | ||
'7.029c-9.373-9.373-24.568-9.373-33.941 0L24.971 93.088c-15.119 15.119-4.411 40.971 16.971 40.971H88v243.882H41.941c-21.382 ' + | ||
'0-32.09 25.851-16.971 40.971l86.059 86.059c9.373 9.373 24.568 9.373 33.941 0l86.059-86.059c15.12-15.119 4.412-40.971-16.97-40.971z'; | ||
/** | ||
@@ -43,5 +43,5 @@ * Font Awesome arrows-alt-h icon. | ||
*/ | ||
exports.arrowHorizontal = "M377.941 169.941V216H134.059v-46.059c0-21.382-25.851-32.09-40.971-16.971L7.029 " + | ||
"239.029c-9.373 9.373-9.373 24.568 0 33.941l86.059 86.059c15.119 15.119 40.971 4.411 40.971-16.971V296h243.882v46.059c0 " + | ||
"21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.568 0-33.941l-86.059-86.059c-15.119-15.12-40.971-4.412-40.971 16.97z"; | ||
exports.arrowHorizontal = 'M377.941 169.941V216H134.059v-46.059c0-21.382-25.851-32.09-40.971-16.971L7.029 ' + | ||
'239.029c-9.373 9.373-9.373 24.568 0 33.941l86.059 86.059c15.119 15.119 40.971 4.411 40.971-16.971V296h243.882v46.059c0 ' + | ||
'21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.568 0-33.941l-86.059-86.059c-15.119-15.12-40.971-4.412-40.971 16.97z'; | ||
//# sourceMappingURL=svg-path.js.map |
{ | ||
"name": "@kieler/klighd-interactive", | ||
"version": "0.5.0-next.c9365de", | ||
"description": "A module for klighd-core to interactively apply constraints to the diagram", | ||
"author": "KIELER <kieler@rtsys.informatik.uni-kiel.de>", | ||
"license": "EPL-2.0", | ||
"keywords": [ | ||
"klighd", | ||
"interactive" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/kieler/klighd-vscode", | ||
"directory": "packages/klighd-core" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf lib", | ||
"lint": "eslint .", | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"publish:next": "yarn publish --new-version \"$(semver $npm_package_version -i minor)-next.$(git rev-parse --short HEAD)\" --tag next --no-git-tag-version" | ||
}, | ||
"dependencies": { | ||
"sprotty": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"rimraf": "^4.4.0", | ||
"semver": "^7.5.4" | ||
}, | ||
"files": [ | ||
"lib", | ||
"src", | ||
"build" | ||
] | ||
"name": "@kieler/klighd-interactive", | ||
"version": "0.5.0-next.c96847b", | ||
"description": "A module for klighd-core to interactively apply constraints to the diagram", | ||
"author": "KIELER <kieler@rtsys.informatik.uni-kiel.de>", | ||
"license": "EPL-2.0", | ||
"keywords": [ | ||
"klighd", | ||
"interactive" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/kieler/klighd-vscode", | ||
"directory": "packages/klighd-core" | ||
}, | ||
"scripts": { | ||
"clean": "rimraf lib", | ||
"lint": "eslint .", | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"publish:next": "yarn publish --new-version \"$(semver $npm_package_version -i minor)-next.$(git rev-parse --short HEAD)\" --tag next --no-git-tag-version" | ||
}, | ||
"dependencies": { | ||
"inversify": "^6.0.2", | ||
"snabbdom": "^3.5.1", | ||
"sprotty": "^1.1.0", | ||
"sprotty-protocol": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"rimraf": "^4.4.0", | ||
"semver": "^7.5.4" | ||
}, | ||
"files": [ | ||
"lib", | ||
"src", | ||
"build" | ||
] | ||
} |
@@ -17,5 +17,7 @@ /* | ||
*/ | ||
// We follow Sprotty's way of redeclaring the interface and its create function, so disable this lint check for this file. | ||
/* eslint-disable no-redeclare */ | ||
import { Action } from 'sprotty-protocol'; | ||
import { DeleteConstraint } from './layered/constraint-types'; | ||
import { Action } from 'sprotty-protocol' | ||
import { DeleteConstraint } from './layered/constraint-types' | ||
@@ -56,2 +58,2 @@ /** | ||
} | ||
} | ||
} |
@@ -18,4 +18,4 @@ /* | ||
import { moveFeature, RectangularNode, SEdgeImpl, selectFeature, SParentElementImpl } from 'sprotty'; | ||
import { Point } from 'sprotty-protocol'; | ||
import { moveFeature, RectangularNode, SEdgeImpl, selectFeature, SParentElementImpl } from 'sprotty' | ||
import { Point } from 'sprotty-protocol' | ||
@@ -28,3 +28,3 @@ /** | ||
*/ | ||
export interface KGraphElement extends SParentElementImpl { | ||
export interface SKGraphElement extends SParentElementImpl { | ||
/** | ||
@@ -46,2 +46,7 @@ * May contain a trace that points back to the server instance where this element was created. | ||
opacity: number | ||
/** | ||
* The properties of this element. | ||
*/ | ||
properties: Record<string, unknown> | ||
} | ||
@@ -52,9 +57,17 @@ | ||
*/ | ||
export class KNode extends RectangularNode implements KGraphElement { | ||
export class KNode extends RectangularNode implements SKGraphElement { | ||
trace?: string | ||
data: KGraphData[] | ||
areChildAreaChildrenRendered = false | ||
areNonChildAreaChildrenRendered = false | ||
hasFeature(feature: symbol): boolean { | ||
return feature === selectFeature || (feature === moveFeature && (this.parent as KNode).properties['org.eclipse.elk.interactiveLayout'] as boolean) | ||
return ( | ||
feature === selectFeature || | ||
(feature === moveFeature && | ||
((this.parent as KNode).properties['org.eclipse.elk.interactiveLayout'] as boolean)) | ||
) | ||
} | ||
@@ -67,3 +80,5 @@ | ||
shadow: boolean | ||
shadowX: number | ||
shadowY: number | ||
@@ -77,3 +92,3 @@ } | ||
DOWN, | ||
UP | ||
UP, | ||
} | ||
@@ -93,8 +108,13 @@ | ||
*/ | ||
export class KEdge extends SEdgeImpl implements KGraphElement { | ||
export class KEdge extends SEdgeImpl implements SKGraphElement { | ||
trace?: string | ||
data: KGraphData[] | ||
junctionPoints: Point[] | ||
areChildAreaChildrenRendered = false | ||
areNonChildAreaChildrenRendered = false | ||
hasFeature(feature: symbol): boolean { | ||
@@ -104,3 +124,5 @@ return feature === selectFeature | ||
properties: Record<string, unknown> | ||
moved: boolean | ||
} | ||
} |
@@ -18,4 +18,4 @@ /* | ||
import { SNodeImpl } from "sprotty" | ||
import { KNode } from "./constraint-classes" | ||
import { SNodeImpl } from 'sprotty' | ||
import { KNode } from './constraint-classes' | ||
@@ -26,3 +26,4 @@ /** | ||
*/ | ||
export function filterKNodes(graphElements: any): KNode[] { // eslint-disable-line | ||
export function filterKNodes(graphElements: any): KNode[] { | ||
// eslint-disable-line | ||
const nodes: KNode[] = [] | ||
@@ -52,5 +53,5 @@ for (const elem of graphElements) { | ||
/** | ||
* Determines whether one of the children is selected. | ||
* @param root Node which children should be checked. | ||
*/ | ||
* Determines whether one of the children is selected. | ||
* @param root Node which children should be checked. | ||
*/ | ||
export function isChildSelected(root: KNode): boolean { | ||
@@ -66,2 +67,2 @@ const nodes = root.children | ||
return false | ||
} | ||
} |
@@ -18,5 +18,5 @@ /* | ||
import { ContainerModule } from 'inversify'; | ||
import { TYPES, configureCommand, MoveCommand, LocationPostprocessor, MoveMouseListener } from 'sprotty'; | ||
import { KlighdInteractiveMouseListener } from './klighd-interactive-mouselistener'; | ||
import { ContainerModule } from 'inversify' | ||
import { TYPES, configureCommand, MoveCommand, LocationPostprocessor, MoveMouseListener } from 'sprotty' | ||
import { KlighdInteractiveMouseListener } from './klighd-interactive-mouselistener' | ||
@@ -30,7 +30,7 @@ /** | ||
bind(MoveMouseListener).toService(KlighdInteractiveMouseListener) | ||
configureCommand({ bind, isBound }, MoveCommand); | ||
bind(TYPES.IVNodePostprocessor).to(LocationPostprocessor); | ||
bind(TYPES.HiddenVNodePostprocessor).to(LocationPostprocessor); | ||
}); | ||
configureCommand({ bind, isBound }, MoveCommand) | ||
bind(TYPES.IVNodePostprocessor).to(LocationPostprocessor) | ||
bind(TYPES.HiddenVNodePostprocessor).to(LocationPostprocessor) | ||
}) | ||
export default interactiveModule; | ||
export default interactiveModule |
@@ -18,20 +18,20 @@ /* | ||
import { injectable } from 'inversify'; | ||
import { MoveMouseListener, SEdgeImpl, SLabelImpl, SModelElementImpl, SNodeImpl } from 'sprotty'; | ||
import { Action, isAction } from "sprotty-protocol" | ||
import { RefreshDiagramAction } from './actions'; | ||
import { KNode } from './constraint-classes'; | ||
import { filterKNodes } from './helper-methods'; | ||
import { DeleteStaticConstraintAction } from './layered/actions'; | ||
import { getLayers, setProperty } from './layered/constraint-utils'; | ||
import { RectPackDeletePositionConstraintAction } from './rect-packing/actions'; | ||
import { setGenerateRectPackAction } from './rect-packing/constraint-util'; | ||
import { injectable } from 'inversify' | ||
import { MoveMouseListener, SEdgeImpl, SLabelImpl, SModelElementImpl, SNodeImpl } from 'sprotty' | ||
import { Action, isAction } from 'sprotty-protocol' | ||
import { RefreshDiagramAction } from './actions' | ||
import { KNode } from './constraint-classes' | ||
import { filterKNodes } from './helper-methods' | ||
import { DeleteStaticConstraintAction } from './layered/actions' | ||
import { getLayers, setProperty } from './layered/constraint-utils' | ||
import { RectPackDeletePositionConstraintAction } from './rect-packing/actions' | ||
import { setGenerateRectPackAction } from './rect-packing/constraint-util' | ||
/* global MouseEvent */ | ||
@injectable() | ||
export class KlighdInteractiveMouseListener extends MoveMouseListener { | ||
/** | ||
* Map to holds algorithm specific data generated on mouse down. | ||
*/ | ||
private data: Map<string, any> = new Map | ||
private data: Map<string, any> = new Map() | ||
@@ -62,8 +62,7 @@ /** | ||
if (this.elementId2startPos.size === 0) { | ||
this.collectStartPositions(this.target.root); | ||
this.collectStartPositions(this.target.root) | ||
} | ||
this.hasDragged = true; | ||
this.hasDragged = true | ||
const moveAction = this.getElementMoves(this.target, event, false) | ||
if (moveAction) | ||
result.push(moveAction); | ||
if (moveAction) result.push(moveAction) | ||
} | ||
@@ -91,3 +90,5 @@ // workaround - when a node is moved and after that an edge, hasDragged is set to true although edges are not movable | ||
const algorithm = ((targetNode as KNode).parent as KNode).properties['org.eclipse.elk.algorithm'] as string | ||
const algorithm = ((targetNode as KNode).parent as KNode).properties[ | ||
'org.eclipse.elk.algorithm' | ||
] as string | ||
// Set algorithm specific data | ||
@@ -107,10 +108,15 @@ if (algorithm === undefined || algorithm.endsWith('layered')) { | ||
if (algorithm === undefined || algorithm.endsWith('layered')) { | ||
return [DeleteStaticConstraintAction.create({ | ||
id: this.target.id | ||
})] | ||
} else if (algorithm.endsWith('rectpacking')) { | ||
return [RectPackDeletePositionConstraintAction.create({ | ||
id: this.target.id | ||
})] | ||
return [ | ||
DeleteStaticConstraintAction.create({ | ||
id: this.target.id, | ||
}), | ||
] | ||
} | ||
if (algorithm.endsWith('rectpacking')) { | ||
return [ | ||
RectPackDeletePositionConstraintAction.create({ | ||
id: this.target.id, | ||
}), | ||
] | ||
} | ||
} | ||
@@ -129,3 +135,3 @@ return super.mouseDown(this.target as SModelElementImpl, event) | ||
mouseEnter(): Action[] { | ||
return []; | ||
return [] | ||
} | ||
@@ -140,6 +146,10 @@ | ||
if (algorithm === undefined || algorithm.endsWith('layered')) { | ||
result = ([setProperty(this.nodes, this.data.get('layered'), this.target)] as (Action | Promise<Action>)[]).concat(super.mouseUp(this.target, event)); | ||
result = ( | ||
[setProperty(this.nodes, this.data.get('layered'), this.target)] as (Action | Promise<Action>)[] | ||
).concat(super.mouseUp(this.target, event)) | ||
} else if (algorithm.endsWith('rectpacking')) { | ||
const parent = this.nodes[0] ? this.nodes[0].parent as KNode : undefined | ||
result = ([setGenerateRectPackAction(this.nodes, this.target, parent, event)] as (Action | Promise<Action>)[]).concat(super.mouseUp(this.target, event)); | ||
const parent = this.nodes[0] ? (this.nodes[0].parent as KNode) : undefined | ||
result = ( | ||
[setGenerateRectPackAction(this.nodes, this.target, parent, event)] as (Action | Promise<Action>)[] | ||
).concat(super.mouseUp(this.target, event)) | ||
} else { | ||
@@ -151,10 +161,10 @@ // Algorithm not supported | ||
// Refresh the diagram according to the moved elements. | ||
if (result.some(action => isAction(action) && action.kind === RefreshDiagramAction.KIND)) { | ||
if (result.some((action) => isAction(action) && action.kind === RefreshDiagramAction.KIND)) { | ||
return result | ||
} else { | ||
return result.concat([RefreshDiagramAction.create()]) | ||
} | ||
} else if (this.target) { | ||
return result.concat([RefreshDiagramAction.create()]) | ||
} | ||
if (this.target) { | ||
this.target.selected = false | ||
const result = super.mouseUp(this.target, event); | ||
const result = super.mouseUp(this.target, event) | ||
this.target = undefined | ||
@@ -165,2 +175,2 @@ return result | ||
} | ||
} | ||
} |
@@ -17,5 +17,7 @@ /* | ||
*/ | ||
// We follow Sprotty's way of redeclaring the interface and its create function, so disable this lint check for this file. | ||
/* eslint-disable no-redeclare */ | ||
import { Action } from 'sprotty-protocol'; | ||
import { DeleteConstraint, LayerConstraint, PositionConstraint, StaticConstraint } from './constraint-types'; | ||
import { Action } from 'sprotty-protocol' | ||
import { DeleteConstraint, LayerConstraint, PositionConstraint, StaticConstraint } from './constraint-types' | ||
@@ -136,2 +138,2 @@ /** | ||
} | ||
} | ||
} |
@@ -18,3 +18,3 @@ /* | ||
import { Direction } from "../constraint-classes" | ||
import { Direction } from '../constraint-classes' | ||
@@ -26,4 +26,7 @@ /** | ||
begin: number | ||
end: number | ||
mid: number | ||
/** | ||
@@ -38,2 +41,3 @@ * Where up is, is determined by the direction | ||
bottomBorder: number | ||
/** | ||
@@ -50,3 +54,2 @@ * 0: UNDEFINED, 1: RIGHT, 2: LEFT, 3: DOWN, 4: UP | ||
} | ||
} | ||
@@ -66,3 +69,5 @@ | ||
id: string | ||
layer: number | ||
layerCons: number | ||
@@ -76,3 +81,5 @@ } | ||
id: string | ||
position: number | ||
posCons: number | ||
@@ -86,6 +93,10 @@ } | ||
id: string | ||
layer: number | ||
position: number | ||
posCons: number | ||
layerCons: number | ||
} | ||
} |
@@ -18,8 +18,8 @@ /* | ||
import { SModelElementImpl } from 'sprotty'; | ||
import { Action } from 'sprotty-protocol'; | ||
import { RefreshDiagramAction } from '../actions'; | ||
import { Direction, KEdge, KNode } from '../constraint-classes'; | ||
import { SetLayerConstraintAction, SetPositionConstraintAction, SetStaticConstraintAction } from './actions'; | ||
import { Layer } from './constraint-types'; | ||
import { SModelElementImpl } from 'sprotty' | ||
import { Action } from 'sprotty-protocol' | ||
import { RefreshDiagramAction } from '../actions' | ||
import { Direction, KEdge, KNode } from '../constraint-classes' | ||
import { SetLayerConstraintAction, SetPositionConstraintAction, SetStaticConstraintAction } from './actions' | ||
import { Layer } from './constraint-types' | ||
@@ -29,7 +29,7 @@ /** | ||
*/ | ||
export const PLACEMENT_TOP_BOTTOM_OFFSET = 20; | ||
export const PLACEMENT_TOP_BOTTOM_OFFSET = 20 | ||
/** | ||
* Layer padding for one layer case. | ||
*/ | ||
export const ONE_LAYER_PADDING = 10; | ||
export const ONE_LAYER_PADDING = 10 | ||
@@ -43,4 +43,6 @@ /** | ||
export function getLayerOfNode(node: KNode, nodes: KNode[], layers: Layer[], direction: Direction): number { | ||
const coordinateInLayoutDirection = (direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.LEFT) | ||
? node.position.x + node.size.width / 2 : node.position.y + node.size.height / 2 | ||
const coordinateInLayoutDirection = | ||
direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.LEFT | ||
? node.position.x + node.size.width / 2 | ||
: node.position.y + node.size.height / 2 | ||
@@ -50,5 +52,7 @@ // check for all layers if the node is in the layer | ||
const layer = layers[i] | ||
if (coordinateInLayoutDirection < layer.end && | ||
(direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN) || | ||
coordinateInLayoutDirection > layer.end && (direction === Direction.LEFT || direction === Direction.UP)) { | ||
if ( | ||
(coordinateInLayoutDirection < layer.end && | ||
(direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN)) || | ||
(coordinateInLayoutDirection > layer.end && (direction === Direction.LEFT || direction === Direction.UP)) | ||
) { | ||
return i | ||
@@ -76,6 +80,9 @@ } | ||
export function getActualLayer(node: KNode, nodes: KNode[], layerCandidate: number): number { | ||
// Examine all nodes that have a layer Id left or equal to the layerCandidate and that have a layerCons > their layerId | ||
const layerConstraintLeftOfCandidate = nodes.filter(n => n.properties['org.eclipse.elk.layered.layering.layerId'] as number <= layerCandidate | ||
&& (n.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] as number) > (n.properties['org.eclipse.elk.layered.layering.layerId'] as number)) | ||
const layerConstraintLeftOfCandidate = nodes.filter( | ||
(n) => | ||
(n.properties['org.eclipse.elk.layered.layering.layerId'] as number) <= layerCandidate && | ||
(n.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] as number) > | ||
(n.properties['org.eclipse.elk.layered.layering.layerId'] as number) | ||
) | ||
@@ -101,3 +108,4 @@ // In case that there are no such nodes return the layerCandidate | ||
if (nodeWithMaxCons !== null) { | ||
const idDiff = layerCandidate - (nodeWithMaxCons.properties['org.eclipse.elk.layered.layering.layerId'] as number) | ||
const idDiff = | ||
layerCandidate - (nodeWithMaxCons.properties['org.eclipse.elk.layered.layering.layerId'] as number) | ||
return maxCons + idDiff | ||
@@ -122,5 +130,10 @@ } | ||
const upperNeighbor = layerNodes[upperIndex] | ||
const posConsOfUpper = upperNeighbor.properties['org.eclipse.elk.layered.crossingMinimization.positionChoiceConstraint'] as number | ||
const posConsOfUpper = upperNeighbor.properties[ | ||
'org.eclipse.elk.layered.crossingMinimization.positionChoiceConstraint' | ||
] as number | ||
if (posConsOfUpper > upperIndex) { | ||
if (alreadyInLayer && upperNeighbor.properties['org.eclipse.elk.layered.crossingMinimization.positionId'] === localTargetIndex) { | ||
if ( | ||
alreadyInLayer && | ||
upperNeighbor.properties['org.eclipse.elk.layered.crossingMinimization.positionId'] === localTargetIndex | ||
) { | ||
localTargetIndex = posConsOfUpper | ||
@@ -141,9 +154,19 @@ } else { | ||
// All nodes within one hierarchy level have the same direction | ||
nodes.sort((a, b) => (a.properties['org.eclipse.elk.layered.layering.layerId'] as number) - (b.properties['org.eclipse.elk.layered.layering.layerId'] as number)) | ||
nodes.sort( | ||
(a, b) => | ||
(a.properties['org.eclipse.elk.layered.layering.layerId'] as number) - | ||
(b.properties['org.eclipse.elk.layered.layering.layerId'] as number) | ||
) | ||
const layers = [] | ||
let layer = 0 | ||
// Begin coordinate of layer, depending of on the layout direction this might be a x or y coordinate | ||
let beginCoordinate = (direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN) ? Number.MAX_VALUE : Number.MIN_VALUE | ||
let beginCoordinate = | ||
direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN | ||
? Number.MAX_VALUE | ||
: Number.MIN_VALUE | ||
// End coordinate of layer, depending of on the layout direction this might be a x or y coordinate | ||
let endCoordinate = (direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN) ? Number.MIN_VALUE : Number.MAX_VALUE | ||
let endCoordinate = | ||
direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN | ||
? Number.MIN_VALUE | ||
: Number.MAX_VALUE | ||
let topBorder = Number.MAX_VALUE // naming fits to the RIGHT direction (1) | ||
@@ -156,5 +179,16 @@ let bottomBorder = Number.MIN_VALUE | ||
// node is in the next layer | ||
layers[layer] = new Layer(beginCoordinate, endCoordinate, beginCoordinate + (endCoordinate - beginCoordinate) / 2, direction) | ||
beginCoordinate = (direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN) ? Number.MAX_VALUE : Number.MIN_VALUE | ||
endCoordinate = (direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN) ? Number.MIN_VALUE : Number.MAX_VALUE | ||
layers[layer] = new Layer( | ||
beginCoordinate, | ||
endCoordinate, | ||
beginCoordinate + (endCoordinate - beginCoordinate) / 2, | ||
direction | ||
) | ||
beginCoordinate = | ||
direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN | ||
? Number.MAX_VALUE | ||
: Number.MIN_VALUE | ||
endCoordinate = | ||
direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN | ||
? Number.MIN_VALUE | ||
: Number.MAX_VALUE | ||
layer++ | ||
@@ -169,3 +203,4 @@ } | ||
switch (direction) { | ||
case Direction.UNDEFINED: case Direction.RIGHT: { | ||
case Direction.UNDEFINED: | ||
case Direction.RIGHT: { | ||
currentBegin = node.shadow ? node.shadowX : node.position.x | ||
@@ -175,3 +210,3 @@ currentEnd = currentBegin + node.size.width | ||
currentBottomBorder = currentTopBorder + node.size.height | ||
break; | ||
break | ||
} | ||
@@ -183,3 +218,3 @@ case Direction.LEFT: { | ||
currentBottomBorder = currentTopBorder + node.size.height | ||
break; | ||
break | ||
} | ||
@@ -191,3 +226,3 @@ case Direction.DOWN: { | ||
currentBottomBorder = currentTopBorder + node.size.width | ||
break; | ||
break | ||
} | ||
@@ -199,11 +234,18 @@ case Direction.UP: { | ||
currentBottomBorder = currentTopBorder + node.size.width | ||
break; | ||
break | ||
} | ||
default: { | ||
console.error('error in constraint-utils.ts, unexpected direction in switch') | ||
} | ||
} | ||
// update coordinates of the current layer | ||
beginCoordinate = (direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN) ? | ||
Math.min(currentBegin, beginCoordinate) : Math.max(currentBegin, beginCoordinate) | ||
endCoordinate = (direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN) ? | ||
Math.max(currentEnd, endCoordinate) : Math.min(currentEnd, endCoordinate) | ||
beginCoordinate = | ||
direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN | ||
? Math.min(currentBegin, beginCoordinate) | ||
: Math.max(currentBegin, beginCoordinate) | ||
endCoordinate = | ||
direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.DOWN | ||
? Math.max(currentEnd, endCoordinate) | ||
: Math.min(currentEnd, endCoordinate) | ||
topBorder = Math.min(currentTopBorder, topBorder) | ||
@@ -213,6 +255,11 @@ bottomBorder = Math.max(currentBottomBorder, bottomBorder) | ||
// add last layer | ||
layers[layer] = new Layer(beginCoordinate, endCoordinate, beginCoordinate + ((endCoordinate - beginCoordinate) / 2), direction) | ||
layers[layer] = new Layer( | ||
beginCoordinate, | ||
endCoordinate, | ||
beginCoordinate + (endCoordinate - beginCoordinate) / 2, | ||
direction | ||
) | ||
// offset above & below the layers | ||
topBorder = topBorder - PLACEMENT_TOP_BOTTOM_OFFSET | ||
bottomBorder = bottomBorder + PLACEMENT_TOP_BOTTOM_OFFSET | ||
topBorder -= PLACEMENT_TOP_BOTTOM_OFFSET | ||
bottomBorder += PLACEMENT_TOP_BOTTOM_OFFSET | ||
// update left and right bounds of the layers and set y bounds | ||
@@ -237,30 +284,34 @@ for (let i = 0; i < layers.length - 1; i++) { | ||
switch (direction) { | ||
case Direction.UNDEFINED: case Direction.RIGHT: { | ||
firstLayer.begin = firstLayer.begin - ONE_LAYER_PADDING | ||
firstLayer.end = firstLayer.end + ONE_LAYER_PADDING | ||
case Direction.UNDEFINED: | ||
case Direction.RIGHT: { | ||
firstLayer.begin -= ONE_LAYER_PADDING | ||
firstLayer.end += ONE_LAYER_PADDING | ||
firstLayer.topBorder = topBorder | ||
firstLayer.bottomBorder = bottomBorder | ||
break; | ||
break | ||
} | ||
case Direction.LEFT: { | ||
firstLayer.begin = firstLayer.begin + ONE_LAYER_PADDING | ||
firstLayer.end = firstLayer.end - ONE_LAYER_PADDING | ||
firstLayer.begin += ONE_LAYER_PADDING | ||
firstLayer.end -= ONE_LAYER_PADDING | ||
firstLayer.topBorder = topBorder | ||
firstLayer.bottomBorder = bottomBorder | ||
break; | ||
break | ||
} | ||
case Direction.DOWN: { | ||
firstLayer.begin = firstLayer.begin - ONE_LAYER_PADDING | ||
firstLayer.end = firstLayer.end + ONE_LAYER_PADDING | ||
firstLayer.begin -= ONE_LAYER_PADDING | ||
firstLayer.end += ONE_LAYER_PADDING | ||
firstLayer.topBorder = topBorder | ||
firstLayer.bottomBorder = bottomBorder | ||
break; | ||
break | ||
} | ||
case Direction.UP: { | ||
firstLayer.begin = firstLayer.begin + ONE_LAYER_PADDING | ||
firstLayer.end = firstLayer.end - ONE_LAYER_PADDING | ||
firstLayer.begin += ONE_LAYER_PADDING | ||
firstLayer.end -= ONE_LAYER_PADDING | ||
firstLayer.topBorder = topBorder | ||
firstLayer.bottomBorder = bottomBorder | ||
break; | ||
break | ||
} | ||
default: { | ||
console.error('error in constraint-utils.ts, unexpected direction in switch') | ||
} | ||
} | ||
@@ -344,6 +395,8 @@ } else { | ||
// check the connected nodes for layer constraints | ||
for (const node of connectedNodes) { | ||
if (node.properties['org.eclipse.elk.layered.layering.layerId'] === layer | ||
&& node.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] !== -1 | ||
&& node.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] !== undefined) { | ||
for (const connectedNode of connectedNodes) { | ||
if ( | ||
connectedNode.properties['org.eclipse.elk.layered.layering.layerId'] === layer && | ||
connectedNode.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] !== -1 && | ||
connectedNode.properties['org.eclipse.elk.layered.layering.layerChoiceConstraint'] !== undefined | ||
) { | ||
// layer is forbidden for the given node | ||
@@ -364,4 +417,6 @@ return true | ||
export function shouldOnlyLCBeSet(node: KNode, layers: Layer[], direction: Direction): boolean { | ||
const coordinateToCheck = (direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.LEFT) ? | ||
node.position.y : node.position.x | ||
const coordinateToCheck = | ||
direction === Direction.UNDEFINED || direction === Direction.RIGHT || direction === Direction.LEFT | ||
? node.position.y | ||
: node.position.x | ||
if (layers.length !== 0) { | ||
@@ -381,3 +436,3 @@ const layerTop = layers[0].topBorder | ||
const targetNode: KNode = target as KNode | ||
const direction = targetNode.direction | ||
const { direction } = targetNode | ||
// calculate layer and position the target has in the graph at the new position | ||
@@ -387,3 +442,7 @@ const layerOfTarget = getLayerOfNode(targetNode, nodes, layers, direction) | ||
const positionOfTarget = getPositionInLayer(nodesOfLayer, targetNode) | ||
const newPositionCons = getActualTargetIndex(positionOfTarget, nodesOfLayer.indexOf(targetNode) !== -1, nodesOfLayer) | ||
const newPositionCons = getActualTargetIndex( | ||
positionOfTarget, | ||
nodesOfLayer.indexOf(targetNode) !== -1, | ||
nodesOfLayer | ||
) | ||
const newLayerCons = getActualLayer(targetNode, nodes, layerOfTarget) | ||
@@ -395,3 +454,4 @@ const forbidden = isLayerForbidden(targetNode, newLayerCons) | ||
return RefreshDiagramAction.create() | ||
} else if (targetNode.properties['org.eclipse.elk.layered.layering.layerId'] !== layerOfTarget) { | ||
} | ||
if (targetNode.properties['org.eclipse.elk.layered.layering.layerId'] !== layerOfTarget) { | ||
// layer constraint should only be set if the layer index changed | ||
@@ -403,28 +463,25 @@ if (shouldOnlyLCBeSet(targetNode, layers, direction)) { | ||
layer: layerOfTarget, | ||
layerCons: newLayerCons | ||
}) | ||
} else { | ||
// If layer and position constraint should be set - send them both in one StaticConstraint | ||
return SetStaticConstraintAction.create({ | ||
id: targetNode.id, | ||
layer: layerOfTarget, | ||
layerCons: newLayerCons, | ||
position: positionOfTarget, | ||
posCons: newPositionCons | ||
}) | ||
} | ||
} else { | ||
// position constraint should only be set if the position of the node changed | ||
if (targetNode.properties['org.eclipse.elk.layered.crossingMinimization.positionId'] !== positionOfTarget) { | ||
// set the position Constraint | ||
return SetPositionConstraintAction.create({ | ||
id: targetNode.id, | ||
position: positionOfTarget, | ||
posCons: newPositionCons | ||
}) | ||
} | ||
// If layer and position constraint should be set - send them both in one StaticConstraint | ||
return SetStaticConstraintAction.create({ | ||
id: targetNode.id, | ||
layer: layerOfTarget, | ||
layerCons: newLayerCons, | ||
position: positionOfTarget, | ||
posCons: newPositionCons, | ||
}) | ||
} | ||
// position constraint should only be set if the position of the node changed | ||
if (targetNode.properties['org.eclipse.elk.layered.crossingMinimization.positionId'] !== positionOfTarget) { | ||
// set the position Constraint | ||
return SetPositionConstraintAction.create({ | ||
id: targetNode.id, | ||
position: positionOfTarget, | ||
posCons: newPositionCons, | ||
}) | ||
} | ||
// If the node was moved without setting a constraint - let it snap back | ||
return RefreshDiagramAction.create() | ||
} | ||
} |
@@ -17,5 +17,7 @@ /* | ||
*/ | ||
// We follow Sprotty's way of redeclaring the interface and its create function, so disable this lint check for this file. | ||
/* eslint-disable no-redeclare */ | ||
import { Action } from 'sprotty-protocol'; | ||
import { AspectRatio, RectPackDeletePositionConstraint, RectPackSetPositionConstraint } from './constraint-types'; | ||
import { Action } from 'sprotty-protocol' | ||
import { AspectRatio, RectPackDeletePositionConstraint, RectPackSetPositionConstraint } from './constraint-types' | ||
@@ -77,2 +79,2 @@ /** | ||
} | ||
} | ||
} |
@@ -18,7 +18,8 @@ /* | ||
/** | ||
* An aspect ratio constraint data class. | ||
*/ | ||
/** | ||
* An aspect ratio constraint data class. | ||
*/ | ||
export class AspectRatio { | ||
id: string | ||
aspectRatio: number | ||
@@ -39,3 +40,4 @@ } | ||
id: string | ||
order: number | ||
} |
@@ -18,7 +18,8 @@ /* | ||
import { getAbsoluteBounds } from 'sprotty'; | ||
import { Action, Bounds } from 'sprotty-protocol'; | ||
import { RectPackSetPositionConstraintAction, SetAspectRatioAction } from './actions'; | ||
import { RefreshDiagramAction } from '../actions'; | ||
import { KNode } from '../constraint-classes'; | ||
import { getAbsoluteBounds } from 'sprotty' | ||
import { Action, Bounds } from 'sprotty-protocol' | ||
import { RectPackSetPositionConstraintAction, SetAspectRatioAction } from './actions' | ||
import { RefreshDiagramAction } from '../actions' | ||
import { KNode } from '../constraint-classes' | ||
/* global MouseEvent */ | ||
@@ -32,11 +33,16 @@ /** | ||
*/ | ||
export function setGenerateRectPackAction(nodes: KNode[], target: KNode, parent: KNode | undefined, event: MouseEvent): Action { | ||
export function setGenerateRectPackAction( | ||
nodes: KNode[], | ||
target: KNode, | ||
parent: KNode | undefined, | ||
event: MouseEvent | ||
): Action { | ||
// If node is not put to a valid position the diagram will be refreshed. | ||
let result: Action = RefreshDiagramAction.create() | ||
// If the node is moved on top of another node it takes its place. | ||
nodes.forEach(node => { | ||
nodes.forEach((node) => { | ||
if (node.id !== target.id) { | ||
const targetBounds = getAbsoluteBounds(node) | ||
const canvasBounds = target.root.canvasBounds; | ||
const boundsInWindow = Bounds.translate(targetBounds, canvasBounds); | ||
const { canvasBounds } = target.root | ||
const boundsInWindow = Bounds.translate(targetBounds, canvasBounds) | ||
const lowX = boundsInWindow.x | ||
@@ -46,4 +52,3 @@ const lowY = boundsInWindow.y | ||
const highY = boundsInWindow.y + boundsInWindow.height | ||
if (event.pageX > lowX && event.pageX < highX | ||
&& event.pageY > lowY && event.pageY < highY) { | ||
if (event.pageX > lowX && event.pageX < highX && event.pageY > lowY && event.pageY < highY) { | ||
let actualPosition = node.properties['org.eclipse.elk.rectPacking.currentPosition'] as number | ||
@@ -55,7 +60,10 @@ if (node.properties['org.eclipse.elk.alg.rectpacking.desiredPosition'] !== -1) { | ||
if (node.properties['org.eclipse.elk.alg.rectpacking.desiredPosition'] !== -1) { | ||
actualTargetPosition = target.properties['org.eclipse.elk.alg.rectpacking.desiredPosition'] as number | ||
actualTargetPosition = target.properties[ | ||
'org.eclipse.elk.alg.rectpacking.desiredPosition' | ||
] as number | ||
} | ||
if (actualPosition !== actualTargetPosition && actualPosition !== -1) { | ||
result = RectPackSetPositionConstraintAction.create({ | ||
id: target.id, order: actualPosition | ||
id: target.id, | ||
order: actualPosition, | ||
}) | ||
@@ -65,3 +73,3 @@ } | ||
} | ||
}); | ||
}) | ||
if (result.kind === RefreshDiagramAction.KIND) { | ||
@@ -75,3 +83,3 @@ // Case node should not be swapped. | ||
let maxY: number = Number.MIN_VALUE | ||
nodes.forEach(node => { | ||
nodes.forEach((node) => { | ||
if (node.position.x < x) { | ||
@@ -96,3 +104,3 @@ x = node.position.x | ||
id: parent.id, | ||
aspectRatio: aspectRatio | ||
aspectRatio, | ||
}) | ||
@@ -102,2 +110,2 @@ } | ||
return result | ||
} | ||
} |
@@ -23,5 +23,6 @@ /* | ||
*/ | ||
export const lockPath = "M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 " + | ||
"152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 " + | ||
"0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z" | ||
export const lockPath = | ||
'M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 ' + | ||
'152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 ' + | ||
'0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z' | ||
@@ -33,5 +34,6 @@ /** | ||
*/ | ||
export const arrowVertical = "M214.059 377.941H168V134.059h46.059c21.382 0 32.09-25.851 16.971-40.971L144.971 " + | ||
"7.029c-9.373-9.373-24.568-9.373-33.941 0L24.971 93.088c-15.119 15.119-4.411 40.971 16.971 40.971H88v243.882H41.941c-21.382 " + | ||
"0-32.09 25.851-16.971 40.971l86.059 86.059c9.373 9.373 24.568 9.373 33.941 0l86.059-86.059c15.12-15.119 4.412-40.971-16.97-40.971z" | ||
export const arrowVertical = | ||
'M214.059 377.941H168V134.059h46.059c21.382 0 32.09-25.851 16.971-40.971L144.971 ' + | ||
'7.029c-9.373-9.373-24.568-9.373-33.941 0L24.971 93.088c-15.119 15.119-4.411 40.971 16.971 40.971H88v243.882H41.941c-21.382 ' + | ||
'0-32.09 25.851-16.971 40.971l86.059 86.059c9.373 9.373 24.568 9.373 33.941 0l86.059-86.059c15.12-15.119 4.412-40.971-16.97-40.971z' | ||
@@ -43,4 +45,5 @@ /** | ||
*/ | ||
export const arrowHorizontal = "M377.941 169.941V216H134.059v-46.059c0-21.382-25.851-32.09-40.971-16.971L7.029 " + | ||
"239.029c-9.373 9.373-9.373 24.568 0 33.941l86.059 86.059c15.119 15.119 40.971 4.411 40.971-16.971V296h243.882v46.059c0 " + | ||
"21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.568 0-33.941l-86.059-86.059c-15.119-15.12-40.971-4.412-40.971 16.97z" | ||
export const arrowHorizontal = | ||
'M377.941 169.941V216H134.059v-46.059c0-21.382-25.851-32.09-40.971-16.971L7.029 ' + | ||
'239.029c-9.373 9.373-9.373 24.568 0 33.941l86.059 86.059c15.119 15.119 40.971 4.411 40.971-16.971V296h243.882v46.059c0 ' + | ||
'21.382 25.851 32.09 40.971 16.971l86.059-86.059c9.373-9.373 9.373-24.568 0-33.941l-86.059-86.059c-15.119-15.12-40.971-4.412-40.971 16.97z' |
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
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
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
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
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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 6 instances in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 6 instances in 1 package
230938
4176
4
+ Addedinversify@^6.0.2
+ Addedsnabbdom@^3.5.1
+ Addedsprotty-protocol@^1.1.0
+ Addedsnabbdom@3.6.2(transitive)