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

Split isFulfilledData into isFulfilledBarData and isFulfilledLineData to allow WhitespaceData with extra properties #1579

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mozeryansky
Copy link
Contributor

@mozeryansky mozeryansky commented May 4, 2024

Type of PR: enhancement

PR checklist:

Overview of change:

isFulfilledData was used to validate both OhlcData and SingleValueData, but based on different keys. This will cause a false assertion to be thrown when valid WhitespaceData is passed but also includes extra keys which cause it to be considered to be "fulfilled" but for the other series type. Also, this validation only occurs in development.

This PR introduces isFulfilledBarData for OhlcData, and isFulfilledLineData for SingleValueData. Specifically only considering the properties open vs value instead of either being present.

Is there anything you'd like reviewers to focus on?

In the function _convertMouseParams, instead of calling isFulfilled*Data directly, it could reuse the method from before. getChecker(seriesType)(data). Also isFulfilledData could be removed and merged into checkBarItem/checkLineItem and return a boolean so _convertMouseParams can be asserted the same. This seemed beyond the initial intention, let me know.

src/model/data-consumer.ts Show resolved Hide resolved
src/model/data-consumer.ts Outdated Show resolved Hide resolved
export function isFulfilledLineData<HorzScaleItem, T extends SeriesDataItemTypeMap<HorzScaleItem>[SeriesType]>(
data: T
): data is Extract<T, BarData<HorzScaleItem> | LineData<HorzScaleItem> | HistogramData<HorzScaleItem>> {
return (data as Partial<LineData<HorzScaleItem>>).value !== undefined;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can add this:

export function isFulfilledData<HorzScaleItem, T extends SeriesDataItemTypeMap<HorzScaleItem>[SeriesType]>(
	data: T
): data is Extract<T, BarData<HorzScaleItem> | LineData<HorzScaleItem> | HistogramData<HorzScaleItem>> {
	return isFulfilledBarData(data) || isFulfilledLineData(data);
}

and then undo the changes in chart-api.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I just noticed too, the data in _convertMouseParams is actually generated, meaning this assert is not for user input, so it's kinda unrelated to the pr.

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.

isFulfilledData should only consider value and not open
2 participants