insertJoinIncomes method

void insertJoinIncomes(
  1. NodeOutput item,
  2. State state,
  3. TraverseQueue levelQueue,
  4. bool addItemToQueue,
)

Implementation

void insertJoinIncomes(NodeOutput item, State state, TraverseQueue levelQueue,
    bool addItemToQueue) {
  final mtx = state.mtx, queue = state.queue, incomes = item.passedIncomes;
  final directY = centred
      ? this.getCenterYAmongIncomes(item, mtx)
      : this.getLowestYAmongIncomes(item, mtx);
  incomes.forEach((String incomeId) {
    final found = mtx.findNode((NodeOutput n) {
      return n.id == incomeId;
    });
    if (found == null) throw "income $incomeId was not found";
    final y = found.coords[1], income = found.item;
    if (directY == y) {
      item.renderIncomes.add(incomeId);
      income.childrenOnMatrix =
          min((income.childrenOnMatrix ?? 0) + 1, income.next.length);
      return;
    }
    state.y = y;
    String id = "$incomeId-${item.id}";
    item.renderIncomes.add(id);
    insertNodeOnMatrix(
      NodeOutput(
        id: id,
        next: [EdgeInput(outcome: item.id)],
        anchorType: AnchorType.join,
        anchorMargin: AnchorMargin.start,
        orientation: y > directY
            ? AnchorOrientation.bottomRight
            : AnchorOrientation.topRight,
        from: incomeId,
        to: item.id,
        isAnchor: true,
        renderIncomes: [incomeId],
        passedIncomes: [incomeId],
        childrenOnMatrix: 1,
      ),
      state,
      false,
    );
  });
  if (addItemToQueue) {
    queue.add(
        incomeId: item.id,
        bufferQueue: levelQueue,
        items: getOutcomesArray(item.id));
  }
  return;
}