Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

support tsv files #8 #31

Merged
merged 1 commit into from
Dec 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pub/scripts/PageData.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ PageData.prototype.fetchData = function () {
return this.callback(error, null)
}

var fileRows = d3.csv.parseRows(fileString)
var fileExtention = Utils.getFileExtension(this.dataUrl)
var fileRows = []
if (fileExtention === 'tsv') {
fileRows = d3.tsv.parseRows(fileString)
} else {
fileRows = d3.csv.parseRows(fileString)
}

var fileFieldNames = fileRows.shift()
// create array of row objects with the field names as keys
var fileData = fileRows.map(function (fileRow) {
Expand Down
7 changes: 7 additions & 0 deletions pub/scripts/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,10 @@ Utils.getTrimmedExtent = function (array) {

return [firstNonEmptyItem, lastNonEmptyItem]
}

Utils.getFileExtension = function (fileString) {
// remove any url parameters
var fileStringWithoutParams = fileString.substring(0, fileString.indexOf('?'))
var fileExtention = fileStringWithoutParams.split('.').pop()
return fileExtention.toLowerCase()
}