translateDrawing method
Translates all points and prices of a drawing by a given candle and price delta.
Implementation
void translateDrawing(String id, int deltaCandles, double deltaPrice) {
final index = _drawings.indexWhere((d) => d.id == id);
if (index >= 0) {
final drawing = _drawings[index];
if (drawing.isLocked) return;
final updatedPoints = drawing.points.map((p) {
return p.copyWith(
candleIndex: p.candleIndex + deltaCandles,
price: double.parse((p.price + deltaPrice).toStringAsFixed(2)),
);
}).toList();
final updatedProps = Map<String, dynamic>.from(drawing.properties);
if (updatedProps.containsKey('targetPrice')) {
updatedProps['targetPrice'] = double.parse(
((updatedProps['targetPrice'] as double) + deltaPrice)
.toStringAsFixed(2),
);
}
if (updatedProps.containsKey('stopPrice')) {
updatedProps['stopPrice'] = double.parse(
((updatedProps['stopPrice'] as double) + deltaPrice).toStringAsFixed(
2,
),
);
}
_drawings[index] = drawing.copyWith(
points: updatedPoints,
properties: updatedProps,
);
notifyListeners();
}
}