GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • @maxgraph/core

This view

  • Original page
  • New address

GeezerVison is showing maxgraph.github.io — Shape | @maxgraph/core

  • Shape

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.

Custom Shapes

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)

  • Shape
    • StencilShape
    • AbstractPathShape
    • SwimlaneShape
    • TextShape
    • ArrowShape
    • ArrowConnectorShape
    • LineShape
    • PolylineShape
    • CylinderShape
    • DoubleEllipseShape
    • EllipseShape
    • RectangleShape
    • RhombusShape
  • Defined in view/shape/Shape.ts:116
Index

Constructors

constructor

Properties

antiAlias boundingBox bounds cursor dialect direction endArrow endSize fill fillOpacity flipH flipV glass gradient gradientDirection image imageSrc indicator indicatorColor indicatorDirection indicatorGradientColor indicatorImageSrc indicatorShape indicatorStrokeColor isDashed isRounded isShadow minSvgStrokeWidth node oldGradients opacity originalPointerEvents outline overlay pointerEvents points preserveImageAspect rotation scale shapePointerEvents spacing startArrow startSize state stencil stencilPointerEvents stroke strokeOpacity strokeWidth style svgPointerEvents svgStrokeTolerance useSvgBoundingBox verticalTextRotation visible

Methods

addPoints afterPaint apply augmentBoundingBox beforePaint checkBounds clear configureCanvas create createBoundingBox createCanvas createSvgCanvas createTransparentSvgRectangle destroy destroyCanvas getArcSize getBaseArcSize getCursor getGradientBounds getLabelBounds getLabelMargins getRotation getShapeRotation getSvgScreenOffset getTextRotation init initStyles isHtmlAllowed isPaintBoundsInverted isRoundable paint paintBackground paintEdgeShape paintForeground paintGlassEffect paintVertexShape redraw redrawHtmlShape redrawShape releaseSvgGradients resetStyles setCursor setTransparentBackgroundImage updateBoundingBox updateBoundsFromPoints updateTransform

Constructors

constructor

  • new Shape(stencil?: StencilShape | null): Shape

    Parameters

    • stencil: StencilShape | null = null

    Returns Shape

    • Defined in view/shape/Shape.ts:294

Properties

antiAlias

antiAlias: boolean = true

Rendering hint for configuring the canvas.

  • Defined in view/shape/Shape.ts:187

boundingBox

boundingBox: Rectangle | null = null

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

  • Defined in view/shape/Shape.ts:223

bounds

bounds: Rectangle | null = null

Holds the Rectangle that specifies the bounds of this shape.

  • Defined in view/shape/Shape.ts:197

cursor

cursor: string = ''
  • Defined in view/shape/Shape.ts:166

dialect

dialect: DialectValue | null = null

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

  • Defined in view/shape/Shape.ts:177

direction

direction: DirectionValue = 'east'
  • Defined in view/shape/Shape.ts:154

endArrow

endArrow: string = NONE
  • Defined in view/shape/Shape.ts:152

endSize

endSize: number = 1
  • Defined in view/shape/Shape.ts:148

fill

fill: string = NONE
  • Defined in view/shape/Shape.ts:130

fillOpacity

fillOpacity: number = 100
  • Defined in view/shape/Shape.ts:136

flipH

flipH: boolean = false
  • Defined in view/shape/Shape.ts:156

flipV

flipV: boolean = false
  • Defined in view/shape/Shape.ts:158

glass

glass: boolean = false
  • Defined in view/shape/Shape.ts:172

gradient

gradient: string = NONE
  • Defined in view/shape/Shape.ts:132

gradientDirection

gradientDirection: DirectionValue = 'east'
  • Defined in view/shape/Shape.ts:134

image

image: ImageBox | null = null
  • Defined in view/shape/Shape.ts:280

imageSrc

imageSrc: string | null = null
  • Defined in view/shape/Shape.ts:282

indicator

indicator: Shape | null = null
  • Defined in view/shape/Shape.ts:123

indicatorColor

indicatorColor: string = NONE
  • Defined in view/shape/Shape.ts:284

indicatorDirection

indicatorDirection: DirectionValue = 'east'
  • Defined in view/shape/Shape.ts:290

indicatorGradientColor

indicatorGradientColor: string = NONE
  • Defined in view/shape/Shape.ts:288

