@maxgraph/core
    Preparing search index...

    Class Shape

    Base class for all shapes. A shape in maxGraph is a separate implementation for SVG, VML and HTML. Which implementation to use is controlled by the dialect property which is assigned from within the CellRenderer when the shape is created. The dialect must be assigned for a shape, and it does normally depend on the browser and the configuration of the graph (see maxGraph rendering hint).

    For each supported shape in SVG and VML, a corresponding shape exists in maxGraph, namely for text, image, rectangle, rhombus, ellipse and polyline. The other shapes are a combination of these shapes (e.g. label and swimlane) or they consist of one or more (filled) path objects (e.g. actor and cylinder). The HTML implementation is optional but may be required for a HTML-only view of the graph.

    A custom shape is a class extending one of the exported shape classes, registered in ShapeRegistry under a name, then referenced by that name as the shape property of a cell style.

    Choose the base class according to what is painted:

    • Shape itself for a vertex made of a single filled and stroked path: override paintVertexShape(c, x, y, w, h) and call c.translate(x, y), c.begin(), the path drawing operations, then c.fillAndStroke().
    • AbstractPathShape for the same single path vertex, without that boilerplate: override redrawPath(c, x, y, w, h) with the drawing operations only.
    • CylinderShape for a filled area plus a stroke only overlay path: override redrawPath(c, x, y, w, h, isForeground).
    • RectangleShape (override paintBackground or paintForeground) or EllipseShape (override paintVertexShape) to decorate an existing shape.
    • For edges, ConnectorShape, PolylineShape, ArrowShape or ArrowConnectorShape: override paintEdgeShape(c, pts).

    The constructor must take no argument. CellRenderer.createShape instantiates the registered class with new shapeConstructor(), for vertices and edges alike, so the legacy (bounds, fill, stroke, strokeWidth) parameters still declared by several built-in shapes are never passed on that path. The renderer populates the instance afterwards: Shape.apply sets Shape.state, Shape.style and the fields derived from the style, then CellRenderer.redrawShape sets Shape.bounds for a vertex, Shape.points for an edge, and Shape.scale.

    Consequently, the cell style is only available at paint time, through Shape.style, which is CellStateStyle | null and must be guarded.

    class CustomShape extends Shape {
    override paintVertexShape(
    c: AbstractCanvas2D,
    x: number,
    y: number,
    w: number,
    h: number
    ): void {
    const notch = this.style?.arcSize ?? 10;
    c.translate(x, y);
    c.begin();
    c.moveTo(0, 0);
    c.lineTo(w - notch, 0);
    c.lineTo(w, notch);
    c.lineTo(w, h);
    c.lineTo(0, h);
    c.close();
    c.fillAndStroke();
    }
    }

    ShapeRegistry.add('customShape', CustomShape);

    graph.insertVertex({ value: 'custom', position: [10, 10], size: [100, 60], style: { shape: 'customShape' } });

    See the Extend maxGraph page of the documentation for a complete walkthrough.

    Hierarchy (View Summary)

    Index
    antiAlias: boolean = true

    Rendering hint for configuring the canvas.

    boundingBox: Rectangle | null = null

    Contains the bounding box of the shape, that is, the smallest rectangle that includes all pixels of the shape.

    bounds: Rectangle | null = null

    Holds the Rectangle that specifies the bounds of this shape.

    cursor: string = ''
    dialect: DialectValue | null = null

    Holds the dialect in which the shape is to be painted.

    direction: DirectionValue = 'east'
    endArrow: string = NONE
    endSize: number = 1
    fill: string = NONE
    fillOpacity: number = 100
    flipH: boolean = false
    flipV: boolean = false
    glass: boolean = false
    gradient: string = NONE
    gradientDirection: DirectionValue = 'east'
    image: ImageBox | null = null
    imageSrc: string | null = null
    indicator: Shape | null = null
    indicatorColor: string = NONE
    indicatorDirection: DirectionValue = 'east'
    indicatorGradientColor: string = NONE
    indicatorImageSrc: string | null = null
    indicatorShape: typeof Shape | null = null
    indicatorStrokeColor: string = NONE
    isDashed: boolean = false
    isRounded: boolean = false
    isShadow: boolean = false
    minSvgStrokeWidth: number = 1

    Minimum stroke width for SVG output.

    node: SVGGElement

    Holds the outermost DOM node that represents this shape.

    oldGradients: GradientMap = {}
    opacity: number = 100

    CellHighlight

    originalPointerEvents: boolean | null = null
    outline: boolean = false

    Specifies if the shape should be drawn as an outline. This disables all fill colors and can be used to disable other drawing states that should not be painted for outlines. Default is false. This should be set before calling .

    overlay: CellOverlay | null = null
    pointerEvents: boolean = true

    Specifies if pointer events should be handled. Default is true.

    points: (Point | null)[] = []

    Holds the array of that specify the points of this shape.

    preserveImageAspect: boolean = false

    Switch to preserve image aspect.

    false
    
    rotation: number = 0
    scale: number = 1

    Holds the scale in which the shape is being painted.

    shapePointerEvents: boolean = false

    Specifies if pointer events outside of shape should be handled. Default is false.

    spacing: number = 0
    startArrow: string = NONE
    startSize: number = 1
    state: CellState | null = null

    Optional reference to the corresponding .

    stencil: StencilShape | null = null

    Holds the StencilShape that defines the shape.

    stencilPointerEvents: boolean = false

    Specifies if pointer events outside of stencils should be handled. Default is false. Set this to true for backwards compatibility with the 1.x branch.

    stroke: string = NONE
    strokeOpacity: number = 100
    strokeWidth: number = 1
    style: CellStateStyle | null = null

    Optional reference to the style of the corresponding .

    svgPointerEvents: string = 'all'

    Specifies if pointer events should be handled. Default is true.

    svgStrokeTolerance: number = 8

    Event-tolerance for SVG strokes (in px). This is only passed to the canvas in createSvgCanvas if pointerEvents is true.

    8
    
    useSvgBoundingBox: boolean = true

    Allows to use the SVG bounding box in SVG. Default is false for performance reasons.

    verticalTextRotation: number = 0
    visible: boolean = true

    Specifies if the shape is visible. Default is true.

    • Paints the given points with rounded corners.

      Parameters

      • c: AbstractCanvas2D
      • pts: Point[]
      • rounded: boolean = false
      • arcSize: number
      • close: boolean = false
      • exclude: number[] = []
      • initialMove: boolean = true

      Returns void

    • Applies the style of the given to the shape. This implementation assigns the following styles to local fields:

      • <'fillColor'> => fill
      • <'gradientColor'> => gradient
      • <'gradientDirection'> => gradientDirection
      • <'opacity'> => opacity
      • Constants#STYLE_FILL_OPACITY => fillOpacity
      • Constants#STYLE_STROKE_OPACITY => strokeOpacity
      • <'strokeColor'> => stroke
      • <'strokeWidth'> => strokewidth
      • <'shadow'> => isShadow
      • <'dashed'> => isDashed
      • <'spacing'> => spacing
      • <'startSize'> => startSize
      • <'endSize'> => endSize
      • <'rounded'> => isRounded
      • <'startArrow'> => startArrow
      • <'endArrow'> => endArrow
      • <'rotation'> => rotation
      • <'direction'> => direction
      • <'glass'> => glass

      This keeps a reference to the