Skip to content

Commit

Permalink
Added hxl.Source.exportArray(). Fixes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmegginson committed Mar 29, 2019
1 parent f057799 commit 972d171
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
2019-04-01 Release 1.1:
- added hxl.Source.exportArray() to export data as an array
including hashtags (and optionally, headers)
- fix bug with null columns when there's no hashtag
- start adding data typing methods

Expand Down
20 changes: 18 additions & 2 deletions hxl.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,25 @@ hxl.classes.Source.prototype.getDisplayTags = function () {
return this.columns.map(col => { return col.displayTag; });
}

/**
* Export the whole dataset, include hashtags.
*
* @param skipHeaders: if truthy, exclude the text headers
* @return {array} an array of arrays forming a parseable HXL dataset
*/
hxl.classes.Source.prototype.exportArray = function(skipHeaders) {
var exported = [];
if (!skipHeaders) {
exported.push(this.headers);
}
exported.push(this.displayTags);
return exported.concat(this.rawData);
};

/**
* Get the minimum value for a column
*
* Uses a < comparison, ignoring empty cells. This method is
* Uses a less-than comparison, ignoring empty cells. This method is
* especially useful for setting ranges in a chart or other
* visualisation.
*
Expand Down Expand Up @@ -492,7 +507,7 @@ hxl.classes.Source.prototype.getMin = function(pattern) {
/**
* Get the maximum value for a column
*
* Uses a > comparison, ignoring empty cells. This method is especially
* Uses a greater-than comparison, ignoring empty cells. This method is especially
* useful for setting ranges in a chart or other visualisation.
*
* <pre>
Expand Down Expand Up @@ -934,6 +949,7 @@ hxl.classes.Dataset.prototype._isTagRow = function(rawRow) {
}



////////////////////////////////////////////////////////////////////////
// hxl.classes.Column
////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 6 additions & 0 deletions test/test-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ QUnit.test("columns", function(assert) {
assert.deepEqual(this.dataset.columns.map(function (col) { return col.displayTag; }), this.test_data[2]);
});

QUnit.test("dataset export", function(assert) {
assert.deepEqual(this.dataset.exportArray(), this.test_data.slice(1));
assert.deepEqual(this.dataset.exportArray(false), this.test_data.slice(1));
assert.deepEqual(this.dataset.exportArray(true), this.test_data.slice(2));
});

QUnit.test("partly-tagged dataset", function(assert) {
// confirm no null columns when not tagged
var dataset = hxl.wrap([
Expand Down

0 comments on commit 972d171

Please sign in to comment.