Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic data loading #1

Open
curran opened this issue Oct 30, 2017 · 0 comments
Open

Generic data loading #1

curran opened this issue Oct 30, 2017 · 0 comments

Comments

@curran
Copy link

curran commented Oct 30, 2017

We'd like to have a data loader function/pattern, so that the application is structured that it first loads all the data sources, and is able to handle different data types (csv, json, svg).

Related feature idea: get status for a progress bar and once all data soruces are loaded and the main code can be executed.

Ideas for implementation, from previous work by @matthewsmawfield :

var dataSources = [
{'name': 'world', 'source': 'scripts/geo/topojson/worldhistory.json'},
{'name': 'centroid', 'source': 'scripts/geo/topojson/centroid.csv'},
{'name': 'disputed_boundaries', 'source': 'scripts/geo/topojson/disputed_boundaries.json'},
{'name': 'disputed_boundaries_polygons', 'source': 'scripts/geo/topojson/disputed_boundaries_polygons.json'},
// {'name': 'poc', 'source': 'scripts/geo/data/poc.json'},
{'name': 'poc', 'source': 'scripts/geo/data/data.json'},
{'name': 'layout', 'source': 'images/layout.svg'},
];
	if(arguments.length == 2){

		var data = [];

		var runstr = 'queue()';	

		sources.forEach(function(d,i) {

			var noCache = '?_=' + new Date().getTime();
			var s = "foo";
			if(d.source.indexOf("arcgis/rest/services") > -1){
				noCache = '';
			};

			if(d.source.indexOf("popdata.unhcr.org") > -1){
				noCache = '';
			};

			var method = 'd3.json';

			if(d.source.indexOf(".json") > -1){ method = 'd3.json';};
			if(d.source.indexOf(".csv") > -1){ method = 'd3.csv';};
			if(d.source.indexOf(".svg") > -1){ method = 'd3.xml';};
			if(d.source.indexOf(".xls") > -1){ method = 'xlsReq';};
			if(d.source.indexOf(".xlsx") > -1){ method = 'xlsxReq';};

			if((sources.length-1)!=i){
				runstr += '.defer('+method+', "'+d.source+noCache+'")';
			} else {
				runstr += '.defer('+method+', "'+d.source+noCache+'").await(function(){for (i = 1; i < arguments.length; i++) { data[sources[i-1].name] = arguments[i];}; callback(data); });';
			}
		});

		eval(runstr);
	}

Related work: https://github.com/chiasm-project/chiasm-dataset-loader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant