Skip to content

Commit 20c93b4

Browse files
committed
document formats
1 parent ee132f6 commit 20c93b4

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,12 +1187,50 @@ These helper functions are provided for use as a *scale*.tickFormat [axis option
11871187

11881188
#### Plot.formatIsoDate(*date*)
11891189

1190-
1190+
Given a Date, returns the [shortest equivalent ISO 8601 UTC string](https://github.com/mbostock/isoformat/).
1191+
1192+
```js
1193+
Plot.formatIsoDate(new Date(Date.UTC(2001, 0, 1))) // "2001-01-01"
1194+
Plot.formatIsoDate(new Date(Date.UTC(2020, 0, 1, 12, 23))) // "2020-01-01T12:23Z"
1195+
```
11911196

11921197
#### Plot.formatWeekday(*locale*, *format*)
11931198

1194-
1199+
Returns a function that formats a week day (numbered from 0—Sunday to 6—Saturday) according to the *locale* and *format*.
1200+
- *locale*: any valid [BCP 47 language tag](https://tools.ietf.org/html/bcp47); defaults to "en-US". Use navigator.language to respect the browser’s setting.
1201+
- *format*: any valid [weekday format](https://tc39.es/ecma402/#datetimeformat-objects), *i.e.* one of "narrow", "short", "long"; defaults to "short".
1202+
1203+
```js
1204+
x: { tickFormat: Plot.formatWeekday() } // Sun, Mon…
1205+
```
1206+
1207+
```js
1208+
Plot.formatWeekday("es-MX", "long") // domingo, lunes…
1209+
```
1210+
1211+
```js
1212+
Plot.formatWeekday(navigator.language, "long") // depends on the browser’s settings
1213+
```
1214+
1215+
This function is periodic: day -1 is Saturday, and day 8 is Sunday.
11951216

11961217
#### Plot.formatMonth(*locale*, *format*)
11971218

1198-
1219+
Returns a function that formats a month (numbered from 0—January to 11—December) according to the *locale* and *format*.
1220+
- *locale*: any valid [BCP 47 language tag](https://tools.ietf.org/html/bcp47); defaults to "en-US". Use navigator.language to respect the browser’s setting.
1221+
- *format*: any valid [month format](https://tc39.es/ecma402/#datetimeformat-objects), *i.e.* one of "2-digit", "numeric", "narrow", "short", "long"; defaults to "short".
1222+
1223+
```js
1224+
x: { tickFormat: Plot.formatMonth() } // Jan, Feb…
1225+
```
1226+
1227+
```js
1228+
Plot.formatMonth("es-MX", "long") // enero, febrero…
1229+
```
1230+
1231+
```js
1232+
Plot.formatMonth(navigator.language, "long") // depends on the browser’s settings
1233+
```
1234+
1235+
This function is periodic: month -1 is December, and month 12 is January.
1236+

0 commit comments

Comments
 (0)