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

feat: fit functions for null y1 values #416

Merged
merged 28 commits into from
Nov 13, 2019

Conversation

nickofthyme
Copy link
Collaborator

@nickofthyme nickofthyme commented Oct 11, 2019

Summary

Add fit functions below to fill null y1 values (y0 null values not yet supported)

Works for ONLY non-stacked series. Stacked series requires another approach having to account for the fitted value of lower series.

Name Description Examples
None Don't draw that value on the graph [2, null null, 8]
Carry Use the last non null value before that [2, 2, 2, 8]
Nearest Use the closest value (either before or after) that was non null [2, 2, 8, 8]
Lookahead Use the next non null value after that (opposite of Carry) [2, 8, 8, 8]
Average Use the average of the last and next non null value [2, 5, 5, 8]
Linear Linear interpolate between closest values [2, 4, 6, 8]
Zero Fills all null values with 0 [2, 0, 0, 8]
Explicit Specify an explicit value (x), that should be used instead [2, x, x, 8]

Note: All "fitted" (aka "filled") points are not rendered but only used to draw the line/area.

Related to fix #388

Usage

within a series spec definition, define the fit type.

import { Fit } from '@elastic/charts';

<AreaSeries
  fit={Fit.Nearest}
/>

when using the explicit type you must provide a value like so...

<AreaSeries
  fit={{
    type: Fit.Explicit,
    value: 5,
  }}
/>

By default, indeterminate endvalues, values not able to be fitted, are set to null. To set a specific value rather than null, you can pass an endValue prop like so...

<AreaSeries
  fit={{
    type: Fit.Average,
    endValue: 4,
  }}
/>

Demos [Non-stacked]

Assuming the following data

const data = [
  { x: 0, y: null },
  { x: 1, y: 3 },
  { x: 2, y: 5 },
  { x: 3, y: null },
  { x: 4, y: 4 },
  { x: 5, y: null },
  { x: 6, y: 5 },
  { x: 7, y: 6 },
  { x: 8, y: null },
  { x: 9, y: null },
  { x: 10, y: null },
  { x: 11, y: 12 },
  { x: 12, y: null },
];

Fit.None [default]

image

Fit.Carry

image

Fit.Nearest

image

Fit.Lookahead

image

Fit.Average

image

Fit.Linear

image

Fit.Zero

image

Fit.Explicit with value set to 4

image

Curved Linear

Also Works with curves
image

Note: If the explicit value is set outside of the xScale domain, the charts will not recompute the domain to include it. This will have to be fixed in a later PR.

Using endValue

The endValue property allows you to set the end null point values to a specific value. This value is only used in the case where the fitting function does not have sufficient information to determine the fitted value. For example, using Fit.Average requires both the trailing and leading non-null boundaries, thus if the endpoints are both null the value can not be found for either.

<AreaSeries
  fit={{
    type: Fit.Average,
    endValue: 4,
  }}
/>

image

Checklist

Use strikethroughs to remove checklist items you don't feel are 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, including a check against IE11
  • 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
  • Each commit follows the convention

@codecov-io
Copy link

codecov-io commented Oct 11, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@f2c7bd9). Click here to learn what that means.
The diff coverage is 86.01%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #416   +/-   ##
=========================================
  Coverage          ?   78.16%           
=========================================
  Files             ?       91           
  Lines             ?     4301           
  Branches          ?      870           
=========================================
  Hits              ?     3362           
  Misses            ?      926           
  Partials          ?       13
Impacted Files Coverage Δ
src/chart_types/xy_chart/utils/interactions.ts 100% <ø> (ø)
src/chart_types/xy_chart/utils/series.ts 100% <ø> (ø)
src/utils/scales/scales.ts 100% <ø> (ø)
src/components/icons/icon.tsx 57.89% <ø> (ø)
src/utils/commons.ts 94.73% <ø> (ø)
src/utils/curves.ts 100% <ø> (ø)
src/components/react_canvas/line_geometries.tsx 24% <0%> (ø)
src/components/react_canvas/area_geometries.tsx 16.39% <0%> (ø)
src/components/react_canvas/reactive_chart.tsx 11.62% <0%> (ø)
src/mocks/specs/index.ts 100% <100%> (ø)
... and 17 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 f2c7bd9...ac9f744. Read the comment docs.

@nickofthyme nickofthyme marked this pull request as ready for review October 12, 2019 14:48
Copy link
Member

@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.

Tested locally and everything looks fine.
I've just two minor concerns:

  1. the static Explicit value is not taken in consideration as part of the data domain
  2. I'd like to add a small change on the endValue to allow either a value and the nearest point to avoid having to specify a value that maybe is not in the range

src/chart_types/xy_chart/utils/fit_function.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/utils/fit_function.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/utils/series.ts Show resolved Hide resolved
@nickofthyme
Copy link
Collaborator Author

Still need to add support for ordinal scale type

@nickofthyme nickofthyme added :chart Chart element related issue enhancement New feature or request labels Oct 28, 2019
@@ -2,7 +2,9 @@ module.exports = {
roots: ['<rootDir>/src'],
preset: 'ts-jest',
testEnvironment: 'jest-environment-jsdom-fourteen',
setupFilesAfterEnv: ['<rootDir>/scripts/setup_enzyme.ts'],
setupFilesAfterEnv: ['jest-extended', '<rootDir>/scripts/setup_enzyme.ts', '<rootDir>/scripts/custom_matchers.ts'],
coveragePathIgnorePatterns: ['<rootDir>/src/mocks/', '<rootDir>/node_modules/'],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@markov00 I don't know why the coverage went down to 78% but it does not appear to be because of my code changes. Maybe this is causing some issues. Any thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I think the current coverage only cover the modules/files imported on each test. Adding the coveragePathIgnorePatterns maybe count also the missing modules without a test file importing them

@nickofthyme nickofthyme requested a review from markov00 October 29, 2019 14:10
Copy link
Member

@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, just few minor comments to fix before merging

CHANGELOG.md Outdated Show resolved Hide resolved
src/mocks/series/series.ts Show resolved Hide resolved
src/chart_types/xy_chart/utils/series.ts Outdated Show resolved Hide resolved
src/chart_types/xy_chart/utils/specs.ts Show resolved Hide resolved
@nickofthyme nickofthyme removed the request for review from wylieconlon November 13, 2019 16:39
@markov00 markov00 self-requested a review November 13, 2019 16:57
Copy link
Member

@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

@nickofthyme nickofthyme merged commit e083755 into elastic:master Nov 13, 2019
@nickofthyme nickofthyme deleted the feat/fit-functions branch November 13, 2019 17:20
markov00 pushed a commit that referenced this pull request Nov 13, 2019
# [14.1.0](v14.0.0...v14.1.0) (2019-11-13)

### Features

* fit functions for null y1 values ([#416](#416)) ([e083755](e083755)), closes [#450](#450) [#388](#388)
@markov00
Copy link
Member

🎉 This PR is included in version 14.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Nov 13, 2019
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
:chart Chart element related issue enhancement New feature or request released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stacked area charts render with gaps when the X coordinates are not continuous
3 participants