@llopht wrote:
GoJS is downloadable as NPM package but it's not possible to easily use extensions because it not export the main function used as class. Is this possible you add this important feature in your roadmap. When we work with a framwork like React/Angular it's an essential need.
I have duplicate the CurvedLinkReshapingTool in my project and refactor some element asked by my linter, but that doesnt work. The curviness change each time I drag the handle but the link is not updated. An idea why ?
import go from 'gojs'; export default function CurvedLinkReshapingTool() { go.LinkReshapingTool.call(this); this._originalCurviness = NaN; } go.Diagram.inherit(CurvedLinkReshapingTool, go.LinkReshapingTool); CurvedLinkReshapingTool.prototype.makeAdornment = function(pathshape) { const link = pathshape.part; if (link !== null && link.curve === go.Link.Bezier && link.pointsCount === 4) { const adornment = new go.Adornment(); adornment.type = go.Panel.Link; const h = this.makeHandle(); this.setReshapingBehavior(h, go.LinkReshapingTool.All); h.cursor = 'move'; adornment.add(h); adornment.category = this.name; adornment.adornedObject = pathshape; return adornment; } return go.LinkReshapingTool.prototype.makeAdornment.call(this, pathshape); }; CurvedLinkReshapingTool.prototype.doActivate = function() { go.LinkReshapingTool.prototype.doActivate.call(this); this._originalCurviness = this.adornedLink.curviness; }; CurvedLinkReshapingTool.prototype.doCancel = function() { this.adornedLink.curviness = this._originalCurviness; go.LinkReshapingTool.prototype.doCancel.call(this); }; CurvedLinkReshapingTool.prototype.reshape = function(newpt) { const link = this.adornedLink; if (link !== null && link.curve === go.Link.Bezier && link.pointsCount === 4) { const start = link.getPoint(0); const end = link.getPoint(3); const ang = start.directionPoint(end); const mid = new go.Point((start.x + end.x) / 2, (start.y + end.y) / 2); const a = new go.Point(9999, 0).rotate(ang + 90).add(mid); const b = new go.Point(9999, 0).rotate(ang - 90).add(mid); const q = newpt.copy().projectOntoLineSegmentPoint(a, b); let curviness = Math.sqrt(mid.distanceSquaredPoint(q)); if (link.fromPort === link.toPort) { if (newpt.y < link.fromPort.getDocumentPoint(go.Spot.Center).y) curviness = -curviness; } else { const diff = mid.directionPoint(q) - ang; if ((diff > 0 && diff < 180) || (diff < -180)) curviness = -curviness; } link.curviness = curviness; // <-- this value change each time I drag the handle return q; } go.LinkReshapingTool.prototype.reshape.call(this, newpt); };
Posts: 3
Participants: 2