const { uniqBy, concat, filter, get } = require('lodash'); /** * 函数标识 * 用于标识函数做最后的解析 * @type {string} */ const SIGN = '-FN-'; /** * 图表类型 * @enum {string[]} */ const SHAPES = [ 'interval', 'line', 'point', 'area', 'polygon', 'edge', 'schema', 'heatmap', 'path', 'pointStack', 'link', 'treemap', 'facetRect', 'lineX', 'lineY', 'geoPath', 'text', 'connector', 'density', 'rect', 'boxplot', 'legends', 'cell', ]; const ENCODE_MAP = { 'encode.x': 'xField', 'encode.y': 'yField', 'encode.color': 'colorField', 'encode.shape': 'shapeField', 'encode.size': 'sizeField', 'encode.key': 'keyField', 'encode.series': 'seriesField', 'encode.position': 'positionField', 'encode.text': 'textField', 'encode.value': 'valueField', 'encode.src': 'srcField', 'encode.linkColor': 'linkColorField', 'encode.fontSize': 'fontSizeField', 'encode.bin': 'binField', }; /** * 处理流程 * @enum {string[]} */ const PIPELINE = [ { key: 'data' }, { key: 'encode' }, { key: 'axis' }, { key: 'legend' }, { key: 'interaction' }, { key: 'style' }, { key: 'state' }, { key: 'viewStyle' }, { key: 'call' }, { key: 'attr' }, { key: 'scale' }, { key: 'animate' }, { key: 'coordinate' }, { key: 'layout' }, { key: 'tooltip', callback: (origin, value) => { if (!value) { origin['tooltip'] = value; } else { origin['tooltip'] = { items: filter(concat(get(origin, ['tooltip', 'items']), value), Boolean), }; } }, }, { key: 'label', callback: (origin, value) => { origin['labels'] = filter(concat(origin['labels'], value), Boolean); }, }, { key: 'transform', callback: (origin, value) => { origin['transform'] = uniqBy(filter(concat(origin['transform'], value), Boolean), 'type'); }, }, ]; module.exports = { SIGN, SHAPES, PIPELINE, ENCODE_MAP, };