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

Add total voxel count and dataset extent to tooltip in dataset info tab #8229

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

dieknolle3333
Copy link
Contributor

@dieknolle3333 dieknolle3333 commented Nov 25, 2024

Screenshot from 2024-11-25 14-39-07

URL of deployed dev instance (used for testing):

Steps to test:

  • Open any annotation or DS in view mode
  • go to dataset info tab
  • hover above icon next to factorized dataset extent in unit and in vx
  • read the product of the extent in vx and unit :)

TODOs:

  • make sure it looks good with large numbers, use scientific notation for large numbers? (found method to format vx)

Issues:


(Please delete unneeded items, merge only when none are left open)

@dieknolle3333 dieknolle3333 self-assigned this Nov 25, 2024
Copy link

coderabbitai bot commented Nov 25, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces several enhancements to the WEBKNOSSOS application, including the addition of a tooltip displaying the total volume of datasets in both voxel and physical units. It modifies the handling of remote URIs by ignoring format prefixes, improves asynchronous image file reading, and enhances error messages related to dataset jobs. Bug fixes address performance issues and incorrect segment color updates. Additionally, the integration with Google Analytics has been removed.

Changes

File Path Change Summary
frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts Added functions for calculating dataset extents in voxel and unit formats.
frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx Updated DatasetExtentRow and FastTooltip components to display formatted dataset extents.
frontend/javascripts/libs/format_utils.ts Enhanced error handling in the formatVoxels function.

Assessment against linked issues

