Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
4 changes: 3 additions & 1 deletion src/symbols/Edge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export const Edge: FC<EdgeProps> = ({
labelVisible = false,
size = 1,
fill,
dashed = false
dashed = false,
dashSize = 3
} = edge;

// Use subLabelPlacement from edge data if available, otherwise use the prop value
Expand Down Expand Up @@ -465,6 +466,7 @@ export const Edge: FC<EdgeProps> = ({
curve={curve}
curved={curved}
dashed={dashed}
dashSize={dashSize}
id={id}
opacity={selectionOpacity}
size={size}
Expand Down
16 changes: 12 additions & 4 deletions src/symbols/Line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export interface LineProps {
*/
dashed?: boolean;

/**
* The size of the dash.
*/
dashSize?: number;

/**
* The unique identifier of the line.
*/
Expand Down Expand Up @@ -93,11 +98,12 @@ const dashedFragmentShader = `
uniform float opacity;
uniform float dashSize;
uniform float gapSize;
uniform float lineLength;
varying vec2 vUv;

void main() {
float totalSize = dashSize + gapSize;
float position = mod(vUv.x * 10.0, totalSize);
float position = mod(vUv.x * lineLength, totalSize);

if (position > dashSize) {
discard;
Expand All @@ -114,6 +120,7 @@ export const Line: FC<LineProps> = ({
curve,
curved = false,
dashed = false,
dashSize = 3,
id,
opacity = 1,
size = 1,
Expand All @@ -136,15 +143,16 @@ export const Line: FC<LineProps> = ({
uniforms: {
color: { value: normalizedColor },
opacity: { value: opacity },
dashSize: { value: 0.5 },
gapSize: { value: 0.3 }
dashSize: { value: dashSize },
gapSize: { value: 1 },
lineLength: { value: curve.getLength() }
},
vertexShader: dashedVertexShader,
fragmentShader: dashedFragmentShader,
transparent: true,
depthTest: false
});
}, [dashed, normalizedColor, opacity]);
}, [dashed, normalizedColor, opacity, curve, dashSize]);

// Do opacity seperate from vertices for perf
const { lineOpacity } = useSpring({
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export interface GraphEdge extends GraphElementBaseAttributes {
*/
dashed?: boolean;

/**
* The size of the dash.
*/
dashSize?: number;

/**
* Placement of the subLabel relative to the main label.
* - 'below': Show subLabel below the main label (default)
Expand Down
66 changes: 66 additions & 0 deletions stories/demos/Edges.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,69 @@ export const Dashed = () => (
]}
/>
);

export const DashSize = () => (
<GraphCanvas
edgeInterpolation="curved"
labelType="all"
nodes={[
{
id: '1',
label: '1'
},
{
id: '2',
label: '2'
},
{
id: '3',
label: '3'
},
{
id: '4',
label: '4'
},
{
id: '5',
label: '5'
}
]}
edges={[
{
source: '1',
target: '2',
id: '1-2',
label: '1-2',
dashed: true,
dashSize: 1
},
{
source: '2',
target: '3',
id: '2-3',
label: '2-3',
size: 5,
dashed: true,
dashSize: 2
},
{
source: '3',
target: '4',
id: '3-4',
label: '3-4',
size: 3,
dashed: true,
dashSize: 10
},
{
source: '4',
target: '5',
id: '4-5',
label: '4-5',
size: 10,
dashed: true,
dashSize: 1
}
]}
/>
);