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

Can we set a fixed width/height? #166

Open
hailwood opened this issue Jan 17, 2020 · 5 comments
Open

Can we set a fixed width/height? #166

hailwood opened this issue Jan 17, 2020 · 5 comments

Comments

@hailwood
Copy link

My client wishes to have a circle drawn behind the labels.

I know the labels are between 1-3 numbers, so I'd like to be able to say draw all the datalabels in a 40x40px circle.

I know how to set the backgrounds etc, just not how to make them a fixed width.

image

@simonbrunel
Copy link
Member

Hi @hailwood! No, it's currently not possible.

@maurk851
Copy link

Is it possible now?

@SanctusAnimus
Copy link

SanctusAnimus commented Feb 14, 2023

For anyone wondering, i actually managed to get pretty close to perfect circles thanks to scriptable padding
NOTE: those values are for font size 14. For other values you'll probably want to tweak multiplier etc cause space/letter changes, and provided code doesn't account for negatives.

borderRadius: 100,
textAlign: "center",
verticalAlign: "middle",
// POC of making any value a circle
// without scriptable width/height
padding: function(context) {
    const dataset = context.dataset;
    const value = dataset.data[context.dataIndex];
    // doesn't really work for singe digits, using known-good preset
    if (value < 10) return {top: 6, bottom: 5, left: 10, right: 10};
    const padding = (Math.log(value) * Math.LOG10E + 1 | 0) * 4
    return {
        top: padding,
        bottom: padding - 2, // slightly less on the bottom, otherwise seems off-center
        left: 8,
        right: 8,
    }
},

image

Doesn't fit piechart all that well on scale cause space is limited, but for other cases should be just fine

@ansariadil
Copy link

whats the timeline for addition of this feature.

@hailwood
Copy link
Author

whats the timeline for addition of this feature.

@ansariadil Depends how quickly you contribute it 😃

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

5 participants