From da048cbc7b358821e6746fbe2d7ee890b7569e95 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Wed, 11 Mar 2020 20:25:55 +0100 Subject: [PATCH] 1295 Handling labels of clusters --- cypress/platform/current.html | 15 +++++++++++---- src/dagre-wrapper/clusters.js | 13 ++++++++++--- src/dagre-wrapper/createLabel.js | 2 +- src/dagre-wrapper/index.js | 14 +++++++------- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/cypress/platform/current.html b/cypress/platform/current.html index d158c27e4..10020a018 100644 --- a/cypress/platform/current.html +++ b/cypress/platform/current.html @@ -34,17 +34,24 @@ C --> D
- graph TB + graph LR A[apan klättrar]-- i träd -->B subgraph id1 [Test with title wider then the node in the subgraph] B end
+
+ flowchart LR + A-- i träd -->B + subgraph id1 [Test] + B + end +
flowchart TB - A[apan klättrar]-- i träd -->B - subgraph id1 [Test with title wider then the node in the subgraph] - B + C[apan klättrar]-- i träd -->D + subgraph id1 [Test] + D end
diff --git a/src/dagre-wrapper/clusters.js b/src/dagre-wrapper/clusters.js index 05667aadc..c0701ed71 100644 --- a/src/dagre-wrapper/clusters.js +++ b/src/dagre-wrapper/clusters.js @@ -33,10 +33,17 @@ const rect = (parent, node) => { .attr('height', node.height + padding); const adj = (node.width + node.padding - bbox.width) / 2; - + logger.info('bbox', bbox.width, node.x, node.width); // Center the label - label.attr('transform', 'translate(' + adj + ', ' + (node.y - node.height / 2) + ')'); - // label.attr('transform', 'translate(' + 70 + ', ' + -node.height / 2 + ')'); + // label.attr('transform', 'translate(' + adj + ', ' + (node.y - node.height / 2) + ')'); + label.attr( + 'transform', + 'translate(' + + (node.x - bbox.width / 2) + + ', ' + + (node.y - node.height / 2 - node.padding / 3 + 3) + + ')' + ); const rectBox = rect.node().getBBox(); node.width = rectBox.width; diff --git a/src/dagre-wrapper/createLabel.js b/src/dagre-wrapper/createLabel.js index 1ae204a4b..3f01e4071 100644 --- a/src/dagre-wrapper/createLabel.js +++ b/src/dagre-wrapper/createLabel.js @@ -8,7 +8,7 @@ const createLabel = (vertexText, style) => { const tspan = document.createElementNS('http://www.w3.org/2000/svg', 'tspan'); tspan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve'); tspan.setAttribute('dy', '1em'); - tspan.setAttribute('x', '1'); + tspan.setAttribute('x', '0'); tspan.textContent = rows[j]; svgLabel.appendChild(tspan); } diff --git a/src/dagre-wrapper/index.js b/src/dagre-wrapper/index.js index 63fef85aa..f1c98060f 100644 --- a/src/dagre-wrapper/index.js +++ b/src/dagre-wrapper/index.js @@ -22,16 +22,16 @@ export const render = (elem, graph) => { if (node.type !== 'group') { insertNode(nodes, graph.node(v)); } else { - const width = getClusterTitleWidth(clusters, node); - const children = graph.children(v); - nodes2expand.push({ id: children[0], width }); + // const width = getClusterTitleWidth(clusters, node); + // const children = graph.children(v); + // nodes2expand.push({ id: children[0], width }); } }); - nodes2expand.forEach(item => { - const node = graph.node(item.id); - node.width = item.width; - }); + // nodes2expand.forEach(item => { + // const node = graph.node(item.id); + // node.width = item.width; + // }); // Inster labels, this will insert them into the dom so that the width can be calculated graph.edges().forEach(function(e) {