本文整理汇总了TypeScript中compassql/build/src/model.getTopSpecQueryItem函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getTopSpecQueryItem函数的具体用法?TypeScript getTopSpecQueryItem怎么用?TypeScript getTopSpecQueryItem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getTopSpecQueryItem函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('converts SpecQueryGroup<SpecQueryModel> to SpecQueryGroup<PlotObject>', () => {
const group = buildSpecQueryModelGroup([
{
mark: Mark.BAR,
encodings: [
{channel: Channel.X}
]
}
]);
const data = {url: 'a/data/set.csv'};
const plotObjectGroup = convertToPlotObjectsGroup(group, data);
// should have a spec
expect(getTopSpecQueryItem(plotObjectGroup).spec).toEqual(
{
data: { url: 'a/data/set.csv' },
mark: 'bar',
encoding: { x: {} },
config:
{
overlay: { line: true },
scale: { useUnaggregatedDomain: true }
}
});
});
示例2: getTopSpecQueryItem
return modelGroup.items.map(item => {
if (isSpecQueryGroup<PlotObject>(item)) {
const childModelGroup = item as SpecQueryGroup<PlotObject>;
return getTopSpecQueryItem(childModelGroup);
}
return item as PlotObject;
});
示例3: plotObject
const items = modelGroup.items.map(item => {
if (isSpecQueryGroup<SpecQueryModel>(item)) {
const childModelGroup = item as SpecQueryModelGroup;
return plotObject(data, getTopSpecQueryItem(childModelGroup));
}
// FIXME: include data in the main spec?
return plotObject(data, item as SpecQueryModel);
});
示例4: shelfSpecReducer
export function shelfSpecReducer(shelfSpec: Readonly<ShelfUnitSpec> = DEFAULT_SHELF_UNIT_SPEC,
action: Action,
schema: Schema): ShelfUnitSpec {
switch (action.type) {
case SHELF_CLEAR:
return DEFAULT_SHELF_UNIT_SPEC;
case SHELF_MARK_CHANGE_TYPE: {
const mark = action.payload;
return {
...shelfSpec,
mark
};
}
case SHELF_FIELD_ADD: {
const {shelfId, fieldDef} = action.payload;
return addEncoding(shelfSpec, shelfId, fieldDef);
}
case SHELF_FIELD_AUTO_ADD: {
const {fieldDef} = action.payload;
if (shelfSpec.anyEncodings.length > 0 || isWildcard(fieldDef.field)) {
// If there was an encoding shelf or if the field is a wildcard, just add to wildcard shelf
return {
...shelfSpec,
anyEncodings: [
...shelfSpec.anyEncodings,
{
channel: SHORT_WILDCARD,
...fieldDef
}
]
};
} else {
// Otherwise, query for the best encoding if there is no wildcard channel
const query = autoAddFieldQuery(shelfSpec, fieldDef);
const rec = recommend(query, schema);
const topSpecQuery = getTopSpecQueryItem(rec.result).specQuery;
return {
...fromSpecQuery(topSpecQuery, shelfSpec.config),
// retain auto-mark if mark is previously auto
...(isWildcard(shelfSpec.mark) ? {mark: shelfSpec.mark} : {})
};
}
}
case SHELF_FIELD_REMOVE:
return removeEncoding(shelfSpec, action.payload).shelf;
case SHELF_FIELD_MOVE: {
const {to, from} = action.payload;
const {fieldDef: fieldDefFrom, shelf: removedShelf1} = removeEncoding(shelfSpec, from);
const {fieldDef: fieldDefTo, shelf: removedShelf2} = removeEncoding(removedShelf1, to);
const addedShelf1 = addEncoding(removedShelf2, to, fieldDefFrom);
const addedShelf2 = addEncoding(addedShelf1, from, fieldDefTo);
return addedShelf2;
}
case SHELF_FUNCTION_CHANGE: {
const {shelfId, fn} = action.payload;
return modifyEncoding(shelfSpec, shelfId, (fieldDef: Readonly<ShelfFieldDef | ShelfAnyEncodingDef>) => {
// Remove all existing functions then assign new function
const {aggregate: _a, bin: _b, timeUnit: _t, hasFn: _h, ...newFieldDef} = fieldDef;
return {
...newFieldDef,
...(getFunctionMixins(fn))
};
});
}
case SHELF_SPEC_LOAD:
const {spec} = action.payload;
const specQ = isWildcard(shelfSpec.mark) ? {
...fromSpec(spec),
mark: SHORT_WILDCARD
} : fromSpec(spec);
// Restore wildcard mark if the shelf previously has wildcard mark.
return fromSpecQuery(specQ, shelfSpec.config);
}
return shelfSpec;
}