mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-17 19:24:10 +01:00
#530 Pull shape functions out to shorten functions
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import dagreD3 from 'dagre-d3-renderer';
|
import dagreD3 from 'dagre-d3-renderer';
|
||||||
|
|
||||||
export function addToRender(render) {
|
function question(parent, bbox, node) {
|
||||||
render.shapes().question = function(parent, bbox, node) {
|
|
||||||
const w = bbox.width;
|
const w = bbox.width;
|
||||||
const h = bbox.height;
|
const h = bbox.height;
|
||||||
const s = (w + h) * 0.9;
|
const s = (w + h) * 0.9;
|
||||||
@@ -16,9 +15,9 @@ export function addToRender(render) {
|
|||||||
return dagreD3.intersect.polygon(node, points, point);
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
};
|
};
|
||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
};
|
}
|
||||||
|
|
||||||
render.shapes().hexagon = function(parent, bbox, node) {
|
function hexagon(parent, bbox, node) {
|
||||||
const f = 4;
|
const f = 4;
|
||||||
const h = bbox.height;
|
const h = bbox.height;
|
||||||
const m = h / f;
|
const m = h / f;
|
||||||
@@ -36,10 +35,9 @@ export function addToRender(render) {
|
|||||||
return dagreD3.intersect.polygon(node, points, point);
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
};
|
};
|
||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Add custom shape for box with inverted arrow on left side
|
function rect_left_inv_arrow(parent, bbox, node) {
|
||||||
render.shapes().rect_left_inv_arrow = function(parent, bbox, node) {
|
|
||||||
const w = bbox.width;
|
const w = bbox.width;
|
||||||
const h = bbox.height;
|
const h = bbox.height;
|
||||||
const points = [
|
const points = [
|
||||||
@@ -54,10 +52,9 @@ export function addToRender(render) {
|
|||||||
return dagreD3.intersect.polygon(node, points, point);
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
};
|
};
|
||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Add custom shape for box with inverted arrow on left side
|
function lean_right (parent, bbox, node) {
|
||||||
render.shapes().lean_right = function(parent, bbox, node) {
|
|
||||||
const w = bbox.width;
|
const w = bbox.width;
|
||||||
const h = bbox.height;
|
const h = bbox.height;
|
||||||
const points = [
|
const points = [
|
||||||
@@ -71,10 +68,9 @@ export function addToRender(render) {
|
|||||||
return dagreD3.intersect.polygon(node, points, point);
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
};
|
};
|
||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Add custom shape for box with inverted arrow on left side
|
function lean_left(parent, bbox, node) {
|
||||||
render.shapes().lean_left = function(parent, bbox, node) {
|
|
||||||
const w = bbox.width;
|
const w = bbox.width;
|
||||||
const h = bbox.height;
|
const h = bbox.height;
|
||||||
const points = [
|
const points = [
|
||||||
@@ -88,10 +84,9 @@ export function addToRender(render) {
|
|||||||
return dagreD3.intersect.polygon(node, points, point);
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
};
|
};
|
||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Add custom shape for box with inverted arrow on left side
|
function trapezoid(parent, bbox, node) {
|
||||||
render.shapes().trapezoid = function(parent, bbox, node) {
|
|
||||||
const w = bbox.width;
|
const w = bbox.width;
|
||||||
const h = bbox.height;
|
const h = bbox.height;
|
||||||
const points = [
|
const points = [
|
||||||
@@ -105,10 +100,9 @@ export function addToRender(render) {
|
|||||||
return dagreD3.intersect.polygon(node, points, point);
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
};
|
};
|
||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Add custom shape for box with inverted arrow on left side
|
function inv_trapezoid(parent, bbox, node) {
|
||||||
render.shapes().inv_trapezoid = function(parent, bbox, node) {
|
|
||||||
const w = bbox.width;
|
const w = bbox.width;
|
||||||
const h = bbox.height;
|
const h = bbox.height;
|
||||||
const points = [
|
const points = [
|
||||||
@@ -122,10 +116,9 @@ export function addToRender(render) {
|
|||||||
return dagreD3.intersect.polygon(node, points, point);
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
};
|
};
|
||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Add custom shape for box with inverted arrow on right side
|
function rect_right_inv_arrow(parent, bbox, node) {
|
||||||
render.shapes().rect_right_inv_arrow = function(parent, bbox, node) {
|
|
||||||
const w = bbox.width;
|
const w = bbox.width;
|
||||||
const h = bbox.height;
|
const h = bbox.height;
|
||||||
const points = [
|
const points = [
|
||||||
@@ -140,7 +133,29 @@ export function addToRender(render) {
|
|||||||
return dagreD3.intersect.polygon(node, points, point);
|
return dagreD3.intersect.polygon(node, points, point);
|
||||||
};
|
};
|
||||||
return shapeSvg;
|
return shapeSvg;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export function addToRender(render) {
|
||||||
|
render.shapes().question = question;
|
||||||
|
render.shapes().hexagon = hexagon;
|
||||||
|
|
||||||
|
// Add custom shape for box with inverted arrow on left side
|
||||||
|
render.shapes().rect_left_inv_arrow = rect_left_inv_arrow;
|
||||||
|
|
||||||
|
// Add custom shape for box with inverted arrow on left side
|
||||||
|
render.shapes().lean_right = lean_right;
|
||||||
|
|
||||||
|
// Add custom shape for box with inverted arrow on left side
|
||||||
|
render.shapes().lean_left = lean_left;
|
||||||
|
|
||||||
|
// Add custom shape for box with inverted arrow on left side
|
||||||
|
render.shapes().trapezoid = trapezoid;
|
||||||
|
|
||||||
|
// Add custom shape for box with inverted arrow on left side
|
||||||
|
render.shapes().inv_trapezoid = inv_trapezoid;
|
||||||
|
|
||||||
|
// Add custom shape for box with inverted arrow on right side
|
||||||
|
render.shapes().rect_right_inv_arrow = rect_right_inv_arrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertPolygonShape(parent, w, h, points) {
|
function insertPolygonShape(parent, w, h, points) {
|
||||||
|
|||||||
Reference in New Issue
Block a user