Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make analysis tree view more "tree like" #1053

Merged
merged 25 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e107aba
feat: make analysis tree view more "tree like"
tom-anders Sep 28, 2024
7b2ea21
adapt tree view styling
tom-anders Sep 30, 2024
3c0ed7f
support hide/show variations again
tom-anders Sep 30, 2024
b129c58
fix unnecessary sideline nesting
tom-anders Oct 2, 2024
6409115
add indentation limit
tom-anders Oct 3, 2024
a72f126
hide sidelines with nesting > 2 when parsing PGN
tom-anders Oct 3, 2024
17c5524
add icon to expand variations
tom-anders Oct 3, 2024
d3f4ce4
increase icon size for expanding variations
tom-anders Oct 4, 2024
3e3dbb5
fix comment
tom-anders Oct 5, 2024
2afbc6b
make LineType and LineInfo private and document them
tom-anders Oct 5, 2024
c17d012
make more stuff private
tom-anders Oct 5, 2024
cca00b9
remove side effects from build()
tom-anders Oct 5, 2024
2e3e49f
add comment about RepaintBoundary
tom-anders Oct 5, 2024
872b2d5
remove redundant Function indirection
tom-anders Oct 5, 2024
6995bda
only rebuild toplevel parts of the tree that actually changed
tom-anders Oct 5, 2024
780830d
skip last mainline part if it has no children
tom-anders Oct 5, 2024
b7aa1c9
add more tests for pgn tree view
tom-anders Oct 5, 2024
9c9d16f
remove RepaintBoundary
tom-anders Oct 6, 2024
8e5f8ab
refactor and improve documentation
tom-anders Oct 6, 2024
f672de7
remove parent parameter that's not needed anymore
tom-anders Oct 6, 2024
0c7d772
add more docs
tom-anders Oct 6, 2024
0ecc30d
factor out rebuilding subtrees into a private function
tom-anders Oct 6, 2024
05122ff
make comment more precise
tom-anders Oct 7, 2024
35203d0
add missing `2.` in test
tom-anders Oct 7, 2024
74b5636
make comments about caching more precise
tom-anders Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/src/model/analysis/analysis_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,24 @@ class AnalysisController extends _$AnalysisController {
_setPath(path);
}

void showAllVariations(UciPath path) {
final parent = _root.parentAt(path);
for (final node in parent.children) {
node.isHidden = false;
void expandVariations(UciPath path) {
final node = _root.nodeAt(path);
for (final child in node.children) {
child.isHidden = false;
for (final grandChild in child.children) {
grandChild.isHidden = false;
}
}
state = state.copyWith(root: _root.view);
}

void hideVariation(UciPath path) {
_root.hideVariationAt(path);
void collapseVariations(UciPath path) {
final node = _root.parentAt(path);

for (final child in node.children) {
child.isHidden = true;
}

state = state.copyWith(root: _root.view);
}

Expand Down
34 changes: 14 additions & 20 deletions lib/src/model/common/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,6 @@ abstract class Node {
parentAt(path).children.removeWhere((child) => child.id == path.last);
}

/// Hides the variation from the node at the given path.
void hideVariationAt(UciPath path) {
final nodes = nodesOn(path).toList();
for (int i = nodes.length - 2; i >= 0; i--) {
final node = nodes[i + 1];
final parent = nodes[i];
if (node is Branch && parent.children.length > 1) {
for (final child in parent.children) {
if (child.id == node.id) {
child.isHidden = true;
}
}
}
}
}

/// Promotes the node at the given path.
void promoteAt(UciPath path, {required bool toMainline}) {
final nodes = nodesOn(path).toList();
Expand Down Expand Up @@ -484,8 +468,8 @@ class Root extends Node {
position: PgnGame.startingPosition(game.headers),
);

final List<({PgnNode<PgnNodeData> from, Node to})> stack = [
(from: game.moves, to: root),
final List<({PgnNode<PgnNodeData> from, Node to, int nesting})> stack = [
(from: game.moves, to: root, nesting: 1),
];

while (stack.isNotEmpty) {
Expand All @@ -503,7 +487,7 @@ class Root extends Node {
final branch = Branch(
sanMove: SanMove(childFrom.data.san, move),
position: newPos,
isHidden: hideVariations && childIdx > 0,
isHidden: frame.nesting > 2 || hideVariations && childIdx > 0,
lichessAnalysisComments:
isLichessAnalysis ? comments?.toList() : null,
startingComments: isLichessAnalysis
Expand All @@ -516,7 +500,17 @@ class Root extends Node {
);

frame.to.addChild(branch);
stack.add((from: childFrom, to: branch));
stack.add(
(
from: childFrom,
to: branch,
nesting: frame.from.children.length == 1 ||
// mainline continuation
(childIdx == 0 && frame.nesting == 1)
? frame.nesting
: frame.nesting + 1,
),
);

onVisitNode?.call(root, branch, isMainline);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/model/common/uci.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class UciPath with _$UciPath {
return UciPath(path.toString());
}

factory UciPath.join(UciPath a, UciPath b) => UciPath(a.value + b.value);

/// Creates a UciPath from a list of UCI moves.
///
/// Throws an [ArgumentError] if any of the moves is invalid.
Expand Down
Loading