Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/pages/answer/queryGraph/QueryGraph.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ const edgeLength = 225;
*/
export default function QueryGraph({ query_graph }) {
const svgRef = useRef();
const { colorMap } = useContext(BiolinkContext);
const { colorMap, predicates } = useContext(BiolinkContext);
const [drawing, setDrawing] = useState(false);
const symmetricPredicates = predicates.filter((predicate) => predicate.symmetric).map((predicate) => predicate.predicate);

/**
* Initialize the svg size
Expand Down Expand Up @@ -141,7 +142,7 @@ export default function QueryGraph({ query_graph }) {
.attr('fill', 'none')
.attr('stroke-width', (d) => d.strokeWidth)
.attr('class', 'edge')
.attr('marker-end', (d) => (graphUtils.shouldShowArrow(d) ? 'url(#arrow)' : '')))
.attr('marker-end', (d) => (graphUtils.shouldShowArrow(d, symmetricPredicates) ? 'url(#arrow)' : '')))
.call((e) => e.append('path')
.attr('stroke', 'transparent')
.attr('fill', 'none')
Expand Down
5 changes: 3 additions & 2 deletions src/pages/answer/resultsTable/ResultExplorer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ export default function ResultExplorer({ answerStore }) {
const node = useRef({});
const edge = useRef({});
const simulation = useRef();
const { colorMap } = useContext(BiolinkContext);
const { colorMap, predicates } = useContext(BiolinkContext);
const [numTrimmedNodes, setNumTrimmedNodes] = useState(answerStore.numQgNodes);
const debouncedTrimmedNodes = useDebounce(numTrimmedNodes, 500);
const [popoverPosition, setPopoverPosition] = useState({ x: 0, y: 0 });
// const [attributesPopoverOpen, setAttributesPopoverOpen] = useState(false);
// const [currentEdgeAttributes, setCurrentEdgeAttributes] = useState({});
const [popoverOpen, setPopoverOpen] = useState(false);
const [popoverData, setPopoverData] = useState({});
const symmetricPredicates = predicates.filter((predicate) => predicate.symmetric).map((predicate) => predicate.predicate);

/**
* Initialize svg object
Expand Down Expand Up @@ -247,7 +248,7 @@ export default function ResultExplorer({ answerStore }) {
.attr('fill', 'none')
.attr('stroke-width', (d) => d.strokeWidth)
.attr('class', 'result_edge')
.attr('marker-end', (d) => (graphUtils.shouldShowArrow(d) ? 'url(#arrow)' : '')))
.attr('marker-end', (d) => (graphUtils.shouldShowArrow(d, symmetricPredicates) ? 'url(#arrow)' : '')))
.attr('fill', 'black')
.attr('stroke', '#999')
.style('transition', 'stroke 100ms ease-in-out, fill 100ms ease-in-out')
Expand Down
7 changes: 6 additions & 1 deletion src/pages/queryBuilder/graphEditor/QueryGraph.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default function QueryGraph({
height, width,
clickState, updateClickState,
}) {
const { colorMap } = useContext(BiolinkContext);
const { colorMap, predicates } = useContext(BiolinkContext);
const symmetricPredicates = predicates.filter((predicate) => predicate.symmetric).map((predicate) => predicate.predicate);
const queryBuilder = useContext(QueryBuilderContext);
const { query_graph } = queryBuilder;
const { nodes, edges } = useMemo(() => queryGraphUtils.getNodeAndEdgeListsForDisplay(query_graph), [queryBuilder.state]);
Expand Down Expand Up @@ -253,6 +254,10 @@ export default function QueryGraph({
// edge ends need the x and y of their attached nodes
// must come after simulation
const edgesWithCurves = edgeUtils.addEdgeCurveProperties(newEdges);
// add symmetricPredicates to each edgesWithCurves
edgesWithCurves.forEach((e) => {
e.symmetric = symmetricPredicates;
});

edge.current = edge.current.data(edgesWithCurves, (d) => d.id)
.join(
Expand Down
1 change: 1 addition & 0 deletions src/stores/useBiolinkModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function useBiolinkModel() {
predicate: strings.edgeFromBiolink(identifier),
domain: strings.nodeFromBiolink(predicate.domain),
range: strings.nodeFromBiolink(predicate.range),
symmetric: predicate.symmetric || false,
}));
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/d3/edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function enter(edge) {
.attr('fill', 'none')
.attr('stroke-width', (d) => d.strokeWidth)
.attr('class', 'edgePath')
.attr('marker-end', (d) => (graphUtils.shouldShowArrow(d) ? 'url(#arrow)' : '')))
.attr('marker-end', (d) => (graphUtils.shouldShowArrow(d, d.symmetric) ? 'url(#arrow)' : '')))
// wider clickable line
.call((e) => e.append('path')
.attr('stroke', 'transparent')
Expand Down Expand Up @@ -232,7 +232,7 @@ function update(edge) {
.text((d) => (d.predicates ? d.predicates.map((p) => strings.displayPredicate(p)).join(', ') : '')))
.call((e) => e.select('.edgePath')
// .attr('stroke-width', (d) => d.strokeWidth)
.attr('marker-end', (d) => (graphUtils.shouldShowArrow(d) ? 'url(#arrow)' : '')))
.attr('marker-end', (d) => (graphUtils.shouldShowArrow(d, d.symmetric) ? 'url(#arrow)' : '')))
.call((e) => e.select('text')
.select('textPath')
.text((d) => (d.predicates ? d.predicates.map((p) => strings.displayPredicate(p)).join(', ') : '')));
Expand Down
4 changes: 2 additions & 2 deletions src/utils/d3/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ function isInside(x, y, cx, cy, r) {
* @param {obj} edge edge object
* @returns {str} url(#arrow) or empty string
*/
function shouldShowArrow(edge) {
return (edge.predicates && edge.predicates.findIndex((p) => p !== 'biolink:related_to') > -1) || (edge.predicate && edge.predicate !== 'biolink:related_to');
function shouldShowArrow(edge, symmetric_predicates = ['biolink:related_to']) {
return (edge.predicates && edge.predicates.findIndex((p) => !symmetric_predicates.includes(p)) > -1) || (edge.predicate && !symmetric_predicates.includes(edge.predicate));
}

/**
Expand Down
Loading