Skip to content

Commit

Permalink
[edge-curve] Adds new option keepLabelUpright
Browse files Browse the repository at this point in the history
This new option is true by default. When it's false, then the labels are
rendered as they were before the previous commit by @benjaminchazelle.
  • Loading branch information
jacomyal committed Aug 29, 2024
1 parent 582a22e commit 2536a3b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/edge-curve/src/edge-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export function createDrawCurvedEdgeLabel<
N extends Attributes = Attributes,
E extends Attributes = Attributes,
G extends Attributes = Attributes,
>({ curvatureAttribute, defaultCurvature }: CreateEdgeCurveProgramOptions): EdgeLabelDrawingFunction<N, E, G> {
>({
curvatureAttribute,
defaultCurvature,
keepLabelUpright = true,
}: CreateEdgeCurveProgramOptions & { keepLabelUpright?: boolean }): EdgeLabelDrawingFunction<N, E, G> {
return (context, edgeData, sourceData, targetData, settings: Settings<N, E, G>): void => {
const size = settings.edgeLabelSize,
curvature = edgeData[curvatureAttribute] || defaultCurvature,
Expand All @@ -50,7 +54,7 @@ export function createDrawCurvedEdgeLabel<
context.font = `${weight} ${size}px ${font}`;

// Computing positions without considering nodes sizes:
const ltr = sourceData.x < targetData.x;
const ltr = !keepLabelUpright || sourceData.x < targetData.x;
let sourceX = ltr ? sourceData.x : targetData.x;
let sourceY = ltr ? sourceData.y : targetData.y;
let targetX = ltr ? targetData.x : sourceData.x;
Expand Down

0 comments on commit 2536a3b

Please sign in to comment.