Skip to content

Control positioning of ReferenceLabel #2541

Description

@timscott
  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

There seems to be no way to accurately prevent a label for a ReferenceLine from exceeding the bounds of the view box. The viewBox argument to the custom function always has a width: 0.

Screen Shot 2021-05-12 at 11 14 33 AM

The following screen shot shows how my label renders when it's positioned toward the right bound of the box. If I knew the width of the box I could shift it left so that the whole label is visible.

Screen Shot 2021-05-12 at 11 12 21 AM

Here's the markup for the actual label:

<g>
  <rect
    x={rectX}
    y={y}
    fill={markerFill}
    stroke={markerStroke}
    width={rectWidth}
    height={rectHeight}
    rx={3}
    ry={3}
  />
  <text
    x={rectX + rectWidth / 2}
    y={y + rectHeight / 2}
    dominantBaseline="middle"
    textAnchor="middle"
    fill={markerText}
  >
    {text}
  </text>
</g>

The problem is that I have no way to calculate the value of rectX since I do not know how wide the viewBox is.

What does the proposed API look like?

Pass the actual width of the view box to the label function.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions