@memberjunction/ng-clustering 0.0.1 → 5.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +441 -27
- package/dist/__tests__/clustering-service.test.d.ts +2 -0
- package/dist/__tests__/clustering-service.test.d.ts.map +1 -0
- package/dist/__tests__/clustering-service.test.js +487 -0
- package/dist/__tests__/clustering-service.test.js.map +1 -0
- package/dist/__tests__/clustering-types.test.d.ts +2 -0
- package/dist/__tests__/clustering-types.test.d.ts.map +1 -0
- package/dist/__tests__/clustering-types.test.js +254 -0
- package/dist/__tests__/clustering-types.test.js.map +1 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +7 -0
- package/dist/__tests__/index.test.js.map +1 -0
- package/dist/__tests__/scatter-component-logic.test.d.ts +2 -0
- package/dist/__tests__/scatter-component-logic.test.d.ts.map +1 -0
- package/dist/__tests__/scatter-component-logic.test.js +494 -0
- package/dist/__tests__/scatter-component-logic.test.js.map +1 -0
- package/dist/lib/cluster-config-panel.component.d.ts +274 -0
- package/dist/lib/cluster-config-panel.component.d.ts.map +1 -0
- package/dist/lib/cluster-config-panel.component.js +732 -0
- package/dist/lib/cluster-config-panel.component.js.map +1 -0
- package/dist/lib/cluster-scatter.component.d.ts +572 -0
- package/dist/lib/cluster-scatter.component.d.ts.map +1 -0
- package/dist/lib/cluster-scatter.component.js +1410 -0
- package/dist/lib/cluster-scatter.component.js.map +1 -0
- package/dist/lib/clustering.module.d.ts +12 -0
- package/dist/lib/clustering.module.d.ts.map +1 -0
- package/dist/lib/clustering.module.js +38 -0
- package/dist/lib/clustering.module.js.map +1 -0
- package/dist/lib/clustering.service.d.ts +43 -0
- package/dist/lib/clustering.service.d.ts.map +1 -0
- package/dist/lib/clustering.service.js +253 -0
- package/dist/lib/clustering.service.js.map +1 -0
- package/dist/lib/clustering.types.d.ts +271 -0
- package/dist/lib/clustering.types.d.ts.map +1 -0
- package/dist/lib/clustering.types.js +74 -0
- package/dist/lib/clustering.types.js.map +1 -0
- package/dist/public-api.d.ts +6 -0
- package/dist/public-api.d.ts.map +1 -0
- package/dist/public-api.js +11 -0
- package/dist/public-api.js.map +1 -0
- package/package.json +41 -6
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared types for the clustering visualization library.
|
|
3
|
+
*
|
|
4
|
+
* This module defines every interface, type alias, and constant used across the
|
|
5
|
+
* `@memberjunction/ng-clustering` package. It is the single source of truth for:
|
|
6
|
+
*
|
|
7
|
+
* - **Data shapes** (`ClusterPoint`, `ClusterInfo`, `ClusterVisualizationResult`, ...)
|
|
8
|
+
* - **Configuration** (`ClusterConfig`, `ClusterAlgorithm`, `ClusterDistanceMetric`)
|
|
9
|
+
* - **Event payloads** (`CancelableEvent`, `ViewportRect`, `ClusterSelectedEvent`, ...)
|
|
10
|
+
* - **Constants** (`CLUSTER_COLORS`, `DefaultClusterConfig`)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import {
|
|
15
|
+
* CancelableEvent,
|
|
16
|
+
* ClusterPoint,
|
|
17
|
+
* ClusterConfig,
|
|
18
|
+
* DefaultClusterConfig,
|
|
19
|
+
* } from '@memberjunction/ng-clustering';
|
|
20
|
+
*
|
|
21
|
+
* const cfg = DefaultClusterConfig();
|
|
22
|
+
* cfg.EntityName = 'Companies';
|
|
23
|
+
* cfg.K = 5;
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Generic wrapper for cancelable events emitted by clustering components.
|
|
28
|
+
*
|
|
29
|
+
* The component emits a `CancelableEvent<T>` **before** performing a
|
|
30
|
+
* side-effect. The consumer can inspect `Data`, and set `Cancel = true` to
|
|
31
|
+
* prevent the default behavior.
|
|
32
|
+
*
|
|
33
|
+
* @typeParam T Payload type carried by the event.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```html
|
|
37
|
+
* <mj-cluster-scatter
|
|
38
|
+
* (BeforePointClick)="onBeforeClick($event)">
|
|
39
|
+
* </mj-cluster-scatter>
|
|
40
|
+
* ```
|
|
41
|
+
* ```typescript
|
|
42
|
+
* onBeforeClick(event: CancelableEvent<ClusterPoint>): void {
|
|
43
|
+
* if (event.Data.ClusterId === -1) {
|
|
44
|
+
* event.Cancel = true; // suppress click on outliers
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export interface CancelableEvent<T = unknown> {
|
|
50
|
+
/** The event payload. */
|
|
51
|
+
Data: T;
|
|
52
|
+
/** Set to `true` to cancel the default operation that would follow. */
|
|
53
|
+
Cancel: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Describes the visible rectangle of the scatter plot after a zoom or pan.
|
|
57
|
+
*
|
|
58
|
+
* Coordinates are in the SVG coordinate space (the `viewBox`).
|
|
59
|
+
*/
|
|
60
|
+
export interface ViewportRect {
|
|
61
|
+
/** Left edge X coordinate. */
|
|
62
|
+
MinX: number;
|
|
63
|
+
/** Top edge Y coordinate. */
|
|
64
|
+
MinY: number;
|
|
65
|
+
/** Viewport width in SVG units. */
|
|
66
|
+
Width: number;
|
|
67
|
+
/** Viewport height in SVG units. */
|
|
68
|
+
Height: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Payload emitted when the user clicks a cluster label in the legend.
|
|
72
|
+
*/
|
|
73
|
+
export interface ClusterSelectedEvent {
|
|
74
|
+
/** The numeric cluster ID that was selected. */
|
|
75
|
+
ClusterId: number;
|
|
76
|
+
/** The human-readable label shown in the legend. */
|
|
77
|
+
Label: string;
|
|
78
|
+
/** The display color of the cluster. */
|
|
79
|
+
Color: string;
|
|
80
|
+
/** Number of points belonging to this cluster. */
|
|
81
|
+
MemberCount: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Simple entity option used by the config panel's entity dropdown.
|
|
85
|
+
* The parent component is responsible for populating this list.
|
|
86
|
+
*/
|
|
87
|
+
export interface ClusterConfigPanelEntityOption {
|
|
88
|
+
/** Entity display name shown in the dropdown. */
|
|
89
|
+
Name: string;
|
|
90
|
+
}
|
|
91
|
+
/** Option for the entity document dropdown in the config panel. */
|
|
92
|
+
export interface ClusterConfigPanelEntityDocOption {
|
|
93
|
+
/** Entity Document ID */
|
|
94
|
+
ID: string;
|
|
95
|
+
/** Display name of the entity document */
|
|
96
|
+
Name: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A single vector provided to `ClusteringService.RunClustering()`.
|
|
100
|
+
*
|
|
101
|
+
* The caller is responsible for fetching/building these vectors from
|
|
102
|
+
* whatever data source is appropriate (database, vector index, API, etc.).
|
|
103
|
+
*/
|
|
104
|
+
export interface ClusterInputVector {
|
|
105
|
+
/** Unique key identifying this vector (e.g., a record ID). */
|
|
106
|
+
Key: string;
|
|
107
|
+
/** The raw embedding / feature vector. */
|
|
108
|
+
Vector: number[];
|
|
109
|
+
/** Optional display label for this point (defaults to Key if omitted). */
|
|
110
|
+
Label?: string;
|
|
111
|
+
/** Arbitrary metadata surfaced in tooltips and click handlers. */
|
|
112
|
+
Metadata?: Record<string, unknown>;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A single point in the 2D scatter plot.
|
|
116
|
+
*
|
|
117
|
+
* Each point corresponds to one vectorized entity record after
|
|
118
|
+
* dimensionality reduction (UMAP or PCA).
|
|
119
|
+
*/
|
|
120
|
+
export interface ClusterPoint {
|
|
121
|
+
/** X coordinate in 2D projected space. */
|
|
122
|
+
X: number;
|
|
123
|
+
/** Y coordinate in 2D projected space. */
|
|
124
|
+
Y: number;
|
|
125
|
+
/** Cluster assignment ID (`-1` for outliers / noise). */
|
|
126
|
+
ClusterId: number;
|
|
127
|
+
/** Display label for this point (typically the entity record identifier). */
|
|
128
|
+
Label: string;
|
|
129
|
+
/** Original vector key (e.g., entity record ID). */
|
|
130
|
+
VectorKey: string;
|
|
131
|
+
/** Arbitrary metadata surfaced in tooltips and click handlers. */
|
|
132
|
+
Metadata: Record<string, unknown>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Summary information about a single cluster.
|
|
136
|
+
*
|
|
137
|
+
* Produced by `ClusteringService.RunPipeline()` and consumed by the
|
|
138
|
+
* scatter plot legend and various event payloads.
|
|
139
|
+
*/
|
|
140
|
+
export interface ClusterInfo {
|
|
141
|
+
/** Unique cluster identifier (zero-based). */
|
|
142
|
+
Id: number;
|
|
143
|
+
/** Human-readable label (auto-generated or user-defined). */
|
|
144
|
+
Label: string;
|
|
145
|
+
/** Display color as a CSS hex string (e.g., `#5b8def`). */
|
|
146
|
+
Color: string;
|
|
147
|
+
/** Number of member points in this cluster. */
|
|
148
|
+
MemberCount: number;
|
|
149
|
+
}
|
|
150
|
+
/** Supported clustering algorithms. */
|
|
151
|
+
export type ClusterAlgorithm = 'kmeans' | 'dbscan';
|
|
152
|
+
/** Supported distance metrics for clustering. */
|
|
153
|
+
export type ClusterDistanceMetric = 'cosine' | 'euclidean' | 'dotproduct';
|
|
154
|
+
/**
|
|
155
|
+
* Full configuration for a clustering run.
|
|
156
|
+
*
|
|
157
|
+
* Pass an instance to `ClusteringService.RunPipeline()` or emit from the
|
|
158
|
+
* config panel's `RunClustering` output.
|
|
159
|
+
*/
|
|
160
|
+
export interface ClusterConfig {
|
|
161
|
+
/** Entity name to cluster (must have Entity Documents with vectors). */
|
|
162
|
+
EntityName: string;
|
|
163
|
+
/** Specific Entity Document ID to use. When blank, the first active doc for the entity is used. */
|
|
164
|
+
EntityDocumentID: string;
|
|
165
|
+
/** Clustering algorithm to use. */
|
|
166
|
+
Algorithm: ClusterAlgorithm;
|
|
167
|
+
/** Number of clusters for K-Means (ignored for DBSCAN). */
|
|
168
|
+
K: number;
|
|
169
|
+
/** Epsilon neighbourhood radius for DBSCAN (ignored for K-Means). */
|
|
170
|
+
Epsilon: number;
|
|
171
|
+
/** Minimum points to form a dense region in DBSCAN (ignored for K-Means). */
|
|
172
|
+
MinPoints: number;
|
|
173
|
+
/** Distance metric used when comparing vectors. */
|
|
174
|
+
DistanceMetric: ClusterDistanceMetric;
|
|
175
|
+
/** Maximum number of entity records to fetch for clustering. */
|
|
176
|
+
MaxRecords: number;
|
|
177
|
+
/** Optional SQL-style filter applied to the Entity Document Runs query. */
|
|
178
|
+
Filter: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Quality and performance metrics returned after a clustering run.
|
|
182
|
+
*/
|
|
183
|
+
export interface ClusterMetrics {
|
|
184
|
+
/** Silhouette score ranging from -1 (poor) to 1 (excellent). */
|
|
185
|
+
SilhouetteScore: number;
|
|
186
|
+
/** Total number of clusters discovered. */
|
|
187
|
+
ClusterCount: number;
|
|
188
|
+
/** Wall-clock computation time in milliseconds. */
|
|
189
|
+
ComputationTimeMs: number;
|
|
190
|
+
/** Total records that were processed. */
|
|
191
|
+
RecordCount: number;
|
|
192
|
+
/** Number of outlier points (DBSCAN only; 0 for K-Means). */
|
|
193
|
+
OutlierCount: number;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Complete result of a clustering visualization pipeline.
|
|
197
|
+
*
|
|
198
|
+
* Returned by {@link ClusteringService.RunPipeline} and consumed by
|
|
199
|
+
* both `mj-cluster-scatter` and `mj-cluster-config-panel`.
|
|
200
|
+
*/
|
|
201
|
+
export interface ClusterVisualizationResult {
|
|
202
|
+
/** 2D projected points ready for rendering. */
|
|
203
|
+
Points: ClusterPoint[];
|
|
204
|
+
/** Cluster summaries with colors and counts. */
|
|
205
|
+
Clusters: ClusterInfo[];
|
|
206
|
+
/** Performance and quality metrics. */
|
|
207
|
+
Metrics: ClusterMetrics;
|
|
208
|
+
/** The config that produced this result. */
|
|
209
|
+
Config: ClusterConfig;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Serializable reference to a saved cluster visualization.
|
|
213
|
+
*
|
|
214
|
+
* Persisted via `UserInfoEngine` user settings so the user can reload
|
|
215
|
+
* previous analyses.
|
|
216
|
+
*/
|
|
217
|
+
export interface SavedClusterVisualization {
|
|
218
|
+
/** Unique identifier (UUID). */
|
|
219
|
+
Id: string;
|
|
220
|
+
/** User-given display name. */
|
|
221
|
+
Name: string;
|
|
222
|
+
/** Entity that was clustered. */
|
|
223
|
+
EntityName: string;
|
|
224
|
+
/** Algorithm used. */
|
|
225
|
+
Algorithm: ClusterAlgorithm;
|
|
226
|
+
/** Snapshot of the full config at save time. */
|
|
227
|
+
Params: Partial<ClusterConfig>;
|
|
228
|
+
/** ISO 8601 timestamp of when this was saved. */
|
|
229
|
+
CreatedAt: string;
|
|
230
|
+
/** Cached clustering result (points, clusters, metrics) — avoids re-computation on restore. */
|
|
231
|
+
Result?: ClusterVisualizationResult;
|
|
232
|
+
/** Viewport transform at save time (pan + zoom state). */
|
|
233
|
+
Viewport?: ViewportTransform;
|
|
234
|
+
/** LLM-generated (or user-edited) labels for each cluster. */
|
|
235
|
+
ClusterLabels?: ClusterLabel[];
|
|
236
|
+
}
|
|
237
|
+
/** Viewport pan/zoom state for restoring scatter plot position. */
|
|
238
|
+
export interface ViewportTransform {
|
|
239
|
+
TranslateX: number;
|
|
240
|
+
TranslateY: number;
|
|
241
|
+
Scale: number;
|
|
242
|
+
}
|
|
243
|
+
/** A human-readable label for a cluster. */
|
|
244
|
+
export interface ClusterLabel {
|
|
245
|
+
/** The cluster ID this label applies to. */
|
|
246
|
+
ClusterId: number;
|
|
247
|
+
/** Short descriptive label (2-5 words). */
|
|
248
|
+
Label: string;
|
|
249
|
+
/** Whether the user has manually edited this label. */
|
|
250
|
+
IsUserEdited: boolean;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Default cluster color palette -- 10 distinct, accessible colors.
|
|
254
|
+
*
|
|
255
|
+
* Override at the component level via `ClusterScatterComponent.ColorPalette`.
|
|
256
|
+
*/
|
|
257
|
+
export declare const CLUSTER_COLORS: string[];
|
|
258
|
+
/**
|
|
259
|
+
* Create a `ClusterConfig` populated with sensible defaults.
|
|
260
|
+
*
|
|
261
|
+
* @returns A new `ClusterConfig` with K-Means / cosine / 500 max records.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* const cfg = DefaultClusterConfig();
|
|
266
|
+
* cfg.EntityName = 'Accounts';
|
|
267
|
+
* cfg.K = 6;
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
export declare function DefaultClusterConfig(): ClusterConfig;
|
|
271
|
+
//# sourceMappingURL=clustering.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clustering.types.d.ts","sourceRoot":"","sources":["../../src/lib/clustering.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IACxC,yBAAyB;IACzB,IAAI,EAAE,CAAC,CAAC;IACR,uEAAuE;IACvE,MAAM,EAAE,OAAO,CAAC;CACnB;AAMD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IACzB,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;CACvB;AAMD;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC3C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AAS,EAAE,MAAM,CAAC;IAClB,+FAA+F;IAC/F,MAAM,CAAC,EAAE,0BAA0B,CAAC;IACpC,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,8DAA8D;IAC9D,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;CAClC;AAED,mEAAmE;AACnE,MAAM,WAAW,iBAAiB;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,4CAA4C;AAC5C,MAAM,WAAW,YAAY;IACzB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,YAAY,EAAE,OAAO,CAAC;CACzB;AAMD;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,EAWlC,CAAC;AAMF;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,IAAI,aAAa,CAYpD"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared types for the clustering visualization library.
|
|
3
|
+
*
|
|
4
|
+
* This module defines every interface, type alias, and constant used across the
|
|
5
|
+
* `@memberjunction/ng-clustering` package. It is the single source of truth for:
|
|
6
|
+
*
|
|
7
|
+
* - **Data shapes** (`ClusterPoint`, `ClusterInfo`, `ClusterVisualizationResult`, ...)
|
|
8
|
+
* - **Configuration** (`ClusterConfig`, `ClusterAlgorithm`, `ClusterDistanceMetric`)
|
|
9
|
+
* - **Event payloads** (`CancelableEvent`, `ViewportRect`, `ClusterSelectedEvent`, ...)
|
|
10
|
+
* - **Constants** (`CLUSTER_COLORS`, `DefaultClusterConfig`)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import {
|
|
15
|
+
* CancelableEvent,
|
|
16
|
+
* ClusterPoint,
|
|
17
|
+
* ClusterConfig,
|
|
18
|
+
* DefaultClusterConfig,
|
|
19
|
+
* } from '@memberjunction/ng-clustering';
|
|
20
|
+
*
|
|
21
|
+
* const cfg = DefaultClusterConfig();
|
|
22
|
+
* cfg.EntityName = 'Companies';
|
|
23
|
+
* cfg.K = 5;
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
// ================================================================
|
|
27
|
+
// Constants
|
|
28
|
+
// ================================================================
|
|
29
|
+
/**
|
|
30
|
+
* Default cluster color palette -- 10 distinct, accessible colors.
|
|
31
|
+
*
|
|
32
|
+
* Override at the component level via `ClusterScatterComponent.ColorPalette`.
|
|
33
|
+
*/
|
|
34
|
+
export const CLUSTER_COLORS = [
|
|
35
|
+
'#5b8def', // blue
|
|
36
|
+
'#34d399', // emerald
|
|
37
|
+
'#fbbf24', // amber
|
|
38
|
+
'#f472b6', // pink
|
|
39
|
+
'#a78bfa', // violet
|
|
40
|
+
'#fb923c', // orange
|
|
41
|
+
'#22d3ee', // cyan
|
|
42
|
+
'#f87171', // red
|
|
43
|
+
'#4ade80', // green
|
|
44
|
+
'#e879f9', // fuchsia
|
|
45
|
+
];
|
|
46
|
+
// ================================================================
|
|
47
|
+
// Factory functions
|
|
48
|
+
// ================================================================
|
|
49
|
+
/**
|
|
50
|
+
* Create a `ClusterConfig` populated with sensible defaults.
|
|
51
|
+
*
|
|
52
|
+
* @returns A new `ClusterConfig` with K-Means / cosine / 500 max records.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const cfg = DefaultClusterConfig();
|
|
57
|
+
* cfg.EntityName = 'Accounts';
|
|
58
|
+
* cfg.K = 6;
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function DefaultClusterConfig() {
|
|
62
|
+
return {
|
|
63
|
+
EntityName: '',
|
|
64
|
+
EntityDocumentID: '',
|
|
65
|
+
Algorithm: 'kmeans',
|
|
66
|
+
K: 4,
|
|
67
|
+
Epsilon: 0.3,
|
|
68
|
+
MinPoints: 3,
|
|
69
|
+
DistanceMetric: 'cosine',
|
|
70
|
+
MaxRecords: 500,
|
|
71
|
+
Filter: '',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=clustering.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clustering.types.js","sourceRoot":"","sources":["../../src/lib/clustering.types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAwQH,mEAAmE;AACnE,YAAY;AACZ,mEAAmE;AAEnE;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAa;IACpC,SAAS,EAAE,OAAO;IAClB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,OAAO;IAClB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,OAAO;IAClB,SAAS,EAAE,MAAM;IACjB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,UAAU;CACxB,CAAC;AAEF,mEAAmE;AACnE,oBAAoB;AACpB,mEAAmE;AAEnE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB;IAChC,OAAO;QACH,UAAU,EAAE,EAAE;QACd,gBAAgB,EAAE,EAAE;QACpB,SAAS,EAAE,QAAQ;QACnB,CAAC,EAAE,CAAC;QACJ,OAAO,EAAE,GAAG;QACZ,SAAS,EAAE,CAAC;QACZ,cAAc,EAAE,QAAQ;QACxB,UAAU,EAAE,GAAG;QACf,MAAM,EAAE,EAAE;KACb,CAAC;AACN,CAAC","sourcesContent":["/**\n * @fileoverview Shared types for the clustering visualization library.\n *\n * This module defines every interface, type alias, and constant used across the\n * `@memberjunction/ng-clustering` package. It is the single source of truth for:\n *\n * - **Data shapes** (`ClusterPoint`, `ClusterInfo`, `ClusterVisualizationResult`, ...)\n * - **Configuration** (`ClusterConfig`, `ClusterAlgorithm`, `ClusterDistanceMetric`)\n * - **Event payloads** (`CancelableEvent`, `ViewportRect`, `ClusterSelectedEvent`, ...)\n * - **Constants** (`CLUSTER_COLORS`, `DefaultClusterConfig`)\n *\n * @example\n * ```typescript\n * import {\n * CancelableEvent,\n * ClusterPoint,\n * ClusterConfig,\n * DefaultClusterConfig,\n * } from '@memberjunction/ng-clustering';\n *\n * const cfg = DefaultClusterConfig();\n * cfg.EntityName = 'Companies';\n * cfg.K = 5;\n * ```\n */\n\n// ================================================================\n// Cancelable event pattern\n// ================================================================\n\n/**\n * Generic wrapper for cancelable events emitted by clustering components.\n *\n * The component emits a `CancelableEvent<T>` **before** performing a\n * side-effect. The consumer can inspect `Data`, and set `Cancel = true` to\n * prevent the default behavior.\n *\n * @typeParam T Payload type carried by the event.\n *\n * @example\n * ```html\n * <mj-cluster-scatter\n * (BeforePointClick)=\"onBeforeClick($event)\">\n * </mj-cluster-scatter>\n * ```\n * ```typescript\n * onBeforeClick(event: CancelableEvent<ClusterPoint>): void {\n * if (event.Data.ClusterId === -1) {\n * event.Cancel = true; // suppress click on outliers\n * }\n * }\n * ```\n */\nexport interface CancelableEvent<T = unknown> {\n /** The event payload. */\n Data: T;\n /** Set to `true` to cancel the default operation that would follow. */\n Cancel: boolean;\n}\n\n// ================================================================\n// Viewport / selection event payloads\n// ================================================================\n\n/**\n * Describes the visible rectangle of the scatter plot after a zoom or pan.\n *\n * Coordinates are in the SVG coordinate space (the `viewBox`).\n */\nexport interface ViewportRect {\n /** Left edge X coordinate. */\n MinX: number;\n /** Top edge Y coordinate. */\n MinY: number;\n /** Viewport width in SVG units. */\n Width: number;\n /** Viewport height in SVG units. */\n Height: number;\n}\n\n/**\n * Payload emitted when the user clicks a cluster label in the legend.\n */\nexport interface ClusterSelectedEvent {\n /** The numeric cluster ID that was selected. */\n ClusterId: number;\n /** The human-readable label shown in the legend. */\n Label: string;\n /** The display color of the cluster. */\n Color: string;\n /** Number of points belonging to this cluster. */\n MemberCount: number;\n}\n\n// ================================================================\n// Config panel types\n// ================================================================\n\n/**\n * Simple entity option used by the config panel's entity dropdown.\n * The parent component is responsible for populating this list.\n */\nexport interface ClusterConfigPanelEntityOption {\n /** Entity display name shown in the dropdown. */\n Name: string;\n}\n\n/** Option for the entity document dropdown in the config panel. */\nexport interface ClusterConfigPanelEntityDocOption {\n /** Entity Document ID */\n ID: string;\n /** Display name of the entity document */\n Name: string;\n}\n\n// ================================================================\n// Input types\n// ================================================================\n\n/**\n * A single vector provided to `ClusteringService.RunClustering()`.\n *\n * The caller is responsible for fetching/building these vectors from\n * whatever data source is appropriate (database, vector index, API, etc.).\n */\nexport interface ClusterInputVector {\n /** Unique key identifying this vector (e.g., a record ID). */\n Key: string;\n /** The raw embedding / feature vector. */\n Vector: number[];\n /** Optional display label for this point (defaults to Key if omitted). */\n Label?: string;\n /** Arbitrary metadata surfaced in tooltips and click handlers. */\n Metadata?: Record<string, unknown>;\n}\n\n// ================================================================\n// Core data types\n// ================================================================\n\n/**\n * A single point in the 2D scatter plot.\n *\n * Each point corresponds to one vectorized entity record after\n * dimensionality reduction (UMAP or PCA).\n */\nexport interface ClusterPoint {\n /** X coordinate in 2D projected space. */\n X: number;\n /** Y coordinate in 2D projected space. */\n Y: number;\n /** Cluster assignment ID (`-1` for outliers / noise). */\n ClusterId: number;\n /** Display label for this point (typically the entity record identifier). */\n Label: string;\n /** Original vector key (e.g., entity record ID). */\n VectorKey: string;\n /** Arbitrary metadata surfaced in tooltips and click handlers. */\n Metadata: Record<string, unknown>;\n}\n\n/**\n * Summary information about a single cluster.\n *\n * Produced by `ClusteringService.RunPipeline()` and consumed by the\n * scatter plot legend and various event payloads.\n */\nexport interface ClusterInfo {\n /** Unique cluster identifier (zero-based). */\n Id: number;\n /** Human-readable label (auto-generated or user-defined). */\n Label: string;\n /** Display color as a CSS hex string (e.g., `#5b8def`). */\n Color: string;\n /** Number of member points in this cluster. */\n MemberCount: number;\n}\n\n/** Supported clustering algorithms. */\nexport type ClusterAlgorithm = 'kmeans' | 'dbscan';\n\n/** Supported distance metrics for clustering. */\nexport type ClusterDistanceMetric = 'cosine' | 'euclidean' | 'dotproduct';\n\n/**\n * Full configuration for a clustering run.\n *\n * Pass an instance to `ClusteringService.RunPipeline()` or emit from the\n * config panel's `RunClustering` output.\n */\nexport interface ClusterConfig {\n /** Entity name to cluster (must have Entity Documents with vectors). */\n EntityName: string;\n /** Specific Entity Document ID to use. When blank, the first active doc for the entity is used. */\n EntityDocumentID: string;\n /** Clustering algorithm to use. */\n Algorithm: ClusterAlgorithm;\n /** Number of clusters for K-Means (ignored for DBSCAN). */\n K: number;\n /** Epsilon neighbourhood radius for DBSCAN (ignored for K-Means). */\n Epsilon: number;\n /** Minimum points to form a dense region in DBSCAN (ignored for K-Means). */\n MinPoints: number;\n /** Distance metric used when comparing vectors. */\n DistanceMetric: ClusterDistanceMetric;\n /** Maximum number of entity records to fetch for clustering. */\n MaxRecords: number;\n /** Optional SQL-style filter applied to the Entity Document Runs query. */\n Filter: string;\n}\n\n/**\n * Quality and performance metrics returned after a clustering run.\n */\nexport interface ClusterMetrics {\n /** Silhouette score ranging from -1 (poor) to 1 (excellent). */\n SilhouetteScore: number;\n /** Total number of clusters discovered. */\n ClusterCount: number;\n /** Wall-clock computation time in milliseconds. */\n ComputationTimeMs: number;\n /** Total records that were processed. */\n RecordCount: number;\n /** Number of outlier points (DBSCAN only; 0 for K-Means). */\n OutlierCount: number;\n}\n\n/**\n * Complete result of a clustering visualization pipeline.\n *\n * Returned by {@link ClusteringService.RunPipeline} and consumed by\n * both `mj-cluster-scatter` and `mj-cluster-config-panel`.\n */\nexport interface ClusterVisualizationResult {\n /** 2D projected points ready for rendering. */\n Points: ClusterPoint[];\n /** Cluster summaries with colors and counts. */\n Clusters: ClusterInfo[];\n /** Performance and quality metrics. */\n Metrics: ClusterMetrics;\n /** The config that produced this result. */\n Config: ClusterConfig;\n}\n\n/**\n * Serializable reference to a saved cluster visualization.\n *\n * Persisted via `UserInfoEngine` user settings so the user can reload\n * previous analyses.\n */\nexport interface SavedClusterVisualization {\n /** Unique identifier (UUID). */\n Id: string;\n /** User-given display name. */\n Name: string;\n /** Entity that was clustered. */\n EntityName: string;\n /** Algorithm used. */\n Algorithm: ClusterAlgorithm;\n /** Snapshot of the full config at save time. */\n Params: Partial<ClusterConfig>;\n /** ISO 8601 timestamp of when this was saved. */\n CreatedAt: string;\n /** Cached clustering result (points, clusters, metrics) — avoids re-computation on restore. */\n Result?: ClusterVisualizationResult;\n /** Viewport transform at save time (pan + zoom state). */\n Viewport?: ViewportTransform;\n /** LLM-generated (or user-edited) labels for each cluster. */\n ClusterLabels?: ClusterLabel[];\n}\n\n/** Viewport pan/zoom state for restoring scatter plot position. */\nexport interface ViewportTransform {\n TranslateX: number;\n TranslateY: number;\n Scale: number;\n}\n\n/** A human-readable label for a cluster. */\nexport interface ClusterLabel {\n /** The cluster ID this label applies to. */\n ClusterId: number;\n /** Short descriptive label (2-5 words). */\n Label: string;\n /** Whether the user has manually edited this label. */\n IsUserEdited: boolean;\n}\n\n// ================================================================\n// Constants\n// ================================================================\n\n/**\n * Default cluster color palette -- 10 distinct, accessible colors.\n *\n * Override at the component level via `ClusterScatterComponent.ColorPalette`.\n */\nexport const CLUSTER_COLORS: string[] = [\n '#5b8def', // blue\n '#34d399', // emerald\n '#fbbf24', // amber\n '#f472b6', // pink\n '#a78bfa', // violet\n '#fb923c', // orange\n '#22d3ee', // cyan\n '#f87171', // red\n '#4ade80', // green\n '#e879f9', // fuchsia\n];\n\n// ================================================================\n// Factory functions\n// ================================================================\n\n/**\n * Create a `ClusterConfig` populated with sensible defaults.\n *\n * @returns A new `ClusterConfig` with K-Means / cosine / 500 max records.\n *\n * @example\n * ```typescript\n * const cfg = DefaultClusterConfig();\n * cfg.EntityName = 'Accounts';\n * cfg.K = 6;\n * ```\n */\nexport function DefaultClusterConfig(): ClusterConfig {\n return {\n EntityName: '',\n EntityDocumentID: '',\n Algorithm: 'kmeans',\n K: 4,\n Epsilon: 0.3,\n MinPoints: 3,\n DistanceMetric: 'cosine',\n MaxRecords: 500,\n Filter: '',\n };\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './lib/clustering.module';
|
|
2
|
+
export * from './lib/cluster-scatter.component';
|
|
3
|
+
export * from './lib/cluster-config-panel.component';
|
|
4
|
+
export * from './lib/clustering.service';
|
|
5
|
+
export * from './lib/clustering.types';
|
|
6
|
+
//# sourceMappingURL=public-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AAGxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AAGrD,cAAc,0BAA0B,CAAC;AAGzC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Public API Surface of @memberjunction/ng-clustering
|
|
2
|
+
// Module
|
|
3
|
+
export * from './lib/clustering.module';
|
|
4
|
+
// Components
|
|
5
|
+
export * from './lib/cluster-scatter.component';
|
|
6
|
+
export * from './lib/cluster-config-panel.component';
|
|
7
|
+
// Service
|
|
8
|
+
export * from './lib/clustering.service';
|
|
9
|
+
// Types
|
|
10
|
+
export * from './lib/clustering.types';
|
|
11
|
+
//# sourceMappingURL=public-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-api.js","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAAA,sDAAsD;AAEtD,SAAS;AACT,cAAc,yBAAyB,CAAC;AAExC,aAAa;AACb,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AAErD,UAAU;AACV,cAAc,0BAA0B,CAAC;AAEzC,QAAQ;AACR,cAAc,wBAAwB,CAAC","sourcesContent":["// Public API Surface of @memberjunction/ng-clustering\n\n// Module\nexport * from './lib/clustering.module';\n\n// Components\nexport * from './lib/cluster-scatter.component';\nexport * from './lib/cluster-config-panel.component';\n\n// Service\nexport * from './lib/clustering.service';\n\n// Types\nexport * from './lib/clustering.types';\n"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-clustering",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.24.0",
|
|
4
|
+
"description": "MemberJunction: Reusable Angular clustering visualization components with scatter plot, config panel, and clustering service",
|
|
5
|
+
"main": "./dist/public-api.js",
|
|
6
|
+
"typings": "./dist/public-api.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "vitest run",
|
|
12
|
+
"build": "ngc",
|
|
13
|
+
"test:watch": "vitest"
|
|
14
|
+
},
|
|
5
15
|
"keywords": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
16
|
+
"angular",
|
|
17
|
+
"clustering",
|
|
18
|
+
"visualization",
|
|
19
|
+
"scatter-plot",
|
|
20
|
+
"memberjunction"
|
|
21
|
+
],
|
|
22
|
+
"author": "MemberJunction",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@angular/compiler": "21.1.3",
|
|
26
|
+
"@angular/compiler-cli": "21.1.3",
|
|
27
|
+
"vitest": "^4.0.18"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@angular/common": "21.1.3",
|
|
31
|
+
"@angular/core": "21.1.3",
|
|
32
|
+
"@angular/forms": "21.1.3"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@memberjunction/ai-vectors-memory": "5.24.0",
|
|
36
|
+
"@memberjunction/ng-entity-card": "5.24.0",
|
|
37
|
+
"tslib": "^2.8.1",
|
|
38
|
+
"umap-js": "^1.4.0"
|
|
39
|
+
},
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/MemberJunction/MJ"
|
|
44
|
+
}
|
|
10
45
|
}
|