(The examples assume defaults of anchor: "centre", align: "center", but analogous issues with other options)
When a bar of height 91 is drawn on an axis with min max 0-100 the positioning of the datalabel is, as expected in the middle:

However if a different scale is required (e.g. because minimum score is actually 80, max score is 120), then the anchor is not visible

Similarly if the top of the bar is cut off (e.g. because this is an unexpectedly high value) then the label can be drawn at an unexpected point in the bar.

Firstly, is there any obvious workaround to this? (I don't think there is, because there's no option to respecify where "center" is on the bar, only to adjust with an pixel-offset)
Secondly can you give any quick pointers on how to start on this as a PR?
Edit(SB): jsfiddle reproducing this issue
Thanks @timdiggins for reporting this issue (same as #15).
Firstly, is there any obvious workaround to this?
Unfortunately no :\
Secondly can you give any quick pointers on how to start on this as a PR?
I may take care of it since I already started some investigations long time ago but missed personal time to continue on it. Though, I'm not sure how it should be resolved and if the current behavior should be considered as a bug? If not a bug, then what do you think about a new clamp option (default false to
avoid breaking changes):

This option would need to work the same whatever the chart type (bar, line, doughnut, etc.).
What do you think?
I like the proposal for clamp: true -- that would be perfect (and very crisply described in that illustration).
I agree it's hard to know whether this is a bug or not. I can't see why anyone would want the clamp: false behaviour -- but then you never know. Might be worth switching the default from false to true at the next appropriate (major or minor) version bump?
@timdiggins what about labels on bar fully outside the viewport?
what about labels on bar fully outside the viewport?
@simonbrunel that is a tricky one. I feel like the chart is largely broken at that point. But the most logical thing seems to me to pull all the anchor points to the closest intersection with the graph, ie:

I implemented the clamp option to not alter anchor points for elements fully outside, which is different from your proposal (in my case, left and right pictures are the same). Here is the clamp documentation:
When
true, enforces the anchor position to be calculated based on the visible geometry of the associated element (i.e. part inside the chart area).
I can change my current implementation (though it would require a new intersection algorithm - I use Cohen鈥揝utherland right now), but I feel that the behavior you described could be better handled by another option (e.g. constrain), which would ensure that the final geometry of the label is fully inside the viewport, whatever the element is visible or not. It would also fix #94.
What do you think?
Nice image btw ;)
Yes -- totally agreed. constrain sounds really useful independently, and I don't think the case we're discussing with bar fully outside the viewport merits specific treatment within clamp.
Fixed in #99, will be released in v0.5.0
Most helpful comment
Released in v0.5.0 (fiddle)