-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: arrow label can be aligned left and middle
- Loading branch information
Showing
10 changed files
with
184 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export function MultilineText(props: { | ||
label: string; | ||
verticalPosition: 'top' | 'center' | 'bottom'; | ||
}) { | ||
const { label, verticalPosition } = props; | ||
if (!label) return; | ||
const lines = label.split(/\r?\n/); | ||
const firstDX = | ||
verticalPosition === 'top' | ||
? 1 | ||
: verticalPosition === 'center' | ||
? -lines.length / 2 + 0.5 | ||
: -lines.length; | ||
return ( | ||
<> | ||
{lines.map((line, index) => ( | ||
<tspan key={index} x="0" dy={index === 0 ? `${firstDX}em` : '1em'}> | ||
{line} | ||
</tspan> | ||
))} | ||
</> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { MultilineText } from './MultilineText'; | ||
|
||
export function Text(props: { | ||
x: number; | ||
y: number; | ||
label: string; | ||
horizontalPosition: 'left' | 'center' | 'right'; | ||
verticalPosition: 'top' | 'center' | 'bottom'; | ||
}) { | ||
const { x, y, label, verticalPosition, horizontalPosition } = props; | ||
const transform = `translate(${x},${y})`; | ||
|
||
let textAnchor; | ||
switch (horizontalPosition) { | ||
case 'left': | ||
textAnchor = 'start'; | ||
break; | ||
case 'center': | ||
textAnchor = 'middle'; | ||
break; | ||
case 'right': | ||
textAnchor = 'end'; | ||
break; | ||
default: | ||
textAnchor = 'middle'; | ||
} | ||
|
||
return ( | ||
<> | ||
<text | ||
textAnchor={textAnchor} | ||
transform={transform} | ||
stroke="rgba(255,255,255,0.5)" | ||
strokeWidth="0.5em" | ||
fill="none" | ||
fontSize="14" | ||
> | ||
<MultilineText label={label} verticalPosition={verticalPosition} /> | ||
</text> | ||
<text | ||
textAnchor={textAnchor} | ||
transform={transform} | ||
stroke="none" | ||
fontSize="14" | ||
fill="black" | ||
> | ||
<MultilineText label={label} verticalPosition={verticalPosition} /> | ||
</text> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.