import * as CHANNEL from 'vega-lite/build/src/channel' ; import { DEFAULT_QUERY_CONFIG , QueryConfig } from '../../config' ; import { SpecQueryModel } from '../../model' ; import { EncodingQuery , isAutoCountQuery , isFieldQuery } from '../../query/encoding' ; import { Schema } from '../../schema' ; import { Dict } from '../../util' ; import { FeatureScore } from '../ranking' ; import { Scorer } from './base' ; /**
 * Effective Score for preferred facet
 */ export class FacetScorer extends Scorer { constructor ( ) { super ( 'Facet' ) ; } protected initScore ( opt ? ) { opt = { ... DEFAULT_QUERY_CONFIG , ... opt } ; const score = { } ; if ( opt . preferredFacet === CHANNEL . ROW ) { score [ CHANNEL . COLUMN ] = - 0.01 ; } else if ( opt . preferredFacet === CHANNEL . COLUMN ) { score [ CHANNEL . ROW ] = - 0.01 ; } return score ; } public getScore ( specM , _ , __ ) { return specM . getEncodings ( ) . reduce ( ( features , encQ ) => { if ( isFieldQuery ( encQ ) || isAutoCountQuery ( encQ ) ) { const featureScore = this . getFeatureScore ( encQ . channel as string ) ; if ( featureScore ) { features . push ( featureScore ) ; } } return features ; } , [ ] ) ; } }