-
Notifications
You must be signed in to change notification settings - Fork 214
refactor: move the density clustering code to its own internal package #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ build/ | |
| dist/ | ||
| distlib/ | ||
| target/ | ||
| pkg/ | ||
| .svelte-kit/ | ||
| .env | ||
| .env.* | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| // Copyright (c) 2025 Apple Inc. Licensed under MIT License. | ||
|
|
||
| import { findClusters } from "../../density_clustering/find_clusters.js"; | ||
| import { findClusters } from "@embedding-atlas/density-clustering"; | ||
| import { dynamicLabelPlacement } from "../../dynamic_label_placement/dynamic_label_placement.js"; | ||
|
|
||
| export { dynamicLabelPlacement, findClusters }; |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /** A resulting cluster from the find clusters function */ | ||
| export interface Cluster { | ||
| /** Cluster identifier */ | ||
| identifier: number; | ||
| /** The total density */ | ||
| sum_density: number; | ||
| /** The mean x location (weighted by density) */ | ||
| mean_x: number; | ||
| /** The mean y location (weighted by density) */ | ||
| mean_y: number; | ||
| /** The maximum density */ | ||
| max_density: number; | ||
| /** The location with the maximum density */ | ||
| max_density_location: [number, number]; | ||
| /** The number of pixels in the cluster */ | ||
| pixel_count: number; | ||
| /** The cluster's boundary represented as a list of polygons */ | ||
| boundary?: [number, number][][]; | ||
| /** The cluster's boundary approximated with a list of rectangles */ | ||
| boundary_rect_approximation?: [number, number, number, number][]; | ||
| } | ||
|
|
||
| /** Options of the find clusters function */ | ||
| export interface FindClustersOptions { | ||
| /** The threshold for unioning two clusters */ | ||
| union_threshold: number; | ||
| } | ||
|
|
||
| /** | ||
| * Find clusters from a density map | ||
| * @param density_map the density map, a `Float32Array` with `width * height` elements | ||
| * @param width the width of the density map | ||
| * @param height the height of the density map | ||
| * @param options algorithm options | ||
| * @returns | ||
| */ | ||
| export async function findClusters( | ||
| density_map: Float32Array, | ||
| width: number, | ||
| height: number, | ||
| options: Partial<FindClustersOptions> = {}, | ||
| ): Promise<Cluster[]>; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "name": "@embedding-atlas/density-clustering", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to publish this as a package or leave it internal?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API is already published as part of the |
||
| "description": "A WebAssembly implementation of a density-based clustering algorithm", | ||
| "main": "density_clustering_wasm/js/index.js", | ||
| "module": "density_clustering_wasm/js/index.js", | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "npx wasm-pack build --release --target web density_clustering_wasm && rm density_clustering_wasm/pkg/.gitignore density_clustering_wasm/pkg/package.json" | ||
| }, | ||
| "files": [ | ||
| "density_clustering_wasm/js/index.js", | ||
| "density_clustering_wasm/pkg/density_clustering_wasm.js", | ||
| "density_clustering_wasm/pkg/density_clustering_wasm_bg.wasm" | ||
| ] | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose these are mapping to native names so we use snake case instead of camel case which would be common in js?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they map to Rust code. I think camel case would be better for JS, but this PR is just to move the code to a new home, so no changes to the naming.