npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

scatter-anti

v1.2.1

Published

A TypeScript library for plotting scatter charts using WebGPU

Downloads

13

Readme

scatter-anti

GitHub license npm version CI Ask DeepWiki

scatter-antiは大規模な散布図を描画するための、TypeScriptライブラリです。

従来の散布図描画ライブラリでは、全文検索などの複雑なフィルタリングに時間がかかりました。scatter-antiは、DuckDB-WASMによるSQL内での高速なデータ処理と、WebGPUによる大規模並列レンダリングを組み合わせることで、数十万点規模のデータでもスムーズな操作を実現します。

  • WebGPUによるレンダリング: GPUの能力を活用し、ブラウザ上で大規模な散布図を高速に描画します。CanvasやSVGでは扱えきれないような大量のデータポイントであっても、スムーズな操作を実現します。

  • DuckDB-WASMによる高速なデータ分析: DuckDB-WASMを内蔵しており、標準的なSQLを実行できます。SQLを使って動的に描画データをフィルタリングしたり、点の色やサイズを計算したりすることが可能です。

  • ラベル表示: データポイントにテキストラベルを表示できます。クラスタリングの結果を可視化する際に、各クラスタの中心や代表点にラベルを表示したり、特定のデータポイントに注釈を付けたりするのに最適です。

画面イメージ

データについて

Parquetファイル

scatter-antiは、Parquet形式のデータファイルを読み込みます。以下のカラムが必要です:

| カラム | 型 | 説明 | |--------|------|------| | x | double | X座標 | | y | double | Y座標 | | IDカラム | 任意 | ポイントを識別するための一意キー(カラム名はidColumnオプションで指定) |

その他のカラムはSQLで参照でき、色やサイズの計算に利用できます。

GeoJSONファイル(ラベル用)

ラベルを表示するには、GeoJSON形式のファイルを指定します:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [x, y]
      },
      "properties": {
        "cluster_label": "ラベルテキスト"
      }
    }
  ]
}

API

const plot = new ScatterPlot({
  canvas: HTMLCanvasElement,  // 描画先のcanvas要素
  dataUrl: string,            // ParquetファイルのURL
  data: {
    idColumn: string,                    // IDカラム名(必須)
    visiblePointLimit?: number,          // 描画最大ポイント数(デフォルト: 100,000)
    sizeSql?: string,                    // サイズ計算SQL式(デフォルト: "3")
    colorSql?: string,                   // 色計算SQL式(ARGB 32bit整数、デフォルト: "0x4D4D4DCC")
    whereConditions?: WhereCondition[],  // フィルタ条件
  },
  gpu?: {
    backgroundColor?: ColorRGBA,  // 背景色
  },
  labels?: {
    url?: string,                        // GeoJSONファイルのURL
    fontSize?: number,                   // フォントサイズ(デフォルト: 12)
    filterLambda?: LabelFilterLambda,    // ラベル表示フィルタ
    onClick?: (label: Label) => void,    // クリックコールバック
  },
  interaction?: {
    onPointHover?: PointHoverCallback,   // ポイントホバーコールバック
    onLabelHover?: LabelHoverCallback,   // ラベルホバーコールバック
  },
});

await plot.initialize();

主要メソッド:

  • render(): 描画
  • setZoom(zoom) / zoomIn() / zoomOut(): ズーム操作
  • setPan(x, y) / getPan(): パン操作
  • resetView(): ビューリセット
  • update(options): オプション更新
  • runQuery(sql): カスタムSQLクエリ実行
  • destroy(): リソース解放

ホバー制御API:

外部コンポーネントからプログラム的にホバー状態を制御できます。

  • setPointHover(pointId): ポイントをホバー状態に(Promise<boolean>
  • clearPointHover(): ポイントホバー解除
  • getHoveredPoint(): ホバー中のポイント取得
  • setLabelHover(identifier): ラベルをホバー状態に(boolean
  • clearLabelHover(): ラベルホバー解除
  • getHoveredLabel(): ホバー中のラベル取得
  • clearAllHover(): 全ホバー解除
// 使用例
await plot.setPointHover(12345);           // IDでポイントをホバー
plot.setLabelHover({ text: 'Cluster A' }); // テキストでラベルをホバー
plot.setLabelHover({ cluster: 5 });        // クラスタ番号でラベルをホバー
plot.clearAllHover();                      // 全ホバー解除

Examples

実行方法

# ライブラリのビルド(ルートディレクトリで)
npm install
npm run build

# サンプルアプリの実行
cd examples/next
npm install
npm run dev

ブラウザで http://localhost:3000 を開きます。

サンプルデータ

サンプルでは、GloVe 6B単語ベクトルをUMAPで2次元に投影したデータを使用しています(約40万単語)。

  • データセット: https://huggingface.co/datasets/mt0rm0/glove.6B.50d.umap.2d

ラベル生成

ラベルはDBSCANクラスタリングとOpenAI APIを使って生成できます:

cd examples/next
export OPENAI_API_KEY="your-api-key"
python scripts/generate_labels.py

ライセンス

このライブラリは MIT License の下でライセンスされています。