diff --git a/packages/editor/cypress/snapshots/topicManager.cy.ts/redoChange.snap.png b/packages/editor/cypress/snapshots/topicManager.cy.ts/redoChange.snap.png index 63d8710c..64332294 100644 Binary files a/packages/editor/cypress/snapshots/topicManager.cy.ts/redoChange.snap.png and b/packages/editor/cypress/snapshots/topicManager.cy.ts/redoChange.snap.png differ diff --git a/packages/mindplot/src/components/ConnectionLine.ts b/packages/mindplot/src/components/ConnectionLine.ts index 6a747d87..62caeeb5 100644 --- a/packages/mindplot/src/components/ConnectionLine.ts +++ b/packages/mindplot/src/components/ConnectionLine.ts @@ -17,7 +17,7 @@ */ import { $assert } from '@wisemapping/core-js'; -import { Point, CurvedLine, PolyLine, Line } from '@wisemapping/web2d'; +import { CurvedLine, PolyLine, Line } from '@wisemapping/web2d'; import RelationshipModel from './model/RelationshipModel'; import Topic from './Topic'; import TopicConfig from './TopicConfig'; @@ -42,7 +42,7 @@ class ConnectionLine { protected _model: RelationshipModel; - constructor(sourceNode: Topic, targetNode: Topic) { + constructor(sourceNode: Topic, targetNode: Topic, type: LineType = LineType.SIMPLE_CURVED) { $assert(targetNode, 'parentNode node can not be null'); $assert(sourceNode, 'childNode node can not be null'); $assert(sourceNode !== targetNode, 'Circular connection'); @@ -50,15 +50,16 @@ class ConnectionLine { this._targetTopic = targetNode; this._sourceTopic = sourceNode; - const ctrlPoints = this._getCtrlPoints(sourceNode, targetNode); - const line = this._createLine(LineType.SIMPLE_CURVED); - line.setSrcControlPoint(ctrlPoints[0]); - line.setDestControlPoint(ctrlPoints[1]); - // Set line styles ... + const line = this._createLine(type); const strokeColor = ConnectionLine.getStrokeColor(); - line.setStroke(1, 'solid', strokeColor, 1); - line.setFill(strokeColor, 1); + if (type === LineType.SIMPLE_CURVED) { + line.setStroke(1, 'solid', strokeColor, 1); + line.setFill(strokeColor, 1); + } else { + line.setStroke(2, 'solid', strokeColor, 1); + } + // Set line styles ... this._line2d = line; } @@ -66,7 +67,10 @@ class ConnectionLine { const srcPos = sourceNode.workoutOutgoingConnectionPoint(targetNode.getPosition()); const destPos = targetNode.workoutIncomingConnectionPoint(sourceNode.getPosition()); const deltaX = (srcPos.x - destPos.x) / 3; - return [new Point(deltaX, 0), new Point(-deltaX, 0)]; + return [ + { x: deltaX, y: 0 }, + { x: -deltaX, y: 0 }, + ]; } protected _createLine(lineType: LineType): Line { diff --git a/packages/mindplot/src/components/RelationshipControlPoints.ts b/packages/mindplot/src/components/RelationshipControlPoints.ts index 6e72e0d9..180592ed 100644 --- a/packages/mindplot/src/components/RelationshipControlPoints.ts +++ b/packages/mindplot/src/components/RelationshipControlPoints.ts @@ -146,8 +146,8 @@ class ControlPivotLine { this._line.setTo(startPosition.x + ctrPosition.x - 5, startPosition.y + ctrPosition.y - 5); this._dot.setPosition( - startPosition.x + ctrPosition.x - 8, - startPosition.y + ctrPosition.y - 8, + startPosition.x + ctrPosition.x - 5, + startPosition.y + ctrPosition.y - 5, ); } } @@ -167,7 +167,7 @@ class ControlPivotLine { this._moveRelHandler(ctlPoint); // Update pivot ... - this._dot.setPosition(mousePosition.x - 8, mousePosition.y - 8); + this._dot.setPosition(mousePosition.x - 5, mousePosition.y - 5); // Update line ... this._line.setTo(mousePosition.x - 5, mousePosition.y - 5); diff --git a/packages/mindplot/src/components/ShrinkConnector.ts b/packages/mindplot/src/components/ShrinkConnector.ts index 6d354722..5acd03aa 100644 --- a/packages/mindplot/src/components/ShrinkConnector.ts +++ b/packages/mindplot/src/components/ShrinkConnector.ts @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Elipse } from '@wisemapping/web2d'; +import { Elipse, Group } from '@wisemapping/web2d'; import TopicConfig from './TopicConfig'; import ActionDispatcher from './ActionDispatcher'; @@ -94,12 +94,12 @@ class ShirinkConnector { this._ellipse.setAttribute(name, value); } - addToWorkspace(group): void { + addToWorkspace(group: Group): void { group.append(this._ellipse); } setPosition(x: number, y: number): void { - this._ellipse.setPosition(x, y); + this._ellipse.setPosition(x + 3, y + 3); } moveToBack(): void { diff --git a/packages/mindplot/src/components/Topic.ts b/packages/mindplot/src/components/Topic.ts index f43af6b6..fb2b350e 100644 --- a/packages/mindplot/src/components/Topic.ts +++ b/packages/mindplot/src/components/Topic.ts @@ -1034,7 +1034,7 @@ abstract class Topic extends NodeGraph { disconnect(workspace: Workspace): void { const outgoingLine = this.getOutgoingLine(); - if ($defined(outgoingLine)) { + if (outgoingLine) { $assert(workspace, 'workspace can not be null'); this._outgoingLine = null; @@ -1069,7 +1069,7 @@ abstract class Topic extends NodeGraph { // Hide connection line?. if (targetTopic.getChildren().length === 0) { const connector = targetTopic.getShrinkConnector(); - if ($defined(connector)) { + if (connector) { connector.setVisibility(false); targetTopic.isCollapsed(false); } @@ -1146,13 +1146,13 @@ abstract class Topic extends NodeGraph { abstract updateTopicShape(targetTopic: Topic); - append(child: Topic) { + append(child: Topic): void { const children = this.getChildren(); children.push(child); } /** */ - removeChild(child: Topic) { + removeChild(child: Topic): void { const children = this.getChildren(); this._children = children.filter((c) => c !== child); } @@ -1167,7 +1167,7 @@ abstract class Topic extends NodeGraph { return result; } - removeFromWorkspace(workspace: Workspace) { + removeFromWorkspace(workspace: Workspace): void { const elem2d = this.get2DElement(); workspace.removeChild(elem2d); const line = this.getOutgoingLine(); @@ -1178,7 +1178,7 @@ abstract class Topic extends NodeGraph { EventBus.instance.fireEvent('topicRemoved', this.getModel()); } - addToWorkspace(workspace: Workspace) { + addToWorkspace(workspace: Workspace): void { const elem = this.get2DElement(); workspace.append(elem); if (!this.isInWorkspace()) { diff --git a/packages/web2d/cypress/snapshots/playground.cy.js/Events.snap.png b/packages/web2d/cypress/snapshots/playground.cy.js/Events.snap.png index 4e083b6f..a42892f3 100644 Binary files a/packages/web2d/cypress/snapshots/playground.cy.js/Events.snap.png and b/packages/web2d/cypress/snapshots/playground.cy.js/Events.snap.png differ diff --git a/packages/web2d/cypress/snapshots/playground.cy.js/Group.snap.png b/packages/web2d/cypress/snapshots/playground.cy.js/Group.snap.png index 12c62553..482cacbe 100644 Binary files a/packages/web2d/cypress/snapshots/playground.cy.js/Group.snap.png and b/packages/web2d/cypress/snapshots/playground.cy.js/Group.snap.png differ diff --git a/packages/web2d/cypress/snapshots/playground.cy.js/Poly Line.snap.png b/packages/web2d/cypress/snapshots/playground.cy.js/Poly Line.snap.png index b94366b0..bf971e2f 100644 Binary files a/packages/web2d/cypress/snapshots/playground.cy.js/Poly Line.snap.png and b/packages/web2d/cypress/snapshots/playground.cy.js/Poly Line.snap.png differ diff --git a/packages/web2d/cypress/snapshots/playground.cy.js/Workspace.snap.png b/packages/web2d/cypress/snapshots/playground.cy.js/Workspace.snap.png index f086d573..b1bc9318 100644 Binary files a/packages/web2d/cypress/snapshots/playground.cy.js/Workspace.snap.png and b/packages/web2d/cypress/snapshots/playground.cy.js/Workspace.snap.png differ diff --git a/packages/web2d/src/components/peer/svg/ElipsePeer.js b/packages/web2d/src/components/peer/svg/ElipsePeer.js index af92b33c..fe62e83d 100644 --- a/packages/web2d/src/components/peer/svg/ElipsePeer.js +++ b/packages/web2d/src/components/peer/svg/ElipsePeer.js @@ -24,6 +24,7 @@ class ElipsePeer extends ElementPeer { super(svgElement); this.attachChangeEventListener('strokeStyle', ElementPeer.prototype.updateStrokeStyle); this._position = { x: 0, y: 0 }; + this._size = { width: 5, height: 5 }; } setSize(width, height) { @@ -35,23 +36,16 @@ class ElipsePeer extends ElementPeer { if ($defined(height)) { this._native.setAttribute('ry', height / 2); } - - const pos = this.getPosition(); - this.setPosition(pos.x, pos.y); } setPosition(pcx, pcy) { - const size = this.getSize(); - - const cx = size.width / 2 + pcx; - const cy = size.height / 2 + pcy; - - if ($defined(cx)) { - this._native.setAttribute('cx', cx); + this._position = { x: pcx, y: pcy }; + if ($defined(pcx)) { + this._native.setAttribute('cx', pcx); } - if ($defined(cy)) { - this._native.setAttribute('cy', cy); + if ($defined(pcy)) { + this._native.setAttribute('cy', pcy); } } diff --git a/packages/web2d/src/components/peer/svg/PolyLinePeer.js b/packages/web2d/src/components/peer/svg/PolyLinePeer.js index cafd9d02..dacbb21e 100644 --- a/packages/web2d/src/components/peer/svg/PolyLinePeer.js +++ b/packages/web2d/src/components/peer/svg/PolyLinePeer.js @@ -57,11 +57,13 @@ class PolyLinePeer extends ElementPeer { } _updatePath() { - if (this._style === 'Curved') { - this._updateMiddleCurvePath(); - } else if (this._style === 'Straight') { + if (this._style === 'Straight') { this._updateStraightPath(); - } else { + } if (this._style === 'MiddleStraight') { + this._updateMiddleStraightPath(); + } else if (this._style === 'MiddleCurved') { + this._updateMiddleCurvePath(); + } else if (this._style === 'Curved' || !this._style) { this._updateCurvePath(); } } @@ -85,10 +87,11 @@ class PolyLinePeer extends ElementPeer { const y1 = this._y1; const x2 = this._x2; const y2 = this._y2; + if ($defined(x1) && $defined(x2) && $defined(y1) && $defined(y2)) { const diff = x2 - x1; const middlex = diff / 2 + x1; - let signx = 1; + let signx = 0; let signy = 1; if (diff < 0) { signx = -1; @@ -96,9 +99,21 @@ class PolyLinePeer extends ElementPeer { if (y2 < y1) { signy = -1; } - const path = `${x1}, ${y1} ${middlex - 10 * signx}, ${y1} ${middlex}, ${ - y1 + 10 * signy - } ${middlex}, ${y2 - 10 * signy} ${middlex + 10 * signx}, ${y2} ${x2}, ${y2}`; + const path = `${x1}, ${y1} ${middlex - 10 * signx}, ${y1} ${middlex}, ${y1 + 10 * signy + } ${middlex}, ${y2 - 10 * signy} ${middlex + 10 * signx}, ${y2} ${x2}, ${y2}`; + this._native.setAttribute('points', path); + } + } + + _updateMiddleStraightPath() { + const x1 = this._x1; + const y1 = this._y1; + const x2 = this._x2; + const y2 = this._y2; + if ($defined(x1) && $defined(x2) && $defined(y1) && $defined(y2)) { + const diff = x2 - x1; + const middlex = diff / 2 + x1; + const path = `${x1}, ${y1} ${middlex}, ${y1} ${middlex}, ${y1} ${middlex}, ${y2} ${middlex}, ${y2} ${x2}, ${y2}`; this._native.setAttribute('points', path); } } diff --git a/packages/web2d/test/playground/polyLine.html b/packages/web2d/test/playground/polyLine.html index ae1cc1f0..5529bcd0 100755 --- a/packages/web2d/test/playground/polyLine.html +++ b/packages/web2d/test/playground/polyLine.html @@ -14,23 +14,37 @@