You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the parser.ts file's loadFromCsv, you have directly invoked .split(",") method. This causes an issue when there is only a single CSV file.
Why is it an issue for me?
In my use case I like to have a csv file for a chart in a separate file rather than having them in the working .md file. The benefit of that is that I can use iOS shortcuts to edit the CSV instead of the YAML code in the main .md file. Plus it makes the file look cleaner.
Solution
I have created a solution that works for me, I am just posting it for you to maybe implement it in a cleaner way for everyone else to use, Thanks.
Here is the code:
async function loadFromCsv(data: string, plugin: ChartsViewPlugin): Promise<DataType> {
var csvFileNames;
const value = [];
if (data.includes(",")){
const csvFileNames = data.split(",");
for (let name of csvFileNames.values()) {
const file = plugin.app.vault.getAbstractFileByPath(plugin.settings.dataPath + "/" + name.trim());
if (file instanceof TFile) {
value.push(parseCsv(await plugin.app.vault.read(file)));
} else {
value.push({});
}
}
} else {
csvFileNames = data;
const file = plugin.app.vault.getAbstractFileByPath(csvFileNames.trim());
console.log(file)
if (file instanceof TFile) {
console.log(data, csvFileNames, parseCsv(await plugin.app.vault.read(file)))
value.push(parseCsv(await plugin.app.vault.read(file)));
} else {
value.push({});
}
}
if (value.length == 0) {
return {};
}
if (value.length == 1) {
return value[0];
}
return value;
}
Thanks a lot for the great plugin.
The text was updated successfully, but these errors were encountered:
Issue
In the parser.ts file's
loadFromCsv
, you have directly invoked.split(",")
method. This causes an issue when there is only a single CSV file.Why is it an issue for me?
In my use case I like to have a csv file for a chart in a separate file rather than having them in the working .md file. The benefit of that is that I can use iOS shortcuts to edit the CSV instead of the YAML code in the main .md file. Plus it makes the file look cleaner.
Solution
I have created a solution that works for me, I am just posting it for you to maybe implement it in a cleaner way for everyone else to use, Thanks.
Here is the code:
Thanks a lot for the great plugin.
The text was updated successfully, but these errors were encountered: