decaf-dev / obsidian-dataloom

Weave together data from diverse sources and display them in different views. Inspired by Excel spreadsheets and Notion.so.
https://dataloom.xyz/
MIT License
901 stars 32 forks source link

WIP: Formula cell #768

Closed roman-balzer closed 4 months ago

roman-balzer commented 9 months ago

Hey, i'm currently working on a Formula Cell. Draft PR for now, since this is the first iteration.

Open issues regarding this feature: #406, #566, #565 and #455

I'm still not sure how to implement the formula syntax currently. Would be great if we could use a library as function parser, where I could fill in the variable with cell data, but I'll have to look into that. If there are some good libs tell me, so I can look into it :)

decaf-dev commented 9 months ago

What kind of operations are you thinking? Something like Excel? =SUM(B4:E4)

An Excel-like operation is pretty simple and won't need a library. You would just need to handle some basics operations sum, max, min. I have already made utility functions for these for the calculation row.

More complex function support might merit a library. It doesn't seem like that is what people are asking for though. I'm open to thoughts.

roman-balzer commented 9 months ago

I thought about more complex Operations.

Thou, this would require a lib, or an implementation of a custom syntax.

natcl commented 8 months ago

If you're looking for a pretty powerful library to manipulate data check JSONata: https://jsonata.org It has pretty much everything needed for these type of calculations and that would make formula cells very powerful !

roman-balzer commented 8 months ago

If you're looking for a pretty powerful library to manipulate data check JSONata: https://jsonata.org It has pretty much everything needed for these type of calculations and that would make formula cells very powerful !

Already looked into JSONata. Thou first of all we don't really have complex JSON structures, but rather simple "key value pairs". Also it's imho quite complex and too powerful, for a simple formula cell. I wouldn't want that they user should have to lookup the docs of JSONata to be able to use the formula cell, especially if they don't have a "coding background".

alexandergunnarson commented 8 months ago

I'd love to simply have the formulas be JS — or at least as close as possible — rather than yet another special query language. (Beyond that, can take inspiration from Coda?) I'd love to be able to call out to external JS libraries too. Granted, potentially this could be non-performant, since special optimizations can't be made for opaque code (unlike e.g. max, min, etc.). However, it means that you won't always be playing whack-a-mole to try to implement user requests for each new function.

roman-balzer commented 4 months ago

Sadly, I won't be finishing this PR, since I don't really find much time to think about a formula syntax, or to use an existing solution like JSONata. And also to be honest, since I don't really use Loom anymore, it really dropped from my priority list.

If someone want to continue this PR, the changes on my branch contain the logic to access the data from other table cells. What's left to implement is a syntax for the user to use these values.