Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [GRWT-3474] Point_Highlight_Enlarges_when_navigating_back_to_same_chart_view #349

Merged
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ publish_to: none

environment:
sdk: ">=3.3.3 <4.0.0"
flutter: "3.19.6"
flutter: "3.24.1"

dependencies:
flutter:
Expand Down
1 change: 1 addition & 0 deletions lib/deriv_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export 'src/add_ons/drawing_tools_ui/drawing_tool_config.dart';
export 'src/add_ons/drawing_tools_ui/fibfan/fibfan_drawing_tool_config.dart';
export 'src/add_ons/drawing_tools_ui/horizontal/horizontal_drawing_tool_config.dart';
export 'src/add_ons/drawing_tools_ui/line/line_drawing_tool_config.dart';
export 'src/add_ons/drawing_tools_ui/line/line_drawing_tool_config_mobile.dart';
export 'src/add_ons/drawing_tools_ui/ray/ray_drawing_tool_config.dart';
export 'src/add_ons/drawing_tools_ui/rectangle/rectangle_drawing_tool_config.dart';
export 'src/add_ons/drawing_tools_ui/trend/trend_drawing_tool_config.dart';
Expand Down
2 changes: 2 additions & 0 deletions lib/src/add_ons/drawing_tools_ui/drawing_tool_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ abstract class DrawingToolConfig extends AddOnConfig {
return HorizontalDrawingToolConfig.fromJson(json);
case LineDrawingToolConfig.name:
return LineDrawingToolConfig.fromJson(json);
case LineDrawingToolConfigMobile.name:
return LineDrawingToolConfigMobile.fromJson(json);
case RayDrawingToolConfig.name:
return RayDrawingToolConfig.fromJson(json);
case RectangleDrawingToolConfig.name:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import 'package:deriv_chart/deriv_chart.dart';
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/callbacks.dart';
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/drawing_tool_item.dart';
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/line/line_drawing_tool_item_mobile.dart';
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/line/line_drawing_tool_label_painter.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/data_model/drawing_pattern.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/data_model/edge_point.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/data_model/point.dart';
import 'package:deriv_chart/src/theme/colors.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:json_annotation/json_annotation.dart';

part 'line_drawing_tool_config_mobile.g.dart';

/// Line drawing tool config
@JsonSerializable()
class LineDrawingToolConfigMobile extends DrawingToolConfig {
/// Initializes
const LineDrawingToolConfigMobile({
String? configId,
DrawingData? drawingData,
List<EdgePoint> edgePoints = const <EdgePoint>[],
this.lineStyle = const LineStyle(
thickness: 0.9,
color: BrandColors.coral,
),
this.overlayStyle,
this.pattern = DrawingPatterns.solid,
super.number,
}) : super(
configId: configId,
drawingData: drawingData,
edgePoints: edgePoints,
);

/// Initializes from JSON.
factory LineDrawingToolConfigMobile.fromJson(Map<String, dynamic> json) =>
_$LineDrawingToolConfigMobileFromJson(json);

/// Drawing tool name
static const String name = 'dt_line_mobile';

@override
Map<String, dynamic> toJson() => _$LineDrawingToolConfigMobileToJson(this)
..putIfAbsent(DrawingToolConfig.nameKey, () => name);

/// Drawing tool line style
final LineStyle lineStyle;

/// Drawing tool overlay style
@JsonKey(
fromJson: _overlayStyleFromJson,
toJson: _overlayStyleToJson,
)
final OverlayStyle? overlayStyle;

/// Drawing tool line pattern: 'solid', 'dotted', 'dashed'
// TODO(maryia-binary): implement 'dotted' and 'dashed' patterns
final DrawingPatterns pattern;

@override
DrawingToolItem getItem(
UpdateDrawingTool updateDrawingTool,
VoidCallback deleteDrawingTool,
) =>
LineDrawingToolItemMobile(
updateDrawingTool: updateDrawingTool,
deleteDrawingTool: deleteDrawingTool,
);

@override
LineDrawingToolConfigMobile copyWith({
String? configId,
DrawingData? drawingData,
LineStyle? lineStyle,
LineStyle? fillStyle,
OverlayStyle? overlayStyle,
DrawingPatterns? pattern,
List<EdgePoint>? edgePoints,
bool? enableLabel,
int? number,
}) =>
LineDrawingToolConfigMobile(
configId: configId ?? this.configId,
drawingData: drawingData ?? this.drawingData,
lineStyle: lineStyle ?? this.lineStyle,
overlayStyle: overlayStyle ?? this.overlayStyle,
pattern: pattern ?? this.pattern,
edgePoints: edgePoints ?? this.edgePoints,
number: number ?? this.number,
);

@override
LineDrawingToolLabelPainter? getLabelPainter({
required Point startPoint,
required Point endPoint,
}) {
if (kIsWeb) {
return null;
} else {
return MobileLineDrawingToolLabelPainter(
const LineDrawingToolConfigMobile(),
startPoint: startPoint,
endPoint: endPoint,
);
}
}

static OverlayStyle? _overlayStyleFromJson(Map<String, dynamic>? json) {
if (json == null) {
return null;
}
return OverlayStyle(
color: Color(json['color'] as int),
);
}

static Map<String, dynamic>? _overlayStyleToJson(OverlayStyle? instance) {
if (instance == null) {
return null;
}
return {
'color': instance.color.value,
};
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import 'package:deriv_chart/generated/l10n.dart';
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/drawing_tool_config.dart';
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/drawing_tool_item.dart';
import 'package:deriv_chart/src/add_ons/drawing_tools_ui/line/line_drawing_tool_config_mobile.dart';
import 'package:deriv_chart/src/add_ons/indicators_ui/widgets/color_selector.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/data_model/drawing_pattern.dart';
import 'package:deriv_chart/src/theme/painting_styles/line_style.dart';
import 'package:flutter/material.dart';
import '../callbacks.dart';

/// Line drawing tool item in the list of drawing tools
class LineDrawingToolItemMobile extends DrawingToolItem {
/// Initializes
const LineDrawingToolItemMobile({
required UpdateDrawingTool updateDrawingTool,
required VoidCallback deleteDrawingTool,
Key? key,
LineDrawingToolConfigMobile config = const LineDrawingToolConfigMobile(),
}) : super(
key: key,
title: 'Line',
config: config,
updateDrawingTool: updateDrawingTool,
deleteDrawingTool: deleteDrawingTool,
);

@override
DrawingToolItemState<DrawingToolConfig> createDrawingToolItemState() =>
LineDrawingToolItemMobileState();
}

/// LineDrawingToolItem State class
class LineDrawingToolItemMobileState
extends DrawingToolItemState<LineDrawingToolConfigMobile> {
LineStyle? _lineStyle;
DrawingPatterns? _pattern;

@override
LineDrawingToolConfigMobile createDrawingToolConfig() =>
LineDrawingToolConfigMobile(
lineStyle: _currentLineStyle,
pattern: _currentPattern,
);

@override
Widget getDrawingToolOptions() => Column(
children: <Widget>[
_buildColorField(),
// TODO(maryia-binary): implement _buildPatternField() to set pattern
],
);

Widget _buildColorField() => Row(
children: <Widget>[
Text(
ChartLocalization.of(context).labelColor,
style: const TextStyle(fontSize: 16),
),
ColorSelector(
currentColor: _currentLineStyle.color,
onColorChanged: (Color selectedColor) {
setState(() {
_lineStyle = _currentLineStyle.copyWith(color: selectedColor);
});
updateDrawingTool();
},
)
],
);

LineStyle get _currentLineStyle =>
_lineStyle ?? (widget.config as LineDrawingToolConfigMobile).lineStyle;

DrawingPatterns get _currentPattern =>
_pattern ?? (widget.config as LineDrawingToolConfigMobile).pattern;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class LineDrawingToolLabelPainter extends DrawingToolLabelPainter {
}) : super(lineDrawingToolConfig);

/// Line drawing tool config.
final LineDrawingToolConfig lineDrawingToolConfig;
late final dynamic lineDrawingToolConfig;

/// Start point.
final Point startPoint;
Expand Down
2 changes: 0 additions & 2 deletions lib/src/add_ons/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import 'dart:math';

import 'package:deriv_chart/deriv_chart.dart';

import 'repository.dart';

/// Extension on Repository<AddOnConfig>.
extension AddOnsRepositoryConfigExtension on Repository<AddOnConfig> {
// TODO(Ramin): Later will do this will be internally handled inside the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,6 @@ class AccumulatorsClosedIndicatorPainter
painter: lowBarrierLabelPainter, anchor: lowBarrierLabelAnchor);

// Draw exit tick position.
paintDot(canvas, exitTickPosition, color);
paintDotWithGlow(canvas, exitTickPosition, color: color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class AccumulatorsRecentlyClosedIndicatorPainter
..drawPath(lowerTrianglePath, _linePaintFill);

// Draw exit tick position.
paintDot(canvas, exitTickPosition, color);
paintDotWithGlow(canvas, exitTickPosition, color: color);

// draw dialog
const double dotPadding = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ part 'draggable_edge_point.g.dart';
/// For example with dots are draggable edge points for the line
/// ⎯⎯⚪️⎯⎯⎯⚪️⎯⎯
@JsonSerializable()
// ignore: must_be_immutable
class DraggableEdgePoint extends EdgePoint {
/// Initializes
DraggableEdgePoint({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_too
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/fibfan/fibfan_drawing.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/horizontal/horizontal_drawing.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/line/line_drawing.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/line/line_drawing_mobile.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/ray/ray_line_drawing.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/rectangle/rectangle_drawing.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/trend/trend_drawing.dart';
Expand Down Expand Up @@ -41,6 +42,8 @@ abstract class Drawing {
return HorizontalDrawing.fromJson(json);
case LineDrawing.nameKey:
return LineDrawing.fromJson(json);
case LineDrawingMobile.nameKey:
return LineDrawingMobile.fromJson(json);
case RayLineDrawing.nameKey:
return RayLineDrawing.fromJson(json);
case RectangleDrawing.nameKey:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/chart_series/data_series.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/channel/channel_drawing_creator.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/continuous/continuous_drawing_creator.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/data_model/drawing_parts.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/data_model/edge_point.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/drawing.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/horizontal/horizontal_drawing_creator.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/fibfan/fibfan_drawing_creator.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/line/line_drawing.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/line/line_drawing_mobile.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/line/line_drawing_creator.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/rectangle/rectangle_drawing_creator.dart';
import 'package:deriv_chart/src/deriv_chart/chart/data_visualization/drawing_tools/ray/ray_drawing_creator.dart';
Expand Down Expand Up @@ -106,6 +109,39 @@ class DrawingToolWidget extends StatelessWidget {
quoteFromCanvasY: quoteFromCanvasY,
clearDrawingToolSelection: clearDrawingToolSelection,
removeUnfinishedDrawing: removeUnfinishedDrawing,
createLineDrawing: ({
required DrawingParts drawingPart,
EdgePoint startEdgePoint = const EdgePoint(),
EdgePoint endEdgePoint = const EdgePoint(),
bool exceedStart = false,
bool exceedEnd = false,
}) =>
LineDrawing(
drawingPart: drawingPart,
startEdgePoint: startEdgePoint,
endEdgePoint: endEdgePoint,
exceedStart: exceedStart,
exceedEnd: exceedEnd),
);
case 'dt_line_mobile':
return LineDrawingCreator(
onAddDrawing: onAddDrawing,
quoteFromCanvasY: quoteFromCanvasY,
clearDrawingToolSelection: clearDrawingToolSelection,
removeUnfinishedDrawing: removeUnfinishedDrawing,
createLineDrawing: ({
required DrawingParts drawingPart,
EdgePoint startEdgePoint = const EdgePoint(),
EdgePoint endEdgePoint = const EdgePoint(),
bool exceedStart = false,
bool exceedEnd = false,
}) =>
LineDrawingMobile(
drawingPart: drawingPart,
startEdgePoint: startEdgePoint,
endEdgePoint: endEdgePoint,
exceedStart: exceedStart,
exceedEnd: exceedEnd),
);
case 'dt_ray':
return RayDrawingCreator(
Expand Down
Loading
Loading