@kieler/klighd-core
Version:
Core KLighD diagram visualization with Sprotty
178 lines • 9.55 kB
TypeScript
import { KGraphData, SKGraphElement } from '@kieler/klighd-interactive/lib/constraint-classes';
import { Bounds, Point } from 'sprotty-protocol';
import { SKGraphModelRenderer } from './skgraph-model-renderer';
import { Decoration, KColoring, KHorizontalAlignment, KLineCap, KLineJoin, KLineStyle, KPolyline, KPosition, KRendering, KRotation, KText, KTextUnderline, KVerticalAlignment, SKEdge, SKLabel, VerticalAlignment } from './skgraph-models';
import { ColorStyle, KStyles } from './views-styles';
/**
* Translates a KLineCap into the text needed for the SVG 'stroke-linecap' attribute.
* @param lineCap The KLineCap.
*/
export declare function lineCapText(lineCap: KLineCap): 'butt' | 'round' | 'square';
/**
* Translates a KLineJoin into the text needed for the SVG 'stroke-linejoin' attribute.
* @param lineJoin The KLineJoin.
*/
export declare function lineJoinText(lineJoin: KLineJoin): 'bevel' | 'miter' | 'round';
/**
* Translates a KLineStyle into the text needed for the SVG 'stroke-dasharray' attribute.
* If the resulting dasharray would be a solid line, return undefined instead.
* @param lineStyle The KLineStyle
* @param lineWidth The width of the drawn line
*/
export declare function lineStyleText(lineStyle: KLineStyle, lineWidth: number): string | undefined;
/**
* Translates a VerticalAlignment into the text needed for the SVG text 'dominant-baseline' attribute.
* @param verticalAlignment The VerticalAlignment.
*/
export declare function verticalAlignmentText(verticalAlignment: VerticalAlignment): 'middle' | 'baseline' | 'hanging';
/**
* Translates a KTextUnderline into the text needed for the SVG 'text-decoration-style' attribute.
* @param underline The KTextUnderline.
*/
export declare function textDecorationStyleText(underline: KTextUnderline): 'solid' | 'double' | 'wavy' | undefined;
export declare function textDecorationColor(underline: KTextUnderline): string | undefined;
/**
* Calculates the x-coordinate of the text's positioning box when considering its available space and its alignment.
* @param x The calculated x-coordinate pointing to the left coordinate of the text rendering box.
* @param width The available width for the text.
* @param horizontalAlignment The KHorizontalAlignment.
* @param textWidth The real width the rendered text needs.
*/
export declare function calculateX(x: number, width: number, horizontalAlignment: KHorizontalAlignment, textWidth?: number): number;
/**
* Calculates the y-coordinate of the text's positioning box when considering its alignment.
* @param y The calculated y-coordinate pointing to the top coordinate of the text rendering box.
* @param height The available height for the text.
* @param verticalAlignment The KVerticalAlignment.
* @param numberOfLines The number of lines in the given text.
*/
export declare function calculateY(y: number, height: number, verticalAlignment: KVerticalAlignment, numberOfLines: number): number;
/**
* Evaluates a position inside given parent bounds. Inspired by the java method PlacementUtil.evaluateKPosition.
* @param position The position.
* @param parentBounds The parent bounds.
* @param topLeft In case position is undefined assume a topLeft KPosition, and a bottomRight KPosition otherwise.
* @returns The evaluated position.
*/
export declare function evaluateKPosition(position: KPosition, parentBounds: Bounds, topLeft: boolean): Point;
/**
* Tries to find the ID in the given map object.
* @param map The object containing something under the given ID.
* @param idString The ID too look up.
*/
export declare function findById(map: Record<string, unknown>, idString: string): any;
/**
* Returns if the given coloring is a single color and no gradient.
* @param coloring The coloring to check.
*/
export declare function isSingleColor(coloring: KColoring): boolean;
/**
* Returns the SVG fill string representing the given coloring, if it is a single color. Check that with isSingleColor(KColoring) beforehand.
* @param coloring The coloring.
*/
export declare function fillSingleColor(coloring: KColoring): ColorStyle;
/**
* Transforms any string in 'CamelCaseFormat' to a string in 'kebab-case-format'.
* @param string The string to transform.
*/
export declare function camelToKebab(string: string): string;
/**
* Calculate the bounds of the given rendering and the SVG transformation string that has to be applied to the SVG element for this rendering.
* @param rendering The rendering to calculate the bounds and transformation for.
* @param kRotation The KRotation style of the rendering.
* @param parent The parent SKGraphElement this rendering is contained in.
* @param context The rendering context used to render this element.
* @param boundingBox If this method should not return the values to be applied to the SVG but the
* box coordinates instead. Required to find the true bounding box of text renderings.
* @param isEdge If the rendering is for an edge.
*/
export declare function findBoundsAndTransformationData(rendering: KRendering, styles: KStyles, parent: SKGraphElement, context: SKGraphModelRenderer, isEdge?: boolean, boundingBox?: boolean): BoundsAndTransformation | undefined;
/**
* Calculate the bounds of the given text rendering and the SVG transformation string that has to be applied to the SVG element for this text.
* @param rendering The text rendering to calculate the bounds and transformation for.
* @param styles The styles for this text rendering
* @param parent The parent SKGraphElement this rendering is contained in.
* @param context The rendering context used to render this element.
*/
export declare function findTextBoundsAndTransformationData(rendering: KText, styles: KStyles, parent: SKGraphElement | SKLabel, context: SKGraphModelRenderer): BoundsAndTransformation | undefined;
/**
* Simple container interface to hold bounds and transformation data.
*/
export interface BoundsAndTransformation {
bounds: Bounds;
transformation: Transformation[];
}
/**
* Transformation data to be easily converted to SVG transformation strings. Data contained in sub-hierarchies.
*/
export interface Transformation {
kind: 'rotate' | 'scale' | 'translate';
}
/**
* A rotation, possibly around a center point. Can be converted to SVG transformation string as `rotate(angle[, x, y])`.
*/
export interface Rotation extends Transformation {
kind: 'rotate';
angle: number;
x?: number;
y?: number;
}
export declare function isRotation(transformation: Transformation): transformation is Rotation;
/**
* A scale. Can be converted to SVG transformation string as `scale(factor)`.
*/
export interface Scale extends Transformation {
kind: 'scale';
factor: number;
}
export declare function isScale(transformation: Transformation): transformation is Scale;
/**
* A translation. Can be converted to SVG transformation string as `translate(x, y)`.
*/
export interface Translation extends Transformation {
kind: 'translate';
x: number;
y: number;
}
export declare function isTranslation(transformation: Transformation): transformation is Translation;
/**
* Converts the transformation into a String, that can be used for the SVG transformation attribute.
* @param transformation The transformation to convert.
* @returns An SVG transformation string.
*/
export declare function transformationToSVGString(transformation: Transformation): string;
/**
* Reverses an array of transformations such that applying the transformation and its reverse counterpart will result in the identity transformation.
* @param transformations The transformations to reverse.
* @returns The reversed transformations.
*/
export declare function reverseTransformations(transformations: Transformation[]): Transformation[];
/**
* Reverses a transformation such that applying the transformation and its reverse counterpart will result in the identity transformation.
* @param transformation The transformation to reverse.
* @returns The reversed transformation.
*/
export declare function reverseTransformation(transformation: Transformation): Transformation;
/**
* Calculates the SVG transformation string that has to be applied to the SVG element.
* @param bounds The bounds of the rendering.
* @param decoration The decoration of the rendering.
* @param kRotation The KRotation style of the rendering.
* @param isEdge If the rendering is for an edge.
* @param isText If the rendering is a text.
*/
export declare function getTransformation(bounds: Bounds, decoration: Decoration, kRotation: KRotation | undefined, isEdge?: boolean, isText?: boolean): Transformation[];
/**
* calculates an array of all points that the polyline rendering should follow.
* @param parent The parent element containing this rendering.
* @param rendering The polyline rendering.
* @param boundsAndTransformation The bounds and transformation data calculated by findBoundsAndTransformation(...).
*/
export declare function getPoints(parent: SKGraphElement | SKEdge, rendering: KPolyline, boundsAndTransformation: BoundsAndTransformation): Point[];
/**
* Looks up the first KRendering in the list of data and returns it. KRenderingReferences are handled and dereferenced as well, so only 'real' renderings are returned.
* @param datas The list of possible renderings.
* @param context The rendering context for this rendering.
*/
export declare function getKRendering(datas: KGraphData[], context: SKGraphModelRenderer): KRendering | undefined;
//# sourceMappingURL=views-common.d.ts.map