-
Notifications
You must be signed in to change notification settings - Fork 120
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: allow use of functions for y, y0, split and stack accessors #943
Conversation
Codecov Report
@@ Coverage Diff @@
## master #943 +/- ##
==========================================
+ Coverage 70.13% 70.66% +0.53%
==========================================
Files 342 359 +17
Lines 11026 11342 +316
Branches 2391 2416 +25
==========================================
+ Hits 7733 8015 +282
- Misses 3279 3307 +28
- Partials 14 20 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Thanks Nick for taking the ownership of this feature.
It looks great, I've written few comments I'd like to discuss before merging
src/utils/accessor.ts
Outdated
@@ -24,7 +24,10 @@ import { Datum } from './commons'; | |||
* @param datum - the datum | |||
* @public | |||
*/ | |||
export type UnaryAccessorFn<Return = any> = (datum: Datum) => Return; | |||
export interface UnaryAccessorFn<Return = any> { | |||
seriesName?: string; |
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.
seriesName
doesn't sound related to the accessor function. A series describe one or multiple objects made up of one or multiple fields and values. Here instead you are requesting a name for an accessor.
We can also barely specify it as a name
or fieldName
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.
Yeah good point. I don't wanna use name
because they could unknowingly set the name based on the variable name of the function itself. See 4b6876c
* @param index | ||
* @internal | ||
*/ | ||
export function getAccessorString(accessor: Accessor | AccessorFn, index: number) { |
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.
Similar to the comment relate to the accessor seriesName
, this can be renamed to something like:
getAccessorName
or getAccessorFieldName
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.
yAccessorFn.seriesName = 'simple y value'; | ||
|
||
// complex example | ||
const yAccessorFn: AccessorFn = ({ range }) => \`\${range.to} - \${range.from}\`; | ||
yAccessorFn.seriesName = 'complex y value'; | ||
\`\`\` | ||
|
||
If no \`seriesName\` is provided, the default value will be set using the index \`(index:0)\`. | ||
|
||
Try changing the \`seriesName\` for the y and split accessor functions in the storybook knobs. |
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.
In case you change the seriesName
field, remember to change also this
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.
const accessorStr = getAccessorString(accessor, index); | ||
splitAccessors.set(accessorStr, value); |
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.
Here there can be an issue when the seriesName
of an accessor function is the same as the key of another accessor.
On the provided story, if you use splitAccessorFn.seriesName = 'g1
the splitSeriesAccessors={['g1', splitAccessorFn]}
will wrongly split the data.
I'm not sure if we need to prevent this or just discourage this practice.
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.
Yeah, that's tough to avoid. I think it's the same with duplicate Accessor
strings in that we cannot really avoid it. I added a note to the story but maybe we can figure out a better way in the future (81b798f)
🎉 This PR is included in version 24.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [24.4.0](elastic/elastic-charts@v24.3.0...v24.4.0) (2020-12-09) ### Bug Fixes * empty labels on debug state ([opensearch-project#940](elastic/elastic-charts#940)) ([3d1281b](elastic/elastic-charts@3d1281b)) ### Features * allow use of functions for y, y0, split and stack accessors ([opensearch-project#943](elastic/elastic-charts#943)) ([e881723](elastic/elastic-charts@e881723))
Summary
closes #808, closes #838, related to #837
Allows for functional accessors (
AccessorFn
) onyAccessors
,y0Accessors
,splitSeriesAccessors
andstackAccessors
.Complex example with
seriesName
If no
seriesName
is provided, the default value will be set using the index(index:0)
.Checklist
src/index.ts
(and stories only import from../src
except for test data & storybook)