Skip to content

fix: clippedRanges when complete dataset is null#1037

Merged
nickofthyme merged 11 commits intoelastic:masterfrom
anishagg17:xy
Mar 4, 2021
Merged

fix: clippedRanges when complete dataset is null#1037
nickofthyme merged 11 commits intoelastic:masterfrom
anishagg17:xy

Conversation

@anishagg17
Copy link
Copy Markdown
Contributor

@anishagg17 anishagg17 commented Feb 28, 2021

Summary

Fixes: #1047

Before

Screenshot 2021-03-03 at 11 59 05 PM

After

Screenshot 2021-03-03 at 11 58 05 PM

Checklist

Delete any items that are not applicable to this PR.

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • This was checked for cross-browser compatibility
  • 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

@kibanamachine
Copy link
Copy Markdown

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@anishagg17
Copy link
Copy Markdown
Contributor Author

anishagg17 commented Feb 28, 2021

I have partially resolved this issue, looking for maintainers' insights on how they would like to proceed with it(there are multiple levels at which data could be filtered).

@anishagg17 anishagg17 changed the title Line doesn't render for null values feat(xy_charts): line doesn't render for null values Mar 1, 2021
@markov00
Copy link
Copy Markdown
Collaborator

markov00 commented Mar 2, 2021

Hi @anishagg17, thank you for your contribution, we really appreciated it.
We usually discuss the issue to better define the constraints and use cases before start working on it.
Some issues/requests look fine at a first glance but they probably need a better and thoughtful discussion before being processed and implemented, some others may be outdated or invalid.
In this case, the issue was a bit vague: it actually adds an additional behavior to a specific edge case, increasing the number of internally managed edge cases that are not immediately understandable and known from the outside.
I think we should not proceed further on this issue and close it as it is. @nickofthyme what do you think?

@nickofthyme
Copy link
Copy Markdown
Collaborator

Hey @anishagg17 Thanks for opening this PR. I can't recall what the impetus was for opening this issue.

I looked through your solution and after thinking more about this issue I am not sure this is something we need to change. The issue is suggesting we show the empty state UI when all values are null. After discussing this with the team, we think this is not the best approach as null values could be useful to visualize the data.

That being said. I do see an issue with how the line is being rendered see #1047. Would you like to take this issue? I can guide you where to look to fix this.

@anishagg17
Copy link
Copy Markdown
Contributor Author

Would you like to take this issue?

Will really like to work on it, as it could help me gain more knowledge regarding the codeBase.

I think that I should make changes for #1047 within this pr only. But could you please let me know where to make changes at, I observed several functions, within which the fix could be implemented

@nickofthyme
Copy link
Copy Markdown
Collaborator

nickofthyme commented Mar 3, 2021

Sweet! So the idea behind the fitting functions is that there is data that may be null or undefined and we provide a few options on how these values can be filled. Filled values appear with subdued areas and dashed lines. You can see this better in this story.

Screen.Recording.2021-03-03.at.11.15.02.AM.mp4

Since there are possibly curved lines we must render the full line/area path for both the "real" data and the fitted data. Then with these paths, we determine the clippedRanges or the segments along the x-axis that represent fitted data, then this can be used to clip the paths and merge them into a single chart. So an illustration of that would be something like...

image

Where the red represents the clippedRanges as a list of intervals (i.e. [[0,1], [3,4]]) which is used to clip the "real" path and the blue represents the inverse of the clippedRanges to clip the "fitted" path.

These clippedRanges are computed here for area series...

const clippedRanges = getClippedRanges(dataSeries.data, xScale, xScaleOffset);

And here for line series...

const clippedRanges = getClippedRanges(dataSeries.data, xScale, xScaleOffset);

So with the example in the issue, the clipped ranges return [] which clips nothing and hence the issue. So I would look into the getClippedRanges function here...

export function getClippedRanges(dataset: DataSeriesDatum[], xScale: Scale, xScaleOffset: number): ClippedRanges {
let firstNonNullX: number | null = null;
let hasNull = false;
return dataset.reduce<ClippedRanges>((acc, data) => {
const xScaled = xScale.scale(data.x);
if (xScaled === null) {
return acc;
}
const xValue = xScaled - xScaleOffset + xScale.bandwidth / 2;
if (isDatumFilled(data)) {
const endXValue = xScale.range[1] - xScale.bandwidth * (2 / 3);
if (firstNonNullX !== null && xValue === endXValue) {
acc.push([firstNonNullX, xValue]);
}
hasNull = true;
} else {
if (hasNull) {
if (firstNonNullX !== null) {
acc.push([firstNonNullX, xValue]);
} else {
acc.push([0, xValue]);
}
hasNull = false;
}
firstNonNullX = xValue;
}
return acc;
}, []);
}

Maybe we could check if all the values are null then return the full domain within the getClippedRanges function or it might need to be done outside of that function (i.e. where that function is called) to have access to the necessary values. I'm not sure.

Let me know if you have any questions about that and if you run into any issues.

@nickofthyme
Copy link
Copy Markdown
Collaborator

nickofthyme commented Mar 3, 2021

