Method and device for generating tree structure

By calculating the maximum number of layers of the tree structure and all parent nodes of each node, generating the main tree structure and adding multiple parent nodes, the problems of frequent renderings of tree structures and data splitting in the existing technology are solved, and the problem of improved Page rendering speed and intuitiveness of data presentation.

CN119166870APending Publication Date: 2024-12-20BAIRONG ZHIXIN (BEIJING) TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411191824.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-28
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

The prior art only supports the design of a single parent node when generating a tree structure, resulting in the fact that when the child node has multiple parent nodes, the tree structure is rendered more times, the page rendering speed is slow, and data splitting occurs.

Method used

By obtaining node data and node relationship data, calculate the maximum number of layers and all parent nodes of each node, generate a main tree structure, and add multiple parent nodes to the main tree structure to generate a target tree structure and reduce the tree shape The number of renderings of the structure can improve the page rendering speed and avoid data splitting.

Benefits of technology

It realizes reducing the number of renderings of tree structures, improving page rendering speed, and making data presentation more intuitive, avoiding data splits and enhancing the readability of node relationships.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166870A_ABST
    Figure CN119166870A_ABST
Patent Text Reader

Abstract

The invention discloses a method and a device for generating a tree structure, relates to the technical field of tree structures, and mainly aims to reduce the rendering times of the tree structure, improve the rendering speed of a page, enable data display to be more intuitive and avoid data splitting. According to the main technical scheme, the method comprises the steps of obtaining node data and node relation data; based on the node data and the node relation data, obtaining the maximum layer number of the to-be-generated target tree structure and all father nodes corresponding to each node; generating a main tree structure in the to-be-generated target tree structure based on the maximum layer number and all father nodes corresponding to each node; wherein each child node in the main tree structure corresponds to one father node; when at least one first child node corresponding to multiple father nodes exists in the main tree structure, at least one corresponding father node is added to the first child node of the main tree structure, a target tree structure is generated, and the first child node is the child node corresponding to the multiple father nodes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of front-end technology, and in particular to a method and device for generating a tree structure. Background Art

[0002] In the front-end development process, tree structures are often used to display data. Tree structures can well display the relationship between data, such as common organizational charts. Through the tree structure, you can clearly see the relationship between each node.

[0003] At present, the method of generating a tree structure is that the front end obtains node data and data on the relationship between nodes from the server through an interface, and renders a tree structure diagram according to the number of parent nodes of child nodes through components. Figure 1 As shown in the figure, if a child node has two parent nodes at the same time, it will be rendered into two independent tree structures. Similarly, if multiple child nodes have multiple parent nodes at the same time, multiple independent tree structures will be rendered, and multiple tree structures will appear on the page.

[0004] However, the above method of generating a tree structure only supports the design of a single parent node. When processing a situation where a child node has multiple parent nodes at the same time, since it needs to be rendered into multiple independent tree structures, it will cause the tree structure to be rendered more times, the page rendering speed will be slower, and there will be problems with data fragmentation. Summary of the invention

[0005] In view of the above problems, the present invention provides a method and device for generating a tree structure, the main purpose of which is to reduce the number of rendering times of the tree structure, improve the rendering speed of the page, and make the data display more intuitive, avoiding the fragmentation of the data.

[0006] In order to solve the above technical problems, the present invention proposes the following solutions:

[0007] In a first aspect, the present invention provides a method for generating a tree structure, the method comprising:

[0008] Get node data and node relationship data;

[0009] Based on the node data and the node relationship data, obtaining the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node;

[0010] Based on the maximum number of layers and all parent nodes corresponding to each node, a main tree structure in the target tree structure to be generated is generated; wherein each child node in the main tree structure corresponds to a parent node;

[0011] When the main tree structure has at least one first child node, at least one corresponding parent node is added to the first child node of the main tree structure to generate the target tree structure, and the first child node is a child node corresponding to multiple parent nodes.

[0012] In a second aspect, the present invention provides a tree structure generation device, comprising:

[0013] A first acquisition unit, used to acquire node data and node relationship data;

[0014] A second acquisition unit, configured to acquire, based on the node data and the node relationship data, a maximum number of layers of a target tree structure to be generated and all parent nodes corresponding to each node;

[0015] A first generating unit is configured to generate a main tree structure in the target tree structure to be generated based on the maximum number of layers and all parent nodes corresponding to each node; wherein each child node in the main tree structure corresponds to a parent node;

[0016] The second generating unit is used to add at least one corresponding parent node to the first child node of the main tree structure to generate the target tree structure when there is at least one first child node in the main tree structure, wherein the first child node is a child node corresponding to multiple parent nodes.

[0017] In order to achieve the above-mentioned purpose, according to a third aspect of the present invention, a storage medium is provided, wherein the storage medium includes a stored program, wherein when the program is running, the device where the storage medium is located is controlled to execute the method for generating a tree structure described in the first aspect.

[0018] In order to achieve the above-mentioned purpose, according to the fourth aspect of the present invention, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, all or part of the steps of the method for generating a tree structure as described in the first aspect are implemented.

[0019] In order to achieve the above-mentioned purpose, according to a fifth aspect of the present invention, there is provided a computer program product, comprising a computer program / instruction, which implements the steps of the method described in the first aspect when executed by a processor.

[0020] By means of the above technical scheme, the method and device for generating a tree structure provided by the present invention are because the current method for generating a tree structure only supports the design of a single parent node. To this end, the present invention obtains node data and node relationship data; based on the node data and the node relationship data, obtains the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node; based on the maximum number of layers and all parent nodes corresponding to each node, generates the main tree structure in the target tree structure to be generated; wherein each child node in the main tree structure corresponds to a parent node; when there is at least one child node in the main tree structure, at least one corresponding parent node is added to the child node of the main tree structure to generate the target tree structure, and the first child node is a child node corresponding to multiple parent nodes. The present invention calculates the main tree structure of the maximum level, and then renders the child nodes through the node relationship data, thereby avoiding repeated rendering of nodes and repeated rendering of tree structures, improving the rendering speed of the page, and more intuitively displaying the relationship between nodes, avoiding the fragmentation of data.

[0021] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0023] Figure 1 A tree structure diagram in the prior art is shown;

[0024] Figure 2-1 A flow chart of a method for generating a tree structure provided by an embodiment of the present invention is shown;

[0025] Figure 2-2 A target tree structure diagram provided by an embodiment of the present invention is shown;

[0026] Figure 2-3 A main tree structure diagram provided by an embodiment of the present invention is shown;

[0027] Figure 2-4 A schematic diagram of constructing a target tree structure from a main tree structure provided by an embodiment of the present invention is shown;

[0028] Figure 2-5Another main tree structure diagram provided by an embodiment of the present invention is shown;

[0029] Figure 2-6 Another schematic diagram of constructing a target tree structure from a main tree structure provided by an embodiment of the present invention is shown;

[0030] Figure 3 A flow chart of another method for generating a tree structure provided by an embodiment of the present invention is shown;

[0031] Figure 4 A tree structure diagram provided by an embodiment of the present invention is shown;

[0032] Figure 5 A block diagram showing a tree structure generation device provided by an embodiment of the present invention;

[0033] Figure 6 A block diagram showing the composition of another tree structure generating device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0034] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0035] The current method for generating a tree structure only supports the design of a single parent node, which results in a large number of tree structure rendering times, resulting in a slow page rendering speed and data fragmentation. To address this problem, the inventors came up with the idea of ​​determining the maximum number of layers of the tree structure to generate a main tree structure, and then adding other parent nodes corresponding to the child nodes to the child nodes corresponding to the main tree structure to generate a target tree structure.

[0036] To this end, an embodiment of the present invention provides a method for generating a tree structure, by which the rendering times of the tree structure are reduced, the rendering speed of the page is improved, and the data display is more intuitive, avoiding the fragmentation of the data. The execution subject is a client, and the specific execution steps are as follows: Figure 2-1 As shown, at least 100-400 are included.

[0037] 100. Obtain node data and node relationship data.

[0038] In the data acquisition phase, the client sends an HTTP (Hyper Text TransferProtocal) request to the server, and can use the API interface to obtain the node data and node relationship data of the target page from the server, where the target page can be the currently visited page, the currently displayed page, or other specified pages. These data are usually transmitted in JSON or XML format, including node data such as the unique identifier, name, and attributes of the node, as well as node relationship data consisting of the association relationship between a node and other nodes. The node relationship data includes but is not limited to parent-child relationships, grandparent-grandchild relationships, superior-subordinate relationships, and peer relationships. For example, in the organizational structure of an enterprise, the employees (I1, I2|...IN) of the enterprise are taken as employee nodes (I1, I2|...IN), and the departments (W1, W2, W3) are taken as department nodes (W1, W2, W3, W4). Since employee I1 belongs to department W1, the node relationship data between employee nodes I1 and W1 is of the parent-child relationship type; at the same time, there may be a collaborative relationship between different departments. For example, if department W2 and department W3 cooperate to carry out a project, then the node relationship data between department nodes W2 and W3 is of the collaborative relationship type. The node relationship data may also be a colleague relationship at the same level or a superior-subordinate relationship, which is not specifically limited in this embodiment.

[0039] 200. Based on the node data and the node relationship data, obtain the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node.

[0040] The target tree structure includes all acquired nodes and the node relationships between each node and other nodes.

[0041] After obtaining the node data and node relationship data from 100, the maximum number of layers is calculated. In one example, the number of tree structures and the number of layers of each tree structure can be determined according to the node data and node relationship data, and the maximum number of layers with the highest number of layers can be determined from the numbers of layers of each tree structure.

