# @graphistry/client-api 中文文档

规范地址：https://npmcn.com/package/%40graphistry/client-api/

版本：5\.1\.8
npm 元数据更新时间：2025-07-16T17:52:28.843Z
中文译文更新时间：2026-11-17T03:53:21.961Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40graphistry/client-api
原文对照：https://npmcn.com/package/%40graphistry/client-api/?lang=original
项目主页：https://github.com/graphistry/graphistry-js/projects/client-api#readme
源码仓库：https://github.com/graphistry/graphistry-js

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：20.1 MB，62 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- 运行依赖：5 个
- peer 依赖：rxjs \>=7\.2\.0
- 首次发布：2017-05-17T10:29:10.523Z
- 最新版本发布：2025-07-16T17:52:28.579Z
- 近 30 天下载量：7103（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：89（近 12 个月 0 个）

## 中文简介

客户端 API 用于与 Graphistry 嵌入式可视化交互.

## 安装

```sh
npm install @graphistry/client-api
```

也可以使用：`pnpm add @graphistry/client-api`、`yarn add @graphistry/client-api`、`bun add @graphistry/client-api`

## README

# Graphistry 的 JavaScript 客户端 API

## Graphistry的客户端-侧式交互API使得开发者容易与嵌入式图形可视化交互.

### 安装

JS软件包支持通用js,esm和iffe格式. 见 [软件包.json](https://npmcn.com/package/%40graphistry/client-api/package.json) 页:1 `dist/` 文件夹内容.

这个 `rxjs` 版本是一个未绑定的对等依赖 :

-   捆绑的版本 `dist/index.{cjs,esm,iife}.min.js` 保留 `rxjs` 作为外部软件包
-   捆绑的版本 `dist/index.full.{cjs,esm,iife}.min.js` 包括它
-   使用 `dist/index.full.iife.min.js` 页:1 `<script src="..."/>` 标记

## 文档

1.  要使用此交互 API,请使用 IFrame 调用 GraphistryJS ,其中包含有图解活化
2.  见 [客户端- api](https://npmcn.com/package/%40graphistry/client-api/projects/client-api/README.md) (单位:千美元)[交互式故事书](https://graphistry.github.io/graphistry-js/?path=/story/graphistry-vanilla-js)(中文(简体) )
3.  关于目前支持的方法,请参看Graphistry类。 再来点!
4.  参考GraphistryJS中的例子

另见 [@ graphistry/ 客户端- api- react 反应文件](https://npmcn.com/package/%40graphistry/client-api-react)

## 导入

根据模块格式,您可以使用 `import`, (中文(简体) ), `require`,以及 `window.GraphistryModule`数字 :

```javascript
const G = GraphistryModule;
const g = G.graphistryJS(elt);
```

```javascript
import { graphistryJS } from '@graphistry/client-api';
const g = graphistryJS(elt);
```

```javascript
const G = require('@graphistry/client-api');
const g = G.graphistryJS(elt);
```

## 双重使用模式

图书馆揭露出两个召募会从中选择.

#### RxJS 组合

```javascript
const G = GraphistryModule;
document.addEventListener("DOMContentLoaded", function () {

    var g = G.graphistryJS(document.getElementById('viz'));
    var sub = g.pipe(
            G.tap(() => console.log('GraphistryJS ready instance as window.g')),
            G.delay(5000),
            G.addFilter('point:degree > 1'),
            G.updateSetting('background', '#FF0000')
        )
        .subscribe(
            function () {},
            function (err) { console.error('exn on setup', err); },
            function () { console.log('finished setup'); });

    //Optional: sub.unsubscribe() to cancel

});
```

#### Async 命令

```javascript
const G = GraphistryModule;
document.addEventListener("DOMContentLoaded", function () {

    var g = G.graphistryJS(document.getElementById('viz'));
    g.pipe(
        G.tap(() => {

            //non-rxjs on ready g
            console.log('GraphistryJS ready instance as window.g');
            setTimeout(
                () => {
                    g.addFilter();
                    g.updateSetting('background', '#FF0000');
                },
                5000);

        }))
        .subscribe();

});
```

## 上传

您也可以使用库配置并上传可视化数据,并获取数据集ID以嵌入为活式可视化:

```javascript
import { Client, Dataset, File, EdgeFile, NodeFile } from '@graphistry/client-api';

//defaults: 'https', 'hub.graphistry.com', 'https://hub.graphistry.com'
const client = new Client('my_username', 'my_password');

//columnar data is fastest; column per attribute; reuse across datasets
const edgesFile = new EdgeFile({'s': ['a1', 'b2'], 'd': ['b2', 'c3']});
const nodesFile = new NodeFile({'n': ['a1', 'b2', 'c3'], 'a1': ['x', 'y', 'z']});

const dataset = new Dataset({
    node_encodings: { bindings: { node: 'n' } },
    edge_encodings: { bindings: { source: 's', destination: 'd' } },
    metadata: {},
    name: 'testdata',
}, edgesFile, nodesFile);

await dataset.upload();
console.info(`View at ${dataset.datasetID} at ${dataset.datasetURL}`);
```

参见本报告中的其他例子 `@graphistry/node-api` 这里的文件或 API 引用

## 常见问题

### @graphistry/client-api 是什么？

客户端 API 用于与 Graphistry 嵌入式可视化交互\.

### 如何安装 @graphistry/client-api？

在项目目录运行 npm install @graphistry/client-api，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：rxjs（\>=7\.2\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @graphistry/client-api 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/graphistry\_\_client-api 是否存在。

### @graphistry/client-api 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @graphistry/client-api 可以商用吗？

@graphistry/client-api 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @graphistry/client-api 的下载量有多少？

根据 npm 官方下载统计，@graphistry/client-api 在 2026/10/17 – 2026/11/15 这 30 天内被下载 7,103 次，日均约 237 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @graphistry/client-api 还在维护吗？

最新版本 5\.1\.8 发布于 2025/07/17（1\.3 年前）；至今共发布 89 个版本，其中过去 12 个月发布了 0 个；首次发布于 2017/05/17。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

