Skip to content

Commit 34a5574

Browse files
committed
fix: Resolved issue where certain lines weren't being diplayed in pathway diagram
1 parent 6ce57f0 commit 34a5574

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

projects/pathway-browser/src/app/diagram/diagram.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {
678678
cy.batch(() => {
679679
this.setSubPathwayVisibility(true, cy);
680680
cy.elements().removeClass('flag');
681-
cy.edges('![?color]').style({'underlay-opacity': 0})
681+
cy.edges().not('[?color]').style({'underlay-opacity': 0})
682682
})
683683

684684
return cy.collection()

projects/pathway-browser/src/app/services/diagram.service.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,13 @@ export class DiagramService {
565565
this.addEdgeInfo(reaction, points, 'forward', targetP);
566566

567567
let [from, to] = [points.shift()!, points.pop()!]
568-
from = from ?? nodeP; // Quick fix to avoid problem with reaction without visible outputs like R-HSA-2424252 in R-HSA-1474244
569-
to = to ?? reactionP; // Quick fix to avoid problem with reaction without visible outputs like R-HSA-2424252 in R-HSA-1474244
568+
// Keep fallback direction aligned with edge source/target for connectors that have missing segment endpoints.
569+
from = from ?? sourceP;
570+
to = to ?? targetP;
571+
if (equal(from, to)) {
572+
from = sourceP;
573+
to = targetP;
574+
}
570575
if (connector.type === 'CATALYST' && connector.endShape) {
571576
to = scale(connector.endShape.centre || connector.endShape.c);
572577
}
@@ -619,8 +624,7 @@ export class DiagramService {
619624
target: target.id + '',
620625
stoichiometry: connector.stoichiometry.value,
621626
...relativeSegments,
622-
sourceEndpoint: this.endpoint(sourceP, from),
623-
targetEndpoint: this.endpoint(targetP, to),
627+
...this.getEndpointData(sourceP, targetP, from, to),
624628
pathway: eventIdToSubPathwayId.get(reaction.reactomeId),
625629
reactomeId: reaction.reactomeId,
626630
reactionId: reaction.id,
@@ -652,6 +656,10 @@ export class DiagramService {
652656
let [from, to] = [points.shift()!, points.pop()!]
653657
from = from ?? sourceP; // Quick fix to avoid problem with reaction without visible outputs like R-HSA-2424252 in R-HSA-1474244
654658
to = to ?? targetP; // Quick fix to avoid problem with reaction without visible outputs like R-HSA-2424252 in R-HSA-1474244
659+
if (equal(from, to)) {
660+
from = sourceP;
661+
to = targetP;
662+
}
655663

656664
// points = addRoundness(from, to, points);
657665
const relatives = this.absoluteToRelative(from, to, points);
@@ -669,8 +677,7 @@ export class DiagramService {
669677
source: link.inputs[0].id + '',
670678
target: link.outputs[0].id + '',
671679
...relativeSegments,
672-
sourceEndpoint: this.endpoint(sourceP, from),
673-
targetEndpoint: this.endpoint(targetP, to),
680+
...this.getEndpointData(sourceP, targetP, from, to),
674681
isFadeOut: link.isFadeOut,
675682
isBackground: isBackground
676683
},
@@ -749,8 +756,26 @@ export class DiagramService {
749756
}
750757
}
751758

752-
private endpoint(source: Position, point: Position): string {
753-
return `${point.x - source.x} ${point.y - source.y}`
759+
private endpoint(source: Position, point: Position): string | undefined {
760+
const dx = point.x - source.x;
761+
const dy = point.y - source.y;
762+
if (!Number.isFinite(dx) || !Number.isFinite(dy)) return undefined;
763+
return `${dx} ${dy}`
764+
}
765+
766+
private getEndpointData(source: Position, target: Position, from: Position, to: Position): Partial<{ sourceEndpoint: string, targetEndpoint: string }> {
767+
if (!isFinitePoint(source) || !isFinitePoint(target) || !isFinitePoint(from) || !isFinitePoint(to)) {
768+
return {};
769+
}
770+
if (equal(source, target)) {
771+
return {};
772+
}
773+
const sourceEndpoint = this.endpoint(source, from);
774+
const targetEndpoint = this.endpoint(target, to);
775+
if (!sourceEndpoint || !targetEndpoint) {
776+
return {};
777+
}
778+
return {sourceEndpoint, targetEndpoint};
754779
}
755780

756781
private getRelativeSegmentsData(relatives: RelativePosition): Partial<{weights: string, distances: string}> {

0 commit comments

Comments
 (0)