Published
Edited
Jun 28, 2018
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getMinDistanceCity = function getMinDistanceCity(cityName,latLongs){
var minDist = Infinity;
var obj = null;
latLongs.forEach((d,i)=>{
var cDist = distance(d.nameGe,cityName);
if(cDist<minDist){
minDist = cDist;
obj = d;
}
})
return {obj:obj,distance:minDist};
}
Insert cell
distance = function distance(a, b){
if(a.length == 0) return b.length;
if(b.length == 0) return a.length;

var matrix = [];

// increment along the first column of each row
var i;
for(i = 0; i <= b.length; i++){
matrix[i] = [i];
}

// increment each column in the first row
var j;
for(j = 0; j <= a.length; j++){
matrix[0][j] = j;
}

// Fill in the rest of the matrix
for(i = 1; i <= b.length; i++){
for(j = 1; j <= a.length; j++){
if(b.charAt(i-1) == a.charAt(j-1)){
matrix[i][j] = matrix[i-1][j-1];
} else {
matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution
Math.min(matrix[i][j-1] + 1, // insertion
matrix[i-1][j] + 1)); // deletion
}
}
}

return matrix[b.length][a.length];
}
Insert cell
Insert cell
mergedData = cities.map((d,i)=>{
var distCity = getMinDistanceCity(d,latLongs);
return {
name:d,
matched:distCity.obj.nameGe,
distance:distCity.distance,
lat:distCity.obj.lat,
lng:distCity.obj.long,
salesCount:sales[i]
};
})
.sort((a,b)=>a.distance<b.distance?1:-1)
Insert cell
Insert cell
latLongs = load('https://raw.githubusercontent.com/bumbeishvili/awesome-georgian-datasets/master/data/maps/districtsAndCities/districts.csv')
Insert cell
cities = cityStr.split(`\n`)
.filter(d=>d)
.map(d=>d.replace(/მუნიციპალიტეტი/g,''))
.map(d=>d.replace(/^ქალაქი/,''))
.map(d=>d.replace(/ყაზბეგი/,'სტეფანწმინდა'))
.map(d=>d.trim())
.map(d=>d.replace(/ს$/g,''))
Insert cell
sales = salesStr
.split(`\n`)
.filter(d=>d)
.map(d=>d.replace(',',""))
.map(d=>Number(d))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
deckgl = {
return new deck.DeckGL({
container,
map: mapboxgl,
mapboxAccessToken: '',
mapStyle: 'https://free.tilehosting.com/styles/darkmatter/style.json?key=U0iNgiZKlYdwvgs9UPm1',
longitude: 43.3,
latitude: 42.3,
zoom: 6.5,
pitch: 40.5
});
}
Insert cell
{
const hexagonLayer = new deck.HexagonLayer({
id: 'heatmap',
colorRange,
data,
elevationRange: [0, 1000],
elevationScale: 250,
extruded: true,
getPosition: d => [ d.lat,d.lng],
opacity: 1,
radius,
upperPercentile,
lightSettings
});

deckgl.setProps({layers: [hexagonLayer]});
return hexagonLayer;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more