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 category spending report #1382

Merged
merged 14 commits into from
Aug 7, 2023
Merged

Conversation

kyrias
Copy link
Contributor

@kyrias kyrias commented Jul 21, 2023

This PR adds a report for showing the budget category spending over time, including the ability to select between no averaging and averaging by 3, 6, or 12 months, or since the first transaction in the category.

Testing appreciated!


TODO

  • I don't know what would be a reasonable overview display of this report, since it only makes sense once you've selected a category.

@netlify
Copy link

netlify bot commented Jul 21, 2023

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit dfb148a
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/64ce405d65d3010008494442
😎 Deploy Preview https://deploy-preview-1382.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.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 21, 2023

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
16 2.08 MB → 2.09 MB (+15.86 kB) +0.74%
Changeset
File Δ Size
../../node_modules/victory-stack/es/helper-methods.js 🆕 +11.29 kB 0 B → 11.29 kB
../../node_modules/victory-stack/es/victory-stack.js 🆕 +6.8 kB 0 B → 6.8 kB
src/components/reports/CategorySpending.js 🆕 +4.38 kB 0 B → 4.38 kB
src/components/reports/graphs/category-spending-spreadsheet.tsx 🆕 +3.9 kB 0 B → 3.9 kB
src/components/reports/CategorySelector.tsx 🆕 +2.95 kB 0 B → 2.95 kB
src/components/reports/graphs/CategorySpendingGraph.tsx 🆕 +1.45 kB 0 B → 1.45 kB
src/components/reports/graphs/common.tsx 🆕 +1.32 kB 0 B → 1.32 kB
src/icons/v2/Filter2.js 🆕 +588 B 0 B → 588 B
src/hooks/useCategories.ts 🆕 +361 B 0 B → 361 B
src/components/reports/ReportRouter.js 📈 +149 B (+25.87%) 576 B → 725 B
src/components/reports/Overview.js 📈 +1.22 kB (+20.53%) 5.92 kB → 7.14 kB
src/hooks/useFeatureFlag.ts 📈 +29 B (+8.45%) 343 B → 372 B
src/components/settings/Experimental.tsx 📈 +101 B (+3.65%) 2.7 kB → 2.8 kB
src/components/reports/Header.js 📈 +54 B (+1.59%) 3.32 kB → 3.38 kB
src/components/accounts/MobileAccount.js 📉 -9 B (-0.15%) 5.95 kB → 5.94 kB
src/components/accounts/MobileAccounts.js 📉 -39 B (-0.68%) 5.6 kB → 5.56 kB
src/components/reports/graphs/NetWorthGraph.tsx 📉 -1.14 kB (-37.07%) 3.07 kB → 1.93 kB
View detailed bundle breakdown

Added

Asset File Size % Changed
static/js/171.chunk.js 0 B → 396.24 kB (+396.24 kB) -

Removed

Asset File Size % Changed
static/js/457.chunk.js 388.22 kB → 0 B (-388.22 kB) -100%

Bigger

Asset File Size % Changed
static/js/reports.chunk.js 33.23 kB → 40.68 kB (+7.46 kB) +22.44%
static/js/main.js 851.72 kB → 851.97 kB (+248 B) +0.03%
static/js/narrow-components.chunk.js 32.06 kB → 32.2 kB (+150 B) +0.46%

Smaller

Asset File Size % Changed
static/js/wide-components.chunk.js 159.17 kB → 159.17 kB (-1 B) -0.00%

Unchanged

Asset File Size % Changed
static/media/Inter-italic.var.woff2 239.29 kB 0%
static/media/Inter-roman.var.woff2 221.86 kB 0%
static/js/383.chunk.js 117.35 kB 0%
static/js/281.chunk.js 28.55 kB 0%
static/js/876.chunk.js 26.2 kB 0%
static/js/969.chunk.js 12.94 kB 0%
static/js/resize-observer-polyfill.chunk.js 8.12 kB 0%
static/css/main.css 5.82 kB 0%
asset-manifest.json 2.07 kB 0%
index.html 1.66 kB 0%
static/media/browser-server.js 963 B 0%

