Skip to content

Commit

Permalink
docs: clarify that we need to turn on customFormatTypes to use cust…
Browse files Browse the repository at this point in the history
…om format types (#8212)

* Update config.md

* Update config.md

* style: auto-formatting [CI]

* Update site/docs/config.md

Co-authored-by: Dominik Moritz <domoritz@gmail.com>

Co-authored-by: GitHub Actions Bot <vega-actions-bot@users.noreply.github.com>
Co-authored-by: Dominik Moritz <domoritz@gmail.com>
  • Loading branch information
3 people authored Jun 23, 2022
1 parent 8cbaed5 commit 393359e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions site/docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ These two config properties define the default number and time formats for text

### Providing Custom Formatters

To customize how Vega-Lite formats numbers or text, you can register a new formatter by (1) registering [an expression function](https://vega.github.io/vega/docs/api/extensibility/#expressions) that takes a data point and an optional format property and (2) setting the `customFormatTypes` config to `true`. For example, to register `customFormatA`, you run need to register the function:
To customize how Vega-Lite formats numbers or text, you can register a custom formatter by

(1) Registering [an expression function](https://vega.github.io/vega/docs/api/extensibility/#expressions) that takes a data point and an optional format property. For example, to register `customFormatA`, you need to register the function:

```js
vega.expressionFunction('customFormatA', function(datum, params) {
Expand All @@ -67,9 +69,18 @@ vega.expressionFunction('customFormatA', function(datum, params) {
});
```

You can then use this custom format function with `format` and `formatType` properties in text encodings and guides (axis/legend/header).
2. Setting the `customFormatTypes` config to `true`.

```json
```js
{
...,
"config": {"customFormatTypes": true}
}
```

3. You can then use this custom format function with `format` and `formatType` properties in text encodings and guides (axis/legend/header).

```js
{
"format": <params>,
"formatType": "customFormatA"
Expand Down

0 comments on commit 393359e

Please sign in to comment.