-
Notifications
You must be signed in to change notification settings - Fork 19.6k
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): support align to edge and labelLine mode #11381 #11632
Conversation
The demo works great, good job! Will review the code closely later. About the configuration design, |
Sure. I will update the name after your review. |
src/chart/pie/labelLayout.js
Outdated
@@ -164,25 +231,38 @@ export default function (seriesModel, r, viewWidth, viewHeight, sum) { | |||
var hasLabelRotate = false; | |||
var minShowLabelRadian = (seriesModel.get('minShowLabelAngle') || 0) * RADIAN; | |||
|
|||
var seriesLabelModel = seriesModel.getModel('label'); | |||
var edgeMargin = seriesLabelModel.get('edgeMargin'); | |||
edgeMargin = parsePercent(edgeMargin, viewWidth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edgeMargin
in the outer scope is not used.
// Closest distance between label and chart edge. | ||
// Works only position is 'outer' and alignTo is 'labelLine' or 'edge'. | ||
edgeMargin: 20, | ||
padding: 3, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra comma here
chart1.setOption(option1); | ||
}); | ||
}); | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add another parameter to test edgeMargin
? Also it will be great to record an interaction for testing.
(1)In the (2)I have test this case: more than one pie charts in one echarts instance. function makeData() {
var count = 10;
var data = [];
var text = '';
for (var i = 0; i < count; i++) {
text += 'X';
data.push({
name: text + i,
value: Math.random()
});
}
return data;
}
var option0 = {
series: [{
type: 'pie',
radius: '25%',
center: ['25%', '50%'],
data: makeData(),
// animation: false,
labelLine: {
minLength2: 50,
maxLength2: 10
},
label: {
// edgeMargin: 20,
position: 'outer',
alignTo: 'edge',
padding: 5
}
}, {
type: 'pie',
radius: '25%',
center: ['75%', '50%'],
data: makeData(),
// animation: false,
labelLine: {
minLength2: 50,
maxLength2: 10
},
label: {
// edgeMargin: 20,
position: 'outer',
alignTo: 'labelLine',
padding: 5
}
}]
}; The result seams buggy. (3)I am not sure about the config |
@100pah (1) is not bug. It's because |
This PR is abandoned. New PR is #11715. |
feat(pie): support align to edge and labelLine mode #11381
Problem and solution
In this PR, I proposed two new layouts for pie labels, aka aligning labels to
'lableLine'
or'edge'
.The default pie label layout may seem to be a little unorganized and not so beautiful, especially on devices with smaller resolutions.
Before:
After (two new layouts proposed):
API changes
The following are new options in this PR:
The priority of
edgeMargin
is the highest. It is used to restrict text and label lines cannot go outside.maxLength2
andminLength2
are used to restrict the length oflength2
so that it looks well on devices with both small and large resolutions.Result and test
test/pie-alignTo.html
provides test cases with differentminLength2
andmaxLength2
.Limitations and todo
textAlign
is calculated from whether it's on the left or right side and cannot be changed by the user. We probably should provide the option to make the text align to the outer sides or the inner sides.