jointjs
Version:
JavaScript diagramming library
1,586 lines (1,077 loc) • 103 kB
TypeScript
export namespace config {
var useCSSSelectors: boolean;
var classNamePrefix: string;
var defaultTheme: string;
}
export namespace dia {
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[];
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 }): T
}
interface Options {
[key: string]: any;
}
interface EmbeddableOptions extends Options {
deep?: boolean;
}
interface DisconnectableOptions {
disconnectLinks?: 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;
protected generateId(): string | number;
toJSON(): any;
remove(opt?: Cell.DisconnectableOptions): this;
toFront(opt?: Cell.EmbeddableOptions): this;
toBack(opt?: Cell.EmbeddableOptions): this;
parent(): string;
parent(parentId: string): this;
getParentCell(): Cell | null;
getAncestors(): Cell[];
getEmbeddedCells(opt?: { deep?: boolean, breadthFirst?: boolean }): Cell[];
isEmbeddedIn(cell: Cell, opt?: Cell.EmbeddableOptions): boolean;
isEmbedded(): boolean;
prop(key: string | string[]): any;
prop(object: Cell.Attributes, opt?: Cell.Options): this;
prop(key: string | string[], value: any, opt?: Cell.Options): this;
removeProp(path: string | string[], opt?: Cell.Options): this;
attr(key?: string): any;
attr(object: Cell.Selectors, opt?: Cell.Options): this;
attr(key: string, value: any, opt?: Cell.Options): this;
clone(): Cell;
clone(opt: Cell.EmbeddableOptions): Cell | Cell[];
removeAttr(path: string | string[], 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;
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[];
getPort(id: string): Element.Port;
getPortsPositions(groupName: string): { [id: string]: Element.PortPosition };
getPortIndex(port: string | Element.Port): number;
portProp(portId: string, path: any, 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 {
markup: string;
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 {
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 };
}
abstract class CellViewGeneric<T extends Cell> extends mvc.View<T> {
constructor(opt?: CellView.Options<T>);
paper: Paper | null;
initFlag: number;
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;
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: JQuery.Event, opt?: { fromPoint?: boolean }): Element;
checkMouseleave(evt: JQuery.Event): void;
getFlag(label: CellView.FlagLabel): number;
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: JQuery.Event, x: number, y: number): void;
protected pointerclick(evt: JQuery.Event, x: number, y: number): void;
protected contextmenu(evt: JQuery.Event, x: number, y: number): void;
protected pointerdown(evt: JQuery.Event, x: number, y: number): void;
protected pointermove(evt: JQuery.Event, x: number, y: number): void;
protected pointerup(evt: JQuery.Event, x: number, y: number): void;
protected mouseover(evt: JQuery.Event): void;
protected mouseout(evt: JQuery.Event): void;
protected mouseenter(evt: JQuery.Event): void;
protected mouseleave(evt: JQuery.Event): void;
protected mousewheel(evt: JQuery.Event, x: number, y: number, delta: number): void;
protected onevent(evt: JQuery.Event, eventName: string, x: number, y: number): void;
protected onmagnet(evt: JQuery.Event, x: number, y: number): void;
static addPresentationAttributes(attributes: CellView.PresentationAttributes): CellView.PresentationAttributes
}
class CellView extends CellViewGeneric<Cell> {
}
// dia.ElementView
export namespace ElementView {
interface InteractivityOptions {
elementMove?: boolean;
addLinkFromMagnet?: 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;
protected renderMarkup(): void;
protected renderJSONMarkup(markup: MarkupJSON): void;
protected renderStringMarkup(markup: string): void;
protected dragStart(evt: JQuery.Event, x: number, y: number): void;
protected dragMagnetStart(evt: JQuery.Event, x: number, y: number): void;
protected drag(evt: JQuery.Event, x: number, y: number): void;
protected dragMagnet(evt: JQuery.Event, x: number, y: number): void;
protected dragEnd(evt: JQuery.Event, x: number, y: number): void;
protected dragMagnetEnd(evt: JQuery.Event, x: number, y: number): void;
protected dragLinkStart(evt: JQuery.Event, magnet: SVGElement, x: number, y: number): void;
protected addLinkFromMagnet(magnet: SVGElement, x: number, y: number): LinkView;
}
// dia.LinkView
export namespace LinkView {
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> {
shortLinkLength?: number,
doubleLinkTools?: boolean,
longLinkLength?: number,
linkToolsOffset?: number,
doubleLinkToolsOffset?: number,
sampleInterval?: number
}
}
class LinkView extends CellViewGeneric<Link> {
options: LinkView.Options;
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(link: Link, attributes: any, opt?: { [key: string]: any }): this;
setInteractivity(value: boolean | LinkView.InteractivityOptions): 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: JQuery.Event, x: number, y: number): void;
protected dragConnectionStart(evt: JQuery.Event, x: number, y: number): void;
protected dragLabelStart(evt: JQuery.Event, x: number, y: number): void;
protected dragVertexStart(evt: JQuery.Event, x: number, y: number): void;
protected dragArrowheadStart(evt: JQuery.Event, x: number, y: number): void;
protected dragStart(evt: JQuery.Event, x: number, y: number): void;
protected dragConnection(evt: JQuery.Event, x: number, y: number): void;
protected dragLabel(evt: JQuery.Event, x: number, y: number): void;
protected dragVertex(evt: JQuery.Event, x: number, y: number): void;
protected dragArrowhead(evt: JQuery.Event, x: number, y: number): void;
protected drag(evt: JQuery.Event, x: number, y: number): void;
protected dragConnectionEnd(evt: JQuery.Event, x: number, y: number): void;
protected dragLabelEnd(evt: JQuery.Event, x: number, y: number): void;
protected dragVertexEnd(evt: JQuery.Event, x: number, y: number): void;
protected dragArrowheadEnd(evt: JQuery.Event, x: number, y: number): void;
protected dragEnd(evt: JQuery.Event, x: number, y: number): void;
protected notifyPointerdown(evt: JQuery.Event, x: number, y: number): void;
protected notifyPointermove(evt: JQuery.Event, x: number, y: number): void;
protected notifyPointerup(evt: JQuery.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'
}
type UpdateStats = {
priority: number;
updated: number;
postponed: number;
unmounted: number;
mounted: number;
empty: boolean;
};
type ViewportCallback = (view: mvc.View<any>, isDetached: boolean, paper: Paper) => boolean;
type ProgressCallback = (done: boolean, processed: number, total: number, stats: UpdateStats, paper: Paper) => void;
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?: { [type: string]: highlighters.HighlighterJSON };
interactive?: ((cellView: CellView, event: string) => boolean) | boolean | CellView.InteractivityOptions
snapLinks?: boolean | { radius: number };
markAvailable?: boolean;
// validations
validateMagnet?: (cellView: CellView, magnet: SVGElement) => boolean;
validateConnection?: (cellViewS: CellView, magnetS: SVGElement, cellViewT: CellView, magnetT: SVGElement, end: LinkEnd, linkView: LinkView) => boolean;
restrictTranslate?: ((elementView: ElementView) => BBox) | boolean;
multiLinks?: boolean;
linkPinning?: boolean;
allowLink?: ((linkView: LinkView, paper: Paper) => boolean) | null;
// events
guard?: (evt: JQuery.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;
findParentBy?: 'bbox' | 'center' | 'origin' | 'corner' | 'topRight' | 'bottomLeft';
validateEmbedding?: (childView: ElementView, parentView: ElementView) => boolean;
// default views, models & attributes
cellViewNamespace?: 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, opt: { [key: string]: any }, paper: Paper) => void;
onViewPostponed?: (view: mvc.View<any>, flag: number, paper: Paper) => boolean;
}
interface ScaleContentOptions {
padding?: number;
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';
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 | undefined;
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;
cancelRenderViews(): 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: JQuery.Event): [JQuery.Event, number, number];
// tools
removeTools(): this;
hideTools(): this;
showTools(): this;
dispatchToolsEvent(eventName: string, ...args: any[]): void;
// rendering
freeze(opt?: {
key?: string
}): void;
unfreeze(opt?: {
key?: string;
mountBatchSize?: number;
unmountBatchSize?: number;
batchSize?: number;
viewport?: Paper.ViewportCallback;
progress?: Paper.ProgressCallback;
}): 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;
};
// 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;
}): 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: JQuery.Event): void;
protected pointerclick(evt: JQuery.Event): void;
protected contextmenu(evt: JQuery.Event): void;
protected pointerdown(evt: JQuery.Event): void;
protected pointermove(evt: JQuery.Event): void;
protected pointerup(evt: JQuery.Event): void;
protected mouseover(evt: JQuery.Event): void;
protected mouseout(evt: JQuery.Event): void;
protected mouseenter(evt: JQuery.Event): void;
protected mouseleave(evt: JQuery.Event): void;
protected mousewheel(evt: JQuery.Event): void;
protected onevent(evt: JQuery.Event): void;
protected onmagnet(evt: JQuery.Event): void;
protected onlabel(evt: JQuery.Event): void;
protected guard(evt: JQuery.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> {
tools?: dia.ToolView[];
name?: string | null;
relatedView?: dia.CellView;
component?: boolean;
}
}
class ToolsView extends mvc.View<undefined> {
constructor(opt?: ToolsView.Options);
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 {
focusOpacity?: number;
}
}
class ToolView extends mvc.View<undefined> {
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;
}
}
export namespace shapes {
namespace standard {
interface RectangleSelectors {
root?: attributes.SVGAttributes;
body?: attributes.SVGRectAttributes;
label?: attributes.SVGTextAttributes;
}
class Rectangle extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<RectangleSelectors>,
opt?: dia.Graph.Options
)
}
interface CircleSelectors {
root?: attributes.SVGAttributes;
body?: attributes.SVGCircleAttributes;
label?: attributes.SVGTextAttributes;
}
class Circle extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<CircleSelectors>,
opt?: dia.Graph.Options
)
}
interface EllipseSelectors {
root?: attributes.SVGAttributes;
body?: attributes.SVGCircleAttributes;
label?: attributes.SVGTextAttributes;
}
class Ellipse extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<EllipseSelectors>,
opt?: dia.Graph.Options
)
}
interface PathSelectors {
root?: attributes.SVGAttributes;
body?: attributes.SVGPathAttributes;
label?: attributes.SVGTextAttributes;
}
class Path extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<PathSelectors>,
opt?: dia.Graph.Options
)
}
interface PolygonSelectors {
root?: attributes.SVGAttributes;
body?: attributes.SVGPolygonAttributes;
label?: attributes.SVGTextAttributes;
}
class Polygon extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<PolygonSelectors>,
opt?: dia.Graph.Options
)
}
interface PolylineSelectors {
root?: attributes.SVGAttributes;
body?: attributes.SVGPolylineAttributes;
label?: attributes.SVGTextAttributes;
}
class Polyline extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<PolylineSelectors>,
opt?: dia.Graph.Options
)
}
interface ImageSelectors {
root?: attributes.SVGAttributes;
image?: attributes.SVGImageAttributes;
label?: attributes.SVGTextAttributes;
}
class Image extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<ImageSelectors>,
opt?: dia.Graph.Options
)
}
interface BorderedImageSelectors {
root?: attributes.SVGAttributes;
border?: attributes.SVGRectAttributes;
background?: attributes.SVGRectAttributes;
image?: attributes.SVGImageAttributes;
label?: attributes.SVGTextAttributes;
}
class BorderedImage extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<BorderedImageSelectors>,
opt?: dia.Graph.Options
)
}
interface EmbeddedImageSelectors {
root?: attributes.SVGAttributes;
body?: attributes.SVGRectAttributes;
image?: attributes.SVGImageAttributes;
label?: attributes.SVGTextAttributes;
}
class EmbeddedImage extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<EmbeddedImageSelectors>,
opt?: dia.Graph.Options
)
}
interface InscribedImageSelectors {
root?: attributes.SVGAttributes;
border?: attributes.SVGEllipseAttributes;
background?: attributes.SVGEllipseAttributes;
image?: attributes.SVGImageAttributes;
label?: attributes.SVGTextAttributes;
}
class InscribedImage extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<InscribedImageSelectors>,
opt?: dia.Graph.Options
)
}
interface HeaderedRectangleSelectors {
root?: attributes.SVGAttributes;
body?: attributes.SVGRectAttributes;
header?: attributes.SVGRectAttributes;
headerText?: attributes.SVGTextAttributes;
bodyText?: attributes.SVGTextAttributes;
}
class HeaderedRectangle extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<HeaderedRectangleSelectors>,
opt?: dia.Graph.Options
)
}
interface CylinderBodyAttributes extends attributes.SVGPathAttributes {
lateralArea?: string | number;
}
interface CylinderSelectors {
root?: attributes.SVGAttributes;
body?: CylinderBodyAttributes;
top?: attributes.SVGEllipseAttributes;
}
class Cylinder extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<CylinderSelectors>,
opt?: dia.Graph.Options
)
topRy(): string | number;
topRy(t: string | number, opt?: dia.Cell.Options): this;
}
interface TextBlockSelectors {
root?: attributes.SVGAttributes;
body?: attributes.SVGRectAttributes;
label?: {
text?: string;
style?: { [key: string]: any };
[key: string]: any;
}
}
class TextBlock extends dia.Element {
constructor(
attributes?: dia.Element.GenericAttributes<TextBlockSelectors>,
opt?: dia.Graph.Options
)
}
interface LinkSelectors {
root?: attributes.SVGAttributes;
line?: attributes.SVGPathAttributes;
wrapper?: attributes.SVGPathAttributes;
}
class Link extends dia.Link {
constructor(
attributes?: dia.Link.GenericAttributes<LinkSelectors>,
opt?: dia.Graph.Options
)
}
interface DoubleLinkSelectors {
root?: attributes.SVGAttributes;
line?: attributes.SVGPathAttributes;
outline?: attributes.SVGPathAttributes;
}
class DoubleLink extends dia.Link {
constructor(
attributes?: dia.Link.GenericAttributes<DoubleLinkSelectors>,