Skip to content

RTL Support for the parent labesl in TreeMap #2673

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

Open
Jamil-Bailony opened this issue Nov 21, 2024 · 1 comment
Open

RTL Support for the parent labesl in TreeMap #2673

Jamil-Bailony opened this issue Nov 21, 2024 · 1 comment
Labels

Comments

@Jamil-Bailony
Copy link

Jamil-Bailony commented Nov 21, 2024

Is your feature request related to a problem? Please describe.

When setting the parent position to top, it works correctly in LTR layouts. However, in RTL layouts, the parent label is incorrectly positioned outside the cell and appears on the left side instead of the right (it should appear on the right with sufficient padding).

  • LTR layout:
    LTR-TreeMap

  • RTL layout:
    RTL-TreeMap
    RTL-tooltip-padding-issue


Describe the solution you'd like

Providing additional options for the parentLabelPosition property to support values like top-left, top-right, and top-center would fit for both layouts. Alternatively, ensuring the text aligns with the starting edge of the cell automatically also would solve the issue.


Describe alternatives you've considered

As a workaround, I manually adjusted the x attribute of the text node (in RTL layout) to align with the cell's starting position using the following code in a React application:

const chartRef = useRef();

useEffect(() => {
    if (direction !== "rtl") {
        return;
    }

    function handleResize() {
        if (!chartRef.current) {
            return;
        }

        // Adjust parent label positions inside the SVG
        const parentLabels = chartRef.current.querySelectorAll('[data-testid^="parentLabel"]');

        parentLabels.forEach((label) => {
            const siblingWidth = label.previousElementSibling.getAttribute("width");
            label.setAttribute("x", siblingWidth);
        });
    }

    // Recalculate text node positions on window resize with debounce
    const debouncedResizeHandler = debounce(handleResize, 600);
    window.addEventListener("resize", debouncedResizeHandler);

    // Initial adjustment delay to allow DOM updates
    setTimeout(handleResize, 20);

    return () => {
        window.removeEventListener("resize", debouncedResizeHandler);
    };
}, [direction]);
/* padding fix */
[dir="rtl"] .chart_container svg [data-testid^="parentLabel"] {
    transform: translate(-6px, 18px);
    text-anchor: start;
}

While this workaround positions the labels correctly, it has limitations:

  • The handler requires debouncing because the DOM updates of the chart svg take time (the above delays 600 and 20 tested for my app and works fine).
  • Changes are not applied dynamically on the fly and smoothly.

Additional context

With the workaround applied, the labels are correctly positioned as shown below:

  • RTL layout with the fix applied:
    RTL-with-fix-TreeMap
Copy link

stale bot commented Feb 25, 2025

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the stale label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant