UNPKG

@eclipse-glsp/layout-elk

Version:

Integration of ELK graph layout algorithms in GLSP Node Server

65 lines 4.06 kB
/******************************************************************************** * Copyright (c) 2018-2025 TypeFox and others. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License v. 2.0 are satisfied: GNU General Public License, version 2 * with the GNU Classpath Exception which is available at * https://www.gnu.org/software/classpath/license.html. * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ import { GEdge, GGraph, GLabel, GModelElement, GModelElementConstructor, GModelRoot, GNode, GPort, GShapeElement, LayoutEngine, LayoutOperation, Logger, MaybePromise, ModelState } from '@eclipse-glsp/server'; import { ELK, ElkExtendedEdge, ElkGraphElement, ElkLabel, ElkNode, ElkPort, ElkShape } from 'elkjs/lib/elk-api'; import { ElementFilter } from './element-filter'; import { LayoutConfigurator } from './layout-configurator'; /** * Factory for ELK instances. Follow the elkjs package documentation on how to configure ELK * instances. For example, the bundled version can be used by importing the ELK constructor * from `"elkjs/lib/elk.bundled"`. For the webworker version, import the constructor from * `"elkjs/lib/elk-api"` and add the option `workerUrl: "elk/elk-worker.min.js"`. */ export type ElkFactory = () => ELK; export declare const ElkFactory: unique symbol; /** * An implementation of GLSP's {@link LayoutEngine} interface that retrieves the graphical model from the {@link ModelState}, * transforms this model into an ELK graph and then invokes the underlying ELK instance for layout computation. */ export declare class GlspElkLayoutEngine implements LayoutEngine { protected readonly filter: ElementFilter; protected readonly configurator: LayoutConfigurator; protected modelState: ModelState; protected readonly logger: Logger; protected readonly elk: ELK; protected elkEdges: ElkExtendedEdge[]; protected idToElkElement: Map<string, ElkGraphElement>; constructor(elkFactory: ElkFactory, filter: ElementFilter, configurator: LayoutConfigurator, modelState: ModelState); layout(operation?: LayoutOperation): MaybePromise<GModelRoot>; protected transformToElk(model: GGraph): ElkNode; protected transformToElk(model: GNode): ElkNode; protected transformToElk(model: GEdge): ElkExtendedEdge; protected transformToElk(model: GLabel): ElkLabel; protected transformToElk(model: GPort): ElkPort; /** * Searches for all children of the given element that are an instance of the given {@link GModelElementConstructor} * and are included by the {@link ElementFilter}. Also considers children that are nested inside of {@link GCompartment}s. * @param element The element whose children should be queried. * @param constructor The class instance that should be matched * @returns A list of all matching children. */ protected findChildren<G extends GModelElement>(element: GModelElement, constructor: GModelElementConstructor<G>): G[]; protected findCommonAncestor(elkEdge: ElkExtendedEdge): ElkNode | undefined; protected transformGraph(graph: GGraph): ElkGraphElement; protected transformNode(node: GNode): ElkNode; protected transformShape(elkShape: ElkShape, shape: GShapeElement): void; protected transformEdge(edge: GEdge): ElkExtendedEdge; protected transformLabel(label: GLabel): ElkLabel; protected transformPort(port: GPort): ElkPort; protected applyLayout(elkNode: ElkNode): void; protected applyShape(shape: GShapeElement, elkShape: ElkShape): void; protected applyEdge(edge: GEdge, elkEdge: ElkExtendedEdge): void; } //# sourceMappingURL=glsp-elk-layout-engine.d.ts.map