Skip to content

Commit 9fc31ee

Browse files
authored
Separate loadChartDataSource from loadTableDataSource (#357)
* separate loadChartDataSource from loadTableDataSource
1 parent 89f2700 commit 9fc31ee

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/table.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export const __query = Object.assign(
169169

170170
export async function loadDataSource(source, mode, name) {
171171
switch (mode) {
172-
case "chart":
172+
case "chart": return loadChartDataSource(source);
173173
case "table": return loadTableDataSource(source, name);
174174
case "sql": return loadSqlDataSource(source, name);
175175
}
@@ -196,6 +196,18 @@ function sourceCache(loadSource) {
196196
};
197197
}
198198

199+
const loadChartDataSource = sourceCache(async (source) => {
200+
if (source instanceof FileAttachment) {
201+
switch (source.mimeType) {
202+
case "text/csv": return source.csv({typed: true});
203+
case "text/tab-separated-values": return source.tsv({typed: true});
204+
case "application/json": return source.json();
205+
}
206+
throw new Error(`unsupported file type: ${source.mimeType}`);
207+
}
208+
return source;
209+
});
210+
199211
const loadTableDataSource = sourceCache(async (source, name) => {
200212
if (source instanceof FileAttachment) {
201213
switch (source.mimeType) {

0 commit comments

Comments
 (0)