@tomaszjarosz/react-visualizers 0.2.13 → 0.3.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 CHANGED
@@ -1,90 +1,183 @@
1
1
  # @tomaszjarosz/react-visualizers
2
2
 
3
- Interactive algorithm and data structure visualizers for React.
3
+ Interactive algorithm and data structure visualizers for React. Perfect for learning, teaching, and interview preparation.
4
4
 
5
- [![Storybook](https://img.shields.io/badge/Storybook-Live%20Demo-ff4785?logo=storybook&logoColor=white)](https://6934a2d9e17d1e509a92c935-rdicbxowdr.chromatic.com/)
6
5
  [![npm version](https://img.shields.io/npm/v/@tomaszjarosz/react-visualizers)](https://www.npmjs.com/package/@tomaszjarosz/react-visualizers)
6
+ [![Storybook](https://img.shields.io/badge/Storybook-Live%20Demo-ff4785?logo=storybook&logoColor=white)](https://6934a2d9e17d1e509a92c935-oajoxaxuir.chromatic.com/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+
9
+ ## Features
10
+
11
+ - **38 interactive visualizers** covering algorithms, data structures, and distributed systems
12
+ - **Interview Mode** with built-in questions, scoring, hints, and explanations
13
+ - **Step-by-step animations** with playback controls (play, pause, step forward/back)
14
+ - **Code highlighting** showing the current line being executed
15
+ - **Keyboard shortcuts** for efficient navigation
16
+ - **URL state persistence** for sharing specific states
17
+ - **Fully typed** with TypeScript
18
+ - **Zero runtime dependencies** (only `lucide-react` for icons)
7
19
 
8
20
  ## Live Demo
9
21
 
10
- **[View all visualizers in Storybook](https://6934a2d9e17d1e509a92c935-rdicbxowdr.chromatic.com/)**
22
+ **[View all visualizers in Storybook](https://6934a2d9e17d1e509a92c935-oajoxaxuir.chromatic.com/)**
11
23
 
12
24
  ## Installation
13
25
 
14
26
  ```bash
15
27
  npm install @tomaszjarosz/react-visualizers
28
+ # or
29
+ pnpm add @tomaszjarosz/react-visualizers
30
+ # or
31
+ yarn add @tomaszjarosz/react-visualizers
32
+ ```
33
+
34
+ **Important:** Import the CSS file in your application entry point:
35
+
36
+ ```tsx
37
+ import '@tomaszjarosz/react-visualizers/styles.css';
16
38
  ```
17
39
 
18
40
  ## Requirements
19
41
 
20
42
  - React 17+
21
- - Tailwind CSS 4+
43
+ - The library includes compiled Tailwind CSS, no additional setup needed
44
+
45
+ ## Quick Start
46
+
47
+ ```tsx
48
+ import { HashMapVisualizer } from '@tomaszjarosz/react-visualizers';
49
+ import '@tomaszjarosz/react-visualizers/styles.css';
50
+
51
+ function App() {
52
+ return <HashMapVisualizer showControls showCode />;
53
+ }
54
+ ```
22
55
 
23
56
  ## Available Visualizers
24
57
 
25
- ### Algorithms
58
+ ### Algorithms (6)
59
+
26
60
  | Visualizer | Description |
27
61
  |------------|-------------|
28
62
  | `BinarySearchVisualizer` | Binary search with O(log n) visualization |
29
- | `SortingVisualizer` | Step-by-step sorting algorithm |
30
- | `SortingComparisonVisualizer` | Side-by-side algorithm comparison |
31
- | `GraphVisualizer` | DFS/BFS graph traversal |
32
- | `DijkstraVisualizer` | Shortest path algorithm |
33
- | `DPVisualizer` | Dynamic programming table |
63
+ | `SortingVisualizer` | Bubble, Selection, Insertion, Quick, Merge sort |
64
+ | `SortingComparisonVisualizer` | Side-by-side algorithm race |
65
+ | `GraphVisualizer` | DFS and BFS traversal |
66
+ | `DijkstraVisualizer` | Shortest path with distance relaxation |
67
+ | `DPVisualizer` | Dynamic programming table (Fibonacci) |
68
+
69
+ ### Data Structures (10)
34
70
 
35
- ### Data Structures
36
71
  | Visualizer | Description |
37
72
  |------------|-------------|
38
- | `ArrayListVisualizer` | Dynamic array with resizing |
39
- | `LinkedListVisualizer` | Node-based list operations |
40
- | `HashMapVisualizer` | Hash table with buckets |
41
- | `HashTableVisualizer` | Hash function internals |
42
- | `ArrayDequeVisualizer` | Circular buffer deque |
43
- | `PriorityQueueVisualizer` | Min-heap operations |
44
- | `TreeSetVisualizer` | Red-Black tree (BST) |
45
- | `LinkedHashMapVisualizer` | Hash + insertion order |
46
- | `EnumSetVisualizer` | Bit vector set |
47
-
48
- ### Concurrency
73
+ | `ArrayListVisualizer` | Dynamic array with amortized resizing |
74
+ | `LinkedListVisualizer` | Singly linked list operations |
75
+ | `HashMapVisualizer` | Hash table with separate chaining |
76
+ | `HashTableVisualizer` | Hash function internals and collisions |
77
+ | `ArrayDequeVisualizer` | Circular buffer double-ended queue |
78
+ | `PriorityQueueVisualizer` | Binary min-heap operations |
79
+ | `TreeSetVisualizer` | Red-Black tree (balanced BST) |
80
+ | `LinkedHashMapVisualizer` | HashMap + insertion order linked list |
81
+ | `EnumSetVisualizer` | Bit vector implementation |
82
+ | `ListComparisonVisualizer` | ArrayList vs LinkedList performance |
83
+
84
+ ### Concurrency (4)
85
+
49
86
  | Visualizer | Description |
50
87
  |------------|-------------|
51
- | `BlockingQueueVisualizer` | Producer-consumer pattern |
52
- | `ConcurrentHashMapVisualizer` | Segment-based locking |
53
- | `CopyOnWriteVisualizer` | Copy-on-write pattern |
88
+ | `BlockingQueueVisualizer` | Producer-consumer with blocking |
89
+ | `ConcurrentHashMapVisualizer` | Segment-based concurrent access |
90
+ | `CopyOnWriteVisualizer` | Copy-on-write pattern for reads |
54
91
  | `ImmutableCollectionsVisualizer` | Java 9+ immutable collections |
55
92
 
56
- ### Other
93
+ ### Advanced Data Structures (4)
94
+
95
+ | Visualizer | Description |
96
+ |------------|-------------|
97
+ | `BloomFilterVisualizer` | Probabilistic set membership |
98
+ | `BTreeVisualizer` | B-Tree with node splitting |
99
+ | `TrieVisualizer` | Prefix tree for autocomplete, spell checking |
100
+ | `UnionFindVisualizer` | Disjoint set union with path compression |
101
+
102
+ ### Distributed Systems (2)
103
+
57
104
  | Visualizer | Description |
58
105
  |------------|-------------|
59
- | `GCVisualizer` | JVM garbage collection |
60
- | `SQLJoinVisualizer` | SQL JOIN operations |
106
+ | `ConsistentHashingVisualizer` | Hash ring with virtual nodes |
107
+ | `RaftVisualizer` | Raft consensus algorithm |
61
108
 
62
- ## Usage
109
+ ### Other (2)
110
+
111
+ | Visualizer | Description |
112
+ |------------|-------------|
113
+ | `GCVisualizer` | JVM generational garbage collection |
114
+ | `SQLJoinVisualizer` | SQL JOIN operations (INNER, LEFT, RIGHT, FULL) |
115
+
116
+ ### Interview Mode (10)
117
+
118
+ Interview visualizers include built-in questions with multiple choice answers, hints, and detailed explanations. Perfect for interview preparation.
119
+
120
+ | Visualizer | Topics |
121
+ |------------|--------|
122
+ | `HashMapInterviewVisualizer` | Hashing, collisions, load factor, rehashing |
123
+ | `TreeSetInterviewVisualizer` | BST properties, Red-Black balancing, rotations |
124
+ | `SortingInterviewVisualizer` | Time complexity, stability, space complexity |
125
+ | `GraphInterviewVisualizer` | DFS vs BFS, cycle detection, topological sort |
126
+ | `DijkstraInterviewVisualizer` | Shortest path, negative weights, relaxation |
127
+ | `DPInterviewVisualizer` | Overlapping subproblems, memoization |
128
+ | `BloomFilterInterviewVisualizer` | False positives, hash functions, bit arrays |
129
+ | `BTreeInterviewVisualizer` | Node splitting, disk-based storage, order |
130
+ | `ConsistentHashingInterviewVisualizer` | Virtual nodes, rebalancing, hot spots |
131
+ | `RaftInterviewVisualizer` | Leader election, log replication, safety |
132
+
133
+ ## Interview Mode Usage
63
134
 
64
135
  ```tsx
65
- import { BinarySearchVisualizer, HashMapVisualizer } from '@tomaszjarosz/react-visualizers';
136
+ import { HashMapInterviewVisualizer } from '@tomaszjarosz/react-visualizers';
66
137
 
67
- function App() {
138
+ function InterviewPrep() {
68
139
  return (
69
- <div>
70
- <BinarySearchVisualizer showControls={true} showCode={true} />
71
- <HashMapVisualizer showControls={true} showCode={true} />
72
- </div>
140
+ <HashMapInterviewVisualizer
141
+ showControls
142
+ showCode
143
+ onComplete={(session) => {
144
+ console.log(`Score: ${session.results.filter(r => r.isCorrect).length}/${session.results.length}`);
145
+ }}
146
+ />
73
147
  );
74
148
  }
75
149
  ```
76
150
 
77
- ### Props
151
+ ## Props
78
152
 
79
- All visualizers accept these props:
153
+ All visualizers accept these common props:
80
154
 
81
155
  | Prop | Type | Default | Description |
82
156
  |------|------|---------|-------------|
83
157
  | `showControls` | `boolean` | `true` | Show playback controls |
84
- | `showCode` | `boolean` | `true` | Show code panel |
158
+ | `showCode` | `boolean` | `true` | Show code panel with highlighting |
85
159
  | `className` | `string` | `''` | Additional CSS classes |
86
160
 
87
- ## Shared Components
161
+ Interview visualizers also accept:
162
+
163
+ | Prop | Type | Default | Description |
164
+ |------|------|---------|-------------|
165
+ | `shuffleQuestions` | `boolean` | `false` | Randomize question order |
166
+ | `onComplete` | `(session) => void` | - | Callback when all questions answered |
167
+
168
+ ## Keyboard Shortcuts
169
+
170
+ | Key | Action |
171
+ |-----|--------|
172
+ | `Space` | Play/Pause |
173
+ | `→` | Next step |
174
+ | `←` | Previous step |
175
+ | `R` | Reset |
176
+ | `?` | Show help |
177
+
178
+ ## Building Custom Visualizers
179
+
180
+ The library exports shared components and hooks for building your own visualizers:
88
181
 
89
182
  ```tsx
90
183
  import {
@@ -93,23 +186,173 @@ import {
93
186
  Legend,
94
187
  StatusPanel,
95
188
  VisualizationArea,
96
- HelpPanel
189
+ useVisualizerPlayback,
190
+ useInterviewMode,
191
+ } from '@tomaszjarosz/react-visualizers';
192
+
193
+ function CustomVisualizer() {
194
+ const { currentStep, isPlaying, play, pause, next, prev, reset } = useVisualizerPlayback({
195
+ totalSteps: 10,
196
+ intervalMs: 500,
197
+ });
198
+
199
+ return (
200
+ <div>
201
+ <VisualizationArea>
202
+ {/* Your visualization */}
203
+ </VisualizationArea>
204
+ <ControlPanel
205
+ isPlaying={isPlaying}
206
+ onPlay={play}
207
+ onPause={pause}
208
+ onNext={next}
209
+ onPrev={prev}
210
+ onReset={reset}
211
+ currentStep={currentStep}
212
+ totalSteps={10}
213
+ />
214
+ </div>
215
+ );
216
+ }
217
+ ```
218
+
219
+ ### Available Hooks
220
+
221
+ | Hook | Description |
222
+ |------|-------------|
223
+ | `useVisualizerPlayback` | Step-through animation control with play/pause |
224
+ | `useUrlState` | Persist visualizer state in URL for sharing |
225
+ | `useInterviewMode` | Interview session with questions and scoring |
226
+
227
+ ### Available Components
228
+
229
+ | Component | Description |
230
+ |-----------|-------------|
231
+ | `ControlPanel` | Play, pause, step, reset buttons |
232
+ | `CodePanel` | Syntax-highlighted code with line highlighting |
233
+ | `Legend` | Color legend for visualization |
234
+ | `StatusPanel` | Current step description |
235
+ | `VisualizationArea` | Container with consistent styling |
236
+ | `HelpPanel` | Keyboard shortcuts overlay |
237
+ | `ArrayInput` | Custom array input for sorting visualizers |
238
+ | `StepHistory` | List of executed steps |
239
+ | `InterviewModePanel` | Question display with options and scoring |
240
+
241
+ ## TypeScript
242
+
243
+ The library is fully typed. All types are exported:
244
+
245
+ ```tsx
246
+ import type {
247
+ ControlPanelProps,
248
+ LegendItem,
249
+ InterviewQuestion,
250
+ InterviewSession,
251
+ UseVisualizerPlaybackOptions,
252
+ UseInterviewModeReturn,
97
253
  } from '@tomaszjarosz/react-visualizers';
98
254
  ```
99
255
 
100
256
  ## Development
101
257
 
258
+ This project uses **bun** as the package manager.
259
+
102
260
  ```bash
103
- # Run Storybook locally
104
- pnpm run storybook
261
+ # Clone the repository
262
+ git clone https://github.com/tomaszjarosz/tomaszjarosz-ui.git
263
+ cd tomaszjarosz-ui/packages/react-visualizers
264
+
265
+ # Install dependencies
266
+ bun install
267
+
268
+ # Run Storybook locally (port 6006)
269
+ bun run storybook
105
270
 
106
271
  # Build library
107
- pnpm run build
272
+ bun run build
108
273
 
109
274
  # Type check
110
- pnpm run typecheck
275
+ bun run typecheck
276
+
277
+ # Run unit tests
278
+ bun run test
279
+
280
+ # Run tests in watch mode
281
+ bun run test:watch
282
+ ```
283
+
284
+ ## Storybook
285
+
286
+ All visualizers have interactive stories in [Storybook](https://storybook.js.org/):
287
+
288
+ - **Local:** `bun run storybook` → http://localhost:6006
289
+ - **Live Demo:** https://6934a2d9e17d1e509a92c935-oajoxaxuir.chromatic.com/
290
+
291
+ Stories are located in `src/visualizers/stories/` directory.
292
+
293
+ ## Chromatic (Visual Testing)
294
+
295
+ This project uses [Chromatic](https://www.chromatic.com/) for visual regression testing and Storybook hosting.
296
+
297
+ - **Automatic deployment** on every push to `main` branch
298
+ - **Visual diff detection** for UI changes
299
+ - **Storybook hosting** at the live demo URL
300
+
301
+ Chromatic runs via GitHub Actions (`.github/workflows/chromatic.yml`).
302
+
303
+ ## Project Structure
304
+
305
+ ```
306
+ packages/react-visualizers/
307
+ ├── src/
308
+ │ ├── index.ts # Main exports
309
+ │ ├── styles.css # Tailwind entry point
310
+ │ ├── shared/ # Shared components & hooks
311
+ │ │ ├── ControlPanel.tsx
312
+ │ │ ├── CodePanel.tsx
313
+ │ │ ├── useVisualizerPlayback.ts
314
+ │ │ ├── useInterviewMode.ts
315
+ │ │ └── *.test.ts # Unit tests
316
+ │ └── visualizers/ # All visualizers
317
+ │ ├── SortingVisualizer.tsx
318
+ │ ├── HashMapVisualizer.tsx
319
+ │ └── stories/ # Storybook stories
320
+ ├── dist/ # Build output
321
+ ├── .storybook/ # Storybook config
322
+ ├── package.json
323
+ └── vite.config.ts
111
324
  ```
112
325
 
326
+ ## Publishing
327
+
328
+ ```bash
329
+ # Bump version
330
+ npm version patch # or minor/major
331
+
332
+ # Build
333
+ bun run build
334
+
335
+ # Publish to npm
336
+ npm publish --access public
337
+
338
+ # Push version tag
339
+ git push && git push --tags
340
+ ```
341
+
342
+ ## Contributing
343
+
344
+ Contributions are welcome! Please:
345
+
346
+ 1. Fork the repository
347
+ 2. Create a feature branch
348
+ 3. Add tests for new functionality
349
+ 4. Ensure all tests pass (`bun run test`)
350
+ 5. Submit a pull request
351
+
113
352
  ## License
114
353
 
115
- MIT
354
+ MIT License - see [LICENSE](LICENSE) for details.
355
+
356
+ ## Author
357
+
358
+ **Tomasz Jarosz** - [tomaszjarosz.dev](https://tomaszjarosz.dev)