[diagrams] Improve removing multiple elements in API v2

In this commit, I added additional methods `removeNodes`, `removeEdges`, `removeGroupNodes` inside `DiagramDataModel`. This is more convenient for external developers, as they don't have to manually group multiple elements.

GitOrigin-RevId: 99a49fbd5ee1b0c740f06b033c708366b21df6f0
This commit is contained in:
Vladislav Annenkov
2023-12-26 18:44:47 +04:00
committed by intellij-monorepo-bot
parent b43227f265
commit 01d336719b
2 changed files with 21 additions and 2 deletions

View File

@@ -23,7 +23,8 @@ class HierarchyTreeImpl<N : Any, GN : N> : HierarchyTree<N, GN> {
private val nodes2ParentGroupsMap = mutableMapOf<N, GN>()
private val groupNodes2Children = mutableMapOf<GN, MutableSet<N>>()
override fun getAllHierarchyNodes(): Set<N> = hierarchyNodes
override val allHierarchyNodes: Set<N>
get() = hierarchyNodes
override fun getParent(node: N): GN? {
return nodes2ParentGroupsMap[node]
@@ -43,6 +44,16 @@ class HierarchyTreeImpl<N : Any, GN : N> : HierarchyTree<N, GN> {
return children
}
override fun getDepth(node: N): Int {
var depth = 0
var parent = getParent(node)
while (parent != null) {
depth++
parent = getParent(parent)
}
return depth
}
override fun connect(child: N, parent: GN) {
hierarchyNodes.add(child)
hierarchyNodes.add(parent)

View File

@@ -29,7 +29,7 @@ interface HierarchyTree<N : Any, GN : N> {
*
* @return The set containing all the hierarchy nodes in the hierarchy tree.
*/
fun getAllHierarchyNodes(): Set<N>
val allHierarchyNodes: Set<N>
/**
* Retrieves the parent node of the given node.
@@ -49,6 +49,14 @@ interface HierarchyTree<N : Any, GN : N> {
*/
fun getChildren(group: GN, isRecursively: Boolean = false): Set<N>
/**
* Retrieves the depth of the given node in the hierarchy tree.
*
* @param node The node for which to retrieve the depth.
* @return The depth of the given node in the hierarchy tree.
*/
fun getDepth(node: N): Int
/**
* Connects a child node to a parent group node in the hierarchy tree.
*