Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add number support for identifiers and LayoutOptions values #260

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions test/mocha/testNumberSupport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2024 Kiel University and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
const chai = require("chai");
const chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();

const ELK = require('../../lib/main.js');
const elk = new ELK();

describe('Number support for identifiers and layout option values', function () {
describe('#layout(...)', function () {
it('Layout identifiers should accept number identifiers', function () {
return elk.layout(numberIdentifierGraph)
.should.eventually.be.fulfilled;
})

it('Layout option values should accept number', function () {
return elk.layout(numberOptionGraph)
.should.eventually.be.fulfilled;
})
})
})

const numberIdentifierGraph = {
id: 'root',
layoutOptions: {},
children: [
{ id: 1, width: 30, height: 30 },
{ id: 2, width: 30, height: 30 },
{ id: 3, width: 30, height: 30 }
],
edges: [
{ id: 'e1', sources: [1], targets: [2] },
{ id: 'e2', sources: [1], targets: [3] }
]
};

const numberOptionGraph = {
id: 'root',
layoutOptions: {
'layered.spacing.nodeNodeBetweenLayers': 40
},
children: [
{ id: '1', width: 30, height: 30 },
{ id: '2', width: 30, height: 30 },
{ id: '3', width: 30, height: 30 }
],
edges: [
{ id: 'e1', sources: ['1'], targets: ['2'] },
{ id: 'e2', sources: ['1'], targets: ['3'] }
]
};
114 changes: 58 additions & 56 deletions typings/elk-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,122 +8,124 @@
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/

export type ElkIdentifier = string | number;

export interface LayoutOptions {
[key: string]: string
[key: string]: string | number;
}

export interface ElkPoint {
x: number
y: number
x: number;
y: number;
}

export interface ElkGraphElement {
id?: string
labels?: ElkLabel[]
layoutOptions?: LayoutOptions
id?: ElkIdentifier;
labels?: ElkLabel[];
layoutOptions?: LayoutOptions;
}

export interface ElkShape extends ElkGraphElement {
x?: number
y?: number
width?: number
height?: number
x?: number;
y?: number;
width?: number;
height?: number;
}

export interface ElkNode extends ElkShape {
id: string
children?: ElkNode[]
ports?: ElkPort[]
edges?: ElkExtendedEdge[]
id: ElkIdentifier;
children?: ElkNode[];
ports?: ElkPort[];
edges?: ElkExtendedEdge[];
}

export interface ElkPort extends ElkShape {
id: string
id: ElkIdentifier;
}

export interface ElkLabel extends ElkShape {
text?: string
text?: string;
}

/**
* @deprecated use ElkExtendedEdge directly
*/
export interface ElkEdge extends ElkGraphElement {
id: string
junctionPoints?: ElkPoint[]
id: ElkIdentifier;
junctionPoints?: ElkPoint[];
}

/**
* @deprecated use ElkExtendedEdge instead
*/
export interface ElkPrimitiveEdge extends ElkEdge {
source: string
sourcePort?: string
target: string
targetPort?: string
sourcePoint?: ElkPoint
targetPoint?: ElkPoint
bendPoints?: ElkPoint[]
source: ElkIdentifier;
sourcePort?: ElkIdentifier;
target: ElkIdentifier;
targetPort?: ElkIdentifier;
sourcePoint?: ElkPoint;
targetPoint?: ElkPoint;
bendPoints?: ElkPoint[];
}

export interface ElkExtendedEdge extends ElkEdge {
sources: string[]
targets: string[]
sections?: ElkEdgeSection[]
sources: ElkIdentifier[];
targets: ElkIdentifier[];
sections?: ElkEdgeSection[];
}

export interface ElkEdgeSection extends ElkGraphElement {
id: string
startPoint: ElkPoint
endPoint: ElkPoint
bendPoints?: ElkPoint[]
incomingShape?: string
outgoingShape?: string
incomingSections?: string[]
outgoingSections?: string[]
id: ElkIdentifier;
startPoint: ElkPoint;
endPoint: ElkPoint;
bendPoints?: ElkPoint[];
incomingShape?: ElkIdentifier;
outgoingShape?: ElkIdentifier;
incomingSections?: ElkIdentifier[];
outgoingSections?: ElkIdentifier[];
}

export interface ElkLayoutArguments {
layoutOptions?: LayoutOptions
logging?: boolean
measureExecutionTime?: boolean
layoutOptions?: LayoutOptions;
logging?: boolean;
measureExecutionTime?: boolean;
}

export interface ElkCommonDescription {
id?: string
name?: string
description?: string
id?: ElkIdentifier;
name?: string;
description?: string;
}

export interface ElkLayoutAlgorithmDescription extends ElkCommonDescription {
category?: string
knownOptions?: string[]
supportedFeatures?: string[]
category?: string;
knownOptions?: string[];
supportedFeatures?: string[];
}

export interface ElkLayoutOptionDescription extends ElkCommonDescription {
group?: string
type?: string
targets?: string[]
group?: string;
type?: string;
targets?: string[];
}

export interface ElkLayoutCategoryDescription extends ElkCommonDescription {
knownLayouters?: string[]
knownLayouters?: string[];
}

export interface ELK {
layout(graph: ElkNode, args?: ElkLayoutArguments): Promise<ElkNode>;
knownLayoutAlgorithms(): Promise<ElkLayoutAlgorithmDescription[]>
knownLayoutOptions(): Promise<ElkLayoutOptionDescription[]>
knownLayoutCategories(): Promise<ElkLayoutCategoryDescription[]>
knownLayoutAlgorithms(): Promise<ElkLayoutAlgorithmDescription[]>;
knownLayoutOptions(): Promise<ElkLayoutOptionDescription[]>;
knownLayoutCategories(): Promise<ElkLayoutCategoryDescription[]>;
terminateWorker(): void;
}

export interface ELKConstructorArguments {
defaultLayoutOptions?: LayoutOptions
algorithms?: string[]
workerUrl?: string
workerFactory?: (url?: string) => Worker
defaultLayoutOptions?: LayoutOptions;
algorithms?: string[];
workerUrl?: string;
workerFactory?: (url?: string) => Worker;
}

declare const ElkConstructor: {
Expand Down