提交 60ebda52 编写于 作者: L lang

Label enhancement

上级 830889d9
......@@ -37,26 +37,19 @@ define(function(require) {
barGap: '30%',
// 类目间柱形距离,默认为类目间距的20%,可设固定值
barCategoryGap: '20%',
label: {
normal: {
show: false
// formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
// label: {
// normal: {
// show: false
// formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
// 默认自适应,水平布局为'top',垂直布局为'right',可选为
// 'inside' | 'insideleft' | 'insideTop' | 'insideRight' | 'insideBottom' |
// 'outside' |'left' | 'right'|'top'|'bottom'
// position:
// // 默认自适应,水平布局为'top',垂直布局为'right',可选为
// // 'inside' | 'insideleft' | 'insideTop' | 'insideRight' | 'insideBottom' |
// // 'outside' |'left' | 'right'|'top'|'bottom'
// position:
// textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
},
emphasis: {
show: true
// formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
// position: 默认自适应,水平布局为'top',垂直布局为'right',可选为
// 'inside'|'left'|'right'|'top'|'bottom'
// textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
}
},
// textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
// }
// },
itemStyle: {
normal: {
// color: '各异',
......
......@@ -97,6 +97,14 @@ define(function (require) {
},
_updateStyle: function (seriesModel, data, isHorizontal) {
function setLabel(style, model, color, labelText, labelPositionOutside) {
graphic.setText(style, model, color);
style.text = labelText;
if (style.textPosition === 'outside') {
style.textPosition = labelPositionOutside;
}
}
data.eachItemGraphicEl(function (rect, idx) {
var itemModel = data.getItemModel(idx);
var labelModel = itemModel.getModel('label.normal');
......@@ -121,22 +129,19 @@ define(function (require) {
var labelText = seriesModel.getFormattedLabel(idx, 'normal')
|| data.getRawValue(idx);
var rectStyle = rect.style;
if (labelModel.get('show')) {
graphic.setText(rectStyle, labelModel, color);
rectStyle.text = labelText;
if (rectStyle.textPosition === 'outside') {
rectStyle.textPosition = labelPositionOutside;
}
var showLabel = labelModel.get('show');
if (showLabel) {
setLabel(
rectStyle, labelModel, color, labelText, labelPositionOutside
);
}
else {
rectStyle.text = '';
}
if (hoverLabelModel.get('show')) {
graphic.setText(hoverStyle, hoverLabelModel, color);
hoverStyle.text = labelText;
if (hoverStyle.textPosition === 'outside') {
hoverStyle.textPosition = labelPositionOutside;
}
if (zrUtil.retrieve(hoverLabelModel.get('show'), showLabel)) {
setLabel(
hoverStyle, hoverLabelModel, color, labelText, labelPositionOutside
);
}
else {
hoverStyle.text = '';
......
......@@ -179,14 +179,16 @@ define(function (require) {
var labelText = seriesModel.getFormattedLabel(idx, 'normal')
|| data.get(lastDim, idx);
var elStyle = el.style;
if (labelModel.get('show')) {
var showLabel = labelModel.get('show');
if (showLabel) {
graphic.setText(elStyle, labelModel, color);
elStyle.text = labelText;
}
else {
elStyle.text = '';
}
if (hoverLabelModel.get('show')) {
if (zrUtil.retrieve(hoverLabelModel.get('show'), showLabel)) {
graphic.setText(hoverStyle, hoverLabelModel, color);
hoverStyle.text = labelText;
}
......
......@@ -37,18 +37,15 @@ define(function (require) {
symbolSize: 10, // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
// symbolRotate: null, // 图形旋转控制
label: {
normal: {
show: false
// label: {
// normal: {
// show: false
// formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
// position: 默认自适应,水平布局为'top',垂直布局为'right',可选为
// 'inside'|'left'|'right'|'top'|'bottom'
// textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
},
emphasis: {
show: true
}
},
// }
// },
itemStyle: {
normal: {
opacity: 0.8
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册