# Add units, precisions and sentiments

## Overview

Reading just `10` under the label `Carrots sold` doesn’t really help you understand anything. But knowing that this value is expressed in `kg/day` (unit), is precise to the gram `10.000` and that it’s better than expected (`positive` sentiment) makes it more understandable.

This is the type of info that you may know about the data but doesn’t appear in any file. You can use Toucan specifiers to communicate context about your value.

> We call *specifiers* little pieces of info on a data cell that are necessary to understanding it.

Available **Specifiers types** are:

* **units**: more precisely units of measurement
* **precision**: how to format the value correctly
* **sentiment**: a color coding associated to this value

{% hint style="info" %}
Note

* Specifiers are declared directly in the *data*. They live there because it’s a property of the *data*, not from a particular *visualization* of it.
* When applying a sentiment and a precision on the same column, the sentiment will be based on the raw data (not the data after applying the precision).
* Currencies are not units! Use the *precision* specifier (see below) to format your values in a financial way.
* In a tile, you can set up a sentiment only for one of your columns
  {% endhint %}

### Units

Not much to say about them! Just input what you want displayed next to the unit.

Two tips though:

* you can add a space before the unit if necessary
* percentage is not a unit of measurement (see the precision specifier below to know how to display this correctly)

### Precision

Precision controls how to display a value.

Precision configurations are text strings. They look like `",.2f"` or `".0%"` or `"duration:h'h' mm'm'"`. To know how to construct them, have a look at [d3-format’s documentation](https://github.com/d3/d3-format#locale_format).

Duration formatting assumes that the **value are in seconds.**

A few examples for the value `1000`:

* `".0f"`: Means no (`0`) decimal position, `f` for *fixed* precision. This is suited for integer quantities, and would be displayed like this: `1000`.
* `",.2f"`: Means 2 decimal positions, and still `f`ixed precision for float, with a character `,` to separate thousands. This is a nice format for currencies, displayed like this: `1,000.00`. The symbols adapts with the chosen language. In French locale, that would be: `1 000,00`.
* `".0%"`: Means no (`0`) decimal position, `%` for percentage format. A percentage of 100% is the value 1, so our value 1000 would be displayed `100000%`. Note that the percentage symbol is added automatically.
* `"$"` : Means that the currency symbol will be displayed along the value
* `".2K"` : (*from v58.1+*) `K` means that locale currency abbreviations will be used (in english, `K` for thousands, `M` for millions, `B` for billions, `T` for trillions). `2` indicates the number of significant digits to keep
* `"duration:narrow"` (the display is adapted automatically according the locale in Toucan) will display the duration within the standardized narrow format. In english local, the value `1000` will be displayed as `16m, 40s`. The granularity will be adapted automatically to the maximum (up to years) one according the value.
* `"duration:narrow"` (the display is adapted automatically according the locale in Toucan) will display the duration within the standardized narrow format. In english local, the value `1000` will be displayed as `16m, 40s`. The granularity will be adapted automatically to the maximum (up to years) one according the value.
* `duration:h'h' mm'm'` (custom format) will display the duration according the custom token defined. For example, the value 1000 will be display as 0h 16m

You can use multiple tokens for duration format: y (for year), M (for month), w (for week), d (for day), h (for hour), m (for minute), s (for seconds), S (for millisecond).

Duration formatting supports also the **padding**, which means that it's possible to force the display with several numbers. So for example if the format `h'h' m'm'` displays `2h 4m`, the format `hh'h' mm'm'` will display 02h 04m.

Recap:

| Raw value | Precision specifier                  | Formatted value           |
| --------- | ------------------------------------ | ------------------------- |
| `1000`    | `".0f"`                              | `1000`                    |
| `1000`    | `",.2f"`                             | `1,000.00` (en)           |
| `1000`    | `".0%"`                              | `100000%`                 |
| `1000`    | `"$"`                                | `$ 1000`                  |
| `1000`    | `"$.2f"`                             | `$ 1000.00`               |
| `1000`    | `"$.2K"`                             | `$ 1.0 K` (en)            |
| `10000`   | `"duration:narrow"`                  | `2d, 8h` (en)             |
| `10000`   | `"duration:short"`                   | `2 days & 8 hr` (en)      |
| `10000`   | `"duration:"`                        | `2 days, 8 hours` (en)    |
| `10000`   | `"duration:long"`                    | `2 days and 8 hours` (en) |
| `10000`   | "`duration:d'd' h'h' m'm' s's'"`     | `2d 7h 33m 20s`           |
| `10000`   | "`duration:dd'd' hh'h' mm'm' ss's'"` | `02d 07h 33m 20s`         |
| `10000`   | "`duration:h'h' mm'm'"`              | `55h 33m`                 |

### Sentiment

Sentiment is a bit different, it’s not a small set of characters but it’s a *scale*. The scale will be represented by color coding. The idea is to indicate how the value should be assessed against some breakpoints.

Available **sentiments** are:

* `"positive"`: generally associated to green
* `"negative"`: generally associated to red color
* `"neutral"`: generally associated to black or gray
* `"warning"`: generally associated to orange

In the nexts steps you are going to see how to use the specifiers like a pro.

### How to use specifiers :: units & precision

**Step 1:** In the Smart Editor you'll see the different specifiers under the Value input

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-6775db56a2d6f778ee5e17582f66f28f9234df51%2Fimage%20(141).png?alt=media" alt=""><figcaption></figcaption></figure>

**Step 2:** Clicking on **Add units** will allow you to specify the unit for this column

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-520ec00ea70b513e7bf48d82f0213b251ff0a4b6%2FScreenshot%202023-07-19%20at%2015.10.21.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

*Saving your changes will update how the data is displayed:*

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-2b8d74d06b7b45a1209d2f16516c129d93ae20be%2FScreenshot%202023-07-19%20at%2015.12.18.png?alt=media" alt=""><figcaption></figcaption></figure>

### How to use specifiers :: units & precision in advanced configuration mode

**Step 1:** In the Smart Editor you'll see the different specifiers under the Value input

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-6775db56a2d6f778ee5e17582f66f28f9234df51%2Fimage%20(141).png?alt=media" alt=""><figcaption></figcaption></figure>

**Step 2:** Clicking on **Add units** will allow you to specify the unit for this column

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-520ec00ea70b513e7bf48d82f0213b251ff0a4b6%2FScreenshot%202023-07-19%20at%2015.10.21.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

**Step 3:** Clicking on “**Advanced**” will allow you to access in advanced configuration mode

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-c8ec0263557dae9b6551386bce0de415231c4260%2FScreenshot%202023-07-19%20at%2015.18.55.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

**Step 4:** Choose one of the options, here we are going to configure units from another column called “Type”:

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-49036b5385270623b98782e01a07a90a36d60b83%2FScreenshot%202023-07-19%20at%2015.26.54.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

### How to use specifiers :: sentiment

**Step 1:** In the Smart Editor you'll see the different specifiers under the Value input

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-6775db56a2d6f778ee5e17582f66f28f9234df51%2Fimage%20(141).png?alt=media" alt=""><figcaption></figcaption></figure>

**Step 2:** Clicking on **Add sentiment** will allow you to specify the sentiment for this column

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-3cb0906295c58082fbaf29ad7a18db999f5962bc%2Fspecifiers-4.png?alt=media" alt="Clicking on Configure sentiment" width="375"><figcaption><p>Clicking on Configure sentiment</p></figcaption></figure>

**Step 3.1:** Sentiment around a fixed value

A simple case would be to consider a value as positive if it’s above 0, and as negative under:

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-ff9de8c3691552c9d94eecb72ccd6245f333b01c%2Fspecifiers-5.png?alt=media" alt="consider a value" width="375"><figcaption><p>consider a value</p></figcaption></figure>

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-76afef7d51266b752fc91c5cd82cab9542b138c8%2Fspecifiers-6.png?alt=media" alt="A simple case" width="375"><figcaption><p>A simple case</p></figcaption></figure>

**Step 3.2:** Sentiment with multiple fixed values

A simple case would be to consider a value as positive if it’s above 1, a neutral step between 0 and 1, warning between 0 and -1, and negative under -1:

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-ff9de8c3691552c9d94eecb72ccd6245f333b01c%2Fspecifiers-5.png?alt=media" alt="consider a value" width="375"><figcaption><p>consider a value</p></figcaption></figure>

Then add a new “bound” by clicking on the line, repeat this step as many times as you wish.

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-d1244079fbcae1a19575d9c3c4b9ac7fb830b614%2Fspecifiers-19.png?alt=media" alt="add a new “bound” by clicking on the line" width="375"><figcaption><p>add a new “bound” by clicking on the line</p></figcaption></figure>

**Step 3.3:** Sentiment towards another column

In other cases, we might want our breakpoints to vary depending on the data row. This can be done by setting our breakpoint to depend on a data column. Given this data:

| person  | grade | target |
| ------- | ----- | ------ |
| `Alice` | `12`  | `10`   |
| `Bob`   | `13`  | `15`   |

Comparing their value to their different targets, we want Alice to feel satisfied but not Bob. This can be expressed by indicating the column “target” as a breakpoint.

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-19d6d047f543176237342fd5e953f3f4a872bd38%2Fspecifiers-18.png?alt=media" alt="indicating the column “target” as a breakpoint" width="375"><figcaption><p>indicating the column “target” as a breakpoint</p></figcaption></figure>

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-4b8564ed6998bd4561b10b3dfd45ae29c66c27e9%2Fspecifiers-7.png?alt=media" alt="Comparing their value to their different targets" width="375"><figcaption><p>Comparing their value to their different targets</p></figcaption></figure>

*Saving your changes will update how the data is displayed*

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-e6c2c0b12557d859dcf1f7d9fa15186fe5f3d117%2FScreenshot%202023-07-19%20at%2015.40.28.png?alt=media" alt=""><figcaption></figcaption></figure>

## How to use specifiers :: sentiment in advanced configuration mode

{% hint style="info" %}
Note

In this exercise, I want to apply a sentiment on the “evolution” that will vary according to the values of “country” column. Because the value differs according to the country (demography, …).
{% endhint %}

**Step 1:** In the Smart Editor you'll see the different specifiers under the Value input

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-6775db56a2d6f778ee5e17582f66f28f9234df51%2Fimage%20(141).png?alt=media" alt=""><figcaption></figcaption></figure>

**Step 2:** Clicking on **Add sentiments** will allow you to specify the sentiment for this column

<div align="center"><figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-b40c491cb8d1ce06ef27f093d600ac2e380df64f%2Fsentiment-advanced-2.png?alt=media" alt="Clicking on Configure"><figcaption><p>Clicking on Configure</p></figcaption></figure></div>

{% hint style="info" %}
Note

I would like to add a sentiment for France with a bound at 50, for Italie at 45 and for others countries at 30.
{% endhint %}

**Step 3:** Clicking on “Or switch to advanced configuration” will give you access to the advanced configuration mode.

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-a455192f7d1ab6752ff209236a3eaadaa459b90f%2FScreenshot%202023-07-19%20at%2015.51.09.png?alt=media" alt="" width="375"><figcaption></figcaption></figure>

*Saving your changes will update how the data is displayed:*

<figure><img src="https://1809014303-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZxYYf1KpgarKMgMsDCrw%2Fuploads%2Fgit-blob-ce56dfef8c9442ccb5a1352eb595f4b379d3a6ad%2FScreenshot%202023-07-19%20at%2015.46.36.png?alt=media" alt=""><figcaption></figcaption></figure>

Need more? Let us know!
