importStates()

in saga/seata-saga-statemachine-designer/src/spec/style/Node.js [303:421]


  importStates(definitions, startState, begin, adjList) {
    const visited = [];
    const queue = [];
    if (begin !== null) {
      if (startState.style === undefined) {
        startState.style = {};
        if (startState.style.bounds === undefined) {
          startState.style.bounds = {
            x: begin.style.bounds.x + 150, // Adjust x-coordinate
            y: begin.style.bounds.y, // Adjust y-coordinate
            width: DEFAULT_WIDTH,
            height: DEFAULT_HEIGHT,
          };
        }
      }
      this.importJson(startState);
    }
    queue.push(startState);

    function setBounds(neighbor, x, y, width1, height1) {
      if (neighbor.style.bounds === undefined) {
        neighbor.style.bounds = {
          x, // Adjust x-coordinate
          y, // Adjust y-coordinate
          width: width1,
          height: height1,
        };
        visited.push([x, y]);
      }
    }

    while (queue.length) {
      const currentState = queue.shift();

      adjList.get(currentState).forEach((neighbor) => {
        if (neighbor.style === undefined) {
          neighbor.style = {};
          if (is(neighbor, 'End')) {
            const target = [];
            target.push(currentState.style.bounds.x + 150, currentState.style.bounds.y);
            if (this.isElementPresent(visited, target)) {
              setBounds(
                neighbor,
                currentState.style.bounds.x + 150,
                currentState.style.bounds.y,
                OFFSET_X,
                OFFSET_X,
              );
            } else {
              setBounds(
                neighbor,
                currentState.style.bounds.x,
                currentState.style.bounds.y + 150,
                OFFSET_X,
                OFFSET_X,
              );
            }
          }

          if (is(neighbor, 'Task') && !neighbor.IsForCompensation) {
            const target = [];
            target.push(currentState.style.bounds.x + 150, currentState.style.bounds.y);
            if (this.isElementPresent(visited, target)) {
              setBounds(
                neighbor,
                currentState.style.bounds.x + 150,
                currentState.style.bounds.y,
                DEFAULT_WIDTH,
                DEFAULT_HEIGHT,
              );
            } else {
              setBounds(
                neighbor,
                currentState.style.bounds.x,
                currentState.style.bounds.y + 150,
                DEFAULT_WIDTH,
                DEFAULT_HEIGHT,
              );
            }

            const { Name } = neighbor;
            queue.push(definitions.States[Name]);
          } else if (is(neighbor, 'Task') && neighbor.IsForCompensation) {
            const target = [];
            target.push(currentState.style.bounds.x, currentState.style.bounds.y + 150);
            if (this.isElementPresent(visited, target)) {
              setBounds(
                neighbor,
                currentState.style.bounds.x,
                currentState.style.bounds.y + 150,
                DEFAULT_WIDTH,
                DEFAULT_HEIGHT,
              );
            }
          } else if (is(neighbor, 'CompensationTrigger')) {
            setBounds(
              neighbor,
              currentState.style.bounds.x,
              currentState.style.bounds.y - 150,
              OFFSET_X,
              OFFSET_X,
            );
            const { Name } = neighbor;
            queue.push(definitions.States[Name]);
          } else if (is(neighbor, 'Choice')) {
            setBounds(
              neighbor,
              currentState.style.bounds.x + 150,
              currentState.style.bounds.y,
              50,
              50,
            );
            const { Name } = neighbor;
            queue.push(definitions.States[Name]);
          }
        }
      });
    }
  }