Skip to content

Support adding text labels to lines and shapes #6430

Closed
@emilykl

Description

@emilykl

Text on Shapes feature

Expand the Shape API to support adding a text label to any line or shape.

Labels can be styled similarly to text annotations, and support options for setting their position relative to the shape or line.

Proposed API

Here is the proposed API for Text on Shapes, as discussed with @alexcjohnson :

  • label : Top-level property to be added to shape, holding all label options
    • text : The label’s text
    • font : The label’s font properties (same properties as for Annotation)
      • color
      • family
      • size
    • position : The label’s position relative to the shape. Possible values: [ left | center | right ] [ top | middle | bottom ] ; OR [ start | end ] for lines
    • textangle : Rotation angle of the label. Possible values : number between -180 and 180 ; OR [ auto ] for lines (same angle as line)
    • xanchor : The x-component of the anchor point on the label used to determine position (in the pre-rotated reference frame). Possible values : [ left | center | right ]
    • yanchor : The y-component of the anchor point on the label used to determine position (in the pre-rotated reference frame). Possible values : [ top | middle | bottom ]
    • padding : Offset of label relative to xanchor and yanchor (symmetrical on all sides)

cc @alexcjohnson @archmoj

Revised 10 Jan 2023: Changed angle property name to textangle

To-dos

  • Add above properties to shape attributes
  • Implement basic functionality of rendering text relative to shape position
  • Properly handle re-render on pan/zoom
  • Properly handle re-render on shape move
  • Implement xanchor
  • Implement yanchor
  • Implement padding
  • Implement position
  • Implement textangle
    • Numeric angles
    • auto angle for lines
  • Implement font
  • Correctly handle multiline labels
  • Correctly handle clipping outside plot area
  • Properly set defaults for all properties
  • Add image test
  • Add Jasmine test

Partnership

Development of this feature is sponsored by Volkswagen's Center of Excellence for Battery Systems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions