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(20221): Apply maxzoom for Bivariate and MCDA layers based on Indicators maxZoom property #923

Conversation

albaranau
Copy link
Contributor

@albaranau albaranau commented Dec 11, 2024

https://kontur.fibery.io/Tasks/Task/FE-Apply-maxzoom-for-bivariate-MCDA-layers-based-on-indicators-metadata-20221

Summary by CodeRabbit

  • New Features

    • Enhanced indicator structure with a new direction property for better context.
    • Dynamic calculation of maximum zoom levels for MCDA and bivariate layers.
  • Bug Fixes

    • Removed unused import statements to clean up code.
  • Tests

    • Introduced a new test suite for validating maximum zoom level calculations.
    • Added test cases to ensure correct functionality of zoom level determination.
  • Documentation

    • Updated comments in the MCDALayer interface regarding future changes.

@albaranau albaranau requested a review from a team December 11, 2024 22:24
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The pull request introduces several modifications across multiple files, primarily enhancing the handling of zoom levels in MCDA and bivariate layers. Key changes include the addition of direction properties to indicators, updates to the MCDALayer interface, and the introduction of new functions for calculating maximum zoom levels. Additionally, test files have been created or modified to validate these functionalities. Overall, the changes improve the structural integrity of the data models and enhance the dynamic computation of zoom levels based on configurations.

Changes

File Change Summary
src/core/logical_layers/renderers/stylesConfigs/mcda/calculations/calculateLayerPipeline.test.ts Added direction properties to indicator_numerator and indicator_denominator in DEFAULT_AXIS.
src/core/logical_layers/renderers/stylesConfigs/mcda/calculations/calculations.test.ts Enhanced TEST_MCDA_LAYER by adding direction properties to its indicators.
src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.test.ts Removed unused import for MCDAConfig, added direction properties to layer1 and layer2 indicators.
src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts Introduced getMaxMCDAZoomLevel function and updated createMCDAStyle to compute maxZoom dynamically.
src/core/logical_layers/renderers/stylesConfigs/mcda/types.ts Updated MCDALayer interface to include direction in indicators.
src/features/bivariate_color_manager/atoms/bivariateColorManagerSamleMap.ts Added getMaxNumeratorZoomLevel import and updated generateLayerStyles to calculate maxZoom.
src/features/mcda/atoms/mcdaLayer.ts Imported getMaxMCDAZoomLevel and modified maxZoom property assignment to use this function.
src/utils/bivariate/bivariateColorThemeUtils.ts Added getMaxNumeratorZoomLevel import and updated functions to use maxZoomLevel instead of meta.
src/utils/bivariate/getMaxZoomLevel.test.ts Created a new test suite for getMaxNumeratorZoomLevel with multiple test cases.
src/utils/bivariate/getMaxZoomLevel.ts Introduced getMaxMCDAZoomLevel and getMaxNumeratorZoomLevel functions for dynamic maximum zoom level calculations.
src/utils/bivariate/types/stat.types.ts Added optional maxZoom property to the Indicator type.
src/core/logical_layers/renderers/BivariateRenderer/BivariateRenderer.tsx Updated mountBivariateLayer to use getMaxNumeratorZoomLevel for setting maxzoom and refined popup visibility logic in addBivariatePopup.
src/core/logical_layers/renderers/BivariateRenderer/constants.ts Updated FALLBACK_BIVARIATE_MAX_ZOOM constant value from 14 to 9.

Poem

In the layers deep where the data flows,
A new direction for indicators grows.
With zoom levels calculated on the fly,
Our MCDA style reaches for the sky!
So hop along, let’s celebrate this cheer,
For every change brings us closer, my dear! 🐰✨

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

Copy link

Language To Recheck Fuzzy Untranslated Total
ar 3 24 101 128
de 2 24 101 127
es 3 24 101 128
id 2 24 101 127
ko 3 24 101 128
uk 0 7 8 15

Copy link

github-actions bot commented Dec 11, 2024

Bundle size diff

Old size New size Diff
5.14 MB 5.14 MB 351 B (0.01%)

Copy link

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 35.29412% with 22 lines in your changes missing coverage. Please review.

Project coverage is 9.57%. Comparing base (2db1802) to head (ebddfbe).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/utils/bivariate/bivariateColorThemeUtils.ts 0.00% 6 Missing ⚠️
.../renderers/BivariateRenderer/BivariateRenderer.tsx 0.00% 4 Missing ⚠️
...lor_manager/atoms/bivariateColorManagerSamleMap.ts 0.00% 4 Missing ⚠️
src/utils/bivariate/getMaxZoomLevel.ts 73.33% 4 Missing ⚠️
...l_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts 0.00% 2 Missing ⚠️
src/features/mcda/atoms/mcdaLayer.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##            main    #923    +/-   ##
======================================
  Coverage   9.56%   9.57%            
======================================
  Files        662     668     +6     
  Lines      28862   29261   +399     
  Branches    1169    1189    +20     
======================================
+ Hits        2761    2802    +41     
- Misses     25576   25930   +354     
- Partials     525     529     +4     
Components Coverage Δ
UI Components 0.26% <ø> (-0.01%) ⬇️
Core Logic 15.75% <14.28%> (-0.11%) ⬇️
Features 1.13% <0.00%> (-0.01%) ⬇️
Utilities 47.84% <52.38%> (-0.75%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Preview environments for this PR:

These previews are automatically updated with each commit.

Note: After a new deployment, it may take a few minutes for the changes to propagate and for caches to update. During this time, you might experience temporary loading issues or see an older version of the app. If the app fails to load, please wait a few minutes and try again.

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: 5

🧹 Outside diff range comments (3)
src/core/logical_layers/renderers/stylesConfigs/mcda/types.ts (1)

Line range hint 32-38: Track TODOs for future breaking changes.

The comments indicate upcoming breaking changes:

  1. The axis field may be removed/renamed
  2. The transformationFunction may become required

Consider creating tracking issues for these changes to ensure they're not forgotten.

Would you like me to create GitHub issues to track these upcoming changes?

src/core/logical_layers/renderers/stylesConfigs/mcda/calculations/calculations.test.ts (1)

Line range hint 1-1: Review Summary: Implementation Incomplete

While the PR adds the maxZoom property to the Indicator type, there are several concerns:

  1. The implementation lacks test coverage for maxZoom functionality
  2. Several changes (direction property additions) appear unrelated to the PR objective
  3. The maxZoom property could benefit from type constraints

Recommendations:

  1. Add comprehensive test coverage for maxZoom functionality
  2. Consider moving direction-related changes to a separate PR
  3. Add type constraints for the maxZoom property
src/utils/bivariate/bivariateColorThemeUtils.ts (1)

Line range hint 1-1: Consider centralizing zoom level constants

Currently, zoom level fallbacks and calculations are spread across MCDA and Bivariate implementations. Consider creating a centralized zoom level management module to improve maintainability.

This could include:

  1. Centralized constants for fallback values
  2. Shared utility functions for zoom level calculations
  3. Type definitions for zoom level configurations
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 75b06f3 and c8d7e66.

📒 Files selected for processing (11)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/calculations/calculateLayerPipeline.test.ts (2 hunks)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/calculations/calculations.test.ts (2 hunks)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.test.ts (4 hunks)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (3 hunks)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/types.ts (1 hunks)
  • src/features/bivariate_color_manager/atoms/bivariateColorManagerSamleMap.ts (2 hunks)
  • src/features/mcda/atoms/mcdaLayer.ts (3 hunks)
  • src/utils/bivariate/bivariateColorThemeUtils.ts (4 hunks)
  • src/utils/bivariate/getMaxZoomLevel.test.ts (1 hunks)
  • src/utils/bivariate/getMaxZoomLevel.ts (1 hunks)
  • src/utils/bivariate/types/stat.types.ts (1 hunks)
🔇 Additional comments (15)
src/utils/bivariate/getMaxZoomLevel.ts (1)

4-9: LGTM! Clean implementation of MCDA zoom level calculation.

The function effectively flattens the nested indicators structure and delegates to the generic indicator zoom calculator.

src/core/logical_layers/renderers/stylesConfigs/mcda/types.ts (1)

30-30: LGTM! Type change aligns with zoom level implementation.

The change from MCDAIndicator[] to Indicator[] properly supports the new maxZoom functionality.

src/utils/bivariate/getMaxZoomLevel.test.ts (2)

24-47: LGTM! Well-structured test data.

The test indicators are well-defined with realistic values and proper typing.


1-47: Verify usage of new zoom level functions.

Let's ensure the new functions are used consistently across the codebase.

✅ Verification successful

Based on the search results, I can now generate the final response as we have comprehensive information about the zoom level function usage across the codebase.

The zoom level functions are properly integrated and used consistently

The implementation is verified and shows proper usage:

  • getMaxIndicatorsZoomLevel is correctly used in bivariate color theme utilities and sample map components
  • getMaxMCDAZoomLevel is properly integrated in MCDA layer and style configurations
  • Both functions are used with appropriate fallback values (FALLBACK_BIVARIATE_MAX_ZOOM)
  • The maxZoom property is consistently handled across different layer types (Generic, Bivariate)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential usage of maxZoom in the codebase
echo "Searching for maxZoom usage..."
rg "maxZoom" --type ts

# Search for direct function usage
echo -e "\nSearching for function usage..."
rg "getMaxMCDAZoomLevel|getMaxIndicatorsZoomLevel" --type ts

# Look for potential zoom-related configurations
echo -e "\nSearching for zoom configurations..."
rg "zoom.*config|config.*zoom" --type ts

Length of output: 5283

src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.test.ts (1)

Line range hint 1-77: Add test coverage for maxZoom functionality

While the changes to add direction property are present, there appears to be no test coverage for the maxZoom functionality that this PR introduces. Consider adding test cases to verify:

  1. How maxZoom affects layer behavior
  2. Edge cases with missing or invalid maxZoom values

Let's check if there are any other test files covering maxZoom:

src/core/logical_layers/renderers/stylesConfigs/mcda/calculations/calculations.test.ts (1)

Line range hint 94-104: Changes appear unrelated to PR objective

The addition of direction properties seems unrelated to the PR's objective of implementing maxZoom functionality. Consider:

  1. Moving these changes to a separate PR focused on the direction feature
  2. Adding test coverage for maxZoom in the appropriate test files

Let's verify if these changes are part of a different feature:

src/features/bivariate_color_manager/atoms/bivariateColorManagerSamleMap.ts (3)

9-9: LGTM: Clean import addition

The import of getMaxIndicatorsZoomLevel aligns with the PR's objective to apply maxzoom based on indicators' properties.


69-69: LGTM: Updated function parameter

Correctly passing maxZoom to generateBivariateStyle instead of meta object.


60-63: Verify handling of empty quotients arrays

The maxZoom calculation looks good, but let's ensure it handles edge cases properly.

✅ Verification successful

Empty quotients arrays are properly handled

The implementation of getMaxIndicatorsZoomLevel safely handles empty arrays:

  • When an empty array is passed, Math.max() with spread operator returns -1
  • When -1 is detected, it returns the fallbackMaxZoom parameter
  • The optional chaining on indicator.maxZoom ?? -1 handles undefined values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if getMaxIndicatorsZoomLevel handles empty quotients gracefully
ast-grep --pattern 'getMaxIndicatorsZoomLevel($args, $_)' | rg -A 5 'getMaxIndicatorsZoomLevel'

Length of output: 95


Script:

#!/bin/bash
# Let's first find the file containing getMaxIndicatorsZoomLevel function
fd getMaxIndicatorsZoomLevel

# Then let's look at its implementation
rg -A 10 "function getMaxIndicatorsZoomLevel" 

Length of output: 808

src/features/mcda/atoms/mcdaLayer.ts (3)

20-20: LGTM: Clean import addition

The import of getMaxMCDAZoomLevel is consistent with the PR's objective.


76-76: LGTM: Proper maxZoom assignment

The maxZoom is correctly assigned in the layer source configuration.


56-56: Verify maxZoom calculation with various MCDA configurations

The maxZoom calculation looks good, but let's verify it works with different MCDA configurations.

✅ Verification successful

MaxZoom calculation implementation is robust and well-handled

The getMaxMCDAZoomLevel function correctly handles various MCDA configurations by:

  • Extracting zoom levels from all indicators across all layers
  • Using the maximum zoom level among all indicators when available
  • Falling back to a reasonable default of 14 when no zoom levels are specified
  • Properly handling undefined zoom levels with the fallback
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check MCDA configurations in the codebase
ast-grep --pattern 'type: "mcda"' | rg -B 5 -A 5 'type: "mcda"'

Length of output: 65


Script:

#!/bin/bash
# Let's check the implementation of getMaxMCDAZoomLevel function
ast-grep --pattern 'function getMaxMCDAZoomLevel' -A 10

# Also check for any MCDA zoom level related configurations
rg -i "mcda.*zoom" 

Length of output: 821


Script:

#!/bin/bash
# Let's check the implementation details of getMaxMCDAZoomLevel function
cat src/utils/bivariate/getMaxZoomLevel.ts

# Check the FALLBACK_BIVARIATE_MAX_ZOOM constant
rg "FALLBACK_BIVARIATE_MAX_ZOOM.*=" -A 1

Length of output: 918

src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (2)

201-201: LGTM: Source configuration updated

The source configuration now correctly uses the dynamically calculated maxzoom value.


16-16: LGTM: Dynamic maxzoom calculation added

The addition of getMaxMCDAZoomLevel improves layer configuration by dynamically calculating the maximum zoom level based on indicators metadata, with a sensible fallback.

Let's verify the implementation of getMaxMCDAZoomLevel:

Also applies to: 177-178

✅ Verification successful

LGTM: Dynamic maxzoom calculation verified

The implementation of getMaxMCDAZoomLevel is properly implemented and tested:

  • It uses getMaxIndicatorsZoomLevel to find the maximum zoom level from all indicators
  • Falls back to FALLBACK_BIVARIATE_MAX_ZOOM (14) when no indicators have maxZoom defined
  • Test coverage confirms both successful and fallback scenarios
  • The function is consistently used across MCDA and bivariate implementations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify getMaxMCDAZoomLevel implementation
# Expected: Function should exist and handle both valid and fallback cases

ast-grep --pattern 'function getMaxMCDAZoomLevel($_: $_) {
  $$$
}'

Length of output: 69


Script:

#!/bin/bash
# Let's try to find the file and implementation using ripgrep
rg -l "getMaxMCDAZoomLevel" --type ts

# Then examine the implementation
rg "getMaxMCDAZoomLevel" -A 10 --type ts

Length of output: 5016


Script:

#!/bin/bash
# Let's check the implementation of getMaxIndicatorsZoomLevel which is used by getMaxMCDAZoomLevel
rg "getMaxIndicatorsZoomLevel" -A 15 --type ts

# Also check for the FALLBACK_BIVARIATE_MAX_ZOOM constant
rg "FALLBACK_BIVARIATE_MAX_ZOOM" -A 2 --type ts

Length of output: 12300

src/utils/bivariate/bivariateColorThemeUtils.ts (1)

148-148: LGTM: Improved parameter typing and usage

The change from meta parameter to explicit maxZoomLevel improves type safety and makes the zoom level configuration more explicit. The source configuration correctly uses this value.

Also applies to: 166-166

Copy link

codecov bot commented Dec 11, 2024

Bundle Report

Changes will increase total bundle size by 507 bytes (0.01%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
konturio/disaster-ninja-fe-esm 5.39MB 507 bytes (0.01%) ⬆️

@albaranau albaranau marked this pull request as draft December 12, 2024 11:23
@albaranau albaranau marked this pull request as ready for review December 12, 2024 17:39
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8d7e66 and 1e4cb3a.

📒 Files selected for processing (4)
  • src/features/bivariate_color_manager/atoms/bivariateColorManagerSamleMap.ts (2 hunks)
  • src/utils/bivariate/bivariateColorThemeUtils.ts (4 hunks)
  • src/utils/bivariate/getMaxZoomLevel.test.ts (1 hunks)
  • src/utils/bivariate/getMaxZoomLevel.ts (1 hunks)
🔇 Additional comments (7)
src/utils/bivariate/getMaxZoomLevel.ts (2)

4-9: LGTM! Clean and focused implementation.

The function has a clear single responsibility of extracting indicators from MCDA config and delegating to getMaxNumeratorZoomLevel.


11-22: ⚠️ Potential issue

Add validation and consider checking all indicators.

The implementation has two potential issues:

  1. No input validation for null/empty arrays or negative fallback zoom
  2. Only checks the first indicator in each array, potentially missing relevant maxZoom values from other indicators

Consider this implementation:

 export function getMaxNumeratorZoomLevel(
   indicators: Indicator[][],
   fallbackMaxZoom: number,
 ) {
+  if (!indicators?.length) {
+    return fallbackMaxZoom;
+  }
+  if (fallbackMaxZoom < 0) {
+    throw new Error('Fallback zoom level must be non-negative');
+  }
   const maxIndicatorsZoom = Math.max(
-    ...indicators.map((indicators) => indicators[0]?.maxZoom ?? -1),
+    ...indicators.flatMap((indicatorArray) => 
+      indicatorArray.map((indicator) => indicator?.maxZoom ?? -1)
+    ),
   );
   if (maxIndicatorsZoom === -1) {
     return fallbackMaxZoom;
   }
   return maxIndicatorsZoom;
 }

Likely invalid or redundant comment.

src/utils/bivariate/getMaxZoomLevel.test.ts (1)

34-62: LGTM! Well-structured test helper.

The axisWithZoomLevels helper function provides a clean way to create test data with all required properties.

src/features/bivariate_color_manager/atoms/bivariateColorManagerSamleMap.ts (1)

60-69: LGTM! Clean integration of maxZoom calculation.

The maxZoom calculation is properly integrated:

  1. Correctly extracts quotients from both axes
  2. Uses meta.max_zoom as fallback
  3. Passes calculated maxZoom to generateBivariateStyle
src/utils/bivariate/bivariateColorThemeUtils.ts (3)

5-5: LGTM: Import changes are consistent with the new maxzoom implementation

The addition of getMaxNumeratorZoomLevel and removal of the Meta type align well with the refactoring to support dynamic maxzoom calculations.

Also applies to: 9-9


137-137: LGTM: Style generation properly implements dynamic maxzoom

The changes correctly implement the dynamic maxzoom functionality based on indicators metadata.

Let's verify if hardcoding minzoom to 0 is the intended behavior:

Also applies to: 148-148, 166-166

✅ Verification successful

Hardcoded minzoom of 0 aligns with codebase conventions

The verification shows that minzoom:0 is consistently used as a default value across the codebase, particularly in GenericRenderer. For bivariate layers, there's also a FALLBACK_BIVARIATE_MIN_ZOOM constant used in the BivariateRenderer, making the current implementation consistent with existing patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other instances of minzoom configuration in the codebase
rg -B 2 -A 2 'minzoom:' --type ts

Length of output: 3139


128-131: ⚠️ Potential issue

Fix array structure in maxZoom calculation

The current implementation creates a nested array structure [[...], [...]], which might not match what getMaxNumeratorZoomLevel expects. Additionally, we should handle undefined quotients safely.

Consider this safer implementation:

  const maxZoom = getMaxNumeratorZoomLevel(
-   [xAxis.quotients ?? [], yAxis.quotients ?? []],
+   [...(xAxis.quotients || []), ...(yAxis.quotients || [])].filter(Boolean),
    stats.meta.max_zoom,
  );

Likely invalid or redundant comment.

src/utils/bivariate/getMaxZoomLevel.test.ts Show resolved Hide resolved
Copy link
Contributor

@vkozio vkozio left a comment

Choose a reason for hiding this comment

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

see comments

src/utils/bivariate/getMaxZoomLevel.ts Outdated Show resolved Hide resolved
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e4cb3a and 9b6e0c0.

📒 Files selected for processing (4)
  • src/core/logical_layers/renderers/BivariateRenderer/BivariateRenderer.tsx (2 hunks)
  • src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (3 hunks)
  • src/utils/bivariate/bivariateColorThemeUtils.ts (4 hunks)
  • src/utils/bivariate/getMaxZoomLevel.ts (1 hunks)
🔇 Additional comments (7)
src/utils/bivariate/getMaxZoomLevel.ts (2)

4-9: LGTM! Function follows single responsibility principle.

The function cleanly extracts indicators from the config layers and delegates to getMaxNumeratorZoomLevel.


11-22: 🛠️ Refactor suggestion

Consider enhancing the zoom level calculation logic.

The current implementation has a few potential issues:

  1. Only considers the first indicator's maxZoom from each array
  2. Missing validation for empty arrays and negative zoom values

Consider this enhanced implementation:

 export function getMaxNumeratorZoomLevel(
   indicators: Indicator[][],
   fallbackMaxZoom: number,
 ) {
+  if (!indicators?.length) {
+    return fallbackMaxZoom;
+  }
+  if (fallbackMaxZoom < 0) {
+    throw new Error('Fallback zoom level must be non-negative');
+  }
   const maxIndicatorsZoom = Math.max(
-    ...indicators.map((indicators) => indicators[0]?.maxZoom ?? -1),
+    ...indicators.flatMap((arr) => 
+      arr.map((indicator) => indicator?.maxZoom ?? -1)
+    ),
   );
   if (maxIndicatorsZoom === -1) {
     return fallbackMaxZoom;
   }
   return maxIndicatorsZoom;
 }

Likely invalid or redundant comment.

src/core/logical_layers/renderers/stylesConfigs/mcda/mcdaStyle.ts (1)

177-178: LGTM! Good use of the new zoom level calculation.

The changes properly integrate the dynamic zoom level calculation while maintaining the fallback behavior.

Also applies to: 201-201

src/utils/bivariate/bivariateColorThemeUtils.ts (2)

149-149: LGTM! Clean parameter update and usage.

The changes to generateBivariateStyle cleanly integrate the maxZoomLevel parameter.

Also applies to: 167-167


129-132: 🧹 Nitpick (assertive)

Consider using more defensive quotients handling.

The current implementation could be made more robust when handling undefined quotients.

Consider this safer implementation:

 const maxZoom = getMaxNumeratorZoomLevel(
-  [xAxis.quotients ?? [], yAxis.quotients ?? []],
+  [
+    Array.isArray(xAxis.quotients) ? xAxis.quotients : [],
+    Array.isArray(yAxis.quotients) ? yAxis.quotients : []
+  ],
   stats.meta.max_zoom || FALLBACK_BIVARIATE_MAX_ZOOM,
 );

Likely invalid or redundant comment.

src/core/logical_layers/renderers/BivariateRenderer/BivariateRenderer.tsx (2)

21-21: LGTM: Import aligns with PR objective

The addition of getMaxNumeratorZoomLevel import is appropriate for implementing the maxzoom functionality based on indicators.


144-147: Verify maxZoom calculation edge cases

The maxZoom calculation handles undefined cases by defaulting to empty arrays, but this could silently mask configuration issues. Consider adding validation for the legend structure.

Let's check for potential edge cases in the codebase:

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b6e0c0 and ebddfbe.

📒 Files selected for processing (1)
  • src/core/logical_layers/renderers/BivariateRenderer/constants.ts (1 hunks)
🔇 Additional comments (1)
src/core/logical_layers/renderers/BivariateRenderer/constants.ts (1)

5-5: Verify the impact of reducing the maximum zoom level.

The maximum zoom level has been significantly reduced from 14 to 9. While this aligns with the PR objective to apply maxzoom based on indicators, we should verify that this fallback value is appropriate for most use cases.

✅ Verification successful

Based on the search results, I can now generate the final response as the findings provide sufficient context about the usage and impact of the FALLBACK_BIVARIATE_MAX_ZOOM constant.

The reduced fallback zoom level (9) appears appropriate and well-integrated

The code search reveals that:

  • The fallback is only used when dynamic zoom calculations fail (stats.meta.max_zoom || FALLBACK_BIVARIATE_MAX_ZOOM)
  • The system primarily relies on dynamic zoom calculations through getMaxNumeratorZoomLevel and getMaxMCDAZoomLevel
  • The fallback is consistently applied across both Bivariate and MCDA rendering contexts
  • No hardcoded maxZoom values in indicator configurations conflict with this fallback
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usage of FALLBACK_BIVARIATE_MAX_ZOOM and typical maxZoom values in indicators

# Find all references to FALLBACK_BIVARIATE_MAX_ZOOM
echo "Searching for FALLBACK_BIVARIATE_MAX_ZOOM usage:"
rg "FALLBACK_BIVARIATE_MAX_ZOOM" -A 3

# Find any hardcoded maxZoom values in indicator configurations
echo -e "\nSearching for maxZoom in indicator configurations:"
rg "maxZoom[\"']?\s*[:=]" -A 1

Length of output: 6210

@albaranau albaranau merged commit 1e96362 into main Dec 16, 2024
20 of 25 checks passed
@albaranau albaranau deleted the 20221-fe-apply-maxzoom-for-bivariate-mcda-layers-based-on-indicators-metadata branch December 16, 2024 16:52
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 participants