From 550f91aa6879c8de0da4e7c284c45581c52a3327 Mon Sep 17 00:00:00 2001 From: Brian Mearns Date: Wed, 2 Oct 2019 22:36:02 -0400 Subject: [PATCH] #530 Better shaping of hexagon The "corner" triangles are a fixed ratio to the height, so the triangles will always be mathemtically similar. --- src/diagrams/flowchart/flowRenderer.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/diagrams/flowchart/flowRenderer.js b/src/diagrams/flowchart/flowRenderer.js index 353400efa..9b5423109 100644 --- a/src/diagrams/flowchart/flowRenderer.js +++ b/src/diagrams/flowchart/flowRenderer.js @@ -362,15 +362,16 @@ export const draw = function(text, id) { }; render.shapes().hexagon = function(parent, bbox, node) { - const q = 7; - const w = (q / (q - 2)) * bbox.width; + const f = 4; const h = bbox.height; + const m = h / 4; + const w = bbox.width + 2 * m; const points = [ - { x: w / q, y: 0 }, - { x: (w * (q - 1)) / q, y: 0 }, + { x: m, y: 0 }, + { x: w - m, y: 0 }, { x: w, y: -h / 2 }, - { x: (w * (q - 1)) / q, y: -h }, - { x: w / q, y: -h }, + { x: w - m, y: -h }, + { x: m, y: -h }, { x: 0, y: -h / 2 } ]; const shapeSvg = parent @@ -385,7 +386,7 @@ export const draw = function(text, id) { ) .attr('rx', 5) .attr('ry', 5) - .attr('transform', 'translate(' + -w / 2 + ',' + (h * 2) / 4 + ')'); + .attr('transform', 'translate(' + -w / 2 + ',' + h / 2 + ')'); node.intersect = function(point) { return dagreD3.intersect.polygon(node, points, point); };