LCOV - code coverage report
Current view: top level - chart - datetime_series_converter.dart (source / functions) Hit Total Coverage
Test: lcov_filtered.info Lines: 17 17 100.0 %
Date: 2019-08-23 11:26:09 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:ui';
       2             : 
       3             : import 'package:fl_animated_linechart/chart/chart_line.dart';
       4             : import 'package:fl_animated_linechart/chart/datetime_chart_point.dart';
       5             : import 'package:fl_animated_linechart/common/dates.dart';
       6             : import 'package:fl_animated_linechart/common/pair.dart';
       7             : 
       8             : class DateTimeSeriesConverter {
       9             : 
      10           2 :   static Pair<List<ChartLine>, Dates> convertFromDateMaps(List<Map<DateTime, double>> series, List<Color> colors) {
      11           2 :     Dates minMax = _findMinMax(series);
      12             : 
      13             :     int index = 0;
      14          12 :     List<ChartLine> lines = series.map((map) => _convert(map, minMax, colors[index++])).toList();
      15             : 
      16           2 :     return Pair(lines, minMax);
      17             :   }
      18             : 
      19           2 :   static ChartLine _convert(Map<DateTime, double> input, Dates minMax, Color color) {
      20           2 :     DateTime from = minMax.min;
      21             : 
      22           2 :     List<DateTimeChartPoint> result = [];
      23             : 
      24           4 :     input.forEach((dateTime, value) {
      25           6 :       double x = dateTime.difference(from).inSeconds.toDouble();
      26             :       double y = value;
      27           4 :       result.add(DateTimeChartPoint(x, y, dateTime));
      28             :     });
      29             : 
      30           2 :     return ChartLine(result, color, 'W');
      31             :   }
      32             : 
      33           2 :   static Dates _findMinMax(List<Map<DateTime, double>> list) {
      34             :     DateTime min;
      35             :     DateTime max;
      36             : 
      37           4 :     list.forEach((map) {
      38           6 :       map.keys.forEach((dateTime) {
      39             :         if (min == null) {
      40             :           min = dateTime;
      41             :           max = dateTime;
      42             :         } else {
      43           2 :           if (dateTime.isBefore(min)) {
      44             :             min = dateTime;
      45             :           }
      46           2 :           if (dateTime.isAfter(max)) {
      47             :             max = dateTime;
      48             :           }
      49             :         }
      50             :       });
      51             :     });
      52             : 
      53           2 :     return Dates(min, max);
      54             :   }
      55             : 
      56             : }

Generated by: LCOV version 1.14