UNDER DEVELOPMENT

CALCULATE

The Calculate extension adds calculating capabilities that will hopefully one day be integrated with calc!

Installation

You could use the Copy Extension button below to individually install this extension. To install, just paste anywhere in your Roam graph and click "Yes, I Know What I'm Doing".

Manual Installation

If instead you prefer to manually install, first create a block with the text {{[[roam/js]]}} on any page in your Roam DB. Then, copy and paste this code block as a child of the block.

var existing = document.getElementById("roamjs-calculate");
if (!existing) {
  var extension = document.createElement("script");
  extension.src = "https://roamjs.com/calculate.js";
  extension.id = "roamjs-calculate";
  extension.async = true;
  extension.type = "text/javascript";
  document.getElementsByTagName("head")[0].appendChild(extension);
}

Usage

Type {{calculate:}} into a block. Everything to the right of the colon will represent the expression to be calculated.

An expression could be one of four options:

  • A number
  • A tag
  • A binary operation
  • A function

Numbers include positive, negative, and decimal values. Tags are pages in either [[]], #[[]], or # formats. A binary operation combines two expressions with one of these four operations:

  • +
  • -
  • *
  • /

A function is a higher level macro that take one or more expressions as input and produces an output. The syntax of each function is {name:(expression)+}. The supported functions are:

  • attr - takes two tag names as input, returning the value assigned to the attribute with the second name on the page with the first name.
    • {attr: [[Example Project]] [[Due Date]]} returns the value assigned to the Due Date attribute on the Example Project page.
  • daily - takes one or more tags as input, and returns all the daily note pages that reference those tags in the same block
    • {daily: [[Example Project]] [[DONE]]} returns all the daily note pages that have blocks with both the DONE and Example Project tags
  • max - Takes multiple values as input and returns the maximum value. Handles both numbers and dates.
    • {max: 4 7} will return 7.
  • since - Takes a date value as input and will return the number of days since that day
    • {since: [[January 20th, 2021]]} will return 2 if today was January 22th, 2021.

Contributors

This extension is brought to you by RoamJS! If you are facing any issues reach out to support@roamjs.com or click on the chat button on the bottom right. If you get value from using this extension, consider sponsoring RoamJS by clicking on the button below!

ROAMJS DIGEST

Add your email below to stay up to date on all RoamJS features, fixes, and news!

Other Extensions