Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
each(subItems, (v) => {
// tslint:disable-next-line: no-shadowed-variable
let point = v.point;
if (!isNil(point) && !isNil(point.x) && !isNil(point.y)) {
const x = isArray(point.x) ? point.x[point.x.length - 1] : point.x;
const y = isArray(point.y) ? point.y[point.y.length - 1] : point.y;
point = coord.applyMatrix(x, y, 1);
v.x = point[0];
v.y = point[1];
v.showMarker = true;
const itemMarker = getItemMarker(geom, v.color);
itemMarker.radius = 40;
v.marker = itemMarker;
if (indexOf(TYPE_SHOW_MARKERS, type) !== -1) {
items.push(v);
}
}
});
items.push(...subItems);
}
});
items = items.filter((item) => item.title === nearestItem.title);
markersItems = markersItems.filter((item) => item.title === nearestItem.title);
}
if (options.shared === false && items.length > 1) {
let snapItem = items[0];
let min = Math.abs(point.y - snapItem.y);
_.each(items, (aItem) => {
if (Math.abs(point.y - aItem.y) <= min) {
snapItem = aItem;
min = Math.abs(point.y - aItem.y);
}
});
if (snapItem && !_.isNil(snapItem.x) && !_.isNil(snapItem.y)) {
markersItems = [snapItem];
}
items = [snapItem];
}
this._setTooltip(point, items, markersItems, target);
// 使查找到的数据对应的 shape 处于 active 状态
// 应该在每次出现 tooltip 的时候就 active 对应的 shapes
view.setActive((obj) => {
let result = false;
_.each(items, (item) => {
const origin = item.point._origin;
if (origin === obj) {
result = true;
return false;
}
});
} else {
throw new Error('dodge is not support linear attribute, please use category attribute!');
}
adjustCfg.adjustNames = adjustNames;
// 每个分组内每条柱子的宽度占比,用户不可指定,用户需要通过 columnWidthRatio 指定
adjustCfg.dodgeRatio = this.theme.columnWidthRatio;
} else if (type === 'stack') {
const coordinate = this.coordinate;
if (!yScale) {
// 一维的情况下获取高度和默认size
adjustCfg.height = coordinate.getHeight();
const size = this.getDefaultValue('size') || 3;
adjustCfg.size = size;
}
// 不进行 transpose 时,用户又没有设置这个参数时,默认从上向下
if (!coordinate.isTransposed && _.isNil(adjustCfg.reverseOrder)) {
adjustCfg.reverseOrder = true;
}
}
const adjustCtor = getAdjust(type);
const adjustInstance = new adjustCtor(adjustCfg);
result = adjustInstance.process(result);
if (type === 'stack' && yScale) {
this._updateStackRange(yField, yScale, result);
}
this.adjusts[type] = adjustInstance;
});
}
if (color) {
if (isStroke) {
if (!get(style, 'stroke')) {
// 如果用户在 style() 中配置了 stroke,则以用户配置的为准
attrs.stroke = color;
}
}
if (isFill) {
if (!get(style, 'fill')) {
// 如果用户在 style() 中配置了 fill
attrs.fill = color;
}
}
}
if (sizeName && isNil(get(style, sizeName)) && !isNil(size)) {
// 如果用户在 style() 中配置了 lineWidth 或者 r 属性
attrs[sizeName] = size;
}
return attrs;
}
function addItem(itemName, itemValue) {
if (!isNil(itemValue) && itemValue !== '') {
// 值为 null的时候,忽视
const item = {
title: tooltipTitle,
data: originData, // 原始数据
mappingData: data, // 映射后的数据
name: itemName || tooltipTitle,
value: itemValue,
color: data.color || defaultColor,
marker: true,
};
items.push(item);
}
}
private _convertPoint(mappedRecord: MappedRecord) {
const { x, y } = mappedRecord;
if (_.isNil(x) || _.isNil(y)) {
return;
}
let rstX;
let rstY;
let obj;
const coordinate = this.coordinate;
if (_.isArray(y) && _.isArray(x)) {
rstX = [];
rstY = [];
for (let i = 0, j = 0, xLen = x.length, yLen = y.length; i < xLen && j < yLen; i += 1, j += 1) {
obj = coordinate.convertPoint({
x: x[i],
y: y[j],
});
rstX.push(obj.x);
function fadeIn(shape, animateCfg) {
const fillOpacity = _.isNil(shape.attr('fillOpacity')) ? 1 : shape.attr('fillOpacity');
const strokeOpacity = _.isNil(shape.attr('strokeOpacity')) ? 1 : shape.attr('strokeOpacity');
shape.attr('fillOpacity', 0);
shape.attr('strokeOpacity', 0);
const endState = {
fillOpacity,
strokeOpacity,
};
doAnimation(shape, endState, animateCfg);
}
constructor(container: HTMLElement, props: T) {
super();
this.containerDOM = typeof container === 'string' ? document.getElementById(container) : container;
this.forceFit = !_.isNil(props.forceFit) ? props.forceFit : _.isNil(props.width) && _.isNil(props.height);
this.renderer = props.renderer || 'canvas';
this.pixelRatio = props.pixelRatio || null;
this.width = props.width;
this.height = props.height;
this.theme = props.theme;
this.canvasController = new CanvasController({
containerDOM: this.containerDOM,
plot: this,
});
/** update layer properties */
this.width = this.canvasController.width;
this.height = this.canvasController.height;
this.canvas = this.canvasController.canvas;
this.layers = [];
this.destroyed = false;
getSideVector(offset, point) {
const center = this.get('center');
const vector = [ point.x - center.x, point.y - center.y ];
if (!Util.isNil(offset)) {
const vecLen = vec2.length(vector);
vec2.scale(vector, vector, offset / vecLen);
}
return vector;
}