2 * Copyright (c) 2017 ZTE Corporation.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * and the Apache License 2.0 which both accompany this distribution,
\r
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
\r
7 * and http://www.apache.org/licenses/LICENSE-2.0
\r
10 * ZTE - initial API and implementation and/or initial documentation
\r
13 import { Injectable } from '@angular/core';
\r
14 import * as jsp from 'jsplumb';
\r
18 * provides all of the operations about jsplumb plugin.
\r
21 export class JsPlumbService {
\r
22 private jsplumbInstance;
\r
29 public initJsPlumbInstance() {
\r
30 this.jsplumbInstance = jsp.jsPlumb.getInstance({
\r
31 Container: 'container'
\r
34 this.jsplumbInstance.importDefaults({
\r
35 Anchor: ['Top', 'RightMiddle', 'LeftMiddle', 'Bottom'],
\r
38 { cornerRadius: 0, stub: 0, gap: 3 },
\r
40 ConnectionOverlays: [
\r
43 { direction: 1, foldback: 1, location: 1, width: 10, length: 10 },
\r
45 ['Label', { label: '', id: 'label', cssClass: 'aLabel' }],
\r
58 // add connection to model data while a new connection is build
\r
59 this.jsplumbInstance.bind('connection', info => {
\r
60 this.jsplumbInstance.bind('connection', info => {
\r
62 info.connection.bind('click', connection => {
\r
63 this.jsplumbInstance.select({ connections: [connection] }).delete();
\r
71 public initNode(selectorString: string) {
\r
72 const selector = this.jsplumbInstance.getSelector(selectorString);
\r
74 this.jsplumbInstance.draggable(selector, {
\r
76 // node.position.left = event.pos[0];
\r
77 // node.position.top = event.pos[1];
\r
81 this.jsplumbInstance.makeTarget(selector, {
\r
87 this.jsplumbInstance.makeSource(selector, {
\r
88 filter: '.anchor, .anchor *',
\r