Published
Edited
Feb 23, 2018
1 star
Insert cell
Insert cell
Insert cell
div = {
var width = 100
var height = 18

var node = DOM.element('div')
var sel = d3.select(node)

var c = d3.conventions({
sel,
height,
width,
margin: {top: 0, left: 0, right: 0, bottom: 0}
})
sel.st({display: 'inline-block'})
var data = d3.range(width).map((d, i) => Math.random()*i)
c.x.domain([0, width])
c.y.domain([0, width])
c.svg.append('path').at({
d: d3.line().x((d, i) => c.x(i)).y(d => c.y(d))(data),
fill: 'none',
stroke: '#f0f'
})
// Changing c.svg's inline style from absolute to relative doesn't work
c.svg.st({position: 'relative'})
c.svg.style('position', 'relative')
console.log(c.svg.style('position')) // relative
console.log(d3.select(node).select('svg').style('position')) // Back to absolute!!

// This does work? Comment out to see chart overlapping with text above
d3.select(node).select('svg').st({position: 'relative'})
console.log(d3.select(c.sel.node()).style('position')) // relative
return node
}
Insert cell
d3.select(div).select('svg').style('position')
Insert cell
d3.select(div).selectAll('svg').size()
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
Insert cell
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