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

Commit

Permalink
Merge pull request #31 from mikesall/ms-file-support
Browse files Browse the repository at this point in the history
support tsv files #8
  • Loading branch information
mikesall committed Dec 1, 2014
2 parents 988d4a5 + 7aa4b7a commit 3971d07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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()
}

0 comments on commit 3971d07

Please sign in to comment.