import { Message } from '@bufbuild/protobuf'; import { castMsg, CustomRenderProps, ProtobufViz, ProtobufVizProps, ProtoFile, } from '@protobuf-viz/react'; import React from 'react'; import { CustomCast } from './CustomCast.tsx'; import { CustomDirect } from './CustomDirect.tsx'; import { CustomFieldReference } from './CustomFieldReference.tsx'; import { CustomFunction } from './CustomFunction.tsx'; import { CustomLiteral } from './CustomLiteral.tsx'; import { CustomNamedStruct } from './CustomNamedStruct.tsx'; import { CustomReferenceSegment } from './CustomReferenceSegment.tsx'; import { CustomRootReference } from './CustomRootReference.tsx'; import { CustomSimpleExtensionDeclaration } from './CustomSimpleExtensionDeclaration.tsx'; import { CustomSimpleExtensionUri } from './CustomSimpleExtensionUri.tsx'; import { CustomStructItem } from './CustomStructItem.tsx'; import { CustomType } from './CustomType.tsx'; import { VersionComponent } from './CustomVersion.tsx'; import { AggregateFunction, Expression_Cast, Expression_FieldReference, Expression_FieldReference_RootReference, Expression_Literal, Expression_MaskExpression_StructItem, Expression_ReferenceSegment, Expression_ScalarFunction, RelCommon_Direct, RelSchema, } from './gen/substrait/algebra_pb.ts'; import { SimpleExtensionDeclaration, SimpleExtensionURI, } from './gen/substrait/extensions/extensions_pb.ts'; import { PlanRelSchema, PlanSchema, Version } from './gen/substrait/plan_pb.ts'; import { NamedStruct, Type } from './gen/substrait/type_pb.ts'; import './SubstraitViz.css'; import { defaultTheme, SubstraitVizTheme } from './theme.ts'; export interface SubstraitVizProps extends Omit< ProtobufVizProps, 'coreNodes' | 'schema' | 'nodeRender' | 'protoMessage' | 'theme' > { plan: ProtoFile; theme?: Partial; } export function SubstraitViz({ plan, theme, ...props }: SubstraitVizProps) { return ( ({ ...defaultTheme, ...theme }), [theme])} /* prettier-ignore */ nodeRender={(props) => { { const casted = castProps('substrait.Version', props); if (casted) return ; } { const casted = castProps('substrait.extensions.SimpleExtensionDeclaration', props); if (casted) return ; } { const casted = castProps('substrait.extensions.SimpleExtensionURI', props); if (casted) return ; } { const casted = castProps('substrait.Expression.FieldReference.RootReference', props); if (casted) return ; } { const casted = castProps('substrait.RelCommon.Direct', props); if (casted) return ; } { const casted = castProps('substrait.Expression.ReferenceSegment', props); if (casted) return ; } { const casted = castProps('substrait.Expression.FieldReference', props); if (casted) return ; } { const casted = castProps('substrait.Type', props); if (casted) return ; } { const casted = castProps('substrait.NamedStruct', props); if (casted) return ; } { const casted = castProps('substrait.Expression.Literal', props); if (casted) return ; } { const casted = castProps('substrait.Expression.MaskExpression.StructItem', props); if (casted) return ; } { const casted = castProps('substrait.Expression.Cast', props); if (casted) return ; } { const casted = castProps('substrait.Expression.ScalarFunction', props); if (casted) return ; } { const casted = castProps('substrait.AggregateFunction', props); if (casted) return ; } }} {...props} /> ); } function castProps( typeName: T['$typeName'], props: CustomRenderProps, ): CustomRenderProps | undefined { if (castMsg(typeName, props.msg)) { return props as CustomRenderProps; } }