[0042] For example: the node data is node A, node B, node C, node D, and node E. The node relationship data is node D and node E as leaf nodes. The parent node of node D and node E is node B. The parent node of node B is node A. Node E has a second parent node C. The maximum number of layers of the target tree structure can be calculated to be 3. Figure 2-2As shown, the E node and C node above constitute a tree structure, and the tree structure is specifically that the second layer is the E node which is a leaf node, and the first layer is the C node which is the parent node of the E node. It can be seen that the maximum number of layers of the tree structure constructed by the E node and the C node is two. The tree structure constructed by the A node, the B node, the D node, and the E node is a three-layer tree structure, and specifically the third layer is "the D node and the E node which are leaf nodes", the second layer is "the B node" which is the parent node of the D node and the E node, and the first layer is "the A node" which is the parent node of the B node. By comparison, it can be seen that the two-layer tree structure constructed by the E node and the C node above has one less layer than the three-layer tree structure constructed by the A node, the B node, the D node, and the E node. Therefore, the maximum number of layers of the tree structure constructed by the above nodes is 3.

[0043] Then continue to obtain all parent nodes corresponding to each node, using the above example to illustrate:

[0044] The parent node of node A is 0, the parent node of node B is 1 (node ​​A), the parent node of node C is 0, the parent node of node D is 1 (node ​​B), and the parent node of node E is 2 (node ​​B and node C).

[0045] It should be noted that, in some embodiments, a recursive method may be used to analyze node data and node relationship data to obtain the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node, which is not specifically limited in this embodiment.

[0046] 300. Generate a main tree structure in the target tree structure to be generated based on the maximum number of layers and all parent nodes corresponding to each node.

[0047] Wherein, each child node in the main tree structure corresponds to a parent node;

[0048] After obtaining the maximum number of layers and all parent nodes corresponding to each node from 200, the main tree structure is determined by the nodes involved in the maximum number of layers and the node relationships.

[0049] Continuing with the example in 200, it is known that the maximum number of layers is three, wherein the nodes involved in the three-layer main tree structure are "node D and node E as leaf nodes" in the third layer, "node B" as the parent node of node D and node E in the second layer, and "node A" as the parent node of node B in the first layer, such as Figure 2-3As shown, the method of constructing this tree structure can be: starting from node A, connect the direct child node B as the branch from the first layer to the second layer; then, connect the direct child nodes of node B, that is, node D and node E as leaf nodes, as the branches from the second layer to the third layer. In this way, we get a three-layer tree structure with node A as the root node, node B as the intermediate node, and node D and node E as leaf nodes.

[0050] 400. When there is at least one first child node in the main tree structure, at least one first corresponding parent node is added to the first child node of the main tree structure to generate a target tree structure, wherein the first child node is a child node corresponding to multiple parent nodes.

[0051] In some embodiments, corresponding to multiple parent nodes means including or having multiple parent nodes.

[0052] After the main tree structure is obtained from 300, since each node data and its node relationship data in the target tree structure are known, that is, all parent nodes corresponding to each node are known, then the parent node of each node is searched in the main tree structure to determine whether there is a node in the main tree structure with multiple parent nodes.

[0053] The example in 200 is continued to illustrate: wherein, the first child node is an E node, which includes two parent nodes, namely, a B node and a C node. The E node and the parent node of the E node (the B node) already exist in the main tree structure constructed by the A node, the B node, the D node and the E node. Therefore, a parent node (the C node) is added to the first child node (the E node) of the main tree structure to obtain a target tree structure, such as Figure 2-4 As shown, on the main tree structure constructed by node A, node B, node D and node E, the parent node of each node is searched. At this time, it is found that node E is the first child node and it also has a parent node, namely node C. Therefore, according to the level of node E, the level of its parent node C is obtained and added to the main tree structure.

