From 68a9d1b07c6ba6f1b360453abd21f50bd584ae6e Mon Sep 17 00:00:00 2001 From: ziajka <dominik.ziajka@gmail.com> Date: Tue, 5 Dec 2017 12:21:35 +0100 Subject: [PATCH] Center label for node --- .../shared/widgets/nodes.widget.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app/cartography/shared/widgets/nodes.widget.ts b/src/app/cartography/shared/widgets/nodes.widget.ts index 4bc549d1..9cd0589d 100644 --- a/src/app/cartography/shared/widgets/nodes.widget.ts +++ b/src/app/cartography/shared/widgets/nodes.widget.ts @@ -52,10 +52,25 @@ export class NodesWidget implements Widget { selection .select<SVGTextElement>('text.label') - .attr('x', (n: Node) => n.label.x - n.width / 2.) - .attr('y', (n: Node) => n.label.y - n.height / 2. + 20) // @todo: server computes y in auto way + // .attr('y', (n: Node) => n.label.y - n.height / 2. + 10) // @todo: server computes y in auto way .attr('style', (n: Node) => n.label.style) - .text((n: Node) => n.label.text); + .text((n: Node) => n.label.text) + .attr('x', function (this: SVGTextElement, n: Node) { + if (n.label.x === null) { + // center + const bbox = this.getBBox(); + return -bbox.width / 2.; + } + return n.label.x - n.width / 2.; + }) + .attr('y', function (this: SVGTextElement, n: Node) { + if (n.label.x === null) { + // center + const bbox = this.getBBox(); + return - n.height + 20; + } + return n.label.y - n.height / 2.; + }); selection .select<SVGTextElement>('text.node_point_label')