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

Support line breaks in axis labels #675

Open
miwig opened this issue Mar 21, 2022 · 1 comment
Open

Support line breaks in axis labels #675

miwig opened this issue Mar 21, 2022 · 1 comment

Comments

@miwig
Copy link

miwig commented Mar 21, 2022

Axis labels are drawn using ctx.fillText, which apparently does not support line breaks. It would be nice if uPlot could work around this automatically.

@leeoniya
Copy link
Owner

should be pretty easy to add. just copy/paste a few bits from the axis renderer:

uPlot/src/uPlot.js

Lines 1804 to 1818 in 852829e

let _parts = val.indexOf("\n") == -1 ? [val] : val.split(/\n/gm);
for (let j = 0; j < _parts.length; j++) {
let text = _parts[j];
if (angle) {
ctx.save();
ctx.translate(x, y + j * lineHeight); // can this be replaced with position math?
ctx.rotate(angle); // can this be done once?
ctx.fillText(text, 0, 0);
ctx.restore();
}
else
ctx.fillText(text, x, y + j * lineHeight);
}

want to make a PR?

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

No branches or pull requests

2 participants