Skip to content
On this page

Shape Payload

available since version 1.3.0

ts
export default {
	shapeSize: 300;
	shapePayload: schema; 
	shapeBuilder: shapeBuilder;
}

The shapePayload is a optional property of a template definition that can be used to define what the payload for a template should look like.

This is done by defining a ajv JSON schema that will be used to validate the payload of a node at runtime before the shape is rendered. Take a look at the ajv documentation for more information on how to define a schema.

Example

ts
const schema = { 
	type: "object", 
	properties: { 
		title: { type: "string" }, 
		color: { type: "string" }, 
		tags: { type: "array", items: { type: "string" } }, 
		category: { type: "string", enum: ["A", "B", "C"] }, 
	}, 
	required: ["title", "color"], 
}; 

export default {
	shapeSize: 300;
	shapePayload: schema; 
	shapeBuilder: shapeBuilder;
}

function shapeBuilder(data, Template) {
	// ...
}

This schema would require the node payload to have a name and color property and optionally a tags and category property. A valid payload would look like this:

json
{
	"title": "My Node",
	"color": "#9575cd",
	"tags": ["tag1", "tag2"],
	"category": "A"
}

Playground

Graphly D3 Documentation