Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export structured data from graph via js as CSV file #58

Open
e22c opened this issue Jan 27, 2022 · 1 comment
Open

Export structured data from graph via js as CSV file #58

e22c opened this issue Jan 27, 2022 · 1 comment

Comments

@e22c
Copy link

e22c commented Jan 27, 2022

Is there an easy way to export structured graph data as CSV file from within graph via java script - eg. right click on graph and select export data or clicking on particular part of graph.

bellow and js example:

let csv = arrayToCsv([
[1, '2', '"3"'],
[true, null, undefined],
]);
downloadBlob(csv, 'export.csv', 'text/csv;charset=utf-8;')

/** Convert a 2D array into a CSV string
*/
function arrayToCsv(data){
return data.map(row =>
row
.map(String) // convert every value to String
.map(v => v.replaceAll('"', '""')) // escape double colons
.map(v => "${v}") // quote it
.join(';') // semi-comma-separated
).join('\r\n'); // rows starting on new lines
}

/** Download contents as a file

// Create a link to download it
var pom = document.createElement('a');
pom.href = url;
pom.setAttribute('download', filename);
pom.click();
}

@goat1000
Copy link
Owner

No, there is not a simple way to do this. The easiest way is to add a link to a separate PHP script that would generate the CSV from the same data you pass into SVGGraph. You can probably find a decent CSV output library on Packagist to help with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants