plebeiangraphlibrary 2.0.1 → 2.1.2

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.
Files changed (58) hide show
  1. package/Build/Core/Edge.d.ts +20 -0
  2. package/Build/Core/Graph.d.ts +114 -0
  3. package/Build/Core/_Node.d.ts +20 -0
  4. package/Build/Core/index.d.ts +3 -0
  5. package/Build/Drawing/Drawing.d.ts +129 -0
  6. package/Build/Drawing/GraphDrawer.d.ts +70 -0
  7. package/Build/Drawing/MeshLineGeometry.d.ts +11 -0
  8. package/Build/Drawing/MeshLineMaterial.d.ts +16 -0
  9. package/Build/Drawing/ThickLine.d.ts +21 -0
  10. package/Build/Drawing/ThreeJSDrawer.d.ts +197 -0
  11. package/Build/Drawing/index.d.ts +3 -0
  12. package/Build/GraphAlgorithms/GraphMethods.d.ts +47 -0
  13. package/Build/GraphAlgorithms/index.d.ts +1 -0
  14. package/Build/HelperClasses/ColorHelper.d.ts +21 -0
  15. package/Build/HelperClasses/GeometryHelpers.d.ts +31 -0
  16. package/Build/HelperClasses/GraphConstructors.d.ts +12 -0
  17. package/Build/HelperClasses/Line.d.ts +12 -0
  18. package/Build/HelperClasses/Point.d.ts +26 -0
  19. package/Build/HelperClasses/Utilities.d.ts +45 -0
  20. package/Build/HelperClasses/index.d.ts +3 -0
  21. package/Build/Hierarchy/KDDistanceStrategy.d.ts +8 -0
  22. package/Build/Hierarchy/KDTree.d.ts +10 -0
  23. package/Build/Hierarchy/buildSimplifiedGraph.d.ts +7 -0
  24. package/Build/Hierarchy/index.d.ts +29 -0
  25. package/Build/Hierarchy/types.d.ts +33 -0
  26. package/Build/MatrixHelpers.d.ts +12 -0
  27. package/Build/Models/ErdosRenyiModel.d.ts +13 -0
  28. package/Build/Models/index.d.ts +1 -0
  29. package/Build/SampleData/DataLoader.d.ts +49 -0
  30. package/Build/SampleData/ZKC.d.ts +5 -0
  31. package/Build/SampleData/ZKC_simulated.d.ts +10 -0
  32. package/Build/SampleData/dwt_1005.d.ts +1008 -0
  33. package/Build/SampleData/index.d.ts +2 -0
  34. package/Build/Shaders/fragmentShader.glsl.d.ts +2 -0
  35. package/Build/Shaders/vertexShader.glsl.d.ts +2 -0
  36. package/Build/Simulation/KamadaKawai3D.d.ts +30 -0
  37. package/Build/Simulation/Octree.d.ts +34 -0
  38. package/Build/Simulation/StressSGD3D.d.ts +45 -0
  39. package/Build/Simulation/index.d.ts +4 -0
  40. package/Build/index.d.ts +40 -0
  41. package/Build/pgl.js +3824 -3389
  42. package/Build/pgl.js.map +1 -1
  43. package/Build/pgl_module.js +20827 -35564
  44. package/Build/pgl_module.js.map +1 -1
  45. package/Examples/10_Adjacency_matrix.html +74 -0
  46. package/Examples/11_Custom_layout.html +89 -0
  47. package/Examples/12_StressSGD_simulation_live.html +80 -0
  48. package/Examples/13_StressSGD_bunny_3d.html +104 -0
  49. package/Examples/4_ToggleActivation.html +1 -1
  50. package/Examples/5_Hierarchy_simple.html +5 -2
  51. package/Examples/9_Simulation_live.html +74 -0
  52. package/Examples/data/bunny.obj +7474 -0
  53. package/Examples/examples.html +27 -2
  54. package/README.md +42 -10
  55. package/package.json +15 -23
  56. package/Build/Textures/Square.png +0 -0
  57. package/Build/pgl.d.ts +0 -703
  58. package/Build/pgl.d.ts.map +0 -1
@@ -0,0 +1,21 @@
1
+ /**
2
+ *
3
+ * Converts Rgb to hex
4
+ *
5
+ * @param r red value
6
+ * @param g green value
7
+ * @param b blue value
8
+ * @returns the hex value
9
+ */
10
+ declare function rgbToHex(r: number, g: number, b: number): string;
11
+ /**
12
+ *
13
+ * @param hex the hex color code
14
+ * @returns RGB values as r, g, b values
15
+ */
16
+ declare function hexToRgb(hex: string | number): {
17
+ r: number;
18
+ g: number;
19
+ b: number;
20
+ } | null;
21
+ export { rgbToHex, hexToRgb };
@@ -0,0 +1,31 @@
1
+ import { default as Point } from './Point';
2
+ import { default as Line } from './Line';
3
+ /**
4
+ * Creates a line based on the number of divisons
5
+ *
6
+ * @param start the start point
7
+ * @param end the end point
8
+ * @param divisions the number of divisions
9
+ * @returns the line object
10
+ */
11
+ declare function line_from_start_end_divisions(start: Point, end: Point, divisions: number): Line;
12
+ /**
13
+ * Divides the line into a number of divisions based on distance
14
+ * @param start - the start point
15
+ * @param end - the end point
16
+ * @param distance - the distance at which this line must be divided
17
+ * @returns A line object with the right number of points
18
+ */
19
+ declare function line_from_start_end_distance(start: Point, end: Point, distance: number): Line;
20
+ /**
21
+ * Calculates the centroid of an array of points
22
+ * @param points An array of points
23
+ * @returns the central point of the array of points
24
+ */
25
+ declare function centroid(points: Point[]): Point;
26
+ declare const _default: {
27
+ line_from_start_end_divisions: typeof line_from_start_end_divisions;
28
+ line_from_start_end_distance: typeof line_from_start_end_distance;
29
+ centroid: typeof centroid;
30
+ };
31
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { default as Graph } from '../Core/Graph';
2
+ /**
3
+ * construct a graph based on an edge list and node list
4
+ * @param nodes nodes as a list
5
+ * @param edges edges as a list
6
+ * @returns A graph that was construct from the list of nodes and edges
7
+ */
8
+ declare function ConstructGraphNodeEdgesList(nodes: any[], edges: any[]): Promise<Graph>;
9
+ declare const _default: {
10
+ ConstructGraphNodeEdgesList: typeof ConstructGraphNodeEdgesList;
11
+ };
12
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { default as Point } from './Point';
2
+ interface Line {
3
+ points: Point[];
4
+ }
5
+ declare class Line {
6
+ /**
7
+ * Constructs a line from an array of points
8
+ * @param points an array of points
9
+ */
10
+ constructor(points: Point[]);
11
+ }
12
+ export default Line;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Minimal 3D point shape. Use for typing position objects (e.g. from custom layout).
3
+ * The Point class implements this interface.
4
+ */
5
+ export type PointLike = {
6
+ x: number;
7
+ y: number;
8
+ z: number;
9
+ };
10
+ interface Point extends PointLike {
11
+ }
12
+ declare class Point {
13
+ /**
14
+ * Constructs a point based on the x y z values
15
+ * @param x x value
16
+ * @param y y value
17
+ * @param z z value
18
+ */
19
+ constructor(x: number, y: number, z: number);
20
+ /**
21
+ * Displaces a point - note this method moves the existing point
22
+ * @param Point - Displacement vector (used as a point)
23
+ */
24
+ translate(Point: Point): void;
25
+ }
26
+ export default Point;
@@ -0,0 +1,45 @@
1
+ import { default as Point } from './Point';
2
+ /**
3
+ * calculate the average of an array of numberss
4
+ * @param arr an array of number whose average has to be calculated
5
+ * @returns the average
6
+ */
7
+ declare function calculateAverage(arr: number[]): number;
8
+ /**
9
+ * Calculate the distance betweeen two points
10
+ * @param p1 the first point
11
+ * @param p2 the second point
12
+ * @returns the distance between the points
13
+ */
14
+ declare function calculateDistance(p1: Point, p2: Point): number;
15
+ /**
16
+ * Calculate the squared distance between two points
17
+ * @param p1 the first point
18
+ * @param p2 the second point
19
+ * @returns the squared distance between the two points
20
+ */
21
+ declare function calculateSquaredDistance(p1: Point, p2: Point): number;
22
+ /**
23
+ * get a random subset of something from a array of things must provide the number of things we want from that array
24
+ * @param arr the array from which the subset has to be made
25
+ * @param n number of items to select
26
+ * @returns a new array made up of a random sample from the original array
27
+ */
28
+ declare function getRandomSubset(arr: any[], n: number): any[];
29
+ /**
30
+ * This is a super useful method to get a random number of edges or something that you would like to draw
31
+ * this is primarily done because there are way too many edges sometimes and and the number of edges is really
32
+ * What slows the whole rendering process down
33
+ * @param map - the map that youd like to reduce
34
+ * @param n - the fraction of items that youd like to return from this map
35
+ * @returns A reduced map with a fractio of those many entries
36
+ */
37
+ declare function getRandomSubset_map(map: Map<number, any>, n: number): Map<any, any>;
38
+ declare const _default: {
39
+ calculateAverage: typeof calculateAverage;
40
+ calculateDistance: typeof calculateDistance;
41
+ calculateSquaredDistance: typeof calculateSquaredDistance;
42
+ getRandomSubset: typeof getRandomSubset;
43
+ getRandomSubset_map: typeof getRandomSubset_map;
44
+ };
45
+ export default _default;
@@ -0,0 +1,3 @@
1
+ export { default as Constructors } from './GraphConstructors';
2
+ export { default as Geometry } from './GeometryHelpers';
3
+ export { default as Utilities } from './Utilities';
@@ -0,0 +1,8 @@
1
+ import { default as Graph } from '../Core/Graph';
2
+ import { ClusterResult, ClusterByDistanceOptions } from './types';
3
+ /**
4
+ * Cluster strategy that groups nodes by Euclidean distance using a KD-tree.
5
+ */
6
+ export declare function createKDDistanceStrategy(): {
7
+ cluster: (graph: Graph, options: ClusterByDistanceOptions) => ClusterResult;
8
+ };
@@ -0,0 +1,10 @@
1
+ import { default as Point } from '../HelperClasses/Point';
2
+ export interface PointWithId {
3
+ point: Point;
4
+ nodeId: number;
5
+ }
6
+ /**
7
+ * Find all point IDs within `radius` of each point in `items`.
8
+ * Returns Map<nodeId, nodeIds[] within radius (including self)>.
9
+ */
10
+ export declare function pointsWithinRadius(items: PointWithId[], radius: number): Map<number, number[]>;
@@ -0,0 +1,7 @@
1
+ import { default as Graph } from '../Core/Graph';
2
+ import { ClusterResult } from './types';
3
+ /**
4
+ * Build a new graph where each cluster is one node (at its centroid) and edges
5
+ * between clusters are merged (one edge per cluster pair; optional weight/count in data).
6
+ */
7
+ export declare function buildSimplifiedGraph(originalGraph: Graph, clusterResult: ClusterResult): Promise<Graph>;
@@ -0,0 +1,29 @@
1
+ import { default as Graph } from '../Core/Graph';
2
+ import { ClusterResult, ClusterStrategy, ClusterByDistanceOptions } from './types';
3
+ import { createKDDistanceStrategy } from './KDDistanceStrategy';
4
+ import { buildSimplifiedGraph } from './buildSimplifiedGraph';
5
+ /**
6
+ * Cluster the graph by distance (KD-tree based) and return a simplified graph.
7
+ * Nodes within `distanceThreshold` are merged; super-nodes are placed at cluster centroids.
8
+ *
9
+ * @param graph - The graph to cluster
10
+ * @param options - { distanceThreshold: number }
11
+ * @returns A new graph with one node per cluster and aggregated edges between clusters
12
+ */
13
+ declare function clusterByDistance(graph: Graph, options: ClusterByDistanceOptions): Promise<Graph>;
14
+ /**
15
+ * Cluster the graph using a custom strategy and return a simplified graph.
16
+ *
17
+ * @param graph - The graph to cluster
18
+ * @param strategy - A ClusterStrategy implementation
19
+ * @param options - Strategy-specific options
20
+ * @returns A new graph with one node per cluster and aggregated edges
21
+ */
22
+ declare function clusterByStrategy(graph: Graph, strategy: ClusterStrategy, options: Record<string, unknown>): Promise<Graph>;
23
+ export type { ClusterResult, ClusterStrategy, ClusterByDistanceOptions };
24
+ export { createKDDistanceStrategy, buildSimplifiedGraph };
25
+ declare const _default: {
26
+ clusterByDistance: typeof clusterByDistance;
27
+ clusterByStrategy: typeof clusterByStrategy;
28
+ };
29
+ export default _default;
@@ -0,0 +1,33 @@
1
+ import { default as Graph } from '../Core/Graph';
2
+ import { default as Point } from '../HelperClasses/Point';
3
+ /**
4
+ * Options for distance-based clustering.
5
+ */
6
+ export interface ClusterByDistanceOptions {
7
+ /** Maximum distance between two nodes for them to be in the same cluster. */
8
+ distanceThreshold: number;
9
+ }
10
+ /**
11
+ * Result of a clustering step: maps each node ID to its cluster ID.
12
+ */
13
+ export interface ClusterResult {
14
+ /** Map from original node ID to cluster ID (integer). */
15
+ nodeToCluster: Map<number, number>;
16
+ /** Map from cluster ID to centroid position (e.g. for super-node placement). */
17
+ clusterCentroids: Map<number, Point>;
18
+ /** List of unique cluster IDs. */
19
+ clusterIds: number[];
20
+ }
21
+ /**
22
+ * Strategy interface for hierarchical node combining.
23
+ * Implementations (e.g. KD-tree distance-based, or future class-based) produce a clustering.
24
+ */
25
+ export interface ClusterStrategy {
26
+ /**
27
+ * Compute clustering of graph nodes.
28
+ * @param graph - The graph to cluster
29
+ * @param options - Strategy-specific options
30
+ * @returns Assignment of each node to a cluster and cluster centroids
31
+ */
32
+ cluster(graph: Graph, options: Record<string, unknown>): ClusterResult;
33
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Helpers for matrix/vector math in the browser. Work with Float32Arrays
3
+ * returned by get_adjacency_matrix() and simulation positions.
4
+ */
5
+ /**
6
+ * Matrix-vector multiply: out = A * x (row-major n×n matrix A).
7
+ */
8
+ export declare function matrixVectorMultiply(A: Float32Array, n: number, x: Float32Array, out: Float32Array): void;
9
+ /**
10
+ * Normalize vector x in-place by its 2-norm. If norm is 0, leaves x unchanged.
11
+ */
12
+ export declare function normalizeVector(x: Float32Array): void;
@@ -0,0 +1,13 @@
1
+ import { default as Graph } from '../Core/Graph';
2
+ /**
3
+ * The G ( n , p ) G(n,p) model, a graph is constructed by connecting labeled nodes randomly. Each edge is included in the graph with probability p p, independently from every other edge.
4
+ * https://en.wikipedia.org/wiki/Erd%C5%91s%E2%80%93R%C3%A9nyi_model
5
+ * @param n Number of nodes
6
+ * @param p Probability of two edges to eb connected
7
+ * @returns A Erdos Reyni graph
8
+ */
9
+ declare function GenerateErdosReyni_n_p(n: number, p: number): Promise<Graph>;
10
+ declare const _default: {
11
+ GenerateErdosReyni_n_p: typeof GenerateErdosReyni_n_p;
12
+ };
13
+ export default _default;
@@ -0,0 +1 @@
1
+ export { default as Models } from './ErdosRenyiModel';
@@ -0,0 +1,49 @@
1
+ import { default as Graph } from '../Core/Graph';
2
+ /**
3
+ * Parse (sgd)²-style edge list text (one "i j" per line; lines starting with # or empty are skipped).
4
+ * Node IDs can be 0-based or 1-based. Returns a graph with nodes at origin (layout will set positions).
5
+ * Format used by the s_gd2 reference implementation from Imperial College London.
6
+ * @see https://github.com/jxz12/s_gd2
7
+ */
8
+ declare function LoadGraphFromEdgeListText(edgeListText: string): Promise<Graph>;
9
+ /**
10
+ *
11
+ * @returns the raw ZKC dataset
12
+ */
13
+ declare function LoadZKC(): Promise<Graph>;
14
+ /**
15
+ *
16
+ * @returns the ZKC dataset with the positions simulated beforehand
17
+ */
18
+ declare function LoadZKCSimulated(): Promise<Graph>;
19
+ /**
20
+ * Result of loading a mesh from OBJ: graph (vertices = nodes, face edges = graph edges) and original 3D positions.
21
+ * positions[i*3], positions[i*3+1], positions[i*3+2] are x,y,z for node id i (0-based).
22
+ */
23
+ export interface LoadGraphFromObjResult {
24
+ graph: Graph;
25
+ /** Flat array of length n*3: x,y,z for each node in order of node id 0..n-1 */
26
+ positions: Float32Array;
27
+ }
28
+ /**
29
+ * Parse OBJ mesh: "v x y z" lines and "f i j k" (or "f i j k l" for quads) lines.
30
+ * Builds a graph whose nodes are mesh vertices (ids 0..n-1) and edges are unique mesh edges from faces.
31
+ * Returns the graph and original vertex positions so they can be used as initial layout (e.g. for 3D stress).
32
+ * OBJ vertex indices are 1-based; we use 0-based node ids.
33
+ * @see e.g. Stanford Bunny https://graphics.stanford.edu/~mdfisher/Data/Meshes/bunny.obj
34
+ */
35
+ declare function LoadGraphFromObjText(objText: string): Promise<LoadGraphFromObjResult>;
36
+ /**
37
+ * Load the DWT 1005 graph from the paper (1005 nodes, adjacency-list format).
38
+ * Same structural graph used in the 2D stress layout reference.
39
+ * @see dwt_1005.ts
40
+ */
41
+ declare function LoadDwt1005(): Promise<Graph>;
42
+ declare const _default: {
43
+ LoadZKC: typeof LoadZKC;
44
+ LoadZKCSimulated: typeof LoadZKCSimulated;
45
+ LoadGraphFromEdgeListText: typeof LoadGraphFromEdgeListText;
46
+ LoadGraphFromObjText: typeof LoadGraphFromObjText;
47
+ LoadDwt1005: typeof LoadDwt1005;
48
+ };
49
+ export default _default;
@@ -0,0 +1,5 @@
1
+ declare const zkc: {
2
+ nodes: number[];
3
+ edges: number[][];
4
+ };
5
+ export { zkc };
@@ -0,0 +1,10 @@
1
+ declare const zkc_simulated: {
2
+ nodes: {
3
+ id: number;
4
+ px: number;
5
+ py: number;
6
+ member: number;
7
+ }[];
8
+ edges: number[][];
9
+ };
10
+ export { zkc_simulated };