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
#10836 add getLabelItems public method #10837
#10836 add getLabelItems public method #10837
Conversation
9b618fb
to
c1b50a2
Compare
43c1160
to
eaa0f75
Compare
38c329a
to
8499920
Compare
@kurkle @LeeLenaleee @dangreen any opinions on what we do with this? I think I'd want to put it in 4.1.0 at a minimum since 4.0.0 is so close |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No big objections from me.
src/core/core.scale.js
Outdated
textBaseline, | ||
translation: [x, y], | ||
backdrop, | ||
renderTextOptions: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The seems badly named as its referring to some method used to render the text and thus exposes (and freezes) internal logic.
I think plain options
would work. Also the textOffset
should go in there too.
IMO we should make the ticks and labels to be (animated) elements in future releases, that is why I suggest plain options
. We could just return the elements as labelItems then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't disagree - obviously the renderTextOptions name came about because it stores a RenderTextOpts typed object. Why textOffset and, for that matter, font are passed separately into renderText() rather than in the options collection is also a mystery that I didn't dive into. I certainly agree that it seems to make sense to fold font and textOffset into the RenderTextOpts object, which simplifies the renderText signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kurkle, renamed to just options, didn't make any changes to textOffset
because I didn't want this change to break any implementations that relied on renderText(). However, now lint tests are failing (passing locally) - seems like perhaps an intermittent issue? Can checks be retriggered?
I think it needs something like |
I'll try it - weird that this passed a week or so ago without a problem:
|
local linter didn't like that - I've reverted to the known lint-passing from this run: |
I don't know - I'm going around in circles. There's no reason commit 58cb9e6 should have broken the types imports. There seems to just be something finicky going on with the linter and I can't reproduce it locally. |
@@ -359,6 +359,14 @@ export default class Scale extends Element { | |||
return this.options.labels || (this.isHorizontal() ? data.xLabels : data.yLabels) || data.labels || []; | |||
} | |||
|
|||
/** | |||
* @return {import('../types').LabelItem[]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return {import('../types').LabelItem[]} | |
* @return {import('../types.js').LabelItem[]} |
import { Color } from '../color'; | ||
import { ChartArea, RoundedRect } from '../geometric'; | ||
import { CanvasFontSpec } from '../../src/helpers/helpers.options'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add js extension
import { DeepPartial, DistributiveArray, UnionToIntersection } from './utils'; | ||
|
||
import { TimeUnit } from '../src/core/core.adapters'; | ||
import PointElement from '../src/elements/element.point'; | ||
import { EasingFunction } from '../src/helpers/helpers.easing'; | ||
import { AnimationEvent } from './animation'; | ||
import { AnyObject, EmptyObject } from './basic'; | ||
import { Color } from './color'; | ||
import Element from '../src/core/core.element'; | ||
import { ChartArea, Padding, Point } from './geometric'; | ||
import { LayoutItem, LayoutPosition } from './layout'; | ||
import { RenderTextOpts } from './helpers/helpers.canvas'; | ||
import { CanvasFontSpec } from '../src/helpers/helpers.options'; | ||
|
||
export { EasingFunction } from '../src/helpers/helpers.easing'; | ||
export { default as ArcElement, ArcProps } from '../src/elements/element.arc'; | ||
export { default as PointElement, PointProps } from '../src/elements/element.point'; | ||
export { Animation, Animations, Animator, AnimationEvent } from './animation'; | ||
export { Color } from './color'; | ||
export { ChartArea, Point } from './geometric'; | ||
export { LayoutItem, LayoutPosition } from './layout'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the same
Proposed solution to #10836. This makes the dimensions of the axis labels public by way of a scale method: getLabelItems() - It solves the problem of customizing labels or creating interactions from them - For a use-case see the following demo, which is based off of this PR branch:
https://codepen.io/cmcnulty/pen/JjZPxmJ
Additionally, there have been several discussions here (and also some in stackoverflow) that attempt to use the private _labelItems in order to solve related problems:
https://github.com/chartjs/Chart.js/discussions?discussions_q=_labelItems