@github-actions
Copy link
Contributor

github-actions bot commented Jul 21, 2023

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
2 1.97 MB → 1.97 MB (-248 B) -0.01%
Changeset
File Δ Size
packages/loot-core/src/server/accounts/sync.ts 📉 -452 B (-1.66%) 26.66 kB → 26.22 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

Asset File Size % Changed
kcab.worker.js 1010.53 kB → 1010.29 kB (-248 B) -0.02%

Unchanged

Asset File Size % Changed
xfo.xfo.kcab.worker.js 1004.04 kB 0%

@MatissJanis
Copy link
Member

Cool idea! What do you think about changing this from a line graph to barcharts? And each bar segment would represent a category. Upon opening the report - all categories would show up, but then you get the option to remove some if you prefer that.

This would also solve the homepage problem. We could just show a barchart of the current month there.

image

@kyrias
Copy link
Contributor Author

kyrias commented Jul 23, 2023

I think that's a good idea, though I'm not sure how to really represent this well in the UI.

It would mean that Filter->Category is actually meaningful again and so we could use that filter, but the other filters are still meaningless for this chart, and having to click a drop-down with a single alternative feels weird.

But maybe just re-using the category filter entry and making that a top-level button would work? Not sure what a good name for it would be then though.

@j-f1
Copy link
Contributor

j-f1 commented Jul 23, 2023

Maybe the filter options could filter the list of transactions that the report sees, and then a separate UI could make it easy to see category totals (or something??) and quickly toggle on/off different categories or focus on just one at a time?

@kyrias
Copy link
Contributor Author

kyrias commented Jul 23, 2023

If we change this to actually look at arbitrary subsets of transactions then this isn't really a category spending report anymore, just an arbitrary spent-per-month (but also not even that if you do date filtering) that happens to show it grouped by category. I feel like it would make it conceptually a very strange report unless it was made even more general and you could select other things to group by, which... would be significantly more complex and something I'm not up for implementing. I rather liked being able to simplify the logic into just being able to look at the actual budget values. 😅

@j-f1
Copy link
Contributor

j-f1 commented Jul 24, 2023

That makes sense! I don’t feel super strongly about filtering, so it would be fine to avoid it for now and see if it’s something that’s frequently requested.

@kyrias
Copy link
Contributor Author

kyrias commented Jul 24, 2023

Cool idea! What do you think about changing this from a line graph to barcharts? And each bar segment would represent a category. Upon opening the report - all categories would show up, but then you get the option to remove some if you prefer that.

This would also solve the homepage problem. We could just show a barchart of the current month there.

image

Rendering negative spent columns, which is what we'd normally expect for most categories, would be easy enough for a bar chart in that we just have to flip the sign and then render them as bar charts. But how do we handle categories with positive spent amounts? It feels like it'd look very confusing to have some categories positive and some negative for the same month in a bar chart version of this.

@ovbm
Copy link

ovbm commented Jul 28, 2023

Hey, I'd love a bar chart colored by expenses. Regarding categories with positive amounts: If a category turns positive, we could show it as a negative value in the axis. I made a crude example of how it could look like:
expenses actual

@kyrias
Copy link
Contributor Author

kyrias commented Jul 28, 2023

I think that looks super confusing personally. 😅

@MatissJanis @j-f1 Do you want me to implement it like that? While I'm not a fan of that positive spent behavior, I'd be fine with implementing it if it's what you want.

@MatissJanis
Copy link
Member

MatissJanis commented Jul 28, 2023

Maybe I'm missing something, but how can an expense (or spent amount if we call it that way) be a positive number?

For inspiration: here's what YNAB does:

@kyrias
Copy link
Contributor Author

kyrias commented Jul 28, 2023

Maybe I'm missing something, but how can an expense (or spent amount if we call it that way) be a positive number?

Well, it's not just expenses, it's the actual category "spent" column. Simple case is when you get a refund the month after the purchase. Or someone sends you money for a specific purpose and you inflow it directly into the category rather than having it misleadingly categorized as income.

@MatissJanis
Copy link
Member

Ok, I see. That makes sense.

I'm ok with either making it zero-based (meaning inflow in a category shows up as "0" spend) or to implement @ovbm suggestion. Either way I find this to likely be a edge case that the majority of users won't experience in their usual workflows.

@ovbm
Copy link

ovbm commented Jul 28, 2023

I don't remember how YNAB handles it, but to prevent the above case of an "expense" category being positive - which can happen if e.g. you get a refund on clothing items - one could filter all positive transactions (refunds, advances, etc.) and label the chart as "Spending per Category and Month". This would eliminate the need to display the axis in my example. With the caveat that it doesn't reflect true expenses of those categories in aggregate.

In my opinion, showing expense categories with positive monthly cashflows in the opposite axis is more useful for the user, because they can more easily see if spending spikes in one months (e.g. buying lots of clothes) in a category are followed by a correction (e.g. returning some of them) in the next.

Edit: sry this took a while to write, feel free to ignore if you've already made a decision. Think it's great that we're getting an expense chart regardless of implementation - thanks a lot!

@kyrias
Copy link
Contributor Author

kyrias commented Jul 28, 2023

2023-07-29T01:21-k74vimqDXN

Slowly getting there, though I'm still rather unsure how to rig up a decent UI for selecting which categories to show. YNAB's version has the advantage of for starters first showing only category groups and then letting you click on the group to then show categories in that group, but that's too advanced for my first implementation of this.

The two things I can think of is either:

  1. A UI like the filter UI where you can select only the categories you want to include, or
  2. Having a drop-down menu with a list of categories with checkboxes next to them, letting you disable ones you don't want to see, which is what YNAB appears to do.

I also have a feeling that the compact view of all categories would break down for pretty much any use of Actual, but we might be able to just select the first X categories for that one.

@Redbox3070
Copy link

Thanks for working on this, in my view is one of the most important things actual is missing. For positive values a good idea could be to implement a toggle that excludes them.

YNAB's version has the advantage of for starters first showing only category groups and then letting you click on the group to then show categories in that group, but that's too advanced for my first implementation of this.
I understand the limitation for the first implementation but I'm worried that with categories most charts would have way too many colors (20 or more categories does not sound too strange).
The two things I can think of is either:

1. A UI like the filter UI where you can select only the categories you want to include, or

2. Having a drop-down menu with a list of categories with checkboxes next to them, letting you _disable_ ones you don't want to see, which is what YNAB appears to do.

I think option 2 is better.

@kyrias
Copy link
Contributor Author

kyrias commented Jul 29, 2023

If anyone who's interested in seeing this finished is better at UI stuff than I then I'd really appreciate some help with two things:

  • Category picker. I have no idea of where to even start on implementing something like this. So what we want is a drop-down menu with a list of checkboxes to enable and disable including a category in the graph.
  • Tooltips. Currently they end up pointing at the top of the segment for segments above the 0 axis and the bottom of the segment for ones below, but I think it would be more reasonable if they were pointing at the middle of the segment. Additionally, the whole tooltip should probably be moved out a bit as it's in the middle of the bar now.

@ovbm
Copy link

ovbm commented Jul 29, 2023

I can give it a shot in the next couple of days.

  • Regarding Category Picker. Not sure it needs to be a drop down. Will give it a go.
  • The tooltips look great IMO.

@ovbm
Copy link

ovbm commented Jul 30, 2023

Did some crude test with the category selection. The current CategorySelector can only handle one category, which is not sufficient for this use case. So I built a custom one - currently just as a list of categories. Could be extended to work within a selector.

test.UI.actual.mov

Let me know if that's something you'd want to build upon, then I can clean up my code a bit.

Would be nice if users could assign colors to categories.

@kyrias
Copy link
Contributor Author

kyrias commented Jul 30, 2023

I feel like always showing the list of categories would take up too much of the available screen width, especially if you don't have the menu collapsed. But other than that I think it's a good start!

@ovbm
Copy link

ovbm commented Jul 30, 2023

Yeah it's not optimal. Just saw that the Autocomplete component supports Multiselect. Will investigate that.

