Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private getTooltipCfg() {
const view = this.view;
const option = this.option;
const theme = view.getTheme();
const defaultCfg = get(theme, ['components', 'tooltip'], {});
let tooltipCfg = {
...defaultCfg,
};
if (isObject(option)) {
tooltipCfg = {
...defaultCfg,
...option,
};
}
// set `crosshairs`
const coordinate = view.getCoordinate();
if (tooltipCfg.showCrosshairs && !tooltipCfg.crosshairs && coordinate.isRect) {
// 目前 Tooltip 辅助线只在直角坐标系下展示
tooltipCfg.crosshairs = !!coordinate.isTransposed ? 'y' : 'x';
}
if (tooltipCfg.showCrosshairs === false) {
tooltipCfg.crosshairs = null;
}
each(option, (value, name) => {
const originCfg = this.get(name);
let newCfg = value;
if (originCfg !== value) {
// 判断两者是否相等,主要是进行 null 的判定
if (isObject(value) && defaultCfg[name]) {
// 新设置的属性与默认值进行合并
newCfg = deepMix({}, defaultCfg[name], value);
}
this.set(name, newCfg);
}
});
private addCustomLegend(field?: string): Legend {
const viewTheme = this.theme;
const view = this.view;
const container = this.container.addGroup({ name: 'legend' });
const canvas = container.get('canvas');
const panelRange = this.panelRange;
const legendOptions = this.options as LegendsOption;
let fieldOption;
if (_.isObject(legendOptions)) {
fieldOption = legendOptions.fields ? (legendOptions.fields[field] as LegendOption) : {};
}
let position = fieldOption.position || legendOptions.position || viewTheme.defaultLegendPosition;
position = this.adjustPosition(position);
const items = fieldOption.items || legendOptions.items;
if (!items) {
return;
}
_.each(items, (item: any) => {
if (!_.isPlainObject(item.marker)) {
// 直接传入字符串或者回调函数时转换为对象,如 item.marker = 'circle'
item.marker = {
symbol: item.marker || 'circle',
radius: MARKER_SIZE,
};
if (_.contains(STROKE_MARKERS, item.marker.symbol)) {
private _createAttrOption(attrName: string, field: AttributeOption | string | number, cfg?) {
if (_.isObject(field)) {
this._setAttrOptions(attrName, field);
} else {
const attrCfg: AttributeOption = {};
if (_.isNumber(field)) {
// size(3)
attrCfg.values = [field];
} else {
attrCfg.fields = parseFields(field);
}
if (cfg) {
if (_.isFunction(cfg)) {
attrCfg.callback = cfg;
} else {
attrCfg.values = cfg;
}
export function mergeTheme(themeObject: object, theme: string | object): object {
const newThemeObject: object = isObject(theme) ? theme : getTheme(theme);
return deepMix(themeObject, newThemeObject);
}
public parseColor() {
const props = this.plot.options;
const colorField = this._getColorMappingField(props);
const config: DataPointType = {};
if (colorField) {
config.fields = colorField;
}
if (props.color) {
if (_.isString(props.color)) {
config.values = [props.color];
} else if (_.isFunction(props.color)) {
config.callback = props.color;
} else if (_.isArray(props.color)) {
config.values = props.color;
} else if (_.isObject(props.color)) {
config.fields = colorField;
config.callback = (d) => {
return props.color[d];
};
}
}
this.config.color = config;
}
_.each(adjusts, (adjust, index) => {
if (!_.isObject(adjust)) {
adjusts[index] = { type: adjust };
}
});
function beforeCompare(label, condition) {
const labelData = { [label.scaleField]: label.value };
const con = _.clone(condition);
if (label.type === 'time' && _.isObject(condition) && !_.isFunction(con.exp)) {
con.exp = new Date(con.exp).getTime();
}
return { labelData, con };
}
each(geom.elements, (el: Element) => {
const data = el.getModel().data;
let value;
if (isObject(data)) {
value = data[field];
} else if (isArray(data)) {
value = data[0][field];
}
if (!isNil(value) && item.name === scale.getText(value)) {
element.setState('active', enable);
}
});
});