sampleData function
Sample data using Ramer-Douglas-Peucker algorithm to preserve curve characteristics. This algorithm keeps points that are important for maintaining the shape of the curve.
Implementation
Map<DateTime, double> sampleData(Map<DateTime, double> data, int targetCount) {
if (data.length <= targetCount) return data;
final entries = data.entries.toList();
// Use Douglas-Peucker algorithm for smart sampling.
final sampled = douglasPeucker(entries, targetCount);
// Convert back to map.
return Map.fromEntries(sampled);
}