Public
Edited
Nov 4
3 forks
4 stars
Insert cell
Insert cell
ridgeLine = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);

for (var i = 0; i < elevationMatrix.length; i += 10) {
var g = svg.append('g').attr('transform', `translate(0,${y(i)})`);

g.selectAll('path')
.data([elevationMatrix[i]])
.enter()
.append('path')
.attr('stroke', 'black')
.attr('fill', 'none')
.attr('stroke-width', 1.2)
.attr('d', line);
}

return svg.node();
}
Insert cell
ridgeHeight = 25
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
elevationMatrix = {
const imageWidth = dimensions[0];
const imageHeight = dimensions[1];

let retval = Array(imageHeight)
.fill()
.map(() => Array(imageWidth).fill(0));

for (var i = 0; i < imageHeight; i++) {
for (var j = 0; j < imageWidth; j++) {
var startIndex = (imageWidth * i + j) * 4;

retval[i][j] = chroma.distance(
"#000",
rgbToHex(
imageData.data[startIndex],
imageData.data[startIndex + 1],
imageData.data[startIndex + 2]
)
);
}
}

return retval;
}
Insert cell
function blobToFile(theBlob, fileName) {
//A Blob() is almost a File() - it's just missing the two properties below which we will add
theBlob.lastModifiedDate = new Date();
theBlob.name = fileName;
return theBlob;
}
Insert cell
Insert cell
Insert cell
Insert cell
height = 700
Insert cell
scale = d3
.scaleLinear()
.domain([1, chroma.distance("#fff", "#000")])
.range([ridgeHeight, 1])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chroma = require("chroma-js@1.3.7")
Insert cell
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