Skip to content

Commit

Permalink
api index
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jul 22, 2023
1 parent ee5eff7 commit c8a5cb5
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export default defineConfig({
{text: "Crosshair", link: "/interactions/crosshair"},
{text: "Pointer", link: "/interactions/pointer"}
]
}
},
{text: "API index", link: "/api"}
],
search: {
provider: "local"
Expand Down
23 changes: 23 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup>

import {data} from "./data/api.data";

</script>

# API index

## Methods

<ul>
<li v-for="[name, comment] in data.methods">
<span style="display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"><a href="#">{{ name }}</a> - {{ comment }}</span>
</li>
</ul>

## Options

<ul>
<li v-for="[name, contexts] in data.options">
{{ name }} - {{ contexts.join(", ") }}
</li>
</ul>
63 changes: 63 additions & 0 deletions docs/data/api.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {rollups, sort} from "d3";
import {FunctionDeclaration, InterfaceDeclaration, Project} from "ts-morph";

// These interfaces tend to represent things that Plot constructs internally,
// rather than objects that the user is expected to provide.
function isInternalInterface(name) {
return (
name === "AutoSpec" ||
name === "Channel" ||
name === "ChannelTransform" ||
name === "Context" ||
name === "Dimensions" ||
name === "Plot" ||
name === "Scale"
);
}

export default {
async load() {
const project = new Project({tsConfigFilePath: "tsconfig.json"});
const allMethods: {name: string; comment: string | undefined}[] = [];
const allOptions: {name: string; context: string}[] = [];
for (const [name, declarations] of project.getSourceFile("src/index.d.ts")!.getExportedDeclarations()) {
for (const declaration of declarations) {
if (declaration instanceof FunctionDeclaration) {
allMethods.push({
name: declaration.getName()!,
comment: declaration
.getJsDocs()[0]
?.getDescription()
.replace(/\n/g, " ")
.replace(/[*_]/g, "")
.replace(/[.:]($|\s+).*/g, "")
.trim()
});
} else if (declaration instanceof InterfaceDeclaration) {
if (isInternalInterface(name)) continue;
for (const property of declaration.getProperties()) {
allOptions.push({name: property.getName(), context: name});
}
}
}
}
return {
methods: sort(
rollups(
allMethods,
(D) => D.find((d) => d.comment)?.comment,
(d) => d.name
),
([name]) => name
),
options: sort(
rollups(
allOptions,
(D) => D.map((d) => d.context).sort(),
(d) => d.name
),
([name]) => name
)
};
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"prettier": "^3.0.0",
"rollup": "^3.7.0",
"topojson-client": "^3.1.0",
"ts-morph": "^19.0.0",
"typescript": "^5.0.2",
"vite": "^4.0.0",
"vitepress": "^1.0.0-beta.2"
Expand Down
2 changes: 1 addition & 1 deletion src/mark.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,5 @@ export class RenderableMark extends Mark {
/** A compound Mark, comprising other marks. */
export type CompoundMark = Markish[] & Pick<Mark, "plot">;

/** Given an array of marks, returns a compound mark; supports *mark.plot shorthand. */
/** Given an array of marks, returns a compound mark; supports *mark*.plot shorthand. */
export function marks(...marks: Markish[]): CompoundMark;
42 changes: 41 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,16 @@
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-2.0.0.tgz#f544a148d3ab35801c1f633a7441fd87c2e484bf"
integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==

"@ts-morph/common@~0.20.0":
version "0.20.0"
resolved "https://registry.yarnpkg.com/@ts-morph/common/-/common-0.20.0.tgz#3f161996b085ba4519731e4d24c35f6cba5b80af"
integrity sha512-7uKjByfbPpwuzkstL3L5MQyuXPSKdoNG93Fmi2JoDcTf3pEP731JdRFAduRVkOs8oqxPsXKA+ScrWkdQ8t/I+Q==
dependencies:
fast-glob "^3.2.12"
minimatch "^7.4.3"
mkdirp "^2.1.6"
path-browserify "^1.0.1"

"@types/d3-array@*":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@types/d3-array/-/d3-array-3.0.5.tgz#857c1afffd3f51319bbc5b301956aca68acaa7b8"
Expand Down Expand Up @@ -1267,6 +1277,11 @@ cliui@^7.0.2:
strip-ansi "^6.0.0"
wrap-ansi "^7.0.0"

code-block-writer@^12.0.0:
version "12.0.0"
resolved "https://registry.yarnpkg.com/code-block-writer/-/code-block-writer-12.0.0.tgz#4dd58946eb4234105aff7f0035977b2afdc2a770"
integrity sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==

color-convert@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
Expand Down Expand Up @@ -1894,7 +1909,7 @@ fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==

fast-glob@^3.2.9:
fast-glob@^3.2.12, fast-glob@^3.2.9:
version "3.3.0"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.3.0.tgz#7c40cb491e1e2ed5664749e87bfb516dbe8727c0"
integrity sha512-ChDuvbOypPuNjO8yIDf36x7BlZX1smcUMTTcyoIjycexOxd6DFsKsg21qVBzEmr3G7fUKIRy2/psii+CIUt7FA==
Expand Down Expand Up @@ -2482,6 +2497,13 @@ minimatch@^5.0.1:
dependencies:
brace-expansion "^2.0.1"

minimatch@^7.4.3:
version "7.4.6"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-7.4.6.tgz#845d6f254d8f4a5e4fd6baf44d5f10c8448365fb"
integrity sha512-sBz8G/YjVniEz6lKPNpKxXwazJe4c19fEfV2GDMX6AjFz+MX9uDWIZW8XreVhkFW3fkIdTv/gxWr/Kks5FFAVw==
dependencies:
brace-expansion "^2.0.1"

minipass@^3.0.0:
version "3.3.6"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-3.3.6.tgz#7bba384db3a1520d18c9c0e5251c3444e95dd94a"
Expand Down Expand Up @@ -2512,6 +2534,11 @@ mkdirp@^1.0.3:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

mkdirp@^2.1.6:
version "2.1.6"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-2.1.6.tgz#964fbcb12b2d8c5d6fbc62a963ac95a273e2cc19"
integrity sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==

mocha@^10.0.0:
version "10.2.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8"
Expand Down Expand Up @@ -2672,6 +2699,11 @@ parse5@^7.1.2:
dependencies:
entities "^4.4.0"

path-browserify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd"
integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==

path-exists@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3"
Expand Down Expand Up @@ -3106,6 +3138,14 @@ ts-api-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.1.tgz#8144e811d44c749cd65b2da305a032510774452d"
integrity sha512-lC/RGlPmwdrIBFTX59wwNzqh7aR2otPNPR/5brHZm/XKFYKsfqxihXUe9pU3JI+3vGkl+vyCoNNnPhJn3aLK1A==

ts-morph@^19.0.0:
version "19.0.0"
resolved "https://registry.yarnpkg.com/ts-morph/-/ts-morph-19.0.0.tgz#43e95fb0156c3fe3c77c814ac26b7d0be2f93169"
integrity sha512-D6qcpiJdn46tUqV45vr5UGM2dnIEuTGNxVhg0sk5NX11orcouwj6i1bMqZIz2mZTZB1Hcgy7C3oEVhAT+f6mbQ==
dependencies:
"@ts-morph/common" "~0.20.0"
code-block-writer "^12.0.0"

type-check@^0.4.0, type-check@~0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"
Expand Down

0 comments on commit c8a5cb5

Please sign in to comment.