-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathconfig.ts
167 lines (142 loc) · 5.36 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import * as CHANNEL from 'vega-lite/build/src/channel';
import {Channel, ExtendedChannel} from 'vega-lite/build/src/channel';
import {Config} from 'vega-lite/build/src/config';
import {DEFAULT_PROP_PRECEDENCE, toKey} from './property';
import {DEFAULT_ENUM_INDEX, EnumIndex} from './wildcard';
// We name this QueryConfig to avoid confusion with Vega-Lite's Config
export interface QueryConfig {
verbose?: boolean;
defaultSpecConfig?: Config;
propertyPrecedence?: string[];
enum?: Partial<EnumIndex>;
/** Default ratio for number fields to be considered ordinal */
numberNominalProportion?: number;
/** Default cutoff for not applying the numberOrdinalProportion inference */
numberNominalLimit?: number;
// SPECIAL MODE
/**
* Allow automatically adding a special count (autoCount) field for plots
* that contain only discrete fields. In such cases, adding count make the
* output plots way more meaningful.
*/
autoAddCount?: boolean;
// CONSTRAINTS
constraintManuallySpecifiedValue?: boolean;
// Spec Constraints
hasAppropriateGraphicTypeForMark?: boolean;
omitAggregate?: boolean;
omitAggregatePlotWithDimensionOnlyOnFacet?: boolean;
omitAggregatePlotWithoutDimension?: boolean;
omitBarLineAreaWithOcclusion?: boolean;
omitBarTickWithSize?: boolean;
omitMultipleNonPositionalChannels?: boolean;
omitRaw?: boolean;
omitRawContinuousFieldForAggregatePlot?: boolean;
omitRawWithXYBothOrdinalScaleOrBin?: boolean;
omitRepeatedField?: boolean;
omitNonPositionalOrFacetOverPositionalChannels?: boolean;
omitTableWithOcclusionIfAutoAddCount?: boolean;
omitVerticalDotPlot?: boolean;
omitInvalidStackSpec?: boolean;
omitNonSumStack?: boolean;
preferredBinAxis?: Channel;
preferredTemporalAxis?: Channel;
preferredOrdinalAxis?: Channel;
preferredNominalAxis?: Channel;
preferredFacet?: ExtendedChannel;
// Field Encoding Constraints
minCardinalityForBin?: number;
maxCardinalityForCategoricalColor?: number;
maxCardinalityForFacet?: number;
maxCardinalityForShape?: number;
timeUnitShouldHaveVariation?: boolean;
typeMatchesSchemaType?: boolean;
// STYLIZE
stylize?: boolean;
smallRangeStepForHighCardinalityOrFacet?: {maxCardinality: number; rangeStep: number};
nominalColorScaleForHighCardinality?: {maxCardinality: number; palette: string};
xAxisOnTopForHighYCardinalityWithoutColumn?: {maxCardinality: number};
// EFFECTIVENESS PREFERENCE
maxGoodCardinalityForColor?: number; // FIXME: revise
maxGoodCardinalityForFacet?: number; // FIXME: revise
// HIGH CARDINALITY STRINGS
minPercentUniqueForKey?: number;
minCardinalityForKey?: number;
}
export const DEFAULT_QUERY_CONFIG: QueryConfig = {
verbose: false,
defaultSpecConfig: {
line: {point: true},
scale: {useUnaggregatedDomain: true},
},
propertyPrecedence: DEFAULT_PROP_PRECEDENCE.map(toKey),
enum: DEFAULT_ENUM_INDEX,
numberNominalProportion: 0.05,
numberNominalLimit: 40,
// CONSTRAINTS
constraintManuallySpecifiedValue: false,
// Spec Constraints -- See description inside src/constraints/spec.ts
autoAddCount: false,
hasAppropriateGraphicTypeForMark: true,
omitAggregate: false,
omitAggregatePlotWithDimensionOnlyOnFacet: true,
omitAggregatePlotWithoutDimension: false,
omitBarLineAreaWithOcclusion: true,
omitBarTickWithSize: true,
omitMultipleNonPositionalChannels: true,
omitRaw: false,
omitRawContinuousFieldForAggregatePlot: true,
omitRepeatedField: true,
omitNonPositionalOrFacetOverPositionalChannels: true,
omitTableWithOcclusionIfAutoAddCount: true,
omitVerticalDotPlot: false,
omitInvalidStackSpec: true,
omitNonSumStack: true,
preferredBinAxis: CHANNEL.X,
preferredTemporalAxis: CHANNEL.X,
preferredOrdinalAxis: CHANNEL.Y, // ordinal on y makes it easier to read.
preferredNominalAxis: CHANNEL.Y, // nominal on y makes it easier to read.
preferredFacet: CHANNEL.ROW, // row make it easier to scroll than column
// Field Encoding Constraints -- See description inside src/constraint/field.ts
minCardinalityForBin: 15,
maxCardinalityForCategoricalColor: 20,
maxCardinalityForFacet: 20,
maxCardinalityForShape: 6,
timeUnitShouldHaveVariation: true,
typeMatchesSchemaType: true,
// STYLIZE
stylize: true,
smallRangeStepForHighCardinalityOrFacet: {maxCardinality: 10, rangeStep: 12},
nominalColorScaleForHighCardinality: {maxCardinality: 10, palette: 'category20'},
xAxisOnTopForHighYCardinalityWithoutColumn: {maxCardinality: 30},
// RANKING PREFERENCE
maxGoodCardinalityForFacet: 5, // FIXME: revise
maxGoodCardinalityForColor: 7, // FIXME: revise
// HIGH CARDINALITY STRINGS
minPercentUniqueForKey: 0.8,
minCardinalityForKey: 50,
};
export function extendConfig(opt: QueryConfig) {
return {
...DEFAULT_QUERY_CONFIG,
...opt,
enum: extendEnumIndex(opt.enum),
};
}
function extendEnumIndex(enumIndex: Partial<EnumIndex>) {
const enumOpt: EnumIndex = {
...DEFAULT_ENUM_INDEX,
...enumIndex,
binProps: extendNestedEnumIndex(enumIndex, 'bin'),
scaleProps: extendNestedEnumIndex(enumIndex, 'scale'),
axisProps: extendNestedEnumIndex(enumIndex, 'axis'),
legendProps: extendNestedEnumIndex(enumIndex, 'legend'),
};
return enumOpt;
}
function extendNestedEnumIndex(enumIndex: Partial<EnumIndex>, prop: 'bin' | 'scale' | 'axis' | 'legend') {
return {
...DEFAULT_ENUM_INDEX[`${prop}Props`],
...enumIndex[`${prop}Props`],
};
}