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(y_axis_domain): updated y-axis domain settings to allow min OR max values to be set. #18040

Merged
merged 11 commits into from
May 12, 2020

Conversation

asalem1
Copy link
Contributor

@asalem1 asalem1 commented May 11, 2020

Closes #17793

Purpose

The purpose of this PR is to allow users to set a Y-domain min/max value without requiring users to set both. In other words, a user should be able to set the Y-domain with either a MIN or a MAX, and should not be required to set both.

Considerations

This feature required a removal of current restrictions on setting domain values, such as:

  • no empty values
  • min <= max

The ramifications of these changes were addressed by dynamically setting empty values based on the data range that is returned. If a user set their minimum value to 0, and left the maximum value blank, the upper bounds of their range would be set dynamically based on the data range. Similarly, if a user set their maximum value to 100 and left he minimum value blank, the lower bounds of their range would be set dynamically based on the data range.

In effect, this treats the non-blank input values as the source of truth for data range visualization. Therefore, if a user sets the minimum y value to be greater than the upper bounds of the data range values, and leaves the maximum value blank, then no data will show up (since it is beyond the range). Similarly, if a user sets the maximum y value to be less than the lower bounds of the data range values and leaves the minimum value blank, then no data will show up (for the same reason as before).

The images below list off the different use cases:
Auto Set:
Screen Shot 2020-05-11 at 13 45 01

Set minimum blank:
Screen Shot 2020-05-11 at 13 45 18

Set fields blank:
Screen Shot 2020-05-11 at 13 45 25

Set the min greater than the max data range:
Screen Shot 2020-05-11 at 13 45 33

Set the min > max:
Screen Shot 2020-05-11 at 13 45 39

Set the min, doesn't set the max:
Screen Shot 2020-05-11 at 13 45 48

Set Max less than the min data range:
Screen Shot 2020-05-11 at 13 45 54

Set Both:
Screen Shot 2020-05-11 at 13 46 00

Screen Shot 2020-05-11 at 13 45 10

  • CHANGELOG.md updated with a link to the PR (not the Issue)
  • Rebased/mergeable

Copy link
Contributor

@hoorayimhelping hoorayimhelping left a comment

Choose a reason for hiding this comment

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

good defensive coding, but some questions on whether it might be overkill in some spots.

another question about the memoization function and the loops there

@@ -69,6 +58,7 @@ const MinMaxInputs: SFC<MinMaxInputsProps> = ({
onChange={e => setMinInput(e.target.value)}
onBlur={emitIfValid}
onKeyPress={handleKeyPress}
testID="min--auto-domain"
Copy link
Contributor

Choose a reason for hiding this comment

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

i think the more BEM-y way of doing this is to scope it like css where it starts less specific progresses to more specific. in other words, we want to think of auto-domain as containing things like min and max:

Suggested change
testID="min--auto-domain"
testID="auto-domain--min"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's BEM stand for?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All good. Thanks for sharing this!

ui/src/shared/components/AutoDomainInput.tsx Outdated Show resolved Hide resolved
ui/src/shared/components/AutoDomainInput.tsx Outdated Show resolved Hide resolved
ui/src/shared/utils/useVisDomainSettings.ts Show resolved Hide resolved
timeRange: TimeRange | null,
storedDomain: number[]
) => {
const range = extent((data as number[]) || [])
Copy link
Contributor

Choose a reason for hiding this comment

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

love the enthusiasm around fallback values, but is the || [] necessary here since line 59 sets a default value of []?

are you trying to do this

  const range = extent((data as number[])) || []

so that range will always be an array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is necessary to set a default for the range since the output of the extent function can be null, in which case we would want to return an empty array.

Copy link
Contributor

Choose a reason for hiding this comment

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

so does that mean it should be

  const range = extent(data as number[]) || []

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aw, I think I see what you were getting at. Ya, that's a bit awkward. Honestly I don't think I took an introspective look at the existing code to analyze why things were set they were there. You're totally right

ui/src/shared/utils/useVisDomainSettings.ts Outdated Show resolved Hide resolved
Comment on lines +82 to +87
if (storedDomain === null || storedDomain.every(val => val === null)) {
return getValidRange(data, timeRange)
}
if (storedDomain.includes(null)) {
return getRemainingRange(data, timeRange, storedDomain)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this code loops over the same structure twice to perform essentially the same check (is the current item null). this happens while rendering. it's good you're using memoization, but you could write this logic using a single loop. what kind of array sizes are we dealing with in these loops?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I follow you, would you mind elaborating on this a bit?

ui/src/shared/components/AutoDomainInput.tsx Show resolved Hide resolved
@asalem1 asalem1 merged commit aad4eea into master May 12, 2020
@asalem1 asalem1 deleted the feat/min-or-max-y-axis branch May 12, 2020 21:36
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.

[2.0] Require min OR max for graph y axis domain
2 participants