Sorry forgot to mention, it's totally fine to make the changes in this pr, just remove the filtering logic on the data for #883.

@anishagg17 anishagg17 changed the title feat(xy_charts): line doesn't render for null values fix: clippedRanges when complete dataset is null Mar 3, 2021
@nickofthyme nickofthyme added :styling Styling related issue bug Something isn't working labels Mar 4, 2021
@nickofthyme
Copy link
Copy Markdown
Collaborator

jenkins test this please

Copy link
Copy Markdown
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

Nicely done! Just a few simplifications.

anishagg17 and others added 2 commits March 4, 2021 23:46
Co-authored-by: Nick Partridge <nick.ryan.partridge@gmail.com>
Co-authored-by: Nick Partridge <nick.ryan.partridge@gmail.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2021

The Workflow run is cancelling this PR. It is an earlier duplicate of 1821200 run.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2021

The Workflow run is cancelling this PR. It is an earlier duplicate of 1202109 run.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2021

The Workflow run is cancelling this PR. It is an earlier duplicate of 1821199 run.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2021

The Workflow run is cancelling this PR. It is an earlier duplicate of 1202109 run.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2021

The Workflow run is cancelling this PR. It is an earlier duplicate of 1821200 run.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2021

The Workflow run is cancelling this PR. It is an earlier duplicate of 1821200 run.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2021

The Workflow run is cancelling this PR. It is an earlier duplicate of 1821199 run.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2021

The Workflow run is cancelling this PR. It is an earlier duplicate of 1821199 run.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2021

The Workflow run is cancelling this PR. It is an earlier duplicate of 1202109 run.

@nickofthyme
Copy link
Copy Markdown
Collaborator

jenkins test this please

@nickofthyme
Copy link
Copy Markdown
Collaborator

jenkins test this please

Copy link
Copy Markdown
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

LGTM

@anishagg17
Copy link
Copy Markdown
Contributor Author

Screenshot 2021-03-05 at 12 12 32 AM

Due to this error, I made a small change.

@nickofthyme
Copy link
Copy Markdown
Collaborator

Sorry about all the updating I had to make some updates to master. I'm done now.

@nickofthyme
Copy link
Copy Markdown
Collaborator

jenkins test this please

@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #1037 (8ae7792) into master (5bcd1cb) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1037      +/-   ##
==========================================
- Coverage   72.80%   72.73%   -0.07%     
==========================================
  Files         363      379      +16     
  Lines       11242    10854     -388     
  Branches     2445     2218     -227     
==========================================
- Hits         8185     7895     -290     
+ Misses       3043     2855     -188     
- Partials       14      104      +90     
Flag Coverage Δ
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/chart_types/xy_chart/rendering/utils.ts 93.10% <100.00%> (-1.22%) ⬇️
src/state/selectors/get_legend_items_labels.ts 50.00% <0.00%> (-50.00%) ⬇️
src/utils/dimensions.ts 71.42% <0.00%> (-28.58%) ⬇️
src/components/no_results.tsx 50.00% <0.00%> (-25.00%) ⬇️
src/chart_types/xy_chart/utils/panel_utils.ts 72.72% <0.00%> (-19.59%) ⬇️
src/components/error_boundary/errors.ts 50.00% <0.00%> (-16.67%) ⬇️
src/chart_types/xy_chart/rendering/point_style.ts 87.50% <0.00%> (-12.50%) ⬇️
...t/state/selectors/compute_small_multiple_scales.ts 87.50% <0.00%> (-12.50%) ⬇️
...rt/renderer/dom/annotations/annotation_tooltip.tsx 79.31% <0.00%> (-10.35%) ⬇️
src/utils/data_generators/data_generator.ts 45.45% <0.00%> (-9.10%) ⬇️
... and 208 more

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 5bcd1cb...8ae7792. Read the comment docs.

@nickofthyme
Copy link
Copy Markdown
Collaborator

@anishagg17 all good to merge this whenever you want 👍🏼

Copy link
Copy Markdown
Collaborator

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @anishagg17 for your work on this, we really appreciate it

@anishagg17
Copy link
Copy Markdown
Contributor Author

@anishagg17 all good to merge this whenever you want 👍🏼

I can't merge this, Since this is a community submitted pull request.

@nickofthyme nickofthyme merged commit 51418d2 into elastic:master Mar 4, 2021
@nickofthyme
Copy link
Copy Markdown
Collaborator

Oh yeah true. Done! Thanks again 🎉

@anishagg17 anishagg17 deleted the xy branch March 4, 2021 20:00
github-actions bot pushed a commit that referenced this pull request Mar 5, 2021
## [25.1.1](v25.1.0...v25.1.1) (2021-03-05)

### Bug Fixes

* clippedRanges when complete dataset is null ([#1037](#1037)) ([51418d2](51418d2))
* **tooltip:** allow explicit boundary element ([#1049](#1049)) ([5cf8461](5cf8461))
@nickofthyme
Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 25.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nickofthyme nickofthyme added the released Issue released publicly label Mar 5, 2021
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working released Issue released publicly :styling Styling related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fitted data on all null values does not dash line

5 participants