Published
Edited
Apr 12, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
wave_interference = function(waves) {
const data = [];
const waves_by_x = waves.map(wave => index_data_by_step(wave));
const all_x = merge_keys(waves_by_x);
for (let i = 0; i < all_x.length; i ++) {
const x = all_x[i];
let y_sum = 0;
waves_by_x.forEach(wave => {
if (x in wave) {
y_sum += wave[x];
}
})

data.push({step: parseInt(x, 10), value: y_sum});
}
return data;
}
Insert cell
Insert cell
Insert cell
amplitude = function(wave) {
return Math.max(...wave.map(point => point.value));
}
Insert cell
overall_amplitude = function(waves) {
return Math.max(...waves.map(wave => amplitude(wave)));
}
Insert cell
Insert cell
d3 = require("d3@6")
Insert cell
Insert cell
Insert cell
md`Generated the SVG path corresponding to a set of (x, y) points.`
Insert cell
Insert cell
xLine = `<line x1="${xAxis(0)}" y1="${yAxis(0)}" x2="${xAxis(1000)}" y2="${yAxis(0)}" stroke="black" />`
Insert cell
all_lines_svg = {
if (!visible.includes("wave")) {
return "";
}
return waves.map(wave => {
return `<path d="${line(wave)}" stroke="${visible.includes("wave") ? "#429bf5" : "none"}" fill="none" />`
}).join("\n");
}
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