chartSwitchOptionsForJson function

List<ChartSwitchOption> chartSwitchOptionsForJson(
  1. Map<String, dynamic> source, {
  2. List<ChartType>? preferredOrder,
  3. bool includeCurrentType = false,
  4. bool registeredOnly = true,
})

Returns ranked switch candidates with capabilities and preview payloads.

Implementation

List<ChartSwitchOption> chartSwitchOptionsForJson(
  Map<String, dynamic> source, {
  List<ChartType>? preferredOrder,
  bool includeCurrentType = false,
  bool registeredOnly = true,
}) {
  final sourceShape = inferSeriesDataShape(source);
  final current = _tryParseCanonicalType(source['type']);
  final ranked = rankedCompatibleChartTypesForJson(
    source,
    preferredOrder: preferredOrder,
    includeCurrentType: includeCurrentType,
    registeredOnly: registeredOnly,
  );

  final options = <ChartSwitchOption>[];
  for (int i = 0; i < ranked.length; i++) {
    final type = ranked[i];
    final capabilities = chartCapabilitiesForType(type);
    final previewPayload = switchChartTypeForSeriesShape(
      source,
      targetType: type,
    );
    options.add(
      ChartSwitchOption(
        type: type,
        rank: i + 1,
        isCurrentType: current == type,
        sourceShape: sourceShape,
        capabilities: capabilities,
        previewPayload: previewPayload,
        reason: _switchReason(type, sourceShape, capabilities, current == type),
      ),
    );
  }
  return options;
}