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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facilitate styling the top line of area charts #79

Closed
franky47 opened this issue Apr 29, 2020 · 3 comments · Fixed by #80
Closed

Facilitate styling the top line of area charts #79

franky47 opened this issue Apr 29, 2020 · 3 comments · Fixed by #80

Comments

@franky47
Copy link
Contributor

franky47 commented Apr 29, 2020

I was looking at recreating this design with react-charts:

chiffre-charts

It contains two visual components:

  • A line with no points, with a blue stroke of 2px
  • A gradient area under the curve

After a discussion with @tannerlinsley on Twitter, who pointed out that Area graphs are made of two components (a line and a filled path, perfect !), I looked into styling them separately using getSeriesStyle.

Looking at the Area component code, both the line and the area path use the same styling inputs, with the exception of the line having an extra fill: none property.

Unfortunately for this design, setting a stroke of 2px for the line would also set it for the area, which produces an undesired outline at the bottom and sides of the graph:

Screenshot 2020-04-29 at 09 19 09

One way I solved this in my project was to use external CSS to disable the stroke on the area path:

g.Series > g > path:first-child {
  /* Rendered path uses inline styles, so !important must be used to override them: */
  stroke-width: 0 !important;
}

I would like to open a PR suggesting an additional area property in what is returned by getSeriesStyle, so that each path can be styled separately without relying on external CSS.

Example:

const getSeriesStyle = React.useCallback(
  () => ({
    area: {
      // See the "Custom Styles" example for gradients usage
      fill: `url(#graph-gradient)`
    },
    line: {
      strokeWidth: '2px',
      stroke: 'blue'
    }
  }),
  []
)

In order not to break existing designs, the area path could use properties from both line and area:

const areaPathProps = {
    d: areaPath,
    style: {
      ...defaultAreaStyle,
      ...style,
      ...style.line,
+     ...style.area
    }
  };

Comments and suggestions are welcome !

@tannerlinsley
Copy link
Collaborator

Yep a PR for this would be great!

franky47 added a commit to franky47/react-charts that referenced this issue Apr 29, 2020
tannerlinsley pushed a commit that referenced this issue Apr 29, 2020
@tannerlinsley
Copy link
Collaborator

🎉 This issue has been resolved in version 0.0.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

@fralfarom
Copy link

fralfarom commented Jan 27, 2021

Hello @franky47 and @tannerlinsley !! is this available? If so, how can I use it?

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

Successfully merging a pull request may close this issue.

3 participants