Public
Edited
Sep 20, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
random = d3.randomLogNormal(0,1)
Insert cell
matrix = d3.range(30).map(i => d3.range(40).map(j => j % 2 ? random() : i % 2 ? random()/5.0 : random()/20.0 ))
Insert cell
row_ordering = !row_clustering.enabled ? d3.range(matrix.length) : (new hclust.agnes(matrix, {distanceFunction: distance[row_clustering.distance_metric], method: row_clustering.method})).indices()
Insert cell
row_sorted_matrix = row_ordering.map(i => matrix[i])
Insert cell
row_sorted_columns = d3.range(row_sorted_matrix[0].length).map(j => row_sorted_matrix.map(row => row[j]))
Insert cell
col_ordering = !col_clustering.enabled ? d3.range(matrix[0].length) : (new hclust.agnes(row_sorted_columns, {distanceFunction: distance[col_clustering.distance_metric], method: col_clustering.method})).indices()
Insert cell
sorted_matrix = row_sorted_matrix.map(row => col_ordering.map(j => row[j]) )
Insert cell
flat_matrix = sorted_matrix.map((row, i) => row.map((value, j) => ({row: i, col: j, value: value}) )).flat()
Insert cell
// By Fabian Inwand - https://observablehq.com/d/fe65c694a06cc12b
// A `template` callback for Inputs.form() that displays all inputs inline.
function filterBar(inputs) {
const scope = DOM.uid().id;
return htl.html`<div class=${scope}>${Object.values(inputs)}
<style>
.${scope} { display: flex; gap: 2ch }
.${scope} form, .${scope} form > * { width: fit-content !important }
`;
}
Insert cell
Insert cell
hclust = (await import("https://cdn.skypack.dev/ml-hclust@3.1.0?min"))
Insert cell
distance = (await import("https://cdn.skypack.dev/ml-distance@3.0.0?min")).distance
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