Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ For more details on the contents of a release, see [the GitHub release page] (ht

_**Note:** Yet to be released breaking changes appear here._

**Breaking Changes**:
- the `SHAPE` enum has been removed. Use values of the `ShapeValue` type instead.

## 0.19.0

Release date: `2025-04-30`
Expand Down
42 changes: 30 additions & 12 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,25 +958,43 @@ export type StylePortConstraint = DirectionValue | DirectionValue[];

/**
* Names used to register the shapes provided out-of-the-box by maxGraph with {@link CellRenderer.registerShape}.
* They can be used as a value for {@link CellStateStyle.shape}.
*
* @category Style
*/
export type ShapeValue =
| 'rectangle'
| 'ellipse'
| 'doubleEllipse'
| 'rhombus'
| 'line'
| 'image'
/** Name under which {@link ActorShape} is registered by default. */
| 'actor'
/** Name under which {@link ArrowShape} is registered by default. */
| 'arrow'
/** Name under which {@link ArrowConnectorShape} is registered by default. */
| 'arrowConnector'
| 'label'
/** Name under which {@link CloudShape} is registered by default. */
| 'cloud'
/** Name under which {@link ConnectorShape} is registered by default. */
| 'connector'
/** Name under which {@link CylinderShape} is registered by default. */
| 'cylinder'
/** Name under which {@link DoubleEllipseShape} is registered by default. */
| 'doubleEllipse'
/** Name under which {@link EllipseShape} is registered by default. */
| 'ellipse'
/** Name under which {@link HexagonShape} is registered by default. */
| 'hexagon'
/** Name under which {@link ImageShape} is registered by default. */
| 'image'
/** Name under which {@link LabelShape} is registered by default. */
| 'label'
/** Name under which {@link LineShape} is registered by default. */
| 'line'
/** Name under which {@link RectangleShape} is registered by default. */
| 'rectangle'
/** Name under which {@link RhombusShape} is registered by default. */
| 'rhombus'
/** Name under which {@link SwimlaneShape} is registered by default. */
| 'swimlane'
| 'connector'
| 'actor'
| 'cloud'
| 'triangle'
| 'hexagon';
/** Name under which {@link TriangleShape} is registered by default. */
| 'triangle';

/**
* {@link ShapeValue} with support for extensions.
Expand Down
86 changes: 0 additions & 86 deletions packages/core/src/util/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,89 +545,3 @@ export enum PERIMETER {
HEXAGON = 'hexagonPerimeter',
TRIANGLE = 'trianglePerimeter',
}

/**
* Names used to register the shapes provided out-of-the-box by maxGraph with {@link CellRenderer.registerShape}.
* Can be used as a value for {@link CellStateStyle.shape}.
*/
export enum SHAPE {
/**
* Name under which {@link RectangleShape} is registered.
*/
RECTANGLE = 'rectangle',

/**
* Name under which {@link Ellipse} is registered.
*/
ELLIPSE = 'ellipse',

/**
* Name under which {@link DoubleEllipse} is registered.
*/
DOUBLE_ELLIPSE = 'doubleEllipse',

/**
* Name under which {@link Rhombus} is registered.
*/
RHOMBUS = 'rhombus',

/**
* Name under which {@link LineShape} is registered.
*/
LINE = 'line',

/**
* Name under which {@link ImageShape} is registered.
*/
IMAGE = 'image',

/**
* Name under which {@link ArrowShape} is registered.
*/
ARROW = 'arrow',

/**
* Name under which {@link ArrowConnectorShape} is registered.
*/
ARROW_CONNECTOR = 'arrowConnector',

/**
* Name under which {@link Label} is registered.
*/
LABEL = 'label',

/**
* Name under which {@link Cylinder} is registered.
*/
CYLINDER = 'cylinder',

/**
* Name under which {@link Swimlane} is registered.
*/
SWIMLANE = 'swimlane',

/**
* Name under which {@link ConnectorShape} is registered.
*/
CONNECTOR = 'connector',

/**
* Name under which {@link Actor} is registered.
*/
ACTOR = 'actor',

/**
* Name under which {@link Cloud} is registered.
*/
CLOUD = 'cloud',

/**
* Name under which {@link Triangle} is registered.
*/
TRIANGLE = 'triangle',

/**
* Name under which {@link Hexagon} is registered.
*/
HEXAGON = 'hexagon',
}
33 changes: 16 additions & 17 deletions packages/core/src/view/cell/register-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import DoubleEllipseShape from '../geometry/node/DoubleEllipseShape';
import SwimlaneShape from '../geometry/node/SwimlaneShape';
import ImageShape from '../geometry/node/ImageShape';
import LabelShape from '../geometry/node/LabelShape';
import { SHAPE } from '../../util/Constants';

let isDefaultElementsRegistered = false;

Expand All @@ -46,22 +45,22 @@ let isDefaultElementsRegistered = false;
export function registerDefaultShapes() {
if (!isDefaultElementsRegistered) {
const shapesToRegister: [ShapeValue, ShapeConstructor][] = [
[SHAPE.ACTOR, ActorShape],
[SHAPE.ARROW, ArrowShape],
[SHAPE.ARROW_CONNECTOR, ArrowConnectorShape],
[SHAPE.CLOUD, CloudShape],
[SHAPE.CONNECTOR, ConnectorShape],
[SHAPE.CYLINDER, CylinderShape],
[SHAPE.DOUBLE_ELLIPSE, DoubleEllipseShape],
[SHAPE.ELLIPSE, EllipseShape],
[SHAPE.HEXAGON, HexagonShape],
[SHAPE.IMAGE, ImageShape],
[SHAPE.LABEL, LabelShape],
[SHAPE.LINE, LineShape],
[SHAPE.RECTANGLE, RectangleShape],
[SHAPE.RHOMBUS, RhombusShape],
[SHAPE.SWIMLANE, SwimlaneShape],
[SHAPE.TRIANGLE, TriangleShape],
['actor', ActorShape],
['arrow', ArrowShape],
['arrowConnector', ArrowConnectorShape],
['cloud', CloudShape],
['connector', ConnectorShape],
['cylinder', CylinderShape],
['doubleEllipse', DoubleEllipseShape],
['ellipse', EllipseShape],
['hexagon', HexagonShape],
['image', ImageShape],
['label', LabelShape],
['line', LineShape],
['rectangle', RectangleShape],
['rhombus', RhombusShape],
['swimlane', SwimlaneShape],
['triangle', TriangleShape],
];
for (const [shapeName, shapeClass] of shapesToRegister) {
CellRenderer.registerShape(shapeName, shapeClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { ColorValue } from '../../../types';
*
* The shape is used to represent edges, not vertices.
*
* By default, this shape is registered under {@link SHAPE.ARROW_CONNECTOR} in {@link CellRenderer}.
* This shape is registered under `arrowConnector` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Edge Shapes
*/
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/view/geometry/edge/ArrowShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import Point from '../Point';
import { ColorValue } from '../../../types';

/**
* Extends {@link Shape} to implement an arrow shape. The shape is used to represent edges, not vertices.
* Extends {@link Shape} to implement an arrow shape.
*
* By default, this shape is registered under {@link SHAPE.ARROW} in {@link CellRenderer}.
* The shape is used to represent edges, not vertices.
*
* This shape is registered under `arrow` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Edge Shapes
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/view/geometry/edge/ConnectorShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { ArrowValue, ColorValue } from '../../../types';
*
* The shape is used to represent edges, not vertices.
*
* This shape is registered under {@link SHAPE.CONNECTOR} in {@link CellRenderer}.
* This shape is registered under `connector` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Edge Shapes
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/view/geometry/edge/LineShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ColorValue } from '../../../types';
*
* The shape is used to represent edges, not vertices.
*
* By default, this shape is registered under {@link SHAPE.LINE} in {@link CellRenderer}.
* This shape is registered under `line` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Edge Shapes
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/view/geometry/edge/PolylineShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ColorValue } from '../../../types';
*
* The shape is used to represent edges, not vertices.
*
* By default, this shape is not registered in {@link CellRenderer}.
* This shape is **NOT** registered in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Edge Shapes
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/view/geometry/node/ActorShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { NONE } from '../../../util/Constants';

/**
* Extends {@link Shape} to implement an actor shape.
* This shape is registered by default under {@link SHAPE.ACTOR} in {@link CellRenderer}.
*
* This shape is registered under `actor` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* If a custom shape with one filled area is needed, then this shape's {@link redrawPath} method should be overridden
* like in the following example:
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/view/geometry/node/CloudShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import Rectangle from '../Rectangle';

/**
* Extends {@link ActorShape} to implement a cloud shape.
* This shape is registered by default under {@link SHAPE.CLOUD} in {@link CellRenderer}.
*
* This shape is registered under `cloud` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Vertex Shapes
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/view/geometry/node/CylinderShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { NONE } from '../../../util/Constants';

/**
* Extends {@link Shape} to implement a cylinder shape.
* This shape is registered by default under {@link SHAPE.CYLINDER} in {@link CellRenderer}.
*
* This shape is registered under `cylinder` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* If a custom shape with one filled area and an overlay path is needed, then this shape's {@link redrawPath} should be overridden.
*
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/view/geometry/node/DoubleEllipseShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import AbstractCanvas2D from '../../../view/canvas/AbstractCanvas2D';

/**
* Extends {@link Shape} to implement a double ellipse shape.
* This shape is registered by default under {@link SHAPE.DOUBLE_ELLIPSE} in {@link CellRenderer}.
*
* This shape is registered under `doubleEllipse` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* If a custom shape is needed to only fill the inner ellipse, then this shape's {@link paintVertexShape} method should be overridden
* like in the following example:
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/view/geometry/node/EllipseShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import Rectangle from '../Rectangle';

/**
* Extends {@link Shape} to implement an ellipse shape.
* This shape is registered by default under {@link SHAPE.ELLIPSE} in {@link CellRenderer}.
*
* This shape is registered under `ellipse` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Vertex Shapes
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/view/geometry/node/HexagonShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import AbstractCanvas2D from '../../canvas/AbstractCanvas2D';
/**
* Implementation of the hexagon shape.
*
* This shape is registered under `hexagon` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Vertex Shapes
*/
class HexagonShape extends ActorShape {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/view/geometry/node/ImageShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import { ColorValue } from '../../../types';

/**
* Extends {@link RectangleShape} to implement an image shape.
* This shape is registered by default under {@link SHAPE.IMAGE} in {@link CellRenderer}.
*
* This shape is registered under `image` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Vertex Shapes
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/view/geometry/node/LabelShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import AbstractCanvas2D from '../../canvas/AbstractCanvas2D';

/**
* Extends {@link RectangleShape} to implement an image shape with a label.
* This shape is registered by default under {@link SHAPE.LABEL} in {@link CellRenderer}.
*
* This shape is registered under `label` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Vertex Shapes
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/view/geometry/node/RectangleShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { ColorValue } from '../../../types';

/**
* Extends {@link Shape} to implement a rectangle shape.
* This shape is registered by default under {@link SHAPE.RECTANGLE} in {@link CellRenderer}.
*
* This shape is registered under `rectangle` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Vertex Shapes
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/view/geometry/node/RhombusShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import AbstractCanvas2D from '../../canvas/AbstractCanvas2D';

/**
* Extends {@link Shape} to implement a rhombus (aka diamond) shape.
* This shape is registered by default under {@link SHAPE.RHOMBUS} in {@link CellRenderer}.
*
* This shape is registered under `rhombus` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Vertex Shapes
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/view/geometry/node/SwimlaneShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import AbstractCanvas2D from '../../canvas/AbstractCanvas2D';

/**
* Extends {@link Shape} to implement a swimlane shape.
* This shape is registered by default under {@link SHAPE.SWIMLANE} in {@link CellRenderer}.
*
* This shape is registered under `swimlane` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* Use:
* - {@link CellStateStyle.startSize} to define the size of the title region,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/view/geometry/node/TextShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import { matchBinaryMask } from '../../../internal/utils';
/**
* Extends {@link Shape} to implement a text shape.
*
* This shape is **NOT** registered in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* To change vertical text from "bottom to top" to "top to bottom", the following code can be used:
* ```javascript
* TextShape.prototype.verticalTextRotation = 90;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/view/geometry/node/TriangleShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import AbstractCanvas2D from '../../canvas/AbstractCanvas2D';
/**
* Implementation of the triangle shape.
*
* This shape is registered under `triangle` in {@link CellRenderer} when using {@link Graph} or calling {@link registerDefaultShapes}.
*
* @category Vertex Shapes
*/
class TriangleShape extends ActorShape {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/view/mixins/CellsMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
DEFAULT_FONTSIZE,
DEFAULT_IMAGESIZE,
DIRECTION,
SHAPE,
} from '../../util/Constants';
import Geometry from '../geometry/Geometry';
import EventObject from '../event/EventObject';
Expand Down Expand Up @@ -958,7 +957,7 @@ export const CellsMixin: PartialType = {

// Adds dimension of image if shape is a label
if (state.getImageSrc() || style.image) {
if (style.shape === SHAPE.LABEL) {
if (style.shape === 'label') {
if (style.verticalAlign === ALIGN.MIDDLE) {
dx += style.imageWidth || DEFAULT_IMAGESIZE;
}
Expand Down
Loading