indicatorImageSrc

indicatorImageSrc: string | null = null
  • Defined in view/shape/Shape.ts:292

indicatorShape

indicatorShape: typeof Shape | null = null
  • Defined in view/shape/Shape.ts:124

indicatorStrokeColor

indicatorStrokeColor: string = NONE
  • Defined in view/shape/Shape.ts:286

isDashed

isDashed: boolean = false
  • Defined in view/shape/Shape.ts:128

isRounded

isRounded: boolean = false
  • Defined in view/shape/Shape.ts:162

isShadow

isShadow: boolean = false
  • Defined in view/shape/Shape.ts:160

minSvgStrokeWidth

minSvgStrokeWidth: number = 1

Minimum stroke width for SVG output.

  • Defined in view/shape/Shape.ts:192

node

node: SVGGElement

Holds the outermost DOM node that represents this shape.

  • Defined in view/shape/Shape.ts:207

oldGradients

oldGradients: GradientMap = {}
  • Defined in view/shape/Shape.ts:170

opacity

opacity: number = 100

See

CellHighlight

  • Defined in view/shape/Shape.ts:127

originalPointerEvents

originalPointerEvents: boolean | null = null
  • Defined in view/shape/Shape.ts:242

outline

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 .

  • Defined in view/shape/Shape.ts:267

overlay

overlay: CellOverlay | null = null
  • Defined in view/shape/Shape.ts:122

pointerEvents

pointerEvents: boolean = true

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

  • Defined in view/shape/Shape.ts:240

points

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

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

  • Defined in view/shape/Shape.ts:202

preserveImageAspect

preserveImageAspect: boolean = false

Switch to preserve image aspect.

Default

false
  • Defined in view/shape/Shape.ts:121

rotation

rotation: number = 0
  • Defined in view/shape/Shape.ts:164

scale

scale: number = 1

Holds the scale in which the shape is being painted.

  • Defined in view/shape/Shape.ts:182

shapePointerEvents

shapePointerEvents: boolean = false

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

  • Defined in view/shape/Shape.ts:253

spacing

spacing: number = 0
  • Defined in view/shape/Shape.ts:144

startArrow

startArrow: string = NONE
  • Defined in view/shape/Shape.ts:150

startSize

startSize: number = 1
  • Defined in view/shape/Shape.ts:146

state

state: CellState | null = null

Optional reference to the corresponding .

  • Defined in view/shape/Shape.ts:212

stencil

stencil: StencilShape | null = null

Holds the StencilShape that defines the shape.

  • Defined in view/shape/Shape.ts:228

stencilPointerEvents

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.

  • Defined in view/shape/Shape.ts:259

stroke

stroke: string = NONE
  • Defined in view/shape/Shape.ts:140

strokeOpacity

strokeOpacity: number = 100
  • Defined in view/shape/Shape.ts:138

strokeWidth

strokeWidth: number = 1
  • Defined in view/shape/Shape.ts:142

style

style: CellStateStyle | null = null

Optional reference to the style of the corresponding .

  • Defined in view/shape/Shape.ts:217

svgPointerEvents

svgPointerEvents: string = 'all'

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

  • Defined in view/shape/Shape.ts:247

svgStrokeTolerance

svgStrokeTolerance: number = 8

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

Default

8
  • Defined in view/shape/Shape.ts:235

useSvgBoundingBox

useSvgBoundingBox: boolean = true

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

  • Defined in view/shape/Shape.ts:278

verticalTextRotation

verticalTextRotation: number = 0
  • Defined in view/shape/Shape.ts:168

visible

visible: boolean = true

Specifies if the shape is visible. Default is true.

  • Defined in view/shape/Shape.ts:272

Methods

addPoints

  • addPoints(
        c: AbstractCanvas2D,
        pts: Point[],
        rounded?: boolean,
        arcSize: number,
        close?: boolean,
        exclude?: number[],
        initialMove?: boolean,
    ): void

    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

    • Defined in view/shape/Shape.ts:839

afterPaint

  • afterPaint(c: AbstractCanvas2D): void

    Invokes after paint was called.

    Parameters

    • c: AbstractCanvas2D

    Returns void

    • Defined in view/shape/Shape.ts:589

apply

  • apply(state: CellState): 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

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.