Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pie): two new alignTo layouts #11715

Merged
merged 10 commits into from
Nov 28, 2019
3 changes: 2 additions & 1 deletion src/chart/pie/PieSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ var PieSeries = echarts.extendSeriesModel({
alignTo: 'none',
// Closest distance between label and chart edge.
// Works only position is 'outer' and alignTo is 'labelLine' or 'edge'.
margin: '20%',
margin: '25%',
bleedMargin: 10,
distanceToLabelLine: 5,
// formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
// 默认使用全局文本样式,详见TEXTSTYLE
Expand Down
9 changes: 5 additions & 4 deletions src/chart/pie/labelLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLef
}
else {
if (layout.x < cx) {
targetTextWidth = layout.x - viewLeft - layout.labelMargin;
targetTextWidth = layout.x - viewLeft - layout.bleedingMargin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bleedingMargin should be bleedMargin?

}
else {
targetTextWidth = viewLeft + viewWidth - layout.x - layout.labelMargin;
targetTextWidth = viewLeft + viewWidth - layout.x - layout.bleedingMargin;
}
}
if (targetTextWidth < layout.textRect.width) {
Expand Down Expand Up @@ -228,7 +228,6 @@ export default function (seriesModel, r, viewWidth, viewHeight, viewLeft, viewTo
var cy;
var hasLabelRotate = false;
var minShowLabelRadian = (seriesModel.get('minShowLabelAngle') || 0) * RADIAN;
var viewSize = Math.min(viewWidth, viewHeight);

data.each(function (idx) {
var layout = data.getItemLayout(idx);
Expand All @@ -239,7 +238,8 @@ export default function (seriesModel, r, viewWidth, viewHeight, viewLeft, viewTo
var labelPosition = labelModel.get('position') || itemModel.get('emphasis.label.position');
var labelDistance = labelModel.get('distanceToLabelLine');
var labelAlignTo = labelModel.get('alignTo');
var labelMargin = parsePercent(labelModel.get('margin'), viewSize);
var labelMargin = parsePercent(labelModel.get('margin'), viewWidth);
var bleedingMargin = labelModel.get('bleedMargin');
var font = labelModel.getFont();

var labelLineModel = itemModel.getModel('labelLine');
Expand Down Expand Up @@ -337,6 +337,7 @@ export default function (seriesModel, r, viewWidth, viewHeight, viewLeft, viewTo
labelDistance: labelDistance,
labelAlignTo: labelAlignTo,
labelMargin:labelMargin,
bleedingMargin: bleedingMargin,
textRect: textRect,
text: text,
font: font
Expand Down
5 changes: 1 addition & 4 deletions test/media-pie.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@
{value:35, name:'rose6'},
{value:30, name:'rose7'},
{value:40, name:'rose8'}
],
label: {
margin: 10
}
]
}
]
},
Expand Down