feat(annotations): marker body with dynamic positioning#1116
feat(annotations): marker body with dynamic positioning#1116nickofthyme merged 19 commits intoelastic:masterfrom
Conversation
src/utils/common.tsx
Outdated
| * @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.
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.
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.
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.
markov00
left a comment
There was a problem hiding this comment.
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
| * @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.
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.
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.
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 <vettorello.marco@gmail.com>
|
🎉 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 <vettorello.marco@gmail.com>
Summary
fixes #1040, fixes #1125
Adds a new render component
markerBodyonLineAnnotationSpecwhich is positioned usingpopper.jswithin the chart<canvas>area.markerBodyandmarker(i.e. the marker icon) are now able to render asReactNodeor aComponentType<LineAnnotationDatum>. This allows for simple text or JSX components or a complex react component that is rendered with theLineAnnotationDatumas 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:
LineMarkercomponent.eachRotationhelper to DRY-up code forit.each<Rotation>logic where-90in a png filename is converted to90, unknowingly causing duplicated png file names to be overridden.idin 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../srcexcept for test data & storybook)