Skip to content

feat: allow serialization of complex values#837

Closed
nickofthyme wants to merge 4 commits intoelastic:masterfrom
nickofthyme:complex-datum
Closed

feat: allow serialization of complex values#837
nickofthyme wants to merge 4 commits intoelastic:masterfrom
nickofthyme:complex-datum

Conversation

@nickofthyme
Copy link
Copy Markdown
Collaborator

@nickofthyme nickofthyme commented Sep 29, 2020

Summary

closes #808

Allows non-primative values to be passed through a serializer. Allows different serializer function for each series on all non-primative x, y and mark accessor values.

Ignores all serialized values that are non-primative values or if the serialization throws an error.

const data = [
  {
    y: {
      value: 2,
    },
    x: {
      from: 3,
      to: 4,
    },
  },
];

return (
  <BarSeries
    xScaleType={ScaleType.Ordinal}
    yScaleType={ScaleType.Linear}
    xSerializer={({ from, to }) => `${from} - ${to}`}
    ySerializer={({ value }) => value}
    data={data}
  />
);

const equivalentData = [
  {
    y: 2,
    x: '3 - 4',
  },
];

Checklist

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios

@nickofthyme nickofthyme added enhancement New feature or request :data Data/series/scales related issue :xy Bar/Line/Area chart related labels Sep 29, 2020
@flash1293
Copy link
Copy Markdown

flash1293 commented Sep 30, 2020

Pretty cool :) cc @dej611 This will simplify the logic in the Lens xy chart renderer because we don't have to map back from the serialized x value (once we start using it of course)

@nickofthyme
Copy link
Copy Markdown
Collaborator Author

nickofthyme commented Sep 30, 2020

Closing this issue to use AccessorFn in place of serializer see #838.

Currently the xAccessor allows for AccessorFn which is analogous to using a separate serializer.

return (
  <BarSeries
    id="bars"
    xScaleType={ScaleType.Ordinal}
    yScaleType={ScaleType.Linear}
    xAccessor={({ obj: { from, to }}) => `${from} - ${to}`}
    yAccessors={['y']}
    data={[
      { y: 2, obj: { from: 10, to: 20 } },
      { y: 7, obj: { from: 20, to: 30 } },
      { y: 3, obj: { from: 30, to: 40 } },
      { y: 6, obj: { from: 40, to: 50 } },
    ]}
  />
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:data Data/series/scales related issue enhancement New feature or request :xy Bar/Line/Area chart related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow non-primitive data values

2 participants