|
1 | 1 | import { arc as d3arc, select } from 'd3';
|
| 2 | +import { createText } from '../../rendering-util/createText.js'; |
2 | 3 | const MAX_SECTIONS = 12;
|
3 | 4 |
|
4 | 5 | export const drawRect = function (elem, rectData) {
|
@@ -523,23 +524,40 @@ export const drawNode = function (elem, node, fullSection, conf) {
|
523 | 524 |
|
524 | 525 | // Create the wrapped text element
|
525 | 526 | const textElem = nodeElem.append('g');
|
| 527 | + const description = node.descr.replace(/(<br\/*>)/g, '\n'); |
| 528 | + const htmlLabels = conf.timeline.htmlLabels; |
| 529 | + |
| 530 | + createText(textElem, description, { |
| 531 | + useHtmlLabels: htmlLabels, |
| 532 | + width: node.width, |
| 533 | + classes: 'timeline-node-label', |
| 534 | + }); |
| 535 | + |
| 536 | + if (!htmlLabels) { |
| 537 | + textElem |
| 538 | + .attr('dy', '1em') |
| 539 | + .attr('alignment-baseline', 'middle') |
| 540 | + .attr('dominant-baseline', 'middle') |
| 541 | + .attr('text-anchor', 'middle'); |
| 542 | + } |
| 543 | + |
| 544 | + const bbox = textElem.node().getBBox(); |
526 | 545 |
|
527 |
| - const txt = textElem |
528 |
| - .append('text') |
529 |
| - .text(node.descr) |
530 |
| - .attr('dy', '1em') |
531 |
| - .attr('alignment-baseline', 'middle') |
532 |
| - .attr('dominant-baseline', 'middle') |
533 |
| - .attr('text-anchor', 'middle') |
534 |
| - .call(wrap, node.width); |
535 |
| - const bbox = txt.node().getBBox(); |
536 | 546 | const fontSize =
|
537 | 547 | conf.fontSize && conf.fontSize.replace ? conf.fontSize.replace('px', '') : conf.fontSize;
|
538 | 548 | node.height = bbox.height + fontSize * 1.1 * 0.5 + node.padding;
|
539 | 549 | node.height = Math.max(node.height, node.maxHeight);
|
540 | 550 | node.width = node.width + 2 * node.padding;
|
541 | 551 |
|
542 |
| - textElem.attr('transform', 'translate(' + node.width / 2 + ', ' + node.padding / 2 + ')'); |
| 552 | + if (!htmlLabels) { |
| 553 | + const dx = node.width / 2; |
| 554 | + const dy = node.padding / 2; |
| 555 | + textElem.attr('transform', 'translate(' + dx + ', ' + dy + ')'); |
| 556 | + } else { |
| 557 | + const dx = (node.width - bbox.width) / 2; |
| 558 | + const dy = (node.height - bbox.height) / 2; |
| 559 | + textElem.attr('transform', 'translate(' + dx + ', ' + dy + ')'); |
| 560 | + } |
543 | 561 |
|
544 | 562 | // Create the background element
|
545 | 563 | defaultBkg(bkgElem, node, section, conf);
|
|
0 commit comments