Commit 5e5528b2 authored by Themousaillon's avatar Themousaillon

add link directed expantion

parent db2c864f
......@@ -308,40 +308,46 @@
}
],
"fieldNames": {
"dateFields": ["isoStartDate", "isoEndDate"],
"geoLocalisation": "latLong"
},
"nodeTypes2": {
"date": {
"labelField": "startDate",
"color": "label",
"color": "#FF7F00",
"icon": ""
},
"regest": {
"labelField": "ident",
"color": "label",
"color": "#FF7F00",
"icon": ""
},
"event": {
"labelField": "label",
"color": "label",
"color": "#FF55FF",
"icon": ""
},
"person": {
"labelField": "label",
"color": "label",
"color": "#FF0000",
"icon": ""
},
"place": {
"labelField": "normalizedGerman",
"color": "label",
"color": "#BB7000",
"icon": ""
},
"indPlace": {
"labelField": "label",
"color": "label",
"color": "#BB7000",
"icon": ""
},
"lemma": {
"labelField": "lemma",
"color": "label",
"color": "#41C4F4",
"icon": ""
},
"literature": {
......@@ -356,12 +362,12 @@
},
"thing": {
"labelField": "label",
"color": "label",
"color": "#00A000",
"icon": ""
},
"entry": {
"labelField": "label",
"color": "label",
"color": "#789FFF",
"icon": ""
}
},
......
......@@ -21,9 +21,9 @@ class QueryEngine {
getNodeName = (node, type) => node.properties[this._dbConnector.settings.nodeTypes2[type].labelField]
getNodeColor = label => {
const nodeType = this._dbConnector.settings.nodeTypes.find(x => x.name === label)
return nodeType ? nodeType.color: null
getNodeColor = type => {
const props = this._dbConnector.settings.nodeTypes2[type]
return props ? props.color: null
}
convertType = labels => {
......@@ -40,16 +40,18 @@ class QueryEngine {
const [year, month, day] = [isoNeoDate.year.low, isoNeoDate.month.low, isoNeoDate.day.low]
return new Date(year, month, day)
}
const startDate = rawNode.properties.isoStartDate ? toDate(rawNode.properties.isoStartDate): null
const endDate = rawNode.properties.isoEndDate ? toDate(rawNode.properties.isoEndDate): null
const [startDateField, endDateField] = this._dbConnector.settings.fieldNames.dateFields
const startDate = rawNode.properties[startDateField] ? toDate(rawNode.properties[startDateField]): null
const endDate = rawNode.properties[endDateField] ? toDate(rawNode.properties[endDateField]): null
return [startDate, endDate]
}
getNodeGeoloc = rawNode => {
const geoField = this._dbConnector.settings.fieldNames.geoLocalisation
if (!rawNode || !rawNode.properties.latLong)
return [null, null]
return rawNode.properties.latLong.split(",").map(Number)
return rawNode.properties[geoField].split(",").map(Number)
}
getNodeData = rawNode => {
......@@ -79,13 +81,13 @@ class QueryEngine {
node2 = new Node2d(node2.identity.low, this.getNodeName(node2, node2Type), node2Type, node2Color, node2Data)
link = new Link(link.source.low, link.target.low, link.type)
if (node1.id === link.source){
node1.addTarget(link.target)
node2.addParent(link.source)
node1.addTarget({id: link.target, type: link.type})
node2.addParent({id: link.source, type: link.type})
}
if (node2.id === link.source){
node2.addTarget(link.target)
node1.addParent(link.source)
node2.addTarget({id: link.target, type: link.type})
node1.addParent({id: link.source, type: link.type})
}
}
return [node1, node2, link]
......@@ -207,10 +209,10 @@ export class Graph2d {
}
)
getChildren = (ids, type="all") => f => this._pending.push(() => {
getChildren = (ids, nodeType="all", relationType="all") => f => this._pending.push(() => {
const children = this._nodes.collectFromKeys(ids)
.map(node => this._nodes.collectFromKeys(node.getTargets())
.filter(node => type === "all" || node.type === type)
.map(node => this._nodes.collectFromKeys(node.getTargets(relationType).map(link => link.id))
.filter(node => nodeType === "all" || node.type === nodeType)
.map(node => node.id)
)
const childrenIds = children.flat()
......@@ -234,10 +236,10 @@ export class Graph2d {
return this._queryEngine.fetchComponents(params, this.addComponents(f))
})
getParents = (ids, type="all") => f => this._pending.push(() => {
getParents = (ids, nodeType="all", relationType="all") => f => this._pending.push(() => {
const parents = this._nodes.collectFromKeys(ids)
.map(node => this._nodes.collectFromKeys(node.getParents())
.filter(node => type === "all" || node.type === type)
.map(node => this._nodes.collectFromKeys(node.getParents(relationType).map(link => link.id))
.filter(node => nodeType === "all" || node.type === nodeType)
.map(node => node.id)
)
......@@ -263,9 +265,9 @@ export class Graph2d {
getRelated = ids => f => {this.getChildren(ids)(f); this.getParents(ids)(f)}
collapseParents = (ids, type="all", recursive=false) => this._nodes.collectFromKeys(ids)
.map(node => this._nodes.collectFromKeys(node.getParents())
.filter(node => type === "all" || node.type === type)
collapseParents = (ids, nodeType="all", relationType="all", recursive=false) => this._nodes.collectFromKeys(ids)
.map(node => this._nodes.collectFromKeys(node.getParents(relationType).map(link => link.id))
.filter(node => nodeType === "all" || node.type === nodeType)
)
.flat()
.forEach(node => {
......@@ -275,9 +277,9 @@ export class Graph2d {
this.collapseParents([node.id])
})
collapseChildren = (ids, type="all", recursive=false) => this._nodes.collectFromKeys(ids)
.map(node => this._nodes.collectFromKeys(node.getTargets())
.filter(node => type === "all" || node.type === type)
collapseChildren = (ids, nodeType="all", relationType="all", recursive=false) => this._nodes.collectFromKeys(ids)
.map(node => this._nodes.collectFromKeys(node.getTargets(relationType).map(link => link.id))
.filter(node => nodeType === "all" || node.type === nodeType)
)
.flat()
.forEach(node => {
......@@ -287,9 +289,9 @@ export class Graph2d {
this.collapseChildren([node.id])
})
collapseRelated = (ids, type="all", recursive=false) => {
this.collapseParents(ids, type, recursive)
this.collapseChildren(ids, type, recursive)
collapseRelated = (ids, nodeType="all", relationType="all", recursive=false) => {
this.collapseParents(ids, nodeType, relationType, recursive)
this.collapseChildren(ids, nodeType, relationType, recursive)
}
......@@ -300,8 +302,8 @@ export class Graph2d {
const prev = this._nodes.get(node.id)
if (prev){
prev.hide = !this._currentNodes.has(node.id)
prev.targets = new Set([...prev.targets, ...node.targets])
prev.parents = new Set([...prev.parents, ...node.parents])
prev.targets.add(node.targets.toArray())
prev.parents.add(node.parents.toArray())
}
if (!node.hide)
......@@ -317,8 +319,8 @@ export class Graph2d {
resolve => {
const nodes = this._nodes.collectFromKeys(idList)
const edgesIds = nodes.map(n => n.getEdgesId()).flat()
const targetsToRemove = nodes.map(node => [node.id, node.getParents()])
const parentsToRemove = nodes.map(node =>[node.id, node.getTargets()])
const targetsToRemove = nodes.map(node => [node.id, node.getParents().map(link => link.id)])
const parentsToRemove = nodes.map(node =>[node.id, node.getTargets().map(link => link.id)])
targetsToRemove.forEach(([id, targets]) => this._nodes.collectFromKeys(targets).forEach(t => t.removeTarget(id)))
parentsToRemove.forEach(([id, parents]) => this._nodes.collectFromKeys(parents).forEach(p => p.removeParent(id)))
this._nodes.removeByIds(idList)
......@@ -339,6 +341,7 @@ export class Graph2d {
this._nodes.collectFromKeys(ids)
.map(node => node.getRelated())
.flat()
.map(link => link.id)
)
ids.forEach(id => related.add(id))
return [...this._currentNodes].filter(id => !related.has(id))
......
......@@ -11,6 +11,8 @@ export default class IdSet {
if (iterable)
iterable.forEach(obj => {this._entries[obj.id] = obj})
}
ids = () => Object.keys(this._entries)
addOne = obj => {
if (obj && !this._entries[obj.id])
......@@ -46,7 +48,7 @@ export default class IdSet {
}
forEachEntry = (f) => {
[...this._entries].forEach(e => f(e))
Object.values(this._entries).forEach(e => f(e))
}
remove = objs => objs.forEach(obj => this.removeOne(obj))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment