import { ComponentProps } from 'react' ; import { BaseDatum , Spec } from '.' ; import { ChartType } from '../chart_types' ; import { Predicate } from '../common/predicate' ; import { buildSFProps , SFProps , useSpecFactory } from '../state/spec_factory' ; import { Datum , stripUndefined } from '../utils/common' ; import { SpecType } from './constants' ; public export type GroupByAccessor < D extends BaseDatum = any > = ( spec : Spec , datum : D ) => string | number ; alpha export type GroupBySort = Predicate ; public export type GroupByFormatter < D extends BaseDatum = any > = ( value : ReturnType < GroupByAccessor < D > > ) => string ; alpha export interface GroupBySpec < D extends BaseDatum = any > extends Spec { /**
     * Function to return a unique value __by__ which to group the data
     */ by : GroupByAccessor < D > ; /**
     * Sort predicate used to sort grouped data
     */ sort : GroupBySort ; /**
     * Formatter used on all `by` values.
     *
     * Only for displayed values, not used in sorting or other internal computations.
     */ format ? : GroupByFormatter < D > ; } const buildProps = buildSFProps < GroupBySpec > ( ) ( { chartType : ChartType . Global , specType : SpecType . IndexOrder , } , { } ) ; public export const GroupBy = function < D extends BaseDatum = Datum > ( props ) { const { defaults , overrides } = buildProps ; useSpecFactory < GroupBySpec < D > > ( { ... defaults , ... stripUndefined ( props ) , ... overrides } ) ; return null ; } ; public export type GroupByProps = ComponentProps < typeof GroupBy > ;