Skip to content

Commit

Permalink
fix(ElevationReader): Apply uniform reader API
Browse files Browse the repository at this point in the history
BREAKING CHANGE: ElevationReader: Add option for network calls and add parseAsText method
  • Loading branch information
jourdain committed Feb 7, 2018
1 parent 0d5a5d5 commit fa37a72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 31 deletions.
3 changes: 2 additions & 1 deletion BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Add more consistency in Readers
- Affected readers:
- STLReader
- Legacy/PolyDataReader

- ElevationReader


## From 4.x to 5

Expand Down
49 changes: 19 additions & 30 deletions Sources/IO/Misc/ElevationReader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,35 @@ function vtkElevationReader(publicAPI, model) {
}

// Internal method to fetch Array
function fetchCSV(url) {
return model.dataAccessHelper.fetchText(publicAPI, url);
function fetchCSV(url, options) {
return model.dataAccessHelper.fetchText(publicAPI, url, options);
}

// Set DataSet url
publicAPI.setUrl = (url) => {
if (url.indexOf('.csv') === -1) {
model.baseURL = url;
model.url = `${url}/index.csv`;
} else {
model.url = url;

// Remove the file in the URL
const path = url.split('/');
path.pop();
model.baseURL = path.join('/');
}
publicAPI.setUrl = (url, options) => {
model.url = url;

// Fetch metadata
return publicAPI.loadData();
return publicAPI.loadData(options);
};

// Fetch the actual data arrays
publicAPI.loadData = () => {
const promise = fetchCSV(model.url);
publicAPI.loadData = (options) =>
fetchCSV(model.url, options).then((csv) => {
publicAPI.parseAsText(csv);
return true;
});

promise.then((csv) => {
model.csv = csv;
model.elevation = [];
publicAPI.parseAsText = (csv) => {
model.csv = csv;
model.elevation = [];

// Parse data
const lines = model.csv.split('\n');
lines.forEach((line, lineIdx) => {
model.elevation.push(line.split(',').map((str) => Number(str)));
});
publicAPI.modified();
// Parse data
const lines = model.csv.split('\n');
lines.forEach((line, lineIdx) => {
model.elevation.push(line.split(',').map((str) => Number(str)));
});

return promise;
publicAPI.modified();
};

publicAPI.requestData = (inData, outData) => {
Expand Down Expand Up @@ -135,7 +125,6 @@ const DEFAULT_VALUES = {
xDirection: 1,
yDirection: -1,
requestCount: 0,
// baseURL: null,
// dataAccessHelper: null,
// url: null,
};
Expand All @@ -147,7 +136,7 @@ export function extend(publicAPI, model, initialValues = {}) {

// Build VTK API
macro.obj(publicAPI, model);
macro.get(publicAPI, model, ['url', 'baseURL']);
macro.get(publicAPI, model, ['url']);
macro.setGet(publicAPI, model, [
'dataAccessHelper',
'xSpacing',
Expand Down

0 comments on commit fa37a72

Please sign in to comment.