Workflow automatic layout method based on topological sorting and dynamic adjustment

By employing a topology-based sorting and dynamic adjustment approach, this study addresses the efficiency and robustness issues of workflow layout in complex modular systems, enabling efficient visualization of modular systems. It is applicable to software-based systems, microservice architectures, and low-code platforms.

CN121832898APending Publication Date: 2026-04-10CHINA SHIPBUILDING IND CORP NO 723 RESEARCH INSTITUTE
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-04
Publication Date
2026-04-10

Smart Images

  • Figure CN121832898A_ABST
    Figure CN121832898A_ABST
Patent Text Reader

Abstract

The invention discloses a workflow automatic layout method based on topological sorting and dynamic adjustment, which comprises the following steps of: analyzing input data, constructing a workflow directed graph of modules and a connection relationship thereof, constructing an adjacency list and an in-degree list based on the workflow directed graph, and then hierarchically dividing the modules by using an improved topological sorting algorithm, and dynamically calculating the coordinate position of each module in the canvas in combination with canvas boundary constraint and minimum spacing limitation, finally outputting JSON data containing complete layout information of each module, and realizing flow chart drawing in combination with a front-end visualization technology. According to the scheme, the problems of low manual layout efficiency, node omission, layout chaos and the like caused by loop dependence in a traditional layout algorithm are effectively solved, and the method has a good visualization effect and high adaptability and can be applied to automatic layout and scene generation of the flow chart of modular systems such as a software system, a micro-service architecture and a low-code platform.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the field of computer graphics and automatic layout, and particularly relates to a work flow automatic layout method based on topological sorting and dynamic adjustment. BACKGROUND

[0002] Software and modular design has become a key technical means to realize system decoupling, improve maintainability and scalability. In typical scenarios such as software application, micro-service system and process engine, the running logic of the system is usually interacted by multiple functional modules through explicit data flow or control flow, thereby constituting a complete task execution process, which is called work flow. In order to enhance the understandability and operability of the system logic, presenting these modules and their connection relationships in a graphical manner has become an important means to improve user experience and development efficiency.

[0003] At present, the automatic layout of work flow mainly relies on two types of mainstream algorithms: one is force-directed layout algorithm based on physical simulation, and the other is topological sorting layout algorithm based on hierarchical division. Among them, the force-directed layout optimizes the layout effect by simulating the attractive and repulsive relationship between nodes, has good visual aesthetics, but has large calculation overhead and slow convergence speed, which is difficult to meet the real-time update demand; while the traditional topological sorting layout realizes efficient arrangement through hierarchical division and coordinate allocation, which is suitable for directed acyclic graph (DAG) structure, but the above methods will face the following problems:

[0004] 1. The force-directed layout has large calculation overhead and slow convergence speed, which is difficult to meet the real-time update demand;

[0005] 2. The traditional topological sorting layout cannot complete complete layout in the presence of circular dependency, resulting in some nodes being missed, affecting the integrity and accuracy of the overall flowchart.

[0006] In addition, the existing automatic layout method generally lacks effective evaluation mechanism for canvas space utilization rate, and when the number of nodes is large or the connection relationship is complex, local density and overall deviation problems may occur, reducing the readability of the visual flowchart. At the same time, most methods do not fully consider the front-end drawing constraints such as module size and minimum distance, resulting in overlapping, misplacement and other phenomena in the actual rendering process of the generated layout result, which still needs manual intervention and adjustment, limiting the practicality and universality of the automatic layout.

[0007] In summary, the existing work flow layout technology has many limitations in dealing with complex modular systems, and an automatic layout method that can realize clear, reasonable and strong adaptability in limited canvas space is urgently needed. Especially for actual application scenarios with circular dependency, a solution that takes into account layout efficiency and robustness is needed to realize efficient visualization support for modular system work flow. SUMMARY

[0008] In view of the above problems, the present application aims to provide a workflow automatic layout method based on topological sorting and dynamic adjustment, which is efficient, adaptable, reasonable in layout and can be applied to software system and other workflow automatic analysis generation and visual scene.

[0009] The specific technical solutions for achieving the object of the present application are as follows:

[0010] A workflow automatic layout method based on topological sorting and dynamic adjustment comprises the following steps:

[0011] Step 1: Analyzing input data and constructing a workflow directed graph of modules and their connection relationships;

[0012] Step 2: Based on the workflow directed graph, constructing an adjacency list and an in-degree list ;

[0013] Step 3: Using an improved topological sorting algorithm to divide the modules into levels;

[0014] Step 4: Dynamically calculating the coordinate positions of the modules in the canvas in combination with canvas boundary constraints and minimum spacing restrictions;

[0015] Step 5: Outputting JSON data containing complete layout information of the modules and realizing flowchart drawing in combination with front-end visualization technology.

[0016] Compared with the prior art, the present application has the following advantages:

[0017] (1) The scheme of the present application constructs an automatic layout algorithm framework suitable for modular systems, breaks through the limitations of low efficiency and easy errors of traditional manual layout, and significantly improves the efficiency and maintainability of flowchart generation;

[0018] (2) The scheme of the present application introduces an improved topological sorting algorithm, which breaks the loop constraint by forcing the in-degree to be zero in the presence of circular dependencies, ensures that all nodes can participate in layout calculation, solves the problem that traditional topological sorting cannot handle closed-loop structures, and enhances the robustness and universality of the algorithm;

[0019] (3) The scheme of the present application adopts a dynamic coordinate allocation mechanism of preferential horizontal arrangement and vertical expansion, in combination with canvas boundary and minimum spacing constraints, realizes the adaptive distribution of modules in limited space, avoids visualization problems such as node overlap and layout disorder, and improves the readability and aesthetics of the flowchart;

[0020] ​(4) The scheme of the present application designs a mathematical modeling method of module size and minimum spacing, so that the layout result can be adapted to various front-end rendering engines (such as jsPlumb, etc.), and has good engineering practicability and cross-platform compatibility;

[0021] (5) The method is suitable for flowchart automatic generation and visual scene of modularized system such as software system, micro-service architecture and low-code platform, and has good adaptability and robustness.

[0022] The present application will be further described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF DRAWINGS

[0023] Figure 1 It is a flowchart of the work flow automatic layout method based on topological sorting and dynamic adjustment of the present application.

[0024] Figure 2 It is a scene diagram in the embodiment of the present application, that is, the configuration content information of a certain function module of software.

[0025] Figure 3 It is a work flow visual interface diagram output by the present application. DETAILED DESCRIPTION

[0026] EMBODIMENT

[0027] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. The described embodiments are only some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.

[0028] As shown in the present application and claims, unless the context clearly indicates otherwise, the words “one”, “a”, “an” and / or “the” do not refer to the singular, but can also include the plural. Generally, the terms “comprise” and “include” only indicate the inclusion of the steps and elements explicitly identified, and these steps and elements do not constitute an exclusive list, and the method or device can also include other steps or elements.

[0029] The foregoing description, for purposes of explanation, uses specific nomenclature to provide a thorough understanding of the application. However, the application described herein can be practiced without the use of this specific nomenclature. The specific nomenclature is used merely to ease description of the embodiments. In this document, relational terms such as first, second, top, bottom, and the like can be used solely to distinguish one entity or action from another entity or action, without necessarily requiring or implying any actual such relationship or order between such entities or actions. The terms "comprises," "comprising," "includes," "including," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises, has, includes, or includes elements or steps that are not recited in a claiming paragraph can still be within the scope of that process, method, article, or apparatus. An exception to this definition will occur when an element is specifically recited as "consisting of' or "consisting essentially of' a list of two or more elements but no additional element is present outside of that list. The terms "a," "an," or "the" can be used interchangeably, and each refer to one or more, unless otherwise indicated by the context. The term "about" means approximately or nearly as understood by those of ordinary skill in the art. The term "coupled" as used herein is intended to mean the direct or indirect coupling between elements, and can be mechanical, electrical, magnetic, or any combination thereof. The term "program," "software program," or "software" as used herein is intended to mean any sequence of instructions designed for execution on a computer system or processing element, and can refer to system software, application software, or both. The term "processing element" as used herein is intended to include any hardware, firmware, or software that is used to execute instructions or process data. The term "computer system" as used herein is intended to include any system that includes one or more processing elements.

[0030] In conjunction with Figure 1 , a workflow automatic layout method based on topological sorting and dynamic adjustment, comprising the following steps:

[0031] Step 1, parse the input data, and construct the workflow directed graph of the module and its connection relationship , wherein represents a set of modules, i.e. a set of nodes, represents a set of connection relationships (i.e. data flow) between modules;

[0032] Here, the module refers to an independent functional service with clear input and output interfaces in a software system (or other similar system) that is managed through a platform such as Nacos, and obtains information between modules through input workflow data;

[0033] Step 2, based on the workflow directed graph, construct an adjacency list and an in-degree list ;

[0034] The adjacency list is used to represent the set of subsequent nodes of the node , and the in-degree list represents the in-degree of the node , :

[0035] ;

[0036] ;

[0037] Here, the subsequent node refers to a downstream module that directly depends on the output of the current module and is executed after it;

[0038] For example, the directed graph obtained for the workflow resolution is: signal acquisition → signal processing → target detection, then for the node v = "signal processing", its successor node is "target detection".

[0039] Step 3, using the improved topological sorting algorithm to divide the modules into levels:

[0040] Step 3-1, initialize an empty queue , add all nodes satisfying =0 to the queue;

[0041] Step 3-2, take out the nodes from the queue one by one , add them to the current layer , and update the in-degree values of all their successor nodes :

[0042]

[0043] where represents the i-th level, and initially i=0;

[0044] If the updated , add the node to the queue , and enter the next level, i=i+1, repeat the step operation until all nodes are traversed.

[0045] Step 3-3, if there are still unvisited nodes after topological sorting, execute the forced in-degree zero strategy on these nodes, and continue the layering process:

[0046] After topological sorting is completed, detect the set of unvisited nodes ;

[0047] For any , set , and add it to the queue to continue participating in topological sorting until all nodes complete the level division.

[0048] The strategy is used to break the circular dependency and ensure that all modules can participate in layout calculation.

[0049] Step 4, dynamically calculate the coordinate positions of each module in the canvas combining the canvas boundary constraints and minimum distance restrictions, this step is used to calculate the final, unique, and non-overlapping coordinate positions (x, y) for each module on the canvas according to the logical level division results generated in step 3 above, combining the actual physical drawing constraints.

[0050] Step 4-1, set the layout constraint conditions, the canvas area is a rectangular space , and the module width is The height is The minimum horizontal and vertical spacing is ;

[0051] Step 4-2: Calculate the total width of the current layer:

[0052]

[0053] in, This represents the number of modules in the l-th layer;

[0054] Step 4-3: If the width of the current row exceeds the maximum width of the canvas. If the line breaks, the text will wrap and expand downwards, updating the vertical starting position to:

[0055]

[0056] in, It refers to the first The starting vertical position of all modules in the layer. It refers to the first The starting vertical position of all modules in layer +1 is adjusted, and they are rearranged horizontally starting from the left side of the canvas based on the updated starting vertical position.

[0057] Step 4-4: Dynamically adjust the position of horizontally arranged modules. The horizontal coordinates of the current layer modules are assigned as follows:

[0058]

[0059]

[0060] in Indicates the current level. For the first The x-axis of the layer module, Indicates the first The final number of modules in the layer.

[0061] Step 5: Output JSON data containing complete layout information for each module, and use front-end visualization technology to draw the flowchart.

[0062] nodeList: Each module has a unique identifier (id), name (nodeName), initial coordinates (x, y), and width and height information for workflow visualization;

[0063] linkList: The source node sourceId, target node targetId, and connection style information for each connection relationship.

[0064] The updated module coordinate information is used for a front-end flowchart rendering engine (such as jsPlumb) to perform work flow graphical display.

[0065] In this embodiment, nacos is used as a configuration management and service management platform of the functional modules, each functional module is a service, and input and output configurations of the service can be queried in the configuration management through a nacos query interface. Configuration contents of each service are as shown in Figure 2 The configuration contents include an IP, a port, input configurations, output configurations and the like, and the relationship between each functional module and other modules, i.e., a work flow relationship, can be obtained through analysis of the input and output configurations of each functional module.

[0066] Hardware platform: server, CPU is Intel Xeon(R) E5-2640 v3, main frequency is 2.6 GHz, and GPU is NVIDIA GeForce RTX 3060;

[0067] Operating system: Ubuntu 18.04.6 LTS;

[0068] Development tool: Vue2.9.6, Java1.8, Springboot2.3.4, jsplumb2.11.0

[0069] Under the above experimental conditions, first, the function services of each module are run, a service list currently running is obtained through a nacos service management interface, and then configuration contents corresponding to each service are queried. The configuration contents of each module currently running are combined, the combined data is analyzed using the method of the application, a directed graph and an adjacency list and an in-degree list of the graph are constructed, and the nodes of each module are hierarchically divided using the improved topological sorting algorithm in the application. For unvisited nodes, a forced in-degree zero strategy is used to re-perform topological sorting, dynamic coordinate calculation of each module is performed, a final module work flow layout result is output, and visualization is performed.

