series method

Future<List<CubeSeries>> series(
  1. String cube,
  2. List<String> xAxis, {
  3. List<String>? series,
  4. List<String>? indices,
  5. Map<String, dynamic>? filters,
  6. bool? groupIndices,
  7. bool? inverseIndices,
})

Retrieve series of cube by xAxis. If series are set, each CubeSeries.name receive the series group value. If indices are set, each CubeSeries.index is set to the index name.

Implementation

Future<List<CubeSeries>> series(String cube, List<String> xAxis,
    {List<String>? series,
    List<String>? indices,
    Map<String, dynamic>? filters,
    bool? groupIndices,
    bool? inverseIndices}) async {
  final response = await dio.put('/cube/$cube', data: {
    'series': series,
    'xAxis': xAxis,
    'filters': filters,
    'indices': indices,
    'groupIndices': groupIndices,
    'inverseIndices': inverseIndices
  });
  final results =
      List<CubeSeries>.from(response.data.map((e) => CubeSeries.fromJson(e)));
  if (results.isEmpty) return results;
  final base = results.elementAt(0);
  final columns = xAxis.toSet();
  if (series != null) columns.addAll(series);
  final configuration =
      session.profile.cubes.firstWhere((element) => element.name == cube);
  final data = await _prepare(cube, columns);

  String translate(String key, List<String> axes) {
    final keys = key.split(complexAxisDivider), labels = [];
    for (var i = 0; i < keys.length; i++) {
      final val = data[axes[i]]![keys[i]];
      labels.add(val ?? keys[i]);
    }
    return labels.join('-');
  }

  var i = 0;
  for (var item in results) {
    for (var point in item.points) {
      point.xLabel = translate(point.x, xAxis);
      if (i > 0 && !base.points.any((element) => element.x == point.x)) {
        base.points.add(Point(point.x, 0));
      }
    }
    if (item.name != null) {
      item.title = translate(item.name!, series!);
    } else {
      final index = configuration.indices
          ?.firstWhereOrNull((element) => element.name == item.index);
      item.title = index?.title;
    }
    i++;
  }
  return results;
}