jointjs
Version:
JavaScript diagramming library
1,593 lines (1,048 loc) • 114 kB
TypeScript
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>;
interface ModelSetOptions extends Backbone.ModelSetOptions {
dry?: boolean;
isolate?: boolean;
[key: string]: any;
}
interface CollectionAddOptions extends Backbone.AddOptions {
dry?: boolean;
[key: string]: any;
}
export namespace Graph {
interface Options {
[key: string]: any;
}
interface ConnectionOptions extends Cell.EmbeddableOptions {
inbound?: boolean;
outbound?: boolean;
}
interface ExploreOptions extends ConnectionOptions {
breadthFirst?: boolean;
}
class Cells extends Backbone.Collection<Cell> {
graph: Graph;
cellNamespace: any;
}
interface Attributes {
cells?: Cells,
[key: string]: any;
}
}
class Graph<A = Graph.Attributes, S = dia.ModelSetOptions> extends Backbone.Model<A, S> {
constructor(attributes?: Graph.Attributes, opt?: { cellNamespace?: any, cellModel?: typeof Cell });
addCell(cell: Cell | Cell[], opt?: CollectionAddOptions): this;
addCells(cells: Cell[], opt?: CollectionAddOptions): this;
resetCells(cells: Cell[], opt?: Graph.Options): 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?: S): void;
removeLinks(cell: Cell, opt?: Cell.DisconnectableOptions): 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?: S): 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?: S): this;
resizeCells(width: number, height: number, cells: Cell[], opt?: S): 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> {
}
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<T = boolean> extends Options {
deep?: T;
}
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<A = Cell.Attributes, S = dia.ModelSetOptions> extends Backbone.Model<A, S> {
constructor(attributes?: A, 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: A, 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(): this;
clone(opt: Cell.EmbeddableOptions<false>): this;
clone(opt: Cell.EmbeddableOptions<true>): 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> {
}
type PortPositionCallback = (ports: Port[], bbox: g.Rect) => dia.Point[];
interface PortPositionJSON {
name?: string,
args?: { [key: string]: any }
}
type PositionType = string | PortPositionCallback | PortPositionJSON;
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<A = Element.Attributes, S = dia.ModelSetOptions> extends Cell<A, S> {
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?: S): this;
addPorts(ports: Element.Port[], opt?: S): this;
insertPort(before: number | string | Element.Port, port: Element.Port, opt?: S): this;
removePort(port: string | Element.Port, opt?: S): this;
removePorts(opt?: S): this;
removePorts(ports: Array<Element.Port|string>, opt?: S): 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?: S): 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> {
}
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<A = Link.Attributes, S = dia.ModelSetOptions> extends Cell<A, S> {
toolMarkup: string;
doubleToolMarkup?: string;
vertexMarkup: string;
arrowHeadMarkup: string;
labelMarkup?: string | MarkupJSON; // default label markup
labelProps?: Link.Label; // default label props
isElement(): boolean;
isLink(): boolean;
disconnect(): this;
source(): Link.EndJSON;
source(source: Link.EndJSON, opt?: S): this;
source(source: Cell, args?: Link.EndCellArgs, opt?: S): this;
target(): Link.EndJSON;
target(target: Link.EndJSON, opt?: S): this;
target(target: Cell, args?: Link.EndCellArgs, opt?: S): this;
router(): routers.Router | routers.RouterJSON | null;
router(router: routers.Router | routers.RouterJSON, opt?: S): this;
router(name: routers.RouterType, args?: routers.RouterArguments, opt?: S): this;
connector(): connectors.Connector | connectors.ConnectorJSON | null;
connector(connector: connectors.Connector | connectors.ConnectorJSON, opt?: S): this;
connector(name: connectors.ConnectorType, args?: connectors.ConnectorArguments, opt?: S): this;
label(index?: number): Link.Label;
label(index: number, label: Link.Label, opt?: S): this;
labels(): Link.Label[];
labels(labels: Link.Label[]): this;
insertLabel(index: number, label: Link.Label, opt?: S): Link.Label[];
appendLabel(label: Link.Label, opt?: S): Link.Label[];
removeLabel(index?: number, opt?: S): Link.Label[];
vertex(index?: number): Link.Vertex;
vertex(index: number, vertex: Link.Vertex, opt?: S): this;
vertices(): Link.Vertex[];
vertices(vertices: Link.Vertex[]): this;
insertVertex(index: number, vertex: Link.Vertex, opt?: S): Link.Vertex[];
removeVertex(index?: number, opt?: S): Link.Vertex[];
reparent(opt?: S): 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?: S): this;
scale(sx: number, sy: number, origin?: Point, opt?: S): this;
translate(tx: number, ty: number, opt?: S): 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, SVGElement> {
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, SVGElement> {
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): SVGElement[];
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;
dragLinkStart(evt: dia.Event, magnet: SVGElement, x: number, y: number): void;
dragLink(evt: dia.Event, x: number, y: number): void;
dragLinkEnd(evt: dia.Event, x: number, y: number): 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;
protected addLinkFromMagnet(magnet: SVGElement, x: number, y: number): LinkView;
protected cleanNodesCache(): void;
protected nodeCache(magnet: SVGElement): CellView.NodeMetrics;
protected getNodeData(magnet: SVGElement): CellView.NodeData;
protected getNodeShape(magnet: SVGElement): g.Shape;
static addPresentationAttributes(attributes: CellView.PresentationAttributes): CellView.PresentationAttributes;
}
class CellView extends CellViewGeneric<Cell> {
}
// dia.ElementView
export namespace ElementView {
enum Flags {
UPDATE = 'UPDATE',
TRANSLATE = 'TRANSLATE',
TOOLS = 'TOOLS',
RESIZE = 'RESIZE',
PORTS = 'PORTS',
ROTATE = 'ROTATE',
RENDER = 'RENDER'
}
interface InteractivityOptions {
elementMove?: boolean;
addLinkFromMagnet?: boolean;
stopDelegation?: boolean;
}
}
class ElementView extends CellViewGeneric<Element> {
update(element?: Element, renderingOnlyAttrs?: { [key: string]: any }): void;
setInteractivity(value: boolean | ElementView.InteractivityOptions): void;
getDelegatedView(): ElementView | null;
findPortNode(portId: string | number, selector?: string): SVGElement | null;
protected renderMarkup(): void;
protected renderJSONMarkup(markup: MarkupJSON): void;
protected renderStringMarkup(markup: string): void;
protected updateTransformation(): void;
protected resize(): void;
protected translate(): void;
protected rotate(): void;
protected getTranslateString(): string;
protected getRotateString(): string;
protected dragStart(evt: dia.Event, x: number, y: number): void;
protected dragMagnetStart(evt: dia.Event, x: number, y: number): void;
protected drag(evt: dia.Event, x: number, y: number): void;
protected dragMagnet(evt: dia.Event, x: number, y: number): void;
protected dragEnd(evt: dia.Event, x: number, y: number): void;
protected dragMagnetEnd(evt: dia.Event, x: number, y: number): void;
}
// dia.LinkView
export namespace LinkView {
enum Flags {
RENDER = 'RENDER',
UPDATE = 'UPDATE',
TOOLS = 'TOOLS',
LEGACY_TOOLS = 'LEGACY_TOOLS',
LABELS = 'LABELS',
VERTICES = 'VERTICES',
SOURCE = 'SOURCE',
TARGET = 'TARGET',
CONNECTOR = 'CONNECTOR'
}
interface InteractivityOptions {
vertexAdd?: boolean,
vertexMove?: boolean,
vertexRemove?: boolean;
arrowheadMove?: boolean;
labelMove?: boolean;
linkMove?: boolean;
useLinkTools?: boolean;
}
interface GetConnectionPoint {
(
linkView: LinkView,
view: ElementView,
magnet: SVGElement,
reference: Point,
end: LinkEnd
): Point;
}
interface LabelOptions extends Cell.Options {
absoluteDistance?: boolean;
reverseDistance?: boolean;
absoluteOffset?: boolean;
keepGradient?: boolean;
ensureLegibility?: boolean;
}
interface VertexOptions extends Cell.Options {
}
interface Options extends mvc.ViewOptions<Link, SVGElement> {
shortLinkLength?: number,
doubleLinkTools?: boolean,
longLinkLength?: number,
linkToolsOffset?: number,
doubleLinkToolsOffset?: number,
sampleInterval?: number
}
}
class LinkView extends CellViewGeneric<Link> {
options: LinkView.Options;
sourceAnchor: g.Point;
targetAnchor: g.Point;
sendToken(token: SVGElement, duration?: number, callback?: () => void): void;
sendToken(token: SVGElement, opt?: { duration?: number, direction?: string; connection?: string }, callback?: () => void): void;
addLabel(coordinates: Point, opt?: LinkView.LabelOptions): number;
addLabel(coordinates: Point, angle: number, opt?: LinkView.LabelOptions): number;
addLabel(x: number, y: number, opt?: LinkView.LabelOptions): number;
addLabel(x: number, y: number, angle: number, opt?: LinkView.LabelOptions): number;
addVertex(coordinates: Point, opt?: LinkView.VertexOptions): number;
addVertex(x: number, y: number, opt?: LinkView.VertexOptions): number;
getConnection(): g.Path;
getSerializedConnection(): string;
getConnectionSubdivisions(): g.Curve[][];
getConnectionLength(): number;
getPointAtLength(length: number): g.Point;
getPointAtRatio(ratio: number): g.Point;
getTangentAtLength(length: number): g.Line;
getTangentAtRatio(ratio: number): g.Line;
getClosestPoint(point: Point): g.Point;
getClosestPointLength(point: Point): number;
getClosestPointRatio(point: Point): number;
getLabelPosition(x: number, y: number, opt?: LinkView.LabelOptions): Link.LabelPosition;
getLabelPosition(x: number, y: number, angle: number, opt?: LinkView.LabelOptions): Link.LabelPosition;
getLabelCoordinates(labelPosition: Link.LabelPosition): g.Point;
getVertexIndex(x: number, y: number): number;
getVertexIndex(point: Point): number;
update(): this;
translate(tx: number, ty: number): void;
requestConnectionUpdate(opt?: { [key: string]: any }): void;
setInteractivity(value: boolean | LinkView.InteractivityOptions): void;
getEndView(endType: dia.LinkEnd): dia.CellView | null;
getEndAnchor(endType: dia.LinkEnd): g.Point;
getEndConnectionPoint(endType: dia.LinkEnd): g.Point;
getEndMagnet(endType: dia.LinkEnd): SVGElement | null;
findLabelNode(labelIndex: string | number, selector?: string): SVGElement | null;
protected updateRoute(): void;
protected updatePath(): void;
protected updateDOM(): void;
protected onLabelsChange(link: Link, labels: Link.Label[], opt: { [key: string]: any }): void;
protected onToolsChange(link: Link, toolsMarkup: string, opt: { [key: string]: any }): void;
protected onVerticesChange(link: Link, vertices: Point[], opt: { [key: string]: any }): void;
protected onSourceChange(element: Element, sourceEnd: any, opt: { [key: string]: any }): void;
protected onTargetChange(element: Element, targetEnd: any, opt: { [key: string]: any }): void;
protected onlabel(evt: dia.Event, x: number, y: number): void;
protected dragConnectionStart(evt: dia.Event, x: number, y: number): void;
protected dragLabelStart(evt: dia.Event, x: number, y: number): void;
protected dragVertexStart(evt: dia.Event, x: number, y: number): void;
protected dragArrowheadStart(evt: dia.Event, x: number, y: number): void;
protected dragStart(evt: dia.Event, x: number, y: number): void;
protected dragConnection(evt: dia.Event, x: number, y: number): void;
protected dragLabel(evt: dia.Event, x: number, y: number): void;
protected dragVertex(evt: dia.Event, x: number, y: number): void;
protected dragArrowhead(evt: dia.Event, x: number, y: number): void;
protected drag(evt: dia.Event, x: number, y: number): void;
protected dragConnectionEnd(evt: dia.Event, x: number, y: number): void;
protected dragLabelEnd(evt: dia.Event, x: number, y: number): void;
protected dragVertexEnd(evt: dia.Event, x: number, y: number): void;
protected dragArrowheadEnd(evt: dia.Event, x: number, y: number): void;
protected dragEnd(evt: dia.Event, x: number, y: number): void;
protected notifyPointerdown(evt: dia.Event, x: number, y: number): void;
protected notifyPointermove(evt: dia.Event, x: number, y: number): void;
protected notifyPointerup(evt: dia.Event, x: number, y: number): void;
}
// dia.Paper
export namespace Paper {
interface GradientOptions {
id?: string;
type: 'linearGradient' | 'radialGradient';
stops: Array<{
offset: string;
color: string;
opacity?: number;
}>;
}
interface GridOptions {
color?: string;
thickness?: number;
name?: 'dot' | 'fixedDot' | 'mesh' | 'doubleMesh';
args?: Array<{ [key: string]: any }> | { [key: string]: any };
}
interface BackgroundOptions {
color?: string;
image?: string;
quality?: number;
position?: Point | string;
size?: Size | string;
repeat?: string;
opacity?: number;
waterMarkAngle?: number;
}
type Dimension = number | string | null;
enum sorting {
EXACT = 'sorting-exact',
APPROX = 'sorting-approximate',
NONE = 'sorting-none'
}
enum Layers {
CELLS = 'cells',
BACK = 'back',
FRONT = 'front',
TOOLS = 'tools'
}
type UpdateStats = {
priority: number;
updated: number;
empty?: boolean;
postponed?: number;
unmounted?: number;
mounted?: number;
batches?: number;
};
type ViewportCallback = (view: mvc.View<any>, isMounted: boolean, paper: Paper) => boolean;
type ProgressCallback = (done: boolean, processed: number, total: number, stats: UpdateStats, paper: Paper) => void;
type BeforeRenderCallback = (opt: { [key: string]: any }, paper: Paper) => void;
type AfterRenderCallback = (stats: UpdateStats, opt: { [key: string]: any }, paper: Paper) => void;
interface FreezeOptions {
key?: string;
}
interface UnfreezeOptions {
key?: string;
mountBatchSize?: number;
unmountBatchSize?: number;
batchSize?: number;
viewport?: ViewportCallback;
progress?: ProgressCallback;
beforeRender?: BeforeRenderCallback;
afterRender?: AfterRenderCallback;
}
type PointConstraintCallback = (x: number, y: number, opt: any) => Point;
type RestrictTranslateCallback = (elementView: ElementView, x0: number, y0: number) => BBox | boolean | PointConstraintCallback;
interface Options extends mvc.ViewOptions<Graph> {
// appearance
width?: Dimension;
height?: Dimension;
origin?: Point;
perpendicularLinks?: boolean;
linkConnectionPoint?: LinkView.GetConnectionPoint;
drawGrid?: boolean | GridOptions | GridOptions[];
background?: BackgroundOptions;
// interactions
gridSize?: number;
highlighting?: boolean | Record<string | dia.CellView.Highlighting, highlighters.HighlighterJSON | boolean>
interactive?: ((cellView: CellView, event: string) => boolean | CellView.InteractivityOptions) | boolean | CellView.InteractivityOptions
snapLabels?: boolean;
snapLinks?: boolean | { radius: number };
markAvailable?: boolean;
// validations
validateMagnet?: (cellView: CellView, magnet: SVGElement, evt: dia.Event) => boolean;
validateConnection?: (cellViewS: CellView, magnetS: SVGElement, cellViewT: CellView, magnetT: SVGElement, end: LinkEnd, linkView: LinkView) => boolean;
restrictTranslate?: RestrictTranslateCallback | boolean | BBox;
multiLinks?: boolean;
linkPinning?: boolean;
allowLink?: ((linkView: LinkView, paper: Paper) => boolean) | null;
// events
guard?: (evt: dia.Event, view: CellView) => boolean;
preventContextMenu?: boolean;
preventDefaultBlankAction?: boolean;
clickThreshold?: number;
moveThreshold?: number;
magnetThreshold?: number | string;
// views
elementView?: typeof ElementView | ((element: Element) => typeof ElementView);
linkView?: typeof LinkView | ((link: Link) => typeof LinkView);
// embedding
embeddingMode?: boolean;
frontParentOnly?: boolean;
findParentBy?: 'bbox' | 'center' | 'origin' | 'corner' | 'topRight' | 'bottomLeft' | ((elementView: ElementView) => Element[]);
validateEmbedding?: (this: Paper, childView: ElementView, parentView: ElementView) => boolean;
validateUnembedding?: (this: Paper, childView: ElementView) => boolean;
// default views, models & attributes
cellViewNamespace?: any;
routerNamespace?: any;
connectorNamespace?: any;
highlighterNamespace?: any;
anchorNamespace?: any;
linkAnchorNamespace?: any,
connectionPointNamespace?: any;
defaultLink?: ((cellView: CellView, magnet: SVGElement) => Link) | Link;
defaultRouter?: routers.Router | routers.RouterJSON;
defaultConnector?: connectors.Connector | connectors.ConnectorJSON;
defaultAnchor?: anchors.AnchorJSON | anchors.Anchor;
defaultLinkAnchor?: anchors.AnchorJSON | anchors.Anchor;
defaultConnectionPoint?: connectionPoints.ConnectionPointJSON | connectionPoints.ConnectionPoint | ((...args: any[]) => connectionPoints.ConnectionPoint);
// connecting
connectionStrategy?: connectionStrategies.ConnectionStrategy;
// rendering
async?: boolean;
sorting?: sorting;
frozen?: boolean;
viewport?: ViewportCallback | null;
onViewUpdate?: (view: mvc.View<any>, flag: number, priority: number, opt: { [key: string]: any }, paper: Paper) => void;
onViewPostponed?: (view: mvc.View<any>, flag: number, paper: Paper) => boolean;
beforeRender?: Paper.BeforeRenderCallback
afterRender?: Paper.AfterRenderCallback
}
interface ScaleContentOptions {
padding?: Padding;
preserveAspectRatio?: boolean;
minScale?: number;
minScaleX?: number;
minScaleY?: number;
maxScale?: number;
maxScaleX?: number;
maxScaleY?: number;
scaleGrid?: number;
useModelGeometry?: boolean;
fittingBBox?: BBox;
contentArea?: BBox;
}
interface FitToContentOptions {
gridWidth?: number;
gridHeight?: number;
padding?: Padding;
allowNewOrigin?: 'negative' | 'positive' | 'any';
allowNegativeBottomRight?: boolean;
minWidth?: number;
minHeight?: number;
maxWidth?: number;
maxHeight?: number;
useModelGeometry?: boolean;
contentArea?: BBox;
}
}
class Paper extends mvc.View<Graph> {
constructor(opt: Paper.Options);
options: Paper.Options;
svg: SVGElement;
defs: SVGDefsElement;
cells: SVGGElement;
tools: SVGGElement;
layers: SVGGElement;
viewport: SVGGElement;
$document: JQuery;
$grid: JQuery;
$background: JQuery;
matrix(): SVGMatrix;
matrix(ctm: SVGMatrix | Vectorizer.Matrix): this;
clientMatrix(): SVGMatrix;
clientOffset(): g.Point;
pageOffset(): g.Point;
clientToLocalPoint(x: number, y: number): g.Point;
clientToLocalPoint(point: Point): g.Point;
clientToLocalRect(x: number, y: number, width: number, height: number): g.Rect;
clientToLocalRect(rect: BBox): g.Rect;
localToClientPoint(x: number, y: number): g.Point;
localToClientPoint(point: Point): g.Point;
localToClientRect(x: number, y: number, width: number, height: number): g.Rect;
localToClientRect(rect: BBox): g.Rect;
localToPagePoint(x: number, y: number): g.Point;
localToPagePoint(point: Point): g.Point;
localToPageRect(x: number, y: number, width: number, height: number): g.Rect;
localToPageRect(rect: BBox): g.Rect;
localToPaperPoint(x: number, y: number): g.Point;
localToPaperPoint(point: Point): g.Point;
localToPaperRect(x: number, y: number, width: number, height: number): g.Rect;
localToPaperRect(rect: BBox): g.Rect;
pageToLocalPoint(x: number, y: number): g.Point;
pageToLocalPoint(point: Point): g.Point;
pageToLocalRect(x: number, y: number, width: number, height: number): g.Rect;
pageToLocalRect(rect: BBox): g.Rect;
paperToLocalPoint(x: number, y: number): g.Point;
paperToLocalPoint(point: Point): g.Point;
paperToLocalRect(x: number, y: number, width: number, height: number): g.Rect;
paperToLocalRect(x: BBox): g.Rect;
snapToGrid(x: number, y: number): g.Point;
snapToGrid(point: Point): g.Point;
defineFilter(filter: { [key: string]: any }): string;
defineGradient(gradient: Paper.GradientOptions): string;
defineMarker(marker: { [key: string]: any }): string;
isDefined(defId: string): boolean;
getComputedSize(): Size;
getArea(): g.Rect;
getRestrictedArea(): g.Rect | null;
getRestrictedArea(elementView: ElementView, x: number, y: number): g.Rect | null | Paper.PointConstraintCallback;
getContentArea(opt?: { useModelGeometry: boolean }): g.Rect;
getContentBBox(opt?: { useModelGeometry: boolean }): g.Rect;
findView<T extends ElementView | LinkView>(element: string | JQuery | SVGElement): T;
findViewByModel<T extends ElementView | LinkView>(model: Cell | string | number): T;
findViewsFromPoint(point: string | Point): ElementView[];
findViewsInArea(rect: BBox, opt?: { strict?: boolean }): ElementView[];
fitToContent(opt?: Paper.FitToContentOptions): g.Rect;
fitToContent(gridWidth?: number, gridHeight?: number, padding?: number, opt?: any): g.Rect;
scaleContentToFit(opt?: Paper.ScaleContentOptions): void;
drawBackground(opt?: Paper.BackgroundOptions): this;
drawGrid(opt?: Paper.GridOptions | Paper.GridOptions[]): this;
clearGrid(): this;
getDefaultLink(cellView: CellView, magnet: SVGElement): Link;
getModelById(id: string | number | Cell): Cell;
setDimensions(width: Paper.Dimension, height: Paper.Dimension): void;
setGridSize(gridSize: number): this;
setInteractivity(value: any): void;
setOrigin(x: number, y: number): this;
scale(): Vectorizer.Scale;
scale(sx: number, sy?: number, ox?: number, oy?: number): this;
translate(): Vectorizer.Translation;
translate(tx: number, ty?: number): this;
update(): this;
getPointerArgs(evt: dia.Event): [dia.Event, number, number];
// tools
removeTools(): this;
hideTools(): this;
showTools(): this;
dispatchToolsEvent(eventName: string, ...args: any[]): void;
// layers
getLayerNode(layerName: Paper.Layers | string): SVGGElement;
// rendering
freeze(opt?: Paper.FreezeOptions): void;
unfreeze(opt?: Paper.UnfreezeOptions): void;
isFrozen(): boolean;
requestViewUpdate(view: mvc.View<any>, flag: number, priority: number, opt?: { [key: string]: any }): void;
requireView<T extends ElementView | LinkView>(model: Cell | string | number, opt?: dia.Cell.Options): T;
dumpViews(opt?: {
batchSize?: number;
mountBatchSize?: number;
unmountBatchSize?: number;
viewport?: Paper.ViewportCallback;
progress?: Paper.ProgressCallback;
}): void;
checkViewport(opt?: {
mountBatchSize?: number;
unmountBatchSize?: number;
viewport?: Paper.ViewportCallback;
}): {
mounted: number;
unmounted: number;
};
updateViews(opt?: {
batchSize?: number;
viewport?: Paper.ViewportCallback;
progress?: Paper.ProgressCallback;
}): {
updated: number;
batches: number;
};
hasScheduledUpdates(): boolean;
// protected
protected scheduleViewUpdate(view: mvc.View<any>, flag: number, priority: number, opt?: { [key: string]: any }): void;
protected dumpViewUpdate(view: mvc.View<any>): number;
protected dumpView(view: mvc.View<any>, opt?: { [key: string]: any }): number;
protected updateView(view: mvc.View<any>, flag: number, opt?: { [key: string]: any }): number;
protected registerUnmountedView(view: mvc.View<any>): number;
protected registerMountedView(view: mvc.View<any>): number;
protected updateViewsAsync(opt?: {
batchSize?: number;
mountBatchSize?: number;
unmountBatchSize?: number;
viewport?: Paper.ViewportCallback;
progress?: Paper.ProgressCallback;
before?: Paper.BeforeRenderCallback
}): void;
protected updateViewsBatch(opt?: {
batchSize?: number;
viewport?: Paper.ViewportCallback;
}): Paper.UpdateStats;
protected checkMountedViews(viewport: Paper.ViewportCallback, opt?: { unmountBatchSize?: number }): number;
protected checkUnmountedViews(viewport: Paper.ViewportCallback, opt?: { mountBatchSize?: number }): number;
protected isAsync(): boolean;
protected isExactSorting(): boolean;
protected sortViews(): void;
protected sortViewsExact(): void;
protected insertView(view: dia.CellView): void;
protected addZPivot(z: number): Comment;
protected removeZPivots(): void
protected pointerdblclick(evt: dia.Event): void;
protected pointerclick(evt: dia.Event): void;
protected contextmenu(evt: dia.Event): void;
protected pointerdown(evt: dia.Event): void;
protected pointermove(evt: dia.Event): void;
protected pointerup(evt: dia.Event): 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): void;
protected onevent(evt: dia.Event): void;
protected onmagnet(evt: dia.Event): void;
protected onlabel(evt: dia.Event): void;
protected guard(evt: dia.Event, view: CellView): boolean;
protected drawBackgroundImage(img: HTMLImageElement, opt: { [key: string]: any }): void;
protected updateBackgroundColor(color: string): void;
protected updateBackgroundImage(opt: { position?: any, size?: any }): void;
protected createViewForModel(cell: Cell): CellView;
protected cloneOptions(): Paper.Options;
protected onCellAdded(cell: Cell, collection: Backbone.Collection<Cell>, opt: dia.Graph.Options): void;
protected onCellRemoved(cell: Cell, collection: Backbone.Collection<Cell>, opt: dia.Graph.Options): void;
protected onCellChanged(cell: Cell, opt: dia.Cell.Options): void;
protected onCellChanged(cell: Backbone.Collection<Cell>, opt: dia.Graph.Options): void;
protected onGraphReset(cells: Backbone.Collection<Cell>, opt: dia.Graph.Options): void;
protected onGraphSort(): void;
protected onGraphBatchStop(): void;
protected onCellHighlight(cellView: CellView, magnetEl: SVGElement, opt?: { highlighter?: highlighters.HighlighterJSON }): void;
protected onCellUnhighlight(cellView: CellView, magnetEl: SVGElement, opt?: { highlighter?: highlighters.HighlighterJSON }): void;
protected onRemove(): void;
protected removeView(cell: Cell): CellView;
protected removeViews(): void;
protected renderView(cell: Cell): CellView;
protected resetViews(cells?: Cell[], opt?: { [key: string]: any }): void;
}
namespace ToolsView {
interface Options extends mvc.ViewOptions<undefined, SVGElement> {
tools?: dia.ToolView[];
name?: string | null;
relatedView?: dia.CellView;
component?: boolean;
}
}
class ToolsView extends mvc.View<undefined, SVGElement> {
constructor(opt?: ToolsView.Options);
isRendered: boolean;
options: ToolsView.Options;
configure(opt?: ToolsView.Options): this;
getName(): string | null;
focusTool(tool: ToolView): this;
blurTool(tool?: ToolView): this;
show(): this;
hide(): this;
mount(): this;
protected simulateRelatedView(el: SVGElement): void;
}
namespace ToolView {
interface Options extends mvc.ViewOptions<undefined, SVGElement> {
focusOpacity?: number;
}
}
class ToolView extends mvc.View<undefined, SVGElement> {
name: string | null;
parentView: ToolsView;
relatedView: dia.CellView;
paper: Paper;
constructor(opt?: ToolView.Options);
configure(opt?: ToolView.Options): this;
show(): void;
hide(): void;
isVisible(): boolean;
focus(): void;
blur(): void;
update(): void;
protected guard(evt: dia.Event): boolean;
}
namespace HighlighterView {
type Constructor<T> = { new (): T }
type NodeSelectorJSON = {
selector?: string;
port?: string;
label?: number;
};
type NodeSelector = string | SVGElement | NodeSelectorJSON;
interface Options extends mvc.ViewOptions<undefined, SVGElement> {
layer?: dia.Paper.Layers | string | null;
}
}
class HighlighterView<Options = HighlighterView.Options> extends mvc.View<undefined, SVGElement> {
constructor(options?: Options);
options: Options;
UPDATABLE: boolean;
MOUNTABLE: boolean;
cellView: dia.CellView;
nodeSelector: HighlighterView.NodeSelector | null;
node: SVGElement | null;
updateRequested: boolean;
transformGroup: Vectorizer | null;
public unmount(): void;
protected findNode(cellView: dia.CellView, nodeSelector: HighlighterView.NodeSelector): SVGElement | null;
protected transform(): void;
protected update(): void;
protected highlight(cellView: dia.CellView, node: SVGElement): void;
protected unhighlight(cellView: dia.CellView, node: SVGElement): void;
static uniqueId(node: SVGElement, options?: any): string;
static add<T extends HighlighterView>(
this: HighlighterView.Const