categories property

  1. @override
List<C> get categories
override

Get categories of a specified series as a collection.

Implementation

@override
List<C> get categories {
  if (_categories != null)
    return _categories!;

  if (_data.isEmpty)
    return const [];

  //merge all categories
  final list = <C>[];
  for (final series in series) {
    final categoryData = _data[series];
    if (categoryData == null)
      continue;

    final categories = categoryData.keys.toList();
    if (list.isEmpty) {
      list.addAll(categories);
      continue;
    }

    while (categories.isNotEmpty) {
      final cate = categories.cast<C?>().firstWhere(list.contains, orElse: () => null);
      var i = cate != null ? categories.indexOf(cate): -1;
      categories.removeAt(i);
      while (i > 0) {
        list.add(categories.removeAt(0));
        i--;
      }
    }
  }

  return _categories = list;
}