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

Added continuousLine prop to line chart #475

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

rferdosi
Copy link

Added continuousLine props to line chart to skip null items in data.

fixes: #468,

Copy link
Owner

@JesperLekland JesperLekland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! In this library I try to introduce as few "custom" props as possible, meaning that I instead try to expose the underlying building blocks, e.g defined so that the user can do more powerful things and the implementation stays clean. Creating a prop for each specific use case would very quickly bloat this library and make the implementation very hard to follow.

New properties also need to thoroughly be documented in the README.

Comment on lines +6 to +21
const { curve, continuousLine } = this.props
let line
if (continuousLine) {
line = shape
.line()
.x((d) => x(d.x))
.y((d) => y(d.y))
.curve(curve)(data.filter((item) => item.y))
} else {
line = shape
.line()
.x((d) => x(d.x))
.y((d) => y(d.y))
.defined((item) => typeof item.y === 'number')
.curve(curve)(data)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this work?
Basically it exposes the defined function to user land, allowing them to implement it anyway they see fit

Suggested change
const { curve, continuousLine } = this.props
let line
if (continuousLine) {
line = shape
.line()
.x((d) => x(d.x))
.y((d) => y(d.y))
.curve(curve)(data.filter((item) => item.y))
} else {
line = shape
.line()
.x((d) => x(d.x))
.y((d) => y(d.y))
.defined((item) => typeof item.y === 'number')
.curve(curve)(data)
}
const {
defined = (item) => typeof item.y === 'number' ,
continuousLine
} = this.props
const shape =
.line()
.x((d) => x(d.x))
.y((d) => y(d.y))
.defined(defined)
.curve(curve)(data)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, can you explain how can I use defined function for this situation?

Copy link
Owner

@JesperLekland JesperLekland May 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, my suggestion above shows that defined is exposed as a prop. Meaning that we can have a default value (the one it is currently) and that the user can override it how they see fit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to implement the defined function for this specific use case but I failed. Do you have any idea?
That would help me to solve the main problem.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could provide a PR with your attempt and clearly stating what isn't working I might be able to help you 👍

Copy link
Author

@rferdosi rferdosi May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me with this?
Actually I think it's impossible to handle this use case without filtering data.
Checkout this example from d3.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I unfortunately don't have any time to assist outside of reviewing the PR. The user controls the data so I don't see why the user won't be able to filter the data? What exactly are you referring to in your example?

Copy link

@ALPNP ALPNP Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JesperLekland For example, we want to show the week, and the data is only available for Monday and Thursday. Line Chart will not be able to connect Monday and Thursday.

Copy link

@zirho zirho Dec 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not only .defined(defined) but also the data being fed to the chain is different.

@brianbscho
Copy link

Hi, I guess I'm late on the discussion but I also need this PR so want to add some comments.

Difference between data.filter (PR) and defined is that data.filter draws line between two dots where nulls in between but defined skips and makes empty space as noted in d3-shape. Once it used defined already, there's no way to draw line. So exposing defined as prop doesn't solve problem that this PR suggests, which solves #266 #399 #468 . Can you please merge this PR?

Comment on lines +9 to +13
line = shape
.line()
.x((d) => x(d.x))
.y((d) => y(d.y))
.curve(curve)(data.filter((item) => item.y))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should look like below, since data is array of line.

Suggested change
line = shape
.line()
.x((d) => x(d.x))
.y((d) => y(d.y))
.curve(curve)(data.filter((item) => item.y))
lines = data.map((line) =>
shape
.line()
.x((d) => x(d.x))
.y((d) => y(d.y))
.curve(curve)(line.filter((item) => item.y))

@adelaadeoye
Copy link

adelaadeoye commented Jun 17, 2021

@rferdosi and @JesperLekland Is this solution available for general usage, I just installed the package and still can't have a continuesLine

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.

LineChart doesn't connect points that skip a point
6 participants