Skip to main content
Version: 4.3

elementAttributes()

function elementAttributes(element): Attributes;

Normalizes a declarative element description into JointJS cell attributes. The portMap shorthand is expanded into native ports via elementPorts (and kept on the result as portMap); a native ports value is passed through untouched. Use it when feeding a ElementModel or building a model's defaults().

Parameters

ParameterTypeDescription
elementElementAttributesThe declarative element description to convert.

Returns

Attributes

Attributes ready to pass to an element model.

Throws

TypeError when element is not a plain object.

Throws

Error when both portMap and ports are supplied.

Examples

Feed an element model:

import { ElementModel, elementAttributes } from '@joint/react';

const element = new ElementModel(
elementAttributes({
type: 'standard.Rectangle',
position: { x: 10, y: 20 },
size: { width: 120, height: 40 },
portMap: { in: { color: '#fff', cx: 0, cy: 0.5 } }, // preset shorthand
})
);

Build a custom model's defaults:

import { ElementModel, elementAttributes } from '@joint/react';

class RectShape extends ElementModel {
defaults() {
return {
...super.defaults(),
...elementAttributes({
type: 'standard.Rectangle',
size: { width: 120, height: 40 },
}),
};
}
}

Stay in the know

Be where thousands of diagramming enthusiasts meet

Star us on GitHub