Skip to content

Commit d305329

Browse files
authored
feat: add display offset and remove flag icon in PnL marker (#466)
1 parent 25f188d commit d305329

3 files changed

Lines changed: 21 additions & 99 deletions

File tree

lib/src/deriv_chart/chart/data_visualization/markers/chart_marker.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class ChartMarker extends Marker {
187187
/// The [text] is the text to display on or near the marker.
188188
/// The [color] is the color of the marker.
189189
/// The [hasReducedOpacity] determines whether the marker should be rendered with reduced opacity by 50%.
190+
/// The [displayOffset] is an optional pixel offset applied to the marker's rendered position.
190191
ChartMarker({
191192
required int epoch,
192193
required double quote,
@@ -196,6 +197,7 @@ class ChartMarker extends Marker {
196197
this.text,
197198
this.color,
198199
this.hasReducedOpacity = false,
200+
this.displayOffset = Offset.zero,
199201
}) : super(epoch: epoch, quote: quote, direction: direction, onTap: onTap);
200202

201203
/// The type of marker, which determines its role and how it's rendered on the chart.
@@ -232,4 +234,16 @@ class ChartMarker extends Marker {
232234
///
233235
/// Defaults to false (full opacity).
234236
final bool hasReducedOpacity;
237+
238+
/// An optional pixel offset applied to the marker's rendered position on the canvas.
239+
///
240+
/// Defaults to [Offset.zero] (no offset). The offset is applied **after** the
241+
/// epoch/quote → canvas coordinate conversion, so it is expressed in logical
242+
/// pixels and is independent of zoom level.
243+
///
244+
/// Use this to nudge a marker visually without changing its underlying
245+
/// epoch/quote data. For example, set `displayOffset: Offset(0, -8)` on a
246+
/// `profitAndLossLabel` marker to position the pill 8 pixels above the exit
247+
/// spot dot when they share the same quote value and would otherwise overlap.
248+
final Offset displayOffset;
235249
}

lib/src/deriv_chart/chart/data_visualization/markers/marker_icon_painters/tick_marker_icon_painter.dart

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import 'package:deriv_chart/src/deriv_chart/chart/helpers/paint_functions/paint_
1414
import 'package:deriv_chart/src/deriv_chart/chart/helpers/paint_functions/paint_text.dart';
1515
import 'package:deriv_chart/src/deriv_chart/chart/y_axis/y_axis_config.dart';
1616
import 'package:deriv_chart/src/theme/chart_theme.dart';
17-
import 'package:deriv_chart/src/theme/quill_icons.dart';
1817
import 'package:deriv_chart/src/theme/painting_styles/marker_style.dart';
1918
import 'package:flutter/material.dart';
2019
import 'dart:ui' as ui;
@@ -36,8 +35,7 @@ import 'dart:math' as math;
3635
/// - Start markers are shown as location pins with optional labels
3736
/// - Entry points are shown as circles with a distinctive border
3837
/// - Tick points are shown as small dots
39-
/// - Exit points are shown as circles
40-
/// - End points are shown as flag icons
38+
/// - Exit and end points are shown as circles
4139
///
4240
/// This class is part of the chart's visualization pipeline and works in conjunction
4341
/// with `MarkerGroupPainter` to render marker groups on the chart canvas.
@@ -133,12 +131,14 @@ class TickMarkerIconPainter extends MarkerGroupIconPainter {
133131
final double markerOpacity =
134132
marker.hasReducedOpacity ? opacity * 0.5 : opacity;
135133

134+
final Offset markerCenter = center + marker.displayOffset;
135+
136136
_drawMarker(
137137
canvas,
138138
size,
139139
theme,
140140
marker,
141-
center,
141+
markerCenter,
142142
markerGroup.style,
143143
1.2,
144144
painterProps.granularity,
@@ -449,9 +449,7 @@ class TickMarkerIconPainter extends MarkerGroupIconPainter {
449449

450450
final double pillHeight = 32 * zoom;
451451
final double radius = pillHeight / 2;
452-
final double iconSize = 24 * zoom;
453-
const double leftPadding = 8;
454-
const double spacing = 4;
452+
const double leftPadding = 16;
455453
const double rightPadding = 16;
456454

457455
final TextStyle textStyle = theme
@@ -467,8 +465,7 @@ class TickMarkerIconPainter extends MarkerGroupIconPainter {
467465
final String text = markerGroup.profitAndLossText ?? '';
468466
final TextPainter textPainter = makeTextPainter(text, textStyle);
469467

470-
final double contentWidth =
471-
leftPadding + iconSize + spacing + textPainter.width + rightPadding;
468+
final double contentWidth = leftPadding + textPainter.width + rightPadding;
472469

473470
Rect pillRect;
474471
if (fixedLeftAligned) {
@@ -500,27 +497,10 @@ class TickMarkerIconPainter extends MarkerGroupIconPainter {
500497
..strokeWidth = 1;
501498
canvas.drawRRect(rrect, strokePaint);
502499

503-
final TextPainter iconPainter = TextPainter(
504-
text: TextSpan(
505-
text: String.fromCharCode(QuillIcons.flag_checkered.codePoint),
506-
style: TextStyle(
507-
fontFamily: QuillIcons.kFontFam,
508-
fontSize: iconSize,
509-
package: QuillIcons.kFontPkg,
510-
color: textIconColor.withOpacity(opacity),
511-
),
512-
),
513-
textDirection: TextDirection.ltr,
514-
)..layout();
515-
516-
final double iconX = pillRect.left + leftPadding;
517-
final double iconY = anchor.dy - iconPainter.height / 2;
518-
iconPainter.paint(canvas, Offset(iconX, iconY));
519-
520500
paintWithTextPainter(
521501
canvas,
522502
painter: textPainter,
523-
anchor: Offset(iconX + iconSize + spacing, anchor.dy),
503+
anchor: Offset(pillRect.left + leftPadding, anchor.dy),
524504
anchorAlignment: Alignment.centerLeft,
525505
);
526506

lib/src/widgets/profit_and_loss_label.dart

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)