-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1641 from kate-deriv/kate/DTRA-2225/chart_colors_…
…updates DTRA-2225 / Kate / Update colors
- Loading branch information
Showing
7 changed files
with
140 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:deriv_chart/deriv_chart.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
/// A [DataPainter] for painting CandleStick data. | ||
class CandlePainter extends OhlcPainter { | ||
/// Initializes | ||
CandlePainter(DataSeries<Candle> series) : super(series); | ||
|
||
late Paint _linePaint; | ||
late Paint _positiveCandlePaint; | ||
late Paint _negativeCandlePaint; | ||
|
||
@override | ||
void onPaintCandle( | ||
Canvas canvas, | ||
OhlcPainting currentPainting, | ||
OhlcPainting prevPainting, | ||
) { | ||
final CandleStyle style = series.style as CandleStyle? ?? theme.candleStyle; | ||
|
||
_linePaint = Paint() | ||
..color = currentPainting.yOpen > currentPainting.yClose | ||
? style.positiveColor | ||
: style.negativeColor | ||
..strokeWidth = 1.2; | ||
|
||
_positiveCandlePaint = Paint()..color = style.positiveColor; | ||
_negativeCandlePaint = Paint()..color = style.negativeColor; | ||
|
||
canvas.drawLine( | ||
Offset(currentPainting.xCenter, currentPainting.yHigh), | ||
Offset(currentPainting.xCenter, currentPainting.yLow), | ||
_linePaint, | ||
); | ||
|
||
if (currentPainting.yOpen == currentPainting.yClose) { | ||
canvas.drawLine( | ||
Offset(currentPainting.xCenter - currentPainting.width / 2, | ||
currentPainting.yOpen), | ||
Offset(currentPainting.xCenter + currentPainting.width / 2, | ||
currentPainting.yOpen), | ||
_linePaint, | ||
); | ||
} else if (currentPainting.yOpen > currentPainting.yClose) { | ||
canvas.drawRect( | ||
Rect.fromLTRB( | ||
currentPainting.xCenter - currentPainting.width / 2, | ||
currentPainting.yClose, | ||
currentPainting.xCenter + currentPainting.width / 2, | ||
currentPainting.yOpen, | ||
), | ||
_positiveCandlePaint, | ||
); | ||
} else { | ||
canvas.drawRect( | ||
Rect.fromLTRB( | ||
currentPainting.xCenter - currentPainting.width / 2, | ||
currentPainting.yOpen, | ||
currentPainting.xCenter + currentPainting.width / 2, | ||
currentPainting.yClose, | ||
), | ||
_negativeCandlePaint, | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import 'package:deriv_chart/deriv_chart.dart' hide OHLCTypeSeries; | ||
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/chart_series/ohlc_series/ohlc_type_series.dart'; | ||
import './candle_painter.dart'; | ||
|
||
/// CandleStick series | ||
class CandleSeries extends OHLCTypeSeries { | ||
/// Initializes | ||
CandleSeries( | ||
List<Candle> entries, { | ||
String? id, | ||
String? painterType, | ||
CandleStyle? style, | ||
HorizontalBarrierStyle? lastTickIndicatorStyle, | ||
}) : super( | ||
entries, | ||
id ?? 'CandleSeries', | ||
style: style, | ||
lastTickIndicatorStyle: lastTickIndicatorStyle, | ||
); | ||
|
||
@override | ||
SeriesPainter<DataSeries<Candle>> createPainter() => CandlePainter(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters