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

✨ (dashboards) piecharts - sorting and label spacing #3855

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

Conversation

MatissJanis
Copy link
Member

Two changes:

  1. the piechart data will now be sorted (from biggest balance to smallest);
  2. slightly increased the spacing between the labels in the piechart (for mobile & dashboard page) - to give it a bit more breathing room and so it wouldn't intersect with the piechart itself

@actual-github-bot actual-github-bot bot changed the title ✨ (dashboards) piecharts - sorting and label spacing [WIP] ✨ (dashboards) piecharts - sorting and label spacing Nov 19, 2024
Copy link

netlify bot commented Nov 19, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit cdabda2
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/6740d6fd3c9952000820fe36
😎 Deploy Preview https://deploy-preview-3855.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Nov 19, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
10 5.45 MB → 5.45 MB (+511 B) +0.01%
Changeset
File Δ Size
src/components/reports/graphs/DonutGraph.tsx 📈 +526 B (+7.01%) 7.33 kB → 7.84 kB
src/components/reports/ChooseGraph.tsx 📉 -15 B (-0.41%) 3.6 kB → 3.58 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/ReportRouter.js 1.52 MB → 1.52 MB (+511 B) +0.03%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/useAccountPreviewTransactions.js 1.68 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/AppliedFilters.js 21.32 kB 0%
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/narrow.js 82.93 kB 0%
static/js/wide.js 241.19 kB 0%
static/js/index.js 3.44 MB 0%

Copy link
Contributor

github-actions bot commented Nov 19, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.32 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.32 MB 0%

@MatissJanis
Copy link
Member Author

/update-vrt

@MatissJanis MatissJanis changed the title [WIP] ✨ (dashboards) piecharts - sorting and label spacing ✨ (dashboards) piecharts - sorting and label spacing Nov 19, 2024
Copy link
Contributor

coderabbitai bot commented Nov 19, 2024

Walkthrough

The pull request introduces modifications to the DonutGraph component in DonutGraph.tsx. The getVal function's parameter type has been explicitly defined as DataEntity, enhancing type safety. A new variable, sortedData, has been introduced to sort the unsortedData based on the getVal function, replacing the previous direct reference to data[splitData] in the rendering logic. The pie chart now utilizes sortedData as its data source. Additionally, the Pie component has been updated to include startAngle and endAngle properties, which adjust the orientation of the pie chart. The logic for determining the compact variable has been moved inside the rendering function, allowing it to dynamically adjust based on container dimensions. Minor adjustments have also been made to the positioning of text elements within the ActiveShapeMobile and ActiveShape components, specifically changing the x and y attributes of certain <text> elements to improve layout consistency. The compact prop has been removed from the DonutGraph invocation in ChooseGraph.tsx, affecting its rendering.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers

  • youngcw

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint (1.23.1)

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eslint-plugin".

(The package "eslint-plugin-eslint-plugin" was not found when loaded as a Node module from the directory "/packages/eslint-plugin-actual".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eslint-plugin@latest --save-dev

The plugin "eslint-plugin-eslint-plugin" was referenced from the config file in "packages/eslint-plugin-actual/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8202aa5 and cdabda2.

📒 Files selected for processing (2)
  • packages/desktop-client/src/components/reports/ChooseGraph.tsx (0 hunks)
  • packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx (3 hunks)
💤 Files with no reviewable changes (1)
  • packages/desktop-client/src/components/reports/ChooseGraph.tsx
🔇 Additional comments (4)
packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx (4)

41-72: Label spacing improvements look good!

The adjustments to text element positioning improve label spacing and prevent overlap:

  • Using -240 degrees for consistent angle calculation
  • Proper vertical spacing between elements
  • Better horizontal distribution of percentage and amount labels

Line range hint 234-240: Type safety improvement looks good!

The addition of the DataEntity type annotation to the getVal function parameter enhances type safety and code maintainability.


244-246: LGTM!

The sorting implementation correctly handles descending order and maintains immutability.


251-283: Rendering improvements enhance responsiveness!

Good changes:

  1. Moving compact calculation inside render function makes it responsive to container dimensions
  2. The pie chart orientation is properly set with startAngle={90} and endAngle={-270}

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.

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

🧹 Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx (1)

1-2: Consider enabling TypeScript strict mode

The file has strict TypeScript checking disabled with // @ts-strict-ignore. Consider gradually enabling strict mode to improve type safety and catch potential issues at compile time.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b4d2d6a and 3b46602.

⛔ Files ignored due to path filters (4)
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-custom-reports-Switches-to-Donut-Graph-and-checks-the-visuals-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-custom-reports-Switches-to-Donut-Graph-and-checks-the-visuals-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-custom-reports-Switches-to-Donut-Graph-and-checks-the-visuals-3-chromium-linux.png is excluded by !**/*.png
  • upcoming-release-notes/3855.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx (6 hunks)
🔇 Additional comments (4)
packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx (4)

43-52: Improved label spacing in mobile view

The adjustments to text element positioning improve the layout by:

  • Centering the main label
  • Separating the amount and percentage with consistent spacing
  • Using proper text anchoring for alignment

This change aligns well with the PR objective to improve label spacing.


Line range hint 214-220: LGTM: Improved type safety

Adding type annotation to getVal function improves type safety and code maintainability.


226-228: Good use of useMemo for performance optimization

The implementation correctly uses useMemo to cache the sorted data, preventing unnecessary re-sorting on every render. The dependency array properly includes both unsortedData and balanceTypeOp.


260-261: Verify the impact of angle adjustments

The addition of startAngle and endAngle properties changes the chart's orientation. While this might help with label positioning, we should ensure it doesn't affect the user experience negatively.

Let's check for any related visual regression tests:

✅ Verification successful

Angle adjustments are safe and intentional

The angle adjustments (startAngle: 90, endAngle: -270) are safe and appropriate for the following reasons:

  • These values create a standard donut chart orientation starting from the top (90°) and going clockwise for a full 360° rotation (-270° = 90° - 360°)
  • The component is already using these angle properties throughout its implementation for both the main sectors and decorative elements
  • The graph is properly integrated into the reporting system with appropriate type definitions and usage controls
  • The changes are consistent with common donut chart implementations where the first slice starts at the top position
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for visual regression tests related to DonutGraph
rg -l "DonutGraph" -g "*.test.*"

Length of output: 32


Script:

#!/bin/bash
# Let's search for any test files or snapshots related to DonutGraph with a broader search
rg -l "DonutGraph" --type-add 'test:*.{test.*,spec.*,stories.*,snap*}' --type test

# Also search for any existing usage of these angle properties to understand the current implementation
rg "startAngle|endAngle" packages/desktop-client/src/components/reports/graphs/

Length of output: 1498


Script:

#!/bin/bash
# Let's check the git history of this file to see if these angle values were different before
git log -p packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx | grep -A 5 -B 5 "startAngle\|endAngle"

# Also let's check if there are any existing usages of DonutGraph to understand the current implementation
rg "DonutGraph" -A 3 -B 3 packages/desktop-client/src/components/

Length of output: 8399

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

📥 Commits

Reviewing files that changed from the base of the PR and between e287049 and 193ee8a.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx (5 hunks)
🔇 Additional comments (4)
packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx (4)

43-52: LGTM: Label spacing improvements

The adjustments to text element positioning provide better spacing between labels, which aligns with the PR objectives to prevent overlap, especially on mobile devices.


Line range hint 214-220: LGTM: Enhanced type safety

Adding the DataEntity type annotation improves type safety while maintaining the correct logic for handling debt values.


251-251: LGTM: Consistent data source update

The pie chart correctly uses the sorted data array.


258-259: LGTM: Improved pie chart orientation

Setting the start angle to 90° and end angle to -270° ensures the pie chart starts from the top and rotates clockwise, which is more intuitive for users.

@youngcw
Copy link
Member

youngcw commented Nov 19, 2024

The category text is getting cut off just a bit in the card
image

@matt-fidd
Copy link
Contributor

Also losing part of the value in the card, should be 1072
image

@MatissJanis
Copy link
Member Author

Ok, did a few extra updates to better scale the widget. It's definitely not perfect. But better than before :)

Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

Looks brilliant, I won't pretend to understand the maths but the code looks good and it's much better in app

@matt-fidd
Copy link
Contributor

@MatissJanis are you wanting this in for 24.12? It would be a big improvement to the piecharts to go alongside the release of the dashboard.

@MatissJanis
Copy link
Member Author

I wasn't planing on merging this during the code freeze as it's not really a bugfix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants