Published
Edited
Feb 29, 2020
1 star
Insert cell
Insert cell
ten_out_of_100 = {
const svg = d3.create('svg')
.attr('viewBox', [0, 0, width, height]);
const wrapper = svg.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`);
wrapper.append('g')
.selectAll('g')
.data(people_position)
.join('g')
.attr('transform', d => `translate(${x(d[0])}, ${y(d[1])})`)
.call(g => g.append('circle')
.attr('cx', sizeCircle / 2)
.attr('cy', sizeCircle / 2)
.attr('r', 15)
.attr('fill', d => {
if (d[0] <= 9 & d[1] <= 0) {
return '#3490DC'
}
return 'none'
})
.attr('fill-opacity', .2))
.call(g => g.append('image')
.attr('xlink:href', 'https://image.flaticon.com/icons/svg/522/522400.svg')
.attr('width', sizeCircle)
.attr('height', sizeCircle)
.attr('stroke', 'blue'));

/*svg.append('image')
.attr('x', 50)
.attr('y', height / 2)
.attr('xlink:href', 'https://image.flaticon.com/icons/svg/522/522400.svg')
.attr('width', 50)
.attr('height', 50)
.attr('stroke', 'blue')*/
return svg.node();
}
Insert cell
sizeCircle = 20
Insert cell
margin = ({left: 20, top: 20, right: 40, bottom: 40})
Insert cell
x = d3.scaleLinear([0, 9], [0, width - margin.left - margin.right])
Insert cell
y = d3.scaleLinear([0, 9], [0, height - margin.top - margin.bottom])
Insert cell
people = d3.range(0, 10, 1)
Insert cell
people.map(d => {
return {'x': d%10, 'y': d%10}
})
Insert cell
people_position = d3.cross(people, people)
Insert cell
height = 400
Insert cell
d3 = require('d3@5')
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