Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion src/lib/Edges/BaseEdge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@
) : null;
</script>

<path {style} d={path} class="react-flow__edge-path" {markerEnd} {markerStart} />
<path
{style}
d={path}
class="react-flow__edge-path"
marker-end={markerEnd}
marker-start={markerStart}
/>
{text}
88 changes: 86 additions & 2 deletions src/lib/Edges/EdgeText.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,89 @@
<script lang="typescript">
import type { EdgeTextProps, Rect } from '../types'; //EdgeTextProps is currently commented out in types/edges.ts
// import React, { memo, useRef, useState, useEffect, FC, PropsWithChildren } from 'react';
import { onMount } from 'svelte';
import cc from 'classcat';

const [edgeTextBbox, setEdgeTextBbox] = useState<Rect>({ x: 0, y: 0, width: 0, height: 0 });
import { EdgeTextProps, Rect } from '../../types';

export let {
//FC<PropsWithChildren<EdgeTextProps>>
x,
y,
label,
labelStyle = {},
labelShowBg = true,
labelBgStyle = {},
labelBgPadding = [2, 4],
labelBgBorderRadius = 2,
children,
className,
...rest
};

// const EdgeText: any = ({
// //FC<PropsWithChildren<EdgeTextProps>>
// x,
// y,
// label,
// labelStyle = {},
// labelShowBg = true,
// labelBgStyle = {},
// labelBgPadding = [2, 4],
// labelBgBorderRadius = 2,
// children,
// className,
// ...rest
// }) => {
const edgeRef: SVGTextElement;
const [edgeTextBbox, setEdgeTextBbox]: Rect = { x: 0, y: 0, width: 0, height: 0 };
const edgeTextClasses = cc(['svelvet__edge-textwrapper', className]);

onMount(() => {
if (edgeRef.current) {
const textBbox = edgeRef.current.getBBox();

setEdgeTextBbox({
x: textBbox.x,
y: textBbox.y,
width: textBbox.width,
height: textBbox.height
});
}
}, [label]); //the typescript error on this line will be fixed once EdgeTextProps is uncommented

if (typeof label === 'undefined' || !label) {
return null;
}
// };
</script>

<g
transform={`translate(${x - edgeTextBbox.width / 2} ${y - edgeTextBbox.height / 2})`}
class={edgeTextClasses}
{...rest}
>
<!-- {labelShowBg && ( -->
{#if labelShowBg}
<rect
width={edgeTextBbox.width + 2 * labelBgPadding[0]}
x={-labelBgPadding[0]}
y={-labelBgPadding[1]}
height={edgeTextBbox.height + 2 * labelBgPadding[1]}
className="react-flow__edge-textbg"
style={labelBgStyle}
rx={labelBgBorderRadius}
ry={labelBgBorderRadius}
/>
{/if}
<!-- )} -->
<text
class="react-flow__edge-text"
y={edgeTextBbox.height / 2}
dy="0.3em"
ref={edgeRef}
style={labelStyle}
>
{label}
</text>
{children}
</g>
8 changes: 4 additions & 4 deletions src/lib/Edges/SimpleBezierEdge.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="typescript">
// import React, { memo } from 'react';
<script lang="typescript" context="module">
import type { EdgeProps } from '../types';
import { Position } from '../types';
import BaseEdge from './BaseEdge.svelte';

export let {
export let propsObj: any;
const {
sourceX,
sourceY,
targetX,
Expand All @@ -20,7 +20,7 @@
style,
markerEnd,
markerStart
}: EdgeProps;
}: EdgeProps = propsObj;

export interface GetSimpleBezierPathParams {
sourceX: number;
Expand Down