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

fix: make labels take up less pie chart space #23

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/hooks/useShapes/area/prepare-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ export const prepareAreaData = (args: {
const labelItems = points.map<LabelData>((p) => getLabelData(p, s, xMax));
if (s.dataLabels.html) {
const htmlLabels = labelItems.map((l) => {
const style = l.style ?? s.dataLabels.style;
const labelSize = getLabelsSize({labels: [l.text], style, html: true});

return {
x: l.x - l.size.width / 2,
y: l.y,
content: l.text,
size: {width: labelSize.maxWidth, height: labelSize.maxHeight},
};
});
htmlElements.push(...htmlLabels);
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useShapes/bar-x/prepare-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export const prepareBarXData = (args: {
x: label.x,
y: label.y,
content: label.text,
size: label.size,
});
} else {
barData.label = getLabelData(barData);
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useShapes/bar-y/prepare-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function setLabel(prepared: PreparedBarYData) {
x,
y: y - height / 2,
content,
size: {width, height},
});
} else {
prepared.label = {
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useShapes/line/prepare-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function getHtmlLabel(point: PointData, series: PreparedLineSeries, xMax: number
x: Math.min(xMax - size.maxWidth, Math.max(0, point.x)),
y: Math.max(0, point.y - series.dataLabels.padding - size.maxHeight),
content,
size: {width: size.maxWidth, height: size.maxHeight},
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useShapes/pie/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,12 @@ export function PieSeriesShapes(args: PreparePieSeriesArgs) {
};
}, [dispatcher, preparedData, seriesOptions]);

const htmlElements = preparedData.map((d) => d.htmlLabels).flat();

return (
<React.Fragment>
<g ref={ref} className={b()} style={{zIndex: 9}} />
<HtmlLayer preparedData={preparedData} htmlLayout={htmlLayout} />
<HtmlLayer preparedData={{htmlElements}} htmlLayout={htmlLayout} />
</React.Fragment>
);
}
Loading
Loading