@naniteninja/trait-visual 1.0.1

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 ADDED
@@ -0,0 +1,216 @@
1
+ # @naniteninja/trait-visual
2
+
3
+ An Angular library for visualizing trait-based relationships in 3D space using Three.js. This library provides a pure visualization component that can be integrated into any Angular application to display personality traits, preferences, and attributes as an interactive 3D visualization.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @naniteninja/trait-visual
9
+ ```
10
+
11
+ ## Requirements
12
+
13
+ - Angular 19.2.0 or higher
14
+ - Three.js (included as dependency)
15
+ - ml-pca (included as dependency)
16
+
17
+ ## Quick Start
18
+
19
+ ### 1. Import the Component
20
+
21
+ ```typescript
22
+ import { TraitVisualComponent } from '@naniteninja/trait-visual';
23
+
24
+ @Component({
25
+ selector: 'app-my-component',
26
+ standalone: true,
27
+ imports: [TraitVisualComponent],
28
+ template: `
29
+ <tv-trait-visual
30
+ [nodeData]="myNodeData"
31
+ [attributeWeights]="myAttributeWeights"
32
+ [preferenceWeights]="myPreferenceWeights"
33
+ ></tv-trait-visual>
34
+ `
35
+ })
36
+ export class MyComponent {
37
+ // Your component logic
38
+ }
39
+ ```
40
+
41
+ ### 2. Prepare Your Data
42
+
43
+ ```typescript
44
+ import { INodeData } from '@naniteninja/trait-visual';
45
+
46
+ const myNodeData: INodeData[] = [
47
+ {
48
+ id: 1,
49
+ name: 'Central Node',
50
+ initialPosition: [0, 0, 0],
51
+ isSun: true,
52
+ color: '#C300FF',
53
+ attributes: { attr1: 50, attr2: 75, attr3: 25 },
54
+ preferences: { attr1: 100, attr2: 80, attr3: 60 }
55
+ },
56
+ {
57
+ id: 2,
58
+ name: 'Node 1',
59
+ initialPosition: [5, 0, 0],
60
+ isSun: false,
61
+ color: '#FF3366',
62
+ attributes: { attr1: 0, attr2: 50, attr3: 100 },
63
+ preferences: { attr1: 0, attr2: 0, attr3: 0 }
64
+ }
65
+ // ... more nodes
66
+ ];
67
+
68
+ const myAttributeWeights = [1.0, 1.2, 0.8];
69
+ const myPreferenceWeights = [1.0, 1.0, 1.0];
70
+ ```
71
+
72
+ ## API Reference
73
+
74
+ ### TraitVisualComponent
75
+
76
+ The main visualization component.
77
+
78
+ #### Inputs
79
+
80
+ - `nodeData: INodeData[]` (required) - Array of node data to visualize
81
+ - `attributeWeights?: number[]` - Weights for attribute calculations (optional)
82
+ - `preferenceWeights?: number[]` - Weights for preference calculations (optional)
83
+ - `attributeCount?: number` - Number of attributes per node (optional)
84
+ - `preferenceCount?: number` - Number of preferences per node (optional)
85
+
86
+ #### Usage
87
+
88
+ ```html
89
+ <tv-trait-visual
90
+ [nodeData]="nodeData"
91
+ [attributeWeights]="attributeWeights"
92
+ [preferenceWeights]="preferenceWeights"
93
+ ></tv-trait-visual>
94
+ ```
95
+
96
+ ### Types
97
+
98
+ #### INodeData
99
+
100
+ ```typescript
101
+ interface INodeData {
102
+ id: number;
103
+ name: string;
104
+ initialPosition: [number, number, number];
105
+ isSun: boolean;
106
+ color: string;
107
+ attributes: IHumanAttributes; // Record<string, number>
108
+ preferences: IHumanAttributes; // Record<string, number>
109
+ }
110
+ ```
111
+
112
+ #### IHumanAttributes
113
+
114
+ ```typescript
115
+ interface IHumanAttributes {
116
+ [key: string]: number;
117
+ }
118
+ ```
119
+
120
+ ### Configuration Utilities
121
+
122
+ The library exports utility functions for working with node data:
123
+
124
+ ```typescript
125
+ import {
126
+ dynamicCounts,
127
+ updateCounts,
128
+ attributeWeights,
129
+ nodeData
130
+ } from '@naniteninja/trait-visual';
131
+
132
+ // Get current attribute/preference counts
133
+ console.log(dynamicCounts.attributes); // 5
134
+ console.log(dynamicCounts.preferences); // 5
135
+
136
+ // Update counts
137
+ updateCounts(7, 7);
138
+
139
+ // Get computed attribute weights from PCA
140
+ console.log(attributeWeights);
141
+
142
+ // Get default node data (for reference)
143
+ console.log(nodeData);
144
+ ```
145
+
146
+ ## Features
147
+
148
+ - **3D Visualization**: Interactive Three.js-based 3D visualization
149
+ - **PCA-based Positioning**: Nodes are positioned in 3D space using Principal Component Analysis
150
+ - **Dynamic Updates**: Component reacts to input changes via Angular's change detection
151
+ - **Customizable**: Full control over node data, weights, and attributes
152
+ - **Standalone Component**: No additional module setup required
153
+
154
+ ## Example: Complete Integration
155
+
156
+ ```typescript
157
+ import { Component, OnInit } from '@angular/core';
158
+ import { TraitVisualComponent, INodeData } from '@naniteninja/trait-visual';
159
+
160
+ @Component({
161
+ selector: 'app-personality-visualizer',
162
+ standalone: true,
163
+ imports: [TraitVisualComponent],
164
+ template: `
165
+ <div style="width: 100vw; height: 100vh;">
166
+ <tv-trait-visual
167
+ [nodeData]="nodes"
168
+ [attributeWeights]="attrWeights"
169
+ [preferenceWeights]="prefWeights"
170
+ ></tv-trait-visual>
171
+ </div>
172
+ `
173
+ })
174
+ export class PersonalityVisualizerComponent implements OnInit {
175
+ nodes: INodeData[] = [];
176
+ attrWeights: number[] = [1, 1, 1, 1, 1];
177
+ prefWeights: number[] = [1, 1, 1, 1, 1];
178
+
179
+ ngOnInit() {
180
+ // Load or generate your node data
181
+ this.nodes = this.generateNodeData();
182
+ }
183
+
184
+ private generateNodeData(): INodeData[] {
185
+ // Your data generation logic
186
+ return [];
187
+ }
188
+ }
189
+ ```
190
+
191
+ ## Styling
192
+
193
+ The component uses minimal styling. You can style the wrapper element:
194
+
195
+ ```css
196
+ tv-trait-visual {
197
+ display: block;
198
+ width: 100%;
199
+ height: 100%;
200
+ }
201
+ ```
202
+
203
+ The canvas will fill its container. Ensure the container has defined dimensions.
204
+
205
+ ## Browser Support
206
+
207
+ - Modern browsers with WebGL support
208
+ - Chrome, Firefox, Safari, Edge (latest versions)
209
+
210
+ ## License
211
+
212
+ MIT
213
+
214
+ ## Author
215
+
216
+ naniteninja