switchChartTypeForSeriesShape function
Switch chart type while preserving/normalizing data where possible.
Throws StateError when target type is not compatible (unless force).
Implementation
Map<String, dynamic> switchChartTypeForSeriesShape(
Map<String, dynamic> source, {
required ChartType targetType,
bool force = false,
}) {
final compatibility = chartSwitchCompatibilityForJson(
source,
targetType: targetType,
registeredOnly: false,
);
final canSwitch =
compatibility.isCompatible ||
(force && compatibility.forceConversionAvailable);
if (!canSwitch) {
throw StateError(compatibility.reason);
}
final normalized = _normalizeDataForTarget(source, targetType);
normalized['type'] = chartTypeToString(targetType);
return normalized;
}