Published
Edited
Sep 20, 2022
Fork of Tiles 0.1.0
Insert cell
Insert cell
Insert cell
viewof select_alpha = select({'options':available_alphas, value: ini_alpha})
Insert cell
viewof select_leiden = select({'options':['none'].concat(available_leidens), value: 'none'})
Insert cell
select_cluster
Insert cell
import {select} from '@jashkenas/inputs'
Insert cell
d3.select('#set_alpha').empty()
Insert cell
viewof opacity = slider({ min: 0.01, max: 1, value: 0.75, step: 0.01, description: 'shape opacity'})
Insert cell
inst_alpha_index = 0
Insert cell
ini_alpha = 0
Insert cell
container = html `<div style="height:${height}px; border-style:solid; border-color:#d3d3d3; border-width:1px; position:relative;"></div>`
Insert cell
// mutable select_cluster = 'none'
mutable select_cluster = select_leiden
Insert cell
unselected_opacity_255 = 20
Insert cell
selected_deckgl_points = deckgl_points['features'].filter(x => x['properties'][cat_name] == select_cluster)
Insert cell
// passing in JSON object
ini_geojson = JSON.parse(geojson_string)
Insert cell
inst_alpha = 5
Insert cell
available_alphas = Array.from(new Set(ini_geojson["features"].map(x => x.properties.alpha))).sort((a, b) => a - b)
Insert cell
available_leidens = Array.from(new Set(ini_geojson.features.map(x => x.properties[cat_name]))).sort((a, b) => parseInt(a) - parseInt(b))
Insert cell
alpha_features = ini_geojson["features"].filter(x => x.properties.alpha == select_alpha)
Insert cell
geojson = ({
type: "FeatureCollection",
features: alpha_features
})
Insert cell
transcript_radius = 1
Insert cell
cell_layer = new deck.GeoJsonLayer({
id: 'cell_layer',
data: selected_deckgl_points,
opacity: opacity,
stroked: false,
filled: true,
getLineWidth: 0.1,

getFillColor: f => {
var rgb_array = d3.color(f.properties.color)
var rgb = [rgb_array.r, rgb_array.g, rgb_array.b]
return rgb
},
getRadius: transcript_radius,

updateTriggers: {
getFillColor: select_cluster,
},

pickable: false
});
Insert cell
geojson
Insert cell
nbhd_layer = new deck.GeoJsonLayer({
id: 'nbhd_layer',
data: geojson,
opacity: opacity,
stroked: false,
filled: true,
getFillColor: d => {
var rgb_array = d3.color(d.properties.color)
var rgb = [rgb_array.r, rgb_array.g, rgb_array.b]
var inst_color
if (select_cluster === 'none'){
inst_color = rgb
} else {
inst_color = [rgb[0], rgb[1], rgb[2], unselected_opacity_255]
// check gene name
if (d['properties'][cat_name] === select_cluster){
inst_color = rgb
}
}
return inst_color
},

updateTriggers: {
getFillColor: [select_cluster],
},
onClick: (info, event) => {
var inst_cat_name = info.object.properties[cat_name]
if (select_cluster !== inst_cat_name){
mutable select_cluster = inst_cat_name
// mutable select_meta = cat_name
d3.select('#leiden_dropdown').select('select').node().value = inst_cat_name
console.log('new cluster', select_cluster, inst_cat_name)
} else {
mutable select_cluster = 'none'
// mutable select_meta = cat_name
d3.select('#leiden_dropdown').select('select').node().value = 'none'
console.log('none cluster', select_cluster)
}
},
pickable: true
});
Insert cell
cat_name = 'leiden'
Insert cell
deckgl.setProps({layers: [nbhd_layer, cell_layer]});
Insert cell
height = 850
Insert cell
center_x = d3.mean(deckgl_points['features'].map(x => x['geometry']['coordinates'][0]))
Insert cell
center_y = d3.mean(deckgl_points['features'].map(x => x['geometry']['coordinates'][1]))
Insert cell
zoom = 3
Insert cell
min_zoom = -6
Insert cell
INITIAL_VIEW_STATE_2D = ({
target: [center_x, center_y, 0],
zoom: zoom,
minZoom:min_zoom,
})
Insert cell
deckgl = {
container.innerHTML = '';
var view = new deck.OrthographicView({id: 'ortho'})
var INITIAL_VIEW_STATE = INITIAL_VIEW_STATE_2D

return new deck.DeckGL({
container,
views:[view],
initialViewState:INITIAL_VIEW_STATE,
// controller: true,
controller: {doubleClickZoom: false},
getTooltip: ({object}) => {
return object && ` ${object['properties'][cat_name]}
`},
});
}
Insert cell
deck = require.alias({
// optional dependencies
h3: {},
s2Geometry: {}
})('deck.gl@8.3.7/dist.min.js')
Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
d3 = require("d3@5")
Insert cell
Insert cell
zip_geojson_string = 'eJytWMtuWzcQ/RXDa4O4fJPdFsiuQPeBETiOmghQLUORF0GQf+85M0Pp6kpyWqeGYXhEcm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UWD0uPxI/k+6RZ1EaKWO3xhFUiZ2lB6nU2fBIlIdv/jHzmO9qA='
Insert cell
geojson_string = decode_zipped_string(zip_geojson_string)
Insert cell
cell_geojson_string = '{"type": "FeatureCollection", "features": [{"id": "0", "type": "Feature", "properties": {"color": "red", "index": 0, "leiden": "0"}, "geometry": {"type": "Point", "coordinates": [54.340494179096545, 27.836938509379618]}}]}'
Insert cell
deckgl_points = JSON.parse(cell_geojson_string)
// deckgl_points = []
Insert cell
pako = require('pako/dist/pako.min.js')
Insert cell
function decode_zipped_string(b64Data){
// Get some base64 encoded binary data from the server. Imagine we got this:
// Decode base64 (convert ascii to binary)
var strData = atob(b64Data);
// Convert binary string to character-number array
var charData = strData.split('').map(function(x){return x.charCodeAt(0);});
// Turn number array into byte-array
var binData = new Uint8Array(charData);
// Pako magic
var data = pako.inflate(binData);
// // Convert gunzipped byteArray back to ascii string:
// var strData = String.fromCharCode.apply(null, new Uint16Array(data));

// https://stackoverflow.com/questions/8936984/uint8array-to-string-in-javascript
var strData = new TextDecoder().decode(data);
// Output to console
// console.log(strData);
return strData
}
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