Estoy tratando de convertir una API de administrador de datos de "Desarrollar un D3.js Edge" - código original https://github.com/backstopmedia/D3Edge/blob/master/code/Chapter07/script.js - de d3v3 a d3v5 .
He abordado el d3.rebind
(creo que utilicé el consejo de d3.rebind en D3 v4 ).
Mi problema y pregunta es que tengo problemas con otras áreas del código, es decir, cómo usar Promises (o asyn/await) aquí. Creo que esta es la fuente de mi error:
Uncaught (in promise) TypeError: loadCsv.on is not a function at Object.exports.loadCsvData (d3Edge_RUPro_Chapter7_v5.3.html:73:21) at d3Edge_RUPro_Chapter7_v5.3.html:136:27
pero no estoy seguro, cualquier consejo sería genial.
Este js.fiddle es lo lejos que he llegado: https://jsfiddle.net/Maltbyjim/xqmau08d/4/
Intenté este intento de usar promesas:
//Create a method to load the csv file, and apply cleaning function asynchronously. exports.loadCsvData = function(_file, _cleaningFunc) { //Create the csv request using d3.csv. //**how you load csv cahnges in d3v5 // https://stackoverflow.com/questions/49599691/how-to-load-data-from-a-csv-file-in-d3-v5 // **previous... //const loadCsv = d3.csv(_file); loadCsv = d3.csv(_file).then(function(_data){ return _data }); //<---SOURCE OF THE ERROR //On the progress event, dispatch the custom dataLoading event. //**previous... //loadCsv.on('progress', function() { dispatch.dataLoading(d3.event.loaded);}); processCsv = loadCsv.then( function (value){ return Promise.all( value().on('progress', function() { dispatch.dataLoading(d3.event.loaded);}), value.get(function (_err, _response) { //Apply the cleaning function supplied in the _cleaningFunc parameter. _response.forEach(function (d) { _cleaningFunc(d); }); }) ); //Assign the cleaned response to our data variable. data = _response; //Dispatch our custom dataReady event passing in the cleaned data. dispatch.dataReady(_response); }); };