[0054] Based on the above Figure 2-1 It can be seen from the implementation of the embodiment that the present invention provides a method for generating a tree structure, which determines the main tree structure by calculating the maximum number of layers in the node data and the node relationship data, and then adds parent nodes other than the main tree structure to the main tree structure based on the situation that its child nodes have multiple parent nodes. In the process of adding parent nodes, only the nodes visible to the user can be rendered, or the nodes that have been rendered can be applied, thereby reducing the rendering time and quickly completing the construction of the target tree structure. Figure 1As shown, nodes 11, 12, 21, 22, 23, and 31 are known. The parent node of node 31 is (node ​​22 and node 12), and the common parent node of nodes 21, 22, and 23 is node 11. The prior art adopts a segmentation processing method to construct a target tree structure, which results in the need to render the above nodes twice, and finally forms two independent target tree structures. However, if the above nodes adopt the technical method of the present invention, the main tree structure is constructed based on nodes 11, 21, 22, 23, and 31 as well as the relationship data between the nodes ( Figure 1 The tree structure on the left in the figure is generated, and a branch of node 12, the parent node of node 31, is added to the main tree structure, so as to render a complete target tree structure containing all nodes and their complex relationships at one time. It can be seen that the present invention reduces the number of rendering times of the tree structure diagram, improves the rendering speed of the page, and avoids the fragmentation of data. The superiors and subordinates of each node can be seen more intuitively, the relationship between nodes can be observed, and the readability of the data is improved.

[0055] In order to obtain the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node, in some embodiments of the present application, the aforementioned 200 includes 210.

[0056] 210. Based on the node data and the node relationship data, the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node are obtained using a preset node object model, wherein each node object of the preset node object model is provided with a parent node list for storing all parent nodes associated with the corresponding node.

[0057] After obtaining the node data and node relationship data from 100, it is necessary to analyze the superior-subordinate relationship between nodes so as to subsequently construct the target tree structure.

[0058] This embodiment adopts a preset node object model to obtain the hierarchical relationship between nodes, and then obtains the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node.

[0059] Specifically, a preset node object model containing parent node relationships is constructed. Each node object in the preset node object model contains a parent node list, which is used to store all parent nodes associated with the node. The maximum number of layers and all parent nodes corresponding to each node can be obtained based on the parent node list.

[0060] For example:

[0061] The parent node list corresponding to node A has 0 parent nodes, the parent node list corresponding to node B has 1 parent node (node ​​A), and the parent node list corresponding to node C has 2 parent nodes (node ​​B and node D). According to the parent node list, node A has no parent node, so node A can be used as the starting point, that is, node A is at the first level; then, we search for nodes related to node A, and we know that node A is the parent node of node B. Since node B is determined based on node A, node B is at the second level. Then, we search for nodes related to node B, and we know that node C’s parent node is node B. Since node C is determined based on node B, node C is at the third level. In addition, node C has another parent node D. If we assume that node D is at the second level (or at least at the same level or higher than node B, but it is considered at the second level according to the maximum number of levels), then the number of levels of the tree structure constructed by nodes A, B, and C is greater than the number of levels of the tree structure constructed by nodes C and D, that is, the maximum number of levels of the target tree structure is 3. That is, in the above process of determining the maximum number of layers, node A is located at the first layer of the target tree structure, and the child nodes related to node A are searched to determine the number of layers of the child nodes, and then the child nodes of the child nodes are searched and their layers are determined, and so on, until the parent node list of all child nodes is traversed to determine the maximum number of layers of the target tree structure. Through the layer-by-layer search method, the node location of the next layer depends on the node of the previous layer. The subordinate relationship thus constructed presents the characteristics of a superior-subordinate relationship, laying the foundation for the hierarchical construction of the target tree structure.

[0062] This embodiment sets a parent node list for each node to store the node information of the node according to the node data and node relationship data by presetting the node object model, which not only clearly shows the position and hierarchical relationship of each node in the entire structure, but also lays the foundation for the subsequent construction of the main tree structure and the target tree structure. In the process of building the tree structure, it can be quickly built directly based on the data that has been sorted out and stored in the parent node list, greatly improving the construction efficiency.

[0063] In order to construct the main tree structure, in some embodiments of the present application, the aforementioned 300 includes 310.

[0064] 310. Based on the target nodes involved in the maximum number of layers and all parent nodes corresponding to each of the target nodes, construct the main tree structure starting from the first child node in the target node.

[0065] In some embodiments, after obtaining the maximum number of layers and all parent nodes corresponding to each node from 200, starting from the first child node in the target node, a main tree structure is constructed according to the parent node list of the node.

[0066] If there is only one first child node in the target node for constructing the main tree structure, the specific construction process of the main tree structure is as follows: according to the parent node list of the target node, a child node with multiple parent nodes, that is, the first child node, is determined, and this node is used as the starting point for constructing the tree structure, and an X node that has a direct data relationship with the first child node is searched, and the X node is added to the first child node, and the relationship between the node and the first child node is a parent-child relationship, and then a Y node that has a direct data relationship with the newly added first child node in the tree structure is searched, and this node is added to the X node, and at this time, the relationship between the Y node and the X node is a parent-child relationship, and so on, until the construction of the main tree structure is completed according to the above node adding operation.

[0067] If there are multiple first child nodes in the target node for constructing the main tree structure, the first child nodes are traversed according to a preset order, and the construction process of constructing the tree structure of the first child nodes in the aforementioned content is executed for each first child node, that is, the above steps are repeated until all the first child nodes are traversed, and a complete main tree structure is constructed in this recursive manner, wherein the preset order can be sorted according to the number of parent nodes of the first child node, such as traversing the nodes with a high number of parent nodes first or traversing the nodes with a low number of parent nodes first, and the specific method of the preset order is not limited here.

[0068] Next, the example of step 210 is used to further explain how to construct the main tree structure in step 310 according to the target nodes involved in the maximum number of layers and all parent nodes corresponding to each of the target nodes, as follows:

[0069] It is known that "the parent node in the parent node list corresponding to node A is 0, the parent node in the parent node list corresponding to node B is 1 (node ​​A), the parent node in the parent node list corresponding to node C is 2 (node ​​B and node D), and the maximum number of layers is 3." Figure 2-5 As shown, the main tree structure constructed by the above nodes has three layers, and the target nodes involved in these three layers are A node, B node and C node as a leaf node. The construction of the main tree structure starts from C node as the first child node, and according to the parent node list corresponding to C node (the parent nodes are B node and D node), the parent node B node is constructed upward from C node. Since D node does not belong to the nodes involved in the maximum number of layers, D node is not constructed; then according to the parent node list corresponding to B node (the parent node is A node), the parent node A node is constructed upward from B node, and then the main tree structure with C node as a leaf node, B node as the parent node of C node, and A node as the parent node of B node is obtained through the above recursive method.

[0070] This embodiment explicitly starts from the first child node in the target node (i.e., the child node corresponding to multiple parent nodes) and constructs the main tree structure in the above-mentioned recursive manner, which can ensure that the main tree structure is constructed in an orderly manner in complex node relationships, reduce redundant steps in the construction process, and improve overall construction efficiency.

[0071] It should be noted that, in some embodiments, when constructing the main tree structure of the target tree structure, there is no first child node. In this case, the main tree structure is constructed starting from the root node or the leaf node in the target node.

[0072] In order to add a parent node other than the main tree structure to the main tree structure, in some embodiments of the present application, the aforementioned 400 includes 410 - 420 .

[0073] 410. Based on all parent nodes corresponding to each node, determine whether there is a first child node in the main tree structure.

[0074] The first child node is a child node corresponding to multiple parent nodes.

[0075] After obtaining the main tree structure and all the parent nodes corresponding to each node from 300, determine whether the node on the main tree structure has other parent nodes. Specifically, a node with multiple parent nodes can be obtained based on the parent node corresponding to each node, and then all the nodes on the main tree structure are matched based on the node with multiple parent nodes. If the match is successful, the corresponding node is determined as the first child node, that is, the main tree structure has the first child node, and step 420 needs to be executed subsequently; otherwise, the main tree structure does not have the first child node, and step 420 does not need to be executed.

[0076] 420. When there is at least one first child node in the main tree structure, add at least one corresponding parent node to each first child node of the main tree structure to generate a target tree structure.

[0077] The judgment result obtained from step 410 is that after there is at least one first child node in the main tree structure, other parent nodes other than the parent node that already exists in the main tree structure are added to the first child node one by one according to the preset order. The specific operation is: first, select the first first child node as the starting point according to the preset order; then, add a node with a direct data relationship with the first child node, at this time, the relationship between the node and the first child node is a parent-child relationship; then, process the next first child node in the same way until all first child nodes complete the establishment of a new parent-child relationship; finally, generate the target tree structure. Among them, the preset order can be sorted according to the number of parent nodes of the first child node, such as nodes with a large number of parent nodes give priority to adding parent nodes in the main tree structure or nodes with a small number of parent nodes give priority to adding parent nodes in the main tree structure, and can also be added to the main tree structure according to the hierarchical order of the first child node in the main tree structure, such as the first child node with a higher hierarchy gives priority to adding parent nodes other than the parent node on the main tree structure or the first child node with a lower hierarchy gives priority to adding parent nodes other than the parent node on the main tree structure. It should be understood that after a parent node is added to a first child node, the superior-subordinate relationship between the first child node and the added parent node remains unchanged, and the level at which the added parent node is located also remains unchanged.

[0078] For example:

[0079] The existing main tree structure is that the child node of node A is node B, the child nodes of node B are node C and node D, and node C and node D are leaf nodes. It is known that node B is the first child node, which corresponds to two parent nodes (node ​​A and node E), and node C is also the first child node, which corresponds to three parent nodes (node ​​B, node F and node G). Then, from the main tree structure, it can be obtained that Figure 2-6 As shown, the number of parent nodes of node C is greater than the number of parent nodes of node B, that is, starting from node C, first add the other parent nodes (node ​​F and node G) except the main tree structure to node C, and then process node B, add the other parent nodes (node ​​E) except the main tree structure to node B to obtain the target tree structure.

[0080] This embodiment completes the construction of the target tree structure by first finding the first child node on the main tree structure and then adding other parent nodes on the first child node to the first child node. This can avoid the fragmentation of data display, more intuitively see the upper and lower levels of each node, and improve the readability of data.

[0081] In order to better render the target tree structure, in some embodiments of the present application, such as Figure 3 As shown, after the aforementioned 400, 500-700 are also included.

[0082] 500. Render the first child node and the second child node in different rendering forms, where the second child node is a child node other than the first child node in the target tree structure, wherein the rendering form of the first child node is consistent with that of the corresponding parent node.

[0083] In the above steps, different rendering forms can be used. The details are as follows:

[0084] Color setting method: set a color, such as red, for the first child node and its corresponding parent node, and set a different color, such as green, for the second child node and its corresponding parent node. The colors have obvious visual differences, and users can quickly identify the different categories to which the first child node and the second child node and their corresponding parent node belong through different colors.

[0085] Simple shape setting method: set a shape for the first child node and its corresponding parent node, such as a square, and set a different shape for the second child node and its corresponding parent node, such as a triangle. The shapes have obvious visual differences, and users can quickly identify the different categories to which the first child node, the second child node, and their corresponding parent node belong through different shapes.

[0086] Mixed color and shape settings: Set one color and shape for the first child node and its corresponding parent node, such as a red square, and set another different color and shape for the second child node and its corresponding parent node, such as a green triangle. This method is not only differentiated in color, but also in shape. This mixed setting method is more visually rich and unique, allowing users to more accurately identify the type of the corresponding node through the dual characteristics of color and shape.

[0087] It is worth noting that the rendering form of the first child node is consistent with that of the corresponding parent node, which means that the first child node having multiple parent nodes on the target tree structure is rendered in different colors and / or different shapes, and the colors and / or shapes of all parent nodes corresponding to the first child node are consistent. Similarly, the rendering form of the second child node is also consistent with that of the corresponding parent node.

[0088] In the preset node object model, corresponding properties and methods can also be set for each node object, where the property can be a background color property, a shape property, etc., which is not specifically limited in this embodiment; the method can be a rendering method (such as a rendering function), a listening event (such as a click event listener), etc., which is not specifically limited in this embodiment, so as to facilitate subsequent operations and rendering.

[0089] Based on the above-mentioned rendering method using different colors and / or different shapes, the embodiment of the present application also provides interactive functions, such as expanding or collapsing child nodes when clicking a node, for example: the Collapse (folding panel) of the Element-Ui component (page layout component), so that users can view and operate the tree structure diagram more conveniently.

[0090] 600. Rendering some nodes visible to the user in the target tree structure by using a virtual scrolling method.

[0091] On the basis of the foregoing embodiments, such as on the basis of 500, the embodiment of the present application further adopts a virtual scrolling method to render some nodes visible to the user, thereby reducing the rendering time.

[0092] The virtual scrolling method is: using a scroll container and a container for displaying data, assuming a data array, calculating the number of data items that the container viewport can accommodate and the total number of data items based on the height of each data item in the data array, and then rendering the data based on the number of data items that the container viewport can accommodate and the total number of data items.

[0093] 700. Utilize a cache mechanism to cache the rendered nodes in the target tree structure.

[0094] Based on the above embodiments, such as 500 or 600, the embodiment of the present application also uses a cache mechanism to cache already rendered nodes so that they can be quickly reused when needed. The cache mechanism is a method that can implement caching, such as browser cache, which is not specifically limited in this embodiment.

[0095] Based on the above Figure 3 It can be seen from the implementation method that the present invention provides a method for generating a tree structure, which makes the relationship between nodes clearer and more intuitive through rendering methods of different colors and / or different shapes, and can more conveniently view and operate the target tree structure with the interactive function. The virtual scrolling method can reduce the rendering data and the cache mechanism can reduce the rendering times, avoid repeated rendering of the tree structure, and improve the page rendering speed.

[0096] It is worth noting that, in this embodiment, when rendering a large target tree structure, the optimization measures (such as virtual scrolling and caching mechanism) provided by 500, 600 and 700 can be used flexibly. Users can choose to apply a strategy alone or in combination according to actual needs to achieve optimal performance. This embodiment remains open to specific usage and does not set hard constraints.

[0097] To better explain the solution provided in the embodiments of the present application, Figure 4 As shown, the following examples are given.

[0098] (1) In the data acquisition stage, the client sends an HTTP (Hyper Text Transfer Protocol) request to the server and obtains node data and node relationship data from the server using the API interface.

[0099] Specifically: node 11, node 12, node 21, node 22, node 23, node 31, the parent node of node 31 is (node ​​22 and node 12), and the common parent node of node 21, node 22 and node 23 is node 11.

[0100] (2) Based on the node data and node relationship data, a preset node object model is used to obtain the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node.

[0101] Specifically, after obtaining the node data and node relationship data in step (1), the preset node object model is used to obtain that the parent node list of node 11 is empty, the parent node list of node 12 is empty, the parent node lists corresponding to nodes 21, 22 and 23 respectively record one parent node, which is node 11, and the parent node list of node 31 records two parent nodes, which are node 12 and node 22. The maximum number of layers is 3, of which the third layer is node 31, the second layer is nodes 21, 22 and 23, and the first layer is node 11.

[0102] (3) Based on the target nodes involved in the maximum number of layers and all parent nodes corresponding to each of the target nodes, the main tree structure is constructed starting from the first child node in the target node.

[0103] Specifically, after obtaining the maximum number of layers and all the parent nodes corresponding to each node in step (2), it can be known from the above data that the main tree structure has three layers, and the node data involved are node 11, node 21, node 22, node 23 and node 31. Node 31 with multiple parent nodes is used as the starting point for constructing the main tree structure. According to the fact that node 22 is the parent node of node 31, node 22 is added to node 31. At this time, the relationship between node 22 and node 31 is a parent-child relationship; then, according to the fact that the parent node of node 22 is node 11, node 11 is added to the node 22 of the constructed tree structure. The relationship between node 22 and node 11 is a parent-child relationship. Then, according to the fact that node 11 is the parent node of node 21 and node 23, node 21 and node 23 are added to the above tree structure respectively. At this time, node 21 and node 23 respectively form a parent-child relationship with node 11. After the above nodes are added, the main tree structure is obtained.

[0104] (4) Based on all parent nodes corresponding to each node, determine whether there is a first child node in the main tree structure.

[0105] Specifically: after the main tree structure is constructed in step (3), according to the above data, the node with two parent nodes in the main tree structure is node 31, whose parent nodes are node 22 and node 12 respectively. It can be seen that the first child node in the main tree structure is node 31.

[0106] (5) When there is at least one first child node in the main tree structure, at least one corresponding parent node is added to each first child node of the main tree structure to generate a target tree structure.

[0107] Specifically, in step (4), it is determined that there is a first child node, i.e., node 31, on the main tree structure. According to the above data, it can be known that node 31 has another parent node 12, that is, node 12 is added to node 31 of the main tree structure constructed in step (3). At this time, the relationship between node 12 and node 31 is a parent-child relationship. After node 12 is added, the target tree structure is generated. If there are other parent nodes in node 31 except node 22 and node 12 at this time, the other parent nodes are added to the main tree structure in the same way as node 12.

[0108] If there is at least one first child node in the main tree structure, add other parent nodes to the first child node one by one in accordance with the preset order except for the parent node that already exists in the main tree structure. The specific operation is: first, select the first first child node as the starting point according to the preset order; then, add a node with a direct data relationship to the first child node, and at this time, the relationship between the node and the first child node is a parent-child relationship; then, process the next first child node in the same way until all first child nodes have completed the establishment of a parent-child relationship; finally, generate the target tree structure. Among them, the preset order can be sorting according to the number of parent nodes of the first child node, such as nodes with a large number of parent nodes are given priority to add parent nodes in the main tree structure, and can also be adding parent nodes in the main tree structure according to the hierarchical order of the first child node in the main tree structure, such as first child nodes with higher hierarchies are given priority to add parent nodes other than the parent nodes on the main tree structure.

[0109] (6) Rendering the first child node and the second child node in different rendering forms, wherein the second child node is a child node other than the first child node in the target tree structure, wherein the rendering form of the first child node is consistent with that of the corresponding parent node.

[0110] Specifically, virtual scrolling can be used to render the first child node and the second node with multiple parent nodes on the target tree structure into different colors and / or different shapes, while all parent nodes corresponding to the first child node and the second child node have the same color and / or shape.

[0111] Specifically: taking the target tree structure determined above as an example, if node 31 as the first child node is set to a certain color and / or shape, at this time, the parent node corresponding to node 31 (node ​​22 and node 12) will also be set to the same color and / or shape as node 31 to distinguish it from other nodes.

[0112] On the other hand, as an implementation of the method shown in the above embodiment, the embodiment of the present invention also provides a device for generating a tree structure. The device embodiment corresponds to the above method embodiment. For ease of reading, the device embodiment will no longer repeat the details of the above method embodiment one by one, but it should be clear that the device in this embodiment can correspond to all the contents of the above method embodiment. Figure 5 As shown, the device comprises:

[0113] A first acquisition unit 31 is used to acquire node data and node relationship data;

[0114] A second acquisition unit 32 is used to acquire the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node based on the node data and the node relationship data obtained from the first acquisition unit 31;

[0115] A first generating unit 33 is configured to generate a main tree structure in the target tree structure to be generated based on the maximum number of layers obtained from the second acquiring unit 32 and all parent nodes corresponding to each node; wherein each child node in the main tree structure corresponds to a parent node;

[0116] The second generating unit 34 is used to add at least one corresponding parent node to the first child node of the main tree structure when there is at least one first child node in the main tree structure obtained from the first generating unit 33, so as to generate the target tree structure, wherein the first child node is a child node corresponding to multiple parent nodes.

[0117] In some embodiments, as a Figure 3 In order to realize the method shown in the figure, the embodiment of the present invention also provides another tree structure generation device for the above Figure 2-1 The method shown is further implemented. This device embodiment corresponds to the aforementioned method embodiment. For ease of reading, this device embodiment will not repeat the details of the aforementioned method embodiment one by one, but it should be clear that the device in this embodiment can correspond to all the contents of the aforementioned method embodiment. Figure 6 As shown, the device comprises:

[0118] A first acquisition unit 31 is used to acquire node data and node relationship data;

[0119] A second acquisition unit 32 is used to acquire the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node based on the node data and the node relationship data obtained from the first acquisition unit 31;

[0120] A first generating unit 33 is configured to generate a main tree structure in the target tree structure to be generated based on the maximum number of layers obtained from the second acquiring unit 32 and all parent nodes corresponding to each node; wherein each child node in the main tree structure corresponds to a parent node;

[0121] A second generating unit 34 is configured to, when the main tree structure obtained from the first generating unit 33 has at least one first child node, add at least one corresponding parent node to the first child node of the main tree structure to generate the target tree structure, wherein the first child node corresponds to child nodes of multiple parent nodes;

[0122] A first rendering unit 35 is configured to render the first child node and the second child node obtained by the second generating unit 34 in different rendering forms, wherein the second child node is a child node other than the first child node in the target tree structure, wherein the first child node has the same rendering form as the corresponding parent node;

[0123] A second rendering unit 36 ​​is used to render, by using a virtual scrolling method, a portion of nodes visible to a user in the target tree structure obtained from the first rendering unit 35;

[0124] The cache unit 37 is used to cache the nodes in the target tree structure that have been rendered by the second rendering unit 36 ​​by using a cache mechanism.

[0125] In some embodiments, the second obtaining unit 32 is further configured to:

[0126] Based on the node data and the node relationship data, a preset node object model is used to obtain the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node; wherein each node object of the preset node object model is provided with a parent node list for storing all parent nodes associated with the corresponding node.

[0127] In some embodiments, the first generating unit 33 is further configured to:

[0128] Based on the target nodes involved in the maximum number of layers and all parent nodes corresponding to each of the target nodes, the main tree structure is constructed starting from the first child node in the target node.

[0129] In some embodiments, the second generating unit 34 includes:

[0130] A judgment module 341 is used to judge whether there is a first child node in the main tree structure based on all parent nodes corresponding to each node;

[0131] The generating module 342 is configured to add at least one corresponding parent node to each of the first child nodes in the main tree structure to generate the target tree structure when there is at least one first child node in the main tree structure.

[0132] In some embodiments, the present invention further provides a processor, the processor is used to run a program, wherein the program executes the above Figure 2-1 to Figure 4 The method for generating the tree structure described in .

[0133] In some embodiments, the present invention further provides a storage medium, wherein the storage medium is used to store a computer program, wherein when the computer program is running, the device where the storage medium is located is controlled to execute the above Figure 2-1 to Figure 4 The method for generating the tree structure described in .

[0134] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0135] It is understandable that the related features in the above methods and devices can be referenced to each other. In addition, the "first", "second" and the like in the above embodiments are used to distinguish the embodiments, but do not represent the advantages and disadvantages of the embodiments.

