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

Review Issue #84 - Weight Tracker #92

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Wiki/advanced-showcases.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Advanced showcases
Trilium provides some advanced functionality in the form of [Scripts](scripts.md) and [promoted attributes](promoted-attributes.md). To explain and visualize these features we've prepared few showcases which are also available in the [demo document](document.md):
# Advanced Showcases

* [Relation map](relation-map.md)
* [Day notes](day-notes.md)
* [Weight Tracker](weight-tracker.md)
* [Task Manager](task-manager.md)
Trilium offers advanced functionality through [Scripts](scripts.md) and [Promoted Attributes](promoted-attributes.md). To illustrate these features, we've prepared several showcases available in the [demo document](document.md):

An important thing to keep in mind is that above showcases and demoed functionality are not built-in into Trilium - these are just examples of Trilium's extensibility.
* [Relation Map](relation-map.md)
* [Day Notes](day-notes.md)
* [Weight Tracker](weight-tracker.md)
* [Task Manager](task-manager.md)

It's important to note that these examples are not natively supported by Trilium out of the box; instead, they demonstrate what you can build within Trilium.
31 changes: 15 additions & 16 deletions Wiki/weight-tracker.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
# Weight-tracker
Weight Tracker is a [Script API](script-api.md) showcase present in the [demo document](document.md).
# Weight-tracker

[Day notes](day-notes.md) shows (among others) how we have "weight" [promoted attribute](promoted-attributes.md) in the day note [template](template.md). This then aggregates the data and shows a nice chart of weight change in time.

Demo
----
The `Weight Tracker` is a [Script API](script-api.md) showcase present in the [demo document](document.md).

![](images/weight-tracker.png)
By adding `weight` as a [promoted attribute](promoted-attributes.md) to the [Day notes](day-notes.md) through its [template](template.md), you can aggregate the data and plot weight change over time.
Alumniminium marked this conversation as resolved.
Show resolved Hide resolved

How to remove Weight Tracker button from the top bar
----------------------------------------------------
![](images/weight-tracker.png)

In the link map of Weight Tracker, there is a note "Button". Open it and delete or comment out its contents. Weight Tracker button will disappear after you close and open the app.
## Implementation

Implementation
--------------
The `Weight Tracker` Note in the screenshot above is of type `Render Note`. That type of note doesn't have any useful content itself, rahter it provides a place where a [script](scripts.md) can render its output.
Alumniminium marked this conversation as resolved.
Show resolved Hide resolved

Note "Weight Tracker" in the screenshot above is of type "Render HTML note". Such note doesn't have any useful content itself, the only purpose of it is to provide a place where some [script](scripts.md) can render some output. This script is defined in [relation](attributes.md) `renderNote` - coincidentally it's the Weight Tracker's child `Implementation`.
Scripts for `Render Notes` are defined in a [relation](attributes.md) called `~renderNote`. In this example, it's the `Weight Tracker`'s child `Implementation`. The Implementation consists of two [code notes](code-notes.md) that contain some HTML and JavaScript respectively, which load all the notes with a `weight` attribute and displays their values in a chart.
Alumniminium marked this conversation as resolved.
Show resolved Hide resolved

This Implementation [code note](code-notes.md) then contains some HTML and JavaScript which loads all the notes with "weight" attribute and displays them in a chart. To actually render chart we're using third party library [chart.js](https://www.chartjs.org/) which is imported as an attachment (it's not built-in into Trilium).
To actually render the chart, we're using a third party library called [chart.js](https://www.chartjs.org/) which is imported as an attachment, since it's not built into Trilium.

### JS code
### Code

To get an idea of the script, here's the "JS code" note content:
Here's the content of the script Note of type `JS Frontend`:
Alumniminium marked this conversation as resolved.
Show resolved Hide resolved

```text-plain
```js
async function getChartData() {
const days = await api.runOnBackend(async () => {
const notes = api.getNotesWithLabel('weight');
Expand Down Expand Up @@ -71,3 +66,7 @@ new chartjs.Chart(ctx, {
data: await getChartData()
});
```

## How to remove the Weight Tracker button from the top bar

In the link map of the `Weight Tracker`, there is a note called `Button`. Open it and delete or comment out its contents. The `Weight Tracker` button will disappear after you restart Trilium.