odileeds/hexmaps

Solution: resources/constituencies.js parsing of rural data does not handle constituencies names with comma - needs to handle enclosed string

Closed this issue · 1 comments

Here's my fix in the code snippet below for the part of the code where this issue is located, old code commented out.

In summary
My fix in the code snippet below makes use of the already existing CSVToArray function in the code to handle constituencies such as "Birmingham, Edgbaston" - which have a comma in their name which must not be seen as a delimiter, so they have quotes to enclose their string (enclosure technique). From my own tests, CSVToArray appears to handle this properly.

My step debugging of the JS code showed that, before my fix, for the constituency names with a comma, the value is NaN (not a number) because the comma in the name has caused the wrong value to be read.

Selection_085

Here is my fix in the following code snippet:

Thank you for a great piece of software - I hope that my contribution helps!

		S().ajax('../data/2011rural.csv',{
			'complete':function(d,attr){
				if(typeof d==="string"){

					// get the output as an array, element per line

					/*
					d = d.replace(/\r/g,'');
					d = d.split(/[\n]/);
					*/

					csvAsArray = CSVToArray( d );




				}
				for(var i = 1; i < csvAsArray.length; i++){
					//c = d[i].split(/,/);

					//var c = CSVToArray(d[i]);

					this.data[attr.type][csvAsArray[i][0]] = parseFloat(csvAsArray[i][2]); 
				}
				this.hex.data[attr.type] = this.data[attr.type];
				this.setColours("rural");
			},
			'type': type,
			'this': this,
			'error':function(){},
			'dataType':'text'
		});
slowe commented

@therobyouknow Thanks for spotting the issue and apologies that it has taken so long to get around to this.