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

Improve colorscheme ux #4763

Merged
merged 16 commits into from
Sep 19, 2024
Merged

Improve colorscheme ux #4763

merged 16 commits into from
Sep 19, 2024

Conversation

lanzhenw
Copy link
Contributor

@lanzhenw lanzhenw commented Sep 3, 2024

What changes are proposed in this pull request?

  • Added validation to ColorScheme class, so users can get error message instantly when argument input is not valid.
  • Improve the colorscheme documentation
  • Improve UX of setting colorscale and mask target colors in the UI by pruning invalid values
  • Fixed a bug of creating continuous colors from unsorted colorscale list
  • Segmentation: the intTarget is no longer limited between 1 and 255. It can be any non-negative integer

example:
Screenshot 2024-09-04 at 6 40 49 PM

How is this patch tested? If it is not, please explain why.

(Details)

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added color_by parameter to dynamically adjust color schemes based on dataset values.
    • Introduced enhanced input validation and error handling for user inputs in various components.
    • Improved flexibility of color scale definitions in the Colorscale component.
    • Updated user interface to clarify requirements for custom colorscales.
    • Removed input limits in several components, allowing for a broader range of user inputs.
  • Bug Fixes

    • Improved clarity and usability of color scheme configuration by specifying constraints and formatting requirements.
  • Documentation

    • Enhanced user guide with detailed notes on configuring color schemes, including updates on the default_colorscale and removal of redundant notes.

@lanzhenw lanzhenw requested review from brimoor and removed request for brimoor September 3, 2024 15:11
@lanzhenw lanzhenw changed the base branch from develop to release/v0.25.1 September 3, 2024 15:12
@lanzhenw lanzhenw changed the title Improve color doc Improve colorscheme documentation Sep 3, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

@coderabbitai review

@voxel51 voxel51 deleted a comment from coderabbitai bot Sep 3, 2024
@lanzhenw
Copy link
Contributor Author

lanzhenw commented Sep 3, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Sep 3, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

coderabbitai bot commented Sep 3, 2024

Walkthrough

The changes involve updates to the documentation and code related to color schemes in datasets. Key modifications include the introduction of a new color_by parameter in the ColorScheme class, allowing color assignment based on dataset values. Additionally, various components have been enhanced for better input validation and user feedback, while documentation clarifies constraints for color parameters and improves overall usability.

Changes

Files Change Summary
docs/source/user_guide/app.rst Minor formatting change in documentation for default_colorscale dictionary.
docs/source/user_guide/using_datasets.rst Introduced color_by parameter in ColorScheme, changing color assignment to be value-based.
fiftyone/core/odm/dataset.py Updated color_by parameter in ColorScheme from "field" to "value"; added validation methods.
app/packages/core/src/components/ColorModal/colorPalette/Colorscale.tsx Modified Colorscale component to support a more flexible definition of color scales.
app/packages/core/src/components/ColorModal/controls/ManualColorScaleList.tsx Introduced onValidateUnitInterval function for input validation; updated NumberInput placeholder.
app/packages/core/src/components/ColorModal/utils.ts Expanded validateIntMask parameter type to accept more input types; simplified validation logic.
app/packages/core/src/components/ColorModal/controls/IdxColorList.tsx Changed onValidate from optional to required in IdxColorProp type; updated input placeholder.
app/packages/core/src/components/ColorModal/controls/ColorscaleList.tsx Removed ColorscaleList component, which managed color-value pairs in a color-by-value mode.
app/packages/core/src/components/ColorModal/controls/DefaultMaskTargets.tsx Removed max prop, allowing input values greater than 255.
app/packages/core/src/components/ColorModal/controls/FieldsMaskTarget.tsx Removed max prop, allowing input values greater than 255.
app/packages/core/src/components/ColorModal/controls/GlobalColorscale.tsx Ensured generated color scale always includes values 0 and 1.
setup.py Modified pymongo version requirement from pymongo>=3.12 to pymongo>=3.12, <4.9.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Dataset
    participant ColorScheme

    User->>Dataset: Configure dataset with color scheme
    Dataset->>ColorScheme: Instantiate ColorScheme with color_by="value"
    ColorScheme->>Dataset: Assign colors based on dataset values
    Dataset->>User: Display dataset with updated color scheme
