mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-10 02:49:40 +02:00
#530 Encapsulate some redudant flow shape code
This commit is contained in:
@@ -342,19 +342,7 @@ export const draw = function(text, id) {
|
|||||||
{ x: s / 2, y: -s },
|
{ x: s / 2, y: -s },
|
||||||
{ x: 0, y: -s / 2 }
|
{ x: 0, y: -s / 2 }
|
||||||
];
|
];
|
||||||
const shapeSvg = parent
|
const shapeSvg = insertPolygonShape(parent, s, s, points);
|
||||||
.insert('polygon', ':first-child')
|
|
||||||
.attr(
|
|
||||||
'points',
|
|
||||||
points
|
|
||||||
.map(function(d) {
|
|
||||||
return d.x + ',' + d.y;
|
|
||||||
})
|
|
||||||
.join(' ')
|
|
||||||
)
|
|
||||||
.attr('rx', 5)
|
|
||||||
.attr('ry', 5)
|
|
||||||
.attr('transform', 'translate(' + -s / 2 + ',' + (s * 2) / 4 + ')');
|
|
||||||
node.intersect = function(point) {
|
node.intersect = function(point) {
|
||||||
return dagreD3.intersect.polygon(node, points, point);
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
};
|
};
|
||||||
@@ -374,19 +362,7 @@ export const draw = function(text, id) {
|
|||||||
{ x: m, y: -h },
|
{ x: m, y: -h },
|
||||||
{ x: 0, y: -h / 2 }
|
{ x: 0, y: -h / 2 }
|
||||||
];
|
];
|
||||||
const shapeSvg = parent
|
const shapeSvg = insertPolygonShape(parent, w, h, points);
|
||||||
.insert('polygon', ':first-child')
|
|
||||||
.attr(
|
|
||||||
'points',
|
|
||||||
points
|
|
||||||
.map(function(d) {
|
|
||||||
return d.x + ',' + d.y;
|
|
||||||
})
|
|
||||||
.join(' ')
|
|
||||||
)
|
|
||||||
.attr('rx', 5)
|
|
||||||
.attr('ry', 5)
|
|
||||||
.attr('transform', 'translate(' + -w / 2 + ',' + h / 2 + ')');
|
|
||||||
node.intersect = function(point) {
|
node.intersect = function(point) {
|
||||||
return dagreD3.intersect.polygon(node, points, point);
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
};
|
};
|
||||||
@@ -656,6 +632,22 @@ export const draw = function(text, id) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function insertPolygonShape(parent, w, h, points) {
|
||||||
|
return parent
|
||||||
|
.insert('polygon', ':first-child')
|
||||||
|
.attr(
|
||||||
|
'points',
|
||||||
|
points
|
||||||
|
.map(function(d) {
|
||||||
|
return d.x + ',' + d.y;
|
||||||
|
})
|
||||||
|
.join(' ')
|
||||||
|
)
|
||||||
|
.attr('rx', 5)
|
||||||
|
.attr('ry', 5)
|
||||||
|
.attr('transform', 'translate(' + -w / 2 + ',' + h / 2 + ')');
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setConf,
|
setConf,
|
||||||
addVertices,
|
addVertices,
|
||||||
|
Reference in New Issue
Block a user