Skip to content

Commit

Permalink
Osama/DERG-1441/add accumulator profit value to accumulator barriers (#…
Browse files Browse the repository at this point in the history
…288)

- Add profit to accumulators barrier component
  • Loading branch information
osama-deriv authored Jan 3, 2024
1 parent 60f70dc commit 25d1398
Show file tree
Hide file tree
Showing 23 changed files with 631 additions and 278 deletions.
3 changes: 2 additions & 1 deletion lib/deriv_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ library deriv_chart;

export 'generated/l10n.dart';
export 'src/deriv_chart/chart/chart.dart';
export 'src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_barriers.dart';
export 'src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_indicator.dart';
export 'src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_entry_spot_barrier.dart';
export 'src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_active_contract.dart';
export 'src/deriv_chart/chart/data_visualization/annotations/barriers/barrier.dart';
export 'src/deriv_chart/chart/data_visualization/annotations/barriers/horizontal_barrier/combined_barrier.dart';
export 'src/deriv_chart/chart/data_visualization/annotations/barriers/horizontal_barrier/horizontal_barrier.dart';
Expand Down
5 changes: 3 additions & 2 deletions lib/src/deriv_chart/chart/chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Chart extends StatefulWidget {
this.dataFitEnabled = false,
this.opacity = 1.0,
this.annotations,
this.chartAxisConfig,
this.chartAxisConfig = const ChartAxisConfig(),
Key? key,
}) : super(key: key);

Expand Down Expand Up @@ -81,7 +81,7 @@ class Chart extends StatefulWidget {
final double opacity;

/// Configurations for chart's axes.
final ChartAxisConfig? chartAxisConfig;
final ChartAxisConfig chartAxisConfig;

@override
State<StatefulWidget> createState() => _ChartState();
Expand Down Expand Up @@ -147,6 +147,7 @@ class _ChartState extends State<Chart> with WidgetsBindingObserver {
onVisibleAreaChanged: _onVisibleAreaChanged,
isLive: widget.isLive,
startWithDataFitMode: widget.dataFitEnabled,
maxCurrentTickOffset: widget.chartAxisConfig.maxCurrentTickOffset,
child: Column(
children: <Widget>[
Expanded(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// Used to hold the active active accumulators contract information.
class AccumulatorsActiveContract {
/// Initializes [AccumulatorsActiveContract].
const AccumulatorsActiveContract({
required this.profit,
required this.currency,
});

/// Profit value of the current contract.
final double? profit;

/// The currency of the current contract.
final String? currency;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AccumulatorsEntrySpotBarrier extends Barrier {
id: id,
title: title,
epoch: endingEpoch,
value: value,
quote: value,
style: style,
longLine: longLine,
);
Expand Down Expand Up @@ -87,5 +87,5 @@ class AccumulatorsEntrySpotBarrier extends Barrier {

@override
BarrierObject createObject() =>
BarrierObject(leftEpoch: startingEpoch, rightEpoch: epoch, value: value);
BarrierObject(leftEpoch: startingEpoch, rightEpoch: epoch, quote: quote);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AccumulatorsEntrySpotBarrierPainter<
// If previous object is null then its first load and no need to perform
// transition animation from previousObject to new object.
if (series.previousObject == null) {
animatedValue = series.value;
animatedValue = series.quote;
if (series.epoch != null) {
dotX = epochToX(series.epoch!);
}
Expand All @@ -50,8 +50,8 @@ class AccumulatorsEntrySpotBarrierPainter<
// transition animation
// from previousObject to new object
animatedValue = ui.lerpDouble(
previousBarrier.value,
series.value,
previousBarrier.quote,
series.quote,
animationInfo.currentTickPercent,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import 'package:deriv_chart/deriv_chart.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/annotations/barriers/accumulators_barriers/accumulators_active_contract.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/chart_series/series_painter.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/models/accumulator_object.dart';

import 'accumulators_barriers_painter.dart';
import 'accumulators_indicator_painter.dart';

/// Accumulator Barriers.
class AccumulatorBarriers extends ChartAnnotation<AccumulatorObject> {
class AccumulatorIndicator extends ChartAnnotation<AccumulatorObject> {
/// Initializes a tick indicator.
AccumulatorBarriers(
AccumulatorIndicator(
this.tick, {
required this.lowBarrier,
required this.highBarrier,
required this.highBarrierDisplay,
required this.lowBarrierDisplay,
required this.profit,
required this.barrierSpotDistance,
required this.barrierEpoch,
required this.isActiveContract,
this.activeContract,
String? id,
HorizontalBarrierStyle? style =
const HorizontalBarrierStyle(labelShape: LabelShape.pentagon),
this.labelVisibility = HorizontalBarrierVisibility.normal,
}) : super(
id ?? 'AccumulatorTickIndicator',
style: style,
);

/// The price difference between the barrier and the [tick] quote.
Expand All @@ -40,24 +44,25 @@ class AccumulatorBarriers extends ChartAnnotation<AccumulatorObject> {
/// The high barrier display value.
final String lowBarrierDisplay;

/// [Optional] The profit value which is being shown in the middle of the tick indicator.
final String? profit;
/// [Optional] Active contract information.
final AccumulatorsActiveContract? activeContract;

/// The [epoch] of the tick that the barriers belong to.
final int barrierEpoch;

/// Weathers there is an active contract or not.
final bool isActiveContract;
/// Tick quote label visibility behavior.
final HorizontalBarrierVisibility labelVisibility;

@override
SeriesPainter<Series> createPainter() => AccumulatorBarriersPainter(this);
SeriesPainter<Series> createPainter() => AccumulatorIndicatorPainter(this);

@override
AccumulatorObject createObject() => AccumulatorObject(
tick: tick,
barrierEpoch: barrierEpoch,
lowBarrier: lowBarrier,
highBarrier: highBarrier,
profit: activeContract?.profit,
);

@override
Expand Down
Loading

0 comments on commit 25d1398

Please sign in to comment.