FShape

GitHubEdit on GitHub
packages@univerjs-pro/sheets-shape-ui

The facade class for sheet shape builder and shape instance operations.

APIs

setPosition

Sets the position, changing where the shape appears on the sheet.

Signature

setPosition(anchorRowPos: number, anchorColPos: number, rowOffset: number, columnOffset: number): this

Parameters

  • anchorRowPos (number) - The row index where the shape top edge is anchored (0-indexed).
  • anchorColPos (number) - The column index where the shape left edge is anchored (0-indexed).
  • rowOffset (number) - The pixel offset from the anchor row.
  • columnOffset (number) - The pixel offset from the anchor column.

Returns

  • (this) - The builder itself for chaining.

setAbsolutePosition

Sets the position by absolute pixel coordinates.

Signature

setAbsolutePosition(x: number, y: number): this

Parameters

  • x (number) - The x-coordinate of the shape top-left corner.
  • y (number) - The y-coordinate of the shape top-left corner.

Returns

  • (this) - The builder itself for chaining.

setShapeType

Sets the type of the shape.

Signature

setShapeType(shapeType: ShapeTypeEnum): this

Parameters

  • shapeType (ShapeTypeEnum) - The target shape type, available from univerAPI.Enum.ShapeTypeEnum.

Returns

  • (this) - The builder itself for chaining.

setShapeSolidFill

Sets a solid fill style for the shape.

Signature

setShapeSolidFill(color: string, opacity?: number): this

Parameters

  • color (string) - Fill color, e.g. #ff0000.
  • opacity (number, optional) - Fill opacity in range 0 to 1.

Returns

  • (this) - The builder itself for chaining.

setShapeGradientFill

Sets a gradient fill style for the shape.

Signature

setShapeGradientFill(shapeGradientType: ShapeGradientTypeEnum, colorStops: Array<{ position: number; color: string }>, gradientAngle?: number): this

Parameters

  • shapeGradientType (ShapeGradientTypeEnum) - Gradient type, e.g. linear/radial.
  • colorStops (Array<{ position: number; color: string }> ) - Gradient stops, each with position (0~1) and color.
  • gradientAngle (number, optional) - Gradient angle in degrees.

Returns

  • (this) - The builder itself for chaining.

setNoneFill

Removes fill and makes the shape transparent.

Signature

setNoneFill(): this

Returns

  • (this) - The builder itself for chaining.

setStrokeColor

Sets stroke color of the shape.

Signature

setStrokeColor(color: string): this

Parameters

  • color (string) - Stroke color, e.g. #ff0000.

Returns

  • (this) - The builder itself for chaining.

setStrokeWidth

Sets stroke width of the shape.

Signature

setStrokeWidth(width: number): this

Parameters

  • width (number) - Stroke width in pixels.

Returns

  • (this) - The builder itself for chaining.

setStrokeLineDashType

Sets stroke dash style.

Signature

setStrokeLineDashType(lineDashType: ShapeLineDashEnum): this

Parameters

  • lineDashType (ShapeLineDashEnum) - Stroke dash style.

Returns

  • (this) - The builder itself for chaining.

setStrokeLineJoinType

Sets stroke line join style.

Signature

setStrokeLineJoinType(lineJoinType: ShapeLineJoinEnum): this

Parameters

  • lineJoinType (ShapeLineJoinEnum) - Line join style.

Returns

  • (this) - The builder itself for chaining.

setStrokeLineCapType

Sets stroke line cap style.

Signature

setStrokeLineCapType(lineCapType: ShapeLineCapEnum): this

Parameters

  • lineCapType (ShapeLineCapEnum) - Line cap style.

Returns

  • (this) - The builder itself for chaining.

setStrokeOpacity

Sets stroke opacity.

Signature

setStrokeOpacity(opacity: number): this

Parameters

  • opacity (number) - Opacity in range 0 to 1.

Returns

  • (this) - The builder itself for chaining.

setStrokeLineType

Sets stroke line type.

Signature

setStrokeLineType(lineType: ShapeLineTypeEnum): this

Parameters

  • lineType (ShapeLineTypeEnum) - Line type, available from univerAPI.Enum.ShapeLineTypeEnum.

Returns

  • (this) - The builder itself for chaining.

setWidth

Sets shape width in pixels.

Signature

setWidth(width: number): this

Parameters

  • width (number) - Width in pixels.

Returns

  • (this) - The builder itself for chaining.

setHeight

Sets shape height in pixels.

Signature

setHeight(height: number): this

Parameters

  • height (number) - Height in pixels.

Returns

  • (this) - The builder itself for chaining.

isLineShape

Returns whether this shape is a line/connector shape.

Signature

isLineShape(): boolean

Returns

  • (boolean) - true if this is a connector shape; otherwise false.

getConnectionSites

Returns connection sites (attachment points) for this shape.

Signature

getConnectionSites(): Array<{ x: number; y: number; index: number; ang: number }>

Returns

  • Array<{ x: number; y: number; index: number; ang: number }> - Local connection sites.
  • x (number) - Local x-coordinate.
  • y (number) - Local y-coordinate.
  • index (number) - Site index.
  • ang (number) - Site angle in 1/60000 degree units.

getAdjustPoints

Returns adjust handles for this shape.

Signature

getAdjustPoints(): Array<{ x: number; y: number; adjName: string }>

Returns

  • Array<{ x: number; y: number; adjName: string }> - Local adjust points.
  • x (number) - Local x-coordinate.
  • y (number) - Local y-coordinate.
  • adjName (string) - Adjust parameter name.

getConnectorLinePoints

Returns connector line points for connector shapes.

Signature

getConnectorLinePoints(): IShapePoint[]

Returns

  • (IShapePoint[]) - Connector points in local coordinates. Returns empty array if not a connector.

getStartConnectInfo

Returns start connection info for connector shapes.

Signature

getStartConnectInfo(): IShapeRelationItem | null

Returns

  • (IShapeRelationItem | null) - Start connection target info, or null if not connected.

getEndConnectInfo

Returns end connection info for connector shapes.

Signature

getEndConnectInfo(): IShapeRelationItem | null

Returns

  • (IShapeRelationItem | null) - End connection target info, or null if not connected.

build

Builds a shape payload for insert/update.

Signature

build(): IShapeBuilderInfo

Returns

  • (IShapeBuilderInfo) - Shape builder info that can be used by insertShape or updateShape.

getShapeId

Returns the unique shape id.

Signature

getShapeId(): string

Returns

  • (string) - Shape id.

getShapeType

Returns the shape type.

Signature

getShapeType(): ShapeTypeEnum | undefined

Returns

  • (ShapeTypeEnum | undefined) - Current shape type.

getShapeData

Returns shape style data (fill/stroke/etc).

Signature

getShapeData(): IShapeData

Returns

  • (IShapeData) - Shape data object.

getPosition

Returns absolute position in pixels.

Signature

getPosition(): { x: number; y: number }

Returns

  • ({ x: number; y: number }) - Position of shape top-left corner.

getSize

Returns size in pixels.

Signature

getSize(): { width: number; height: number }

Returns

  • ({ width: number; height: number }) - Shape width and height.