[0136] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0137] The algorithm and display provided herein are not inherently related to any particular computer, virtual system or other device. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious that the structure required for constructing such systems. In addition, the present invention is not directed to any specific programming language either. It should be understood that various programming languages ​​can be utilized to realize the content of the present invention described herein, and the description of the above specific languages ​​is for disclosing the best mode of the present invention.

[0138] In addition, the memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0139] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0140] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0141] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0142] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0143] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0144] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0145] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0146] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0147] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0148] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.

Claims

1. A method for generating a tree structure, characterized in that: The method comprises: Get node data and node relationship data; Based on the node data and the node relationship data, obtaining the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node; Based on the maximum number of layers and all parent nodes corresponding to each node, a main tree structure in the target tree structure to be generated is generated; wherein each child node in the main tree structure corresponds to a parent node; When the main tree structure has at least one first child node, at least one corresponding parent node is added to the first child node of the main tree structure to generate the target tree structure, and the first child node is a child node corresponding to multiple parent nodes.

2. The method according to claim 1, characterized in that The step of obtaining the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node based on the node data and the node relationship data includes: Based on the node data and the node relationship data, a preset node object model is used to obtain the maximum number of layers of the target tree structure to be generated and all parent nodes corresponding to each node; wherein each node object of the preset node object model is provided with a parent node list for storing all parent nodes associated with the corresponding node.

