Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xy-chart] add renderLabel to <BarSeries /> #147

Merged
merged 9 commits into from
Nov 14, 2018

Conversation

williaster
Copy link
Owner

@williaster williaster commented Nov 14, 2018

bar-labels

馃弳 Enhancements

  • Adds support to <BarSeries /> for rendering labels via the renderLabel and defaultLabelProps props
    • by default, if a datum has a label property, it will have a label rendered out of the box using the amazing @vx/text <Text /> component (which wraps svg text, etc.). labels are always rendered on top of the Bars themeselves.
    • The label has "smart" default aesthetics (taking from the @data-ui theme), text anchors, and wrapping behavior, but you can override them by setting defaultLabelProps to your own object.
    • to support full label customization, users can define a renderLabel function with the signature ({ datum, index, labelProps }) => node. labelProps includes all values from defaultLabelProps as well as "smart" default values for width, x, y, dx, dy, verticalAnchor, and textAnchor based on bar position, size, and orientation (horizontal vs vertical)
    • Example usage
<BarSeries
  {...restProps}
  defaultLabelProps
  renderLabel={({ datum, labelProps, index: i }) =>
    datum.label ? (
      <Text
        {...labelProps}
        fill={datum.selected ? COLOR_2 : COLOR_1}
      >
        {datum.label}
      </Text>
    ) : null
  }
/>
  • Exports the @vx/text <Text /> component to support rendering custom labels.

馃挃 Breaking Changes

  • Updates <PointSeries /> label API to match <BarSeries /> (these are the only series types that support Labels).
  • specifically labelComponent was replaced with renderLabel and defaultLabelProps

TODO

  • add + fix tests
  • update readme

cc @conglei @kristw @rmusa

@codecov
Copy link

codecov bot commented Nov 14, 2018

Codecov Report

Merging #147 into master will increase coverage by 0.03%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #147      +/-   ##
==========================================
+ Coverage    80.5%   80.53%   +0.03%     
==========================================
  Files         109      109              
  Lines        2395     2415      +20     
  Branches      556      568      +12     
==========================================
+ Hits         1928     1945      +17     
  Misses        290      290              
- Partials      177      180       +3
Impacted Files Coverage 螖
...y-chart/src/annotation/HorizontalReferenceLine.jsx 100% <100%> (酶) 猬嗭笍
.../xy-chart/src/annotation/VerticalReferenceLine.jsx 92.85% <100%> (酶) 猬嗭笍
packages/xy-chart/src/series/PointSeries.jsx 97.43% <87.5%> (-2.57%) 猬囷笍
packages/xy-chart/src/series/BarSeries.jsx 94.91% <88.23%> (-2.76%) 猬囷笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update c08f6b9...19b7cb4. Read the comment docs.

@williaster williaster merged commit b6e05ca into master Nov 14, 2018
@williaster williaster deleted the chris--bar-labels-n-such branch November 14, 2018 08:38
@williaster williaster added this to the v0.0.70 milestone Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant