Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions lib/src/model/analysis/analysis_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,31 @@ class AnalysisController extends _$AnalysisController {
);
}

void jumpToNthNode(int n) {
UciPath path = _root.mainlinePath;
while (!path.penultimate.isEmpty) {
path = path.penultimate;
}
Node? node = _root.nodeAt(path);
int count = 0;

while (node != null && count < n) {
if (node.children.isNotEmpty) {
path = path + node.children.first.id;
node = _root.nodeAt(path);
count++;
} else {
break;
}
}

if (node != null) {
_setPath(
path,
);
}
}

void toggleBoard() {
state = state.copyWith(pov: state.pov.opposite);
}
Expand Down
28 changes: 26 additions & 2 deletions lib/src/view/analysis/analysis_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1043,13 +1043,37 @@ class AcplChart extends ConsumerWidget {
padding: const EdgeInsets.all(16.0),
child: LineChart(
LineChartData(
lineTouchData: const LineTouchData(enabled: false),
lineTouchData: LineTouchData(
enabled: false,
touchCallback:
(FlTouchEvent event, LineTouchResponse? touchResponse) {
if (event is FlTapUpEvent) {
final touchX = event.localPosition.dx;
final chartWidth = context.size!.width -
32; // Insets on both sides of the chart of 16
final minX = spots.first.x;
final maxX = spots.last.x;
final touchXDataValue =
minX + (touchX / chartWidth) * (maxX - minX);
final closestSpot = spots.reduce(
(a, b) => (a.x - touchXDataValue).abs() <
(b.x - touchXDataValue).abs()
? a
: b,
);
final closestNodeIndex = closestSpot.x.round();
ref
.read(analysisControllerProvider(options).notifier)
.jumpToNthNode(closestNodeIndex);
}
},
),
minY: -1.0,
maxY: 1.0,
lineBarsData: [
LineChartBarData(
spots: spots,
isCurved: true,
isCurved: false,
barWidth: 1,
color: mainLineColor,
aboveBarData: BarAreaData(
Expand Down