Skip to content

Commit c8a5cb5

Browse files
committed
api index
1 parent ee5eff7 commit c8a5cb5

File tree

6 files changed

+131
-3
lines changed

6 files changed

+131
-3
lines changed

docs/.vitepress/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ export default defineConfig({
130130
{text: "Crosshair", link: "/interactions/crosshair"},
131131
{text: "Pointer", link: "/interactions/pointer"}
132132
]
133-
}
133+
},
134+
{text: "API index", link: "/api"}
134135
],
135136
search: {
136137
provider: "local"

docs/api.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script setup>
2+
3+
import {data} from "./data/api.data";
4+
5+
</script>
6+
7+
# API index
8+
9+
## Methods
10+
11+
<ul>
12+
<li v-for="[name, comment] in data.methods">
13+
<span style="display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"><a href="#">{{ name }}</a> - {{ comment }}</span>
14+
</li>
15+
</ul>
16+
17+
## Options
18+
19+
<ul>
20+
<li v-for="[name, contexts] in data.options">
21+
{{ name }} - {{ contexts.join(", ") }}
22+
</li>
23+
</ul>

docs/data/api.data.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {rollups, sort} from "d3";
2+
import {FunctionDeclaration, InterfaceDeclaration, Project} from "ts-morph";
3+
4+
// These interfaces tend to represent things that Plot constructs internally,
5+
// rather than objects that the user is expected to provide.
6+
function isInternalInterface(name) {
7+
return (
8+
name === "AutoSpec" ||
9+
name === "Channel" ||
10+
name === "ChannelTransform" ||
11+
name === "Context" ||
12+
name === "Dimensions" ||
13+
name === "Plot" ||
14+
name === "Scale"
15+
);
16+
}
17+
18+
export default {
19+
async load() {
20+
const project = new Project({tsConfigFilePath: "tsconfig.json"});
21+
const allMethods: {name: string; comment: string | undefined}[] = [];
22+
const allOptions: {name: string; context: string}[] = [];
23+
for (const [name, declarations] of project.getSourceFile("src/index.d.ts")!.getExportedDeclarations()) {
24+
for (const declaration of declarations) {
25+
if (declaration instanceof FunctionDeclaration) {
26+
allMethods.push({
27+
name: declaration.getName()!,
28+
comment: declaration
29+
.getJsDocs()[0]
30+
?.getDescription()
31+
.replace(/\n/g, " ")
32+
.replace(/[*_]/g, "")
33+
.replace(/[.:]($|\s+).*/g, "")
34+
.trim()
35+
});
36+
} else if (declaration instanceof InterfaceDeclaration) {
37+
if (isInternalInterface(name)) continue;
38+
for (const property of declaration.getProperties()) {
39+
allOptions.push({name: property.getName(), context: name});
40+
}
41+
}
42+
}
43+
}
44+
return {
45+
methods: sort(
46+
rollups(
47+
allMethods,
48+
(D) => D.find((d) => d.comment)?.comment,
49+
(d) => d.name
50+
),
51+
([name]) => name
52+
),
53+
options: sort(
54+
rollups(
55+
allOptions,
56+
(D) => D.map((d) => d.context).sort(),
57+
(d) => d.name
58+
),
59+
([name]) => name
60+
)
61+
};
62+
}
63+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"prettier": "^3.0.0",
6969
"rollup": "^3.7.0",
7070
"topojson-client": "^3.1.0",
71+
"ts-morph": "^19.0.0",
7172
"typescript": "^5.0.2",
7273
"vite": "^4.0.0",
7374
"vitepress": "^1.0.0-beta.2"

src/mark.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,5 +477,5 @@ export class RenderableMark extends Mark {
477477
/** A compound Mark, comprising other marks. */
478478
export type CompoundMark = Markish[] & Pick<Mark, "plot">;
479479

480-
/** Given an array of marks, returns a compound mark; supports *mark.plot shorthand. */
480+
/** Given an array of marks, returns a compound mark; supports *mark*.plot shorthand. */
481481
export function marks(...marks: Markish[]): CompoundMark;

yarn.lock

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,16 @@
580580
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf"
581581
integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==
582582

583+
"@ts-morph/common@~0.20.0":
584+
version "0.20.0"
585+
resolved "https://registry.yarnpkg.com/@ts-morph/common/-/common-0.20.0.tgz#3f161996b085ba4519731e4d24c35f6cba5b80af"
586+
integrity sha512-7uKjByfbPpwuzkstL3L5MQyuXPSKdoNG93Fmi2JoDcTf3pEP731JdRFAduRVkOs8oqxPsXKA+ScrWkdQ8t/I+Q==
587+
dependencies:
588+
fast-glob "^3.2.12"
589+
minimatch "^7.4.3"
590+
mkdirp "^2.1.6"
591+
path-browserify "^1.0.1"
592+
583593
"@types/d3-array@*":
584594
version "3.0.5"
585595
resolved "https://registry.yarnpkg.com/@types/d3-array/-/d3-array-3.0.5.tgz#857c1afffd3f51319bbc5b301956aca68acaa7b8"
@@ -1267,6 +1277,11 @@ cliui@^7.0.2:
12671277
strip-ansi "^6.0.0"
12681278
wrap-ansi "^7.0.0"
12691279

1280+
code-block-writer@^12.0.0:
1281+
version "12.0.0"
1282+
resolved "https://registry.yarnpkg.com/code-block-writer/-/code-block-writer-12.0.0.tgz#4dd58946eb4234105aff7f0035977b2afdc2a770"
1283+
integrity sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==
1284+
12701285
color-convert@^2.0.1:
12711286
version "2.0.1"
12721287
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
@@ -1894,7 +1909,7 @@ fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
18941909
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
18951910
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
18961911

1897-
fast-glob@^3.2.9:
1912+
fast-glob@^3.2.12, fast-glob@^3.2.9:
18981913
version "3.3.0"
18991914
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.0.tgz#7c40cb491e1e2ed5664749e87bfb516dbe8727c0"
19001915
integrity sha512-ChDuvbOypPuNjO8yIDf36x7BlZX1smcUMTTcyoIjycexOxd6DFsKsg21qVBzEmr3G7fUKIRy2/psii+CIUt7FA==
@@ -2482,6 +2497,13 @@ minimatch@^5.0.1:
24822497
dependencies:
24832498
brace-expansion "^2.0.1"
24842499

2500+
minimatch@^7.4.3:
2501+
version "7.4.6"
2502+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-7.4.6.tgz#845d6f254d8f4a5e4fd6baf44d5f10c8448365fb"
2503+
integrity sha512-sBz8G/YjVniEz6lKPNpKxXwazJe4c19fEfV2GDMX6AjFz+MX9uDWIZW8XreVhkFW3fkIdTv/gxWr/Kks5FFAVw==
2504+
dependencies:
2505+
brace-expansion "^2.0.1"
2506+
24852507
minipass@^3.0.0:
24862508
version "3.3.6"
24872509
resolved "https://registry.yarnpkg.com/minipass/-/minipass-3.3.6.tgz#7bba384db3a1520d18c9c0e5251c3444e95dd94a"
@@ -2512,6 +2534,11 @@ mkdirp@^1.0.3:
25122534
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
25132535
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==
25142536

2537+
mkdirp@^2.1.6:
2538+
version "2.1.6"
2539+
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-2.1.6.tgz#964fbcb12b2d8c5d6fbc62a963ac95a273e2cc19"
2540+
integrity sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==
2541+
25152542
mocha@^10.0.0:
25162543
version "10.2.0"
25172544
resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8"
@@ -2672,6 +2699,11 @@ parse5@^7.1.2:
26722699
dependencies:
26732700
entities "^4.4.0"
26742701

2702+
path-browserify@^1.0.1:
2703+
version "1.0.1"
2704+
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd"
2705+
integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==
2706+
26752707
path-exists@^4.0.0:
26762708
version "4.0.0"
26772709
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3"
@@ -3106,6 +3138,14 @@ ts-api-utils@^1.0.1:
31063138
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.1.tgz#8144e811d44c749cd65b2da305a032510774452d"
31073139
integrity sha512-lC/RGlPmwdrIBFTX59wwNzqh7aR2otPNPR/5brHZm/XKFYKsfqxihXUe9pU3JI+3vGkl+vyCoNNnPhJn3aLK1A==
31083140

3141+
ts-morph@^19.0.0:
3142+
version "19.0.0"
3143+
resolved "https://registry.yarnpkg.com/ts-morph/-/ts-morph-19.0.0.tgz#43e95fb0156c3fe3c77c814ac26b7d0be2f93169"
3144+
integrity sha512-D6qcpiJdn46tUqV45vr5UGM2dnIEuTGNxVhg0sk5NX11orcouwj6i1bMqZIz2mZTZB1Hcgy7C3oEVhAT+f6mbQ==
3145+
dependencies:
3146+
"@ts-morph/common" "~0.20.0"
3147+
code-block-writer "^12.0.0"
3148+
31093149
type-check@^0.4.0, type-check@~0.4.0:
31103150
version "0.4.0"
31113151
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"

0 commit comments

Comments
 (0)