add nodes style based on text props
This commit is contained in:
@@ -12,8 +12,8 @@
|
|||||||
:key="index"
|
:key="index"
|
||||||
:cx="node.x"
|
:cx="node.x"
|
||||||
:cy="node.y"
|
:cy="node.y"
|
||||||
:fill="getNodeFill(node)"
|
:class="node.data.class"
|
||||||
:r="5"
|
:r="node.children ? 7 : 5"
|
||||||
>
|
>
|
||||||
<title>{{ node.data.name }}</title>
|
<title>{{ node.data.name }}</title>
|
||||||
</circle>
|
</circle>
|
||||||
@@ -107,10 +107,6 @@ export default {
|
|||||||
.force('center', forceCenter(this.width * 0.5, this.height * 0.5))
|
.force('center', forceCenter(this.width * 0.5, this.height * 0.5))
|
||||||
},
|
},
|
||||||
|
|
||||||
getNodeFill (node) {
|
|
||||||
return node.data.type === 'textref' ? 'red' : 'black'
|
|
||||||
},
|
|
||||||
|
|
||||||
// DRAG EVENT HANDLER
|
// DRAG EVENT HANDLER
|
||||||
|
|
||||||
onNodeDragStart (e, node) {
|
onNodeDragStart (e, node) {
|
||||||
@@ -142,4 +138,20 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
path {
|
||||||
|
stroke: grey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@each $id in map-keys($families){
|
||||||
|
.family-#{$id} {
|
||||||
|
fill: setColorFromId($id);
|
||||||
|
@if $id == 9 {
|
||||||
|
stroke: black;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.first {
|
||||||
|
stroke-width: 2px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
+2
-2
@@ -15,8 +15,8 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
created () {
|
created () {
|
||||||
this.$store.dispatch('GET_TEXT', 1).then(({ data }) => {
|
this.$store.dispatch('GET_TEXT', { id: 1 }).then(data => {
|
||||||
this.text = data.data.textref
|
this.text = data.textref
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-5
@@ -27,26 +27,31 @@ export default new Vuex.Store({
|
|||||||
|
|
||||||
'GET_TREE' ({ dispatch }, id) {
|
'GET_TREE' ({ dispatch }, id) {
|
||||||
return api.post('', { query: print(TextdepartRecursive), variables: { id } }).then(({ data }) => {
|
return api.post('', { query: print(TextdepartRecursive), variables: { id } }).then(({ data }) => {
|
||||||
return parse(data.data.textref)
|
const text = data.data.textref
|
||||||
|
return parse(text, text.id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Temp data processing
|
// Temp data processing
|
||||||
function parse (d) {
|
function parse (d, originalId) {
|
||||||
const child = {
|
const child = {
|
||||||
name: d.title,
|
name: d.title,
|
||||||
type: d.__typename.toLowerCase()
|
type: d.__typename.toLowerCase(),
|
||||||
|
class: 'family-' + d.familles[0].id
|
||||||
|
}
|
||||||
|
if (d.id === originalId) {
|
||||||
|
child.class += ' first'
|
||||||
}
|
}
|
||||||
let children = []
|
let children = []
|
||||||
for (const key of ['text_en_rebond', 'text_produits']) {
|
for (const key of ['text_en_rebond', 'text_produits']) {
|
||||||
if (d[key]) {
|
if (d[key]) {
|
||||||
children = [...children, ...d[key].map(text => parse(text))]
|
children = [...children, ...d[key].filter(text => text.id !== originalId)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (children.length) {
|
if (children.length) {
|
||||||
child.children = children
|
child.children = children.map(child => parse(child, originalId))
|
||||||
}
|
}
|
||||||
return child
|
return child
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user