Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export interface SupportedChannelMap {
[mark: string]: {
[channel: string]: boolean;
};
}
/**
* Supported Encoding Channel for each mark type
*/
export const DEFAULT_SUPPORTED_CHANNEL_TYPE: SupportedChannelMap = {
bar: toSet(['row', 'column', 'x', 'y', 'size', 'color', 'fill', 'stroke', 'detail']),
line: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'color', 'detail']),
trail: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'color', 'detail', 'size']),
area: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'detail']),
tick: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'detail']),
circle: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'size', 'detail']),
square: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'size', 'detail']),
point: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'size', 'detail', 'shape']),
geoshape: toSet(['row', 'column', 'color', 'fill', 'stroke', 'detail', 'shape']),
text: toSet(['row', 'column', 'size', 'color', 'fill', 'stroke', 'text']) // TODO(#724) revise
};
// TODO: consider if we should add validate method and
// requires ZSchema in the main vega-lite repo
/**
* Further check if encoding mapping of a spec is invalid and
* return error if it is invalid.
*
* This checks if
* (1) all the required encoding channels for the mark type are specified
/**
* Required Encoding Channels for each mark type
*/
export const DEFAULT_REQUIRED_CHANNEL_MAP = {
text: ['text'],
line: ['x', 'y'],
trail: ['x', 'y'],
area: ['x', 'y']
};
/**
* Supported Encoding Channel for each mark type
*/
export const DEFAULT_SUPPORTED_CHANNEL_TYPE = {
bar: toSet(['row', 'column', 'x', 'y', 'size', 'color', 'fill', 'stroke', 'detail']),
line: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'color', 'detail']),
trail: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'color', 'detail', 'size']),
area: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'detail']),
tick: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'detail']),
circle: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'size', 'detail']),
square: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'size', 'detail']),
point: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'size', 'detail', 'shape']),
geoshape: toSet(['row', 'column', 'color', 'fill', 'stroke', 'detail', 'shape']),
text: toSet(['row', 'column', 'size', 'color', 'fill', 'stroke', 'text']) // TODO(#724) revise
};
// TODO: consider if we should add validate method and
// requires ZSchema in the main vega-lite repo
/**
* Further check if encoding mapping of a spec is invalid and
* return error if it is invalid.
*
* This checks if
* (1) all the required encoding channels for the mark type are specified
};
}
/**
* Supported Encoding Channel for each mark type
*/
export const DEFAULT_SUPPORTED_CHANNEL_TYPE: SupportedChannelMap = {
bar: toSet(['row', 'column', 'x', 'y', 'size', 'color', 'fill', 'stroke', 'detail']),
line: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'color', 'detail']),
trail: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'color', 'detail', 'size']),
area: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'detail']),
tick: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'detail']),
circle: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'size', 'detail']),
square: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'size', 'detail']),
point: toSet(['row', 'column', 'x', 'y', 'color', 'fill', 'stroke', 'size', 'detail', 'shape']),
geoshape: toSet(['row', 'column', 'color', 'fill', 'stroke', 'detail', 'shape']),
text: toSet(['row', 'column', 'size', 'color', 'fill', 'stroke', 'text']) // TODO(#724) revise
};
// TODO: consider if we should add validate method and
// requires ZSchema in the main vega-lite repo
/**
* Further check if encoding mapping of a spec is invalid and
* return error if it is invalid.
*
* This checks if
* (1) all the required encoding channels for the mark type are specified
* (2) all the specified encoding channels are supported by the mark type
* @param {[type]} spec [description]
* @param {RequiredChannelMap = DefaultRequiredChannelMap} requiredChannelMap
* @param {SupportedChannelMap = DefaultSupportedChannelMap} supportedChannelMap
SPEC_FUNCTION_ADD_WILDCARD,
SPEC_FUNCTION_DISABLE_WILDCARD,
SPEC_FUNCTION_ENABLE_WILDCARD,
SPEC_FUNCTION_REMOVE_WILDCARD,
SPEC_LOAD,
SPEC_VALUE_CHANGE,
// Tab Actions
TAB_ADD,
TAB_SWITCH,
TAB_REMOVE,
TAB_TITLE_UPDATE
];
export const USER_ACTION_INDEX: Object = toSet(USER_ACTIONS);
/**
* Actions that are to be grouped with actions that precede them. (Usually for async actions.)
*/
export const GROUPED_ACTIONS: ActionType[] = [
DATASET_RECEIVE // Should be grouped with DATASET_REQUEST
];
let _groupId = 0;
function getNextGroupId(): number {
_groupId += 1;
return _groupId;
}
function groupAction(action: Action, currentState: UndoableStateBase,
export default function(opt) {
opt = opt || {};
var whitelist = opt.whitelist ? toSet(opt.whitelist) : {},
blacklist = opt.blacklist ? toSet(opt.blacklist) : {},
constants = opt.constants || Constants,
functions = (opt.functions || Functions)(visit),
globalvar = opt.globalvar,
fieldvar = opt.fieldvar,
globals = {},
fields = {},
memberDepth = 0;
var outputGlobal = isFunction(globalvar)
? globalvar
: function (id) { return globalvar + '["' + id + '"]'; };
function visit(ast) {
if (isString(ast)) return ast;
var generator = Generators[ast.type];
if (generator == null) error('Unsupported type: ' + ast.type);
function create(type, constructor, metadata) {
const ctr = function scale() {
var s = constructor();
if (!s.invertRange) {
s.invertRange = s.invert ? invertRange(s)
: s.invertExtent ? invertRangeExtent(s)
: undefined;
}
s.type = type;
return s;
};
ctr.metadata = toSet(array(metadata));
return ctr;
}
ordinal: 0,
'bin-ordinal': 0,
quantile: 0,
quantize: 0,
threshold: 0
};
/**
* Return scale categories -- only scale of the same categories can be merged together.
*/
export function scaleTypePrecedence(scaleType: ScaleType): number {
return SCALE_PRECEDENCE_INDEX[scaleType];
}
export const CONTINUOUS_TO_CONTINUOUS_SCALES: ScaleType[] = ['linear', 'log', 'pow', 'sqrt', 'symlog', 'time', 'utc'];
const CONTINUOUS_TO_CONTINUOUS_INDEX = toSet(CONTINUOUS_TO_CONTINUOUS_SCALES);
export const QUANTITATIVE_SCALES: ScaleType[] = ['linear', 'log', 'pow', 'sqrt', 'symlog'];
export const CONTINUOUS_TO_DISCRETE_SCALES: ScaleType[] = ['quantile', 'quantize', 'threshold'];
const CONTINUOUS_TO_DISCRETE_INDEX = toSet(CONTINUOUS_TO_DISCRETE_SCALES);
export const CONTINUOUS_DOMAIN_SCALES: ScaleType[] = CONTINUOUS_TO_CONTINUOUS_SCALES.concat([
'quantile',
'quantize',
'threshold'
]);
const CONTINUOUS_DOMAIN_INDEX = toSet(CONTINUOUS_DOMAIN_SCALES);
export const DISCRETE_DOMAIN_SCALES: ScaleType[] = ['ordinal', 'bin-ordinal', 'point', 'band'];
const DISCRETE_DOMAIN_INDEX = toSet(DISCRETE_DOMAIN_SCALES);
keys.forEach(k => {
if (isArray(obj[k])) obj[k] = toSet(obj[k]);
});
};