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

data pivot - calculated columns #991

Merged
merged 29 commits into from
Mar 14, 2024
Merged

data pivot - calculated columns #991

merged 29 commits into from
Mar 14, 2024

Conversation

shapiromatron
Copy link
Owner

@shapiromatron shapiromatron commented Feb 13, 2024

Enable the ability to add calculated fields in a data pivot whose output is derived from other fields in the dataset. Coupled with #987, this allows for users to mix and match columns to present to the right of a data pivot using information presented in the visual.

For example:

  • The endpoints column: ${endpoint name} (${response units}) @ ${observation time text}
  • The dose column: match(dose,0)?-:${dose} ${dose units}
  • The response column: ${response} ± round(stdev,2) (round(percent control mean,1)%)

Renders:

image

@shapiromatron shapiromatron changed the title Dp calculated columns data pivot - calculated columns Feb 13, 2024
@rabstejnek rabstejnek marked this pull request as ready for review February 22, 2024 22:50
@rabstejnek
Copy link
Collaborator

@shapiromatron Ready for review!

  • You can include a column value by doing ${column}
    • ie This is a ${species}. with {species: "rat"} returns This is a rat.
  • You can use ternaries by doing match(column,str/int)?Truthy string:Falsey string
    • ie match(species,"cat")?This is a cat.:This is not a cat. with {species: "rat"} returns This is not a cat.
  • You can escape characters using \
    • ie \${species} would return ${species}

@shapiromatron shapiromatron self-assigned this Mar 4, 2024
@shapiromatron shapiromatron marked this pull request as draft March 4, 2024 17:21
@rabstejnek
Copy link
Collaborator

rabstejnek commented Mar 12, 2024

@shapiromatron I have updated the parser language so that it can handle nested ternaries correctly; an example is in the test suite. I also added the exists condition with some tests. The logic for exists is as follows:

return options.getValue(id) != null & options.getValue(id) != "";

There is also an npm script that generates the query and format parsers:

npm run generate-parsers

This PR is ready for review!

@rabstejnek rabstejnek marked this pull request as ready for review March 12, 2024 17:16
Copy link
Owner Author

@shapiromatron shapiromatron left a comment

Choose a reason for hiding this comment

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

@rabstejnek I think you have to do the final review b/c I opened the PR initially, but I think this is great and will be a I think a highlight of our next release.

I made the following edits:

If you're ok w/ the changes, please approve.


To document our sidebar chats, but it'd be good to get this in use initially to determine the need first:

  • we may change ${} to show() in the future
  • we may rewrite the ternary expression a?b:c to ifelse(a,b,c)

@rabstejnek rabstejnek merged commit 3213583 into main Mar 14, 2024
6 checks passed
@rabstejnek rabstejnek deleted the dp-calculated-columns branch March 14, 2024 19:07
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