PeopleViewer = {
return {
template: `
<div>
<svg ref="svg" :width="width" :height="height" style="border: 1px solid black">
<circle
v-for="user in users"
:key="'user-' + user.id"
:fill="user.color"
:cx="user.position[0]"
:cy="user.position[1]"
r="10" />
<circle
:cx="mouseX"
:cy="mouseY"
r="12"
fill="none"
stroke-width="1"
stroke="black"
stroke-opacity="0.1"
/>
</svg>
</div>`,
props: {
users: Array,
user: Object
},
data : function () {
return {
width: width,
height: 600,
mouseX: 0,
mouseY: 0
}
},
mounted: function () {
let svg = d3.select(this.$refs.svg)
.on('mousemove', () => {
if(!this.user) return;
this.mouseX = d3.event.x - svg.node().getBoundingClientRect().x
this.mouseY = d3.event.y - svg.node().getBoundingClientRect().y
this.user.mouse = [
this.mouseX,
this.mouseY
]
})
.on('mousedown', () => {
if(!this.user) return;
this.user.position = [
d3.event.x - svg.node().getBoundingClientRect().x,
d3.event.y - svg.node().getBoundingClientRect().y
]
db.collection('users')
.doc(this.user.id)
.set(this.user)
.then(() => {
})
})
},
methods: {
}
}
}