Skip to content

Commit

Permalink
Merge pull request #237 from reaviz/fix/Label-rotation
Browse files Browse the repository at this point in the history
Fix label rotation
  • Loading branch information
amcdnl authored Apr 30, 2024
2 parents 9c489c4 + 745bc0b commit 81e0cea
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/symbols/Edge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export const Edge: FC<EdgeProps> = ({
() =>
labelVisible &&
label && (
<a.group position={labelPosition as any} rotation={labelRotation}>
<a.group position={labelPosition as any}>
<Label
text={label}
ellipsis={15}
Expand All @@ -330,6 +330,7 @@ export const Edge: FC<EdgeProps> = ({
}
opacity={selectionOpacity}
fontSize={theme.edge.label.fontSize}
rotation={labelRotation}
/>
</a.group>
),
Expand Down
11 changes: 9 additions & 2 deletions src/symbols/Label.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC, useMemo } from 'react';
import { Billboard, Text } from 'glodrei';
import { Color, ColorRepresentation } from 'three';
import { Color, ColorRepresentation, Euler } from 'three';
import ellipsize from 'ellipsize';

export interface LabelProps {
Expand Down Expand Up @@ -44,6 +44,11 @@ export interface LabelProps {
* Whether the label is active ( dragging, hover, focus ).
*/
active?: boolean;

/**
* Rotation of the label.
*/
rotation?: Euler | [number, number, number];
}

export const Label: FC<LabelProps> = ({
Expand All @@ -54,7 +59,8 @@ export const Label: FC<LabelProps> = ({
opacity,
stroke,
active,
ellipsis
ellipsis,
rotation
}) => {
const shortText = ellipsis && !active ? ellipsize(text, ellipsis) : text;
const normalizedColor = useMemo(() => new Color(color), [color]);
Expand All @@ -76,6 +82,7 @@ export const Label: FC<LabelProps> = ({
depthOffset={0}
maxWidth={100}
overflowWrap="break-word"
rotation={rotation}
>
{shortText}
</Text>
Expand Down
3 changes: 2 additions & 1 deletion src/symbols/edges/Edge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const Edge: FC<EdgeProps> = ({
return (
<group>
{labelVisible && label && (
<a.group position={labelPosition as any} rotation={labelRotation}>
<a.group position={labelPosition as any}>
<Label
text={label}
ellipsis={15}
Expand All @@ -156,6 +156,7 @@ export const Edge: FC<EdgeProps> = ({
color={color}
opacity={opacity}
fontSize={theme.edge.label.fontSize}
rotation={labelRotation}
/>
</a.group>
)}
Expand Down

0 comments on commit 81e0cea

Please sign in to comment.