Я пытаюсь добавить div в центр моего узла (круга) на моем графике.
Иностранные объекты в настоящее время используются для добавления текстов к узлам, я хочу добавить значок в центр (связывание, прикрепление) - так как, похоже, все тексты, похоже, привязаны к узлам, и я не могу сделай это здесь!
![enter image description here](https://i.stack.imgur.com/VjdHQ.jpg)
Я бы хотел одну из иконок слева, в центре. Я просто не понимаю, как работают другие посторонние объекты и как они прикреплены к другим узлам окружности (все тексты находятся внутри чужих объектов, как вы теперь увидите в коде)
Первая часть этого кода назначает тексты, вторая часть - это попытка присвоить иконку.
addInsightText(): void {
const length = this.nodes[0] && this.nodes[0].name ? this.nodes[0].name.length : 0;
const expr = length > 50 || this.mainNodeType !== NODE_IMAGE_TYPE.title;
let titleClass = `Engagement-OrganizationTitle--${expr ? 'Small' : 'Big'}`;
titleClass += this.mainNodeType !== NODE_IMAGE_TYPE.title ? ' Engagement-OrganizationTitle--Uncentered' : '';
this.group
.selectAll('foreignObject')
.data(this.nodes, node => node)
.enter()
.filter(node => node.parent)
.append('foreignObject')
.attr('class', 'Engagement-GraphNodeLabel')
.attr('x', 0)
.attr('y', 0)
.attr('transform', `translate(0, 0)`)
.attr('width', node => node.depth === 0 ? node.nodeRadius * 2 : this.labelWidth)
.attr('height', node => this.nodeHeight(node))
.style('opacity', node => node.visible ? 1 : 0)
.style('visibility', node => node.visible ? 'visible' : 'hidden')
.append('xhtml:div')
.classed('Engagement-GraphNodeLabelText', node => node.depth !== 0)
.classed('Engagement-GraphOrganizationTitle ' + titleClass, node => node.depth === 0)
.html(node => {
if (node && node.depth !== 0 && node.name && node.name.length > 60) {
return `<p>${node.name.substring(0, 60)}...</p>`;
}
return `<p>${node.name}</p>`;
})
this.group
// .selectAll('foreignObject')
.data(this.nodes, node => node)
.enter()
.filter(node => !node.parent)
.append('foreignObject')
.attr('x', 0)
.attr('y', 0)
.attr('width', node => node.depth === 0 ? node.nodeRadius * 2 : this.labelWidth)
.attr('height', node => this.nodeHeight(node))
.append('xhtml:div')
.html(`<div class ="insightIcon"> </div>`
)
}
Я действительно изо всех сил пытаюсь исправить этот второй посторонний объект или понять начальные части.