chartSwitchCompatibilityForJson function
Checks whether targetType can safely consume source without throwing.
isCompatible means the target accepts the inferred source data shape
directly. forceConversionAvailable means Tenun can perform a supported
cross-shape conversion when force: true is used with
switchChartTypeForSeriesShape.
Implementation
ChartSwitchCompatibility chartSwitchCompatibilityForJson(
Map<String, dynamic> source, {
required ChartType targetType,
bool registeredOnly = true,
}) {
final sourceShape = inferSeriesDataShape(source);
final targetShape = targetSeriesDataShape(targetType);
final targetCapabilities = chartCapabilitiesForType(targetType);
final targetRegistered =
!registeredOnly || ChartRegistry.isRegistered(targetType);
final compatibleTypes = compatibleChartTypesForShape(
sourceShape,
registeredOnly: registeredOnly,
);
final isCompatible = targetRegistered && compatibleTypes.contains(targetType);
final forceConversionAvailable =
targetRegistered &&
!isCompatible &&
_hasSupportedForceConversion(source, targetType);
return ChartSwitchCompatibility(
targetType: targetType,
sourceShape: sourceShape,
targetShape: targetShape,
isCompatible: isCompatible,
forceConversionAvailable: forceConversionAvailable,
targetRegistered: targetRegistered,
compatibleTypes: compatibleTypes,
targetCapabilities: targetCapabilities,
reason: _switchCompatibilityReason(
targetType: targetType,
sourceShape: sourceShape,
targetShape: targetShape,
isCompatible: isCompatible,
forceConversionAvailable: forceConversionAvailable,
targetRegistered: targetRegistered,
compatibleTypes: compatibleTypes,
),
);
}