Loading

🐇 "In the garden where colors bloom,
A new scheme dances, dispelling gloom.
With values bright, they leap and play,
Hopping through data, come what may.
A palette fresh, a joyful sight,
Let’s celebrate this change tonight!" 🥕✨

Possibly related PRs

  • Remove desktop App #4748: The main PR involves documentation changes related to the removal of the desktop application, which aligns with the changes in this PR that also focus on the removal of desktop application support and related documentation.
  • Adding support for remotely-sourced zoo models #4786: While this PR primarily adds support for remotely-sourced models, it also includes documentation updates that may indirectly relate to the overall documentation structure and user guidance, which is relevant to the main PR's focus on documentation changes.

Suggested labels

cleaning, core

Suggested reviewers

  • lanzhenw
  • mwoodson1
  • jacobmarks

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 440b2a1 and 5fe8e60.

Files selected for processing (1)
  • setup.py (1 hunks)
Additional comments not posted (1)
setup.py (1)

58-58: LGTM!

Updating the pymongo version requirement to pymongo>=3.12, <4.9 is a good change. It ensures the codebase remains compatible with the intended range of pymongo versions and prevents potential issues that could arise from using untested newer versions.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
docs/source/user_guide/using_datasets.rst (1)

462-462: Consider using a more specific variable name.

Instead of color_by="value", consider using a more descriptive name like color_by="mask_target_value" to clarify what the value represents.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1fdd870 and 8328a46.

Files selected for processing (3)
  • docs/source/user_guide/app.rst (1 hunks)
  • docs/source/user_guide/using_datasets.rst (1 hunks)
  • fiftyone/core/odm/dataset.py (6 hunks)
Files skipped from review due to trivial changes (1)
  • docs/source/user_guide/app.rst
Files skipped from review as they are similar to previous changes (1)
  • fiftyone/core/odm/dataset.py

@lanzhenw lanzhenw self-assigned this Sep 3, 2024
@lanzhenw lanzhenw added documentation Documentation work enhancement Code enhancement labels Sep 3, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8328a46 and d9f1af0.

Files selected for processing (1)
  • docs/source/user_guide/using_datasets.rst (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • docs/source/user_guide/using_datasets.rst

@lanzhenw lanzhenw changed the base branch from release/v0.25.1 to develop September 3, 2024 18:23
@lanzhenw lanzhenw marked this pull request as draft September 4, 2024 23:59
@lanzhenw lanzhenw force-pushed the improveColorDoc branch 2 times, most recently from aae922b to a673d46 Compare September 5, 2024 16:37
@lanzhenw lanzhenw marked this pull request as ready for review September 6, 2024 20:59
@lanzhenw lanzhenw changed the title Improve colorscheme documentation Improve colorscheme ux Sep 6, 2024
@lanzhenw lanzhenw added the app Issues related to App features label Sep 6, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Outside diff range, codebase verification and nitpick comments (9)
app/packages/core/src/components/ColorModal/controls/IdxColorList.tsx (1)

36-36: Approve changes to validation logic and suggest placeholder text refinement.

The changes to make the onValidate property required and the integration of validation logic into the NumberInput component are positive, enhancing the robustness and clarity of the component. The updated placeholder text "integer (>0)" is more inclusive of valid input values but could be further refined to "Enter a positive integer" for better clarity.

Also applies to: 170-170, 180-180, 189-189

app/packages/core/src/components/ColorModal/controls/ManualColorScaleList.tsx (1)

151-154: Approve new validation function and suggest placeholder text improvement.

The introduction of the onValidateNumber function is a positive change, centralizing and clarifying the validation logic for float inputs. However, the simplified placeholder text "float" could be improved to "Enter a float between 0 and 1" to provide better guidance to users about the expected input range.

Also applies to: 175-175, 177-178

app/packages/core/src/components/ColorModal/colorPalette/DefaultMaskTargets.tsx (3)

Line range hint 1-1: Documentation and TODOs are missing.

The file lacks a comprehensive documentation header explaining the purpose and functionality of the component. Adding a detailed comment at the beginning of the file would improve maintainability and understandability.


Line range hint 6-6: Consider using TypeScript for better type safety.

The file uses plain JavaScript. Converting this to TypeScript could enhance type safety and reduce potential runtime errors, especially in a complex state management scenario like this one.


Enhance Validation Logic in validateIntMask

The validateIntMask function currently checks if the input is a positive integer but does not handle values above 255. Given the removal of the max prop, it's important to update this function to include an upper limit check to prevent potential bugs.

  • File: app/packages/core/src/components/ColorModal/utils.ts
  • Function: validateIntMask
  • Suggested Enhancement: Add a condition to ensure the value does not exceed 255.
Analysis chain

Line range hint 6-6: Validation logic might need enhancement.

Given the removal of the max prop, it's crucial to ensure that the validation logic (validateIntMask) adequately handles cases where the input might exceed expected limits. This change could potentially introduce bugs if the validation logic is not robust enough.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the implementation of `validateIntMask` to ensure it handles values above 255.

# Test: Search for the function implementation. Expect: Handling of values above 255.
ast-grep --lang javascript --pattern $'function validateIntMask($_) {
  $$$
}'

