Added jitterStip to prevent the graphs overlaying each other
This commit is contained in:
@@ -6,6 +6,13 @@ class CustomTheme {
|
|||||||
static Color backgroundColor = const Color(0xFF101010);
|
static Color backgroundColor = const Color(0xFF101010);
|
||||||
static Color backgroundTintColor = CupertinoColors.darkBackgroundGray;
|
static Color backgroundTintColor = CupertinoColors.darkBackgroundGray;
|
||||||
|
|
||||||
|
// graph colors
|
||||||
|
static const Color graphColor1 = Color(0xFFF44336);
|
||||||
|
static const Color graphColor2 = Color(0xFF2196F3); //FF2196F3
|
||||||
|
static const Color graphColor3 = Color(0xFFFFA726); //FFFFA726
|
||||||
|
static const Color graphColor4 = Color(0xFF9C27B0); //9C27B0
|
||||||
|
static final Color graphColor5 = primaryColor;
|
||||||
|
|
||||||
static TextStyle modeTitle = TextStyle(
|
static TextStyle modeTitle = TextStyle(
|
||||||
color: primaryColor,
|
color: primaryColor,
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
import 'package:cabo_counter/core/custom_theme.dart';
|
||||||
import 'package:cabo_counter/data/game_session.dart';
|
import 'package:cabo_counter/data/game_session.dart';
|
||||||
import 'package:cabo_counter/l10n/generated/app_localizations.dart';
|
import 'package:cabo_counter/l10n/generated/app_localizations.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||||
|
|
||||||
class GraphView extends StatefulWidget {
|
class GraphView extends StatefulWidget {
|
||||||
@@ -15,12 +15,12 @@ class GraphView extends StatefulWidget {
|
|||||||
|
|
||||||
class _GraphViewState extends State<GraphView> {
|
class _GraphViewState extends State<GraphView> {
|
||||||
/// List of colors for the graph lines.
|
/// List of colors for the graph lines.
|
||||||
List<Color> lineColors = [
|
final List<Color> lineColors = [
|
||||||
Colors.red,
|
CustomTheme.graphColor1,
|
||||||
Colors.blue,
|
CustomTheme.graphColor2,
|
||||||
Colors.orange.shade400,
|
CustomTheme.graphColor3,
|
||||||
Colors.purple,
|
CustomTheme.graphColor4,
|
||||||
Colors.green,
|
CustomTheme.graphColor5
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -36,7 +36,10 @@ class _GraphViewState extends State<GraphView> {
|
|||||||
child: SfCartesianChart(
|
child: SfCartesianChart(
|
||||||
legend: const Legend(
|
legend: const Legend(
|
||||||
isVisible: true, position: LegendPosition.bottom),
|
isVisible: true, position: LegendPosition.bottom),
|
||||||
primaryXAxis: const NumericAxis(),
|
primaryXAxis: const NumericAxis(
|
||||||
|
interval: 1,
|
||||||
|
decimalPlaces: 0,
|
||||||
|
),
|
||||||
primaryYAxis: const NumericAxis(),
|
primaryYAxis: const NumericAxis(),
|
||||||
series: getCumulativeScores(),
|
series: getCumulativeScores(),
|
||||||
),
|
),
|
||||||
@@ -64,7 +67,7 @@ class _GraphViewState extends State<GraphView> {
|
|||||||
/// Returns a list of LineSeries representing the cumulative scores of each player.
|
/// Returns a list of LineSeries representing the cumulative scores of each player.
|
||||||
/// Each series contains data points for each round, showing the cumulative score up to that round.
|
/// Each series contains data points for each round, showing the cumulative score up to that round.
|
||||||
/// The x-axis represents the round number, and the y-axis represents the cumulative score.
|
/// The x-axis represents the round number, and the y-axis represents the cumulative score.
|
||||||
List<LineSeries<(int, int), int>> getCumulativeScores() {
|
List<LineSeries<(int, num), int>> getCumulativeScores() {
|
||||||
final rounds = widget.gameSession.roundList;
|
final rounds = widget.gameSession.roundList;
|
||||||
final playerCount = widget.gameSession.players.length;
|
final playerCount = widget.gameSession.players.length;
|
||||||
final playerNames = widget.gameSession.players;
|
final playerNames = widget.gameSession.players;
|
||||||
@@ -79,21 +82,26 @@ class _GraphViewState extends State<GraphView> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const double jitterStep = 0.15;
|
||||||
|
|
||||||
/// Create a list of LineSeries for each player
|
/// Create a list of LineSeries for each player
|
||||||
/// Each series contains data points for each round
|
/// Each series contains data points for each round
|
||||||
return List.generate(playerCount, (i) {
|
return List.generate(playerCount, (i) {
|
||||||
final data = List.generate(
|
final data = List.generate(
|
||||||
cumulativeScores[i].length,
|
cumulativeScores[i].length,
|
||||||
(j) => (j + 1, cumulativeScores[i][j]), // (round, score)
|
(j) => (
|
||||||
|
j + 1,
|
||||||
|
cumulativeScores[i][j] + (i - playerCount ~/ 2) * jitterStep
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Create a LineSeries for the player
|
/// Create a LineSeries for the player
|
||||||
/// The xValueMapper maps the round number, and the yValueMapper maps the cumulative score.
|
/// The xValueMapper maps the round number, and the yValueMapper maps the cumulative score.
|
||||||
return LineSeries<(int, int), int>(
|
return LineSeries<(int, num), int>(
|
||||||
name: playerNames[i],
|
name: playerNames[i],
|
||||||
dataSource: data,
|
dataSource: data,
|
||||||
xValueMapper: (record, _) => record.$1, // Runde
|
xValueMapper: (record, _) => record.$1,
|
||||||
yValueMapper: (record, _) => record.$2, // Punktestand
|
yValueMapper: (record, _) => record.$2,
|
||||||
markerSettings: const MarkerSettings(isVisible: true),
|
markerSettings: const MarkerSettings(isVisible: true),
|
||||||
color: lineColors[i],
|
color: lineColors[i],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user