Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1840256: Fix for re-display of EventSources with links in topology #5569

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 31 additions & 28 deletions frontend/packages/topology/src/anchors/SVGAnchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export default class SVGAnchor extends AbstractAnchor {
this.svgElement = svgElement;
}

getCircleLocation(circle: SVGCircleElement, reference: Point): Point {
private getCircleLocation(circle: SVGCircleElement, reference: Point): Point {
const center: Point = new Point(circle.cx.baseVal.value, circle.cy.baseVal.value);
this.owner.translateToParent(center);
const diameter = circle.r.baseVal.value * 2 + this.offset * 2;

return getEllipseAnchorPoint(center, diameter, diameter, reference);
}

getEllipseLocation(ellipse: SVGEllipseElement, reference: Point): Point {
private getEllipseLocation(ellipse: SVGEllipseElement, reference: Point): Point {
const center: Point = new Point(ellipse.cx.baseVal.value, ellipse.cy.baseVal.value);
this.owner.translateToParent(center);
const offset2x = this.offset * 2;
Expand All @@ -34,7 +34,7 @@ export default class SVGAnchor extends AbstractAnchor {
return getEllipseAnchorPoint(center, width, height, reference);
}

getRectLocation(rect: SVGRectElement, reference: Point): Point {
private getRectLocation(rect: SVGRectElement, reference: Point): Point {
const width = rect.width.baseVal.value;
const height = rect.height.baseVal.value;

Expand All @@ -48,15 +48,15 @@ export default class SVGAnchor extends AbstractAnchor {
return getRectAnchorPoint(center, width + offset2x, height + offset2x, reference);
}

getPathLocation(path: SVGPathElement, reference: Point): Point {
private getPathLocation(path: SVGPathElement, reference: Point): Point {
const translatedRef = reference.clone();
this.owner.translateFromParent(translatedRef);
const anchorPoint = getPathAnchorPoint(path, translatedRef);
this.owner.translateToParent(anchorPoint);
return anchorPoint;
}

getPolygonLocation(polygon: SVGPolygonElement, reference: Point): Point {
private getPolygonLocation(polygon: SVGPolygonElement, reference: Point): Point {
const translatedRef = reference.clone();
this.owner.translateFromParent(translatedRef);
const anchorPoint = getPolygonAnchorPoint(polygon, translatedRef);
Expand All @@ -65,36 +65,39 @@ export default class SVGAnchor extends AbstractAnchor {
}

getLocation(reference: Point): Point {
if (this.svgElement instanceof SVGCircleElement) {
return this.getCircleLocation(this.svgElement, reference);
}

if (this.svgElement instanceof SVGEllipseElement) {
return this.getEllipseLocation(this.svgElement, reference);
}

if (this.svgElement instanceof SVGRectElement) {
return this.getRectLocation(this.svgElement, reference);
}

if (this.svgElement instanceof SVGPathElement) {
return this.getPathLocation(this.svgElement, reference);
}

if (this.svgElement instanceof SVGPolygonElement) {
return this.getPolygonLocation(this.svgElement, reference);
if (this.svgElement?.viewportElement) {
if (this.svgElement instanceof SVGCircleElement) {
return this.getCircleLocation(this.svgElement, reference);
}

if (this.svgElement instanceof SVGEllipseElement) {
return this.getEllipseLocation(this.svgElement, reference);
}

if (this.svgElement instanceof SVGRectElement) {
return this.getRectLocation(this.svgElement, reference);
}

if (this.svgElement instanceof SVGPathElement) {
return this.getPathLocation(this.svgElement, reference);
}

if (this.svgElement instanceof SVGPolygonElement) {
return this.getPolygonLocation(this.svgElement, reference);
}
}

return this.owner.getBounds().getCenter();
}

getReferencePoint(): Point {
if (
this.svgElement instanceof SVGCircleElement ||
this.svgElement instanceof SVGEllipseElement ||
this.svgElement instanceof SVGRectElement ||
this.svgElement instanceof SVGPathElement ||
this.svgElement instanceof SVGPolygonElement
this.svgElement?.viewportElement &&
(this.svgElement instanceof SVGCircleElement ||
this.svgElement instanceof SVGEllipseElement ||
this.svgElement instanceof SVGRectElement ||
this.svgElement instanceof SVGPathElement ||
this.svgElement instanceof SVGPolygonElement)
) {
const bbox = this.svgElement.getBBox();
const ref = new Point(bbox.x + bbox.width / 2, bbox.y + bbox.height / 2);
Expand Down