@kyrias
Copy link
Contributor Author

kyrias commented Jul 30, 2023

The multiselect is what you get if you go to Filter -> Category -> "one of". It wouldn't be a good UI for this since they for one wouldn't be separated by category group, and would be a rather busy UI if we enable all by default.

@j-f1
Copy link
Contributor

j-f1 commented Jul 30, 2023

I really like what you have there @ovbm! Maybe with a button to show/hide that column so that people can get the full width if needed? But your example chart doesn’t particularly feel horizontal space constrained.

@kyrias
Copy link
Contributor Author

kyrias commented Jul 31, 2023

@ovbm's changes have been added now and it's looking pretty great!

One thing though, while I like having more colors available I don't really feel like the ones we switched to now fit in with the other colors in the Actual UI.

I looked up the built-in color scales and the qualitative one appears to have more colors while matching the Actual colors better. What does everyone think of using that one instead? Or should we come up with our own set of matching colors? I think it's better overall, but while the dark blue matches the menu-bar blue fairly well, I also think that it's a bit too heavy for having in the graph, so I guess we could probably at least take that set of colors and either remove that one color or replace it with a nicer one.

2023-08-01T00:04-5unpW2Y7aL
2023-08-01T00:05-XA1IHGWUFi

@ovbm
Copy link

ovbm commented Jul 31, 2023

No preferences on my side, I was just playing around and left some palettes in I experimented with.

One thought regarding averages: While using it I didn't understand what the averages were useful for. Showing rolling averages as monthly bars doesn't really make sense in my mind because the bar chart is meant to show specific spending latterns per month. And averages blur those patterns. If the averages stay in I'd suggest showing them as line or area charts.

@kyrias
Copy link
Contributor Author

kyrias commented Jul 31, 2023

Showing rolling averages as monthly bars doesn't really make sense in my mind because the bar chart is meant to show specific spending latterns per month. And averages blur those patterns. If the averages stay in I'd suggest showing them as line or area charts.

I think that's funny, because the rolling averages is the only thing I was interested in and the no-average option was a late addition, and this was a line chart until I was asked to change it to a bar chart. :p

@trafico-bot trafico-bot bot added 🔍 Ready for Review and removed ⚠️ Changes requested Pull Request needs changes before it can be reviewed again labels Aug 4, 2023
@kyrias
Copy link
Contributor Author

kyrias commented Aug 4, 2023

On the 12 month report, it might be nice to show all of the months on the bottom scale if the width is over a certain size. There isn't room on smaller screens, but larger screens could easily fit all of the months without crowding.

I think that make sense, though I'm not really sure what would be a reasonable calculation for this. If you have a suggestion I can plug it in. (It'll just involve changing the 5 here.)

Out of curiosity, how many colors are included in the color palette? Is there going to be repeating colors once you reach a certain number of categories?

The qualitative style has 10 colors, and they're reused, yes. I'd be happy with any suggestions for a new color palette though. :)

@shall0pass
Copy link
Contributor

I think that make sense, though I'm not really sure what would be a reasonable calculation for this. If you have a suggestion I can plug it in. (It'll just involve changing the 5 here.)

width > 760 ? 12 : 5 ... This felt appropriate, though it's a bit subjective so a little more or less would be ok I think.

Copy link
Contributor

@shall0pass shall0pass left a comment

Choose a reason for hiding this comment

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

This all looks good on my end!

Copy link
Member

@MatissJanis MatissJanis left a comment

Choose a reason for hiding this comment

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

Great!

(I won't merge just yet as we're planing on doing v23.8.1 patch release very soon; we can merge straight after though)

@MatissJanis MatissJanis added this to the v23.9.0 milestone Aug 5, 2023
@MatissJanis MatissJanis merged commit e17d90c into actualbudget:master Aug 7, 2023
15 checks passed
@trafico-bot trafico-bot bot added ✨ Merged Pull Request has been merged successfully and removed ✅ Approved labels Aug 7, 2023
FlorianLang06 pushed a commit to FlorianLang06/actual that referenced this pull request Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Merged Pull Request has been merged successfully
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants