Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private getLabelConfig(region, labelOptions, index) {
let x = 0;
let y = 0;
let style: any = {};
let text = labelOptions.text;
if (isFunction(text)) {
text = text(region);
} else if (isArray(text)) {
text = text[index];
}
const { position } = labelOptions;
const pos = position.split('-');
const dim = region.name.split('-');
// x方向
if (dim[1] === 'left') {
if (pos[0] === 'inner') {
x = region.bbox.maxX - labelOptions.offset;
style.textAlign = 'right';
}
if (pos[0] === 'outter') {
x = region.bbox.minX + labelOptions.offset;
style.textAlign = 'left';
private _gridParser() {
const { grid: gridCfg } = this.localProps;
const { style } = gridCfg;
if (_.isFunction(style)) {
// @see g2/component/src/axis/base:_renderGrid
this.config.grid = (text: string, index: number, count: number) => {
const cfg = style(text, index, count);
return _.deepMix({}, _.get(this.themeConfig, `grid.style`), cfg);
};
} else if (style) {
this.config.grid = style;
this.applyThemeConfig('grid');
}
}
Util.each(items, (item: CommonCfg, index: number) => {
const checked = item.checked;
const value = this.formatterValue(item.value); // 按照 formatter 配置格式化文本
const originColor = item.marker.fill || item.marker.stroke;
const color = checked ? originColor : unSelectedColor;
let itemDom;
if (Util.isFunction(itemTpl)) {
// 用户声明了回调
const domStr = itemTpl(value, color, checked, index);
itemDom = domUtil.createDom(domStr);
} else {
itemDom = domUtil.createDom(itemTpl);
const textDom = _findNodeByClass(itemDom, `${prefixClassName}-item-text`);
textDom.innerHTML = value;
}
itemStyle.color = color; // 设置为当前状态对应的文本颜色
markerStyle.backgroundColor = color; // 设置为当前状态 marker 的背景色
domUtil.modifyCSS(itemDom, itemStyle);
itemDom.setAttribute('data-checked', checked); // 存储当前的选中状态
itemDom.setAttribute('data-value', item.value); // 存储 item 的原始值
itemDom.setAttribute('data-color', originColor); // 存储 item 的原始颜色
public parseColor() {
const props = this.plot.options;
const config: DataPointType = {};
const colorMappingField = this._getColorMappingField();
if (colorMappingField) {
config.fields = colorMappingField;
}
if (_.has(props, 'color')) {
const color = props.color;
if (_.isString(color)) {
config.values = [color];
} else if (_.isFunction(color)) {
config.callback = color;
} else {
config.values = color as [];
}
}
this.config.color = config;
}
const labelProps = this.originConfig;
const theme = this.plot.getPlotTheme();
const config: DataPointType = { ...labelProps };
this._parseOffset(labelProps, config);
if (labelProps.position) {
if (_.isFunction(labelProps.position)) {
config.position = labelProps.position(val);
} else {
config.position = labelProps.position;
}
}
if (labelProps.formatter) {
config.formatter = labelProps.formatter;
}
if (labelProps.style) {
if (_.isFunction(labelProps.style)) {
config.textStyle = labelProps.style(val);
} else {
config.textStyle = labelProps.style;
}
}
config.textStyle = _.deepMix({}, _.get(theme, 'label.style'), config.textStyle);
if (labelProps.autoRotate) {
config.autoRotate = labelProps.autoRotate;
}
return config;
}
public setLabelPosition(point, originPoint, index, originPosition) {
let position = originPosition;
if (_.isFunction(position)) {
position = position(originPoint);
}
const coord = this.get('coord');
const point0 = coord.convertPoint(originPoint.points[0]);
const point1 = coord.convertPoint(originPoint.points[2]);
const width = (point0.x - point1.x) / 2;
const height = (point0.y - point1.y) / 2;
switch (position) {
case 'right':
point.x -= width;
point.y += height;
point.textAlign = point.textAlign || 'left';
break;
case 'left':
point.x += width;
export function getAnimateParam(animateCfg, index, id) {
return {
delay: _.isFunction(animateCfg.delay) ? animateCfg.delay(index, id) : animateCfg.delay,
easing: _.isFunction(animateCfg.easing) ? animateCfg.easing(index, id) : animateCfg.easing,
duration: _.isFunction(animateCfg.duration) ? animateCfg.duration(index, id) : animateCfg.duration,
callback: animateCfg.callback,
};
}
private _parseColor(props, config) {
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;
}
}
}
shape.setSilent('animating', true);
animateCfg.callback = () => {
if (shape && !shape.get('destroyed')) {
shape.attr('clip', null);
shape.setSilent('cacheShape', null);
shape.setSilent('animating', false);
clip.remove();
if (direction === 'antiClockWise') {
shape.attr('path', path);
}
}
};
/** 执行动画 */
/** 准备动画参数 */
let delay = animateCfg.delay;
if (_.isFunction(delay)) {
delay = animateCfg.delay(index);
}
let easing = animateCfg.easing;
if (_.isFunction(easing)) {
easing = animateCfg.easing(index);
}
/** 动起来 */
clip.animate(uniform, animateCfg.duration, easing, animateCfg.callback, delay);
}
setShapeInfo(shape, startAngle, endAngle);
}
export function compare(origin, condition) {
if (!_.isFunction(condition)) {
const { name, exp } = condition;
if (_.isFunction(exp)) {
return exp(origin[name]);
}
return origin[name] === exp;
}
return condition(origin);
}