Length of output: 79


Script:

#!/bin/bash
# Search for the term `validateIntMask` across the entire codebase to locate its definition or usage.
rg 'validateIntMask' -A 5

Length of output: 3191

app/packages/core/src/components/ColorModal/colorPalette/FieldsMaskTarget.tsx (3)

Line range hint 1-1: Documentation and TODOs are missing.

The file lacks a comprehensive documentation header explaining the purpose and functionality of the component. Adding a detailed comment at the beginning of the file would improve maintainability and understandability.


Line range hint 6-6: Consider using TypeScript for better type safety.

The file uses plain JavaScript. Converting this to TypeScript could enhance type safety and reduce potential runtime errors, especially in a complex state management scenario like this one.


Enhance Validation Logic in validateIntMask

The validateIntMask function currently does not handle cases where the input value exceeds 255. To prevent potential bugs, consider enhancing the validation logic to include a check for values above 255.

  • File: app/packages/core/src/components/ColorModal/utils.ts
  • Function: validateIntMask
Analysis chain

Line range hint 6-6: Validation logic might need enhancement.

Given the removal of the max prop, it's crucial to ensure that the validation logic (validateIntMask) adequately handles cases where the input might exceed expected limits. This change could potentially introduce bugs if the validation logic is not robust enough.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the implementation of `validateIntMask` to ensure it handles values above 255.

# Test: Search for the function implementation. Expect: Handling of values above 255.
ast-grep --lang javascript --pattern $'function validateIntMask($_) {
  $$$
}'

Length of output: 79


Script:

#!/bin/bash
# Search for the term `validateIntMask` across the codebase to locate its definition or references.
rg 'validateIntMask'

Length of output: 580


Script:

#!/bin/bash
# Extract the implementation of `validateIntMask` from utils.ts to analyze its logic.
rg -A 10 'export const validateIntMask' app/packages/core/src/components/ColorModal/utils.ts

Length of output: 490

app/packages/core/src/components/Common/Input.tsx (1)

1-1: Documentation and TODOs are missing.

The file lacks a comprehensive documentation header explaining the purpose and functionality of the component. Adding a detailed comment at the beginning of the file would improve maintainability and understandability.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d9f1af0 and bf29aca.

