Published
Edited
Feb 23, 2021
Insert cell
Insert cell
Insert cell
text = fetch('https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/scatterplot-data.txt').then(r => r.text())
Insert cell
lines = text.split('\n');
Insert cell
sampleLine = decodeSequence(lines[0])
Insert cell
sampleBbox = decodeBbox(lines[0].slice(0,20))
Insert cell
sampleBitmap = decodeBitmap(lines[0].slice(20))
Insert cell
Insert cell
{
var count = 0;
var result = [];
lines.forEach(function (l, i) {
var sequence = decodeSequence(l);
var bbox = decodeBbox(l.slice(0, 20));
var bitmap = decodeBitmap(l.slice(20));

for (var i = 0; i < bitmap.length; i++) {
if (bitmap[i] > 0) {
var point = [bbox[0] + (bbox[2] - bbox[0]) * sequence[i * 2], bbox[1] + (bbox[3] - bbox[1]) * sequence[i * 2 + 1], Number(bitmap[i])];
result.push(point);
count++;
}
}
})
return result
}
Insert cell
Insert cell
function decodeSequence(str) {
var seq = [];
var tokens = str.split(/([A-Z])/).map(function (v) {
return parseInt(v, 36);
});

for (var i = 0; i < tokens.length - 1; i += 2) {
seq.push(tokens[i] / Math.pow(2, tokens[i + 1] - 10));
}

return seq;
}

Insert cell
Insert cell
function decodeBbox(str) {
var multiplyer = Math.pow(10, COORDINATE_PRECISION);
return decodeNumberArr(str, 90, 32, 5).map(function (x) {
return x / multiplyer - 180;
});
}
Insert cell
function decodeNumberArr(str, b, shift, length) {
var result = [];

for (var j = 0; j < str.length; j += length) {
var token = str.slice(j, j + length);
result.push(decodeNumber(token, b, shift));
}

return result;
}

Insert cell
function decodeNumber(str, b, shift) {
var x = 0;
var p = 1;

for (var i = str.length; i--;) {
x += (str.charCodeAt(i) - shift) * p;
p *= b;
}

return x;
}
Insert cell
function decodeBitmap(str) {
var chunkSize = 4;
var match = '';

for (var i = 0; i < str.length; i++) {
var seg = (str.charCodeAt(i) - 32).toString(3);

while (seg.length < chunkSize) {
seg = "0".concat(seg);
}

match += seg;
}

return match;
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more