https://codetricity.github.io/d3-bts/profile.html
https://codetricity.github.io/d3-bts/transition.html
https://github.com/codetricity/d3-bts/blob/master/js/profile.js
Call the new function showData()
...
showData(memberName);
});
function showData(memberName) {
}
Put around the buttons.on('change'...
event handler.
d3.csv('data/bts-profiles.csv').then((data) => {
buttons.on('change', function(d) {
let memberName = this.value;
showImage(memberName);
showData(memberName, data);
});
});
function showData(memberName, data) {
console.log(data);
}
const profileListing = svg.append('g');
Put this above the code to read in the data from file. Put it below the code you set the svg constant (close to the top of the code).
Use this simpler method of removing all text elements.
function showData(memberName, data) {
profileListing.selectAll('text').remove();
Go through array and search for memberName, which was taken from the button value.
function showData(memberName, data) {
profileListing.selectAll('text').remove();
data.forEach((element) => {
if (element.name == memberName) {
function showData(memberName, data) {
profileListing.selectAll('text').remove();
data.forEach((element) => {
if (element.name == memberName) {
var yPosition = 80;
for (var memberInfo in element) {
let memberValue = element[memberInfo];
profileListing
.append('text')
.attr('x', '50')
.attr('y', yPosition)
.text(`${memberInfo}: ${memberValue}`);
yPosition += 50;
}
}
});
}