mdbook-plotly 0.2.0

An mdbook preprocessor that renders plot code blocks (e.g., ```plot) into interactive or static charts during book build.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
# mdbook-plotly User Manual

This is the official user manual (English edition) for **mdbook-plotly**, a preprocessor that renders interactive or static Plotly charts in mdbook documentation. The manual provides comprehensive reference and usage instructions.

> [!NOTE]
> This user manual is available in multiple languages; however, not all language versions are guaranteed to reflect the latest application updates. In case of discrepancies among different language versions, the Chinese version shall prevail.

## Table of Contents

- [Quick Start]#quick-start
  - [Installation]#installation
  - [Basic Configuration]#basic-configuration
  - [First Chart Example]#first-chart-example
- [Configuration Reference]#configuration-reference
  - [Configuration Syntax]#configuration-syntax
  - [Configuration Options]#configuration-options
- [Input Formats]#input-formats
  - [JSON Input]#json-input
    - [JSON Syntax and Type System]#json-syntax-and-type-system
    - [Map and Generators]#map-and-generators
    - [Chart Main Format]#chart-main-format
    - [Layout Format]#layout-format
    - [Config Format]#config-format
    - Trace Types
      - [Bar Charts]#data-bar
      - [Box Plots]#data-box
      - [Contour Plots]#data-contour
      - [Mapbox Density Heatmaps]#data-density_mapbox
      - [Heat Maps]#data-heatmap
      - [Histograms]#data-histogram
      - [Image Traces]#data-image
      - [3D Mesh Plots]#data-mesh3d
      - [OHLC Charts]#data-ohlc
      - [Pie Charts]#data-pie
      - [Sankey Diagrams]#data-sankey
      - [Scatter Plots]#data-scatter
      - [3D Scatter Plots]#data-scatter3d
      - [Geographic Scatter Plots]#data-scatter_geo
      - [Mapbox Scatter Plots]#data-scatter_mapbox
      - [Polar Scatter Plots]#data-scatter_polar
      - [3D Surface Plots]#data-surface
      - [Tables]#data-table
  - [SandBoxScript (Deprecated)]#sand-box-script
- [Output Formats]#output-formats

## Quick Start

This section guides you through installing mdbook-plotly, configuring your mdbook, and creating your first chart.

### Installation

#### Using Cargo

```shell
cargo install mdbook-plotly
```

If you use `cargo-binstall`:

```shell
cargo binstall mdbook-plotly
```

#### Manual Download

Download the latest release for your platform from the [Releases](https://github.com/TickPoints/mdbook-plotly/releases) page and add the binary to your system's PATH.

### Basic Configuration

Add the following to your book's `book.toml` file:

```toml
[preprocessor.plotly]
after = ["links"]
```

This configuration enables the default JSON5 input format. Code blocks with language `plot` or `plotly` will be processed into interactive Plotly charts.

> [!NOTE]
> mdbook-plotly uses **JSON5** syntax, which extends JSON with comments, trailing commas, unquoted object keys, single‑quoted strings, hexadecimal numbers, and multi‑line strings. This improves readability and maintainability of chart definitions.

### First Chart Example

A minimal chart definition requires three top‑level fields: `data`, `layout`, and `config`:

````markdown
```plot
{
    layout: {
        title: "Test Chart",
    },
    data: [{
        type: "pie",
        values: [10, 20, 30, 40],
    }],
    config: {
        static_plot: true,
    }
}
```
````

This example:

- Sets the chart title to "Test Chart"
- Creates a pie chart with four slices
- Disables interactivity (static plot)

For detailed information on available chart types, configuration options, and advanced features, refer to the sections below.

## Configuration Reference

Configuration options for mdbook-plotly are specified in the `[preprocessor.plotly]` section of your `book.toml`.

### Configuration Syntax

All configuration keys use `kebab-case`. The parser follows these rules:

1. **Unknown keys are ignored** – unrecognized configuration keys are silently dropped.
2. **Type‑sensitive validation** – a key with an invalid type (e.g., a string where a boolean is expected) causes the entire configuration to be rejected. All settings then revert to their defaults, and an error is logged.
3. **Missing section warning** – if the `[preprocessor.plotly]` section is absent, a warning is issued and default values are used. If the section is present but the warning appears, please file a bug report.

Example error when an invalid enum variant is supplied:

```shell
Illegal config format for 'preprocessor.mdbook-plotly': unknown variant `plotlyhtml`, expected `plotly-html`       |  in `output-type`
```

### Configuration Options

```toml
[preprocessor.plotly]
after = ["links"]

# Output format – determines the rendered chart format.
# Valid values: "plotly-html", "plotly-svg" (experimental)
output-type = "plotly-html"

# Input format – specifies the syntax of chart definitions.
# Valid values: "json-input", "sandbox-script" (deprecated)
input-type = "json-input"

# Whether to use offline JavaScript sources (true/false).
offline_js_sources = false
```

## Input Formats

The `input-type` configuration option determines the syntax used to define charts inside `plot`/`plotly` code blocks. Supported values:

- `json-input` – JSON5‑based chart definitions (recommended)
- `sand-box-script` – deprecated script‑based format

### JSON Input

This is the primary and recommended format. Charts are defined using JSON5 syntax, which extends standard JSON with comments, trailing commas, unquoted keys, and other conveniences.

> [!NOTE]
> mdbook‑plotly implements its own deserialization logic. While the structure generally follows Plotly’s native schema, compatibility is not guaranteed, and extensions (such as map references and generators) are available. Always refer to the documented fields below for reliable usage. Missing fields can be requested via GitHub issues.

#### JSON Syntax and Type System

The following notation is used throughout this reference to describe expected types and optionality.

```json5
{
    // A `?` after a field name indicates the field is optional.
    data?: [
        {
            // No `?` means the field is required.
            type: "pie",
            // Some fields become required when another field has a specific value.
            // Such dependencies are noted in the documentation.
            values: [usize; usize]   // Required when `type` is `"pie"`.
        }
    ],

    layout?: {
        legend?: {
            title?: String,
            background_color?: Rgba
        }
    }
}
```

##### Basic Types

- **Objects**`{ "key": value }` or `{ key: value }` (JSON5 allows unquoted keys)
- **Arrays**`[value1, value2, ...]`; notation `[T; N]` means an array of `N` elements each of type `T`
- **Strings**`"text"` or `'text'`; `String` denotes any string
- **Numbers**`usize` (non‑negative integer), `isize` (signed integer), `f64` (floating‑point)
- **Booleans**`true` or `false`
- **Unions**`"a" | "b"` means the value can be either `"a"` or `"b"`
- **Ranges**`0..6f64` means any `f64` value ≥ 0.0 and < 6.0

##### Common Composite Types

- **Rgb**`"rgb(u8, u8, u8)"` (e.g., `"rgb(0, 0, 0)"`)
- **Rgba**`"rgba(u8, u8, u8, f64)"` (e.g., `"rgba(0, 0, 0, 0.0)"`)
- **Color** – can be one of the following:
  - A named CSS color: `"aliceblue"`
  - An RGB color: `"rgb(255, 0, 0)"`
  - An RGBA color: `"rgba(255, 0, 0, 0.5)"`

##### Common Complex Types

The `marker` object controls the visual appearance of data points, including color, opacity, size, symbol shape, and color scale. This object applies to trace types that support a `marker` field (e.g., `scatter`, `bar`, `scatterpolar`, etc.).

```json5
{
    // ===== Basic visual properties =====
    // Fill color of the data points
    color?: Color,
    // Opacity from 0 (transparent) to 1 (opaque)
    opacity?: f64,
    // Uniform size of data points (pixels or interpreted according to size_mode)
    size?: usize,
    // Per‑point size array
    size_array?: [usize; usize],

    // Marker symbol shape
    symbol?: "circle" | "square" | "diamond" | "cross" | "x" | "triangle-up" | "triangle-down" | "triangle-left" | "triangle-right" | "pentagon" | "hexagon",
    // Size mode:
    //   "area"     – size value represents marker area (default)
    //   "diameter" – size value represents marker diameter
    size_mode?: "area" | "diameter",

    // ===== Size and display limits =====
    // Maximum number of displayed data points (excess points are hidden)
    max_displayed?: usize,
    // Size reference value for custom sizing (used with size_array, etc.)
    size_ref?: usize,
    // Minimum size constraint
    size_min?: usize,

    // ===== Color scale (for encoding numeric values) =====
    // Whether to auto‑compute the color scale range (cmax/cmin)
    cauto?: bool,
    // Maximum value of the color scale
    cmax?: f64,
    // Minimum value of the color scale
    cmin?: f64,
    // Midpoint of the color scale (used for diverging color bars)
    cmid?: f64,
    // Whether to automatically select the color scale
    auto_color_scale?: bool,
    // Whether to reverse the color scale
    reverse_scale?: bool,
    // Whether to display the color bar
    show_scale?: bool,
    // Color for outlier points (only effective in certain trace types)
    outlier_color?: Color,
}
```

#### Map and Generators

The `map` field provides a mapping table that can be referenced elsewhere in the chart definition using the `map.key` syntax. This allows reuse of data and generation of complex values via built-in generators.

Map values can be either raw data (any JSON value) or generator objects. Generator objects have a `type` field indicating the generation algorithm, plus additional parameters.

##### Generator Types

The `map` field provides a mapping table that can be referenced elsewhere in the chart definition using the `map.key` syntax. This allows reuse of data and generation of complex values via built-in generators.

Map values can be either raw data (any JSON value) or generator objects. Generator objects have a `type` field indicating the generation algorithm, plus additional parameters.

#### Generator Types

All generator objects must have a `type` field. The following generator types are supported:

- **`raw`** — Passes through data unchanged.

  _Parameters:_

  ```json5
  {
      type: "raw",
      data: T  // Any value to be used directly
  }
  ```

  _Example:_

  ```json5
  { type: "raw", data: [1, 2, 3] }
  ```

- **`g-number-list`** — Generates a list of numbers by evaluating an expression for each integer in a range.

  _Parameters:_

  ```json5
  {
      type: "g-number-list",
      begin: usize,   // inclusive start index
      end: usize,     // exclusive end index
      expr: String    // arithmetic expression in variable `i`
  }
  ```

  The expression is evaluated using the [fasteval]https://crates.io/crates/fasteval library; the variable `i` (as `f64`) is available inside the expression.

  _Example:_

  ```json5
  { type: "g-number-list", begin: 0, end: 3, expr: "i * 2" }
  // yields [0.0, 2.0, 4.0]
  ```

- **`g-number`** — Evaluates a constant arithmetic expression.

  _Parameters:_

  ```json5
  {
      type: "g-number",
      expr: String    // arithmetic expression (no variables)
  }
  ```

  _Example:_

  ```json5
  { type: "g-number", expr: "2 + 3 * 4" }
  // yields 14.0
  ```

- **`g-range`** — Generates an arithmetic progression of floating‑point numbers.

  _Parameters:_

  ```json5
  {
      type: "g-range",
      begin: f64,     // first value (inclusive)
      end: f64,       // upper bound (exclusive)
      step?: f64      // step size (default 1.0, must be positive)
  }
  ```

  _Example:_

  ```json5
  { type: "g-range", begin: 0.0, end: 5.0, step: 1.0 }
  // yields [0.0, 1.0, 2.0, 3.0, 4.0]
  ```

- **`g-repeat`** — Repeats a given value a specified number of times.

  _Parameters:_

  ```json5
  {
      type: "g-repeat",
      value: T,       // any JSON value
      count: usize    // number of repetitions
  }
  ```

  _Example:_

  ```json5
  { type: "g-repeat", value: 42.0, count: 3 }
  // yields [42.0, 42.0, 42.0]
  ```

- **`g-linear`** — Generates `count` values linearly spaced between `begin` and `end` (inclusive of both endpoints).

  _Parameters:_

  ```json5
  {
      type: "g-linear",
      begin: f64,
      end: f64,
      count: usize    // must be positive
  }
  ```

  If `count` is 1, the result is `[begin]`. Otherwise the step is `(end - begin) / (count - 1)`.

  _Example:_

  ```json5
  { type: "g-linear", begin: 0.0, end: 1.0, count: 5 }
  // yields [0.0, 0.25, 0.5, 0.75, 1.0]
  ```

- **`g-random`** — Generates random numbers. Can produce a single value or an array; supports integers or floats; an optional seed ensures reproducibility.

  _Parameters:_

  ```json5
  {
      type: "g-random",
      min: f64,           // minimum value (inclusive)
      max: f64,           // maximum value (exclusive)
      integer?: bool,     // generate integers (default false)
      seed?: u64,         // random seed (optional; same seed → same sequence)
      count?: u64         // number of values to generate (omit for a single value)
  }
  ```

  _Example:_

  ```json5
  // Generate a single floating‑point number between 0 and 100
  { type: "g-random", min: 0, max: 100 }

  // Generate 5 integers between 1 and 10 (fixed seed)
  { type: "g-random", min: 1, max: 11, integer: true, seed: 42, count: 5 }
  ```

- **`g-choose`** — Randomly picks from a list of options. Can pick a single value or an array; optional seed.

  _Parameters:_

  ```json5
  {
      type: "g-choose",
      options: [T; usize],  // candidates (must not be empty)
      seed?: u64,           // random seed (optional)
      count?: u64           // number of picks (omit for a single pick)
  }
  ```

  _Example:_

  ```json5
  { type: "g-choose", options: ["red", "green", "blue", "yellow"], seed: 1, count: 3 }
  // might yield ["blue", "red", "yellow"]
  ```

- **`g-env`** — Reads the value of an environment variable. Useful for injecting build‑time configuration; an optional default can be provided.

  _Parameters:_

  ```json5
  {
      type: "g-env",
      name: String,         // environment variable name
      default?: String      // fallback when the variable is not set
  }
  ```

  If the variable is not set and no `default` is given, an error is raised.

  _Example:_

  ```json5
  { type: "g-env", name: "MAPBOX_TOKEN", default: "" }
  // reads $MAPBOX_TOKEN, returns "" if not set
  ```

- **`g-join`** — Joins an array of strings into a single string using a separator.

  _Parameters:_

  ```json5
  {
      type: "g-join",
      values: [String; usize],  // strings to join
      separator?: String        // separator (default: empty string)
  }
  ```

  _Example:_

  ```json5
  { type: "g-join", values: ["a", "b", "c"], separator: ", " }
  // yields "a, b, c"
  ```

- **`if`** — Conditionally selects between two values based on an arithmetic expression.

  _Parameters:_

  ```json5
  {
      type: "if",
      condition: String,    // arithmetic expression that evaluates to a number
      true: T,              // value used when condition ≠ 0.0
      false: T              // value used when condition = 0.0
  }
  ```

  The condition is evaluated using the [fasteval]https://crates.io/crates/fasteval library; no variables are available. Comparison operators (e.g., `2 > 1`) yield `1.0` (true) or `0.0` (false).

  _Example:_

  ```json5
  { type: "if", condition: "2 > 1", true: [1,2,3], false: [4,5,6] }
  // yields [1,2,3] because 2 > 1 evaluates to 1.0 (non‑zero)
  ```

- **`time`** — Generates a sequence of timestamps between two time points at a specified interval.

  _Parameters:_

  ```json5
  {
      type: "time",
      start: String,        // start time string
      end: String,          // end time string
      interval: String,     // interval (e.g., "1d", "2h", "30m")
      format?: String       // optional output format (strftime syntax, default RFC 3339)
  }
  ```

  Supported time string formats: RFC 3339, `YYYY-MM-DDTHH:MM:SS`, `YYYY-MM-DD HH:MM:SS`, `YYYY-MM-DD`.
  Relative times are also supported: `now`, `now+1d`, `now-2h`, etc.

  Supported interval units: `s` (seconds), `m` (minutes), `h` (hours), `d` (days), `w` (weeks). Units can be combined, e.g., `"1d12h30m"`.

  _Example:_

  ```json5
  { type: "time", start: "2026-01-01", end: "2026-01-03", interval: "1d" }
  // yields ["2026-01-01T00:00:00+00:00", "2026-01-02T00:00:00+00:00", "2026-01-03T00:00:00+00:00"]

  { type: "time", start: "now", end: "now+3d", interval: "1d", format: "%Y-%m-%d" }
  // yields [today, tomorrow, day after tomorrow, 3 days from now] formatted as "YYYY-MM-DD"
  ```

##### Using the Map

Map entries are referenced elsewhere by prefixing the key with `map.`. For example, if the map contains a key `myrange`, you can refer to it as `"map.myrange"` in any field that accepts a `DataPack<T>` (most array and numeric fields).

_Complete example:_

```json5
{
    map: {
        xs: { type: "g-linear", begin: 0, end: 10, count: 5 },
        ys: { type: "g-number-list", begin: 0, end: 5, expr: "i * i" }
    },
    data: [{
        type: "scatter",
        x: "map.xs",
        y: "map.ys"
    }]
}
```

Since most of them are compatible with `DataPack<T>`, only the incompatible ones are given here:

- Any `type` field (usually hard-coded in the code, so it is not recommended to change)
- Primitive generators in Map

Also note that the generator is lazily loaded each time it is processed, and the same generator does not share data between different fields, so it will be re-evaluated each time a Map is used.

If you find that some items are not given above, but do not support Map, please submit an Issue, and we will solve it.

#### Chart Main Format

```json5
{
    // Build a mapping table for populating mappings in the sections below.
    map?: Map,

    // Chart layout configuration
    layout?: Layout,

    // Chart data
    data?: [Data; usize],

    // Chart configuration
    config?: Configuration,
}
```

#### Layout Format

```json5
layout: {
    // The chart title
    title?: String,
    // Whether to display the legend
    show_legend?: bool,
    // Chart height
    // NOTE: The chart can auto-resize; modifying this may cause layout issues on some devices.
    height?: usize,
    // Chart width
    // NOTE: The chart can auto-resize; modifying this may cause layout issues on some devices.
    width?: usize,
    // Chart colorway
    // For example, a pie chart requires multiple colors for its slices;
    // the program picks colors sequentially from this colorway.
    colorway?: [Color; usize],
    // Chart background color
    plot_background_color?: Color,
    // Separators
    separators?: String,
    // Whether to enable automatic size adjustment (default true)
    auto_size?: bool,
    // Paper background colour (distinct from plot_background_color)
    paper_background_color?: Color,

    // ===== Phase 1 fields =====

    // Bar gap (0~1), controls spacing between bars in the same group
    bar_gap?: f64,
    // Bar group gap (0~1), controls spacing between bar groups
    bar_group_gap?: f64,
    // Box gap (0~1), controls spacing between boxes in the same group
    box_gap?: f64,
    // Box group gap (0~1), controls spacing between box groups
    box_group_gap?: f64,

    // Hover mode
    // "x": show only data aligned with x coordinate
    // "y": show only data aligned with y coordinate
    // "closest": show closest data point
    // "false": disable hover
    // "x unified": unified display for x-aligned data
    // "y unified": unified display for y-aligned data
    hover_mode?: "x" | "y" | "closest" | "false" | "x unified" | "y unified",

    // Drag mode
    // "zoom": box select zoom
    // "pan": pan
    // "select": box select
    // "lasso": lasso select
    // "orbit": 3D orbit rotation
    // "turntable": 3D turntable rotation
    // "false": disabled
    drag_mode?: "zoom" | "pan" | "select" | "lasso" | "orbit" | "turntable" | "false",

    // Click mode
    // "event": fire click events
    // "select": trigger selection
    // "none": disabled
    click_mode?: "event" | "select" | "none",

    // Global font settings
    font?: {
        // Font family (e.g., "Arial", "sans-serif")
        family?: String,
        // Font size (pixels)
        size?: usize,
        // Font color
        color?: Color,
    },

    // Color axis configuration
    coloraxis?: {
        // Color scale minimum
        cmin?: f64,
        // Color scale maximum
        cmax?: f64,
        // Color scale midpoint (for diverging color bars)
        cmid?: f64,
        // Whether to auto-select the color scale
        auto_color_scale?: bool,
        // Whether to reverse the color scale
        reverse_scale?: bool,
        // Whether to display the color bar
        show_scale?: bool,
    },

    // ===== Axis Configuration =====
    // Default axes: xaxis, yaxis
    xaxis?: Axis,
    yaxis?: Axis,
    // Additional named axes: up to 8 (xaxis2~xaxis8, yaxis2~yaxis8)
    xaxis2?: Axis,
    xaxis3?: Axis,
    xaxis4?: Axis,
    xaxis5?: Axis,
    xaxis6?: Axis,
    xaxis7?: Axis,
    xaxis8?: Axis,
    yaxis2?: Axis,
    yaxis3?: Axis,
    yaxis4?: Axis,
    yaxis5?: Axis,
    yaxis6?: Axis,
    yaxis7?: Axis,
    yaxis8?: Axis,

    // Legend configuration
    legend?: {
        // Background color
        background_color?: Color,
        // Border color
        border_color?: Color,
        // Border width
        border_width?: usize,
        // X-axis extent
        x?: f64,
        // Y-axis extent
        y?: f64,
        // Gap between trace groups
        trace_group_gap?: usize,
        // Title
        title?: String,
        // Width of each legend item (pixels)
        item_width?: usize,

        // Trace display order within the legend
        // "normal": natural order
        // "reversed": reversed order
        // "grouped": grouped by trace group
        // "reversed+grouped": reversed and grouped
        trace_order?: "normal" | "reversed" | "grouped" | "reversed+grouped",

        // Legend item sizing mode
        // "trace": sized per trace
        // "constant": constant width
        item_sizing?: "trace" | "constant",

        // Single-click behaviour on legend items
        // "toggle": toggle the trace
        // "toggleothers": toggle all other traces
        // "false": no action
        item_click?: "toggle" | "toggleothers" | "false",

        // Double-click behaviour on legend items (same values as item_click)
        item_double_click?: "toggle" | "toggleothers" | "false",

        // Vertical alignment of legend text
        // "top", "middle", "bottom"
        valign?: "top" | "middle" | "bottom",

        // Click behaviour on legend groups
        // "toggleitem": toggle all items in the group
        // "togglegroup": toggle the group
        group_click?: "toggleitem" | "togglegroup",
    },

    // Chart margin configuration
    margin?: {
        // Left margin width
        left?: usize,
        // Right margin width
        right?: usize,
        // Top margin width
        top?: usize,
        // Bottom margin width
        bottom?: usize,
        // Uniform margin width
        // NOTE: This option overrides all individual margin settings.
        // Not recommended to use together with individual margin settings.
        pad?: usize,
        // Auto-expand
        auto_expand?: bool
    },
}
```

##### Axis Reference

The `Axis` object configures x and y axes. Supports the default axes (`xaxis`/`yaxis`)
as well as up to 8 additional named axes (`xaxis2`–`xaxis8`/`yaxis2`–`yaxis8`).

All Axis fields support [DataPack map references](#map-and-generators) (e.g. `"map.my_range"`).

```json5
{
    // Axis title
    title?: String,
    // Axis type
    // "linear": linear scale (default)
    // "log": logarithmic scale
    // "date": date/time axis
    // "category": categorical axis
    // "multicategory": multi-level categorical axis
    type?: "-" | "linear" | "log" | "date" | "category" | "multicategory",

    // Axis range [min, max]
    // Use null for open bounds, e.g. [0, null] = from 0 upward
    // Date axes accept date strings, e.g. ["2024-01-01", "2024-01-10"]
    range?: [f64; 2],

    // Axis domain on the canvas (0~1)
    // e.g. [0, 0.5] means the axis occupies the left half
    domain?: [f64; 2],

    // The axis this one is anchored to (e.g. "y", "y2", "free")
    anchor?: String,
    // Show/hide the axis
    visible?: bool,
    // Whether to auto-adjust margins
    auto_margin?: bool,

    // Grid & line styling
    show_grid?: bool,       // Show grid lines
    show_line?: bool,       // Show axis line
    show_tick_labels?: bool,// Show tick labels
    zero_line?: bool,       // Show zero line
    grid_color?: Color,     // Grid line color
    line_color?: Color,     // Axis line color
    grid_width?: f64,       // Grid line width
    line_width?: f64,       // Axis line width
    color?: Color,          // Tick color

    // Tick configuration
    tick_prefix?: String,   // Tick label prefix
    tick_suffix?: String,   // Tick label suffix
    tick_format?: String,   // Tick format (d3-format syntax)
    tick_angle?: f64,       // Tick label rotation angle
    tick0?: f64,            // Starting tick value
    dtick?: f64,            // Tick step
    nticks?: usize,         // Number of ticks
    hover_format?: String,  // Hover tooltip format

    // Category axis
    category_array?: [String; usize],   // Category order list
    category_order?: "trace" | "category-ascending" | "category-descending"
                    | "array" | "total-ascending" | "total-descending"
                    | "min-ascending" | "min-descending"
                    | "max-ascending" | "max-descending"
                    | "sum-ascending" | "sum-descending"
                    | "mean-ascending" | "mean-descending"
                    | "median-ascending" | "median-descending",

    // Axis overlay (for dual-axis charts)
    // e.g. yaxis2.overlaying: "y" means y2 overlays on y
    overlaying?: String,
    // Axis side
    side?: "bottom" | "top" | "left" | "right",
    // Axis position offset
    position?: f64,
    // Axis layer
    // "above traces": drawn above data
    // "below traces": drawn below data
    layer?: String,

    // Fixed range (disable zoom/pan)
    fixed_range?: bool,
    // Scale anchor (e.g., y axis scales anchored to x axis)
    scale_anchor?: String,
    // Scale ratio
    scale_ratio?: f64,
}
```

##### Dual Y-Axis Example

```json5
{
    layout: {
        xaxis: {
            title: "Time",
        },
        yaxis: {
            title: "Left Axis",
            side: "left",
        },
        yaxis2: {
            title: "Right Axis",
            overlaying: "y",
            side: "right",
        },
    },
    data: [
        { type: "scatter", x: [1,2,3], y: [4,5,6] },
        { type: "scatter", x: [1,2,3], y: [10,20,30], yaxis: "y2" },
    ]
}
```

#### Config Format

```json5
config: {
    // Static chart (disables interactivity)
    static_plot?: bool,
    // Math typesetting
    // Effective when MathJax is present on the page
    typeset_math?: bool,
    // Whether the chart is editable
    editable?: bool,
    // Whether auto-sizing is enabled
    autosizable?: bool,
    // Whether to fill the screen
    // NOTE: Only effective when `autosizable` is `true`.
    fill_frame?: bool,
    // Margin width
    // NOTE: Only effective when `autosizable` is `true`.
    frame_margins?: f64,
    // Whether mouse scroll wheel or two-finger pinch zoom is enabled
    // NOTE: Disabled by default for Cartesian subplots; enabled by default for others.
    scroll_zoom?: bool,
    // Show drag handles for panning/zooming on Cartesian axes
    show_axis_drag_handles?: bool,
    // Show range input boxes when panning/zooming
    // NOTE: Only effective when `show_axis_drag_handles` is `true`.
    show_axis_range_entry_boxes?: bool,
    // Whether to show tips for interactive charts
    show_tips?: bool,
    // Whether to display a link to Chart Studio Cloud in the bottom-right corner of the chart
    show_link?: bool,
    // Whether to include data linked only to Chart Studio Cloud files
    // NOTE: Only effective when `show_link` is `true`.
    send_data?: bool,
    // Available delay interval for certain double-click actions
    double_click_delay?: usize,
    // Mapbox access token
    mapbox_access_token?: String,
    // Set the length of the undo/redo queue
    queue_length?: usize,
    // Whether to display the Plotly logo at the end of the mode bar
    display_logo?: bool,
    // Watermark the image with a company logo
    watermark?: bool,

    // Controls when the modebar appears
    // "hover": only show on hover
    // "true": always show (default)
    // "false": never show
    display_mode_bar?: "hover" | "true" | "false",

    // Double-click behaviour
    // "false": no action
    // "reset": reset the chart view
    // "autosize": autosize
    // "reset+autosize": reset and autosize
    double_click?: "false" | "reset" | "autosize" | "reset+autosize",

    // Whether to show an "Edit in Chart Studio" link (alias for show_link)
    show_edit_in_chart_studio?: bool,
}
```

#### Data-bar

`bar` can be a `Data` entry. This `Data` will be rendered as a bar chart.

```json5
{
    type: "bar",

    // X-axis coordinate data
    x: [f64; usize],
    // Y-axis coordinate data
    y: [f64; usize],

    // Unique identifier for each data point
    ids?: [String; usize],
    // Uniform offset for all bars relative to their default positions
    offset?: f64,
    // Individual offset for each bar
    offset_array?: [f64; usize],
    // Uniform text displayed on the bars
    text?: String,
    // Individual text for each bar
    text_array?: [String; usize],
    // Text template with variable substitution (e.g., "%{x}", "%{y}")
    text_template?: String,
    // Hover label template
    hover_template?: String,
    // Individual hover template for each data point
    hover_template_array?: [String; usize],
    // Uniform text displayed on hover
    hover_text?: String,
    // Individual hover text for each data point
    hover_text_array?: [String; usize],
    // Trace name, displayed in the legend and hover info
    name?: String,
    // Opacity, ranging from 0 (fully transparent) to 1 (fully opaque)
    opacity?: f64,
    // Binds this trace to a specific x-axis (for multi-axis charts, e.g., "x2")
    x_axis?: String,
    // Binds this trace to a specific y-axis (for multi-axis charts, e.g., "y2")
    y_axis?: String,
    // Alignment group identifier; bars in the same group are aligned along the axis
    alignment_group?: String,
    // Offset group identifier; bars in the same group share offset space
    offset_group?: String,
    // Whether to clip content that extends beyond the axis range
    clip_on_axis?: bool,
    // Whether to show this trace in the legend
    show_legend?: bool,
    // Legend group identifier; traces in the same group are grouped together in the legend
    legend_group?: String,
    // Bar width (in data coordinate units)
    width?: f64,
    // Rotation angle for text on the bars (in degrees)
    text_angle?: f64,
    // Bar orientation: "v" for vertical bar chart, "h" for horizontal bar chart
    orientation?: "v" | "h",
    // Controls the visual appearance of data points
    marker?: Marker,
}
```

#### Data-candlestick

`candlestick` can be a `Data` entry. This `Data` will be rendered as a candlestick chart—the most common representation of price movements in financial visualization.

```json5
{
    type: "candlestick",

    // X-axis data (typically date strings, e.g., "2024-01-15")
    x: [String; usize],
    // Opening price
    open: [f64; usize],
    // Highest price
    high: [f64; usize],
    // Lowest price
    low: [f64; usize],
    // Closing price (close > open indicates a bullish candle; otherwise bearish)
    close: [f64; usize],

    // Trace name, displayed in the legend and hover info
    name?: String,
    // Whether to show this trace in the legend
    show_legend?: bool,
    // Legend group identifier
    legend_group?: String,
    // Opacity, ranging from 0 to 1
    opacity?: f64,
    // Uniform text displayed on data points
    text?: String,
    // Individual text for each data point
    text_array?: [String; usize],
    // Uniform text displayed on hover
    hover_text?: String,
    // Individual hover text for each data point
    hover_text_array?: [String; usize],
    // Whisker width, ranging from 0 to 1 (0 = no whisker tick, 1 = same width as the body)
    whisker_width?: f64,
    // Binds this trace to a specific x-axis (for multi-axis charts, e.g., "x2")
    x_axis?: String,
    // Binds this trace to a specific y-axis (for multi-axis charts, e.g., "y2")
    y_axis?: String,
    // Visibility control
    // "true": visible (default)
    // "false": hidden
    // "legendonly": not drawn but shown in the legend
    visible?: "true" | "false" | "legendonly",
}
```

#### Data-density_mapbox

`densitymapbox` can be a `Data` entry. This `Data` will be rendered as a density heatmap on a map.

> [!NOTE]
> Using this `trace` requires configuring the corresponding `mapbox` object in `Layout`.

```json5
{
    type: "density_mapbox",

    // Latitude of each data point
    lat: [f64; usize],
    // Longitude of each data point
    lon: [f64; usize],
    // Weight value for each data point, determining density intensity
    z: [f64; usize],

    // Whether to show this trace in the legend
    show_legend?: bool,
    // Trace name, displayed in the legend and hover info
    name?: String,
    // Legend group identifier; traces in the same group are grouped together in the legend
    legend_group?: String,
    // Legend sort priority; lower values appear first
    legend_rank?: usize,
    // Opacity, ranging from 0 to 1
    opacity?: f64,
    // Influence radius for each data point (in pixels, default 30)
    radius?: u8,
    // Map zoom level
    zoom?: u8,
    // Whether to automatically compute zmin and zmax from the data
    zauto?: bool,
    // Lower bound for color mapping
    zmin?: f64,
    // Midpoint for color mapping
    zmid?: f64,
    // Upper bound for color mapping
    zmax?: f64,
    // Specifies the mapbox subplot to use (e.g., "mapbox", "mapbox2")
    subplot?: String,
}
```

#### Data-histogram

`histogram` can be a `Data` entry. This `Data` will be rendered as a histogram.

```json5
{
    type: "histogram",

    // X-axis data (at least one of x and y must be provided)
    // Providing only x creates a histogram along the horizontal axis
    x?: [f64; usize],
    // Y-axis data (at least one of x and y must be provided)
    // Providing only y creates a histogram along the vertical axis
    // Providing both x and y creates a bivariate histogram
    y?: [f64; usize],

    // Trace name, displayed in the legend and hover info
    name?: String,
    // Whether to show this trace in the legend
    show_legend?: bool,
    // Legend group identifier
    legend_group?: String,
    // Opacity, ranging from 0 to 1
    opacity?: f64,
    // Uniform text displayed on the bars
    text?: String,
    // Individual text for each bar
    text_array?: [String; usize],
    // Uniform text displayed on hover
    hover_text?: String,
    // Individual hover text for each bar
    hover_text_array?: [String; usize],
    // Hover label template
    hover_template?: String,
    // Individual hover template for each bar
    hover_template_array?: [String; usize],
    // Whether to automatically determine the number of bins for the x-axis
    auto_bin_x?: bool,
    // Number of bins for the x-axis (effective when auto_bin_x is false)
    n_bins_x?: usize,
    // Whether to automatically determine the number of bins for the y-axis
    auto_bin_y?: bool,
    // Number of bins for the y-axis (effective when auto_bin_y is false)
    n_bins_y?: usize,
    // Alignment group identifier; bars in the same group are aligned along the axis
    alignment_group?: String,
    // Offset group identifier; bars in the same group share offset space
    offset_group?: String,
    // Bin group identifier; histograms in the same group share bin boundaries
    bin_group?: String,
    // Binds this trace to a specific x-axis (for multi-axis charts, e.g., "x2")
    x_axis?: String,
    // Binds this trace to a specific y-axis (for multi-axis charts, e.g., "y2")
    y_axis?: String,
    // Bar orientation: "v" for vertical, "h" for horizontal
    orientation?: "v" | "h",
    // Histogram aggregation function, determining how values within each bin are computed
    // "count": count (default)
    // "sum": sum
    // "avg": average
    // "min": minimum
    // "max": maximum
    hist_func?: "count" | "sum" | "avg" | "min" | "max",
    // Histogram normalization mode
    // "": no normalization (default)
    // "percent": expressed as a percentage
    // "probability": expressed as probability (sums to 1)
    // "density": probability density (area integrates to 1)
    // "probability density": probability density (similar to density)
    hist_norm?: "" | "percent" | "probability" | "density" | "probability density",
    // Controls the visual appearance of data points
    marker?: Marker,
}
```

#### Data-ohlc

`ohlc` can be a `Data` entry. This `Data` will be rendered as an OHLC chart, commonly used for financial stock trend analysis.

```json5
{
    type: "ohlc",

    // X-axis data (typically date strings, e.g., "2024-01-15")
    x: [String; usize],
    // Opening price
    open: [f64; usize],
    // Highest price
    high: [f64; usize],
    // Lowest price
    low: [f64; usize],
    // Closing price (close > open indicates an uptrend; otherwise a downtrend)
    close: [f64; usize],

    // Trace name, displayed in the legend and hover info
    name?: String,
    // Whether to show this trace in the legend
    show_legend?: bool,
    // Legend group identifier
    legend_group?: String,
    // Opacity, ranging from 0 to 1
    opacity?: f64,
    // Uniform text displayed on hover
    hover_text?: String,
    // Individual hover text for each data point
    hover_text_array?: [String; usize],
    // Width of the top and bottom tick marks, ranging from 0 to 0.5
    tick_width?: f64,
    // Visibility control
    // "true": visible (default)
    // "false": hidden
    // "legendonly": not drawn but shown in the legend
    visible?: "true" | "false" | "legendonly",
}
```

#### Data-image

`image` can be a `Data` entry. This `Data` will be rendered as a pixel image, supporting direct image display via a 2D pixel array within a Cartesian coordinate system.

```json5
{
    type: "image",

    // Image pixel data
    z: [[Rgb; unsize]; unsize],

    // Opacity, ranging from 0 (fully transparent) to 1 (fully opaque)
    opacity?: f64,
    // Trace name, displayed in the legend and hover info
    name?: String,
    // Legend sort priority; lower values appear first
    legend_rank?: usize,
    // Uniform text displayed on the image
    text?: String,
    // Individual text for each pixel
    text_array?: [String; usize],
    // Uniform text displayed on hover
    hover_text?: String,
    // Individual hover text for each pixel
    hover_text_array?: [String; usize],
    // Hover label template
    hover_template?: String,
    // Individual hover template for each pixel
    hover_template_array?: [String; usize],
    // Image source specified via data URI (e.g., "data:image/png;base64,...")
    // When set, z data will be ignored
    source?: String,
    // X coordinate of the image's bottom-left corner (default 0)
    x0?: f64,
    // Pixel spacing in the x direction (default 1)
    dx?: f64,
    // Y coordinate of the image's bottom-left corner (default 0)
    y0?: f64,
    // Pixel spacing in the y direction (default 1)
    dy?: f64,
    // Binds this trace to a specific x-axis (for multi-axis charts, e.g., "x2")
    x_axis?: String,
    // Binds this trace to a specific y-axis (for multi-axis charts, e.g., "y2")
    y_axis?: String,
    // Unique identifier for each data point
    ids?: [String; usize],
    // Metadata, accessible in templates via %{meta}
    meta?: String,
    // Image smoothing algorithm
    // "fast": fast smoothing
    // "false": no smoothing (shows raw pixels)
    z_smooth?: "fast" | "false",
}
```

#### Data-pie

`pie` can be a `Data` entry. This `Data` will be rendered as a pie chart.

```json5
{
    type: "pie",

    // Numeric value for each sector
    values: [f64; usize],

    // Whether to auto-adjust margins to prevent text clipping
    automargin?: bool,
    // Delta value between adjacent labels (used with label0)
    dlabel?: f64,
    // Proportion of the center hole, ranging from 0 to 1 (0 = full pie, >0 = donut chart)
    hole?: f64,
    // Hover label template
    hover_template?: String,
    // Individual hover template for each sector
    hover_template_array?: [String; usize],
    // Uniform text displayed on hover
    hover_text?: String,
    // Individual hover text for each sector
    hover_text_array?: [String; usize],
    // Unique identifier for each sector
    ids?: [String; usize],
    // Starting label value (used with dlabel to auto-generate labels)
    label0?: f64,
    // Label text for each sector
    labels?: [String; usize],
    // Legend group identifier
    legend_group?: String,
    // Legend sort priority; lower values appear first
    legend_rank?: usize,
    // Trace name, displayed in the legend and hover info
    name?: String,
    // Opacity, ranging from 0 to 1
    opacity?: f64,
    // Metadata, accessible in templates via %{meta}
    meta?: String,
    // Whether to sort sectors by value
    sort?: bool,
    // Text position source identifier
    text_position_src?: String,
    // Individual text position source identifier for each sector
    text_position_src_array?: [String; usize],
    // Uniform text displayed on sectors
    text?: String,
    // Individual text for each sector
    text_array?: [String; usize],
    // Controls the displayed information content (e.g., "percent", "label", "value", or combinations)
    text_info?: String,
    // Whether to show this trace in the legend
    show_legend?: bool,
    // Starting rotation angle for the pie chart (in degrees; default starts from the 12 o'clock position)
    rotation?: f64,
    // Pull distance for sectors, ranging from 0 to 1 (used to highlight a specific sector)
    pull?: f64,
    // Sector arrangement direction
    direction?: "clockwise" | "counterclockwise",
    // Controls the visual appearance of data points
    marker?: Marker,
}
```

#### Data-sankey

`sankey` can be a `Data` entry. This `Data` will be rendered as a Sankey diagram, used for visualizing flow relationships between nodes.

```json5
{
    type: "sankey",

    // Node configuration
    node?: {
        // Node colors
        color?: [Color; usize],
        // Padding between nodes (in pixels)
        pad?: f64,
        // Node thickness (in pixels)
        thickness?: f64,
    },

    // Trace name, displayed in the legend and hover info
    name?: String,
    // Whether the trace is visible
    visible?: bool,
    // Value format string (d3-format syntax, e.g., ".3f" for 3 decimal places)
    value_format?: String,
    // Value suffix text (unit, e.g., "TWh", "$")
    value_suffix?: String,
    // Diagram orientation: "v" for vertical, "h" for horizontal
    orientation?: "v" | "h",
    // Node arrangement mode
    // "snap": snap to grid (default)
    // "perpendicular": perpendicular arrangement
    // "freeform": free layout (draggable)
    // "fixed": fixed position (not draggable)
    arrangement?: "snap" | "perpendicular" | "freeform" | "fixed",
}
```

#### Data-scatter_geo

`scatter_geo` can be a `Data` entry. This `Data` will be rendered as a geographic scatter plot, drawn on a geographic coordinate system.

```json5
{
    type: "scatter_geo",

    // Latitude of each data point
    lat: [f64; usize],
    // Longitude of each data point
    lon: [f64; usize],

    // Unique identifier for each data point
    ids?: [String; usize],
    // Whether to show this trace in the legend
    show_legend?: bool,
    // Trace name, displayed in the legend and hover info
    name?: String,
    // Legend group identifier
    legend_group?: String,
    // Legend sort priority; lower values appear first
    legend_rank?: usize,
    // Opacity, ranging from 0 to 1
    opacity?: f64,
    // Uniform text displayed on data points
    text?: String,
    // Individual text for each data point
    text_array?: [String; usize],
    // Text template with variable substitution (e.g., "%{lat}", "%{lon}")
    text_template?: String,
    // Individual text template for each data point
    text_template_array?: [String; usize],
    // Uniform text displayed on hover
    hover_text?: String,
    // Individual hover text for each data point
    hover_text_array?: [String; usize],
    // Hover label template
    hover_template?: String,
    // Individual hover template for each data point
    hover_template_array?: [String; usize],
    // Whether to connect gaps between missing data points
    connect_gaps?: bool,
    // Specifies the geo subplot to use (e.g., "geo", "geo2")
    subplot?: String,
    // Controls the layer drawing order for this trace
    below?: String,
    // Drawing mode, determining how data points are rendered
    // "lines": lines
    // "markers": scatter markers
    // "text": text only
    // "linesmarkers": lines + markers
    // "linestext": lines + text
    // "markerstext": markers + text
    // "linemarkerstext": lines + markers + text
    // "none": hidden
    mode?: "lines" | "markers" | "text" | "linesmarkers" | "linestext" | "markerstext" | "linemarkerstext" | "none",
    // Controls the visual appearance of data points
    marker?: Marker,
}
```

#### Data-scatter_mapbox

`scatter_mapbox` can be a `Data` entry. This `Data` will be rendered as a Mapbox scatter plot.
> [!NOTE]
> Using this `trace` requires configuring the corresponding `mapbox` object in `Layout`.

```json5
{
    type: "scatter_mapbox",

    // Latitude of each data point
    lat: [f64; usize],
    // Longitude of each data point
    lon: [f64; usize],

    // Unique identifier for each data point
    ids?: [String; usize],
    // List of selected data point indices
    selected_points?: [usize; usize],
    // Whether to show this trace in the legend
    show_legend?: bool,
    // Trace name, displayed in the legend and hover info
    name?: String,
    // Legend group identifier
    legend_group?: String,
    // Legend sort priority; lower values appear first
    legend_rank?: usize,
    // Opacity, ranging from 0 to 1
    opacity?: f64,
    // Uniform text displayed on data points
    text?: String,
    // Individual text for each data point
    text_array?: [String; usize],
    // Text template with variable substitution (e.g., "%{lat}", "%{lon}")
    text_template?: String,
    // Individual text template for each data point
    text_template_array?: [String; usize],
    // Uniform text displayed on hover
    hover_text?: String,
    // Individual hover text for each data point
    hover_text_array?: [String; usize],
    // Hover label template
    hover_template?: String,
    // Individual hover template for each data point
    hover_template_array?: [String; usize],
    // Specifies the mapbox subplot to use (e.g., "mapbox", "mapbox2")
    subplot?: String,
    // Controls the layer drawing order for this trace
    below?: String,
    // Metadata, accessible in templates via %{meta}
    meta?: String,
    // Drawing mode, determining how data points are rendered
    // "lines": lines
    // "markers": scatter markers
    // "text": text only
    // "linesmarkers": lines + markers
    // "linestext": lines + text
    // "markerstext": markers + text
    // "linemarkerstext": lines + markers + text
    // "none": hidden
    mode?: "lines" | "markers" | "text" | "linesmarkers" | "linestext" | "markerstext" | "linemarkerstext" | "none",
    // Controls the visual appearance of data points
    marker?: Marker,
}
```

#### Data-scatter_polar

`scatter_polar` can be a `Data` entry. This `Data` will be rendered as a scatter plot in polar coordinates.

```json5
{
    type: "scatter_polar",

    // Angular coordinates (degrees unless layout.polar.angularaxis.thetaunit is overridden)
    theta: [f64; usize],
    // Radial coordinates
    r: [f64; usize],

    // Trace name, displayed in legend and hover info
    name?: String,
    // Whether to show this trace in the legend
    show_legend?: bool,
    // Legend group identifier
    legend_group?: String,
    // Opacity, from 0 (transparent) to 1 (opaque)
    opacity?: f64,
    // Uniform text displayed on data points
    text?: String,
    // Per-point text
    text_array?: [String; usize],
    // Uniform hover text
    hover_text?: String,
    // Per-point hover text
    hover_text_array?: [String; usize],
    // Hover label template
    hover_template?: String,
    // Per-point hover template
    hover_template_array?: [String; usize],
    // Polar subplot to use (e.g. "polar", "polar2")
    subplot?: String,
    // Whether to connect gaps between missing data points
    connect_gaps?: bool,
    // Reference start value for radial coordinates (used to map array indices to radial distance)
    r0?: f64,
    // Radial step (used with r0)
    dr?: f64,
    // Reference start value for angular coordinates (degrees)
    theta0?: f64,
    // Angular step (degrees)
    dtheta?: f64,
    // Fill style
    // "tozeroy": fill to r=0
    // "tozerox": fill to theta=0
    // "tonexty": fill to next trace's r values
    // "tonextx": fill to next trace's theta values
    // "toself": fill enclosed area
    // "tonext": fill to next trace
    // "none": no fill
    fill?: "tozeroy" | "tozerox" | "tonexty" | "tonextx" | "toself" | "tonext" | "none",
    // Drawing mode
    // "lines": lines only
    // "markers": markers only
    // "text": text only
    // "linesmarkers": lines + markers
    // "linestext": lines + text
    // "markerstext": markers + text
    // "linemarkerstext": lines + markers + text
    // "none": hidden
    mode?: "lines" | "markers" | "text" | "linesmarkers" | "linestext" | "markerstext" | "linemarkerstext" | "none",
    // Visibility control
    // "true": visible (default)
    // "false": hidden
    // "legendonly": not drawn but shown in legend
    visible?: "true" | "false" | "legendonly",
    // Controls the visual appearance of data points
    marker?: Marker,
}
```

#### Data-scatter

`scatter` can be a `Data` entry. This `Data` will be rendered as a filled area chart.

```json5
{
    type: "scatter",

    // X-axis coordinate data
    x: [f64; usize],
    // Y-axis coordinate data
    y: [f64; usize],

    // Whether to enable WebGL rendering (can significantly improve performance with large datasets)
    web_gl_mode?: bool,
    // X-axis starting value (used with dx to auto-generate x coordinates at linear intervals)
    x0?: f64,
    // X-axis step size
    dx?: f64,
    // Y-axis starting value (used with dy to auto-generate y coordinates at linear intervals)
    y0?: f64,
    // Y-axis step size
    dy?: f64,
    // Unique identifier for each data point
    ids?: [String; usize],
    // Uniform text displayed on data points
    text?: String,
    // Individual text for each data point
    text_array?: [String; usize],
    // Text template with variable substitution (e.g., "%{x}", "%{y}")
    text_template?: String,
    // Hover label template
    hover_template?: String,
    // Individual hover template for each data point
    hover_template_array?: [String; usize],
    // Uniform text displayed on hover
    hover_text?: String,
    // Individual hover text for each data point
    hover_text_array?: [String; usize],
    // Trace name, displayed in the legend and hover info
    name?: String,
    // Opacity, ranging from 0 to 1
    opacity?: f64,
    // Metadata, accessible in templates via %{meta}
    meta?: String,
    // Binds this trace to a specific x-axis (for multi-axis charts, e.g., "x2")
    x_axis?: String,
    // Binds this trace to a specific y-axis (for multi-axis charts, e.g., "y2")
    y_axis?: String,
    // Stack group identifier; traces in the same group will be stacked together
    stack_group?: String,
    // Whether to clip content that extends beyond the axis range
    clip_on_axis?: bool,
    // Whether to connect gaps between missing data points (NaN / null)
    connect_gaps?: bool,
    // Fill area color
    fill_color?: Rgba,
    // Whether to show this trace in the legend
    show_legend?: bool,
    // Legend group identifier; traces in the same group are grouped together in the legend
    legend_group?: String,
    // Fill area type
    // "tozeroy": fill to y=0
    // "tozerox": fill to x=0
    // "tonexty": fill to the next trace's y values
    // "tonextx": fill to the next trace's x values
    // "toself": fill the enclosed area itself
    // "tonext": fill to the next trace
    // "none": no fill
    fill?: "tozeroy" | "tozerox" | "tonexty" | "tonextx" | "toself" | "tonext" | "none",
    // Drawing mode, determining how data points are rendered
    // "lines": line chart
    // "markers": scatter markers
    // "text": text only
    // "linesmarkers": lines + markers
    // "linestext": lines + text
    // "markerstext": markers + text
    // "linemarkerstext": lines + markers + text
    // "none": hidden
    mode?: "lines" | "markers" | "text" | "linesmarkers" | "linestext" | "markerstext" | "linemarkerstext" | "none",
    // Controls the visual appearance of data points
    marker?: Marker,
}
```

#### Data-table

`table` can be a `Data` entry. This `Data` will be rendered as a table.

```json5
{
    type: "table",

    // Header data; each inner array represents the header values for one column
    header_values: [[String; usize]; usize],
    // Cell data; each inner array represents the data values for one column
    // The number of values in each column must match the header
    cells_values: [[String; usize]; usize],

    // Trace name, displayed in the legend and hover info
    name?: String,
    // Column width ratio (proportionally fills available width)
    column_width?: f64,
    // Rendering order of data columns (e.g., [2, 0, 1] means the original column 0 is rendered as the 3rd column)
    column_order?: [usize; usize],
    // Visibility control
    // "true": visible (default)
    // "false": hidden
    // "legendonly": not drawn but shown in the legend
    visible?: "true" | "false" | "legendonly",
}
```

### Data-box

`box` can be a `Data` entry. This `Data` will be rendered as a box plot.

```json5
{
    type: "box",
    y?: [f64; usize],
    x?: [f64; usize],
    name?: String,
    opacity?: f64,
    ids?: [String; usize],
    width?: usize,
    text?: String,
    text_array?: [String; usize],
    hover_text?: String,
    hover_text_array?: [String; usize],
    hover_template?: String,
    hover_template_array?: [String; usize],
    x_axis?: String,
    y_axis?: String,
    alignment_group?: String,
    offset_group?: String,
    show_legend?: bool,
    legend_group?: String,
    fill_color?: Color,
    notched?: bool,
    notch_width?: f64,
    whisker_width?: f64,
    q1?: [f64; usize],
    median?: [f64; usize],
    q3?: [f64; usize],
    upper_fence?: [f64; usize],
    lower_fence?: [f64; usize],
    notch_span?: [f64; usize],
    mean?: [f64; usize],
    standard_deviation?: [f64; usize],
    point_pos?: f64,
    jitter?: f64,
    orientation?: "v" | "h",
    box_mean?: "true" | "false" | "sd",
    box_points?: "all" | "outliers" | "suspectedoutliers" | "false",
    quartile_method?: "linear" | "exclusive" | "inclusive",
    hover_on?: "points" | "boxes" | "boxes+points",
    marker?: Marker,
}
```

### Data-contour

`contour` can be a `Data` entry. This `Data` will be rendered as a contour plot.

```json5
{
    type: "contour",
    z: [[f64; usize]; usize],
    x?: [f64; usize],
    y?: [f64; usize],
    x0?: f64,
    dx?: f64,
    y0?: f64,
    dy?: f64,
    opacity?: f64,
    n_contours?: usize,
    connect_gaps?: bool,
    hover_on_gaps?: bool,
    show_legend?: bool,
    transpose?: bool,
    auto_contour?: bool,
    auto_color_scale?: bool,
    reverse_scale?: bool,
    show_scale?: bool,
    zauto?: bool,
    fill_color?: Color,
    contours?: {
        start?: f64,
        end?: f64,
        size?: f64,
        coloring?: "fill" | "heatmap" | "lines" | "none",
    },
    line?: Line,
    color_bar?: ColorBar,
    color_scale?: "greys" | "ylgnbu" | "greens" | "ylorrd" | "bluered" | "rdbu" | "reds" | "blues" | "picnic" | "rainbow" | "portland" | "jet" | "hot" | "blackbody" | "earth" | "electric" | "viridis" | "cividis",
}
```

### Data-heatmap

`heatmap` can be a `Data` entry. This `Data` will be rendered as a heat map.

```json5
{
    type: "heatmap",
    z: [[f64; usize]; usize],
    x?: [f64; usize],
    y?: [f64; usize],
    name?: String,
    opacity?: f64,
    hover_template?: String,
    hover_template_array?: [String; usize],
    hover_text?: String,
    hover_text_array?: [String; usize],
    hover_text_matrix?: [[String; usize]; usize],
    text?: String,
    text_array?: [String; usize],
    text_matrix?: [[String; usize]; usize],
    show_legend?: bool,
    legend_group?: String,
    x_axis?: String,
    y_axis?: String,
    connect_gaps?: bool,
    transpose?: bool,
    auto_color_scale?: bool,
    reverse_scale?: bool,
    show_scale?: bool,
    zauto?: bool,
    zmax?: f64,
    zmin?: f64,
    zmid?: f64,
    x_gap?: usize,
    y_gap?: usize,
    hover_info?: "all" | "x" | "y" | "z" | "x+y" | "x+z" | "y+z" | "x+y+z" | "text" | "name" | "none" | "skip",
    color_bar?: ColorBar,
    color_scale?: "greys" | "ylgnbu" | "greens" | "ylorrd" | "bluered" | "rdbu" | "reds" | "blues" | "picnic" | "rainbow" | "portland" | "jet" | "hot" | "blackbody" | "earth" | "electric" | "viridis" | "cividis",
}
```

### Data-mesh3d

`mesh3d` can be a `Data` entry. This `Data` will be rendered as a 3D mesh plot.

```json5
{
    type: "mesh3d",
    x: [f64; usize],
    y: [f64; usize],
    z: [f64; usize],
    i?: [usize; usize],
    j?: [usize; usize],
    k?: [usize; usize],
    name?: String,
    opacity?: f64,
    ids?: [String; usize],
    text?: String,
    text_array?: [String; usize],
    hover_text?: String,
    hover_text_array?: [String; usize],
    hover_template?: String,
    hover_template_array?: [String; usize],
    show_legend?: bool,
    legend_group?: String,
    legend_rank?: usize,
    color?: Color,
    face_color?: [Color; usize],
    vertex_color?: [Color; usize],
    intensity?: [f64; usize],
    intensity_mode?: "vertex" | "cell",
    scene?: String,
    flat_shading?: bool,
    alpha_hull?: f64,
    delaunay_axis?: "x" | "y" | "z",
    meta?: String,
    color_axis?: String,
    hover_info?: "all" | "x" | "y" | "z" | "x+y" | "x+z" | "y+z" | "x+y+z" | "text" | "name" | "none" | "skip",
    color_bar?: ColorBar,
    color_scale?: "greys" | "ylgnbu" | "greens" | "ylorrd" | "bluered" | "rdbu" | "reds" | "blues" | "picnic" | "rainbow" | "portland" | "jet" | "hot" | "blackbody" | "earth" | "electric" | "viridis" | "cividis",
    lighting?: { ambient?: f64, diffuse?: f64, specular?: f64, roughness?: f64, fresnel?: f64 },
    light_position?: { x?: f64, y?: f64, z?: f64 },
}
```

### Data-scatter3d

`scatter3d` can be a `Data` entry. This `Data` will be rendered as a 3D scatter plot.

```json5
{
    type: "scatter3d",
    x: [f64; usize],
    y: [f64; usize],
    z: [f64; usize],
    name?: String,
    opacity?: f64,
    ids?: [String; usize],
    text?: String,
    text_array?: [String; usize],
    text_template?: String,
    text_template_array?: [String; usize],
    hover_text?: String,
    hover_text_array?: [String; usize],
    hover_template?: String,
    hover_template_array?: [String; usize],
    show_legend?: bool,
    legend_group?: String,
    legend_rank?: usize,
    surface_color?: Color,
    connect_gaps?: bool,
    scene?: String,
    meta?: String,
    mode?: "lines" | "markers" | "text" | "linesmarkers" | "linestext" | "markerstext" | "linemarkerstext" | "none",
    hover_info?: "all" | "x" | "y" | "z" | "x+y" | "x+z" | "y+z" | "x+y+z" | "text" | "name" | "none" | "skip",
    text_position?: "top left" | "top center" | "top right" | "middle left" | "middle center" | "middle right" | "bottom left" | "bottom center" | "bottom right",
    surface_axis?: "-1" | "0" | "1" | "2",
    marker?: Marker,
    line?: Line,
}
```

### Data-surface

`surface` can be a `Data` entry. This `Data` will be rendered as a 3D surface plot.

```json5
{
    type: "surface",
    z: [[f64; usize]; usize],
    x?: [f64; usize],
    y?: [f64; usize],
    name?: String,
    opacity?: f64,
    text?: String,
    text_array?: [String; usize],
    hover_text?: String,
    hover_text_array?: [String; usize],
    hover_template?: String,
    hover_template_array?: [String; usize],
    show_legend?: bool,
    legend_group?: String,
    connect_gaps?: bool,
    hide_surface?: bool,
    surface_color?: [Color; usize],
    auto_color_scale?: bool,
    reverse_scale?: bool,
    show_scale?: bool,
    cauto?: bool,
    cmax?: f64,
    cmin?: f64,
    cmid?: f64,
    hover_info?: "all" | "x" | "y" | "z" | "x+y" | "x+z" | "y+z" | "x+y+z" | "text" | "name" | "none" | "skip",
    color_bar?: ColorBar,
    color_scale?: "greys" | "ylgnbu" | "greens" | "ylorrd" | "bluered" | "rdbu" | "reds" | "blues" | "picnic" | "rainbow" | "portland" | "jet" | "hot" | "blackbody" | "earth" | "electric" | "viridis" | "cividis",
    lighting?: { ambient?: f64, diffuse?: f64, specular?: f64, roughness?: f64, fresnel?: f64 },
    light_position?: { x?: i32, y?: i32, z?: i32 },
}
```

### Sand Box Script

> [!WARNING]
> **This format is deprecated**. Using it will emit a warning and a debug message, and fall back to rendering the default chart.

This format allows you to define a script that runs in a local sandboxed environment. Upon execution, the script generates the corresponding chart object.

## Output Formats

Output formats determine whether the final rendered result is HTML, SVG, or another format. Each format has its own advantages and trade-offs—we leave the choice to the user.

Output format must be configured globally; for details, see [Configuration](#configuration-reference).

| Raw Name | Formatted Name | Effect | Additional Notes |
|--------|--------|--------|--------|
| **PlotlyHtml** | `plotly-html`  | Outputs an `<div>` element and a companion `<script>` containing Plotly logic | May cause compatibility issues with Markdown parsers that do not support raw HTML; less suitable for client-side rendering scenarios |
| **PlotlySvg**  | `plotly-svg`   | **TODO** | Not yet implemented; intended to perform most rendering locally, but may increase build time |