From 72b070ba3c809fa7ea6e89bf8c3be9a8a01acafc Mon Sep 17 00:00:00 2001
From: Roman Bruckner As we can see, the As we can see, the
- Attributes defined in
Add a new cell to the graph. If Presentation
selector: 'label'
}]
-joint.shapes.standard.Rect
shape consists of two subelements
: one SVGRectElement named 'body'
and one SVGTextElement named 'label'
. The attrs
object refers to the subelements' names (selectors
) to provide SVG attributes to these constituent SVGElements.joint.shapes.standard.Rectangle
shape consists of two subelements
: one SVGRectElement named 'body'
and one SVGTextElement named 'label'
. The attrs
object refers to the subelements' names (selectors
) to provide SVG attributes to these constituent SVGElements.Styling
@@ -64,9 +64,9 @@ Styling
Attributes
markup
are evaluated once at CellView creation,
- while attributes defined in attrs
are evaluated on every model change. As JointJS special attributes usually depend on the
- current state of the model, we should define them in attrs
, along with any other SVG attributes that will be modified
+ Attributes defined in markup
are evaluated once at CellView creation,
+ while attributes defined in attrs
are evaluated on every model change. As JointJS special attributes usually depend on the
+ current state of the model, we should define them in attrs
, along with any other SVG attributes that will be modified
in the runtime of your application.
cell
is an array, all the cells in the array will be added to the graph.
- Any additional option or custom property provided in the options object will be accessible in the callback function of
+ Any additional option or custom property provided in the options object will be accessible in the callback function of
the graph add event.
opt.sort
is set to false
, the cell
will be added at the end of the collection.
const rect = new joint.shapes.standard.Rectangle({
+const rect = new joint.shapes.standard.Rectangle({
position: { x: 100, y: 100 },
size: { width: 90, height: 30 },
attrs: { label: { text: 'my rectangle' } }
});
const rect2 = rect.clone();
-const link = new joint.dia.Link({ source: { id: rect.id }, target: { id: rect2.id } });
+const link = new joint.shapes.standard.Link({ source: { id: rect.id }, target: { id: rect2.id } });
const graph = new joint.dia.Graph({}, { cellNamespace: joint.shapes });
graph.addCell(rect).addCell(rect2).addCell(link);
diff --git a/packages/joint-core/docs/src/joint/api/dia/Link/intro.html b/packages/joint-core/docs/src/joint/api/dia/Link/intro.html
index 741f6fe84..9f2626758 100644
--- a/packages/joint-core/docs/src/joint/api/dia/Link/intro.html
+++ b/packages/joint-core/docs/src/joint/api/dia/Link/intro.html
@@ -6,12 +6,13 @@ Geometry
Links have two crucial properties: source
and target
. They define the starting point and the end point of the link. They can be defined with a Cell id (optionally, with additional subelement/magnet/port reference) or with a Point:
-var link1 = new joint.dia.Link({
+// `shapes.standard.Link` inherits from `dia.Link` (`dia.Link` is an abstract class that has no SVG markup defined)
+var link1 = new joint.shapes.standard.Link({
source: { id: sourceId },
target: { id: targetId, port: portId }
});
-var link2 = new joint.dia.Link({
+var link2 = new joint.shapes.standard.Link({
source: { id: sourceId },
target: { x: 100, y: 100 }
});
@@ -22,7 +23,8 @@ Geometry
Presentation
-Each joint.dia.Link
defines its own SVG markup
which is then used by joint.dia.LinkView
to render the link to the paper. For instance, the joint.shapes.standard.Link
(which inherits from joint.dia.Link
) defines its markup using the JSON array notation as follows:
+Each joint.dia.Link
defines its own SVG markup
which is then used by joint.dia.LinkView
to render the link to the paper.
+ For instance, the joint.shapes.standard.Link
(which inherits from joint.dia.Link
) defines its markup using the JSON array notation as follows:
markup: [{
tagName: 'path',
@@ -44,44 +46,6 @@ Presentation
As we can see, the joint.shapes.standard.Link
shape consists of two subelements
: one SVGPathElement named 'wrapper'
and one SVGPathElement named 'line'
. The attrs
object refers to the subelements' names (selectors
) to provide SVG attributes to these constituent SVGElements.
-Direct use of joint.dia.Link
is deprecated. Use links from the standard
namespace.
-
-The joint.dia.Link
markup looks like the following:
-
-<path class="connection"/>
-<path class="marker-source"/>
-<path class="marker-target"/>
-<path class="connection-wrap"/>
-<g class="labels" />
-<g class="marker-vertices"/>
-<g class="marker-arrowheads"/>
-<g class="link-tools" />
-
-As you can see, the link consists of a couple of SVG path elements and a couple of SVG group elements:
-
-
- .connection
is the actual line of the link.
- .connection-wrap
is an SVG path element that covers the .connection
element and is usually thicker so that the link is able to handle pointer events (mousedown, mousemove, mouseup) that didn't target the thin .connection
path exactly. This makes it easy to grab
the link even though the mouse cursor didn't point exactly at the (usually thin) .connection
path element.
- .marker-source
and .marker-target
are the arrowheads of the link.
-
-
-The subelements of the link can be optionally styled through link attributes. For example:
-
-link.attr({
- '.connection': { stroke: 'blue' },
- '.marker-source': { fill: 'red', d: 'M 10 0 L 0 5 L 10 10 z' },
- '.marker-target': { fill: 'yellow', d: 'M 10 0 L 0 5 L 10 10 z' }
-});
-
-The markup
attribute is not the only presentation attribute that may be specified for a joint.dia.Link
. However, the following four Link properties are deprecated and included only for backwards compatibility. Use link tools instead.
-
-
- vertexMarkup
- provide default vertex markup for all vertices created on an instance of this Link type (on hover).
- toolMarkup
- provide custom tool markup for all instances of this Link type (on hover).
- doubleToolMarkup
- provide custom markup for second set of tools for all instances of this Link type (on hover, if linkView.doubleLinkTools
is true
).
- arrowheadMarkup
- provide custom arrowhead markup for all instances of this Link type (on hover).
-
-
Styling
The keys of the attrs
object are selectors
that match subelements defined in the link's markup
(see above). The values of this object are special JointJS attributes or native SVG attributes that should be set on the selected subelements. (A list of native SVG attributes and their descriptions can be found online, e.g. on MDN.)
@@ -212,18 +176,18 @@ Custom Properties
interactive: function(cellView) {
if (cellView.model.get('customLinkInteractions')) {
// only links with `customLinkInteractions: true`
- return { vertexAdd: false };
+ return true;
}
- return true; // otherwise
+ return { labelMove: false }; // otherwise
}
});
-var link1 = new joint.dia.Link({
+var link1 = new joint.shapes.standard.Link({
//...
customLinkInteractions: true // right-click adds a label
});
-var link2 = new joint.dia.Link({
+var link2 = new joint.shapes.standard.Link({
//...
customLinkInteractions: false // or omit completely
});
diff --git a/packages/joint-core/docs/src/joint/api/dia/Paper/events.html b/packages/joint-core/docs/src/joint/api/dia/Paper/events.html
index f245e5092..3ab031104 100644
--- a/packages/joint-core/docs/src/joint/api/dia/Paper/events.html
+++ b/packages/joint-core/docs/src/joint/api/dia/Paper/events.html
@@ -505,14 +505,14 @@
// Create a new link by dragging
paper.on({
'blank:pointerdown': function(evt, x, y) {
- var link = new joint.dia.Link();
- link.set('source', { x: x, y: y });
- link.set('target', { x: x, y: y });
+ const link = new joint.shapes.standard.Link();
+ link.set('source', { x, y });
+ link.set('target', { x, y });
link.addTo(this.model);
- evt.data = { link: link, x: x, y: y };
+ evt.data = { link, x, y };
},
'blank:pointermove': function(evt, x, y) {
- evt.data.link.set('target', { x: x, y: y });
+ evt.data.link.set('target', { x, y });
},
'blank:pointerup': function(evt) {
var target = evt.data.link.get('target');
diff --git a/packages/joint-core/docs/src/joint/api/dia/Paper/prototype/options/defaultLink.html b/packages/joint-core/docs/src/joint/api/dia/Paper/prototype/options/defaultLink.html
index e87344655..305bb4313 100644
--- a/packages/joint-core/docs/src/joint/api/dia/Paper/prototype/options/defaultLink.html
+++ b/packages/joint-core/docs/src/joint/api/dia/Paper/prototype/options/defaultLink.html
@@ -1 +1 @@
-defaultLink
- link that should be created when the user clicks and drags an active magnet (when creating a link from a port via the UI). Defaults to new joint.dia.Link
. It can also be a function with signature function(cellView, magnet) {}
that must return an object of type joint.dia.Link
.
+defaultLink
- link that should be created when the user clicks and drags an active magnet (when creating a link from a port via the UI). Defaults to new joint.shapes.standard.Link()
. It can also be a function with signature function(cellView, magnet) {}
that must return an object of type joint.dia.Link
.
diff --git a/packages/joint-core/docs/src/joint/api/dia/Paper/prototype/options/interactive.html b/packages/joint-core/docs/src/joint/api/dia/Paper/prototype/options/interactive.html
index 5b1ff3305..289330839 100644
--- a/packages/joint-core/docs/src/joint/api/dia/Paper/prototype/options/interactive.html
+++ b/packages/joint-core/docs/src/joint/api/dia/Paper/prototype/options/interactive.html
@@ -18,10 +18,10 @@
Using an object, specific interactions may be disabled by assigning false
to their corresponding property name. It is not necessary to pass true
values; all omitted properties are assigned true
by default. (Note that the passed object is not merged with the default; unless labelMove
is explicitly excluded, it becomes enabled.) A full list of recognized interaction keys is provided below.
-// disable arrowheadMove
+// disable labelMove
var paper = new joint.dia.Paper({
// ...
- interactive: { arrowheadMove: false }
+ interactive: { labelMove: false }
});
// disable all element interactions
@@ -40,11 +40,6 @@
return {
linkMove: false,
labelMove: false,
- arrowheadMove: false,
- vertexMove: false,
- vertexAdd: false,
- vertexRemove: false,
- useLinkTools: false,
};
}
@@ -78,46 +73,6 @@
-
- arrowheadMove
-
- Deprecated. Use a link tool instead.
- (Is the user allowed to move the arrowheads?)
-
-
-
-
- vertexMove
-
- Deprecated. Use a link tool instead.
- (Is the user allowed to move the vertices?)
-
-
-
-
- vertexAdd
-
- Deprecated. Use a link tool instead.
- (Is the user allowed to add vertices by clicking along the link path?)
-
-
-
-
- vertexRemove
-
- Deprecated. Use a link tool instead.
- (Is the user allowed to remove vertices?)
-
-
-
-
- useLinkTools
-
- Deprecated.
- (Is the user allowed to use the default link buttons?)
-
-
-
Elements:
diff --git a/packages/joint-core/docs/src/joint/api/layout/DirectedGraph.html b/packages/joint-core/docs/src/joint/api/layout/DirectedGraph.html
index e6b4fe677..5b83fca07 100644
--- a/packages/joint-core/docs/src/joint/api/layout/DirectedGraph.html
+++ b/packages/joint-core/docs/src/joint/api/layout/DirectedGraph.html
@@ -182,7 +182,7 @@ API
});
},
importEdge: function(edge) {
- return new joint.dia.Link({
+ return new joint.shapes.standard.Link({
source: { id: edge.v },
target: { id: edge.w }
});
diff --git a/packages/joint-core/docs/src/joint/api/linkTools/Vertices.html b/packages/joint-core/docs/src/joint/api/linkTools/Vertices.html
index f343b8e4b..67d7da001 100644
--- a/packages/joint-core/docs/src/joint/api/linkTools/Vertices.html
+++ b/packages/joint-core/docs/src/joint/api/linkTools/Vertices.html
@@ -16,6 +16,16 @@
boolean
Can the user add new vertices (by clicking a segment of the link)? Default is true
.
+
+ vertexMoving
+ boolean
+ Can the user move vertices (by dragging them)? Default is true
.
+
+
+ vertexRemoving
+ boolean
+ Can the user remove vertices (by double clicking them)? Default is true
.
+
stopPropagation
boolean
diff --git a/packages/joint-core/src/dia/CellView.mjs b/packages/joint-core/src/dia/CellView.mjs
index 02d440fa1..f82741c69 100644
--- a/packages/joint-core/src/dia/CellView.mjs
+++ b/packages/joint-core/src/dia/CellView.mjs
@@ -189,7 +189,7 @@ export const CellView = View.extend({
},
// Return `true` if cell link is allowed to perform a certain UI `feature`.
- // Example: `can('vertexMove')`, `can('labelMove')`.
+ // Example: `can('labelMove')`.
can: function(feature) {
var interactive = isFunction(this.options.interactive)
diff --git a/packages/joint-core/src/dia/Link.mjs b/packages/joint-core/src/dia/Link.mjs
index 74d61721f..7968256e3 100644
--- a/packages/joint-core/src/dia/Link.mjs
+++ b/packages/joint-core/src/dia/Link.mjs
@@ -7,54 +7,6 @@ import { Point, Polyline } from '../g/index.mjs';
export const Link = Cell.extend({
- // The default markup for links.
- markup: [
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' ',
- ' '
- ].join(''),
-
- toolMarkup: [
- '',
- '',
- ' ',
- ' ',
- 'Remove link. ',
- ' ',
- '',
- ' ',
- ' ',
- 'Link options. ',
- ' ',
- ' '
- ].join(''),
-
- doubleToolMarkup: undefined,
-
- // The default markup for showing/removing vertices. These elements are the children of the .marker-vertices element (see `this.markup`).
- // Only .marker-vertex and .marker-vertex-remove element have special meaning. The former is used for
- // dragging vertices (changing their position). The latter is used for removing vertices.
- vertexMarkup: [
- '',
- ' ',
- ' ',
- '',
- 'Remove vertex. ',
- ' ',
- ' '
- ].join(''),
-
- arrowheadMarkup: [
- '',
- ' ',
- ' '
- ].join(''),
-
// may be overwritten by user to change default label (its markup, size, attrs, position)
defaultLabel: undefined,
diff --git a/packages/joint-core/src/dia/LinkView.mjs b/packages/joint-core/src/dia/LinkView.mjs
index ecdbc5437..549e07f5f 100644
--- a/packages/joint-core/src/dia/LinkView.mjs
+++ b/packages/joint-core/src/dia/LinkView.mjs
@@ -1,20 +1,17 @@
import { CellView } from './CellView.mjs';
import { Link } from './Link.mjs';
import V from '../V/index.mjs';
-import { addClassNamePrefix, removeClassNamePrefix, merge, template, assign, toArray, isObject, isFunction, clone, isPercentage, result, isEqual, camelCase } from '../util/index.mjs';
+import { addClassNamePrefix, merge, assign, isObject, isFunction, clone, isPercentage, result, isEqual } from '../util/index.mjs';
import { Point, Line, Path, normalizeAngle, Rect, Polyline } from '../g/index.mjs';
import * as routers from '../routers/index.mjs';
import * as connectors from '../connectors/index.mjs';
-import $ from '../mvc/Dom/index.mjs';
const Flags = {
TOOLS: CellView.Flags.TOOLS,
RENDER: 'RENDER',
UPDATE: 'UPDATE',
- LEGACY_TOOLS: 'LEGACY_TOOLS',
LABELS: 'LABELS',
- VERTICES: 'VERTICES',
SOURCE: 'SOURCE',
TARGET: 'TARGET',
CONNECTOR: 'CONNECTOR'
@@ -46,7 +43,6 @@ export const LinkView = CellView.extend({
_labelCache: null,
_labelSelectors: null,
- _markerCache: null,
_V: null,
_dragData: null, // deprecated
@@ -65,9 +61,6 @@ export const LinkView = CellView.extend({
// a cache of label selectors
this._labelSelectors = {};
- // keeps markers bboxes and positions again for quicker access
- this._markerCache = {};
-
// cache of default markup nodes
this._V = {};
@@ -80,11 +73,9 @@ export const LinkView = CellView.extend({
attrs: [Flags.UPDATE],
router: [Flags.UPDATE],
connector: [Flags.CONNECTOR],
- toolMarkup: [Flags.LEGACY_TOOLS],
labels: [Flags.LABELS],
labelMarkup: [Flags.LABELS],
- vertices: [Flags.VERTICES, Flags.UPDATE],
- vertexMarkup: [Flags.VERTICES],
+ vertices: [Flags.UPDATE],
source: [Flags.SOURCE, Flags.UPDATE],
target: [Flags.TARGET, Flags.UPDATE]
},
@@ -117,21 +108,15 @@ export const LinkView = CellView.extend({
this.render();
this.updateHighlighters(true);
this.updateTools(opt);
- flags = this.removeFlag(flags, [Flags.RENDER, Flags.UPDATE, Flags.VERTICES, Flags.LABELS, Flags.TOOLS, Flags.LEGACY_TOOLS, Flags.CONNECTOR]);
+ flags = this.removeFlag(flags, [Flags.RENDER, Flags.UPDATE, Flags.LABELS, Flags.TOOLS, Flags.CONNECTOR]);
return flags;
}
let updateHighlighters = false;
- if (this.hasFlag(flags, Flags.VERTICES)) {
- this.renderVertexMarkers();
- flags = this.removeFlag(flags, Flags.VERTICES);
- }
-
const { model } = this;
const { attributes } = model;
let updateLabels = this.hasFlag(flags, Flags.LABELS);
- let updateLegacyTools = this.hasFlag(flags, Flags.LEGACY_TOOLS);
if (updateLabels) {
this.onLabelsChange(model, attributes.labels, opt);
@@ -139,11 +124,6 @@ export const LinkView = CellView.extend({
updateHighlighters = true;
}
- if (updateLegacyTools) {
- this.renderTools();
- flags = this.removeFlag(flags, Flags.LEGACY_TOOLS);
- }
-
const updateAll = this.hasFlag(flags, Flags.UPDATE);
const updateConnector = this.hasFlag(flags, Flags.CONNECTOR);
if (updateAll || updateConnector) {
@@ -162,7 +142,6 @@ export const LinkView = CellView.extend({
this.updateTools(opt);
flags = this.removeFlag(flags, [Flags.UPDATE, Flags.TOOLS, Flags.CONNECTOR]);
updateLabels = false;
- updateLegacyTools = false;
updateHighlighters = true;
}
@@ -170,10 +149,6 @@ export const LinkView = CellView.extend({
this.updateLabelPositions();
}
- if (updateLegacyTools) {
- this.updateToolsPosition();
- }
-
if (updateHighlighters) {
this.updateHighlighters();
}
@@ -276,21 +251,7 @@ export const LinkView = CellView.extend({
var children = V(markup);
// custom markup may contain only one children
if (!Array.isArray(children)) children = [children];
- // Cache all children elements for quicker access.
- var cache = this._V; // vectorized markup;
- for (var i = 0, n = children.length; i < n; i++) {
- var child = children[i];
- var className = child.attr('class');
- if (className) {
- // Strip the joint class name prefix, if there is one.
- className = removeClassNamePrefix(className);
- cache[camelCase(className)] = child;
- }
- }
- // partial rendering
- this.renderTools();
- this.renderVertexMarkers();
- this.renderArrowheadMarkers();
+
this.vel.append(children);
},
@@ -537,83 +498,6 @@ export const LinkView = CellView.extend({
return this;
},
- renderTools: function() {
-
- if (!this._V.linkTools) return this;
-
- // Tools are a group of clickable elements that manipulate the whole link.
- // A good example of this is the remove tool that removes the whole link.
- // Tools appear after hovering the link close to the `source` element/point of the link
- // but are offset a bit so that they don't cover the `marker-arrowhead`.
-
- var $tools = $(this._V.linkTools.node).empty();
- var toolTemplate = template(this.model.get('toolMarkup') || this.model.toolMarkup);
- var tool = V(toolTemplate());
-
- $tools.append(tool.node);
-
- // Cache the tool node so that the `updateToolsPosition()` can update the tool position quickly.
- this._toolCache = tool;
-
- // If `doubleLinkTools` is enabled, we render copy of the tools on the other side of the
- // link as well but only if the link is longer than `longLinkLength`.
- if (this.options.doubleLinkTools) {
-
- var tool2;
- if (this.model.get('doubleToolMarkup') || this.model.doubleToolMarkup) {
- toolTemplate = template(this.model.get('doubleToolMarkup') || this.model.doubleToolMarkup);
- tool2 = V(toolTemplate());
- } else {
- tool2 = tool.clone();
- }
-
- $tools.append(tool2.node);
- this._tool2Cache = tool2;
- }
-
- return this;
- },
-
- renderVertexMarkers: function() {
-
- if (!this._V.markerVertices) return this;
-
- var $markerVertices = $(this._V.markerVertices.node).empty();
-
- // A special markup can be given in the `properties.vertexMarkup` property. This might be handy
- // if default styling (elements) are not desired. This makes it possible to use any
- // SVG elements for .marker-vertex and .marker-vertex-remove tools.
- var markupTemplate = template(this.model.get('vertexMarkup') || this.model.vertexMarkup);
-
- this.model.vertices().forEach(function(vertex, idx) {
- $markerVertices.append(V(markupTemplate(assign({ idx: idx }, vertex))).node);
- });
-
- return this;
- },
-
- renderArrowheadMarkers: function() {
-
- // Custom markups might not have arrowhead markers. Therefore, jump of this function immediately if that's the case.
- if (!this._V.markerArrowheads) return this;
-
- var $markerArrowheads = $(this._V.markerArrowheads.node);
-
- $markerArrowheads.empty();
-
- // A special markup can be given in the `properties.vertexMarkup` property. This might be handy
- // if default styling (elements) are not desired. This makes it possible to use any
- // SVG elements for .marker-vertex and .marker-vertex-remove tools.
- var markupTemplate = template(this.model.get('arrowheadMarkup') || this.model.arrowheadMarkup);
-
- this._V.sourceArrowhead = V(markupTemplate({ end: 'source' }));
- this._V.targetArrowhead = V(markupTemplate({ end: 'target' }));
-
- $markerArrowheads.append(this._V.sourceArrowhead.node, this._V.targetArrowhead.node);
-
- return this;
- },
-
// remove vertices that lie on (or nearly on) straight lines within the link
// return the number of removed points
removeRedundantLinearVertices: function(opt) {
@@ -640,23 +524,6 @@ export const LinkView = CellView.extend({
return (numRoutePoints - numPolylinePoints);
},
- updateDefaultConnectionPath: function() {
-
- var cache = this._V;
-
- if (cache.connection) {
- cache.connection.attr('d', this.getSerializedConnection());
- }
-
- if (cache.connectionWrap) {
- cache.connectionWrap.attr('d', this.getSerializedConnection());
- }
-
- if (cache.markerSource && cache.markerTarget) {
- this._translateAndAutoOrientArrows(cache.markerSource, cache.markerTarget);
- }
- },
-
getEndView: function(type) {
switch (type) {
case 'source':
@@ -724,8 +591,11 @@ export const LinkView = CellView.extend({
const polyline = new Polyline(route);
polyline.translate(tx, ty);
this.route = polyline.points;
- // translate source and target connection and marker points.
- this._translateConnectionPoints(tx, ty);
+ // translate source and target connection and anchor points.
+ this.sourcePoint.offset(tx, ty);
+ this.targetPoint.offset(tx, ty);
+ this.sourceAnchor.offset(tx, ty);
+ this.targetAnchor.offset(tx, ty);
// translate the geometry path
path.translate(tx, ty);
this.updateDOM();
@@ -736,12 +606,8 @@ export const LinkView = CellView.extend({
this.cleanNodesCache();
// update SVG attributes defined by 'attrs/'.
this.updateDOMSubtreeAttributes(el, model.attr(), { selectors });
- // legacy link path update
- this.updateDefaultConnectionPath();
// update the label position etc.
this.updateLabelPositions();
- this.updateToolsPosition();
- this.updateArrowheadMarkers();
// *Deprecated*
// Local perpendicular flag (as opposed to one defined on paper).
// Could be enabled inside a connector/router. It's valid only
@@ -767,55 +633,11 @@ export const LinkView = CellView.extend({
updatePath: function() {
const { route, sourcePoint, targetPoint } = this;
- // 3b. Find Marker Connection Point - Backwards Compatibility
- const markerPoints = this.findMarkerPoints(route, sourcePoint, targetPoint);
// 4. Find Connection
- const path = this.findPath(route, markerPoints.source || sourcePoint, markerPoints.target || targetPoint);
+ const path = this.findPath(route, sourcePoint.clone(), targetPoint.clone());
this.path = path;
},
- findMarkerPoints: function(route, sourcePoint, targetPoint) {
-
- var firstWaypoint = route[0];
- var lastWaypoint = route[route.length - 1];
-
- // Move the source point by the width of the marker taking into account
- // its scale around x-axis. Note that scale is the only transform that
- // makes sense to be set in `.marker-source` attributes object
- // as all other transforms (translate/rotate) will be replaced
- // by the `translateAndAutoOrient()` function.
- var cache = this._markerCache;
- // cache source and target points
- var sourceMarkerPoint, targetMarkerPoint;
-
- if (this._V.markerSource) {
-
- cache.sourceBBox = cache.sourceBBox || this._V.markerSource.getBBox();
- sourceMarkerPoint = Point(sourcePoint).move(
- firstWaypoint || targetPoint,
- cache.sourceBBox.width * this._V.markerSource.scale().sx * -1
- ).round();
- }
-
- if (this._V.markerTarget) {
-
- cache.targetBBox = cache.targetBBox || this._V.markerTarget.getBBox();
- targetMarkerPoint = Point(targetPoint).move(
- lastWaypoint || sourcePoint,
- cache.targetBBox.width * this._V.markerTarget.scale().sx * -1
- ).round();
- }
-
- // if there was no markup for the marker, use the connection point.
- cache.sourcePoint = sourceMarkerPoint || sourcePoint.clone();
- cache.targetPoint = targetMarkerPoint || targetPoint.clone();
-
- return {
- source: sourceMarkerPoint,
- target: targetMarkerPoint
- };
- },
-
findAnchorsOrdered: function(firstEndType, firstRef, secondEndType, secondRef) {
var firstAnchor, secondAnchor;
@@ -986,18 +808,6 @@ export const LinkView = CellView.extend({
return connectionPoint.round(this.decimalsRounding);
},
- _translateConnectionPoints: function(tx, ty) {
-
- var cache = this._markerCache;
-
- cache.sourcePoint.offset(tx, ty);
- cache.targetPoint.offset(tx, ty);
- this.sourcePoint.offset(tx, ty);
- this.targetPoint.offset(tx, ty);
- this.sourceAnchor.offset(tx, ty);
- this.targetAnchor.offset(tx, ty);
- },
-
// combine default label position with built-in default label position
_getDefaultLabelPositionProperty: function() {
@@ -1077,63 +887,6 @@ export const LinkView = CellView.extend({
}
},
- updateToolsPosition: function() {
-
- if (!this._V.linkTools) return this;
-
- // Move the tools a bit to the target position but don't cover the `sourceArrowhead` marker.
- // Note that the offset is hardcoded here. The offset should be always
- // more than the `this.$('.marker-arrowhead[end="source"]')[0].bbox().width` but looking
- // this up all the time would be slow.
-
- var scale = '';
- var offset = this.options.linkToolsOffset;
- var connectionLength = this.getConnectionLength();
-
- // Firefox returns connectionLength=NaN in odd cases (for bezier curves).
- // In that case we won't update tools position at all.
- if (!Number.isNaN(connectionLength)) {
-
- // If the link is too short, make the tools half the size and the offset twice as low.
- if (connectionLength < this.options.shortLinkLength) {
- scale = 'scale(.5)';
- offset /= 2;
- }
-
- var toolPosition = this.getPointAtLength(offset);
-
- this._toolCache.attr('transform', 'translate(' + toolPosition.x + ', ' + toolPosition.y + ') ' + scale);
-
- if (this.options.doubleLinkTools && connectionLength >= this.options.longLinkLength) {
-
- var doubleLinkToolsOffset = this.options.doubleLinkToolsOffset || offset;
-
- toolPosition = this.getPointAtLength(connectionLength - doubleLinkToolsOffset);
- this._tool2Cache.attr('transform', 'translate(' + toolPosition.x + ', ' + toolPosition.y + ') ' + scale);
- this._tool2Cache.attr('display', 'inline');
-
- } else if (this.options.doubleLinkTools) {
-
- this._tool2Cache.attr('display', 'none');
- }
- }
-
- return this;
- },
-
- updateArrowheadMarkers: function() {
-
- if (!this._V.markerArrowheads) return this;
-
- var sx = this.getConnectionLength() < this.options.shortLinkLength ? .5 : 1;
- this._V.sourceArrowhead.scale(sx);
- this._V.targetArrowhead.scale(sx);
-
- this._translateAndAutoOrientArrows(this._V.sourceArrowhead, this._V.targetArrowhead);
-
- return this;
- },
-
updateEndProperties: function(endType) {
const { model, paper } = this;
@@ -1175,28 +928,6 @@ export const LinkView = CellView.extend({
}
},
- _translateAndAutoOrientArrows: function(sourceArrow, targetArrow) {
-
- // Make the markers "point" to their sticky points being auto-oriented towards
- // `targetPosition`/`sourcePosition`. And do so only if there is a markup for them.
- var route = toArray(this.route);
- if (sourceArrow) {
- sourceArrow.translateAndAutoOrient(
- this.sourcePoint,
- route[0] || this.targetPoint,
- this.paper.cells
- );
- }
-
- if (targetArrow) {
- targetArrow.translateAndAutoOrient(
- this.targetPoint,
- route[route.length - 1] || this.sourcePoint,
- this.paper.cells
- );
- }
- },
-
_getLabelPositionProperty: function(idx) {
return (this.model.label(idx).position || {});
@@ -1311,7 +1042,7 @@ export const LinkView = CellView.extend({
// Send a token (an SVG element, usually a circle) along the connection path.
// Example: `link.findView(paper).sendToken(V('circle', { r: 7, fill: 'green' }).node)`
// `opt.duration` is optional and is a time in milliseconds that the token travels from the source to the target of the link. Default is `1000`.
- // `opt.directon` is optional and it determines whether the token goes from source to target or other way round (`reverse`)
+ // `opt.direction` is optional and it determines whether the token goes from source to target or other way round (`reverse`)
// `opt.connection` is an optional selector to the connection path.
// `callback` is optional and is a function to be called once the token reaches the target.
sendToken: function(token, opt, callback) {
@@ -1740,34 +1471,6 @@ export const LinkView = CellView.extend({
pointerdown: function(evt, x, y) {
this.notifyPointerdown(evt, x, y);
-
- // Backwards compatibility for the default markup
- var className = evt.target.getAttribute('class');
- switch (className) {
-
- case 'marker-vertex':
- this.dragVertexStart(evt, x, y);
- return;
-
- case 'marker-vertex-remove':
- case 'marker-vertex-remove-area':
- this.dragVertexRemoveStart(evt, x, y);
- return;
-
- case 'marker-arrowhead':
- this.dragArrowheadStart(evt, x, y);
- return;
-
- case 'connection':
- case 'connection-wrap':
- this.dragConnectionStart(evt, x, y);
- return;
-
- case 'marker-source':
- case 'marker-target':
- return;
- }
-
this.dragStart(evt, x, y);
},
@@ -1780,10 +1483,6 @@ export const LinkView = CellView.extend({
var data = this.eventData(evt);
switch (data.action) {
- case 'vertex-move':
- this.dragVertex(evt, x, y);
- break;
-
case 'label-move':
this.dragLabel(evt, x, y);
break;
@@ -1815,10 +1514,6 @@ export const LinkView = CellView.extend({
var data = this.eventData(evt);
switch (data.action) {
- case 'vertex-move':
- this.dragVertexEnd(evt, x, y);
- break;
-
case 'label-move':
this.dragLabelEnd(evt, x, y);
break;
@@ -1865,36 +1560,6 @@ export const LinkView = CellView.extend({
this.notify('link:mousewheel', evt, x, y, delta);
},
- onevent: function(evt, eventName, x, y) {
-
- // Backwards compatibility
- var linkTool = V(evt.target).findParentByClass('link-tool', this.el);
- if (linkTool) {
- // No further action to be executed
- evt.stopPropagation();
-
- // Allow `interactive.useLinkTools=false`
- if (this.can('useLinkTools')) {
- if (eventName === 'remove') {
- // Built-in remove event
- this.model.remove({ ui: true });
- // Do not trigger link pointerdown
- return;
-
- } else {
- // link:options and other custom events inside the link tools
- this.notify(eventName, evt, x, y);
- }
- }
-
- this.notifyPointerdown(evt, x, y);
- this.paper.delegateDragEvents(this, evt.data);
-
- } else {
- CellView.prototype.onevent.apply(this, arguments);
- }
- },
-
onlabel: function(evt, x, y) {
this.notifyPointerdown(evt, x, y);
@@ -1907,19 +1572,6 @@ export const LinkView = CellView.extend({
// Drag Start Handlers
- dragConnectionStart: function(evt, x, y) {
-
- if (!this.can('vertexAdd')) return;
-
- // Store the index at which the new vertex has just been placed.
- // We'll be update the very same vertex position in `pointermove()`.
- var vertexIdx = this.addVertex({ x: x, y: y }, { ui: true });
- this.eventData(evt, {
- action: 'vertex-move',
- vertexIdx: vertexIdx
- });
- },
-
dragLabelStart: function(evt, x, y) {
if (this.can('labelMove')) {
@@ -1962,27 +1614,6 @@ export const LinkView = CellView.extend({
this.paper.delegateDragEvents(this, evt.data);
},
- dragVertexStart: function(evt, x, y) {
-
- if (!this.can('vertexMove')) return;
-
- var vertexNode = evt.target;
- var vertexIdx = parseInt(vertexNode.getAttribute('idx'), 10);
- this.eventData(evt, {
- action: 'vertex-move',
- vertexIdx: vertexIdx
- });
- },
-
- dragVertexRemoveStart: function(evt, x, y) {
-
- if (!this.can('vertexRemove')) return;
-
- var removeNode = evt.target;
- var vertexIdx = parseInt(removeNode.getAttribute('idx'), 10);
- this.model.removeVertex(vertexIdx);
- },
-
dragArrowheadStart: function(evt, x, y) {
if (!this.can('arrowheadMove')) return;
@@ -2026,12 +1657,6 @@ export const LinkView = CellView.extend({
this.model.label(data.labelIdx, label, setOptions);
},
- dragVertex: function(evt, x, y) {
-
- var data = this.eventData(evt);
- this.model.vertex(data.vertexIdx, { x: x, y: y }, { ui: true });
- },
-
dragArrowhead: function(evt, x, y) {
if (this.paper.options.snapLinks) {
const isSnapped = this._snapArrowhead(evt, x, y);
@@ -2063,10 +1688,6 @@ export const LinkView = CellView.extend({
// noop
},
- dragVertexEnd: function() {
- // noop
- },
-
dragArrowheadEnd: function(evt, x, y) {
var data = this.eventData(evt);
diff --git a/packages/joint-core/src/dia/Paper.mjs b/packages/joint-core/src/dia/Paper.mjs
index bbad4c34c..bbf9ad33c 100644
--- a/packages/joint-core/src/dia/Paper.mjs
+++ b/packages/joint-core/src/dia/Paper.mjs
@@ -37,7 +37,6 @@ import { View, views } from '../mvc/index.mjs';
import { CellView } from './CellView.mjs';
import { ElementView } from './ElementView.mjs';
import { LinkView } from './LinkView.mjs';
-import { Link } from './Link.mjs';
import { Cell } from './Cell.mjs';
import { Graph } from './Graph.mjs';
import { LayersNames, PaperLayer } from './PaperLayer.mjs';
@@ -168,8 +167,16 @@ export const Paper = View.extend({
// Defines what link model is added to the graph after an user clicks on an active magnet.
// Value could be the mvc.model or a function returning the mvc.model
- // defaultLink: function(elementView, magnet) { return condition ? new customLink1() : new customLink2() }
- defaultLink: new Link,
+ // defaultLink: (elementView, magnet) => {
+ // return condition ? new customLink1() : new customLink2()
+ // }
+ defaultLink: function() {
+ // Do not create hard dependency on the joint.shapes.standard namespace (by importing the standard.Link model directly)
+ const { cellNamespace } = this.model.get('cells');
+ const ctor = getByPath(cellNamespace, ['standard', 'Link']);
+ if (!ctor) throw new Error('dia.Paper: no default link model found. Use `options.defaultLink` to specify a default link model.');
+ return new ctor();
+ },
// A connector that is used by links with no connector defined on the model.
// e.g. { name: 'rounded', args: { radius: 5 }} or a function
diff --git a/packages/joint-core/src/linkTools/Arrowhead.mjs b/packages/joint-core/src/linkTools/Arrowhead.mjs
index 9b4a9c6a9..7ce59e12b 100644
--- a/packages/joint-core/src/linkTools/Arrowhead.mjs
+++ b/packages/joint-core/src/linkTools/Arrowhead.mjs
@@ -49,11 +49,9 @@ const Arrowhead = ToolView.extend({
evt.preventDefault();
var relatedView = this.relatedView;
relatedView.model.startBatch('arrowhead-move', { ui: true, tool: this.cid });
- if (relatedView.can('arrowheadMove')) {
- relatedView.startArrowheadMove(this.arrowheadType);
- this.delegateDocumentEvents();
- relatedView.paper.undelegateEvents();
- }
+ relatedView.startArrowheadMove(this.arrowheadType);
+ this.delegateDocumentEvents();
+ relatedView.paper.undelegateEvents();
this.focus();
this.el.style.pointerEvents = 'none';
},
diff --git a/packages/joint-core/src/linkTools/Vertices.mjs b/packages/joint-core/src/linkTools/Vertices.mjs
index 03ce84147..8a98a6345 100644
--- a/packages/joint-core/src/linkTools/Vertices.mjs
+++ b/packages/joint-core/src/linkTools/Vertices.mjs
@@ -150,13 +150,13 @@ export const Vertices = ToolView.extend({
if (connection) connection.setAttribute('d', this.relatedView.getSerializedConnection());
},
startHandleListening: function(handle) {
- var relatedView = this.relatedView;
- if (relatedView.can('vertexMove')) {
+ const { vertexRemoving = true, vertexMoving = true } = this.options;
+ if (vertexMoving) {
this.listenTo(handle, 'will-change', this.onHandleWillChange);
this.listenTo(handle, 'changing', this.onHandleChanging);
this.listenTo(handle, 'changed', this.onHandleChanged);
}
- if (relatedView.can('vertexRemove')) {
+ if (vertexRemoving) {
this.listenTo(handle, 'remove', this.onHandleRemove);
}
},
diff --git a/packages/joint-core/test/jointjs/basic.js b/packages/joint-core/test/jointjs/basic.js
index adbc63702..95e7827a3 100644
--- a/packages/joint-core/test/jointjs/basic.js
+++ b/packages/joint-core/test/jointjs/basic.js
@@ -31,7 +31,7 @@ QUnit.module('basic', function(hooks) {
function ml(id, a, b) {
var source = a.x ? a : { id: a.id };
var target = b.x ? b : { id: b.id };
- return new joint.dia.Link({ id: id, source: source, target: target, name: id }).addTo(graph);
+ return new joint.shapes.standard.Link({ id: id, source: source, target: target, name: id }).addTo(graph);
}
var a = me('a');
@@ -604,11 +604,11 @@ QUnit.module('basic', function(hooks) {
assert.equal(elView.$('.big').attr('stroke'), undefined, 'The stroke was correctly unset from the element by removeAttr()');
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { x: 100, y: 100 },
target: { x: 200, y: 200 },
attrs: {
- '.connection': { width: 100, height: 50, fill: 'gray', 'stroke-width': 2 }
+ line: { fill: 'gray', strokeWidth: 2 }
}
});
@@ -616,11 +616,11 @@ QUnit.module('basic', function(hooks) {
var linkView = this.paper.findViewByModel(link);
- assert.equal(linkView.$('.connection').attr('stroke-width'), '2', 'A stroke is set on the link');
+ assert.equal(linkView.findNode('line').getAttribute('stroke-width'), '2', 'A stroke is set on the link');
- link.removeAttr('.connection/stroke-width');
+ link.removeAttr('line/strokeWidth');
- assert.equal(linkView.$('.connection').attr('stroke-width'), undefined, 'The stroke was correctly unset from the link by removeAttr()');
+ assert.equal(linkView.findNode('line').getAttribute('stroke-width'), undefined, 'The stroke was correctly unset from the link by removeAttr()');
});
@@ -1209,7 +1209,7 @@ QUnit.module('basic', function(hooks) {
// Deep clone.
- var l = new joint.dia.Link({ source: { id: r1.id }, target: { id: r2.id }});
+ var l = new joint.shapes.standard.Link({ source: { id: r1.id }, target: { id: r2.id }});
this.graph.addCell(l);
var clones = r1.clone({ deep: true });
@@ -2107,9 +2107,9 @@ QUnit.module('basic', function(hooks) {
QUnit.test('cell.isEmbedded()', function(assert) {
var rect = new joint.shapes.standard.Rectangle;
- var link = new joint.dia.Link;
+ var link = new joint.shapes.standard.Link;
var embeddedRect = new joint.shapes.standard.Rectangle;
- var embeddedLink = new joint.dia.Link;
+ var embeddedLink = new joint.shapes.standard.Link;
rect.embed(embeddedRect);
rect.embed(embeddedLink);
@@ -2129,7 +2129,7 @@ QUnit.module('basic', function(hooks) {
};
hooks.beforeEach(function() {
- this.link = new joint.dia.Link({
+ this.link = new joint.shapes.standard.Link({
source: { x: 100, y: 100 },
target: { x: 200, y: 200 },
vertices: []
@@ -2192,7 +2192,7 @@ QUnit.module('basic', function(hooks) {
QUnit.module('Link.scale()', function(hooks) {
hooks.beforeEach(function() {
- this.link = new joint.dia.Link({
+ this.link = new joint.shapes.standard.Link({
source: { x: 100, y: 100 },
target: { x: 200, y: 200 },
vertices: [{ x: 100, y: 200 }]
diff --git a/packages/joint-core/test/jointjs/connectors.js b/packages/joint-core/test/jointjs/connectors.js
index e211221a6..539e8b1ce 100644
--- a/packages/joint-core/test/jointjs/connectors.js
+++ b/packages/joint-core/test/jointjs/connectors.js
@@ -28,7 +28,7 @@ QUnit.module('connectors', function(hooks) {
this.graph.addCell([r1, r2]);
- var l0 = new joint.dia.Link({
+ var l0 = new joint.shapes.standard.Link({
source: { id: r1.id },
target: { id: r2.id },
vertices: [{ x: 150, y: 200 }],
@@ -42,17 +42,17 @@ QUnit.module('connectors', function(hooks) {
l0.set('connector', { name: 'normal' });
this.graph.addCell(l0);
assert.equal(this.graph.getLinks().length, 1, 'A link with the normal connector was successfully added to the graph');
- assert.checkDataPath(this.paper.findViewByModel(l0).getConnection().round(2).serialize(), 'M 102 110 L 150 200 L 320 104', 'A link with the normal connector was correctly rendered');
+ assert.checkDataPath(this.paper.findViewByModel(l0).getConnection().round().serialize(), 'M 102 110 L 150 200 L 320 104', 'A link with the normal connector was correctly rendered');
var l1 = l0.clone().set('connector', { name: 'rounded' });
this.graph.addCell(l1);
assert.equal(this.graph.getLinks().length, 2, 'A link with the rounded connector was successfully added to the graph');
- assert.checkDataPath(this.paper.findViewByModel(l1).getConnection().round(2).serialize(), 'M 102 110 L 145 191 C 148.33 197 153 198.33 159 195 L 320 104', 'A link with the rounded connector was correctly rendered');
+ assert.checkDataPath(this.paper.findViewByModel(l1).getConnection().round().serialize(), 'M 102 110 L 145 191 C 148 197 153 198 159 195 L 320 104', 'A link with the rounded connector was correctly rendered');
var l2 = l0.clone().set('connector', { name: 'smooth' });
this.graph.addCell(l2);
assert.equal(this.graph.getLinks().length, 3, 'A link with the smooth connector was successfully added to the graph');
- assert.checkDataPath(this.paper.findViewByModel(l2).getConnection().round(2).serialize(), 'M 102 110 C 107.83 155.5 113.67 201 150 200 C 186.33 199 253.17 151.5 320 104', 'A link with the smooth connector was correctly rendered');
+ assert.checkDataPath(this.paper.findViewByModel(l2).getConnection().round().serialize(), 'M 102 110 C 108 156 114 201 150 200 C 186 199 253 151 320 104', 'A link with the smooth connector was correctly rendered');
var l3 = l0.clone().set('connector', { name: 'straight', args: { cornerType: 'non-existing' }});
assert.throws(function() {
@@ -62,30 +62,30 @@ QUnit.module('connectors', function(hooks) {
l3.set('connector', { name: 'straight' });
this.graph.addCell(l3);
assert.equal(this.graph.getLinks().length, 4, 'A link with the (default) straight connector was successfully added to the graph');
- assert.checkDataPath(this.paper.findViewByModel(l3).getConnection().round(2).serialize(), 'M 102 110 L 150 200 L 320 104', 'A link with the (default) straight connector was correctly rendered');
+ assert.checkDataPath(this.paper.findViewByModel(l3).getConnection().round().serialize(), 'M 102 110 L 150 200 L 320 104', 'A link with the (default) straight connector was correctly rendered');
assert.checkDataPath(this.paper.findViewByModel(l3).getConnection().round(2).serialize(), this.paper.findViewByModel(l0).getConnection().round(2).serialize(), 'A link with the (default) straight connector was rendered same as if it had the normal connector');
var l4 = l0.clone().set('connector', { name: 'straight', args: { cornerType: 'point' }});
this.graph.addCell(l4);
assert.equal(this.graph.getLinks().length, 5, 'A link with the (point) straight connector was successfully added to the graph');
- assert.checkDataPath(this.paper.findViewByModel(l4).getConnection().round(2).serialize(), 'M 102 110 L 150 200 L 320 104', 'A link with the (point) straight connector was correctly rendered');
+ assert.checkDataPath(this.paper.findViewByModel(l4).getConnection().round().serialize(), 'M 102 110 L 150 200 L 320 104', 'A link with the (point) straight connector was correctly rendered');
assert.checkDataPath(this.paper.findViewByModel(l4).getConnection().round(2).serialize(), this.paper.findViewByModel(l0).getConnection().round(2).serialize(), 'A link with the (point) straight connector was rendered same as if it had the normal connector');
var l5 = l0.clone().set('connector', { name: 'straight', args: { cornerType: 'cubic', precision: 0 }});
this.graph.addCell(l5);
assert.equal(this.graph.getLinks().length, 6, 'A link with the (cubic) straight connector was successfully added to the graph');
- assert.checkDataPath(this.paper.findViewByModel(l5).getConnection().round(2).serialize(), 'M 102 110 L 145 191 C 148.33 197 153 198.33 159 195 L 320 104', 'A link with the (cubic) straight connector was correctly rendered');
+ assert.checkDataPath(this.paper.findViewByModel(l5).getConnection().round().serialize(), 'M 102 110 L 145 191 C 148 197 153 198 159 195 L 320 104', 'A link with the (cubic) straight connector was correctly rendered');
assert.checkDataPath(this.paper.findViewByModel(l5).getConnection().round(2).serialize(), this.paper.findViewByModel(l1).getConnection().round(2).serialize(), 'A link with the (cubic) straight connector was rendered same as if it had the rounded connector');
var l6 = l0.clone().set('connector', { name: 'straight', args: { cornerType: 'line' }});
this.graph.addCell(l6);
assert.equal(this.graph.getLinks().length, 7, 'A link with the (line) straight connector was successfully added to the graph');
- assert.checkDataPath(this.paper.findViewByModel(l6).getConnection().round(2).serialize(), 'M 102 110 L 145.3 191.2 L 158.7 195.1 L 320 104', 'A link with the (line) straight connector was correctly rendered');
+ assert.checkDataPath(this.paper.findViewByModel(l6).getConnection().round().serialize(), 'M 102 110 L 145 191 L 159 195 L 320 104', 'A link with the (line) straight connector was correctly rendered');
var l7 = l0.clone().set('connector', { name: 'straight', args: { cornerType: 'gap' }});
this.graph.addCell(l7);
assert.equal(this.graph.getLinks().length, 8, 'A link with the (gap) straight connector was successfully added to the graph');
- assert.checkDataPath(this.paper.findViewByModel(l7).getConnection().round(2).serialize(), 'M 102 110 L 145.3 191.2 M 158.7 195.1 L 320 104', 'A link with the (gap) straight connector was correctly rendered');
+ assert.checkDataPath(this.paper.findViewByModel(l7).getConnection().round().serialize(), 'M 102 110 L 145 191 M 159 195 L 320 104', 'A link with the (gap) straight connector was correctly rendered');
var customCalled = 0;
var l99 = l0.clone().set('connector', function() {
diff --git a/packages/joint-core/test/jointjs/dia/attributes.js b/packages/joint-core/test/jointjs/dia/attributes.js
index 02fdc78b4..e1624ef32 100644
--- a/packages/joint-core/test/jointjs/dia/attributes.js
+++ b/packages/joint-core/test/jointjs/dia/attributes.js
@@ -210,7 +210,7 @@ QUnit.module('Attributes', function() {
paper.on('cell:unhighlight', unhighlightSpy);
paper.options.validateConnection = validateSpy;
- var link = new joint.dia.Link({ width: 100, height: 100 });
+ var link = new joint.shapes.standard.Link();
link.addTo(graph);
var linkView = link.findView(paper);
assert.equal(linkView.sourceMagnet, null);
@@ -252,7 +252,7 @@ QUnit.module('Attributes', function() {
paper.on('cell:unhighlight', unhighlightSpy);
paper.options.validateConnection = validateSpy;
- var link = new joint.dia.Link({ width: 100, height: 100 });
+ var link = new joint.shapes.standard.Link();
link.addTo(graph);
var linkView = link.findView(paper);
assert.equal(linkView.sourceMagnet, null);
@@ -321,7 +321,7 @@ QUnit.module('Attributes', function() {
paper.on('cell:unhighlight', unhighlightSpy);
paper.options.validateConnection = validateSpy;
- var link = new joint.dia.Link({ width: 100, height: 100 });
+ var link = new joint.shapes.standard.Link();
link.addTo(graph);
var linkView = link.findView(paper);
assert.equal(linkView.sourceMagnet, null);
diff --git a/packages/joint-core/test/jointjs/embedding.js b/packages/joint-core/test/jointjs/embedding.js
index 3e9cb611b..fdaede1fc 100644
--- a/packages/joint-core/test/jointjs/embedding.js
+++ b/packages/joint-core/test/jointjs/embedding.js
@@ -162,8 +162,8 @@ QUnit.module('embedding', function(hooks) {
var r1 = new joint.shapes.standard.Rectangle({ position: { x: 100, y: 100 }, size: { width: 100, height: 100 }});
var r2 = new joint.shapes.standard.Rectangle({ position: { x: 500, y: 500 }, size: { width: 100, height: 100 }});
var r3 = new joint.shapes.standard.Rectangle({ position: { x: 600, y: 600 }, size: { width: 100, height: 100 }});
- var l23 = new joint.dia.Link({ source: { id: r2.id }, target: { id: r3.id }});
- var l22 = new joint.dia.Link({ source: { id: r2.id }, target: { id: r2.id }});
+ var l23 = new joint.shapes.standard.Link({ source: { id: r2.id }, target: { id: r3.id }});
+ var l22 = new joint.shapes.standard.Link({ source: { id: r2.id }, target: { id: r2.id }});
this.graph.addCells([r1, r2, r3, l23, l22]);
var v2 = r2.findView(this.paper);
diff --git a/packages/joint-core/test/jointjs/graph.js b/packages/joint-core/test/jointjs/graph.js
index 3c7f49197..e5faac4f8 100644
--- a/packages/joint-core/test/jointjs/graph.js
+++ b/packages/joint-core/test/jointjs/graph.js
@@ -21,15 +21,15 @@ QUnit.module('graph', function(hooks) {
var g = new joint.shapes.standard.Rectangle({ id: 'g' }).addTo(graph); // -> g
new joint.shapes.standard.Rectangle({ id: 'h' }).addTo(graph);
- new joint.dia.Link({ id: 'l1', source: { id: a.id }, target: { id: b.id }}).addTo(graph); // a -> b
- new joint.dia.Link({ id: 'l2', source: { id: a.id }, target: { id: c.id }}).addTo(graph); // a -> c
- new joint.dia.Link({ id: 'l3', source: { id: a.id }, target: { id: d.id }}).addTo(graph); // a -> d
- new joint.dia.Link({ id: 'l4', source: { id: d.id }, target: { id: e.id }}).addTo(graph); // d -> e
- new joint.dia.Link({ id: 'l5', source: { id: e.id }, target: { id: b.id }}).addTo(graph); // e -> b
- new joint.dia.Link({ id: 'l6', source: { id: e.id }, target: { id: a.id }}).addTo(graph); // e -> a
- new joint.dia.Link({ id: 'l7', source: { id: f.id }, target: { x: 50, y: 50 }}).addTo(graph); // f ->
- new joint.dia.Link({ id: 'l8', source: { x: 100, y: 100 }, target: { id: g.id }}).addTo(graph); // -> g
- new joint.dia.Link({ id: 'l9', source: { x: 200, y: 200 }, target: { x: 300, y: 300 }}).addTo(graph); // ->
+ new joint.shapes.standard.Link({ id: 'l1', source: { id: a.id }, target: { id: b.id }}).addTo(graph); // a -> b
+ new joint.shapes.standard.Link({ id: 'l2', source: { id: a.id }, target: { id: c.id }}).addTo(graph); // a -> c
+ new joint.shapes.standard.Link({ id: 'l3', source: { id: a.id }, target: { id: d.id }}).addTo(graph); // a -> d
+ new joint.shapes.standard.Link({ id: 'l4', source: { id: d.id }, target: { id: e.id }}).addTo(graph); // d -> e
+ new joint.shapes.standard.Link({ id: 'l5', source: { id: e.id }, target: { id: b.id }}).addTo(graph); // e -> b
+ new joint.shapes.standard.Link({ id: 'l6', source: { id: e.id }, target: { id: a.id }}).addTo(graph); // e -> a
+ new joint.shapes.standard.Link({ id: 'l7', source: { id: f.id }, target: { x: 50, y: 50 }}).addTo(graph); // f ->
+ new joint.shapes.standard.Link({ id: 'l8', source: { x: 100, y: 100 }, target: { id: g.id }}).addTo(graph); // -> g
+ new joint.shapes.standard.Link({ id: 'l9', source: { x: 200, y: 200 }, target: { x: 300, y: 300 }}).addTo(graph); // ->
// Add hierarchy.
var aa = new joint.shapes.standard.Rectangle({ id: 'aa' }).addTo(graph); // top -> aa; child of a, parent of aaa
@@ -37,11 +37,11 @@ QUnit.module('graph', function(hooks) {
var aaa = new joint.shapes.standard.Rectangle({ id: 'aaa' }).addTo(graph); // top, aa -> aaa -> top; aaa -> aaa (loop); child of a(aa)
aa.embed(aaa);
var top = new joint.shapes.standard.Rectangle({ id: 'top' }).addTo(graph); // aaa -> top -> aaa
- new joint.dia.Link({ id: 'l10', source: { id: top.id }, target: { id: aa.id }}).addTo(graph); // top -> aa
- new joint.dia.Link({ id: 'l11', source: { id: top.id }, target: { id: aaa.id }}).addTo(graph); // top -> aaa
- new joint.dia.Link({ id: 'l12', source: { id: aaa.id }, target: { id: top.id }}).addTo(graph); // aaa -> top
- new joint.dia.Link({ id: 'l13', source: { id: aaa.id }, target: { id: aaa.id }}).addTo(graph); // aaa -> aaa
- new joint.dia.Link({ id: 'l14', source: { id: aa.id }, target: { id: aaa.id }}).addTo(graph); // aa -> aaa
+ new joint.shapes.standard.Link({ id: 'l10', source: { id: top.id }, target: { id: aa.id }}).addTo(graph); // top -> aa
+ new joint.shapes.standard.Link({ id: 'l11', source: { id: top.id }, target: { id: aaa.id }}).addTo(graph); // top -> aaa
+ new joint.shapes.standard.Link({ id: 'l12', source: { id: aaa.id }, target: { id: top.id }}).addTo(graph); // aaa -> top
+ new joint.shapes.standard.Link({ id: 'l13', source: { id: aaa.id }, target: { id: aaa.id }}).addTo(graph); // aaa -> aaa
+ new joint.shapes.standard.Link({ id: 'l14', source: { id: aa.id }, target: { id: aaa.id }}).addTo(graph); // aa -> aaa
};
this.setupTestTreeGraph = function(graph) {
@@ -55,7 +55,7 @@ QUnit.module('graph', function(hooks) {
function ml(id, a, b) {
var source = a.x ? a : { id: a.id };
var target = b.x ? b : { id: b.id };
- return new joint.dia.Link({ id: id, source: source, target: target, name: id }).addTo(graph);
+ return new joint.shapes.standard.Link({ id: id, source: source, target: target, name: id }).addTo(graph);
}
var a = me('a'); var b = me('b'); var c = me('c'); var d = me('d');
@@ -98,7 +98,7 @@ QUnit.module('graph', function(hooks) {
function ml(id, a, b) {
var source = a.x ? a : { id: a.id };
var target = b.x ? b : { id: b.id };
- return new joint.dia.Link({ id: id, source: source, target: target, name: id }).addTo(graph);
+ return new joint.shapes.standard.Link({ id: id, source: source, target: target, name: id }).addTo(graph);
}
var a = me('a');
@@ -451,7 +451,7 @@ QUnit.module('graph', function(hooks) {
var graph = this.graph;
var r1 = new joint.shapes.standard.Rectangle({ id: 'r1' });
var r2 = new joint.shapes.standard.Rectangle({ id: 'r2' });
- var l1 = new joint.dia.Link({ id: 'l1' });
+ var l1 = new joint.shapes.standard.Link({ id: 'l1' });
graph.addCells([r1, r2, l1]);
@@ -647,7 +647,7 @@ QUnit.module('graph', function(hooks) {
new joint.shapes.standard.Rectangle({ id: 'el1' }).addTo(graph);
new joint.shapes.standard.Rectangle({ id: 'el2' }).addTo(graph);
- var l1 = new joint.dia.Link({ id: 'l1', source: { id: 'el1' }, target: { id: 'el2' }}).addTo(graph);
+ var l1 = new joint.shapes.standard.Link({ id: 'l1', source: { id: 'el1' }, target: { id: 'el2' }}).addTo(graph);
var sinks = graph.getSinks();
assert.equal(sinks.length, 1, 'only one sink is in the graph');
@@ -811,7 +811,7 @@ QUnit.module('graph', function(hooks) {
assert.equal(this.graph.getCellsBBox([]), null, 'graph.getBBox([]) with empty array returns null');
- var l = new joint.dia.Link();
+ var l = new joint.shapes.standard.Link();
l.source({ x: 10, y: 20 });
l.target({ x: 110, y: 120 });
this.graph.addCell(l);
@@ -1176,13 +1176,13 @@ QUnit.module('graph', function(hooks) {
size: { width: 40, height: 60 }
});
- var link1 = new joint.dia.Link({
+ var link1 = new joint.shapes.standard.Link({
id: 'link1',
source: { x: 200, y: 200 },
target: { x: 300, y: 300 }
});
- var link2 = new joint.dia.Link({
+ var link2 = new joint.shapes.standard.Link({
id: 'link2',
source: { id: 'rect1' },
target: { id: 'rect2' },
@@ -1199,7 +1199,7 @@ QUnit.module('graph', function(hooks) {
rect1.embed(embeddedElement1);
- var embeddedLink1 = new joint.dia.Link({
+ var embeddedLink1 = new joint.shapes.standard.Link({
id: 'embeddedLink1',
source: { x: 20, y: 20 },
target: { x: 30, y: 30 }
@@ -1286,7 +1286,7 @@ QUnit.module('graph', function(hooks) {
var graph = this.graph;
var el = new joint.shapes.standard.Rectangle({ size: { width: 100, height: 50 }});
- var l = new joint.dia.Link();
+ var l = new joint.shapes.standard.Link();
this.ea = el.clone().set('id', 'a').position(100, 100).addTo(graph);
this.eb = el.clone().set('id', 'b').position(300, 100).addTo(graph);
@@ -1325,7 +1325,7 @@ QUnit.module('graph', function(hooks) {
var graph = this.graph;
var el = new joint.shapes.standard.Rectangle({ size: { width: 100, height: 50 }});
- var l = new joint.dia.Link();
+ var l = new joint.shapes.standard.Link();
this.ea = el.clone().set('id', 'a').position(100, 100).addTo(graph);
this.eb = el.clone().set('id', 'b').position(300, 100).addTo(graph);
diff --git a/packages/joint-core/test/jointjs/linkView.js b/packages/joint-core/test/jointjs/linkView.js
index dd572a7b9..df42a56b2 100644
--- a/packages/joint-core/test/jointjs/linkView.js
+++ b/packages/joint-core/test/jointjs/linkView.js
@@ -17,14 +17,14 @@ QUnit.module('linkView', function(hooks) {
height: 300
});
- link = new joint.dia.Link({
+ link = new joint.shapes.standard.Link({
source: { x: 100, y: 100 },
target: { x: 200, y: 100 }
});
link.addTo(paper.model);
linkView = link.findView(paper);
- link2 = new joint.dia.Link({
+ link2 = new joint.shapes.standard.Link({
source: { x: 100, y: 100 },
target: { x: 100, y: 100 }
});
@@ -750,12 +750,12 @@ QUnit.module('linkView', function(hooks) {
var sourceMagnetAnchorSpy = joint.anchors.test1 = sinon.spy(function() {
return sourceAnchor;
});
- linkView.model.prop('source/magnet', '.connection');
+ linkView.model.prop('source/magnet', 'line');
assert.ok(sourceAnchorSpy.notCalled);
assert.ok(sourceMagnetAnchorSpy.calledWithExactly(
linkView2,
// eslint-disable-next-line no-undef
- linkView2.el.querySelector('.connection'),
+ linkView2.findNode('line'),
sinon.match(function(value) {
return value instanceof SVGElement;
}), // requires resolving
@@ -770,12 +770,12 @@ QUnit.module('linkView', function(hooks) {
var targetMagnetAnchorSpy = joint.anchors.test2 = sinon.spy(function() {
return targetAnchor;
});
- linkView.model.prop('target/magnet', '.connection');
+ linkView.model.prop('target/magnet', 'line');
assert.ok(targetAnchorSpy.notCalled);
assert.ok(targetMagnetAnchorSpy.calledWithExactly(
linkView2,
- linkView2.el.querySelector('.connection'),
+ linkView2.findNode('line'),
sinon.match.instanceOf(g.Point),
sinon.match({ testArg2: true }),
'target',
@@ -1096,28 +1096,12 @@ QUnit.module('linkView', function(hooks) {
QUnit.test('sanity', function(assert) {
- var data;
var strategySpy = paper.options.connectionStrategy = sinon.spy(function(end) {
end.test = true;
});
// Source
- data = {};
- linkView.pointerdown({
- target: linkView.el.querySelector('.marker-arrowhead[end=source]'),
- type: 'mousedown',
- data: data
- }, 0, 0);
- linkView.pointermove({
- target: rv1.el,
- type: 'mousemove',
- data: data
- }, 50, 50);
- linkView.pointerup({
- target: rv1.el,
- type: 'mouseup',
- data: data
- }, 50, 50);
+ simulate.dragLinkView(linkView, 'source', { targetEl: rv1.el, x: 50, y: 50 });
assert.ok(strategySpy.calledOnce);
assert.ok(strategySpy.calledWithExactly(
@@ -1133,22 +1117,7 @@ QUnit.module('linkView', function(hooks) {
assert.equal(linkView.model.attributes.source.test, true);
// Target
- data = {};
- linkView.pointerdown({
- target: linkView.el.querySelector('.marker-arrowhead[end=target]'),
- type: 'mousedown',
- data: data
- }, 0, 0);
- linkView.pointermove({
- target: rv1.el,
- type: 'mousemove',
- data: data
- }, 40, 40);
- linkView.pointerup({
- target: rv1.el,
- type: 'mouseup',
- data: data
- }, 40, 40);
+ simulate.dragLinkView(linkView, 'target', { targetEl: rv1.el, x: 40, y: 40 });
assert.ok(strategySpy.calledTwice);
assert.ok(strategySpy.calledWithExactly(
@@ -1207,11 +1176,7 @@ QUnit.module('linkView', function(hooks) {
r1.translate(10,0);
// Source
data = {};
- linkView.pointerdown({
- target: linkView.el.querySelector('.marker-arrowhead[end=source]'),
- type: 'mousedown',
- data: data
- }, 0, 0);
+ simulate.dragLinkView(linkView, 'source', { data });
// the first move
linkView.pointermove({
target: rv1.el,
@@ -1292,11 +1257,7 @@ QUnit.module('linkView', function(hooks) {
paper.options.snapLinksSelf = { radius: 40 };
// Source
data = {};
- linkView.pointerdown({
- target: linkView.el.querySelector('.marker-arrowhead[end=source]'),
- type: 'mousedown',
- data: data
- }, 0, 0);
+ simulate.dragLinkView(linkView, 'source', { data });
// the move
linkView.pointermove({
target: paper,
diff --git a/packages/joint-core/test/jointjs/links.js b/packages/joint-core/test/jointjs/links.js
index e21be678f..64a6517bb 100644
--- a/packages/joint-core/test/jointjs/links.js
+++ b/packages/joint-core/test/jointjs/links.js
@@ -30,7 +30,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('should return FALSE', function(assert) {
- var link = new joint.dia.Link;
+ var link = new joint.shapes.standard.Link;
assert.notOk(link.isElement());
});
@@ -45,7 +45,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('should return TRUE', function(assert) {
- var link = new joint.dia.Link;
+ var link = new joint.shapes.standard.Link;
assert.ok(link.isLink());
});
@@ -58,24 +58,27 @@ QUnit.module('links', function(hooks) {
this.graph.addCell([r1, r2]);
- var l0 = new joint.dia.Link({
+ var l0 = new joint.shapes.standard.Link({
source: { id: r1.id },
target: { id: r2.id },
- attrs: { '.connection': { stroke: 'black' }}
+ attrs: { line: { stroke: 'black' }}
});
this.graph.addCell(l0);
- assert.strictEqual(l0.constructor, joint.dia.Link, 'link.constructor === joint.dia.Link');
+ assert.strictEqual(l0.constructor, joint.shapes.standard.Link, 'link.constructor === joint.shapes.standard.Link');
var v0 = this.paper.findViewByModel(l0);
- assert.checkDataPath(v0.$('.connection').attr('d'), 'M 140 70 L 320 70', 'link path data starts at the source right-middle point and ends in the target left-middle point');
+ assert.checkDataPath(v0.findNode('line').getAttribute('d'), 'M 140 70 L 320 70', 'link path data starts at the source right-middle point and ends in the target left-middle point');
var l1 = new joint.dia.Link({
+ type: 'test-link',
source: { id: r1.id },
target: { id: r2.id },
- markup: ' '
+ markup: joint.util.svg/*xml*/`
+
+ `
});
assert.ok(_.isUndefined(l1.get('source').x) && _.isUndefined(l1.get('source').y),
@@ -89,9 +92,13 @@ QUnit.module('links', function(hooks) {
assert.ok(v1, 'link with custom markup (1 child) is rendered.');
var l2 = new joint.dia.Link({
+ type: 'test-link',
source: { id: r1.id },
target: { id: r2.id },
- markup: ' '
+ markup: joint.util.svg/*xml*/`
+
+
+ `
});
this.graph.addCell(l2);
var v2 = this.paper.findViewByModel(l2);
@@ -99,7 +106,7 @@ QUnit.module('links', function(hooks) {
assert.ok(v2, 'link with custom markup (2 children) is rendered.');
// It should be possible to create empty links and set source/target later.
- var lEmpty = new joint.dia.Link;
+ var lEmpty = new joint.shapes.standard.Link;
assert.ok(true, 'creating a link with no source/target does not throw an exception');
var rEmpty = new joint.shapes.standard.Rectangle;
var r2Empty = new joint.shapes.standard.Rectangle;
@@ -192,7 +199,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('interaction', function(assert) {
- assert.expect(6);
+ assert.expect(4);
var event;
var r1 = new joint.shapes.standard.Rectangle({ position: { x: 20, y: 30 }, size: { width: 120, height: 80 }});
@@ -204,10 +211,15 @@ QUnit.module('links', function(hooks) {
var vr1 = this.paper.findViewByModel(r1);
var vr3 = this.paper.findViewByModel(r3);
- var l0 = new joint.dia.Link({
+ var l0 = new joint.shapes.standard.Link({
source: { id: r1.id },
target: { id: r2.id },
- attrs: { '.connection': { stroke: 'black' }},
+ attrs: {
+ line: {
+ stroke: 'black',
+ }
+ },
+ vertices: [{ x: 300, y: 100 }],
labels: [
{ position: .5, attrs: { text: { text: 'test label' }}}
]
@@ -216,30 +228,11 @@ QUnit.module('links', function(hooks) {
this.graph.addCell(l0);
var v0 = this.paper.findViewByModel(l0);
-
this.paper.options.validateConnection = function(vs, ms, vt, mt, v) {
assert.ok(vs === vr1 && vt === vr3, 'connection validation executed');
return vt instanceof joint.dia.ElementView;
};
- // adding vertices
- event = { target: v0.el.querySelector('.connection') };
- v0.pointerdown(event, 200, 70);
- v0.pointerup(event);
- assert.deepEqual(l0.get('vertices'), [{ x: 200, y: 70 }], 'vertex added after click the connection.');
-
- var firstVertexRemoveArea = v0.el.querySelector('.marker-vertex-remove-area');
-
- event = { target: v0.el.querySelector('.connection') };
- v0.pointerdown(event, 300, 70);
- v0.pointermove(event, 300, 100);
- v0.pointerup(event);
- assert.deepEqual(l0.get('vertices'), [{ x: 200, y: 70 }, { x: 300, y: 100 }], 'vertex added and translated after click the connection wrapper and mousemove.');
-
- event = { target: firstVertexRemoveArea };
- v0.pointerdown(event);
- v0.pointerup(event);
-
// arrowheadmove
var highlighted = false;
@@ -258,8 +251,9 @@ QUnit.module('links', function(hooks) {
}
});
- event = { target: v0.el.querySelector('.marker-arrowhead[end="target"]') };
- v0.pointerdown(event);
+ var data = {};
+ event = { data };
+ simulate.dragLinkView(v0, 'target', { data });
event.target = vr3.el;
event.type = 'mousemove';
v0.pointermove(event, 630, 40);
@@ -270,29 +264,29 @@ QUnit.module('links', function(hooks) {
assert.notOk(highlighted, 'after moving the pointer to coordinates 400, 400 the rectangle is not highlighted anymore');
v0.pointerup(event);
- assert.checkDataPath(v0.el.querySelector('.connection').getAttribute('d'), 'M 140 78 L 300 100 L 400 400', 'link path data starts at the source right-middle point, going through the vertex and ends at the coordinates 400, 400');
+ assert.checkDataPath(v0.getConnection().round().serialize(), 'M 140 78 L 300 100 L 400 400', 'link path data starts at the source right-middle point, going through the vertex and ends at the coordinates 400, 400');
});
QUnit.test('defaultLink', function(assert) {
assert.expect(10);
- this.paper.options.defaultLink = new joint.dia.Link();
+ this.paper.options.defaultLink = new joint.shapes.standard.DoubleLink();
var link = this.paper.getDefaultLink();
- assert.ok(link instanceof joint.dia.Link, 'sanity: defaultLink is cloned');
+ assert.ok(link instanceof joint.shapes.standard.DoubleLink, 'sanity: defaultLink is cloned');
this.paper.options.defaultLink = function(v, m) {
- return new joint.dia.Link();
+ return new joint.shapes.standard.DoubleLink();
};
link = this.paper.getDefaultLink();
- assert.ok(link instanceof joint.dia.Link, 'sanity: defaultLink is a function');
+ assert.ok(link instanceof joint.shapes.standard.DoubleLink, 'sanity: defaultLink is a function');
- var MyLink = joint.dia.Link.extend({
+ var MyLink = joint.shapes.standard.Link.extend({
isMyLink: true
});
@@ -305,7 +299,7 @@ QUnit.module('links', function(hooks) {
this.graph.addCell(model);
var view = this.paper.findViewByModel(model);
- var rect = view.$('rect')[0];
+ var rect = view.findNode('body');
this.graph.on('add', function(cell) {
@@ -345,7 +339,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('source', function(assert) {
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { x: 40, y: 40 },
target: { x: 100, y: 100 }
});
@@ -377,7 +371,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('target', function(assert) {
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { x: 40, y: 40 },
target: { x: 100, y: 100 }
});
@@ -421,11 +415,11 @@ QUnit.module('links', function(hooks) {
myrect2.translate(300);
this.graph.addCell(myrect2);
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { id: myrect.id },
target: { id: myrect2.id },
- attrs: { '.connection': { stroke: 'black' }}
+ attrs: { link: { stroke: 'black' }}
});
this.graph.addCell(link);
@@ -438,20 +432,20 @@ QUnit.module('links', function(hooks) {
assert.notOk(link.get('source').id, 'source of the link became a point');
assert.ok(link.get('target').id, 'target of the link is still not a point');
- assert.checkDataPath(linkView.$('.connection').attr('d'), 'M 140 70 L 320 70', 'link path data stayed the same after disconnection');
- assert.checkDataPath(linkView.$('.connection-wrap').attr('d'), 'M 140 70 L 320 70', 'link connection-wrap path data is the same as the .connection path data');
+ assert.checkDataPath(linkView.findNode('line').getAttribute('d'), 'M 140 70 L 320 70', 'link path data stayed the same after disconnection');
+ assert.checkDataPath(linkView.findNode('wrapper').getAttribute('d'), 'M 140 70 L 320 70', 'link connection-wrap path data is the same as the .connection path data');
myrect.translate(-10);
- assert.checkDataPath(linkView.$('.connection').attr('d'), 'M 140 70 L 320 70', 'link path data stayed the same after the disconnected source moved');
+ assert.checkDataPath(linkView.findNode('line').getAttribute('d'), 'M 140 70 L 320 70', 'link path data stayed the same after the disconnected source moved');
link.set('source', { id: myrect.id });
- assert.checkDataPath(linkView.$('.connection').attr('d'), 'M 130 70 L 320 70', 'link path data updated after the disconnected source became re-connected again');
+ assert.checkDataPath(linkView.findNode('line').getAttribute('d'), 'M 130 70 L 320 70', 'link path data updated after the disconnected source became re-connected again');
myrect.translate(10);
- assert.checkDataPath(linkView.$('.connection').attr('d'), 'M 140 70 L 320 70', 'link path data updated after the just connected source moved');
+ assert.checkDataPath(linkView.findNode('line').getAttribute('d'), 'M 140 70 L 320 70', 'link path data updated after the just connected source moved');
// disconnect:
link.set('target', linkView.targetPoint.toJSON());
@@ -478,7 +472,7 @@ QUnit.module('links', function(hooks) {
this.graph.addCell(myrect);
this.graph.addCell(myrect2);
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { id: myrect.id },
target: { id: myrect2.id }
});
@@ -502,13 +496,13 @@ QUnit.module('links', function(hooks) {
var myrect = new joint.shapes.standard.Rectangle;
this.graph.addCell(myrect);
- var link = new joint.dia.Link({ source: { id: myrect.id }, target: { id: myrect.id }});
+ var link = new joint.shapes.standard.Link({ source: { id: myrect.id }, target: { id: myrect.id }});
this.graph.addCell(link);
assert.equal(link.hasLoop(), true, 'link has a loop');
var myrect2 = new joint.shapes.standard.Rectangle;
this.graph.addCell(myrect2);
- var link2 = new joint.dia.Link({ source: { id: myrect2.id }, target: { x: 20, y: 20 }});
+ var link2 = new joint.shapes.standard.Link({ source: { id: myrect2.id }, target: { x: 20, y: 20 }});
this.graph.addCell(link2);
assert.equal(link2.hasLoop(), false, 'link pinned to the paper does not have a loop');
assert.equal(link2.hasLoop({ deep: true }), false, 'link pinned to the paper does not have a loop with deep = true');
@@ -517,7 +511,7 @@ QUnit.module('links', function(hooks) {
var myrect3a = new joint.shapes.standard.Rectangle;
myrect3.embed(myrect3a);
this.graph.addCells([myrect3, myrect3a]);
- var link3 = new joint.dia.Link({ source: { id: myrect3.id }, target: { id: myrect3a.id }});
+ var link3 = new joint.shapes.standard.Link({ source: { id: myrect3.id }, target: { id: myrect3a.id }});
this.graph.addCell(link3);
assert.equal(link3.hasLoop(), false, 'link targetting an embedded element does not have a loop with deep = false');
assert.equal(link3.hasLoop({ deep: true }), true, 'link targetting an embedded element does have a loop with deep = true');
@@ -525,200 +519,76 @@ QUnit.module('links', function(hooks) {
QUnit.test('markers', function(assert) {
- var myrect = new joint.shapes.standard.Rectangle({
+ const myrect1 = new joint.shapes.standard.Rectangle({
position: { x: 20, y: 30 },
size: { width: 120, height: 80 },
attrs: { text: { text: 'my rectangle' }}
});
- var myrect2 = myrect.clone();
- myrect2.translate(300);
-
- this.graph.addCell(myrect);
- this.graph.addCell(myrect2);
-
- var link = new joint.dia.Link({
-
- source: { id: myrect.id },
- target: { id: myrect2.id },
- attrs: {
- '.connection': {
- stroke: 'black'
- },
- '.marker-source': {
- d: 'M 10 0 L 0 5 L 10 10 z'
- },
- '.marker-target': {
- d: 'M 10 0 L 0 5 L 10 10 z'
- }
- }
- });
-
- this.graph.addCell(link);
-
- var linkView = this.paper.findViewByModel(link);
-
- var markerSourceBbox = V(linkView.$('.marker-source')[0]).bbox();
-
- assert.deepEqual(
- { x: markerSourceBbox.x, y: markerSourceBbox.y, width: markerSourceBbox.width, height: markerSourceBbox.height },
- { x: 140, y: 65, width: 10, height: 10 },
- '.marker-source should point to the left edge of the rectangle'
- );
-
- var markerTargetBbox = V(linkView.$('.marker-target')[0]).bbox();
- assert.deepEqual(
- { x: markerTargetBbox.x, y: markerTargetBbox.y, width: markerTargetBbox.width, height: markerTargetBbox.height, rotation: V(linkView.$('.marker-target')[0]).rotate().angle },
- { x: 310, y: 65, width: 10, height: 10, rotation: -180 },
- '.marker-target should point to the right edge of the rectangle 2 and should be rotated by -180 degrees'
- );
- });
-
- QUnit.test('vertices', function(assert) {
-
- var myrect = new joint.shapes.standard.Rectangle({
- position: { x: 20, y: 30 },
- size: { width: 120, height: 80 },
- attrs: { text: { text: 'my rectangle' }}
- });
- var myrect2 = myrect.clone();
+ const myrect2 = myrect1.clone();
myrect2.translate(300);
- this.graph.addCell(myrect);
- this.graph.addCell(myrect2);
-
- var link = new joint.dia.Link({
-
- source: { id: myrect.id },
+ const link = new joint.shapes.standard.Link({
+ source: { id: myrect1.id },
target: { id: myrect2.id },
- vertices: [{ x: 80, y: 150 }, { x: 380, y: 150 }],
attrs: {
- '.connection': {
- stroke: 'black'
- },
- '.marker-source': {
- d: 'M 10 0 L 0 5 L 10 10 z'
- },
- '.marker-target': {
- d: 'M 10 0 L 0 5 L 10 10 z'
+ line: {
+ sourceMarker: {
+ d: 'M 10 0 L 0 5 L 10 10 z',
+ testSourceMarker: true
+ },
+ targetMarker: {
+ d: 'M 10 0 L 0 5 L 10 10 z',
+ testTargetMarker: true
+ },
+ vertexMarker: {
+ d: 'M 10 0 L 0 5 L 10 10 z',
+ testMidMarker: true
+ }
}
}
});
+ this.graph.addCell(myrect1);
+ this.graph.addCell(myrect2);
this.graph.addCell(link);
- var linkView = this.paper.findViewByModel(link);
+ const linkView = this.paper.findViewByModel(link);
- var markerSourceBbox = V(linkView.$('.marker-source')[0]).bbox();
+ assert.ok(linkView.findNode('line').getAttribute('marker-start'));
+ assert.ok(linkView.findNode('line').getAttribute('marker-end'));
+ assert.ok(linkView.findNode('line').getAttribute('marker-mid'));
- assert.deepEqual(
- {
- x: markerSourceBbox.x,
- y: markerSourceBbox.y,
- width: markerSourceBbox.width,
- height: markerSourceBbox.height,
- rotation: g.normalizeAngle(V(linkView.$('.marker-source')[0]).rotate().angle)
- },
- {
- x: 75,
- y: 110,
- width: 10,
- height: 10,
- rotation: g.normalizeAngle(-270)
- },
- '.marker-source should point to the bottom edge of the rectangle and should be rotated by -270 degrees'
- );
-
- var markerTargetBbox = V(linkView.$('.marker-target')[0]).bbox();
-
- assert.deepEqual(
- {
- x: markerTargetBbox.x,
- y: markerTargetBbox.y,
- width: markerTargetBbox.width,
- height: markerTargetBbox.height,
- rotation: g.normalizeAngle(V(linkView.$('.marker-target')[0]).rotate().angle)
- },
- {
- x: 375,
- y: 110,
- width: 10,
- height: 10,
- rotation: g.normalizeAngle(-270)
- },
- '.marker-target should point to the bottom edge of the rectangle 2 and should be rotated by -270 degrees'
- );
-
- assert.equal($('.marker-vertex').length, 2, 'there is exactly 2 vertex markers on the page');
-
- var firstVertextPosition = g.rect(V($('.marker-vertex')[0]).bbox()).center();
- assert.deepEqual(
- { x: firstVertextPosition.x, y: firstVertextPosition.y },
- link.get('vertices')[0],
- 'first vertex is in the same position as defined in the vertices array'
- );
-
- var secondVertextPosition = g.rect(V($('.marker-vertex')[1]).bbox()).center();
- assert.deepEqual(
- { x: secondVertextPosition.x, y: secondVertextPosition.y },
- link.get('vertices')[1],
- 'second vertex is in the same position as defined in the vertices array'
- );
+ assert.ok(this.paper.defs.contains(this.paper.el.querySelector('[test-source-marker]')));
+ assert.ok(this.paper.defs.contains(this.paper.el.querySelector('[test-target-marker]')));
+ assert.ok(this.paper.defs.contains(this.paper.el.querySelector('[test-mid-marker]')));
});
QUnit.test('perpendicular links', function(assert) {
this.paper.options.defaultAnchor = { name: 'perpendicular' };
- var myrect = new joint.shapes.standard.Rectangle({
+ const myrect1 = new joint.shapes.standard.Rectangle({
position: { x: 20, y: 30 },
size: { width: 120, height: 80 },
attrs: { text: { text: 'my rectangle' }}
});
- var myrect2 = myrect.clone();
+ const myrect2 = myrect1.clone();
myrect2.translate(300);
- this.graph.addCell(myrect);
- this.graph.addCell(myrect2);
-
- var link = new joint.dia.Link({
-
- source: { id: myrect.id },
+ const link = new joint.shapes.standard.Link({
+ source: { id: myrect1.id },
target: { id: myrect2.id },
vertices: [{ x: 138, y: 150 }, { x: 180, y: 108 }],
- attrs: {
- '.connection': {
- stroke: 'black'
- },
- '.marker-source': {
- d: 'M 0 0 L 0 0 z'
- },
- '.marker-target': {
- d: 'M 0 0 L 0 0 z'
- }
- }
});
+ this.graph.addCell(myrect1);
+ this.graph.addCell(myrect2);
this.graph.addCell(link);
- var linkView = this.paper.findViewByModel(link);
-
- var markerSourceBbox = V(linkView.$('.marker-source')[0]).bbox();
-
- assert.deepEqual(
- { x: markerSourceBbox.x, y: markerSourceBbox.y },
- { x: 138, y: 110 },
- '.marker-source should point vertically to the edge of the source rectangle making the part of the link before the first vertex perpendicular to the source rectangle'
- );
-
- var markerTargetBbox = V(linkView.$('.marker-target')[0]).bbox();
-
- assert.deepEqual(
- { x: markerTargetBbox.x, y: markerTargetBbox.y },
- { x: myrect2.get('position').x, y: 108 },
- '.marker-target should point horizontally to the edge of the target rectangle making the part of the link after the last vertex perpendicular to the target rectangle'
- );
-
+ const linkView = this.paper.findViewByModel(link);
+ assert.equal(linkView.sourcePoint.toString(), '138@110');
+ assert.equal(linkView.targetPoint.toString(), '320@108');
});
QUnit.module('Labels', function(assert) {
@@ -732,7 +602,7 @@ QUnit.module('links', function(hooks) {
this.graph.addCell(myrect);
this.graph.addCell(myrect2);
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { id: myrect.id },
target: { id: myrect2.id },
@@ -1262,7 +1132,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('change:labels', function(assert) {
- var l = new joint.dia.Link({
+ var l = new joint.shapes.standard.Link({
source: { x: 0, y: 0 },
target: { x: 100, y: 100 }
}).addTo(this.graph);
@@ -1347,7 +1217,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('change:labels + change:source', function(assert) {
var graph = this.graph;
var paper = this.paper;
- var l = new joint.dia.Link({
+ var l = new joint.shapes.standard.Link({
source: { x: 0, y: 0 },
target: { x: 100, y: 100 }
}).addTo(graph);
@@ -1401,7 +1271,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('snap links', function(assert) {
var event;
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { x: 0, y: 0 },
target: { x: 0, y: 0 }
});
@@ -1413,17 +1283,11 @@ QUnit.module('links', function(hooks) {
this.graph.addCells([myrect, link]);
var v = this.paper.findViewByModel(link);
- var t = v.el.querySelector('.marker-arrowhead[end=target]');
// link target was out of the radius and therefore was not snapped to the element
this.paper.options.snapLinks = { radius: 5 };
-
- event = { target: t };
- v.pointerdown(event, 0, 0);
- event.target = this.paper.el;
- v.pointermove(event, 90, 90);
- v.pointerup(event, 90, 90);
+ simulate.dragLinkView(v, 'target', { targetEl: this.paper.el, x: 90, y: 90 });
assert.deepEqual(link.get('target'), {
x: 90, y: 90
@@ -1432,12 +1296,7 @@ QUnit.module('links', function(hooks) {
// link target was snapped to the element
this.paper.options.snapLinks = { radius: 50 };
-
- event = { target: t };
- v.pointerdown(event, 0, 0);
- event.target = this.paper.el;
- v.pointermove(event, 90, 90);
- v.pointerup(event, 90, 90);
+ simulate.dragLinkView(v, 'target', { targetEl: this.paper.el, x: 90, y: 90 });
assert.ok(link.get('target').id === myrect.id, 'link target was snapped to the element');
@@ -1446,28 +1305,18 @@ QUnit.module('links', function(hooks) {
// getBoundingClientRect returns negative values for top and left when paper not visible
this.paper.options.snapLinks = { radius: Number.MAX_VALUE };
- myrect.attr('.', { magnet: false });
- myrect.attr('text', { magnet: true, port: 'port' });
+ myrect.attr('root', { magnet: false });
+ myrect.attr('label', { magnet: true, port: 'port' });
this.paper.options.validateConnection = function() { return true; };
-
- event = { target: t };
- v.pointerdown(event, 0, 0);
- event.target = this.paper.el;
- v.pointermove(event, 90, 90);
- v.pointerup(event, 90, 90);
+ simulate.dragLinkView(v, 'target', { targetEl: this.paper.el, x: 90, y: 90 });
assert.ok(link.get('target').port === 'port', 'link target was snapped to the port');
// the validation is taken into account when snapping to port
this.paper.options.validateConnection = function() { return false; };
-
- event = { target: t };
- v.pointerdown(event, 0, 0);
- event.target = this.paper.el;
- v.pointermove(event, 90, 90);
- v.pointerup(event, 90, 90);
+ simulate.dragLinkView(v, 'target', { targetEl: this.paper.el, x: 90, y: 90 });
assert.deepEqual(link.get('target'), {
x: 90, y: 90
@@ -1477,7 +1326,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('mark available', function(assert) {
var event;
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { x: 0, y: 0 },
target: { x: 0, y: 0 }
});
@@ -1498,12 +1347,12 @@ QUnit.module('links', function(hooks) {
this.graph.addCells([myrect1, myrect2, link]);
var v = this.paper.findViewByModel(link);
- var t = v.el.querySelector('.marker-arrowhead[end=target]');
this.paper.options.markAvailable = true;
- event = { target: t };
- v.pointerdown(event, 0, 0);
+ var data = {};
+ event = { data };
+ simulate.dragLinkView(v, 'target', { data });
var availableMagnets = this.paper.el.querySelectorAll('.available-magnet');
var availableCells = this.paper.el.querySelectorAll('.available-cell');
@@ -1531,13 +1380,13 @@ QUnit.module('links', function(hooks) {
assert.ok(vertices.length > 0, 'Default router was used for the model with no router defined.');
};
- var linkDefaultRouter = new joint.dia.Link({
+ var linkDefaultRouter = new joint.shapes.standard.Link({
source: { x: 0, y: 0 },
target: { x: 0, y: 0 },
vertices: [{ x: 50, y: 50 }]
});
- var linkOwnRouter = new joint.dia.Link({
+ var linkOwnRouter = new joint.shapes.standard.Link({
source: { x: 0, y: 0 },
target: { x: 0, y: 0 },
router: { name: 'orthogonal' },
@@ -1556,13 +1405,13 @@ QUnit.module('links', function(hooks) {
return 'M 0 0';
};
- var linkDefaultConnector = new joint.dia.Link({
+ var linkDefaultConnector = new joint.shapes.standard.Link({
source: { x: 0, y: 0 },
target: { x: 0, y: 0 },
vertices: [{ x: 50, y: 50 }]
});
- var linkOwnConnector = new joint.dia.Link({
+ var linkOwnConnector = new joint.shapes.standard.Link({
source: { x: 0, y: 0 },
target: { x: 0, y: 0 },
connector: { name: 'normal' },
@@ -1574,7 +1423,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('getSourceCell', function(assert) {
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { x: 40, y: 40 },
target: { x: 100, y: 100 }
});
@@ -1602,7 +1451,7 @@ QUnit.module('links', function(hooks) {
assert.ok(source && source instanceof joint.dia.Element && source.id === element.id, 'with source element');
- var linkNotInGraph = new joint.dia.Link({
+ var linkNotInGraph = new joint.shapes.standard.Link({
source: { id: element.get('id') },
target: { id: element.get('id') }
});
@@ -1642,7 +1491,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('getTargetCell', function(assert) {
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { x: 40, y: 40 },
target: { x: 100, y: 100 }
});
@@ -1670,7 +1519,7 @@ QUnit.module('links', function(hooks) {
assert.ok(target && target instanceof joint.dia.Element && target.id === element.id, 'with target element');
- var linkNotInGraph = new joint.dia.Link({
+ var linkNotInGraph = new joint.shapes.standard.Link({
source: { id: element.get('id') },
target: { id: element.get('id') }
});
@@ -1714,7 +1563,7 @@ QUnit.module('links', function(hooks) {
var a = new joint.shapes.standard.Rectangle({ id: 'a' });
var b = new joint.shapes.standard.Rectangle({ id: 'b' });
var c = new joint.shapes.standard.Rectangle({ id: 'c' });
- var l = new joint.dia.Link({ id: 'l' });
+ var l = new joint.shapes.standard.Link({ id: 'l' });
this.graph.addCells([a, b, c, l]);
@@ -1741,7 +1590,7 @@ QUnit.module('links', function(hooks) {
var a = new joint.shapes.standard.Rectangle({ id: 'a' });
var b = new joint.shapes.standard.Rectangle({ id: 'b' });
var c = new joint.shapes.standard.Rectangle({ id: 'c' });
- var l = new joint.dia.Link({ id: 'l' });
+ var l = new joint.shapes.standard.Link({ id: 'l' });
this.graph.addCells([a, b, c, l]);
@@ -1765,8 +1614,8 @@ QUnit.module('links', function(hooks) {
var a = new joint.shapes.standard.Rectangle({ id: 'a' });
var b = new joint.shapes.standard.Rectangle({ id: 'b' });
var c = new joint.shapes.standard.Rectangle({ id: 'c' });
- var l = new joint.dia.Link({ id: 'l' });
- var l2 = new joint.dia.Link({ id: 'l2' });
+ var l = new joint.shapes.standard.Link({ id: 'l' });
+ var l2 = new joint.shapes.standard.Link({ id: 'l2' });
this.graph.addCells([a, b, c, l, l2]);
var lv = l.findView(this.paper);
@@ -2050,14 +1899,14 @@ QUnit.module('links', function(hooks) {
QUnit.module('label', function() {
QUnit.test('getter', function(assert) {
- var link = new joint.dia.Link({ labels: [{ position: { distance: 10, offset: 10 }}, { position: { distance: 20, offset: 20 }}] });
+ var link = new joint.shapes.standard.Link({ labels: [{ position: { distance: 10, offset: 10 }}, { position: { distance: 20, offset: 20 }}] });
assert.deepEqual(link.label(0), { position: { distance: 10, offset: 10 }});
assert.deepEqual(link.label(1), { position: { distance: 20, offset: 20 }});
assert.deepEqual(link.label(2), undefined);
});
QUnit.test('setter', function(assert) {
- var link = new joint.dia.Link({ labels: [{ position: { distance: 10, offset: 10 }}, { position: { distance: 20, offset: 20 }}] });
+ var link = new joint.shapes.standard.Link({ labels: [{ position: { distance: 10, offset: 10 }}, { position: { distance: 20, offset: 20 }}] });
link.label(0, { position: { distance: 100, offset: 100 }});
link.label(1, { position: { distance: 200 }});
link.label(2, { position: { distance: 30, offset: 30 }});
@@ -2068,7 +1917,7 @@ QUnit.module('links', function(hooks) {
QUnit.module('labels', function() {
QUnit.test('getter', function(assert) {
- var link = new joint.dia.Link();
+ var link = new joint.shapes.standard.Link();
assert.deepEqual(link.labels(), []);
link.set('labels', [{ position: { distance: 10, offset: 10 }}]);
assert.notEqual(link.labels(), link.get('labels'), 'Copy');
@@ -2076,7 +1925,7 @@ QUnit.module('links', function(hooks) {
});
QUnit.test('setter', function(assert) {
- var link = new joint.dia.Link({ labels: [{ position: { distance: 10, offset: 10 }}, { position: { distance: 20, offset: 20 }}] });
+ var link = new joint.shapes.standard.Link({ labels: [{ position: { distance: 10, offset: 10 }}, { position: { distance: 20, offset: 20 }}] });
link.labels([{ position: { distance: 30, offset: 30 }}]);
assert.deepEqual(link.get('labels'), [{ position: { distance: 30, offset: 30 }}]);
});
@@ -2085,7 +1934,7 @@ QUnit.module('links', function(hooks) {
QUnit.module('insertLabel', function() {
QUnit.test('sanity', function(assert) {
- var link = new joint.dia.Link();
+ var link = new joint.shapes.standard.Link();
var error;
try {
@@ -2105,7 +1954,7 @@ QUnit.module('links', function(hooks) {
QUnit.module('appendLabel', function() {
QUnit.test('sanity', function(assert) {
- var link = new joint.dia.Link();
+ var link = new joint.shapes.standard.Link();
var error;
try {
@@ -2123,7 +1972,7 @@ QUnit.module('links', function(hooks) {
QUnit.module('removeLabel', function() {
QUnit.test('sanity', function(assert) {
- var link = new joint.dia.Link({ labels: [{ position: { distance: 10, offset: 10 }}, { position: { distance: 20, offset: 20 }}, { position: { distance: 30, offset: 30 }}, { position: { distance: 40, offset: 40 }}] });
+ var link = new joint.shapes.standard.Link({ labels: [{ position: { distance: 10, offset: 10 }}, { position: { distance: 20, offset: 20 }}, { position: { distance: 30, offset: 30 }}, { position: { distance: 40, offset: 40 }}] });
link.removeLabel(100);
assert.deepEqual(link.labels(), [{ position: { distance: 10, offset: 10 }}, { position: { distance: 20, offset: 20 }}, { position: { distance: 30, offset: 30 }}, { position: { distance: 40, offset: 40 }}]);
link.removeLabel(-1);
@@ -2139,13 +1988,13 @@ QUnit.module('links', function(hooks) {
QUnit.module('vertex', function() {
QUnit.test('getter', function(assert) {
- var link = new joint.dia.Link();
+ var link = new joint.shapes.standard.Link();
link.vertices([{ x: 0, y: 0 }, { x: 1, y: 1 }]);
assert.deepEqual(link.vertex(0), { x: 0, y: 0 });
assert.deepEqual(link.vertex(1), { x: 1, y: 1 });
assert.deepEqual(link.vertex(2), undefined);
- var link2 = new joint.dia.Link();
+ var link2 = new joint.shapes.standard.Link();
link2.vertices([new g.Point(0, 0), new g.Point(1, 1)]);
assert.deepEqual(link2.vertex(0), { x: 0, y: 0 });
assert.deepEqual(link2.vertex(1), { x: 1, y: 1 });
@@ -2153,7 +2002,7 @@ QUnit.module('links', function(hooks) {
});
QUnit.test('setter', function(assert) {
- var link = new joint.dia.Link();
+ var link = new joint.shapes.standard.Link();
link.vertices([{ x: 0, y: 0 }, { x: 1, y: 1 }]);
link.vertex(0, { x: 10, y: 10 });
link.vertex(1, { x: 20 });
@@ -2161,7 +2010,7 @@ QUnit.module('links', function(hooks) {
assert.deepEqual(link.get('vertices'), [{ x: 10, y: 10 }, { x: 20, y: 1 }, { x: 3, y: 3 }]);
assert.deepEqual(link.vertices(), [{ x: 10, y: 10 }, { x: 20, y: 1 }, { x: 3, y: 3 }]);
- var link2 = new joint.dia.Link();
+ var link2 = new joint.shapes.standard.Link();
link2.vertices([new g.Point(0, 0), new g.Point(1, 1)]);
link2.vertex(0, { x: 10, y: 10 });
link2.vertex(1, { x: 20 });
@@ -2174,18 +2023,18 @@ QUnit.module('links', function(hooks) {
QUnit.module('vertices', function() {
QUnit.test('getter', function(assert) {
- var link = new joint.dia.Link();
+ var link = new joint.shapes.standard.Link();
assert.deepEqual(link.get('vertices'), undefined);
assert.deepEqual(link.vertices(), []);
- var link2 = new joint.dia.Link();
+ var link2 = new joint.shapes.standard.Link();
link2.vertices([{ x: 0, y: 0 }]);
assert.deepEqual(link2.get('vertices'), [{ x: 0, y: 0 }]);
assert.deepEqual(link2.vertices(), [{ x: 0, y: 0 }]);
});
QUnit.test('setter', function(assert) {
- var link = new joint.dia.Link();
+ var link = new joint.shapes.standard.Link();
link.vertices([{ x: 0, y: 0 }, { x: 1, y: 1 }]);
assert.deepEqual(link.get('vertices'), [{ x: 0, y: 0 }, { x: 1, y: 1 }]);
assert.deepEqual(link.vertices(), [{ x: 0, y: 0 }, { x: 1, y: 1 }]);
@@ -2193,7 +2042,7 @@ QUnit.module('links', function(hooks) {
assert.deepEqual(link.get('vertices'), [{ x: 3, y: 3 }]);
assert.deepEqual(link.vertices(), [{ x: 3, y: 3 }]);
- var link2 = new joint.dia.Link();
+ var link2 = new joint.shapes.standard.Link();
link2.vertices([new g.Point(0, 0), new g.Point(1, 1)]);
assert.deepEqual(link2.get('vertices'), [{ x: 0, y: 0 }, { x: 1, y: 1 }]);
assert.deepEqual(link2.vertices(), [{ x: 0, y: 0 }, { x: 1, y: 1 }]);
@@ -2208,7 +2057,7 @@ QUnit.module('links', function(hooks) {
QUnit.test('sanity', function(assert) {
var error;
- var link = new joint.dia.Link();
+ var link = new joint.shapes.standard.Link();
error = null;
try {
link.insertVertex(0);
@@ -2223,7 +2072,7 @@ QUnit.module('links', function(hooks) {
assert.deepEqual(link.get('vertices'), [{ x: 0, y: 0 }, { x: 1, y: 1 }, { x: 2, y: 2 }]);
assert.deepEqual(link.vertices(), [{ x: 0, y: 0 }, { x: 1, y: 1 }, { x: 2, y: 2 }]);
- var link2 = new joint.dia.Link();
+ var link2 = new joint.shapes.standard.Link();
error = null;
try {
link2.insertVertex(0);
@@ -2243,7 +2092,7 @@ QUnit.module('links', function(hooks) {
QUnit.module('removeVertex', function() {
QUnit.test('sanity', function(assert) {
- var link = new joint.dia.Link();
+ var link = new joint.shapes.standard.Link();
link.vertices([{ x: 0, y: 0 }, { x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 3 }]);
link.removeVertex(100);
assert.deepEqual(link.get('vertices'), [{ x: 0, y: 0 }, { x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 3 }]);
@@ -2255,7 +2104,7 @@ QUnit.module('links', function(hooks) {
assert.deepEqual(link.get('vertices'), [{ x: 1, y: 1 }, { x: 2, y: 2 }]);
assert.deepEqual(link.vertices(), [{ x: 1, y: 1 }, { x: 2, y: 2 }]);
- var link2 = new joint.dia.Link();
+ var link2 = new joint.shapes.standard.Link();
link2.vertices([{ x: 0, y: 0 }, { x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 3 }]);
link2.removeVertex(100);
assert.deepEqual(link2.get('vertices'), [{ x: 0, y: 0 }, { x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 3 }]);
diff --git a/packages/joint-core/test/jointjs/paper.js b/packages/joint-core/test/jointjs/paper.js
index 8b4f24187..290227934 100644
--- a/packages/joint-core/test/jointjs/paper.js
+++ b/packages/joint-core/test/jointjs/paper.js
@@ -185,7 +185,7 @@ QUnit.module('paper', function(hooks) {
this.paper.options.sorting = joint.dia.Paper.sorting.EXACT;
- var json = JSON.parse('{"cells":[{"type":"standard.Ellipse","size":{"width":100,"height":60},"position":{"x":110,"y":480},"id":"bbb9e641-9756-4f42-997a-f4818b89f374","embeds":"","z":0},{"type":"link","source":{"id":"bbb9e641-9756-4f42-997a-f4818b89f374"},"target":{"id":"cbd1109e-4d34-4023-91b0-f31bce1318e6"},"id":"b4289c08-07ea-49d2-8dde-e67eb2f2a06a","z":1},{"type":"standard.Rectangle","position":{"x":420,"y":410},"size":{"width":100,"height":60},"id":"cbd1109e-4d34-4023-91b0-f31bce1318e6","embeds":"","z":2}]}');
+ var json = JSON.parse('{"cells":[{"type":"standard.Ellipse","size":{"width":100,"height":60},"position":{"x":110,"y":480},"id":"bbb9e641-9756-4f42-997a-f4818b89f374","embeds":"","z":0},{"type":"standard.Link","source":{"id":"bbb9e641-9756-4f42-997a-f4818b89f374"},"target":{"id":"cbd1109e-4d34-4023-91b0-f31bce1318e6"},"id":"b4289c08-07ea-49d2-8dde-e67eb2f2a06a","z":1},{"type":"standard.Rectangle","position":{"x":420,"y":410},"size":{"width":100,"height":60},"id":"cbd1109e-4d34-4023-91b0-f31bce1318e6","embeds":"","z":2}]}');
this.graph.fromJSON(json);
@@ -317,7 +317,7 @@ QUnit.module('paper', function(hooks) {
var customElementView = joint.dia.ElementView.extend({ custom: true });
var customLinkView = joint.dia.LinkView.extend({ custom: true });
var element = new joint.shapes.standard.Rectangle();
- var link = new joint.dia.Link();
+ var link = new joint.shapes.standard.Link();
// Custom View via class
@@ -385,7 +385,7 @@ QUnit.module('paper', function(hooks) {
var customElementView = joint.dia.ElementView.extend({ custom: true });
var customLinkView = joint.dia.LinkView.extend({ custom: true });
var element = new joint.shapes.standard.Rectangle({ type: 'elements.Element' });
- var link = new joint.dia.Link({ type: 'links.Link' });
+ var link = new joint.shapes.standard.Link({ type: 'links.Link' });
this.paper.options.cellViewNamespace = {
elements: { ElementView: customElementView },
@@ -426,8 +426,8 @@ QUnit.module('paper', function(hooks) {
position: { x: 400, y: 400 },
size: { width: 100, height: 100 }
});
- var link = new joint.dia.Link({ id: 'link', source: { id: source.id }, target: { id: target.id }});
- var soloLink = new joint.dia.Link({ id: 'link2', source: { id: source.id }, target: { x: 300, y: 300 }});
+ var link = new joint.shapes.standard.Link({ id: 'link', source: { id: source.id }, target: { id: target.id }});
+ var soloLink = new joint.shapes.standard.Link({ id: 'link2', source: { id: source.id }, target: { x: 300, y: 300 }});
graphCells = [source, target, solo, link, soloLink];
this.graph.addCells(graphCells);
@@ -443,12 +443,7 @@ QUnit.module('paper', function(hooks) {
QUnit.test('disconnect from element', function(assert) {
- var arrowhead = connectedLinkView.el.querySelector('.marker-arrowhead[end=target]');
-
- var data = {};
- connectedLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- connectedLinkView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 0, 0);
- connectedLinkView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 0, 0);
+ simulate.dragLinkView(connectedLinkView, 'target', { targetEl: this.paper.el, x: 0, y: 0 });
assert.notOk(connectSpy.called);
assert.ok(disconnectSpy.calledOnce);
@@ -456,13 +451,9 @@ QUnit.module('paper', function(hooks) {
QUnit.test('disconnect from element, connect to new one', function(assert) {
- var arrowhead = connectedLinkView.el.querySelector('.marker-arrowhead[end=target]');
var soloView = graphCells[2].findView(this.paper);
- var data = {};
- connectedLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- connectedLinkView.pointermove({ target: soloView.el, type: 'mousemove', data: data }, 450, 450);
- connectedLinkView.pointerup({ target: soloView.el, type: 'mouseup', data: data }, 450, 450);
+ simulate.dragLinkView(connectedLinkView, 'target', { targetEl: soloView.el, x: 450, y: 450 });
assert.ok(connectSpy.calledOnce, 'connect to solo');
assert.ok(disconnectSpy.calledOnce, 'disconnect from source');
@@ -470,13 +461,9 @@ QUnit.module('paper', function(hooks) {
QUnit.test('disconnect from element, connect to same one - nothing changed', function(assert) {
- var arrowhead = connectedLinkView.el.querySelector('.marker-arrowhead[end=target]');
var targetView = graphCells[1].findView(this.paper);
- var data = {};
- connectedLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- connectedLinkView.pointermove({ target: targetView.el, type: 'mousemove', data: data }, 450, 450);
- connectedLinkView.pointerup({ target: targetView.el, type: 'mouseup', data: data }, 450, 150);
+ simulate.dragLinkView(connectedLinkView, 'target', { targetEl: targetView.el, x: 450, y: 150 });
assert.notOk(connectSpy.called, 'connect should not be called');
assert.notOk(disconnectSpy.called, 'disconnect should not be called');
@@ -488,12 +475,11 @@ QUnit.module('paper', function(hooks) {
this.paper.options.snapLinks = true;
- var arrowhead = soloLinkView.el.querySelector('.marker-arrowhead[end=target]');
var targetView = graphCells[1].findView(this.paper);
var soloView = graphCells[2].findView(this.paper);
var data = {};
- soloLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
+ simulate.dragLinkView(soloLinkView, 'target', { data });
soloLinkView.pointermove({ target: soloView.el, type: 'mousemove', data: data }, 450, 450);
soloLinkView.pointermove({ target: targetView.el, type: 'mousemove', data: data }, 450, 150);
soloLinkView.pointerup({ target: targetView.el, type: 'mouseup', data: data }, 450, 450);
@@ -508,12 +494,11 @@ QUnit.module('paper', function(hooks) {
this.paper.options.validateConnection = validateConnectionSpy;
this.paper.options.snapLinks = true;
- var arrowhead = soloLinkView.el.querySelector('.marker-arrowhead[end=target]');
var targetView = graphCells[1].findView(this.paper);
var soloView = graphCells[2].findView(this.paper);
var data = {};
- soloLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
+ simulate.dragLinkView(soloLinkView, 'target', { data });
assert.equal(validateConnectionSpy.callCount, 0);
soloLinkView.pointermove({ target: soloView.el, type: 'mousemove', data: data }, 450, 450);
assert.equal(validateConnectionSpy.callCount, 1);
@@ -532,12 +517,7 @@ QUnit.module('paper', function(hooks) {
this.paper.options.linkPinning = true;
- var arrowhead = connectedLinkView.el.querySelector('.marker-arrowhead[end=target]');
-
- var data = {};
- connectedLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- connectedLinkView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 50, 50);
- connectedLinkView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 50, 50);
+ simulate.dragLinkView(connectedLinkView, 'target', { targetEl: this.paper.el, x: 50, y: 50 });
assert.ok(disconnectSpy.called);
assert.notOk(connectSpy.called);
@@ -547,12 +527,7 @@ QUnit.module('paper', function(hooks) {
this.paper.options.linkPinning = true;
- var arrowhead = connectedLinkView.el.querySelector('.marker-arrowhead[end=target]');
-
- var data = {};
- connectedLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- connectedLinkView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 50, 50);
- connectedLinkView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 50, 50);
+ simulate.dragLinkView(connectedLinkView, 'target', { targetEl: this.paper.el, x: 50, y: 50 });
assert.ok(disconnectSpy.called);
assert.notOk(connectSpy.called);
@@ -562,12 +537,7 @@ QUnit.module('paper', function(hooks) {
this.paper.options.linkPinning = false;
- var arrowhead = connectedLinkView.el.querySelector('.marker-arrowhead[end=target]');
-
- var data = {};
- connectedLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- connectedLinkView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 50, 50);
- connectedLinkView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 50, 50);
+ simulate.dragLinkView(connectedLinkView, 'target', { targetEl: this.paper.el, x: 50, y: 50 });
assert.notOk(disconnectSpy.called, 'message');
assert.notOk(connectSpy.called, 'message');
@@ -582,13 +552,7 @@ QUnit.module('paper', function(hooks) {
var allowLinkSpy = sinon.spy();
this.paper.options.allowLink = allowLinkSpy;
-
- var arrowhead = connectedLinkView.el.querySelector('.marker-arrowhead[end=target]');
-
- var data = {};
- connectedLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- connectedLinkView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 50, 50);
- connectedLinkView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 50, 50);
+ simulate.dragLinkView(connectedLinkView, 'target', { targetEl: this.paper.el, x: 50, y: 50 });
assert.ok(allowLinkSpy.calledOnce);
assert.ok(allowLinkSpy.calledWith(connectedLinkView, connectedLinkView.paper));
@@ -599,12 +563,7 @@ QUnit.module('paper', function(hooks) {
this.paper.options.allowLink = function() { return false; };
- var arrowhead = connectedLinkView.el.querySelector('.marker-arrowhead[end=target]');
-
- var data = {};
- connectedLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- connectedLinkView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 50, 50);
- connectedLinkView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 50, 50);
+ simulate.dragLinkView(connectedLinkView, 'target', { targetEl: this.paper.el, x: 50, y: 50 });
assert.notOk(disconnectSpy.called);
});
@@ -613,12 +572,7 @@ QUnit.module('paper', function(hooks) {
this.paper.options.allowLink = function() { return true; };
- var arrowhead = connectedLinkView.el.querySelector('.marker-arrowhead[end=target]');
-
- var data = {};
- connectedLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- connectedLinkView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 50, 50);
- connectedLinkView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 50, 50);
+ simulate.dragLinkView(connectedLinkView, 'target', { targetEl: this.paper.el, x: 50, y: 50 });
assert.ok(disconnectSpy.called);
});
@@ -627,14 +581,9 @@ QUnit.module('paper', function(hooks) {
this.paper.options.allowLink = null;
- var arrowhead = connectedLinkView.el.querySelector('.marker-arrowhead[end=target]');
+ simulate.dragLinkView(connectedLinkView, 'target', { targetEl: this.paper.el, x: 50, y: 50 });
- var data = {};
- connectedLinkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- connectedLinkView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 50, 50);
- connectedLinkView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 50, 50);
-
- assert.ok(disconnectSpy.called, 'message');
+ assert.ok(disconnectSpy.called);
});
});
@@ -648,7 +597,7 @@ QUnit.module('paper', function(hooks) {
var link;
hooks.beforeEach(function() {
- link = new joint.dia.Link();
+ link = new joint.shapes.standard.Link();
element = new joint.shapes.standard.Rectangle({
position: { x: 500, y: 250 },
size: { width: 100, height: 100 },
@@ -684,7 +633,6 @@ QUnit.module('paper', function(hooks) {
var paper = this.paper;
var linkView = link.findView(paper);
var elementView = element.findView(paper);
- var arrowhead = linkView.el.querySelector('.marker-arrowhead[end=' + end + ']');
var ports = element.getPortsPositions('in');
var position = element.position();
var in1PortEl = elementView.el.querySelector('[port="in1"]');
@@ -692,7 +640,7 @@ QUnit.module('paper', function(hooks) {
var x, y, evt;
var data = {};
- linkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
+ simulate.dragLinkView(linkView, end, { data });
// Connect to IN1
x = position.x + ports.in1.x;
y = position.y + ports.in1.y;
@@ -770,17 +718,13 @@ QUnit.module('paper', function(hooks) {
QUnit.test('connect to port', function(assert) {
- var link = new joint.dia.Link({ id: 'link' });
+ var link = new joint.shapes.standard.Link({ id: 'link' });
this.graph.addCells([this.modelWithPorts, link]);
var linkView = link.findView(this.paper);
- var arrowhead = linkView.el.querySelector('.marker-arrowhead[end=source]');
var port = this.paper.findViewByModel(this.modelWithPorts).el.querySelector('[port="in1"]');
- var data = {};
- linkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- linkView.pointermove({ target: port, type: 'mousemove', data: data }, 0, 0);
- linkView.pointerup({ target: port, type: 'mouseup', data: data }, 0, 0);
+ simulate.dragLinkView(linkView, 'source', { targetEl: port });
assert.ok(connectSpy.calledOnce);
assert.notOk(disconnectSpy.called);
@@ -788,17 +732,13 @@ QUnit.module('paper', function(hooks) {
QUnit.test('reconnect port', function(assert) {
- var link = new joint.dia.Link({ id: 'link', source: { id: this.modelWithPorts, port: 'in1' }});
+ var link = new joint.shapes.standard.Link({ id: 'link', source: { id: this.modelWithPorts, port: 'in1' }});
this.graph.addCells([this.modelWithPorts, link]);
var linkView = link.findView(this.paper);
- var arrowhead = linkView.el.querySelector('.marker-arrowhead[end=source]');
var portElement = this.paper.findViewByModel(this.modelWithPorts).el.querySelector('[port="in2"]');
- var data = {};
- linkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- linkView.pointermove({ target: portElement, type: 'mousemove', data: data }, 0, 0);
- linkView.pointerup({ target: portElement, type: 'mouseup', data: data }, 0, 0);
+ simulate.dragLinkView(linkView, 'source', { targetEl: portElement });
assert.ok(connectSpy.calledOnce);
assert.ok(disconnectSpy.calledOnce);
@@ -976,7 +916,7 @@ QUnit.module('paper', function(hooks) {
position: { x: 400, y: 100 },
size: { width: 100, height: 100 }
});
- var link = new joint.dia.Link({ id: 'link', source: { id: source.id }, target: { id: target.id }});
+ var link = new joint.shapes.standard.Link({ id: 'link', source: { id: source.id }, target: { id: target.id }});
var newLink; // to be created.
this.graph.addCells([source, target, link]);
@@ -985,21 +925,13 @@ QUnit.module('paper', function(hooks) {
var sourceView = source.findView(this.paper);
var targetView = target.findView(this.paper);
- var arrowhead = linkView.el.querySelector('.marker-arrowhead[end=target]');
-
this.paper.options.linkPinning = false;
- data = {};
- linkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- linkView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 50, 50);
- linkView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 50, 50);
+ simulate.dragLinkView(linkView, 'target', { targetEl: this.paper.el, x: 50, y: 50 });
assert.deepEqual(link.get('target'), { id: target.id }, 'pinning disabled: when the arrowhead is dragged&dropped to the blank paper area, the arrowhead is return to its original position.');
this.paper.options.linkPinning = true;
- data = {};
- linkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- linkView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 50, 50);
- linkView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 50, 50);
+ simulate.dragLinkView(linkView, 'target', { targetEl: this.paper.el, x: 50, y: 50 });
assert.deepEqual(link.get('target'), {
x: 50,
@@ -1007,10 +939,7 @@ QUnit.module('paper', function(hooks) {
}, 'pinning enabled: when the arrowhead is dragged&dropped to the blank paper area, the arrowhead is set to a point.');
this.paper.options.linkPinning = false;
- data = {};
- linkView.pointerdown({ target: arrowhead, type: 'mousedown', data: data }, 0, 0);
- linkView.pointermove({ target: targetView.el, type: 'mousemove', data: data }, 450, 150);
- linkView.pointerup({ target: targetView.el, type: 'mouseup', data: data }, 450, 150);
+ simulate.dragLinkView(linkView, 'target', { targetEl: targetView.el, x: 450, y: 150 });
assert.deepEqual(link.get('target'), { id: 'target' }, 'pinning disabled: it\'s still possible to connect link to elements.');
@@ -1021,19 +950,14 @@ QUnit.module('paper', function(hooks) {
sourceView.pointermove({ type: 'mousemove', data: data }, 150, 400);
newLink = _.reject(this.graph.getLinks(), { id: 'link' })[0];
- if (newLink) {
- assert.deepEqual(newLink.get('target'), {
- x: 150,
- y: 400
- }, 'pinning enabled: when there was a link created from a magnet a dropped into the blank paper area, the link target is set to a point.');
- newLink.remove();
- }
+ assert.deepEqual(newLink.get('target'), {
+ x: 150,
+ y: 400
+ }, 'pinning enabled: when there was a link created from a magnet a dropped into the blank paper area, the link target is set to a point.');
+ newLink.remove();
this.paper.options.linkPinning = false;
- data = {};
- sourceView.pointerdown({ target: sourceView.el, type: 'mousedown', data: data }, 150, 150);
- sourceView.pointermove({ target: this.paper.el, type: 'mousemove', data: data }, 150, 400);
- sourceView.pointerup({ target: this.paper.el, type: 'mouseup', data: data }, 150, 400);
+ simulate.dragLinkView(linkView, 'target', { targetEl: this.paper.el, x: 150, y: 400 });
newLink = _.reject(this.graph.getLinks(), { id: 'link' })[0];
assert.notOk(newLink, 'pinning disabled: when there was a link created from a magnet a dropped into the blank paper area, the link was removed after the drop.');
@@ -1354,7 +1278,7 @@ QUnit.module('paper', function(hooks) {
this.paper.options.multiLinks = true;
this.paper.options.linkPinning = true;
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { x: 300, y: 300 },
target: { x: 320, y: 320 }
});
@@ -1365,7 +1289,7 @@ QUnit.module('paper', function(hooks) {
assert.ok(this.paper.linkAllowed(linkView), 'can use link view');
- var pinnedLink = new joint.dia.Link({
+ var pinnedLink = new joint.shapes.standard.Link({
source: { id: rect1.id },
target: { x: 200, y: 200 }
});
@@ -1380,12 +1304,12 @@ QUnit.module('paper', function(hooks) {
this.paper.options.linkPinning = true;
assert.ok(this.paper.linkAllowed(pinnedLinkView), 'pinned link allowed when link pinning is enabled');
- var multiLink1 = new joint.dia.Link({
+ var multiLink1 = new joint.shapes.standard.Link({
source: { id: rect1.id },
target: { id: rect2.id }
});
- var multiLink2 = new joint.dia.Link({
+ var multiLink2 = new joint.shapes.standard.Link({
source: { id: rect1.id },
target: { id: rect2.id }
});
@@ -1782,7 +1706,7 @@ QUnit.module('paper', function(hooks) {
this.graph.addCell(r1);
this.graph.addCell(r2);
- new joint.dia.Link()
+ new joint.shapes.standard.Link()
.set({
source: { id: r1.id },
target: { id: r2.id }
diff --git a/packages/joint-core/test/jointjs/routers.js b/packages/joint-core/test/jointjs/routers.js
index d7c37cbbe..88d626de7 100644
--- a/packages/joint-core/test/jointjs/routers.js
+++ b/packages/joint-core/test/jointjs/routers.js
@@ -27,7 +27,7 @@ QUnit.module('routers', function(hooks) {
this.graph.addCell([r1, r2]);
- var l0 = new joint.dia.Link({
+ var l0 = new joint.shapes.standard.Link({
source: { id: r1.id },
target: { id: r2.id },
router: { name: 'non-existing' }
@@ -62,7 +62,7 @@ QUnit.module('routers', function(hooks) {
var r1 = new joint.shapes.standard.Rectangle({ position: { x: 200, y: 60 }, size: { width: 50, height: 30 }});
var r2 = new joint.shapes.standard.Rectangle({ position: { x: 125, y: 60 }, size: { width: 50, height: 30 }});
- var link = new joint.dia.Link({
+ var link = new joint.shapes.standard.Link({
source: { id: r1.id },
target: { id: r2.id },
router: { name: 'normal' },
@@ -72,7 +72,7 @@ QUnit.module('routers', function(hooks) {
this.graph.addCells([r1, r2, link]);
var linkView = this.paper.findViewByModel(link);
- var pathData = linkView.$('.connection').attr('d');
+ var pathData = linkView.findNode('line').getAttribute('d');
assert.checkDataPath(pathData, 'M 216 90 L 150 200 L 150 90', 'link was correctly routed');
});
@@ -84,7 +84,7 @@ QUnit.module('routers', function(hooks) {
var r1 = new joint.shapes.standard.Rectangle({ position: { x: 200, y: 60 }, size: { width: 50, height: 30 }});
var r2 = new joint.shapes.standard.Rectangle({ position: { x: 125, y: 60 }, size: { width: 50, height: 30 }});
- var l1 = new joint.dia.Link({
+ var l1 = new joint.shapes.standard.Link({
source: { id: r1.id },
target: { id: r2.id },
router: { name: 'orthogonal' },
@@ -94,7 +94,7 @@ QUnit.module('routers', function(hooks) {
this.graph.addCells([r1, r2, l1]);
var l1View = this.paper.findViewByModel(l1);
- var l1PathData = l1View.$('.connection').attr('d');
+ var l1PathData = l1View.findNode('line').getAttribute('d');
assert.checkDataPath(l1PathData, 'M 225 90 L 225 200 L 150 200 L 150 90', 'link with one vertex was correctly routed');
@@ -103,7 +103,7 @@ QUnit.module('routers', function(hooks) {
var r3 = new joint.shapes.standard.Rectangle({ position: { x: 40, y: 40 }, size: { width: 50, height: 30 }});
var r4 = new joint.shapes.standard.Rectangle({ position: { x: 220, y: 120 }, size: { width: 50, height: 30 }});
- var l2 = new joint.dia.Link({
+ var l2 = new joint.shapes.standard.Link({
source: { id: r3.id },
target: { id: r4.id },
router: { name: 'orthogonal' },
@@ -112,7 +112,7 @@ QUnit.module('routers', function(hooks) {
this.graph.addCells([r3, r4, l2]);
var l2View = this.paper.findViewByModel(l2);
- var l2PathData = l2View.$('.connection').attr('d');
+ var l2PathData = l2View.findNode('line').getAttribute('d');
assert.checkDataPath(l2PathData, 'M 90 55 L 245 55 L 245 120', 'link with no vertex was correctly routed');
@@ -121,7 +121,7 @@ QUnit.module('routers', function(hooks) {
var r5 = new joint.shapes.standard.Rectangle({ position: { x: 200, y: 60 }, size: { width: 50, height: 30 }});
var r6 = new joint.shapes.standard.Rectangle({ position: { x: 350, y: 40 }, size: { width: 50, height: 30 }});
- var l3 = new joint.dia.Link({
+ var l3 = new joint.shapes.standard.Link({
source: { id: r5.id },
target: { id: r6.id },
router: { name: 'orthogonal' },
@@ -131,7 +131,7 @@ QUnit.module('routers', function(hooks) {
this.graph.addCells([r5, r6, l3]);
var l3View = this.paper.findViewByModel(l3);
- var l3PathData = l3View.$('.connection').attr('d');
+ var l3PathData = l3View.findNode('line').getAttribute('d');
assert.checkDataPath(l3PathData, 'M 225 90 L 225 200 L 150 200 L 150 55 L 350 55', 'no spike (a return path segment) was created');
});
@@ -143,7 +143,7 @@ QUnit.module('routers', function(hooks) {
var r3 = r2.clone().translate(300);
- var l0 = new joint.dia.Link({
+ var l0 = new joint.shapes.standard.Link({
source: { id: r1.id },
target: { id: r3.id },
router: {
@@ -158,20 +158,20 @@ QUnit.module('routers', function(hooks) {
var v0 = this.paper.findViewByModel(l0);
- var d = v0.$('.connection').attr('d');
+ var d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 140 70 L 300 70 L 300 10 L 600 10 L 600 70 L 620 70', 'Route avoids an obstacle.');
r1.translate(0, 50);
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 140 120 L 600 120 L 600 70 L 620 70',
'Source has been moved. Route recalculated starting from target.');
r3.translate(0, -50);
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 140 120 L 600 120 L 600 20 L 620 20',
'Target has been moved. Route recalculated starting from source.');
@@ -187,7 +187,7 @@ QUnit.module('routers', function(hooks) {
}
});
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 140 120 L 280 120 L 280 0 L 580 0 L 580 20 L 620 20',
'The option paddingBox was passed. The source and target element and obstacles are avoided taken this padding in account.');
@@ -214,7 +214,7 @@ QUnit.module('routers', function(hooks) {
}
});
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 140 120 L 680 120 L 680 60',
'The default fallback router made an orthogonal link.');
@@ -230,7 +230,7 @@ QUnit.module('routers', function(hooks) {
}
});
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 80 80 L 80 20 L 20 20 L 20 0 L 600 0 L 600 20 L 620 20',
'A vertex was added. Route correctly recalculated.');
@@ -239,7 +239,7 @@ QUnit.module('routers', function(hooks) {
vertices: [{ x: 21, y: 21 }]
});
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 80 80 L 80 21 L 21 21 L 21 20 L 620 20',
'A vertex was moved (not snapped to the grid now). Route correctly recalculated.');
@@ -274,7 +274,7 @@ QUnit.module('routers', function(hooks) {
r1.translate(0, -50);
r3.translate(0, 50);
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 140 70 L 620 70',
'Set excludeTypes parameter to "standard.Rectangle" makes routing ignore those shapes.');
@@ -293,7 +293,7 @@ QUnit.module('routers', function(hooks) {
}
});
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 140 70 L 800 70 L 800 80 L 760 80 L 760 70 L 740 70',
'Set excludeEnds parameter to "target" makes routing ignore target element.');
@@ -311,7 +311,7 @@ QUnit.module('routers', function(hooks) {
}
});
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 20 70 L 0 70 L 0 10 L 760 10 L 760 70 L 740 70',
'Set startDirections & endDirections parameters makes routing starts and ends from/to the given direction.');
@@ -329,7 +329,7 @@ QUnit.module('routers', function(hooks) {
}
});
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.ok(spyIsPointObstacle.called);
assert.ok(spyIsPointObstacle.alwaysCalledWithExactly(sinon.match.instanceOf(g.Point)));
@@ -344,7 +344,7 @@ QUnit.module('routers', function(hooks) {
var r3 = r2.clone().translate(300, 300);
- var l0 = new joint.dia.Link({
+ var l0 = new joint.shapes.standard.Link({
source: { id: r1.id },
target: { id: r3.id },
router: {
@@ -360,7 +360,7 @@ QUnit.module('routers', function(hooks) {
var v0 = this.paper.findViewByModel(l0);
- var d = v0.$('.connection').attr('d');
+ var d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 140 70 L 160 70 L 400 310 L 440 310 L 680 550 L 680 630',
'Route avoids an obstacle.');
@@ -372,7 +372,7 @@ QUnit.module('routers', function(hooks) {
}
});
- d = v0.$('.connection').attr('d');
+ d = v0.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 80 70 L 81 70 L 680 670 L 680 670',
'The default fallback router made a metro link.');
@@ -383,7 +383,7 @@ QUnit.module('routers', function(hooks) {
var r1 = new joint.shapes.standard.Rectangle({ position: { x: 20, y: 30 }, size: { width: 120, height: 80 }});
var r2 = r1.clone().translate(300, 300);
- var l = new joint.dia.Link({ source: { id: r1.id }, target: { id: r2.id }});
+ var l = new joint.shapes.standard.Link({ source: { id: r1.id }, target: { id: r2.id }});
this.graph.addCell([r1, r2, l]);
@@ -391,27 +391,27 @@ QUnit.module('routers', function(hooks) {
// Left side
l.set('router', { name: 'oneSide', args: { padding: 20, side: 'left' }});
- var d = v.$('.connection').attr('d');
+ var d = v.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 20 70 L 0 70 L 0 370 L 320 370', 'Route goes only on the left side.');
// Padding option
l.set('router', { name: 'oneSide', args: { padding: 40, side: 'left' }});
- d = v.$('.connection').attr('d');
+ d = v.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 20 70 L -20 70 L -20 370 L 320 370', 'Route respects the padding.');
// Right side
l.set('router', { name: 'oneSide', args: { padding: 40, side: 'right' }});
- d = v.$('.connection').attr('d');
+ d = v.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 140 70 L 480 70 L 480 370 L 440 370', 'Route goes only on the right side.');
// Top side
l.set('router', { name: 'oneSide', args: { padding: 40, side: 'top' }});
- d = v.$('.connection').attr('d');
+ d = v.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 80 30 L 80 -10 L 380 -10 L 380 330', 'Route goes only on the top.');
// Bottom side
l.set('router', { name: 'oneSide', args: { padding: 40, side: 'bottom' }});
- d = v.$('.connection').attr('d');
+ d = v.findNode('line').getAttribute('d');
assert.checkDataPath(d, 'M 80 110 L 80 450 L 380 450 L 380 410', 'Route goes only on the bottom');
// Wrong side specified
@@ -424,7 +424,7 @@ QUnit.module('routers', function(hooks) {
var r1 = new joint.shapes.standard.Rectangle({ position: { x: 20, y: 30 }, size: { width: 120, height: 80 }});
var r2 = r1.clone().translate(300, 300);
- var l = new joint.dia.Link({ source: { id: r1.id }, target: { id: r2.id }});
+ var l = new joint.shapes.standard.Link({ source: { id: r1.id }, target: { id: r2.id }});
this.graph.addCell([r1, r2, l]);
diff --git a/packages/joint-core/test/utils.js b/packages/joint-core/test/utils.js
index e001c21ab..650b26007 100644
--- a/packages/joint-core/test/utils.js
+++ b/packages/joint-core/test/utils.js
@@ -300,7 +300,37 @@ window.simulate = {
touchend: function(touchInit) {
return this.touchevent({ ...touchInit, type: 'touchend' });
+ },
+
+ dragLinkView: function(linkView, endType, options = {}) {
+ const {
+ targetEl,
+ x = 0 ,
+ y = 0,
+ data: userData
+ } = options;
+ const data = userData || {};
+ const mousedownEvent = {
+ // Dummy event target determines the arrowhead to move.
+ target: V('circle', { r: 10, end: endType }).node,
+ type: 'mousedown',
+ data: data
+ };
+ linkView.pointerdown(mousedownEvent, 0, 0);
+ linkView.dragArrowheadStart(mousedownEvent);
+ if (!targetEl) return;
+ linkView.pointermove({
+ target: targetEl,
+ type: 'mousemove',
+ data: data
+ }, x, y);
+ linkView.pointerup({
+ target: targetEl,
+ type: 'mouseup',
+ data: data
+ }, x, y);
}
+
};
window.fixtures = {
diff --git a/packages/joint-core/types/joint.d.ts b/packages/joint-core/types/joint.d.ts
index b5e94b08c..33fbc3f05 100644
--- a/packages/joint-core/types/joint.d.ts
+++ b/packages/joint-core/types/joint.d.ts
@@ -1098,32 +1098,20 @@ export namespace dia {
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;
@@ -4186,6 +4174,8 @@ export namespace linkTools {
snapRadius?: number;
redundancyRemoval?: boolean;
vertexAdding?: boolean;
+ vertexRemoving?: boolean;
+ vertexMoving?: boolean;
stopPropagation?: boolean;
scale?: number;
}