rankedCompatibleChartTypesForJson function
Returns compatible target chart types ranked by preferredOrder.
By default, current type is excluded so the first result is a true alternative for runtime switching.
Implementation
List<ChartType> rankedCompatibleChartTypesForJson(
Map<String, dynamic> source, {
List<ChartType>? preferredOrder,
bool includeCurrentType = false,
bool registeredOnly = true,
}) {
final compatible = compatibleChartTypesForJson(
source,
registeredOnly: registeredOnly,
);
if (compatible.isEmpty) return const [];
final ranked = <ChartType>[];
for (final t in preferredOrder ?? const <ChartType>[]) {
if (compatible.contains(t) && !ranked.contains(t)) {
ranked.add(t);
}
}
for (final t in compatible) {
if (!ranked.contains(t)) {
ranked.add(t);
}
}
if (!includeCurrentType) {
final current = _tryParseCanonicalType(source['type']);
if (current != null) {
ranked.remove(current);
}
}
return ranked;
}