Published
Edited
Apr 14, 2021
Insert cell
Insert cell
container = html `<div style="height:${height}px"></div>`
Insert cell
viewof map_morph = slider({
value: 0,
min: 0,
max: 1,
precision: 3,
description: 'Slide between "Map" and "UMAP"'
})
Insert cell
// viewof radius = Range([0, 255], {step: 1})
radius = 10
Insert cell
import {Select, Range} from '@observablehq/inputs'
Insert cell
viewof select_meta = Select([null].concat(meta_data_cols), {label: "Metadata"})
Insert cell
{

const autoHighlight = true
const scatterLayer = new deck.ScatterplotLayer({
data: data_viz,
getPosition: d => [parseFloat(d.x), -parseFloat(d.y)],
getFillColor: d => d.color,
getRadius: radius,
pickable: true,
// autoHighlight: true,
highlightColor: d => [50, 50, 50],
radiusMinPixels: radius_min_pixels,
})
const metaScatterLayer = new deck.ScatterplotLayer({
data: data_viz,
getPosition: d => [parseFloat(d.x), -parseFloat(d.y)],
getFillColor: d => d.meta_color,
getRadius: radius * meta_size_scale,
pickable: false,
// autoHighlight: true,
// highlightColor: d => [50, 50, 50],
radiusMinPixels: radius_min_pixels * meta_size_scale,
})
deckgl.setProps({layers: [scatterLayer, metaScatterLayer]});

}
Insert cell
meta_data_cols = Object.keys(data[0])
.filter(x => position_cols.includes(x) === false)
Insert cell
meta_max = Math.max.apply(Math, data.map(function(x) { return parseFloat(x[select_meta]) }))
Insert cell
opacity_scale = d3.scaleLinear()
.domain([0, meta_max])
.range([0, 250])
Insert cell
position_cols = ['x', 'y']
Insert cell
data = [
{
'x': 1,
'y': 1,
'some':0,
'umap-x':2,
'umap-y':2
}
]

Insert cell
x_min = Math.min.apply(Math, data.map(function(o) { return parseFloat(o['x']) }))
Insert cell
x_max = Math.max.apply(Math, data.map(function(o) { return parseFloat(o['x']) }))
Insert cell
y_min = Math.min.apply(Math, data.map(function(o) { return parseFloat(o['y']) }))
Insert cell
y_max = Math.max.apply(Math, data.map(function(o) { return parseFloat(o['y']) }))
Insert cell
umap_x_min = Math.min.apply(Math, data.map(function(o) { return parseFloat(o['umap-x']) }))
Insert cell
umap_x_max = Math.max.apply(Math, data.map(function(o) { return parseFloat(o['umap-x']) }))
Insert cell
umap_y_min = Math.min.apply(Math, data.map(function(o) { return parseFloat(o['umap-y']) }))
Insert cell
umap_y_max = Math.max.apply(Math, data.map(function(o) { return parseFloat(o['umap-y']) }))
Insert cell
umap_x_scale = d3.scaleLinear()
.domain([umap_x_min, umap_x_max])
.range([x_min, x_max]);
Insert cell
umap_y_scale = d3.scaleLinear()
.domain([umap_y_min, umap_y_max])
.range([y_min, y_max]);
Insert cell
data_viz = data.map(x => {
var inst_color
if (select_meta === null){
inst_color = [50, 50, 50, 100]
} else {
inst_color = [50, 50, 50, 100 * unselected_opacity_scale]
}

var meta_color
if (select_meta === null){
meta_color = [0, 0, 0, 0]
} else {
meta_color = [255, 0, 0, opacity_scale(x[select_meta])]
}
var umap_x = umap_x_scale(parseFloat(x['umap-x']))
var umap_y = umap_y_scale(parseFloat(x['umap-y']))
var inst_x = x.x * (1 - map_morph) + umap_x * map_morph
var inst_y = x.y * (1 - map_morph) + umap_y * map_morph
var inst_obj = ({
'x': inst_x,
'y': inst_y,
'color': inst_color,
'meta_color': meta_color
})
return inst_obj
})
Insert cell
data_viz[0]
Insert cell
import {slider} from '@jashkenas/inputs'
Insert cell
unselected_opacity_scale = 0.25
Insert cell
meta_size_scale = 3
Insert cell
default_opacity = 0.5
Insert cell
radius_min_pixels = 1
Insert cell
height = 500
Insert cell
initial_view_state = ({
target: [0, 0, 0],
zoom: 1,
minZoom:-4
})
Insert cell
deckgl = {
// // reference for below https://observablehq.com/@tomvantilburg/deckgl-mapbox-and-3d-tiles
// // This is an Observable hack: clear previously generated content
container.innerHTML = '';
const view = new deck.OrthographicView({id: 'ortho'})
return new deck.DeckGL({
container,
views:[view],
initialViewState:initial_view_state,
controller: true,
getTooltip: ({object}) => {
return object && `${object.x} ${object['y']}`},
});
}
Insert cell
deck = require.alias({
// optional dependencies
h3: {}
})('deck.gl@latest/dist.min.js')
Insert cell
d3 = require("d3@5")
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