Files selected for processing (11)
  • app/packages/core/src/components/ColorModal/colorPalette/Colorscale.tsx (7 hunks)
  • app/packages/core/src/components/ColorModal/colorPalette/DefaultMaskTargets.tsx (1 hunks)
  • app/packages/core/src/components/ColorModal/colorPalette/FieldsMaskTarget.tsx (1 hunks)
  • app/packages/core/src/components/ColorModal/controls/IdxColorList.tsx (4 hunks)
  • app/packages/core/src/components/ColorModal/controls/ManualColorScaleList.tsx (2 hunks)
  • app/packages/core/src/components/ColorModal/utils.ts (1 hunks)
  • app/packages/core/src/components/Common/Input.tsx (3 hunks)
  • docs/source/user_guide/app.rst (1 hunks)
  • docs/source/user_guide/using_datasets.rst (2 hunks)
  • fiftyone/core/odm/dataset.py (6 hunks)
  • fiftyone/core/plots/plotly.py (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • docs/source/user_guide/app.rst
  • docs/source/user_guide/using_datasets.rst
  • fiftyone/core/odm/dataset.py
Additional context used
Path-based instructions (7)
app/packages/core/src/components/ColorModal/colorPalette/DefaultMaskTargets.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/ColorModal/colorPalette/FieldsMaskTarget.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/Common/Input.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/ColorModal/utils.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/ColorModal/controls/IdxColorList.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/ColorModal/controls/ManualColorScaleList.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/ColorModal/colorPalette/Colorscale.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Biome
app/packages/core/src/components/Common/Input.tsx

[error] 170-170: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 223-223: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 232-232: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (4)
app/packages/core/src/components/ColorModal/colorPalette/DefaultMaskTargets.tsx (1)

Line range hint 6-6: Use of multiple Recoil hooks.

The component uses multiple Recoil hooks (useRecoilValue, useSetSessionColorScheme) effectively to manage global state. This is a good practice in Recoil-based applications, ensuring that the component reacts to state changes efficiently.

app/packages/core/src/components/ColorModal/colorPalette/FieldsMaskTarget.tsx (1)

Line range hint 6-6: Use of multiple Recoil hooks.

The component uses multiple Recoil hooks (useRecoilValue, useRecoilState) effectively to manage global state. This is a good practice in Recoil-based applications, ensuring that the component reacts to state changes efficiently.

app/packages/core/src/components/Common/Input.tsx (1)

159-239: Robust error handling added to NumberInput.

The addition of error handling logic in the NumberInput component is a significant improvement. It enhances the user experience by providing immediate feedback on input validity. The implementation of useState for managing the error state and the handleBlur function for onBlur event handling are well-integrated.

Tools
Biome

[error] 170-170: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 223-223: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 232-232: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

fiftyone/core/plots/plotly.py (1)

1523-1523: Review of _get_continuous_color function sorting addition.

The addition of sorting to the colorscale list ensures that the colors are processed in ascending order based on the first element of each tuple. This is crucial for the correct functioning of the color interpolation logic that follows, ensuring that the colors are interpolated correctly based on the sorted order.

This change aligns with the PR's objective to enhance the clarity and correctness of color handling in plots, particularly ensuring that the colorscale is correctly applied. The sorting logic is implemented efficiently and should not introduce significant overhead.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
app/packages/core/src/components/Common/Input.tsx (1)

169-176: LGTM, but consider using optional chaining for better safety.

The code changes are approved. The handleBlur function is implemented correctly to validate the input and update the error state.

However, the static analysis tool suggests using optional chaining for onBlur to enhance code safety and readability. This change would prevent potential runtime errors when onBlur is undefined.

Apply this diff to implement optional chaining:

- onBlur && onBlur();
+ onBlur?.();
Tools
Biome

[error] 170-170: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bf29aca and 848abfc.

Files selected for processing (11)
  • app/packages/core/src/components/ColorModal/colorPalette/Colorscale.tsx (7 hunks)
  • app/packages/core/src/components/ColorModal/colorPalette/DefaultMaskTargets.tsx (1 hunks)
  • app/packages/core/src/components/ColorModal/colorPalette/FieldsMaskTarget.tsx (1 hunks)
  • app/packages/core/src/components/ColorModal/controls/IdxColorList.tsx (4 hunks)
  • app/packages/core/src/components/ColorModal/controls/ManualColorScaleList.tsx (2 hunks)
  • app/packages/core/src/components/ColorModal/utils.ts (1 hunks)
  • app/packages/core/src/components/Common/Input.tsx (3 hunks)
  • docs/source/user_guide/app.rst (1 hunks)
  • docs/source/user_guide/using_datasets.rst (2 hunks)
  • fiftyone/core/odm/dataset.py (6 hunks)
  • fiftyone/core/plots/plotly.py (1 hunks)
Files skipped from review as they are similar to previous changes (8)
  • app/packages/core/src/components/ColorModal/colorPalette/Colorscale.tsx
  • app/packages/core/src/components/ColorModal/colorPalette/DefaultMaskTargets.tsx
  • app/packages/core/src/components/ColorModal/colorPalette/FieldsMaskTarget.tsx
  • app/packages/core/src/components/ColorModal/controls/IdxColorList.tsx
  • app/packages/core/src/components/ColorModal/controls/ManualColorScaleList.tsx
  • docs/source/user_guide/app.rst
  • docs/source/user_guide/using_datasets.rst
  • fiftyone/core/plots/plotly.py
Additional context used
Path-based instructions (2)
app/packages/core/src/components/Common/Input.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/core/src/components/ColorModal/utils.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Biome
app/packages/core/src/components/Common/Input.tsx

[error] 170-170: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 223-223: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 232-232: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (14)
app/packages/core/src/components/Common/Input.tsx (4)

159-167: LGTM!

The code changes are approved. The introduction of the error state variable and the construction of the error message based on the min and max props are implemented correctly. This will provide useful feedback to the user about the input constraints.


178-184: LGTM!

The code changes are approved. The useEffect hook is implemented correctly to validate the input whenever the value or validator changes and update the error state accordingly. This ensures that the error message is always in sync with the current input value and validation rules.


223-223: The suggestion to use optional chaining for onKeyDown is valid but has already been covered in a previous review comment. Please refer to that comment for the recommended changes.

Tools
Biome

[error] 223-223: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


232-232: The suggestion to use optional chaining for onFocus is valid but has already been covered in a previous review comment. Please refer to that comment for the recommended changes.

Tools
Biome

[error] 232-232: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

app/packages/core/src/components/ColorModal/utils.ts (1)

205-206: ** Address the concerns raised in the previous review comment.**

The past review comment is still valid as the validation logic has been further simplified without addressing the following concerns:

  • The function now accepts a broader range of input types (number | string | undefined), which increases flexibility but could lead to issues with type safety if non-numeric strings are passed. Consider adding explicit type checks to ensure the input can be reliably converted to a number.
  • The previous validation criteria, which required the value to be within the range of 1 to 255, have been removed. Clarify if this change is intended or if the range check needs to be added back.

Apply this diff to address the concerns:

-export const validateIntMask = (value: number | string | undefined) => {
-  if (!value || !Number.isInteger(Number(value)) || Number(value) <= 0) {
+export const validateIntMask = (value: number | string | undefined) => {
+  if (typeof value !== 'number' && typeof value !== 'string') {
+    return false;
+  }
+  const numValue = Number(value);
+  if (!Number.isInteger(numValue) || numValue < 1 || numValue > 255) {
     return false;
   }
   return true;
fiftyone/core/odm/dataset.py (9)

179-179: LGTM!

The code change is approved. The color_by parameter has been updated to indicate that colors should be assigned based on dataset values.


194-194: LGTM!

The code change is approved. The comment provides useful guidance to users about not defining intTarget 0 in maskTargetsColors.


211-211: LGTM!

The code change is approved. The comment provides useful guidance to users about the valid range for value in colorscales.


225-225: LGTM!

The code change is approved. The comment provides useful guidance to users about not defining intTarget 0 in default_mask_targets_colors.


317-319: LGTM!

The code change is approved. Calling the clean method during initialization ensures that the ColorScheme instance is validated.


325-331: LGTM!

The code change is approved. The clean method ensures that various properties of the ColorScheme instance are validated, including color_by, opacity, and mask target colors.


333-337: LGTM!

The code change is approved. The _validate_color_by method ensures that color_by must be one of the specified values.


339-341: LGTM!

The code change is approved. The _validate_opacity method ensures that opacity must be between 0 and 1.


343-455: LGTM!

The code changes are approved. The added validation methods, including _validate_default_mask_targets_colors, _validate_fields, _validate_mask_targets, _validate_colorscales, _validate_default_colorscale, and _validate_single_colorscale, enhance the robustness and clarity of the color scheme configuration, making it easier for users to understand and utilize the color settings effectively.

These methods ensure that various properties of the ColorScheme instance are validated, such as:

  • Default mask target colors must have positive integer intTarget values.
  • Fields must have a path specified.
  • Mask targets must have positive integer intTarget values.
  • Colorscales must be a list or None.
  • Default colorscale must be a dict with either a name or a list.
  • Single colorscale must be a dict with either a name or a list, and the list must have colors defined for 0 and 1.

The added validation logic improves the user experience by providing immediate error messages when invalid arguments are input, preventing confusion and ensuring correct usage.

@@ -315,6 +316,137 @@ def _id(self):
def _id(self, value):
self.id = str(value)

def _validate(self):
Copy link
Contributor

@brimoor brimoor Sep 12, 2024

Choose a reason for hiding this comment

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

@lanzhenw I changed this to a private _validate() method because if we were to implement it as clean(), it would cause it to become impossible to load an existing dataset that happens to have an invalid color scheme:

dataset = fo.load_dataset("dataset-with-invalid-color-scheme")
# ValueError: color_by field "foo" is invalid

The only backwards compatible thing I can think of to do is provide a method that users can manually call to check if their color scheme is valid or not.

- ``color``: a color string

Note that the pixel value ``0`` is a reserved "background" class
Copy link
Contributor

Choose a reason for hiding this comment

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

@lanzhenw if this is not already the case, can you update the frontend so that if maskTargets are provided that contain target=0, it will simply ignore the value rather than crashing?

Here's how this is documented for Segmentation fields:
Screenshot 2024-09-11 at 11 26 35 PM

Note that it doesn't say that target=0 is not allowed. It just says that this is a special value that is always rendered as invisible in the App, which means that if the user provided 0: "background" in their mask targets, then they won't see background in the tooltip when hovering over 0 pixels in the App.

The consistent behavior for color schemes would be to silently ignore a color if it is provided for pixel value 0.

Copy link
Contributor Author

@lanzhenw lanzhenw Sep 13, 2024

Choose a reason for hiding this comment

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

Just tested. It's behaving as you suggested: color schemes would be to silently ignore a color if it is provided for pixel value 0.

Screenshot 2024-09-13 at 11 39 37 AM

Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

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

The backend aspects of this LGTM to me now, but I need to defer to @benjaminpkane for review of the frontend aspects (I have not tested this locally)

Also seeking confirmation from @lanzhenw that the App will indeed gracefully ignore target=0 mask targets if provided.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
app/packages/core/src/components/Common/Input.tsx (1)

187-239: Rendering logic looks good! Consider using optional chaining for better safety.

The rendering logic is correctly modified to include the ErrorMessage component for displaying error messages. The conditional rendering based on the error state is implemented correctly.

The static analysis tool suggests using optional chaining at several places to enhance code safety and readability. This change would prevent potential runtime errors when accessing properties on undefined objects.

Apply this diff to implement optional chaining:

- onBlur && onBlur();
+ onBlur?.();

- onKeyDown && onKeyDown(e);
+ onKeyDown?.(e);

- onFocus && onFocus();
+ onFocus?.();
Tools
Biome

[error] 223-223: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 232-232: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5f43d2f and 2b59cc7.

Files selected for processing (11)
  • app/packages/core/src/components/ColorModal/colorPalette/Colorscale.tsx (6 hunks)
  • app/packages/core/src/components/ColorModal/colorPalette/DefaultMaskTargets.tsx (0 hunks)
  • app/packages/core/src/components/ColorModal/colorPalette/FieldsMaskTarget.tsx (0 hunks)
  • app/packages/core/src/components/ColorModal/controls/IdxColorList.tsx (4 hunks)
  • app/packages/core/src/components/ColorModal/controls/ManualColorScaleList.tsx (2 hunks)
  • app/packages/core/src/components/ColorModal/utils.ts (1 hunks)
  • app/packages/core/src/components/Common/Input.tsx (3 hunks)
  • docs/source/user_guide/app.rst (1 hunks)
  • docs/source/user_guide/using_datasets.rst (1 hunks)
  • fiftyone/core/odm/dataset.py (6 hunks)
  • fiftyone/core/plots/plotly.py (1 hunks)
Files not reviewed due to no reviewable changes (2)
  • app/packages/core/src/components/ColorModal/colorPalette/DefaultMaskTargets.tsx
  • app/packages/core/src/components/ColorModal/colorPalette/FieldsMaskTarget.tsx
Files skipped from review as they are similar to previous changes (8)
  • app/packages/core/src/components/ColorModal/colorPalette/Colorscale.tsx
  • app/packages/core/src/components/ColorModal/controls/IdxColorList.tsx
  • app/packages/core/src/components/ColorModal/controls/ManualColorScaleList.tsx
  • app/packages/core/src/components/ColorModal/utils.ts
  • docs/source/user_guide/app.rst
  • docs/source/user_guide/using_datasets.rst
  • fiftyone/core/odm/dataset.py
  • fiftyone/core/plots/plotly.py
Additional context used
Path-based instructions (1)
app/packages/core/src/components/Common/Input.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Biome
app/packages/core/src/components/Common/Input.tsx

[error] 170-170: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 223-223: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 232-232: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (2)
app/packages/core/src/components/Common/Input.tsx (2)

35-40: LGTM!

The ErrorMessage styled component is correctly defined and styled for displaying error messages.


159-184: Great job adding error handling!

The error handling logic is correctly implemented using the useState and useEffect hooks. The error message construction based on min and max props, the handleBlur function for input validation, and the useEffect hook for keeping the error state in sync with the input value and validator are all implemented correctly.

Tools
Biome

[error] 170-170: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
app/packages/core/src/components/Common/Input.tsx (1)

170-170: Consider using optional chaining for better safety.

The static analysis tool suggests using optional chaining at several places to enhance code safety and readability. This change would prevent potential runtime errors when accessing properties on undefined objects.

Apply this diff to implement optional chaining:

- onBlur && onBlur();
+ onBlur?.();

- onKeyDown && onKeyDown(e);
+ onKeyDown?.(e);

- onFocus && onFocus();
+ onFocus?.();

Also applies to: 223-223, 232-232

Tools
Biome

[error] 170-170: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 844a11d and 6f9641a.

Files selected for processing (1)
  • app/packages/core/src/components/Common/Input.tsx (3 hunks)
Additional context used
Path-based instructions (1)
app/packages/core/src/components/Common/Input.tsx (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Biome
app/packages/core/src/components/Common/Input.tsx

[error] 170-170: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 223-223: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 232-232: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (1)
app/packages/core/src/components/Common/Input.tsx (1)

159-184: Excellent work on improving the error handling and user feedback!

The added error handling logic and rendering of error messages greatly enhance the user experience by providing immediate feedback on input validity. The error state variable is appropriately managed using the useState hook, and the handleBlur function and useEffect hook ensure that the error state is kept in sync with the input value.

The ErrorMessage styled component is a nice touch for displaying the error message below the input field when an error is present.

Also applies to: 187-239

Tools
Biome

[error] 170-170: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Comment on lines +82 to +87
if (list[0].value !== 0) {
list.unshift({ value: 0, color: list[0].color });
}
if (list[list.length - 1].value !== 1) {
list.push({ value: 1, color: list[list.length - 1].color });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@lanzhenw lanzhenw merged commit 3d0fc24 into develop Sep 19, 2024
13 of 14 checks passed
@lanzhenw lanzhenw deleted the improveColorDoc branch September 19, 2024 16:48
@coderabbitai coderabbitai bot mentioned this pull request Sep 19, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Issues related to App features documentation Documentation work enhancement Code enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants