From 96b7bfb4eb6701bda4b312095abb78b97f564f58 Mon Sep 17 00:00:00 2001 From: ramin-deriv Date: Tue, 27 Feb 2024 16:24:29 +0800 Subject: [PATCH 1/2] add fractionalDigits field to ActiveContract model --- .../accumulators_barriers/accumulators_active_contract.dart | 5 +++++ .../accumulators_closed_indicator_painter.dart | 4 +++- .../accumulators_indicator_painter.dart | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_active_contract.dart b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_active_contract.dart index cf77c3d98..4f3cea610 100644 --- a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_active_contract.dart +++ b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_active_contract.dart @@ -4,6 +4,7 @@ class AccumulatorsActiveContract { const AccumulatorsActiveContract({ required this.profit, required this.currency, + required this.fractionalDigits, }); /// Profit value of the current contract. @@ -11,4 +12,8 @@ class AccumulatorsActiveContract { /// The currency of the current contract. final String? currency; + + /// The number of decimal places to show the correct formatting of the profit + /// value. + final int fractionalDigits; } diff --git a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_closed_indicator_painter.dart b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_closed_indicator_painter.dart index 6e8021b21..c0bbc88a1 100644 --- a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_closed_indicator_painter.dart +++ b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_closed_indicator_painter.dart @@ -192,7 +192,9 @@ class AccumulatorsClosedIndicatorPainter if (indicator.activeContract?.profit != null) { final double profit = indicator.activeContract!.profit!; final String profitText = - '${profit < 0 ? '' : '+'}${profit.toStringAsFixed(2)}'; + '${profit < 0 ? '' : '+'}${profit.toStringAsFixed( + indicator.activeContract!.fractionalDigits, + )}'; final String currencyText = '${indicator.activeContract?.currency ?? ''}'; final TextPainter profitPainter = makeTextPainter( diff --git a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_indicator_painter.dart b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_indicator_painter.dart index a7b8bbf56..9cf7d2e9d 100644 --- a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_indicator_painter.dart +++ b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_indicator_painter.dart @@ -223,7 +223,9 @@ class AccumulatorIndicatorPainter extends SeriesPainter { // profit if (animatedProfit != null && animatedProfit != 0) { final TextPainter profitPainter = makeTextPainter( - '${animatedProfit < 0 ? '' : '+'}${animatedProfit.toStringAsFixed(2)}', + '${animatedProfit < 0 ? '' : '+'}${animatedProfit.toStringAsFixed( + indicator.activeContract!.fractionalDigits, + )}', style.textStyle.copyWith(color: color, fontSize: 26), ); From d8b5b6f64f759d5909e5958c5dbc10544a156673 Mon Sep 17 00:00:00 2001 From: ramin-deriv Date: Tue, 27 Feb 2024 18:15:29 +0800 Subject: [PATCH 2/2] minor refactor --- .../accumulators_active_contract.dart | 7 ++++--- .../accumulators_closed_indicator_painter.dart | 2 +- .../accumulators_indicator_painter.dart | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_active_contract.dart b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_active_contract.dart index 4f3cea610..37c679253 100644 --- a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_active_contract.dart +++ b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_active_contract.dart @@ -3,15 +3,16 @@ class AccumulatorsActiveContract { /// Initializes [AccumulatorsActiveContract]. const AccumulatorsActiveContract({ required this.profit, - required this.currency, + required this.profitUnit, required this.fractionalDigits, }); /// Profit value of the current contract. final double? profit; - /// The currency of the current contract. - final String? currency; + /// The profit unit label either currency or %, etc that will be shown next to + /// profit value. + final String? profitUnit; /// The number of decimal places to show the correct formatting of the profit /// value. diff --git a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_closed_indicator_painter.dart b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_closed_indicator_painter.dart index c0bbc88a1..671ab7d0d 100644 --- a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_closed_indicator_painter.dart +++ b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_closed_indicator_painter.dart @@ -196,7 +196,7 @@ class AccumulatorsClosedIndicatorPainter indicator.activeContract!.fractionalDigits, )}'; final String currencyText = - '${indicator.activeContract?.currency ?? ''}'; + '${indicator.activeContract?.profitUnit ?? ''}'; final TextPainter profitPainter = makeTextPainter( '$profitText $currencyText', style.textStyle.copyWith( diff --git a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_indicator_painter.dart b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_indicator_painter.dart index 9cf7d2e9d..35de3f209 100644 --- a/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_indicator_painter.dart +++ b/lib/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_indicator_painter.dart @@ -230,7 +230,7 @@ class AccumulatorIndicatorPainter extends SeriesPainter { ); final TextPainter currencyPainter = makeTextPainter( - indicator.activeContract?.currency ?? '', + indicator.activeContract?.profitUnit ?? '', style.textStyle.copyWith(color: color, fontSize: 14), );