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
Support data accessor functions #84
Comments
more detail: Right now the data prop is pretty naive. Just a array (or array of arrays) of data objects that need to have x and y values to work. The data prop is probably going to stay pretty simple, but in the near future we will be adding accessor functions to make it more flexible. What I mean by that is...
|
+1 |
To-do list for supporting data accessors:
|
Here's how the data accessor API will look: All chart types may be passed
The default Since this replaces the old behavior for |
@boygirl All of the PR's mentioned above are now ready for review! Please take a look and let me know what you think. Hit me up on chat if you have any questions/comments. |
All of the PR's have been merged into the |
update: |
|
Does this also support using data ancestors in style. Something like: <VictoryBar
data={data}
style={{ data: {
width: data => data.x,
}}}
/> |
@okonet yep! Your example above will work. If you specify functions for style attributes they will be evaluated using the corresponding data point for each bar. |
I've tried it and it didn't work. Probably I miss something. Do you have a test/example for it? |
|
I'm trying to do this with the <VictoryLine
style={{data: {fill: data => { console.log(data)}}}}
data={[
{x: 0, y: 1},
{x: 1, y: 3},
{x: 2, y: 2},
{x: 3, y: 4},
{x: 4, y: 3},
{x: 5, y: 5}
]}
/> outputs:
but <VictoryBar
style={{data: {fill: data => { console.log(data)}}}}
data={[
{x: 0, y: 1},
{x: 1, y: 3},
{x: 2, y: 2},
{x: 3, y: 4},
{x: 4, y: 3},
{x: 5, y: 5}
]}
/> outputs
|
@okonet mind opening another issue and adding JSFiddle to it, with the issue? |
Will do! |
Yeah lines are a little funny... Only a single component gets rendered for an entire dataset, so the style functions get the entire dataset. If you have a preferred behavior / use case I would love to hear about it. |
Oh I see now... and it makes sense, actually. Otherwise, you'll end up with creating tons of lines for each section... |
Requirements: Ability to pass in props to any component to specify how to get (x, y) data, which is either:
It would be great if this were implemented as a mixin/composable that could be imported from
victory-util
.The text was updated successfully, but these errors were encountered: