import * as CHANNEL from 'vega-lite/build/src/channel' ; import * as MARK from 'vega-lite/build/src/mark' ; import { Mark } from 'vega-lite/build/src/mark' ; import { QueryConfig } from '../../config' ; import { SpecQueryModel } from '../../model' ; import { Schema } from '../../schema' ; import { Dict , forEach } from '../../util' ; import { FeatureScore } from '../ranking' ; import { Scorer } from './base' ; import { BIN_Q , ExtendedType , getExtendedType , K , N , NONE , O , Q , T , TIMEUNIT_O , TIMEUNIT_T } from './type' ; export class MarkScorer extends Scorer { constructor ( ) { super ( 'Mark' ) ; } protected initScore ( ) { return init ( ) ; } public getScore ( specM , _ , __ ) { let mark = specM . getMark ( ) as Mark ; if ( mark === MARK . CIRCLE || mark === MARK . SQUARE ) { mark = MARK . POINT ; } const xEncQ = specM . getEncodingQueryByChannel ( CHANNEL . X ) ; const xType = xEncQ ? getExtendedType ( xEncQ ) : NONE ; const yEncQ = specM . getEncodingQueryByChannel ( CHANNEL . Y ) ; const yType = yEncQ ? getExtendedType ( yEncQ ) : NONE ; const isOccluded = ! specM . isAggregate ( ) ; const feature = `${ xType }_${ yType }_${ isOccluded }_${ mark }` ; const featureScore = this . getFeatureScore ( feature ) ; if ( featureScore ) { return [ featureScore ] ; } console . error ( 'feature score missing for' , feature ) ; return [ ] ; } } export function featurize ( xType , yType , hasOcclusion , mark ) { return `${ xType }_${ yType }_${ hasOcclusion }_${ mark }` ; } function init ( ) { const MEASURES = [ Q , T ] ; const DISCRETE = [ BIN_Q , TIMEUNIT_O , O , N , K ] ; const DISCRETE_OR_NONE = DISCRETE . concat ( [ NONE ] ) ; const SCORE = { } as Dict < number > ; MEASURES . forEach ( ( xType ) => { MEASURES . forEach ( ( yType ) => { const occludedQQMark = { point : 0 , text : - 0.2 , tick : - 0.5 , rect : - 1 , bar : - 2 , line : - 2 , area : - 2 , rule : - 2.5 , } ; forEach ( occludedQQMark , ( score , mark ) => { const feature = featurize ( xType , yType , true , mark ) ; SCORE [ feature ] = score ; } ) ; const noOccludedQQMark = { point : 0 , text : - 0.2 , tick : - 0.5 , bar : - 2 , line : - 2 , area : - 2 , rule : - 2.5 , } ; forEach ( noOccludedQQMark , ( score , mark ) => { const feature = featurize ( xType , yType , false , mark ) ; SCORE [ feature ] = score ; } ) ; } ) ; } ) ; MEASURES . forEach ( ( xType ) => { DISCRETE_OR_NONE . forEach ( ( yType ) => { const occludedDimensionMeasureMark = { tick : 0 , point : - 0.2 , text : - 0.5 , bar : - 2 , line : - 2 , area : - 2 , rule : - 2.5 , } ; forEach ( occludedDimensionMeasureMark , ( score , mark ) => { const feature = featurize ( xType , yType , true , mark ) ; SCORE [ feature ] = score ; const feature2 = featurize ( yType , xType , true , mark ) ; SCORE [ feature2 ] = score ; } ) ; } ) ; [ TIMEUNIT_T ] . forEach ( ( yType ) => { const occludedDimensionMeasureMark = { point : 0 , text : - 0.5 , tick : - 1 , bar : - 2 , line : - 2 , area : - 2 , rule : - 2.5 , } ; forEach ( occludedDimensionMeasureMark , ( score , mark ) => { const feature = featurize ( xType , yType , true , mark ) ; SCORE [ feature ] = score ; const feature2 = featurize ( yType , xType , true , mark ) ; SCORE [ feature2 ] = score ; } ) ; } ) ; [ NONE , N , O , K ] . forEach ( ( yType ) => { const noOccludedQxN = { bar : 0 , point : - 0.2 , tick : - 0.25 , text : - 0.3 , line : - 2 , area : - 2 , rule : - 2.5 , } ; forEach ( noOccludedQxN , ( score , mark ) => { const feature = featurize ( xType , yType , false , mark ) ; SCORE [ feature ] = score ; const feature2 = featurize ( yType , xType , false , mark ) ; SCORE [ feature2 ] = score ; } ) ; } ) ; [ BIN_Q ] . forEach ( ( yType ) => { const noOccludedQxBinQ = { bar : 0 , point : - 0.2 , tick : - 0.25 , text : - 0.3 , line : - 0.5 , area : - 0.5 , rule : - 2.5 , } ; forEach ( noOccludedQxBinQ , ( score , mark ) => { const feature = featurize ( xType , yType , false , mark ) ; SCORE [ feature ] = score ; const feature2 = featurize ( yType , xType , false , mark ) ; SCORE [ feature2 ] = score ; } ) ; } ) ; [ TIMEUNIT_T , TIMEUNIT_O ] . forEach ( ( yType ) => { const noOccludedQxBinQ = { line : 0 , area : - 0.1 , bar : - 0.2 , point : - 0.3 , tick : - 0.35 , text : - 0.4 , rule : - 2.5 , } ; forEach ( noOccludedQxBinQ , ( score , mark ) => { const feature = featurize ( xType , yType , false , mark ) ; SCORE [ feature ] = score ; const feature2 = featurize ( yType , xType , false , mark ) ; SCORE [ feature2 ] = score ; } ) ; } ) ; } ) ; [ TIMEUNIT_T ] . forEach ( ( xType ) => { [ TIMEUNIT_T ] . forEach ( ( yType ) => { const ttMark = { point : 0 , rect : - 0.1 , text : - 0.5 , tick : - 1 , bar : - 2 , line : - 2 , area : - 2 , rule : - 2.5 , } ; forEach ( ttMark , ( score , mark ) => { const feature = featurize ( xType , yType , true , mark ) ; SCORE [ feature ] = score ; } ) ; forEach ( ttMark , ( score , mark ) => { const feature = featurize ( xType , yType , false , mark ) ; SCORE [ feature ] = score ; } ) ; } ) ; DISCRETE_OR_NONE . forEach ( ( yType ) => { const tdMark = { tick : 0 , point : - 0.2 , text : - 0.5 , rect : - 1 , bar : - 2 , line : - 2 , area : - 2 , rule : - 2.5 , } ; forEach ( tdMark , ( score , mark ) => { const feature = featurize ( xType , yType , true , mark ) ; SCORE [ feature ] = score ; } ) ; forEach ( tdMark , ( score , mark ) => { const feature = featurize ( yType , xType , true , mark ) ; SCORE [ feature ] = score ; } ) ; forEach ( tdMark , ( score , mark ) => { const feature = featurize ( xType , yType , false , mark ) ; SCORE [ feature ] = score ; } ) ; forEach ( tdMark , ( score , mark ) => { const feature = featurize ( yType , xType , false , mark ) ; SCORE [ feature ] = score ; } ) ; } ) ; } ) ; for ( const xType of DISCRETE_OR_NONE ) { for ( const yType of DISCRETE_OR_NONE ) { const ddMark = { point : 0 , rect : 0 , text : - 0.1 , tick : - 1 , bar : - 2 , line : - 2 , area : - 2 , rule : - 2.5 , } ; forEach ( ddMark , ( score , mark ) => { const feature = featurize ( xType , yType , true , mark ) ; SCORE [ feature ] = score ; } ) ; forEach ( ddMark , ( score , mark ) => { const feature = featurize ( xType , yType , false , mark ) ; SCORE [ feature ] = score ; } ) ; } } return SCORE ; }