open text on map node click & uniformized openText and closeText methods

This commit is contained in:
axolotle
2021-03-10 18:09:18 +01:00
parent 19f37aa23b
commit 43f558ad2f
4 changed files with 34 additions and 12 deletions
+15 -1
View File
@@ -18,6 +18,9 @@
:cy="node.y" :cy="node.y"
:class="node.data.class + (node.data.first ? ' first' : '')" :class="node.data.class + (node.data.first ? ' first' : '')"
:r="node.children ? 7 : 5" :r="node.children ? 7 : 5"
tabindex="0"
@click="onNodeClick(node.data)"
@keyup.enter="onNodeClick(node.data)"
> >
<title>{{ node.data.title }}</title> <title>{{ node.data.title }}</title>
</circle> </circle>
@@ -107,7 +110,7 @@ export default {
.force('center', forceCenter(this.width * 0.5, this.height * 0.5)) .force('center', forceCenter(this.width * 0.5, this.height * 0.5))
}, },
// DRAG EVENT HANDLER // D3 DRAG EVENT HANDLERS
onNodeDragStart (e, node) { onNodeDragStart (e, node) {
if (!e.active) { if (!e.active) {
@@ -128,6 +131,17 @@ export default {
} }
node.fx = null node.fx = null
node.fy = null node.fy = null
},
// BASIC HANDLERS
onNodeClick (nodeData) {
const { id, parents } = nodeData
if (parents) {
this.$emit('open', parents[0].id, id)
} else {
this.$emit('open', id)
}
} }
}, },
+2 -2
View File
@@ -17,12 +17,12 @@
<b-nav class="ml-auto flex-nowrap"> <b-nav class="ml-auto flex-nowrap">
<b-nav-item <b-nav-item
v-for="child in text.children" :key="child.id" v-for="child in text.children" :key="child.id"
@click="$emit('open', child.id)" @click="$emit('open', id, child.id)"
> >
{{ child.id }} {{ child.id }}
</b-nav-item> </b-nav-item>
<b-nav-item @click="$emit('close')"> <b-nav-item @click="$emit('close', id)">
x x
</b-nav-item> </b-nav-item>
</b-nav> </b-nav>
+16 -9
View File
@@ -1,16 +1,16 @@
<template> <template>
<div class="h-100 position-relative"> <div class="h-100 position-relative">
<!-- BACKGROUND (mode) --> <!-- BACKGROUND (mode) -->
<component :is="mode" /> <component :is="mode" @open="openText" />
<!-- FOREGROUND (texts) --> <!-- FOREGROUND (texts) -->
<section v-for="parent in parents" :key="parent.id" class="split-screen"> <section v-for="parent in parents" :key="parent.id" class="split-screen">
<text-card :id="parent.id" @open="openText(parent, $event)" @close="closeText(parent)" /> <text-card :id="parent.id" @open="openText" @close="closeText" />
<div> <div>
<text-card <text-card
v-for="id in parent.children" :key="id" v-for="id in parent.children" :key="id"
:id="id" :id="id"
@close="closeText(parent, id)" @close="closeText(parent.id, $event)"
/> />
</div> </div>
</section> </section>
@@ -47,17 +47,24 @@ export default {
}, },
methods: { methods: {
openText (parent, id) { openText (id, childId) {
if (parent.children.includes(id)) return const parent = this.parents.find(p => p.id === id)
parent.children.push(id) if (parent && (childId === undefined || parent.children.includes(childId))) return
if (!parent) {
this.parents.push({ id, children: childId ? [childId] : [] })
} else if (childId) {
parent.children.push(childId)
}
this.updateQuery(this.parents) this.updateQuery(this.parents)
}, },
closeText (parent, id) { closeText (id, childId) {
if (!id) { const parent = this.parents.find(p => p.id === id)
if (!childId) {
this.updateQuery(this.parents.filter(p => p !== parent)) this.updateQuery(this.parents.filter(p => p !== parent))
} else { } else {
parent.children = parent.children.filter(id_ => id_ !== id) parent.children = parent.children.filter(childId_ => childId_ !== childId)
this.updateQuery(this.parents) this.updateQuery(this.parents)
} }
}, },
+1
View File
@@ -4,6 +4,7 @@
v-if="!loading" v-if="!loading"
v-bind="mapData" v-bind="mapData"
:show-id="true" :show-id="true"
v-on="$listeners"
/> />
</b-overlay> </b-overlay>
</template> </template>