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

When using with zoom plugin, clip: true affect the labels on the edge #398

Open
helloint opened this issue Oct 10, 2023 · 0 comments
Open

Comments

@helloint
Copy link

helloint commented Oct 10, 2023

See this demo: https://codesandbox.io/s/chart-js-data-labels-plugin-clip-issue-mqkrgd?file=/src/App.tsx It use zoom and datalabels

When using with zoom, you have to set clip: true on datalabels, otherwise the label will overlap with the yAxis
image
But if did this, the first and the last bar label get cut.
image
Because it is beyond the chart area.
image
The document tells me the clip is calling CanvasRenderingContext2D.clip(), so I then took a look at the source code here:

    if (model.clip) {
      area = model.area;
      ctx.beginPath();
      ctx.rect(
        area.left,
        area.top,
        area.right - area.left,
        area.bottom - area.top);
      ctx.clip();
    }

I guess maybe we can allow a paddingOffset to slightly extend the rect area, to let customer to adjust? like:

    var paddingOffset = modal.paddingOffset;
    if (model.clip) {
        area = model.area;
        ctx.beginPath();
        ctx.rect(
            area.left - paddingOffset,
            area.top - paddingOffset,
            area.right + paddingOffset * 2 - area.left,
            area.bottom + paddingOffset * 2 - area.top);
        ctx.clip();
    }
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

1 participant