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

[partition] Centering labels in partitions #2195

Open
Tracked by #2128
chao813 opened this issue Oct 12, 2023 · 3 comments
Open
Tracked by #2128

[partition] Centering labels in partitions #2195

chao813 opened this issue Oct 12, 2023 · 3 comments

Comments

@chao813
Copy link

chao813 commented Oct 12, 2023

Is there a way to center the fill labels in the partitions? I've been looking at the PartialTheme FillLabelConfig but can't find a way to center the labels.

Expected:
image

Current:
image

@nickofthyme
Copy link
Collaborator

nickofthyme commented Oct 13, 2023

Hey @chao813 unfortunately no, and I don't see a real workaround to this as it currently stands.

There is an issue open here #2128 to improve the current label positioning/sizing for partition charts. I think this would be a good case to add when there is a full circle.

@chao813
Copy link
Author

chao813 commented Oct 13, 2023

Hi @nickofthyme, what does the padding in the fillLabel do then?

partition: { fillLabel: { padding: { top: 100, bottom: 100, left: 100, right: 100 }, } }

@nickofthyme
Copy link
Collaborator

nickofthyme commented Oct 13, 2023

Strangely nothing 🤔

After testing and seeing no affect I dug into the code and found the padding is only passed to the getSectorRowGeometry function, shown below, but the function definition is actually missing two parameters from the GetShapeRowGeometry function type signature after the rotation param, one of which is the padding.

So it's passed in but never accounted for. This is definitely a bug I'll open up a new issue for this to be address alongside #2128 and this centering issue.

export const getSectorRowGeometry: GetShapeRowGeometry<RingSectorConstruction> = (
ringSector,
cx,
cy,
totalRowCount,
linePitch,
rowIndex,
fontSize,
rotation,
) => {
const offset = (totalRowCount / 2) * fontSize + fontSize / 2 - linePitch * rowIndex;
const topCircline = makeRowCircline(cx, cy, offset, rotation, fontSize, 1);
const bottomCircline = makeRowCircline(cx, cy, offset, rotation, fontSize, -1);
const midCircline = makeRowCircline(cx, cy, offset, rotation, 0, 0);
const valid1 = conjunctiveConstraint(ringSector, { ...topCircline, from: 0, to: TAU })[0];
if (!valid1) return { rowAnchorX: cx, rowAnchorY: cy, maximumRowLength: 0 };
const valid2 = conjunctiveConstraint(ringSector, { ...bottomCircline, from: 0, to: TAU })[0];
if (!valid2) return { rowAnchorX: cx, rowAnchorY: cy, maximumRowLength: 0 };
const from = Math.max(valid1.from, valid2.from);
const to = Math.min(valid1.to, valid2.to);
const midAngle = (from + to) / 2;
const cheapTangent = Math.max(0, to - from); /* Math.tan(Math.max(0, to - from)) */ // https://en.wikipedia.org/wiki/Small-angle_approximation
const rowAnchorX = midCircline.r * Math.cos(midAngle) + midCircline.x;
const rowAnchorY = midCircline.r * Math.sin(midAngle) + midCircline.y;
const maximumRowLength = cheapTangent * INFINITY_RADIUS;
return { rowAnchorX, rowAnchorY, maximumRowLength };
};

But this code is original to the partition chart implementation 3 years ago and hasn't been touched since.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants