Skip to content

Commit 4004074

Browse files
committed
change node label option
1 parent 45c81a0 commit 4004074

File tree

2 files changed

+82
-26
lines changed

2 files changed

+82
-26
lines changed

src/components/output/GraphOutput.vue

Lines changed: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ const q = useQuasar()
2020
const expandedNodesMap = ref(props.expandedNodesState)
2121
2222
const graph = ref()
23-
const properties = ref({})
2423
const selectedElement = ref({
2524
nodeOrRelationship: '',
2625
id: '',
2726
type: '',
2827
color: '',
28+
captionKey: '',
29+
caption: '',
30+
properties: {},
2931
clicked: false
3032
})
3133
const hideOverviewBtn = ref(false)
@@ -102,6 +104,8 @@ const nodeExpansion = async (nodeId) => {
102104
const hasType = props.nodes.find((n) => n.type === fn.type)
103105
if (hasType) {
104106
fn.color = hasType.color
107+
fn.captionKey = hasType.captionKey
108+
fn.caption = hasType.caption
105109
}
106110
return fn
107111
})
@@ -186,6 +190,24 @@ const nodeColorChange = ({ type, color }) => {
186190
emit('updateNodeProperties', nodes)
187191
}
188192
193+
const nodeCaptionChange = ({ type, captionKey, properties }) => {
194+
const nodes = nvl.getNodes().map((v) => {
195+
if (v.type === type) {
196+
v.captionKey = captionKey
197+
if (captionKey === '<type>') {
198+
v.caption = type
199+
} else {
200+
v.caption = properties[captionKey]
201+
}
202+
}
203+
return v
204+
})
205+
206+
nvl.addAndUpdateElementsInGraph(nodes)
207+
208+
emit('updateNodeProperties', nodes)
209+
}
210+
189211
const isNodeExpanded = (nodeId) => {
190212
return expandedNodesMap.value.has(nodeId)
191213
}
@@ -246,9 +268,11 @@ const updateNvlElementselectedElement = (element) => {
246268
selectedElement.value.type = ''
247269
selectedElement.value.color = ''
248270
selectedElement.value.clicked = false
249-
properties.value = {}
271+
selectedElement.value.properties = {}
272+
selectedElement.value.captionKey = ''
273+
selectedElement.value.caption = ''
250274
} else if (element && selectedElement.value.id === '') {
251-
properties.value = element.properties
275+
selectedElement.value.properties = element.properties
252276
element.selected = true
253277
if (element.nodeOrRelationship === 'node') {
254278
nvl.addAndUpdateElementsInGraph([element], [])
@@ -259,8 +283,10 @@ const updateNvlElementselectedElement = (element) => {
259283
selectedElement.value.nodeOrRelationship = element.nodeOrRelationship
260284
selectedElement.value.type = element.type
261285
selectedElement.value.color = element.color
286+
selectedElement.value.captionKey = element.captionKey
287+
selectedElement.value.caption = element.caption
262288
} else if (element && element?.id !== selectedElement.value.id) {
263-
properties.value = element.properties
289+
selectedElement.value.properties = element.properties
264290
element.selected = true
265291
if (selectedElement.value.nodeOrRelationship === 'node') {
266292
const oldNode = nvl.getNodeById(selectedElement.value.id)
@@ -290,6 +316,8 @@ const updateNvlElementselectedElement = (element) => {
290316
selectedElement.value.nodeOrRelationship = element.nodeOrRelationship
291317
selectedElement.value.type = element.type
292318
selectedElement.value.color = element.color
319+
selectedElement.value.captionKey = element.captionKey
320+
selectedElement.value.caption = element.caption
293321
}
294322
}
295323
@@ -303,17 +331,21 @@ const init = (nodes, relationships) => {
303331
new HoverInteraction(nvl).updateCallback('onHover', (element, hitElements, event) => {
304332
if (!selectedElement.value.clicked) {
305333
if (element) {
306-
properties.value = element.properties
334+
selectedElement.value.properties = element.properties
307335
selectedElement.value.id = ''
308336
selectedElement.value.nodeOrRelationship = element.nodeOrRelationship
309337
selectedElement.value.type = element.type
310338
selectedElement.value.color = element.color
339+
selectedElement.value.captionKey = element.captionKey
340+
selectedElement.value.caption = element.caption
311341
} else {
312-
properties.value = {}
342+
selectedElement.value.properties = {}
313343
selectedElement.value.id = ''
314344
selectedElement.value.nodeOrRelationship = ''
315345
selectedElement.value.type = ''
316346
selectedElement.value.color = ''
347+
selectedElement.value.captionKey = ''
348+
selectedElement.value.caption = ''
317349
}
318350
}
319351
})
@@ -446,12 +478,24 @@ onUnmounted(() => {
446478
:style="`background-color: ${selectedElement.color};`"
447479
>
448480
<q-popup-proxy>
449-
<q-color
450-
v-model="selectedElement.color"
451-
@change="nodeColorChange(selectedElement)"
452-
no-header-tabs
453-
no-footer
454-
/>
481+
<q-card>
482+
<q-card-section>
483+
<div class="text-subtitle1">Customize Style</div>
484+
<q-color
485+
v-model="selectedElement.color"
486+
@change="nodeColorChange(selectedElement)"
487+
no-header-tabs
488+
no-footer
489+
/>
490+
<q-select
491+
v-model="selectedElement.captionKey"
492+
:options="Object.keys(selectedElement.properties).concat(['<type>'])"
493+
label="Caption"
494+
outlined
495+
@update:model-value="nodeCaptionChange(selectedElement)"
496+
/>
497+
</q-card-section>
498+
</q-card>
455499
</q-popup-proxy>
456500
</q-badge>
457501
</div>
@@ -469,11 +513,9 @@ onUnmounted(() => {
469513
<div>
470514
<span
471515
class="q-mr-sm"
472-
v-for="(node, index) in nodes
473-
.map((el) => ({ type: el.type, color: el.color }))
474-
.filter(
475-
(value, index, self) => index === self.findIndex((t) => t.type === value.type)
476-
)"
516+
v-for="(node, index) in nodes.filter(
517+
(value, index, self) => index === self.findIndex((t) => t.type === value.type)
518+
)"
477519
:key="index"
478520
>
479521
<q-badge
@@ -482,12 +524,25 @@ onUnmounted(() => {
482524
:style="`background-color: ${node.color};`"
483525
>
484526
<q-popup-proxy>
485-
<q-color
486-
v-model="node.color"
487-
@change="nodeColorChange(node)"
488-
no-header-tabs
489-
no-footer
490-
/>
527+
<q-card>
528+
<q-card-section>
529+
<div class="text-subtitle1">Customize Style</div>
530+
<q-color
531+
v-model="node.color"
532+
@change="nodeColorChange(node)"
533+
no-header-tabs
534+
no-footer
535+
flat
536+
/>
537+
<q-select
538+
v-model="node.captionKey"
539+
:options="Object.keys(node.properties).concat(['<type>'])"
540+
label="Caption"
541+
outlined
542+
@update:model-value="nodeCaptionChange(node)"
543+
/>
544+
</q-card-section>
545+
</q-card>
491546
</q-popup-proxy>
492547
</q-badge>
493548
</span>
@@ -507,7 +562,7 @@ onUnmounted(() => {
507562
<q-markup-table flat wrap-cells dense>
508563
<thead></thead>
509564
<tbody>
510-
<tr v-for="(property, key, index) in properties" :key="index">
565+
<tr v-for="(property, key, index) in selectedElement.properties" :key="index">
511566
<td class="text-bold text-left overview-property-key">
512567
{{ key }}
513568
</td>

src/plugins/Neo4jApi.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,13 @@ const Neo4jApi = {
8989
})
9090
return {
9191
id: node['_element_id'],
92-
caption: String(node['_properties'][Object.keys(node['_properties'])[0]]['_value']),
92+
caption: Object.values(properties)[0],
9393
color: colorMap.get(nodeType),
9494
properties: properties,
9595
nodeOrRelationship: 'node',
9696
selected: false,
97-
type: nodeType
97+
type: nodeType,
98+
captionKey: Object.keys(properties)[0]
9899
}
99100
}
100101

0 commit comments

Comments
 (0)