jointjs
Version:
JavaScript diagramming library
1,778 lines (1,082 loc) • 142 kB
TypeScript
/*! JointJS v3.4.2 (2021-09-06) - JavaScript diagramming library
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Definitions by:
// Aidan Reel <http://github.com/areel>,
// David Durman <http://github.com/DavidDurman>,
// Ewout Van Gossum <https://github.com/DenEwout>,
// Federico Caselli <https://github.com/CaselIT>,
// Chris Moran <https://github.com/ChrisMoran>
// Michael MacFadden https://github.com/mmacfadden
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// typings: https://github.com/CaselIT/typings-jointjs
/// <reference types="backbone" />
import * as Backbone from "backbone";
export as namespace joint;
export namespace g {
export type Shape = Path | Point | Line | Polyline | Rect | Ellipse;
export interface PlainPoint {
x: number;
y: number;
}
export interface PlainRect {
x: number;
y: number;
width: number;
height: number;
}
export interface Scale {
sx: number;
sy: number;
}
export interface PrecisionOpt {
precision?: number;
}
export interface SubdivisionsOpt extends PrecisionOpt {
subdivisions?: Curve[];
}
export interface SegmentSubdivisionsOpt extends PrecisionOpt {
segmentSubdivisions?: Curve[][];
}
export interface PathT {
segmentIndex: number;
value: number;
}
export interface Segment {
type: SegmentType;
isSegment: boolean;
isSubpathStart: boolean;
isVisible: boolean;
nextSegment: Segment | null;
previousSegment: Segment | null;
subpathStartSegment: Segment | null;
start: Point | null | never; // getter, `never` for Moveto
end: Point | null; // getter or directly assigned
bbox(): Rect | null;
clone(): Segment;
closestPoint(p: Point, opt?: SubdivisionsOpt): Point;
closestPointLength(p: Point, opt?: SubdivisionsOpt): number;
closestPointNormalizedLength(p: Point, opt?: SubdivisionsOpt): number;
closestPointT(p: Point): number;
closestPointTangent(p: Point): Line | null;
divideAt(ratio: number, opt?: SubdivisionsOpt): [Segment, Segment];
divideAtLength(length: number, opt?: SubdivisionsOpt): [Segment, Segment];
divideAtT(t: number): [Segment, Segment];
equals(segment: Segment): boolean;
getSubdivisions(): Curve[];
isDifferentiable(): boolean;
length(): number;
lengthAtT(t: number, opt?: PrecisionOpt): number;
pointAt(ratio: number): Point;
pointAtLength(length: number): Point;
pointAtT(t: number): Point;
round(precision?: number): this;
scale(sx: number, sy: number, origin?: PlainPoint): this;
tangentAt(ratio: number): Line | null;
tangentAtLength(length: number): Line | null;
tangentAtT(t: number): Line | null;
translate(tx?: number, ty?: number): this;
translate(tx: PlainPoint): this;
serialize(): string;
toString(): string;
}
export interface SegmentTypes {
[key: string]: Segment;
}
type CardinalDirection = 'NE' | 'E' | 'SE' | 'S' | 'SW' | 'W' | 'NW' | 'N';
type RectangleSide = 'left' | 'right' | 'top' | 'bottom';
type PathSegmentUnit = Segment | Segment[];
type PathObjectUnit = Line | Line[] | Curve | Curve[];
type SegmentType = 'L' | 'C' | 'M' | 'Z' | 'z';
export function normalizeAngle(angle: number): number;
export function snapToGrid(val: number, gridSize: number): number;
export function toDeg(rad: number): number;
export function toRad(deg: number, over360?: boolean): number;
export function random(min?: number, max?: number): number;
class Curve {
start: Point;
controlPoint1: Point;
controlPoint2: Point;
end: Point;
constructor(p1: PlainPoint | string, p2: PlainPoint | string, p3: PlainPoint | string, p4: PlainPoint | string);
constructor(curve: Curve);
bbox(): Rect;
clone(): Curve;
closestPoint(p: PlainPoint, opt?: SubdivisionsOpt): Point;
closestPointLength(p: PlainPoint, opt?: SubdivisionsOpt): number;
closestPointNormalizedLength(p: PlainPoint, opt?: SubdivisionsOpt): number;
closestPointT(p: PlainPoint, opt?: SubdivisionsOpt): number;
closestPointTangent(p: PlainPoint, opt?: SubdivisionsOpt): Line | null;
containsPoint(p: PlainPoint, opt?: SubdivisionsOpt): boolean;
divideAt(ratio: number, opt?: SubdivisionsOpt): [Curve, Curve];
divideAtLength(length: number, opt?: SubdivisionsOpt): [Curve, Curve];
divideAtT(t: number): [Curve, Curve];
divide(t: number): [Curve, Curve]; // alias to `divideAtT`
endpointDistance(): number;
equals(c: Curve): boolean;
getSkeletonPoints(t: number): [Point, Point, Point, Point, Point];
getSubdivisions(opt?: PrecisionOpt): Curve[];
isDifferentiable(): boolean;
length(opt?: SubdivisionsOpt): number;
lengthAtT(t: number, opt?: PrecisionOpt): number;
pointAt(ratio: number, opt?: SubdivisionsOpt): Point;
pointAtLength(length: number, opt?: SubdivisionsOpt): Point;
pointAtT(t: number): Point;
round(precision?: number): this;
scale(sx: number, sy: number, origin?: PlainPoint | string): this;
tangentAt(ratio: number, opt?: SubdivisionsOpt): Line | null;
tangentAtLength(length: number, opt?: SubdivisionsOpt): Line | null;
tangentAtT(t: number): Line | null;
tAt(ratio: number, opt?: SubdivisionsOpt): number;
tAtLength(length: number, opt?: SubdivisionsOpt): number;
translate(tx?: number, ty?: number): this;
translate(tx: PlainPoint): this;
toPoints(opt?: SubdivisionsOpt): Point[];
toPolyline(opt?: SubdivisionsOpt): Polyline;
toString(): string;
static throughPoints(points: PlainPoint[]): Curve[];
}
class Ellipse {
x: number;
y: number;
a: number;
b: number;
constructor(center: PlainPoint | string, a: number, b: number);
constructor(ellipse: Ellipse);
bbox(): Rect;
center(): Point;
clone(): Ellipse;
containsPoint(p: PlainPoint): boolean;
equals(ellipse: Ellipse): boolean;
inflate(dx?: number, dy?: number): this;
intersectionWithLine(l: Line): Point[] | null;
intersectionWithLineFromCenterToPoint(p: PlainPoint, angle?: number): Point;
normalizedDistance(point: PlainPoint): number;
round(precision?: number): this;
tangentTheta(p: PlainPoint): number;
toString(): string;
static fromRect(rect: PlainRect): Ellipse;
}
class Line {
start: Point;
end: Point;
constructor(p1: PlainPoint | string, p2: PlainPoint | string);
constructor(line: Line);
constructor();
angle(): number;
bbox(): Rect;
bearing(): CardinalDirection;
clone(): Line;
parallel(): Line;
closestPoint(p: PlainPoint | string): Point;
closestPointLength(p: PlainPoint | string): number;
closestPointNormalizedLength(p: PlainPoint | string): number;
closestPointTangent(p: PlainPoint | string): Line | null;
containsPoint(p: PlainPoint): boolean;
divideAt(t: number): [Line, Line];
divideAtLength(length: number): [Line, Line];
equals(line: Line): boolean;
intersect(line: Line): Point | null; // Backwards compatibility, should return an array
intersect(rect: Rect): Point[] | null;
intersect(ellipse: Ellipse): Point[] | null;
intersect(polyline: Polyline): Point[] | null;
intersect(path: Path, opt?: SegmentSubdivisionsOpt): Point[] | null;
intersectionWithLine(l: Line): Point[] | null;
isDifferentiable(): boolean;
length(): number;
midpoint(): Point;
pointAt(t: number): Point;
pointAtLength(length: number): Point;
pointOffset(p: PlainPoint | string): number;
rotate(origin: PlainPoint, angle: number): this;
round(precision?: number): this;
scale(sx: number, sy: number, origin?: PlainPoint): this;
setLength(length: number): this;
squaredLength(): number;
tangentAt(t: number): Line | null;
tangentAtLength(length: number): Line | null;
translate(tx?: number, ty?: number): this;
translate(tx: PlainPoint): this;
vector(): Point;
toString(): string;
serialize(): string;
}
class Path {
segments: Segment[];
start: Point | null; // getter
end: Point | null; // getter
constructor();
constructor(pathData: string);
constructor(segments: PathSegmentUnit | PathSegmentUnit[]);
constructor(objects: PathObjectUnit | PathObjectUnit[]);
constructor(polyline: Polyline);
appendSegment(segments: PathSegmentUnit | PathSegmentUnit[]): void;
bbox(): Rect | null;
clone(): Path;
closestPoint(p: Point, opt?: SegmentSubdivisionsOpt): Point | null;
closestPointLength(p: Point, opt?: SegmentSubdivisionsOpt): number;
closestPointNormalizedLength(p: Point, opt?: SegmentSubdivisionsOpt): number;
closestPointTangent(p: Point, opt?: SegmentSubdivisionsOpt): Line | null;
containsPoint(p: PlainPoint, opt?: SegmentSubdivisionsOpt): boolean;
divideAt(ratio: number, opt?: SegmentSubdivisionsOpt): [Path, Path] | null;
divideAtLength(length: number, opt?: SegmentSubdivisionsOpt): [Path, Path] | null;
equals(p: Path): boolean;
getSegment(index: number): Segment | null;
getSegmentSubdivisions(opt?: PrecisionOpt): Curve[][];
getSubpaths(): Path[];
insertSegment(index: number, segments: PathSegmentUnit | PathSegmentUnit[]): void;
intersectionWithLine(l: Line, opt?: SegmentSubdivisionsOpt): Point[] | null;
isDifferentiable(): boolean;
isValid(): boolean;
length(opt?: SegmentSubdivisionsOpt): number;
pointAt(ratio: number, opt?: SegmentSubdivisionsOpt): Point | null;
pointAtLength(length: number, opt?: SegmentSubdivisionsOpt): Point | null;
removeSegment(index: number): void;
replaceSegment(index: number, segments: PathSegmentUnit | PathSegmentUnit[]): void;
round(precision?: number): this;
scale(sx: number, sy: number, origin?: PlainPoint | string): this;
segmentAt(ratio: number, opt?: SegmentSubdivisionsOpt): Segment | null;
segmentAtLength(length: number, opt?: SegmentSubdivisionsOpt): Segment | null;
segmentIndexAt(ratio: number, opt?: SegmentSubdivisionsOpt): number | null;
segmentIndexAtLength(length: number, opt?: SegmentSubdivisionsOpt): number | null;
tangentAt(ratio: number, opt?: SegmentSubdivisionsOpt): Line | null;
tangentAtLength(length: number, opt?: SegmentSubdivisionsOpt): Line | null;
toPoints(opt?: SegmentSubdivisionsOpt): Point[][] | null;
toPolylines(opt?: SegmentSubdivisionsOpt): Polyline[] | null;
translate(tx?: number, ty?: number): this;
translate(tx: PlainPoint): this;
serialize(): string;
toString(): string;
validate(): this;
private closestPointT(p: Point, opt?: SegmentSubdivisionsOpt): PathT | null;
private lengthAtT(t: PathT, opt?: SegmentSubdivisionsOpt): number;
private pointAtT(t: PathT): Point | null;
private tangentAtT(t: PathT): Line | null;
private prepareSegment(segment: Segment, previousSegment?: Segment | null, nextSegment?: Segment | null): Segment;
private updateSubpathStartSegment(segment: Segment): void;
static createSegment(type: SegmentType, ...args: any[]): PathSegmentUnit;
static parse(pathData: string): Path;
static segmentTypes: SegmentTypes;
static isDataSupported(pathData: string): boolean;
}
class Point implements PlainPoint {
x: number;
y: number;
constructor(x?: number, y?: number);
constructor(p: PlainPoint | string);
chooseClosest(points: PlainPoint[]): Point | null;
adhereToRect(r: Rect): this;
angleBetween(p1: PlainPoint, p2: PlainPoint) : number;
bearing(p: Point): CardinalDirection;
changeInAngle(dx: number, dy: number, ref: PlainPoint | string): number;
clone(): Point;
cross(p1: PlainPoint, p2: PlainPoint) : number;
difference(dx?: number, dy?: number): Point;
difference(p: PlainPoint): Point;
distance(p: PlainPoint | string): number;
dot(p: PlainPoint): number;
equals(p: Point): boolean;
lerp(p: Point, t: number): Point;
magnitude(): number;
manhattanDistance(p: PlainPoint): number;
move(ref: PlainPoint | string, distance: number): this;
normalize(length: number): this;
offset(dx?: number, dy?: number): this;
offset(p: PlainPoint): this;
reflection(ref: PlainPoint | string): Point;
rotate(origin: PlainPoint | string, angle: number): this;
round(precision?: number): this;
scale(sx: number, sy: number, origin?: PlainPoint | string): this;
snapToGrid(gx: number, gy?: number): this;
squaredDistance(p: PlainPoint | string): number;
theta(p: PlainPoint | string): number;
toJSON(): PlainPoint;
toPolar(origin?: PlainPoint | string): this;
toString(): string;
serialize(): string;
translate(tx?: number, ty?: number): this;
translate(tx: PlainPoint): this;
update(x?: number, y?: number): this;
update(p: PlainPoint): this;
vectorAngle(p: PlainPoint) : number;
static fromPolar(distance: number, angle: number, origin?: PlainPoint | string): Point;
static random(x1: number, x2: number, y1: number, y2: number): Point;
}
class Polyline {
points: Point[];
start: Point | null; // getter
end: Point | null; // getter
constructor();
constructor(svgString: string);
constructor(points: PlainPoint[]);
bbox(): Rect | null;
clone(): Polyline;
closestPoint(p: PlainPoint | string): Point | null;
closestPointLength(p: PlainPoint | string): number;
closestPointNormalizedLength(p: PlainPoint | string): number;
closestPointTangent(p: PlainPoint | string): Line | null;
containsPoint(p: PlainPoint): boolean;
convexHull(): Polyline;
equals(p: Polyline): boolean;
isDifferentiable(): boolean;
intersectionWithLine(l: Line): Point[] | null;
length(): number;
pointAt(ratio: number): Point | null;
pointAtLength(length: number): Point | null;
round(precision?: number): this;
scale(sx: number, sy: number, origin?: PlainPoint | string): this;
simplify(opt?: { threshold?: number }): this;
tangentAt(ratio: number): Line | null;
tangentAtLength(length: number): Line | null;
translate(tx?: number, ty?: number): this;
translate(tx: PlainPoint): this;
serialize(): string;
toString(): string;
static parse(svgString: string): Polyline;
}
class Rect implements PlainRect {
x: number;
y: number;
width: number;
height: number;
constructor(x?: number, y?: number, width?: number, height?: number);
constructor(r: PlainRect);
bbox(angle?: number): Rect;
bottomLeft(): Point;
bottomLine(): Line;
bottomMiddle(): Point;
bottomRight(): Point;
center(): Point;
clone(): Rect;
containsPoint(p: PlainPoint | string): boolean;
containsRect(r: PlainRect): boolean;
corner(): Point;
equals(r: PlainRect): boolean;
inflate(dx?: number, dy?: number): this;
intersect(r: Rect): Rect | null;
intersectionWithLine(l: Line): Point[] | null;
intersectionWithLineFromCenterToPoint(p: PlainPoint | string, angle?: number): Point;
leftLine(): Line;
leftMiddle(): Point;
maxRectScaleToFit(rect: PlainRect, origin?: PlainPoint): Scale;
maxRectUniformScaleToFit(rect: PlainRect, origin?: PlainPoint): number;
moveAndExpand(r: PlainRect): this;
normalize(): this;
offset(dx?: number, dy?: number): this;
offset(p: PlainPoint): this;
origin(): Point;
pointNearestToPoint(point: PlainPoint | string): Point;
rightLine(): Line;
rightMiddle(): Point;
round(precision?: number): this;
scale(sx: number, sy: number, origin?: PlainPoint | string): this;
sideNearestToPoint(point: PlainPoint | string): RectangleSide;
snapToGrid(gx: number, gy?: number): this;
topLeft(): Point;
topLine(): Line;
topMiddle(): Point;
topRight(): Point;
translate(tx?: number, ty?: number): this;
translate(tx: PlainPoint): this;
toJSON(): PlainRect;
toString(): string;
union(rect: PlainRect): Rect;
update(x?: number, y?: number, width?: number, height?: number): this;
update(rect: PlainRect): this;
static fromEllipse(e: Ellipse): Rect;
static fromPointUnion(...points: PlainPoint[]): Rect | null;
static fromRectUnion(...rects: PlainRect[]): Rect | null;
}
namespace bezier {
interface IBezierCurve {
p0: Point;
p1: Point;
p2: Point;
p3: Point;
}
export function curveThroughPoints(points: PlainPoint[] | Point[]): string[];
export function getCurveControlPoints(points: PlainPoint[] | Point[]): [Point[], Point[]];
export function getCurveDivider(
p0: string | PlainPoint,
p1: string | PlainPoint,
p2: string | PlainPoint,
p3: string | PlainPoint
): (t: number) => [IBezierCurve, IBezierCurve];
export function getFirstControlPoints(rhs: number[]): number[];
export function getInversionSolver(
p0: PlainPoint,
p1: PlainPoint,
p2: PlainPoint,
p3: PlainPoint
): (p: PlainPoint) => number;
}
namespace scale {
export function linear(domain: [number, number], range: [number, number], value: number): number;
}
}
export function V(
svg: SVGElement | Vectorizer | string,
attrs?: { [key: string]: any },
children?: Vectorizer | Vectorizer[] | SVGElement | SVGElement[]
): Vectorizer;
export namespace Vectorizer {
interface RotateOptions {
absolute?: boolean;
}
interface AnnotateStringOptions {
includeAnnotationIndices?: boolean;
offset?: number;
}
type TextVerticalAnchor = 'top' | 'bottom' | 'middle';
interface TextOptions {
eol?: string;
x?: number | string;
textVerticalAnchor?: TextVerticalAnchor | number | string;
lineHeight?: number | string;
textPath?: string | { [key: string]: any };
annotations?: TextAnnotation[];
includeAnnotationIndices?: boolean;
displayEmpty?: boolean;
}
interface GetBBoxOptions {
target?: SVGElement | Vectorizer;
recursive?: boolean;
}
interface TransformOptions {
absolute?: boolean;
}
interface ParseXMLOptions {
async?: boolean;
}
interface TextAnnotation {
start: number;
end: number;
attrs: { [key: string]: any };
}
// modifiable Matrix. SVGMatrix doesn't allow set on properties or a constructor.
interface Matrix {
a: number;
b: number;
c: number;
d: number;
e: number;
f: number;
}
interface Sample {
x: number;
y: number;
distance: number;
}
interface DecomposedTransformation {
translateX: number;
translateY: number;
scaleX: number;
scaleY: number;
skewX: number;
skewY: number;
rotation: number;
}
interface RoundedRect extends g.PlainRect {
'rx'?: number;
'ry'?: number;
'top-rx'?: number;
'top-ry'?: number;
'bottom-rx'?: number;
'bottom-ry'?: number;
}
interface Rotation {
angle: number;
cx?: number;
cy?: number;
}
interface Translation {
tx: number;
ty: number;
}
interface Scale {
sx: number;
sy: number;
}
interface Transform {
value: string;
translate: Translation;
rotate: Rotation;
scale: Scale;
}
interface QualifiedAttribute {
ns: string | null;
local: string;
}
}
export class Vectorizer {
id: string;
node: SVGElement;
constructor(
el: string | SVGElement,
attrs?: { [key: string]: any },
children?: Vectorizer | Vectorizer[] | SVGElement | SVGElement[]
);
getTransformToElement(toElem: SVGGElement | Vectorizer): SVGMatrix;
transform(): SVGMatrix;
transform(matrix: SVGMatrix | Vectorizer.Matrix, opt?: Vectorizer.TransformOptions): this;
translate(): Vectorizer.Translation;
translate(tx: number, ty?: number, opt?: Vectorizer.TransformOptions): this;
rotate(): Vectorizer.Rotation;
rotate(angle: number, cx?: number, cy?: number, opt?: Vectorizer.RotateOptions): this;
scale(): Vectorizer.Scale;
scale(sx: number, sy?: number): this;
bbox(withoutTransformations?: boolean, target?: SVGElement | Vectorizer): g.Rect;
getBBox(opt?: Vectorizer.GetBBoxOptions) : g.Rect;
text(content: string, opt?: Vectorizer.TextOptions): this;
removeAttr(name: string): this;
attr(): { [key: string]: string };
attr(name: string): string | null;
attr(name: string, value: any): this;
attr(attrs: { [key: string]: any }): this;
normalizePath(): this;
remove(): this;
empty(): this;
append(els: Vectorizer | Vectorizer[] | SVGElement | SVGElement[]): this;
prepend(els: Vectorizer | Vectorizer[] | SVGElement | SVGElement[]): this;
before(els: Vectorizer | Vectorizer[] | SVGElement | SVGElement[]): this;
appendTo(el: SVGElement | Vectorizer) : this;
parent(): Vectorizer | null;
// returns either this or Vectorizer, no point in specifying this.
svg(): Vectorizer;
tagName(): string;
defs(): Vectorizer | undefined;
clone(): Vectorizer;
findOne(selector: string): Vectorizer | undefined;
find(selector: string): Vectorizer[];
children(): Vectorizer[];
index(): number;
findParentByClass(className: string, terminator?: SVGElement): Vectorizer | null;
contains(el: SVGElement | Vectorizer): boolean;
toLocalPoint(x: number, y: number): SVGPoint;
translateCenterToPoint(p: g.PlainPoint): this;
translateAndAutoOrient(position: g.PlainPoint, reference: g.PlainPoint, target?: SVGElement | Vectorizer): this;
animateAlongPath(attrs: { [key: string]: any }, path: SVGElement | Vectorizer): void;
hasClass(className: string): boolean;
addClass(className: string): Vectorizer;
removeClass(className: string): this;
toggleClass(className: string, switchArg?: boolean): this;
sample(interval?: number): Vectorizer.Sample[];
convertToPath(): Vectorizer;
convertToPathData(): string;
findIntersection(ref: g.PlainPoint, target: SVGElement | Vectorizer): g.PlainPoint | undefined;
toGeometryShape(): g.Shape;
private setAttributes(attrs: { [key: string]: any }): this;
private setAttribute(name: string, value: string): this;
static createSVGDocument(content: string): Document;
static createSVGStyle(stylesheet: string): SVGStyleElement;
static createCDATASection(data: string): CDATASection;
static uniqueId(): string;
static ensureId(node: SVGElement | Vectorizer): string;
static sanitizeText(text: string): string;
static isUndefined(value: any): boolean;
static isString(value: any): boolean;
static isObject(value: any): boolean;
static isArray(value: any): boolean;
static parseXML(data: string, opt?: Vectorizer.ParseXMLOptions): XMLDocument;
static qualifyAttr(name: string): Vectorizer.QualifiedAttribute;
static transformStringToMatrix(transform: string): SVGMatrix;
static matrixToTransformString(matrix: SVGMatrix | Vectorizer.Matrix): string;
static parseTransformString(transform: string): Vectorizer.Transform;
static deltaTransformPoint(matrix: SVGMatrix | Vectorizer.Matrix, point: SVGPoint | g.PlainPoint): g.PlainPoint;
static decomposeMatrix(matrix: SVGMatrix | Vectorizer.Matrix): Vectorizer.DecomposedTransformation;
static matrixToScale(matrix: SVGMatrix | Vectorizer.Matrix): Vectorizer.Scale;
static matrixToRotate(matrix: SVGMatrix | Vectorizer.Matrix): Vectorizer.Rotation;
static matrixToTranslate(matrix: SVGMatrix | Vectorizer.Matrix): Vectorizer.Translation;
static isV(value: any): boolean;
static isVElement(value: any): boolean;
static isSVGGraphicsElement(value: any): boolean;
static createSVGMatrix(matrix: SVGMatrix | Vectorizer.Matrix): SVGMatrix;
static createSVGTransform(matrix?: SVGMatrix | Vectorizer.Matrix): SVGTransform;
static createSVGPoint(x: number, y: number): SVGPoint;
static transformRect(r: g.PlainRect, matrix: SVGMatrix): g.Rect;
static transformPoint(p: g.PlainPoint, matrix: SVGMatrix): g.Point;
static transformLine(p: g.Line, matrix: SVGMatrix): g.Line;
static transformPolyline(p: g.Polyline | g.PlainPoint[], matrix: SVGMatrix): g.Polyline;
static styleToObject(styleString: string): { [key: string]: string };
static createSlicePathData(innerRadius: number, outRadius: number, startAngle: number, endAngle: number): string;
static mergeAttrs(a: any, b: any): any;
static annotateString(t: string, annotations: Vectorizer.TextAnnotation[], opt?: Vectorizer.AnnotateStringOptions): Array< string | { [key: string]: any }> ;
static findAnnotationsAtIndex(annotations: Vectorizer.TextAnnotation[], index: number): Vectorizer.TextAnnotation[];
static findAnnotationsBetweenIndexes(annotations: Vectorizer.TextAnnotation[], start: number, end: number): Vectorizer.TextAnnotation[];
static shiftAnnotations(annotations: Vectorizer.TextAnnotation[], index: number, offset: number): Vectorizer.TextAnnotation[];
static convertLineToPathData(line: string | SVGElement | Vectorizer): string;
static convertPolygonToPathData(line: string | SVGElement | Vectorizer): string;
static convertPolylineToPathData(line: string | SVGElement | Vectorizer): string;
static svgPointsToPath(points: g.PlainPoint[] | SVGPoint[]): string;
static getPointsFromSvgNode(node: SVGElement | Vectorizer): SVGPoint[];
static convertCircleToPathData(circle: string | SVGElement | Vectorizer): string;
static convertEllipseToPathData(ellipse: string | SVGElement | Vectorizer): string;
static convertRectToPathData(rect: string | SVGElement | Vectorizer): string;
static rectToPath(r: Vectorizer.RoundedRect): string;
static normalizePathData(path: string): string;
static toNode(el: SVGElement | Vectorizer | SVGElement[]): SVGElement;
}
export const version: string;
export namespace config {
var useCSSSelectors: boolean;
var classNamePrefix: string;
var defaultTheme: string;
}
export namespace dia {
type Event = JQuery.TriggeredEvent;
type Point = g.PlainPoint;
type BBox = g.PlainRect;
type Size = Pick<BBox, 'width' | 'height'>;
type PaddingJSON = {
left?: number;
top?: number;
right?: number;
bottom?: number;
};
type Padding = number | PaddingJSON;
type SidesJSON = {
left?: number;
top?: number;
right?: number;
bottom?: number;
horizontal?: number;
vertical?: number;
}
type Sides = number | SidesJSON;
type OrthogonalDirection =
'left' | 'top' | 'right' | 'bottom';
type Direction =
OrthogonalDirection |
'top-left' | 'top-right' | 'bottom-right' | 'bottom-left';
type LinkEnd =
'source' | 'target';
type MarkupNodeJSON = {
tagName: string;
selector?: string;
groupSelector?: string;
namespaceURI?: string;
className?: string;
attributes?: attributes.NativeSVGAttributes;
style?: { [key: string]: any };
children?: MarkupJSON;
textContent?: string;
}
type MarkupJSON = MarkupNodeJSON[];
type Path = string | Array<string | number>;
export namespace Graph {
interface Options {
[key: string]: any;
}
interface ConnectionOptions extends Cell.EmbeddableOptions {
inbound?: boolean;
outbound?: boolean;
}
interface ExploreOptions extends ConnectionOptions {
breadthFirst?: boolean;
}
}
class Graph extends Backbone.Model {
constructor(attributes?: any, opt?: { cellNamespace?: any, cellModel?: typeof Cell });
addCell(cell: Cell | Cell[], opt?: { [key: string]: any }): this;
addCells(cells: Cell[], opt?: { [key: string]: any }): this;
resetCells(cells: Cell[], opt?: { [key: string]: any }): this;
getCell(id: string | number | Cell): Cell;
getElements(): Element[];
getLinks(): Link[];
getCells(): Cell[];
getFirstCell(): Cell | undefined;
getLastCell(): Cell | undefined;
getConnectedLinks(cell: Cell, opt?: Graph.ConnectionOptions): Link[];
disconnectLinks(cell: Cell, opt?: { [key: string]: any }): void;
removeLinks(cell: Cell, opt?: { [key: string]: any }): void;
translate(tx: number, ty?: number, opt?: Element.TranslateOptions): this;
cloneCells(cells: Cell[]): { [id: string]: Cell };
getSubgraph(cells: Cell[], opt?: Cell.EmbeddableOptions): Cell[];
cloneSubgraph(cells: Cell[], opt?: Cell.EmbeddableOptions): { [id: string]: Cell };
dfs(element: Element, iteratee: (element: Element, distance: number) => boolean, opt?: Graph.ConnectionOptions): void;
bfs(element: Element, iteratee: (element: Element, distance: number) => boolean, opt?: Graph.ConnectionOptions): void;
search(element: Element, iteratee: (element: Element, distance: number) => boolean, opt?: Graph.ExploreOptions): void;
getSuccessors(element: Element, opt?: Graph.ExploreOptions): Element[];
getPredecessors(element: Element, opt?: Graph.ExploreOptions): Element[];
isSuccessor(elementA: Element, elementB: Element): boolean;
isPredecessor(elementA: Element, elementB: Element): boolean;
isSource(element: Element): boolean;
isSink(element: Element): boolean;
getSources(): Element[];
getSinks(): Element[];
getNeighbors(element: Element, opt?: Graph.ConnectionOptions): Element[];
isNeighbor(elementA: Element, elementB: Element, opt?: Graph.ConnectionOptions): boolean;
getCommonAncestor(...cells: Cell[]): Element | undefined;
toJSON(): any;
fromJSON(json: any, opt?: { [key: string]: any }): this;
clear(opt?: { [key: string]: any }): this;
findModelsFromPoint(p: Point): Element[];
findModelsInArea(rect: BBox, opt?: { strict?: boolean }): Element[];
findModelsUnderElement(element: Element, opt?: {
searchBy?: 'bottomLeft' | 'bottomMiddle' | 'center' |
'corner' | 'leftMiddle' | 'origin' | 'rightMiddle' |
'topMiddle' | 'topRight' | 'bbox'
}): Element[];
getBBox(): g.Rect | null;
getCellsBBox(cells: Cell[], opt?: Cell.EmbeddableOptions): g.Rect | null;
hasActiveBatch(name?: string | string[]): boolean;
maxZIndex(): number;
minZIndex(): number;
removeCells(cells: Cell[], opt?: Cell.DisconnectableOptions): this;
resize(width: number, height: number, opt?: { [key: string]: any }): this;
resizeCells(width: number, height: number, cells: Cell[], opt?: { [key: string]: any }): this;
startBatch(name: string, data?: { [key: string]: any }): this;
stopBatch(name: string, data?: { [key: string]: any }): this;
toGraphLib(opt?: { [key: string]: any }): any;
fromGraphLib(glGraph: any, opt?: { [key: string]: any }): this;
}
// dia.Cell
export namespace Cell {
interface GenericAttributes<T> {
attrs?: T;
z?: number;
[key: string]: any;
}
interface Selectors {
[selector: string]: attributes.SVGAttributes | undefined;
}
interface Attributes extends GenericAttributes<Selectors> {
[key: string]: any;
}
interface Constructor<T extends Backbone.Model> {
new (opt?: { id?: string, [key: string]: any }): T;
define(type: string, defaults?: any, protoProps?: any, staticProps?: any): dia.Cell.Constructor<T>;
}
interface Options {
[key: string]: any;
}
interface EmbeddableOptions extends Options {
deep?: boolean;
}
interface DisconnectableOptions extends Options {
disconnectLinks?: boolean;
}
interface GetEmbeddedCellsOptions extends EmbeddableOptions {
breadthFirst?: boolean;
}
interface TransitionOptions extends Options {
delay?: number;
duration?: number;
timingFunction?: util.timing.TimingFunction;
valueFunction?: util.interpolate.InterpolateFunction<any>;
}
}
class Cell extends Backbone.Model {
constructor(attributes?: Cell.Attributes, opt?: Graph.Options);
id: string | number;
graph: Graph;
markup: string | MarkupJSON;
protected generateId(): string | number;
toJSON(): any;
remove(opt?: Cell.DisconnectableOptions): this;
toFront(opt?: Cell.GetEmbeddedCellsOptions): this;
toBack(opt?: Cell.GetEmbeddedCellsOptions): this;
parent(): string;
parent(parentId: string): this;
getParentCell(): Cell | null;
getAncestors(): Cell[];
getEmbeddedCells(opt?: Cell.GetEmbeddedCellsOptions): Cell[];
isEmbeddedIn(cell: Cell, opt?: Cell.EmbeddableOptions): boolean;
isEmbedded(): boolean;
prop(key: Path): any;
prop(object: Cell.Attributes, opt?: Cell.Options): this;
prop(key: Path, value: any, opt?: Cell.Options): this;
removeProp(path: Path, opt?: Cell.Options): this;
attr(key?: Path): any;
attr(object: Cell.Selectors, opt?: Cell.Options): this;
attr(key: Path, value: any, opt?: Cell.Options): this;
clone(): Cell;
clone(opt: Cell.EmbeddableOptions): Cell | Cell[];
removeAttr(path: Path, opt?: Cell.Options): this;
transition(path: string, value?: any, opt?: Cell.TransitionOptions, delim?: string): number;
getTransitions(): string[];
stopTransitions(path?: string, delim?: string): this;
embed(cell: Cell, opt?: Graph.Options): this;
unembed(cell: Cell, opt?: Graph.Options): this;
addTo(graph: Graph, opt?: Graph.Options): this;
findView(paper: Paper): CellView;
isLink(): boolean;
isElement(): boolean;
startBatch(name: string, opt?: Graph.Options): this;
stopBatch(name: string, opt?: Graph.Options): this;
angle(): number;
getBBox(): g.Rect;
getPointFromConnectedLink(link: dia.Link, endType: dia.LinkEnd): g.Point;
getChangeFlag(attributes: { [key: string]: number }): number;
static define(type: string, defaults?: any, protoProps?: any, staticProps?: any): Cell.Constructor<Cell>;
/**
* @deprecated
*/
protected processPorts(): void;
}
// dia.Element
export namespace Element {
interface GenericAttributes<T> extends Cell.GenericAttributes<T> {
markup?: string | MarkupJSON;
position?: Point;
size?: Size;
angle?: number;
ports?: {
groups?: { [key: string]: PortGroup},
items?: Port[]
}
}
interface Attributes extends GenericAttributes<Cell.Selectors> {
[key: string]: any
}
type PositionType = string | {
name?: string,
args?: { [key: string]: any }
}
interface PortGroup {
position?: PositionType,
markup?: string | MarkupJSON;
attrs?: Cell.Selectors;
label?: {
markup?: string | MarkupJSON;
position?: PositionType;
}
}
interface Port {
id?: string;
markup?: string | MarkupJSON;
group?: string;
attrs?: Cell.Selectors;
args?: { [key: string]: any };
label?: {
markup?: string | MarkupJSON;
position?: PositionType;
}
z?: number | 'auto';
}
interface PortPosition extends Point {
angle: number;
}
interface TranslateOptions {
restrictedArea?: BBox;
transition?: Cell.TransitionOptions;
}
}
class Element extends Cell {
constructor(attributes?: Element.Attributes, opt?: Graph.Options);
isElement(): boolean;
isLink(): boolean;
translate(tx: number, ty?: number, opt?: Element.TranslateOptions): this;
position(opt?: { parentRelative?: boolean, [key: string]: any }): g.Point;
position(x: number, y: number, opt?: { parentRelative?: boolean, deep?: boolean, [key: string]: any }): this;
size(): Size;
size(width: number, height?: number, opt?: { direction?: Direction, [key: string]: any }): this;
resize(width: number, height: number, opt?: { direction?: Direction, [key: string]: any }): this;
rotate(deg: number, absolute?: boolean, origin?: Point, opt?: { [key: string]: any }): this;
angle(): number;
scale(scaleX: number, scaleY: number, origin?: Point, opt?: { [key: string]: any }): this;
fitEmbeds(opt?: { deep?: boolean, padding?: Padding }): this;
getBBox(opt?: Cell.EmbeddableOptions): g.Rect;
addPort(port: Element.Port, opt?: Cell.Options): this;
addPorts(ports: Element.Port[], opt?: Cell.Options): this;
insertPort(before: number | string | Element.Port, port: Element.Port, opt?: Cell.Options): this;
removePort(port: string | Element.Port, opt?: Cell.Options): this;
removePorts(opt?: Cell.Options): this;
removePorts(ports: Array<Element.Port|string>, opt?: Cell.Options): this;
hasPorts(): boolean;
hasPort(id: string): boolean;
getPorts(): Element.Port[];
getGroupPorts(groupName: string): Element.Port[];
getPort(id: string): Element.Port;
getPortsPositions(groupName: string): { [id: string]: Element.PortPosition };
getPortIndex(port: string | Element.Port): number;
portProp(portId: string, path: dia.Path): any;
portProp(portId: string, path: dia.Path, value?: any, opt?: Cell.Options): Element;
protected generatePortId(): string | number;
static define(type: string, defaults?: any, protoProps?: any, staticProps?: any): Cell.Constructor<Element>;
}
// dia.Link
export namespace Link {
interface EndCellArgs {
magnet?: string;
selector?: string;
port?: string;
anchor?: anchors.AnchorJSON;
connectionPoint?: connectionPoints.ConnectionPointJSON;
priority?: boolean;
}
interface EndJSON extends EndCellArgs {
id?: number | string;
x?: number;
y?: number;
}
interface GenericAttributes<T> extends Cell.GenericAttributes<T> {
source?: EndJSON;
target?: EndJSON;
labels?: Label[];
vertices?: Point[];
manhattan?: boolean;
router?: routers.Router | routers.RouterJSON;
smooth?: boolean;
connector?: connectors.Connector | connectors.ConnectorJSON;
}
interface LinkSelectors extends Cell.Selectors {
'.connection'?: attributes.SVGPathAttributes;
'.connection-wrap'?: attributes.SVGPathAttributes;
'.marker-source'?: attributes.SVGPathAttributes;
'.marker-target'?: attributes.SVGPathAttributes;
'.labels'?: attributes.SVGAttributes;
'.marker-vertices'?: attributes.SVGAttributes;
'.marker-arrowheads'?: attributes.SVGAttributes;
'.link-tools'?: attributes.SVGAttributes;
}
interface Attributes extends Cell.GenericAttributes<LinkSelectors> {
[key: string]: any;
}
interface LabelPosition {
distance?: number; // optional for default labels
offset?: number | { x: number; y: number; };
angle?: number;
args?: LinkView.LabelOptions;
}
interface Label {
markup?: string | MarkupJSON;
position?: LabelPosition | number; // optional for default labels
attrs?: Cell.Selectors;
size?: Size;
}
interface Vertex extends Point {
[key: string]: any;
}
}
class Link extends Cell {
toolMarkup: string;
doubleToolMarkup?: string;
vertexMarkup: string;
arrowHeadMarkup: string;
labelMarkup?: string | MarkupJSON; // default label markup
labelProps?: Link.Label; // default label props
constructor(attributes?: Link.Attributes, opt?: Graph.Options);
isElement(): boolean;
isLink(): boolean;
disconnect(): this;
source(): Link.EndJSON;
source(source: Link.EndJSON, opt?: Cell.Options): this;
source(source: Cell, args?: Link.EndCellArgs, opt?: Cell.Options): this;
target(): Link.EndJSON;
target(target: Link.EndJSON, opt?: Cell.Options): this;
target(target: Cell, args?: Link.EndCellArgs, opt?: Cell.Options): this;
router(): routers.Router | routers.RouterJSON | null;
router(router: routers.Router | routers.RouterJSON, opt?: Cell.Options): this;
router(name: routers.RouterType, args?: routers.RouterArguments, opt?: Cell.Options): this;
connector(): connectors.Connector | connectors.ConnectorJSON | null;
connector(connector: connectors.Connector | connectors.ConnectorJSON, opt?: Cell.Options): this;
connector(name: connectors.ConnectorType, args?: connectors.ConnectorArguments, opt?: Cell.Options): this;
label(index?: number): Link.Label;
label(index: number, label: Link.Label, opt?: Cell.Options): this;
labels(): Link.Label[];
labels(labels: Link.Label[]): this;
insertLabel(index: number, label: Link.Label, opt?: Cell.Options): Link.Label[];
appendLabel(label: Link.Label, opt?: Cell.Options): Link.Label[];
removeLabel(index?: number, opt?: Cell.Options): Link.Label[];
vertex(index?: number): Link.Vertex;
vertex(index: number, vertex: Link.Vertex, opt?: Cell.Options): this;
vertices(): Link.Vertex[];
vertices(vertices: Link.Vertex[]): this;
insertVertex(index: number, vertex: Link.Vertex, opt?: Cell.Options): Link.Vertex[];
removeVertex(index?: number, opt?: Cell.Options): Link.Vertex[];
reparent(opt?: Cell.Options): Element;
getSourceElement(): null | Element;
getTargetElement(): null | Element;
getSourceCell(): null | Cell;
getTargetCell(): null | Cell;
getPolyline(): g.Polyline;
getSourcePoint(): g.Point;
getTargetPoint(): g.Point;
getBBox(): g.Rect;
hasLoop(opt?: Cell.EmbeddableOptions): boolean;
getRelationshipAncestor(): undefined | Element;
isRelationshipEmbeddedIn(cell: Cell): boolean;
applyToPoints(fn: (p: Point) => Point, opt?: Cell.Options): this;
scale(sx: number, sy: number, origin?: Point, opt?: Cell.Options): this;
translate(tx: number, ty: number, opt?: Cell.Options): this;
static define(type: string, defaults?: any, protoProps?: any, staticProps?: any): Cell.Constructor<Link>;
}
// dia.CellView
export namespace CellView {
enum Highlighting {
DEFAULT = 'default',
EMBEDDING = 'embedding',
CONNECTING = 'connecting',
MAGNET_AVAILABILITY = 'magnetAvailability',
ELEMENT_AVAILABILITY = 'elementAvailability'
}
interface Options<T extends Cell> extends mvc.ViewOptions<T> {
id?: string
}
interface InteractivityOptions extends ElementView.InteractivityOptions, LinkView.InteractivityOptions {
}
type FlagLabel = string | string[];
type PresentationAttributes = { [key: string]: FlagLabel };
type NodeData = { [key: string]: any };
type NodeMetrics = {
data: NodeData;
boundingRect: g.Rect;
magnetMatrix: SVGMatrix;
geometryShape: g.Shape;
}
}
abstract class CellViewGeneric<T extends Cell> extends mvc.View<T> {
constructor(opt?: CellView.Options<T>);
paper: Paper | null;
initFlag(): CellView.FlagLabel;
presentationAttributes(): CellView.PresentationAttributes;
highlight(el?: SVGElement | JQuery | string, opt?: { [key: string]: any }): this;
unhighlight(el?: SVGElement | JQuery | string, opt?: { [key: string]: any }): this;
can(feature: string): boolean;
findMagnet(el: SVGElement | JQuery | string): SVGElement | undefined;
findBySelector(selector: string, root?: SVGElement | JQuery | string): JQuery;
findProxyNode(el: SVGElement | null, type: string): SVGElement;
getSelector(el: SVGElement, prevSelector?: string): string;
notify(eventName: string, ...eventArguments: any[]): void;
addTools(tools: dia.ToolsView): this;
hasTools(name?: string): boolean;
removeTools(): this;
showTools(): this;
hideTools(): this;
updateTools(opt?: { [key: string]: any }): this;
getNodeMatrix(node: SVGElement): SVGMatrix;
getNodeBoundingRect(node: SVGElement): g.Rect;
getBBox(opt?: { useModelGeometry?: boolean }): g.Rect;
getNodeBBox(node: SVGElement): g.Rect;
getNodeUnrotatedBBox(node: SVGElement): g.Rect;
isNodeConnection(node: SVGElement): boolean;
getEventTarget(evt: dia.Event, opt?: { fromPoint?: boolean }): Element;
checkMouseleave(evt: dia.Event): void;
getFlag(label: CellView.FlagLabel): number;
requestUpdate(flags: number, opt?: { [key: string]: any }): void;
protected removeHighlighters(): void;
protected updateHighlighters(): void;
protected transformHighlighters(): void;
protected hasFlag(flags: number, label: CellView.FlagLabel): boolean;
protected removeFlag(flags: number, label: CellView.FlagLabel): number;
protected setFlags(): void;
protected onToolEvent(eventName: string): void;
protected pointerdblclick(evt: dia.Event, x: number, y: number): void;
protected pointerclick(evt: dia.Event, x: number, y: number): void;
protected contextmenu(evt: dia.Event, x: number, y: number): void;
protected pointerdown(evt: dia.Event, x: number, y: number): void;
protected pointermove(evt: dia.Event, x: number, y: number): void;
protected pointerup(evt: dia.Event, x: number, y: number): void;
protected mouseover(evt: dia.Event): void;
protected mouseout(evt: dia.Event): void;
protected mouseenter(evt: dia.Event): void;
protected mouseleave(evt: dia.Event): void;
protected mousewheel(evt: dia.Event, x: number, y: number, delta: number): void;
protected onevent(evt: dia.Event, eventName: string, x: number, y: number): void;
protected onmagnet(evt: dia.Event, x: number, y: number): void;
protected getLinkEnd(magnet: SVGElement, x: number, y: number, link: dia.Link, endType: dia.LinkEnd): dia.Link.EndJSON;
protected getMagnetFromLinkEnd(end: dia.Link.EndJSON): SVGElement;
protected customizeLinkEnd(end: dia.Link.EndJSON, magnet: SVGElement, x: number, y: number, link: dia.Link, endType: dia.LinkEnd): dia.Link.EndJSON;