#2032 Adding new statement to add choice shape in state diagrams

This commit is contained in:
Knut Sveidqvist
2021-05-01 18:09:42 +02:00
parent b20f8668be
commit 6dc71122b8
11 changed files with 353 additions and 189 deletions

View File

@@ -34,6 +34,44 @@ const question = (parent, node) => {
return shapeSvg;
};
const choice = (parent, node) => {
const shapeSvg = parent
.insert('g')
.attr('class', 'node default')
.attr('id', node.domId || node.id);
const s = 28;
const points = [
{ x: 0, y: s / 2 },
{ x: s / 2, y: 0 },
{ x: 0, y: -s / 2 },
{ x: -s / 2, y: 0 }
];
const choice = shapeSvg.insert('polygon', ':first-child').attr(
'points',
points
.map(function(d) {
return d.x + ',' + d.y;
})
.join(' ')
);
// center the circle around its coordinate
choice
.attr('class', 'state-start')
.attr('r', 7)
.attr('width', 28)
.attr('height', 28);
node.width = 28;
node.height = 28;
node.intersect = function(point) {
return intersect.circle(node, 14, point);
};
return shapeSvg;
};
const hexagon = (parent, node) => {
const { shapeSvg, bbox } = labelHelper(parent, node, undefined, true);
@@ -836,6 +874,7 @@ const shapes = {
question,
rect,
rectWithTitle,
choice,
circle,
stadium,
hexagon,