Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

fix(plugin-chart-echarts): improve yAxisBounds parsing #815

Merged
merged 1 commit into from
Oct 28, 2020

Conversation

villebro
Copy link
Contributor

@villebro villebro commented Oct 28, 2020

🐛 Bug Fix
Currently the YAxisBoundsControl will initialize with null values despite being passed undefined, causing trouble when setting the y axis bounds. This improves the parsing of said values prior to using them so Y-axis bounds are always either undefined or valid values.

Before

image

After

image

@villebro villebro requested a review from a team as a code owner October 28, 2020 07:40
@vercel
Copy link

vercel bot commented Oct 28, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/superset/superset-ui/mzy5te28i
✅ Preview: https://superset-ui-git-villebro-fix-yaxisbounds.superset.now.sh

@codecov
Copy link

codecov bot commented Oct 28, 2020

Codecov Report

Merging #815 into master will increase coverage by 0.08%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #815      +/-   ##
==========================================
+ Coverage   25.57%   25.66%   +0.08%     
==========================================
  Files         359      361       +2     
  Lines        7949     7957       +8     
  Branches     1055     1058       +3     
==========================================
+ Hits         2033     2042       +9     
+ Misses       5796     5795       -1     
  Partials      120      120              
Impacted Files Coverage Δ
...gin-chart-echarts/src/Timeseries/transformProps.ts 27.65% <100.00%> (+0.57%) ⬆️
plugins/plugin-chart-echarts/src/utils/controls.ts 100.00% <100.00%> (ø)
...ges/superset-ui-core/src/query/buildQueryObject.ts 100.00% <0.00%> (ø)
.../superset-ui-core/src/query/types/QueryFormData.ts 100.00% <0.00%> (ø)
...uperset-ui-core/src/query/types/AnnotationLayer.ts 100.00% <0.00%> (ø)

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 d4eb01f...adf2cad. Read the comment docs.

expect(parseYAxisBound(1)).toEqual(1);
expect(parseYAxisBound('1')).toEqual(1);
expect(parseYAxisBound(10.1)).toEqual(10.1);
expect(parseYAxisBound('10.1')).toEqual(10.1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK the YAxisBoundsControl doesn't actually return strings, but I decided to parse string values, just in case.

*/
// eslint-disable-next-line import/prefer-default-export
export function parseYAxisBound(bound?: string | number | null): number | undefined {
if (bound === undefined || bound === null || Number.isNaN(Number(bound))) {
Copy link
Member

@rusackas rusackas Oct 28, 2020

Choose a reason for hiding this comment

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

Number(undefined) returns NaN, so you don't technically need that, but if it helps for code-reading clarity, so be it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! Just to make sure I understood correctly: That last bit is to catch unparseable strings and NaNs (`undefined was already checked at the beginning). If this can be written more compactly I'm happy to learn+change!

Copy link
Member

@rusackas rusackas left a comment

Choose a reason for hiding this comment

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

LGTM!

@villebro villebro merged commit 6859c75 into apache-superset:master Oct 28, 2020
@villebro villebro deleted the villebro/fix-yaxisbounds branch October 28, 2020 18:07
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants