Published
Edited
Sep 25, 2021
Insert cell
Insert cell
container = html `<div style="height:${height}px"></div>`
Insert cell
cors_anywhere = 'https://cors-anywhere.herokuapp.com/'
Insert cell
slice_info = '100960033?groups=28'

// slice_info = '100960081?groups=28'

//slice_info = '100960176?groups=28'

Insert cell
svg_url = cors_anywhere + 'http://api.brain-map.org/api/v2/svg_download/' + slice_info
Insert cell
d3 = require("d3@5")
Insert cell
svg_data = d3.svg(svg_url)
Insert cell
svg_data
Insert cell
Insert cell
// path = svg_data.getElementById("180638373").querySelector('path')
Insert cell
path_list = d3.select(svg_data)
.selectAll('path')
._groups[0]
Insert cell
Insert cell
path = path_list[10]
Insert cell
inst_id = d3.select(path).attr('id')
Insert cell
d3.select(path).attr('style').split('fill:')[1]
Insert cell
Insert cell
path_array = Array.from(path_list)
Insert cell
Insert cell
polygon_data = path_array.map(x => get_coords('something', x))
Insert cell
Insert cell
numSamples = 1000
Insert cell
scale_down = 100
Insert cell
polygon_data[0]
Insert cell
function get_coords(name, path){
var path_length = path.getTotalLength()
var step = Math.ceil(path_length / numSamples)
let points = [];
for (let i = 0; i < numSamples; i++) {
let point = path.getPointAtLength(i * step);
// points.push({ x: point.x, y: point.y });
points.push([point.x/scale_down, point.y/scale_down]);
}

var color = d3.select(path).attr('style').split('fill:')[1]
var structure_id = d3.select(path).attr('structure_id')
var coords = {
'name': name,
'coordinates': points,
'color': color,
'structure_id': structure_id
}

return coords
}
Insert cell
// coords = get_coords('something', path)
Insert cell
// polygon_data = ([
// coords
// ])
Insert cell
polygon_data
Insert cell
// data = points
Insert cell
{
const polygonLayer = new deck.PolygonLayer({
id: 'PolygonLayer',
data: polygon_data,
getFillColor: [250, 0, 0, 50],
getLineColor: [250, 0, 0, 50],
getLineWidth: d => 0.1,
getPolygon: d => d.coordinates,
stroked: true,
filled: true,
wireframe: true,
pickable: true,
// opacity: rescue_opacity
});
deckgl.setProps({layers: [polygonLayer]});
}
Insert cell
INITIAL_VIEW_STATE = ({
target: [2, 10, 0],
zoom: 2
})
Insert cell
deck = require.alias({
// optional dependencies
h3: {},
s2Geometry: {}
})('deck.gl@8.3.7/dist.min.js')
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.name}
`},
});
}
Insert cell
height = 850
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