3. The method according to claim 2, characterized in that The generating a main tree structure in the target tree structure to be generated based on the maximum number of layers and all parent nodes corresponding to each node includes: Based on the target nodes involved in the maximum number of layers and all parent nodes corresponding to each of the target nodes, the main tree structure is constructed starting from the first child node in the target node.

4. The method according to claim 3, characterized in that When the main tree structure has at least one first child node, at least one corresponding parent node is added to the first child node of the main tree structure to generate the target tree structure, wherein the first child node is a child node corresponding to multiple parent nodes, including: Based on all parent nodes corresponding to each node, determining whether the first child node exists in the main tree structure; When there is at least one first child node in the main tree structure, at least one corresponding parent node is added to each of the first child nodes in the main tree structure to generate the target tree structure.

5. The method according to any one of claims 1 to 4, characterized in that: When the main tree structure has at least one first child node, at least one corresponding parent node is added to the first child node of the main tree structure to generate the target tree structure, and the first child node is a child node corresponding to multiple parent nodes, the method further includes: The first child node and the second child node are rendered in different rendering forms, the second child node being a child node other than the first child node in the target tree structure, wherein the rendering form of the first child node is consistent with that of the corresponding parent node.

6. The method according to claim 5, characterized in that The method further comprises: Rendering a portion of nodes visible to a user in the target tree structure by using a virtual scrolling method; and / or The rendered nodes in the target tree structure are cached using a cache mechanism.

7. A tree structure generation device, characterized in that: include: A first acquisition unit, used to acquire node data and node relationship data; A second acquisition unit, configured to acquire, based on the node data and the node relationship data, a maximum number of layers of a target tree structure to be generated and all parent nodes corresponding to each node; A first generating unit is configured to generate a main tree structure in the target tree structure to be generated based on the maximum number of layers and all parent nodes corresponding to each node; wherein each child node in the main tree structure corresponds to a parent node; The second generating unit is used to add at least one corresponding parent node to the first child node of the main tree structure to generate the target tree structure when there is at least one first child node in the main tree structure, wherein the first child node is a child node corresponding to multiple parent nodes.

8. A storage medium comprising a stored program, characterized in that: When the program is running, the device where the storage medium is located is controlled to execute the method for generating a tree structure as described in any one of claims 1 to 6.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, all or part of the steps of the method for generating a tree structure according to any one of claims 1 to 6 are implemented.

10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of the method for generating a tree structure as described in any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Tree control construction method, system and equipment and storage medium

    CN118377473A

  • Diagramming child nodes with multiple parent nodes

    US11336532B1

  • Identifying and graphically representing multiple parent nodes of a child node

    US20200042639A1