[0070] Figure 3 For a work flow visualization interface, Figure 3 It can be seen that the method of the application is used to automatically layout a software work flow based on input and output relationships of each module of the software. From the layout result, it can be seen that the method of the application achieves a good work flow visualization effect through the improved topological sorting and dynamic coordinate adjustment, and there is no node overlapping and layout confusion. Meanwhile, the method has drag, edit and interactive functions, and can clearly display communication protocol information and data flow directions between modules.

[0071] The above-described embodiments are merely illustrative of several embodiments of the present application, which are described in more detail and in a specific and detailed manner, but should not be construed as limiting the scope of the patent. It should be noted that for those skilled in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application should be subject to the appended claims.

Claims

1. A method for automatic layout of workflow based on topological sorting and dynamic adjustment, characterized in that, The method comprises the following steps: Step 1, parsing input data, constructing a workflow directed graph of modules and their connection relationships; Step 2, based on the workflow directed graph, construct the adjacency list and the in-degree list ; Step 3, using an improved topological sorting algorithm to divide the modules into levels; Step 4, combining canvas boundary constraints and minimum spacing restrictions to dynamically calculate the coordinate positions of each module in the canvas; Step 5, outputting JSON data containing complete layout information of each module, and realizing flowchart drawing by combining front-end visualization technology.

2. The method of claim 1, wherein, The workflow directed graph in step 1 is wherein represents a set of modules, represents a set of connection relationships (i.e., data flows) among the modules.

3. The method of claim 2, wherein, The adjacency list in step 2 For representing a module node The in-degree table of the subsequent node set The in-degree of the node :​ ; 。 4. The method of claim 1, wherein, In step 3, the improved topological sorting algorithm is used to divide the modules into levels, specifically: Step 3-1, initialize an empty queue All nodes that satisfy =0 are added to the queue; Step 3-2, take the nodes from the queue in order and add them to the current layer and update the in-degree values of all their successor nodes ​ ; wherein represents the i-th level, initially i = 0; If updated , the node is added to the queue , and the next layer is entered, i = i + 1, and the operation of this step is repeated until all nodes are traversed. Step 3-3, if there are still unvisited nodes after topological sorting, perform a forced in-degree zero strategy on these nodes and continue the layering process.

5. The method of claim 4, wherein, In step 3-3, the forced in-degree zero strategy is specifically: After the topological sorting is completed, a set of unvisited nodes is detected ; For any , set , and add it to the queue to continue participating in the topological sort until all nodes complete the hierarchy partitioning; The strategy is used to break the circular dependency and ensure that all modules can participate in layout calculation.

6. The method for automatic workflow layout based on topological sorting and dynamic adjustment according to claim 1, wherein, In step 4, the canvas boundary constraints and minimum spacing restrictions are combined to dynamically calculate the coordinate positions of each module in the canvas, specifically: Step 4-1, set layout constraint condition, canvas area is rectangular space , module width is , height is , horizontal and vertical minimum distance is ; Step 4-2, calculate the total width of the current layer: ; wherein represents the number of modules of the lth layer; Step 4 - 3, if the current layer width exceeds the canvas maximum width then wrap and extend down, updating the vertical start position to: ; wherein, refers to the starting longitudinal position of the first layer of all modules, refers to the starting longitudinal position of the first +1 layer of all modules, re-arranged horizontally from the left side of the canvas according to the updated longitudinal starting position; Step 4-4, dynamically adjust the horizontal arrangement of modules, and the modules in the current layer are allocated horizontal coordinates as follows: ; ; wherein represents the current level, is the first more modular horizontal coordinate for the layer.

7. The method of claim 1, wherein, The JSON data output in step 5 includes: nodeList: each module has a unique identifier id, name nodeName, initial coordinates x, y, width height information width, height for workflow visualization; linkList: source node sourceId, target node targetId, and connection line style information of each connection relationship.

8. A workflow automatic layout system based on topological sorting and dynamic adjustment, characterized in that, The method comprises the following modules: Data parsing module: used to parse input data, construct a workflow directed graph of modules and their connection relationships; Layout module: for constructing adjacency list based on workflow directed graph and in-degree list , using improved topological sorting algorithm to divide the module into layers, combined with the canvas boundary constraints and minimum spacing limit, dynamically calculate the coordinate position of each module in the canvas; Data output module: used to output JSON data containing complete layout information of each module, and realize flowchart drawing by combining front-end visualization technology.

9. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor executes the computer program to realize the steps of the method of any one of claims 1-6.

10. A computer storable medium having stored thereon a computer program, characterized in that The computer program is executed by the processor to realize the steps of the method of any one of claims 1-6.