-
Notifications
You must be signed in to change notification settings - Fork 122
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
feat(annotations): marker body with dynamic positioning #1116
feat(annotations): marker body with dynamic positioning #1116
Conversation
src/utils/common.tsx
Outdated
@@ -541,7 +558,7 @@ export function isDefined<T>(value?: T): value is NonNullable<T> { | |||
* | |||
* @internal | |||
*/ | |||
export const isDefinedFrom = <T>(typeCheck: (value: RecursivePartial<T>) => boolean) => ( | |||
export const isDefinedFrom = <T,>(typeCheck: (value: RecursivePartial<T>) => boolean) => ( |
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.
Converting this from *.ts
to *.tsx
file, the generic const
function declaration has issues.
This is a convenient fix that does not affect the type of the generic.
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.
What if instead of having this hack (as described in the stackoverflow comment) we transform these to named functions?
import * as common from '../../../../../utils/common'; | ||
import { buildAreaStyles } from './area'; | ||
|
||
jest.mock('../../../../../common/color_library_wrappers'); | ||
jest.mock('../../../../../utils/common'); | ||
jest.spyOn(common, 'getColorFromVariant'); |
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'm not sure how or why my changes to utils/common.ts(x)
affected this but this caused mocks to return undefined
. This changes the logic to now only spys on the common#getColorFromVariant
utils module method for conducting mock returns in styles unit tests.
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.
LGTM. Tested locally and works fine.
I've few doubts about the "padding" comments on the story, but I think it's fine leaving it like that. Probably a different background for the annotation or pushing the annotation text and line after the axis labels can be useful
src/utils/common.tsx
Outdated
@@ -541,7 +558,7 @@ export function isDefined<T>(value?: T): value is NonNullable<T> { | |||
* | |||
* @internal | |||
*/ | |||
export const isDefinedFrom = <T>(typeCheck: (value: RecursivePartial<T>) => boolean) => ( | |||
export const isDefinedFrom = <T,>(typeCheck: (value: RecursivePartial<T>) => boolean) => ( |
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.
What if instead of having this hack (as described in the stackoverflow comment) we transform these to named functions?
src/chart_types/xy_chart/renderer/dom/annotations/annotations.tsx
Outdated
Show resolved
Hide resolved
src/chart_types/xy_chart/renderer/dom/annotations/line_marker.tsx
Outdated
Show resolved
Hide resolved
const setPopper = useCallback(() => { | ||
if (!iconRef.current || !testRef.current) return; | ||
|
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.
On a different PR we should extract the popper.js
to be a HOF or something similar to enhance the positioning of everything that we need
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.
That's not a bad idea. I wonder if the logic is too bespoke for a HOC, I could see a class. Anyway, happy to discuss this in the future. I also secretly want to test popper on eui and see if it's better performance 🤪, we'll see if I ever have the time.
# [29.0.0](v28.2.0...v29.0.0) (2021-04-22) ### Features * **a11y:** add label for screen readers ([#1121](#1121)) ([920e585](920e585)), closes [#1096](#1096) * **annotations:** marker body with dynamic positioning ([#1116](#1116)) ([601abac](601abac)) ### BREAKING CHANGES * **a11y:** `description` prop in `<Settings/>` is renamed to `ariaDescription` Co-authored-by: Marco Vettorello <[email protected]>
🎉 This PR is included in version 29.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [29.0.0](elastic/elastic-charts@v28.2.0...v29.0.0) (2021-04-22) ### Features * **a11y:** add label for screen readers ([opensearch-project#1121](elastic/elastic-charts#1121)) ([ddb8782](elastic/elastic-charts@ddb8782)), closes [opensearch-project#1096](elastic/elastic-charts#1096) * **annotations:** marker body with dynamic positioning ([#1116](elastic/elastic-charts#1116)) ([997d487](elastic/elastic-charts@997d487)) ### BREAKING CHANGES * **a11y:** `description` prop in `<Settings/>` is renamed to `ariaDescription` Co-authored-by: Marco Vettorello <[email protected]>
Summary
fixes #1040, fixes #1125
Adds a new render component
markerBody
onLineAnnotationSpec
which is positioned usingpopper.js
within the chart<canvas>
area.markerBody
andmarker
(i.e. the marker icon) are now able to render asReactNode
or aComponentType<LineAnnotationDatum>
. This allows for simple text or JSX components or a complex react component that is rendered with theLineAnnotationDatum
as props. With these props one can render a marker icon or body based on values from the datum.Screen.Recording.2021-04-19.at.04.38.49.PM.mp4
Refactoring notes:
LineMarker
component.eachRotation
helper to DRY-up code forit.each<Rotation>
logic where-90
in a png filename is converted to90
, unknowingly causing duplicated png file names to be overridden.id
in the likely event there are multiple annotations with the same joined parameters as seen in the code below...elastic-charts/src/chart_types/xy_chart/annotations/line/dimensions.ts
Lines 407 to 415 in 4bf2ab1
Checklist
src/index.ts
(and stories only import from../src
except for test data & storybook)