New to Javascript, I’m trying to adapt a script used to display SVG images, currently the script reads the values form within the script, I want to adapt this to read the values from a CSV, the issue I have is the script doesn’t seem to interpret the value correctly, the column I’m having issues with is “nodeStyle” ,if I change the column variable from nodeStyle to {width:100,height:100} it works but it wont read it from CSV, any help would be great
//Data.CSV format
//id, x, y, href, nodeStyleW,nodeStyle,properties,label_text
//NODE22,650,50,/icon.png,{width:100,height:100},,NODE22
fetch('/data.csv')
.then(response => response.text())
.then(data => {
const rows = data.split('n').slice(1); // Skip header row
rows.forEach(row => {
const [id, x, y, href, nodeStyle, properties, label_text] = row.split(/,(?![^{]*})/);
net.addNode(id,parseInt(x),parseInt(y),href,nodeStyle,properties,label_text);
});
});
// Mode added via script
net.addNode("NODE2",600,50,"/images/icon.png",{width:100,height:100},"","","NODE2");
I have tried adding the value directly and this works
net.addNode(id,parseInt(x),parseInt(y),href,nodeStyle,properties,label_text);
net.addNode(id,parseInt(x),parseInt(y),href,{width:100,height:100},properties,label_text);