Render nodes as real links

This commit is contained in:
Philipp A
2018-11-28 17:09:34 +01:00
parent a4992963b3
commit aca80726d7
2 changed files with 12 additions and 9 deletions

View File

@@ -181,14 +181,7 @@ const setLink = function (id, linkStr) {
return
}
if (typeof vertices[id] !== 'undefined') {
funs.push(function (element) {
const elem = d3.select(element).select(`[id="${id}"]`)
if (elem !== null) {
elem.on('click', function () {
window.open(linkStr, 'newTab')
})
}
})
vertices[id].link = linkStr
}
}
export const getTooltip = function (id) {

View File

@@ -70,6 +70,9 @@ export const addVertices = function (vert, g) {
verticeText = verticeText.replace(/fa:fa[\w-]+/g, function (s) {
return '<i class="fa ' + s.substring(3) + '"></i>'
})
if (vertice.link) {
verticeText = '<a href="' + vertice.link + '" rel="noopener">' + verticeText + '</a>'
}
} else {
const svgLabel = document.createElementNS('http://www.w3.org/2000/svg', 'text')
@@ -85,8 +88,15 @@ export const addVertices = function (vert, g) {
}
labelTypeStr = 'svg'
if (vertice.link) {
const link = document.createElementNS('http://www.w3.org/2000/svg', 'a')
link.setAttributeNS('http://www.w3.org/2000/svg', 'href', vertice.link)
link.setAttributeNS('http://www.w3.org/2000/svg', 'rel', 'noopener')
verticeText = link
} else {
verticeText = svgLabel
}
}
let radious = 0
let _shape = ''