Skip to content

Commit

Permalink
[#148] [NF] Chart for Accounts. Limit scope
Browse files Browse the repository at this point in the history
  • Loading branch information
lyskouski committed Aug 21, 2023
1 parent b884f1c commit 41e5bf6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/_classes/storage/data_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ class DataHandler {
return result;
}

static List<OhlcData> generateOhlcSummary(List<List<TransactionLogData>?> scope, {required Exchange exchange}) {
static List<OhlcData> generateOhlcSummary(List<List<TransactionLogData>?> scope,
{required Exchange exchange, DateTime? cut}) {
final data = scope.firstOrNull;
for (int i = 1; i < scope.length; i++) {
data!.addAll(scope[i]!);
data!.addAll(scope[i]!.where((e) => cut == null || e.timestamp.isAfter(cut)));
}
if (data != null && data.isNotEmpty) {
data.sort((a, b) => a.timestamp.compareTo(b.timestamp));
Expand Down
9 changes: 5 additions & 4 deletions lib/charts/ohlc_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class OhlcChart extends StatefulWidget {
final double width;
final double height;
final double indent;
final DateTime xMin;
final String tooltip;
final List<OhlcData> data;

Expand All @@ -20,6 +21,7 @@ class OhlcChart extends StatefulWidget {
required this.data,
required this.width,
required this.height,
required this.xMin,
this.indent = 0.0,
this.tooltip = '',
});
Expand All @@ -34,15 +36,14 @@ class OhlcChartState extends State<OhlcChart> {
final now = DateTime.now();
final size = Size(widget.width, widget.height);
final bgColor = Theme.of(context).colorScheme.onBackground;
final xMin = DateTime(now.year, now.month - 5);
final xMax = DateTime(now.year, now.month + 1);
double yMin = 0.0;
double yMax = 0.0;
for (int i = 0; i < widget.data.length; i++) {
if (widget.data[i].low < yMin) yMin = widget.data[i].low;
if (widget.data[i].high > yMax) yMax = widget.data[i].high;
}
yMax *= 1.2;
yMax *= 1.25;
final bg = ForegroundChartPainter(
size: size,
color: bgColor,
Expand All @@ -51,7 +52,7 @@ class OhlcChartState extends State<OhlcChart> {
yMin: yMin,
yMax: yMax,
xType: DateTime,
xMin: xMin,
xMin: widget.xMin,
xMax: xMax,
xDivider: 6,
xTpl: DateFormat.Md(AppLocale.code),
Expand All @@ -67,7 +68,7 @@ class OhlcChartState extends State<OhlcChart> {
size: size,
data: widget.data,
yMax: yMax,
xMin: xMin.microsecondsSinceEpoch.toDouble(),
xMin: widget.xMin.microsecondsSinceEpoch.toDouble(),
xMax: xMax.microsecondsSinceEpoch.toDouble(),
),
foregroundPainter: bg,
Expand Down
4 changes: 4 additions & 0 deletions lib/widgets/metrics/account_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class AccountTab extends StatelessWidget {
final TextTheme textTheme = Theme.of(context).textTheme;
double indent = ThemeHelper.getIndent();
final exchange = Exchange(store: store);
final now = DateTime.now();
final xMin = DateTime(now.year, now.month - 5);
return SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(indent * 2),
Expand All @@ -37,9 +39,11 @@ class AccountTab extends StatelessWidget {
width: ThemeHelper.getWidth(context, 4),
height: 200,
indent: indent,
xMin: xMin,
data: DataHandler.generateOhlcSummary(
store.getMultiLog(store.getList(AppDataType.accounts).cast<AccountAppData>()),
exchange: exchange,
cut: xMin,
),
),
],
Expand Down

0 comments on commit 41e5bf6

Please sign in to comment.