# HG changeset patch # User Chris Cannam # Date 1295264657 0 # Node ID b8ded5213d16e095cc3582489d8a601b485db551 # Parent 45f69889d28d57d7574a6d480ad5ea7cf9ac85c5 * Revert the grapher change from revision ec2baee80833 on Dec 19th 2010. The change definitely performed worse than the original (now reinstated) logic in the real-world soundsoftware-site case, with far more connection overlaps and ambiguous placements. diff -r 45f69889d28d -r b8ded5213d16 grapher.cpp --- a/grapher.cpp Wed Jan 12 16:38:13 2011 +0000 +++ b/grapher.cpp Mon Jan 17 11:44:17 2011 +0000 @@ -23,10 +23,7 @@ #include -#include - -int Grapher::findAvailableColumn(int row, int parent, int sign, - bool preferParentCol) +int Grapher::findAvailableColumn(int row, int parent, bool preferParentCol) { int col = parent; if (preferParentCol) { @@ -39,9 +36,7 @@ if (isAvailable(row, ++col)) return col; } col = parent; - if (sign == 0) { - sign = (col < 0 ? -1 : 1); - } + int sign = (col < 0 ? -1 : 1); while (1) { col += sign; if (isAvailable(row, col)) return col; @@ -147,7 +142,6 @@ int col = 0; int row = item->row(); QString branch = cs->branch(); - int branchHome = m_branchHomes[branch]; int nparents = cs->parents().size(); QString parentId; @@ -156,7 +150,8 @@ switch (nparents) { case 0: - col = findAvailableColumn(row, branchHome, 0, true); + col = m_branchHomes[cs->branch()]; + col = findAvailableColumn(row, col, true); break; case 1: @@ -170,7 +165,7 @@ col = m_items[parentId]->column(); } - col = findAvailableColumn(row, col, branchHome - col, true); + col = findAvailableColumn(row, col, true); break; case 2: @@ -190,9 +185,9 @@ if (parentsOnSameBranch > 0) { col /= parentsOnSameBranch; - col = findAvailableColumn(item->row(), col, 0, true); + col = findAvailableColumn(item->row(), col, true); } else { - col = findAvailableColumn(item->row(), col, 0, false); + col = findAvailableColumn(item->row(), col, false); } break; } @@ -209,7 +204,7 @@ if (m_uncommittedParents.contains(id)) { if (m_uncommittedParents[0] == id) { - int ucol = findAvailableColumn(row-1, col, branchHome - col, true); + int ucol = findAvailableColumn(row-1, col, true); m_uncommitted->setColumn(ucol); m_haveAllocatedUncommittedColumn = true; } @@ -263,7 +258,7 @@ for (int i = 0; i < 2; ++i) { int off = i * 2 - 1; // 0 -> -1, 1 -> 1 ChangesetItem *it = m_items[special[i]]; - it->setColumn(findAvailableColumn(it->row(), col + off, 0, true)); + it->setColumn(findAvailableColumn(it->row(), col + off, true)); for (int r = row-1; r >= it->row(); --r) { m_alloc[r].insert(it->column()); } @@ -287,34 +282,10 @@ void Grapher::allocateBranchHomes(Changesets csets) { - QMap branchCounts; - QMap branchParents; - - QStringList branches; - foreach (Changeset *cs, csets) { - QString branch = cs->branch(); - - if (!branchCounts.contains(branch)) { - // Guess at the parent branch for this one which we - // haven't seen before. This is not entirely reliable, but - // it doesn't need to be - if (!cs->parents().empty()) { - QString firstParentId = cs->parents()[0]; - if (m_changesets.contains(firstParentId)) { - Changeset *firstParent = m_changesets[firstParentId]; - branchParents[branch] = firstParent->branch(); - } - } - branches.push_back(branch); - } - - branchCounts[branch]++; - ChangesetItem *item = m_items[cs->id()]; if (!item) continue; - int row = item->row(); if (!m_branchRanges.contains(branch)) { m_branchRanges[branch] = Range(row, row); @@ -328,20 +299,8 @@ m_branchHomes[""] = 0; m_branchHomes["default"] = 0; -/* - QStringList orderedBranches; // will be ordered by "popularity" - QMultiMap branchesByCount; - foreach (QString branch, branchCounts.keys()) { - branchesByCount.insert(branchCounts[branch], branch); - } - foreach (QString branch, branchesByCount) { - orderedBranches.push_front(branch); - } -*/ - int sign = -1; - - foreach (QString branch, branches) { + foreach (QString branch, m_branchRanges.keys()) { if (branch == "") continue; QSet taken; taken.insert(0); @@ -356,23 +315,26 @@ } } int home = 2; - QString parent = branchParents[branch]; - if (parent != "" && parent != "default" && - m_branchHomes.contains(parent)) { - home = m_branchHomes[parent]; - if (home > 0) sign = 1; - else sign = -1; - } else { - sign = -sign; - } while (taken.contains(home)) { - home = home + 2 * sign; + if (home > 0) { + if (home % 2 == 1) { + home = -home; + } else { + home = home + 1; + } + } else { + if ((-home) % 2 == 1) { + home = home + 1; + } else { + home = -(home-2); + } + } } m_branchHomes[branch] = home; } - foreach (QString branch, branches) { - DEBUG << branch << ": pop " << branchCounts[branch] << ", parent " << branchParents[branch] << ", range " << m_branchRanges[branch].first << " - " << m_branchRanges[branch].second << ", home " << m_branchHomes[branch] << endl; + foreach (QString branch, m_branchRanges.keys()) { + DEBUG << branch.toStdString() << ": " << m_branchRanges[branch].first << " - " << m_branchRanges[branch].second << ", home " << m_branchHomes[branch] << endl; } } diff -r 45f69889d28d -r b8ded5213d16 grapher.h --- a/grapher.h Wed Jan 12 16:38:13 2011 +0000 +++ b/grapher.h Mon Jan 17 11:44:17 2011 +0000 @@ -88,7 +88,7 @@ void layoutCol(QString id); void allocateBranchHomes(Changesets csets); bool rangesConflict(const Range &r1, const Range &r2); - int findAvailableColumn(int row, int parent, int sign, bool preferParentCol); + int findAvailableColumn(int row, int parent, bool preferParentCol); bool isAvailable(int row, int col); };