Objective Addressed Explanation
Add a tooltip that shows the total number of voxels in a dataset (#8128)

Possibly related PRs

Suggested labels

enhancement, frontend

Suggested reviewers

  • fm3
  • MichaelBuessemeyer

Poem

🐰 In the dataset's vast, a volume to see,
A tooltip now whispers, "Look here, follow me!"
With colors that change, and formats so bright,
Our data's a treasure, a true delight!
So hop on this journey, let’s explore and play,
With every new feature, we brighten the way! 🌟


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@dieknolle3333 dieknolle3333 marked this pull request as ready for review November 25, 2024 13:46
Copy link

@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: 1

🧹 Outside diff range and nitpick comments (5)
CHANGELOG.unreleased.md (1)

15-15: Enhance the changelog entry with more specific details.

The current entry could be more descriptive about the tooltip's functionality. Consider expanding it to explicitly mention both display units and its location.

-Added the total volume of a dataset to a tooltip in the dataset info tab. [#8229](https://github.com/scalableminds/webknossos/pull/8229)
+Added a tooltip in the dataset info tab displaying the total volume of a dataset in both voxel count and physical units, shown next to the factorized dataset extent. [#8229](https://github.com/scalableminds/webknossos/pull/8229)
frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx (2)

133-136: Fix variable naming convention

The variable name has inconsistent casing.

-  const formattedExtentinUnit = formatNumberToVolume(
+  const formattedExtentInUnit = formatNumberToVolume(

138-148: Enhance tooltip content formatting

Consider improving the tooltip's readability by:

  1. Adding labels for each value
  2. Using consistent spacing
   const renderDSExtentTooltip = () => {
     return (
       <div>
-        Dataset extent:
+        <strong>Dataset Extent</strong>
         <br />
-        {formatVoxels(extentProductInVx)}
-        <br />
-        {formattedExtentinUnit}
+        Volume: {formatVoxels(extentProductInVx)}
+        <br />
+        Physical Volume: {formattedExtentInUnit}
       </div>
     );
   };
frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts (2)

355-360: Add JSDoc documentation for the new exported functions.

The functions should be documented to explain their purpose, parameters, return values, and potential errors.

+/**
+ * Calculates the total number of voxels in the dataset by multiplying width, height, and depth.
+ * @param dataset The dataset to calculate the extent for
+ * @returns The total number of voxels
+ * @throws {Error} If the product exceeds the maximum safe number
+ */
 export function getDatasetExtentInVoxelAsProduct(dataset: APIDataset) {
   return getDataSetExtentAsProduct(getDatasetExtentInVoxel(dataset));
 }

+/**
+ * Calculates the total volume of the dataset in physical units by multiplying width, height, and depth.
+ * @param dataset The dataset to calculate the extent for
+ * @returns The total volume in dataset units
+ * @throws {Error} If the product exceeds the maximum safe number
+ */
 export function getDatasetExtentInUnitAsProduct(dataset: APIDataset) {
   return getDataSetExtentAsProduct(getDatasetExtentInUnit(dataset));
 }

355-360: Consider memoizing the extent product calculations.

Since these functions might be called frequently (e.g., in UI renders) and datasets are typically immutable, consider memoizing the results using the existing memoization pattern from the codebase.

+const _getDatasetExtentInVoxelAsProduct = (dataset: APIDataset) => {
+  return getDataSetExtentAsProduct(getDatasetExtentInVoxel(dataset));
+};
+
+export const getDatasetExtentInVoxelAsProduct = memoizeOne(_getDatasetExtentInVoxelAsProduct);
+
+const _getDatasetExtentInUnitAsProduct = (dataset: APIDataset) => {
+  return getDataSetExtentAsProduct(getDatasetExtentInUnit(dataset));
+};
+
+export const getDatasetExtentInUnitAsProduct = memoizeOne(_getDatasetExtentInUnitAsProduct);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bf6ea15 and 3c7e9bb.

📒 Files selected for processing (3)
  • CHANGELOG.unreleased.md (1 hunks)
  • frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts (1 hunks)
  • frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx (2 hunks)
🔇 Additional comments (3)
frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx (2)

9-14: LGTM: Import changes align with new functionality

The new imports support the addition of volume calculations and unit conversions for the dataset extent tooltip.


131-151: LGTM: Dataset extent tooltip implementation

The implementation successfully:

  • Calculates total volume in both voxels and physical units
  • Provides clear tooltip information
  • Uses proper unit conversion

Let's verify the usage of the formatting utilities:

✅ Verification successful

Based on the search results, I can now generate the final response since I have sufficient information about the formatting utilities. The test cases in format_utils.spec.ts show comprehensive coverage of various scenarios:

Verified: Dataset extent tooltip uses robust formatting utilities

The implementation is correct and robust because:

  • formatNumberToVolume handles a wide range of volumes from very small (1e-33 nm³) to very large (1234e33 m³)
  • Unit conversions are properly tested (mm³ to cm³, µm³ to cm³, etc.)
  • formatVoxels has safeguards for large numbers (>2^50) using PVx notation
  • Both functions are well-tested with edge cases and maintain consistent precision
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of formatNumberToVolume and formatVoxels
# to ensure they handle large numbers appropriately

# Search for test cases of these formatting functions
rg -A 5 "formatNumberToVolume|formatVoxels" --type ts

Length of output: 12109

frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts (1)

355-360: LGTM! Clean integration with existing extent-related functions.

The new functions properly build upon existing functionality and maintain consistency with the codebase.

Copy link

@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 (2)
frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx (2)

131-151: LGTM with minor suggestions for tooltip content

The implementation correctly calculates and displays both voxel and unit volumes. Consider enhancing the tooltip content to be more descriptive:

-        Dataset extent:
+        Total Dataset Volume:
         <br />
-        {extentProductInVx != null ? formatVoxels(extentProductInVx) : "Unable to calculate"}
+        Voxels: {extentProductInVx != null ? formatVoxels(extentProductInVx) : "Unable to calculate"}
         <br />
-        {formattedExtentinUnit}
+        Physical Volume: {formattedExtentinUnit}

133-139: Consider enhancing number formatting for better readability

For large datasets, the volume numbers could become quite large. Consider adding options for scientific notation or appropriate number grouping to improve readability.

Example implementation:

const formattedExtentinUnit =
  extentProductInUnit != null
    ? formatNumberToVolume(
        extentProductInUnit,
        LongUnitToShortUnitMap[dataset.dataSource.scale.unit],
+       { useScientificNotation: extentProductInUnit > 1e6 }
      )
    : "Unable to calculate";
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3c7e9bb and b5b12df.

📒 Files selected for processing (2)
  • frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts (1 hunks)
  • frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts
🔇 Additional comments (1)
frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx (1)

9-14: LGTM: Import statements are well-organized

The new imports are properly structured and align with the PR's objective of adding volume calculations to the tooltip.

Copy link

@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 (3)
CHANGELOG.unreleased.md (1)

15-15: Enhance the changelog entry to better reflect the implemented features.

The current entry could be more specific about the tooltip's functionality. Consider revising it to explicitly mention both the voxel count and physical unit representation.

- Added the total volume of a dataset to a tooltip in the dataset info tab. [#8229](https://github.com/scalableminds/webknossos/pull/8229)
+ Added a tooltip in the dataset info tab displaying the total dataset volume in both voxel count and physical units. [#8229](https://github.com/scalableminds/webknossos/pull/8229)
frontend/javascripts/libs/format_utils.ts (1)

Line range hint 535-535: Fix inconsistent unit suffix for small numbers.

The function returns "B" for small numbers while using "Vx" (voxels) as the unit suffix for larger numbers. This inconsistency could confuse users.

Apply this diff to fix the inconsistency:

-  return `${voxelCount} B`;
+  return `${voxelCount} Vx`;
frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts (1)

349-355: Consider handling numeric overflow for large datasets.

The multiplication of dimensions could potentially overflow for large datasets. Consider using safe multiplication or handling overflow cases.

 function getDatasetExtentAsProduct(extent: {
   width: number;
   height: number;
   depth: number;
 }) {
-  return extent.width * extent.height * extent.depth;
+  const result = extent.width * extent.height * extent.depth;
+  if (!Number.isFinite(result)) {
+    // For very large datasets, return Infinity instead of NaN
+    return Number.POSITIVE_INFINITY;
+  }
+  return result;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b5b12df and 3feaa7f.

📒 Files selected for processing (4)
  • CHANGELOG.unreleased.md (1 hunks)
  • frontend/javascripts/libs/format_utils.ts (1 hunks)
  • frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts (1 hunks)
  • frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx
🧰 Additional context used
📓 Learnings (1)
frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts (1)
Learnt from: dieknolle3333
PR: scalableminds/webknossos#8229
File: frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts:348-354
Timestamp: 2024-11-25T14:38:49.345Z
Learning: For the `getDatasetExtentAsProduct` function in `dataset_accessor.ts`, input validation for negative or zero dimensions is not necessary.
🔇 Additional comments (7)
CHANGELOG.unreleased.md (1)

Line range hint 1-24: LGTM! Well-structured changelog following best practices.

The changelog is well-organized, with appropriate categorization of changes and consistent formatting throughout. Each entry includes a PR reference, making it easy to track the source of changes.

frontend/javascripts/libs/format_utils.ts (4)

516-521: LGTM! Improved edge case handling.

The separation of null and non-finite checks makes the code more maintainable and explicit.


Line range hint 522-534: LGTM! Well-implemented large number formatting.

The implementation:

  • Uses appropriate binary prefixes (K, M, G, T, P)
  • Maintains consistent precision using toPrecision(4)
  • Follows the established pattern used in other formatting functions

Line range hint 516-535: Verify function usage and test coverage.

Let's verify the usage of this function and ensure test coverage for the new edge cases.

✅ Verification successful

Based on the shell script results, I can now provide a final response:

The formatVoxels function is properly used and tested in the codebase.

The function is used in two specific locations:

  • frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx: For displaying the total voxel count in the dataset info tab
  • frontend/javascripts/oxalis/view/jobs/train_ai_model.tsx: For showing bounding box voxel counts in the AI model training view

The implementation follows the same pattern as other similar formatting functions in the file (like formatBytes), and the usage is consistent with the PR's objective of displaying voxel counts in a human-readable format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage of formatVoxels function and related test files

# Find all files that import or use formatVoxels
echo "Files using formatVoxels:"
rg "formatVoxels" --type ts --type tsx

# Look for related test files
echo -e "\nRelated test files:"
fd "format.*test\.(ts|tsx)$"

# Check for existing test cases in test files
echo -e "\nExisting test cases:"
rg "test|describe.*formatVoxels" --type ts --type tsx

Length of output: 354


Script:

#!/bin/bash
# Let's try a different approach with more specific commands

# Search for formatVoxels usage with ripgrep
echo "Files using formatVoxels:"
rg "formatVoxels" -t typescript

# Find test files related to format utils
echo -e "\nFormat util test files:"
find . -type f -name "format*test.ts" -o -name "format*test.tsx"

# Check content of format utils test file
echo -e "\nTest file content:"
find . -type f -name "format*test.ts" -o -name "format*test.tsx" -exec cat {} \;

# Look for any imports of format_utils
echo -e "\nFiles importing from format_utils:"
rg "from.*format_utils" -t typescript

Length of output: 556


Script:

#!/bin/bash
# Let's try without file type specifications and use simpler commands

# Search for formatVoxels usage
echo "Files using formatVoxels:"
rg "formatVoxels"

# Find test files
echo -e "\nFormat util test files:"
rg "format_utils.*test" --files-with-matches

# Look for imports
echo -e "\nFiles importing format_utils:"
rg "import.*format_utils"

# Check the content of the format_utils.ts file
echo -e "\nFormat utils implementation:"
cat frontend/javascripts/libs/format_utils.ts

Length of output: 21417


Line range hint 516-535: Verify physical unit display implementation.

The PR objective mentions displaying both voxel count and physical unit in the tooltip. While this function handles the voxel count formatting, let's verify the physical unit display implementation.

✅ Verification successful

Physical unit display is properly implemented.

Looking at the DatasetExtentRow component in dataset_info_tab_view.tsx, both voxel count and physical unit are displayed in the tooltip. The component uses formatVoxels for voxel count and formatNumberToVolume with the appropriate unit for physical size. This is exactly what was intended in the PR objective.

Example from the code:

const renderDSExtentTooltip = () => {
  return (
    <div>
      Dataset extent:
      <br />
      {formatVoxels(extentProductInVx)}
      <br />
      {formattedExtentinUnit}
    </div>
  );
};
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Look for code handling physical unit display in the dataset info tab

# Search for dataset info tab component
echo "Dataset info tab implementation:"
fd "dataset.*info.*tab" --type ts --type tsx

# Look for tooltip implementations
echo -e "\nTooltip implementations:"
rg "tooltip.*dataset.*extent|dataset.*extent.*tooltip" --type ts --type tsx

Length of output: 462


Script:

#!/bin/bash
# Search for dataset info tab component with correct file extensions
echo "Dataset info tab implementation:"
fd "dataset.*info.*tab" -e ts -e tsx

# Look for tooltip implementations without file type restrictions
echo -e "\nTooltip and extent related implementations:"
rg "tooltip.*dataset.*extent|dataset.*extent.*tooltip|extent.*tooltip"

# Search for physical unit related code
echo -e "\nPhysical unit related code:"
rg "physical.*unit|unit.*display|extent.*unit"

# Look for other tooltip implementations in the same directory
echo -e "\nTooltip implementations in format_utils and nearby files:"
rg "tooltip" frontend/javascripts/libs/

Length of output: 1119


Script:

#!/bin/bash
# Let's examine the dataset info tab view implementation
echo "Dataset info tab view content:"
cat frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx

# Look for voxel size and extent related code
echo -e "\nVoxel size and extent related code in format_utils:"
rg -A 5 "voxel.*size|extent" frontend/javascripts/libs/format_utils.ts

# Check for other formatting functions in format_utils
echo -e "\nOther formatting functions in format_utils:"
ast-grep --pattern 'function $NAME($$$) {
  $$$
}'  frontend/javascripts/libs/format_utils.ts

Length of output: 26032

frontend/javascripts/oxalis/model/accessors/dataset_accessor.ts (2)

356-358: LGTM! Clean and focused implementation.

The function correctly uses the existing getDatasetExtentInVoxel function to calculate the total voxel count.


359-361: LGTM! Clean and focused implementation.

The function correctly uses the existing getDatasetExtentInUnit function to calculate the total volume in physical units.

Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

lgtm! only see my one nitpick before merging.

Copy link

@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)
frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx (1)

139-149: Enhance tooltip accessibility and semantics

Consider these improvements for better accessibility and semantic structure:

 const renderDSExtentTooltip = () => {
   return (
-    <div>
+    <div role="tooltip" aria-label="Dataset extent information">
-      Dataset extent:
-      <br />
-      {formatVoxels(extentProductInVx)}
-      <br />
-      {formattedExtentInUnit}
+      <strong>Dataset extent:</strong>
+      <dl>
+        <dt>Voxels:</dt>
+        <dd>{formatVoxels(extentProductInVx)}</dd>
+        <dt>Volume:</dt>
+        <dd>{formattedExtentInUnit}</dd>
+      </dl>
     </div>
   );
 };

This change:

  • Adds ARIA attributes for better screen reader support
  • Uses semantic HTML elements (dl, dt, dd) for better structure
  • Improves visual hierarchy with strong element
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3feaa7f and dc4b3c5.

📒 Files selected for processing (2)
  • CHANGELOG.unreleased.md (1 hunks)
  • frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.unreleased.md
🔇 Additional comments (2)
frontend/javascripts/oxalis/view/right-border-tabs/dataset_info_tab_view.tsx (2)

9-14: LGTM! Import changes are well-organized

The new imports are properly structured and align with the feature requirements for calculating and displaying dataset volumes.


132-137: LGTM! Volume calculations are properly implemented

The implementation correctly calculates and formats the dataset extent in both voxels and physical units, aligning with the PR objectives.

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.

Tooltip with voxel count
2 participants