Skip to content

Commit

Permalink
Merge pull request #123 from leandroberetta/show-tag-logic
Browse files Browse the repository at this point in the history
Logic for showing, scaling or hiding the tag on an edge depending on the details level of the graph
  • Loading branch information
jeff-phillips-18 authored Dec 13, 2023
2 parents 070321a + a0f9c53 commit bf94564
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions packages/module/src/components/edges/DefaultEdge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import * as _ from 'lodash';
import { observer } from 'mobx-react';
import { Edge, EdgeTerminalType, GraphElement, isEdge, isNode, NodeStatus } from '../../types';
import { Edge, EdgeTerminalType, GraphElement, isEdge, isNode, NodeStatus, ScaleDetailsLevel } from '../../types';
import { ConnectDragSource, OnSelect } from '../../behavior';
import { getClosestVisibleParent, useHover } from '../../utils';
import { Layer } from '../layers';
Expand Down Expand Up @@ -112,6 +112,8 @@ const DefaultEdgeInner: React.FunctionComponent<DefaultEdgeInnerProps> = observe
return null;
}

const detailsLevel = element.getGraph().getDetailsLevel();

const groupClassName = css(
styles.topologyEdge,
className,
Expand All @@ -126,9 +128,8 @@ const DefaultEdgeInner: React.FunctionComponent<DefaultEdgeInnerProps> = observe

const bendpoints = element.getBendpoints();

const d = `M${startPoint.x} ${startPoint.y} ${bendpoints.map((b: Point) => `L${b.x} ${b.y} `).join('')}L${
endPoint.x
} ${endPoint.y}`;
const d = `M${startPoint.x} ${startPoint.y} ${bendpoints.map((b: Point) => `L${b.x} ${b.y} `).join('')}L${endPoint.x
} ${endPoint.y}`;

const bgStartPoint =
!startTerminalType || startTerminalType === EdgeTerminalType.none
Expand All @@ -141,6 +142,11 @@ const DefaultEdgeInner: React.FunctionComponent<DefaultEdgeInnerProps> = observe
const backgroundPath = `M${bgStartPoint[0]} ${bgStartPoint[1]} ${bendpoints
.map((b: Point) => `L${b.x} ${b.y} `)
.join('')}L${bgEndPoint[0]} ${bgEndPoint[1]}`;

const showTag = tag && (detailsLevel === ScaleDetailsLevel.high || hover);
const scale = element.getGraph().getScale();
const tagScale = hover && !(detailsLevel === ScaleDetailsLevel.high) ? Math.max(1, 1 / scale) : 1;
const tagPositionScale = hover && !(detailsLevel === ScaleDetailsLevel.high) ? Math.min(1, scale) : 1;

return (
<Layer id={dragging || hover ? TOP_LAYER : undefined}>
Expand All @@ -158,14 +164,16 @@ const DefaultEdgeInner: React.FunctionComponent<DefaultEdgeInnerProps> = observe
onMouseLeave={onHideRemoveConnector}
/>
<path className={linkClassName} d={d} style={{ animationDuration: `${edgeAnimationDuration}s` }} />
{tag && (
<DefaultConnectorTag
className={tagClass}
startPoint={element.getStartPoint()}
endPoint={element.getEndPoint()}
tag={tag}
status={tagStatus}
/>
{showTag && (
<g transform={`scale(${hover ? tagScale : 1})`}>
<DefaultConnectorTag
className={tagClass}
startPoint={element.getStartPoint().scale(tagPositionScale)}
endPoint={element.getEndPoint().scale(tagPositionScale)}
tag={tag}
status={tagStatus}
/>
</g>
)}
<DefaultConnectorTerminal
className={startTerminalClass}
Expand Down Expand Up @@ -193,7 +201,7 @@ const DefaultEdgeInner: React.FunctionComponent<DefaultEdgeInnerProps> = observe
);
});

const DefaultEdge: React.FunctionComponent<DefaultEdgeProps>= ({
const DefaultEdge: React.FunctionComponent<DefaultEdgeProps> = ({
element,
startTerminalType = EdgeTerminalType.none,
startTerminalSize = 14,
Expand Down

0 comments on commit bf94564

Please sign in to comment.