insertSplitOutcomes method

void insertSplitOutcomes(
  1. NodeOutput item,
  2. State state,
  3. TraverseQueue levelQueue
)

Implementation

void insertSplitOutcomes(
    NodeOutput item, State state, TraverseQueue levelQueue) {
  var queue = state.queue, outcomes = this.outcomes(item.id);
  if (outcomes.length == 0) throw "split ${item.id} has no outcomes";
  outcomes = List.from(outcomes);
  if (centred) {
    int initialY = state.y;
    List<String> topOutcomes = [];
    int half = (outcomes.length.toDouble() / 2).ceil() - 1;

    while (half != 0) {
      half--;
      if (state.y == 0 ||
          state.mtx.hasHorizontalCollision(state.x, state.y - 1)) {
        state.mtx.insertRowBefore(state.y);
        initialY++;
      } else {
        state.y--;
      }

      topOutcomes.add(outcomes.removeAt(0));
    }
    topOutcomes.forEach((String outcomeId) {
      String id = "${item.id}-$outcomeId";
      insertNodeOnMatrix(
        NodeOutput(
          id: id,
          next: [EdgeInput(outcome: outcomeId)],
          anchorType: AnchorType.split,
          anchorMargin: AnchorMargin.end,
          orientation: AnchorOrientation.topLeft,
          from: item.id,
          to: outcomeId,
          isAnchor: true,
          renderIncomes: [item.id],
          passedIncomes: [item.id],
          childrenOnMatrix: 0,
        ),
        state,
        true,
      );
      NodeInput v = this.node(outcomeId);
      queue.add(incomeId: id, bufferQueue: levelQueue, items: [v]);
      state.y++;
    });
    state.y = initialY;
  }
  String directOutcomeId = outcomes.removeAt(0);
  NodeInput direct = this.node(directOutcomeId);
  queue.add(incomeId: item.id, bufferQueue: levelQueue, items: [
    NodeInput(
      id: direct.id,
      next: direct.next,
      size: direct.size,
    )
  ]);
  outcomes.forEach((String outcomeId) {
    state.y++;
    String id = "${item.id}-$outcomeId";
    insertNodeOnMatrix(
      NodeOutput(
        id: id,
        next: [EdgeInput(outcome: outcomeId)],
        anchorType: AnchorType.split,
        anchorMargin: AnchorMargin.end,
        orientation: AnchorOrientation.bottomLeft,
        from: item.id,
        to: outcomeId,
        isAnchor: true,
        renderIncomes: [item.id],
        passedIncomes: [item.id],
        childrenOnMatrix: 0,
      ),
      state,
      true,
    );
    NodeInput v = this.node(outcomeId);
    queue.add(incomeId: id, bufferQueue: levelQueue, items: [v]);
  });
}