#1676 Adding click support and tooltip support for flowchart

This commit is contained in:
Knut Sveidqvist
2020-09-12 10:56:23 +02:00
parent 6360ed52b2
commit c8c4554299
4 changed files with 79 additions and 54 deletions

View File

@@ -552,19 +552,11 @@ const class_box = (parent, node) => {
classes = 'node ' + node.classes;
}
// Add outer g element
const shapeSvgG = parent
const shapeSvg = parent
.insert('g')
.attr('class', classes)
.attr('id', node.domId || node.id);
// Add link
const shapeSvg = node.link
? shapeSvgG
.append('svg:a')
.attr('xlink:href', node.link)
.attr('target', node.linkTarget || '_blank')
: shapeSvgG;
// Create the title label and insert it after the rect
const rect = shapeSvg.insert('rect', ':first-child');
const topLine = shapeSvg.insert('line');
@@ -830,7 +822,26 @@ const shapes = {
let nodeElems = {};
export const insertNode = (elem, node, dir) => {
nodeElems[node.id] = shapes[node.shape](elem, node, dir);
let newEl;
let el;
// Add link when appropriate
if (node.link) {
newEl = elem
.insert('svg:a')
.attr('xlink:href', node.link)
.attr('target', node.linkTarget || '_blank');
el = shapes[node.shape](newEl, node, dir);
} else {
el = shapes[node.shape](elem, node, dir);
newEl = el;
}
if (node.tooltip) {
el.attr('title', node.tooltip);
}
nodeElems[node.id] = newEl;
if (node.haveCallback) {
nodeElems[node.id].attr('class', nodeElems[node.id].attr('class') + ' clickable');
}