function commsPill(foundRole, comm) {
const roleActivityChars = Math.round(layout.relatedRolePillWidth / layout.relatedActivityFontSize * 1.75)
const lines = calculateLines(comm.activity, roleActivityChars)
const relatedRolePillHeight = layout.relatedRoleFontSize * 1.5 + (layout.relatedActivityFontSize * lines.length * 1.3);
const svgNode = d3.create('svg')
.attr('width', layout.relatedRolePillWidth + 'px')
.attr('height', relatedRolePillHeight)
.attr('id', 'comms')
const Activity = svgNode.append('g')
let circleColor = foundRole.color
let circleInitials = getInitials(foundRole.role)
let pillColor = rolesColor(comm.id)
let pillRole = comm.role
if (comm.request === 'receives') {
circleColor = rolesColor(comm.id)
circleInitials = getInitials(comm.role)
pillColor = foundRole.color
pillRole = foundRole.role
}
Activity.append('rect')
.attr('fill', pillColor)
.attr('width', layout.relatedRolePillWidth)
.attr('height', relatedRolePillHeight)
.attr('rx', layout.relatedRolePillHeight/2)
.attr('ry', layout.relatedRolePillHeight/2)
Activity.append('rect')
.attr('transform', 'translate(' + 4 + ',' + 4 + ')')
.attr('fill', circleColor)
.attr('stroke', 'white')
.attr('width', layout.relatedRolePillHeight - 8)
.attr('height', layout.relatedRolePillHeight - 8)
.attr('rx', layout.relatedRolePillHeight / 2)
.attr('ry', layout.relatedRolePillHeight / 2)
Activity.append('text')
.attr('class', 'relatedRoleInitials')
.attr('transform', 'translate(' + (layout.relatedRolePillHeight / 2) + ',' + (layout.relatedRolePillHeight - layout.relatedInitialsFontSize * .8) + ')')
.text(circleInitials)
Activity.append('text')
.attr('class', 'relatedRoleName')
.attr('transform', 'translate(' + (layout.relatedRolePillHeight + layout.padding) + ',' + layout.relatedRolePillHeight / 2.25 + ')')
.text(pillRole)
Activity.append('text')
.attr('class', 'relatedRoleActivity')
.attr('transform', 'translate(' + (layout.relatedRolePillHeight + layout.padding) + ',' + (layout.relatedRolePillHeight - (layout.relatedActivityFontSize * .4)) + ')')
.text(comm.activity)
if (lines.length > 1) svgNode.selectAll(".relatedRoleActivity").call(lines2tspans, lines);
return svgNode;
}