update Map view to query text tree on the fly & add show id option

This commit is contained in:
axolotle
2021-03-01 14:00:44 +01:00
parent 038d91b5b5
commit c2c5c99745
2 changed files with 104 additions and 42 deletions
+27 -18
View File
@@ -3,24 +3,30 @@
width="100%" height="100%" width="100%" height="100%"
ref="svg" :id="id" ref="svg" :id="id"
> >
<path <template v-if="ready">
v-for="(item, index) in links" <path
:key="`link_${index}`" v-for="(item, index) in links"
:d="lineGenerator([item.source, item.target])" :key="`link_${index}`"
stroke="black" :d="lineGenerator([item.source, item.target])"
/> stroke="black"
/>
<template v-for="(node, index) in nodes"> <template v-for="(node, index) in nodes">
<circle <circle
:key="'circle' + index" :key="'circle' + index"
:cx="node.x" :cx="node.x"
: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"
> >
<title>{{ node.data.title }}</title> <title>{{ node.data.title }}</title>
</circle> </circle>
<text :key="'text' + index" :x="node.x + 7" :y="node.y-7">{{ node.data.id }}</text>
<text
v-if="showId"
:key="'text' + index" :x="node.x + 7" :y="node.y-7"
>{{ node.data.id }}</text>
</template>
</template> </template>
</svg> </svg>
</template> </template>
@@ -45,11 +51,13 @@ export default {
props: { props: {
nodes: { type: Array, required: true }, nodes: { type: Array, required: true },
links: { type: Array, required: true }, links: { type: Array, required: true },
id: { type: String, default: 'map' } id: { type: String, default: 'node-map' },
showId: { type: Boolean, default: true }
}, },
data () { data () {
return { return {
ready: false,
width: 100, width: 100,
height: 100, height: 100,
simulation: forceSimulation(), simulation: forceSimulation(),
@@ -74,6 +82,7 @@ export default {
this.setupForces() this.setupForces()
// Wait for DOM update so d3 can select // Wait for DOM update so d3 can select
this.$nextTick(this.initListeners) this.$nextTick(this.initListeners)
this.ready = true
}, },
initListeners () { initListeners () {
+77 -24
View File
@@ -1,16 +1,50 @@
<template> <template>
<div id="map"> <div class="d-flex flex-column h-100 px-4 py-3">
<node-map class="node-map" v-if="data" v-bind="one" /> <div id="maps">
<node-map <div>
class="node-map" v-if="data2" v-bind="two" <h4>Carte avec duplication</h4>
id="ùmqsldùml" <node-map
/> v-if="data"
v-bind="mapSingle"
:key="data.id + '-single'"
class="node-map"
:show-id="showId"
/>
</div>
<div>
<h4>Carte avec liens multiples</h4>
<node-map
v-if="data"
v-bind="mapMany"
:key="data.id + '-many'"
class="node-map"
:show-id="showId"
id="map-2"
/>
</div>
</div>
<b-form class="mt-4">
<b-form-group label="Texte de départ :" label-cols="2" class="mb-2">
<b-form-select
v-model="textId"
:options="textsDepartOptions"
/>
</b-form-group>
<b-form-checkbox v-model="showId" name="check-button" switch>
Afficher les numéros
</b-form-checkbox>
</b-form>
</div> </div>
</template> </template>
<script> <script>
import { toSingleManyData, toManyManyData } from '@/helpers/d3Data' import { mapGetters } from 'vuex'
import NodeMap from '@/components/NodeMap' import NodeMap from '@/components/NodeMap'
import { toSingleManyData, toManyManyData } from '@/helpers/d3Data'
export default { export default {
name: 'Home', name: 'Home',
@@ -21,35 +55,54 @@ export default {
data () { data () {
return { return {
id: 39, textId: undefined,
showId: true,
data: null, data: null,
data2: null, mapSingle: { nodes: null, links: null },
one: { nodes: null, links: null }, mapMany: { nodes: null, links: null }
two: { nodes: null, links: null } }
},
computed: {
...mapGetters(['textsDepartOptions'])
},
watch: {
textId (id) {
this.$store.dispatch('GET_TREE', id).then((data) => {
this.mapSingle = toSingleManyData(data)
this.mapMany = toManyManyData(data)
this.data = data
})
} }
}, },
created () { created () {
this.$store.dispatch('GET_TREE', this.id).then((data) => { this.$store.dispatch('GET_TEXTS_DEPART').then(textsDepart => {
this.data = data this.textId = textsDepart[0].id
this.one = toSingleManyData(data)
})
this.$store.dispatch('GET_TREE', this.id).then((data) => {
this.data2 = data
this.two = toManyManyData(data)
}) })
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
#map { #maps {
height: 100%;
width: 100%; width: 100%;
height: 100%;
display: flex; display: flex;
flex-basis: 50%;
} & > div {
.node-map { flex-basis: 50%;
width: 50vw; display: flex;
flex-direction: column;
& + div .node-map {
border-left: none;
}
}
.node-map {
border: 1px solid grey;
}
} }
</style> </style>