Public
Edited
Jul 6, 2023
Insert cell
# Communications
A visualization showing the communications activities within an organization and to external organizations.
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function hover(event, d) {

// debugger;
const selectedRole = event.currentTarget.classList[1];
const diagram = d3.select("#diagram")

// Highlight Role Pill
const highlight = d3.select(`rect.${selectedRole}`)
.attr('stroke', 'rgba(0,0,0,.5)')
.attr('stroke-width', 2)

// Update Activity Panel
const foundRole = roles.find(rol => rol.id === selectedRole);

foundRole.communications.forEach((comm, i) => {
const relatedRole = roles.find(rol => rol.id == comm.id);
if (intLocations.includes(comm.location)) {
d3.select('div#intActivities')
.append('div')
.style('padding-left', '5px')
.append(() => commsPill(foundRole, comm).node())
} else {
d3.select('div#extActivities')
.append('div')
.style('padding-left', '5px')
.append(() => commsPill(foundRole, comm).node())
}
})
// debugger;
// d3.select("#activities").selectAll(".relatedRoleActivity").call(wrap, 32);
//Highlight connections for related roles
InteractionContext.UpdateConnectionsRtSR(foundRole);
InteractionContext.ConnectionsRtSR.transition().duration(250).attr('opacity', 1);
//Fade connections for unrelated roles
InteractionContext.UpdateConnectionsNRtSR(foundRole);
InteractionContext.ConnectionsNRtSR.classed('faded', true);

// Fade unrelated roles
InteractionContext.UpdateRolesNRtSR(foundRole);
InteractionContext.RolesNRtSR.classed('faded', true);
}
Insert cell
Insert cell
Insert cell
Insert cell
function commsPill(foundRole, comm) {

// console.log("comm.activity: ", comm.activity)
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);
// console.log("Outside lines: ", lines)

// const activityLines = wrapActivity(comm.activity, 32)
// console.log("activityLines: ", activityLines)

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
}
// Pill
Activity.append('rect')
.attr('fill', pillColor)
.attr('width', layout.relatedRolePillWidth)
// .attr('height', layout.relatedRolePillHeight * activityLines.length())
.attr('height', relatedRolePillHeight)
.attr('rx', layout.relatedRolePillHeight/2)
.attr('ry', layout.relatedRolePillHeight/2)

// Circle
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)

// Circle Initials
Activity.append('text')
.attr('class', 'relatedRoleInitials')
.attr('transform', 'translate(' + (layout.relatedRolePillHeight / 2) + ',' + (layout.relatedRolePillHeight - layout.relatedInitialsFontSize * .8) + ')')
.text(circleInitials)

// Pill Role
Activity.append('text')
.attr('class', 'relatedRoleName')
.attr('transform', 'translate(' + (layout.relatedRolePillHeight + layout.padding) + ',' + layout.relatedRolePillHeight / 2.25 + ')')
.text(pillRole)

//Activity
Activity.append('text')
.attr('class', 'relatedRoleActivity')
.attr('transform', 'translate(' + (layout.relatedRolePillHeight + layout.padding) + ',' + (layout.relatedRolePillHeight - (layout.relatedActivityFontSize * .4)) + ')')
.text(comm.activity)
// lines2tspans(Activity.text, lines) Is there a form of this statement that works?

if (lines.length > 1) svgNode.selectAll(".relatedRoleActivity").call(lines2tspans, lines);

return svgNode;
}
Insert cell
Insert cell
Insert cell
Insert cell
toolTip = d3.select('body').append('div').attr('class', 'toolTip')
Insert cell
getColorDiagnostic = roles.find(r => r.id === 'Borrower-Individuals').color
Insert cell
Insert cell
Insert cell
viewof intScale = Inputs.select(Object.keys(scales), {value: 'rdPU', label: 'Internal locations color scheme'})
Insert cell
ramp(scales[intScale])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof comms = Inputs.table(data)
Insert cell
Insert cell
# Tests
Insert cell
locExtTest = locations.filter(item => item.id != internalLocations);
Insert cell
locIntTest = locations.filter(item => item.id == internalLocations);
Insert cell
Insert cell
# Resources
Insert cell
d3 = require('d3@6')
Insert cell
import { scales } from '@makio135/give-me-colors'
Insert cell
// import { ramp } from '@mbostock/color-ramp'
Insert cell
import { select } from '@jashkenas/inputs'
Insert cell
import { ramp, swatches } from '@mbostock/working-with-color'
Insert cell
_ = require('lodash')
Insert cell
symbols = (await import('https://cdn.jsdelivr.net/npm/d3-symbol-extra@0.1.0/build/d3-symbol-extra.min.js').default)
Insert cell
Insert cell
workbook = FileAttachment('https://iceholdings-my.sharepoint.com/:x:/g/personal/kmochel_cpex_com/EaXLLO0ZZz1JgSiZ6xfusq0BV2tcoLkwCyV37Ss858nJuQ?e=dxukDQ').xlsx()
Insert cell
workbook.sheetNames
Insert cell
Inputs.table(
workbook.sheet(0, {
headers: false,
// range: 'A1:J10'
})
)
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more