@tomaszjarosz/react-visualizers 0.2.0 → 0.2.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.
- package/dist/index.cjs +115 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +115 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3240,7 +3240,58 @@ const DijkstraVisualizerComponent = ({
|
|
|
3240
3240
|
] })
|
|
3241
3241
|
] }) }) }),
|
|
3242
3242
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4 overflow-x-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col lg:flex-row gap-4 min-w-0", children: [
|
|
3243
|
-
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight:
|
|
3243
|
+
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 500, className: "flex-1 min-w-0", children: [
|
|
3244
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 bg-gradient-to-r from-orange-50 to-amber-50 rounded-xl border-2 border-orange-200", children: [
|
|
3245
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-semibold text-orange-800 mb-3", children: "Distance Array (shortest paths from node 0)" }),
|
|
3246
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2 justify-center", children: distances.map((dist, idx) => {
|
|
3247
|
+
const isSource = idx === 0;
|
|
3248
|
+
const isCurrent = idx === current;
|
|
3249
|
+
const isVisited = visited.includes(idx);
|
|
3250
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3251
|
+
"div",
|
|
3252
|
+
{
|
|
3253
|
+
className: `flex flex-col items-center p-2 rounded-lg border-2 min-w-[60px] transition-colors ${isCurrent ? "bg-yellow-100 border-yellow-400 ring-2 ring-yellow-300" : isVisited ? "bg-green-100 border-green-400" : "bg-white border-gray-300"}`,
|
|
3254
|
+
children: [
|
|
3255
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: `text-xs font-medium ${isCurrent ? "text-yellow-800" : isVisited ? "text-green-800" : "text-gray-500"}`, children: [
|
|
3256
|
+
"Node ",
|
|
3257
|
+
idx,
|
|
3258
|
+
isSource && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-1", children: "(src)" })
|
|
3259
|
+
] }),
|
|
3260
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: `text-xl font-bold font-mono ${isCurrent ? "text-yellow-900" : isVisited ? "text-green-900" : "text-gray-700"}`, children: dist === Infinity ? "∞" : dist }),
|
|
3261
|
+
isCurrent && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-yellow-700 font-bold", children: "← PROCESSING" }),
|
|
3262
|
+
isVisited && !isCurrent && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-green-600", children: "✓ Final" })
|
|
3263
|
+
]
|
|
3264
|
+
},
|
|
3265
|
+
idx
|
|
3266
|
+
);
|
|
3267
|
+
}) })
|
|
3268
|
+
] }),
|
|
3269
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-3 bg-blue-50 rounded-lg border border-blue-200", children: [
|
|
3270
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-semibold text-blue-800 mb-2", children: "Relaxation Formula" }),
|
|
3271
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-sm text-center", children: [
|
|
3272
|
+
"if dist[u] + weight(u,v) < dist[v] → ",
|
|
3273
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-green-600 font-bold", children: "update dist[v]" })
|
|
3274
|
+
] })
|
|
3275
|
+
] }),
|
|
3276
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-3 bg-orange-50 rounded-lg border border-orange-200", children: [
|
|
3277
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 mb-2", children: [
|
|
3278
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-semibold text-orange-800", children: "Priority Queue (min-heap)" }),
|
|
3279
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-orange-600", children: "(node:distance)" })
|
|
3280
|
+
] }),
|
|
3281
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: priorityQueue.length > 0 ? priorityQueue.sort((a, b) => a.dist - b.dist).map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3282
|
+
"span",
|
|
3283
|
+
{
|
|
3284
|
+
className: `px-3 py-1.5 rounded-lg font-mono text-sm font-medium ${index === 0 ? "bg-orange-200 text-orange-900 ring-2 ring-orange-400" : "bg-white text-orange-800 border border-orange-300"}`,
|
|
3285
|
+
children: [
|
|
3286
|
+
item.node,
|
|
3287
|
+
":",
|
|
3288
|
+
item.dist,
|
|
3289
|
+
index === 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-1 text-xs", children: "← MIN" })
|
|
3290
|
+
]
|
|
3291
|
+
},
|
|
3292
|
+
index
|
|
3293
|
+
)) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-gray-400 italic", children: "empty" }) })
|
|
3294
|
+
] }),
|
|
3244
3295
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-gray-50 rounded-lg", children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { viewBox: "0 0 420 300", className: "w-full h-64 md:h-72", children: [
|
|
3245
3296
|
graph.edges.map((edge, index) => {
|
|
3246
3297
|
const fromNode = graph.nodes[edge.from];
|
|
@@ -3310,7 +3361,7 @@ const DijkstraVisualizerComponent = ({
|
|
|
3310
3361
|
cx: node.x,
|
|
3311
3362
|
cy: node.y,
|
|
3312
3363
|
r: 22,
|
|
3313
|
-
className: `${getNodeColor(node.id)} stroke-2 transition-
|
|
3364
|
+
className: `${getNodeColor(node.id)} stroke-2 transition-colors duration-300`
|
|
3314
3365
|
}
|
|
3315
3366
|
),
|
|
3316
3367
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -3325,38 +3376,6 @@ const DijkstraVisualizerComponent = ({
|
|
|
3325
3376
|
)
|
|
3326
3377
|
] }, node.id))
|
|
3327
3378
|
] }) }),
|
|
3328
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-3 flex flex-wrap gap-3", children: [
|
|
3329
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [
|
|
3330
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-gray-600", children: "Dist:" }),
|
|
3331
|
-
distances.map((dist, idx) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3332
|
-
"span",
|
|
3333
|
-
{
|
|
3334
|
-
className: `px-2 py-0.5 text-xs font-mono rounded ${idx === current ? "bg-yellow-200 text-yellow-900" : visited.includes(idx) ? "bg-green-100 text-green-800" : "bg-gray-100 text-gray-600"}`,
|
|
3335
|
-
children: [
|
|
3336
|
-
idx,
|
|
3337
|
-
":",
|
|
3338
|
-
dist === Infinity ? "∞" : dist
|
|
3339
|
-
]
|
|
3340
|
-
},
|
|
3341
|
-
idx
|
|
3342
|
-
))
|
|
3343
|
-
] }),
|
|
3344
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [
|
|
3345
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-gray-600", children: "PQ:" }),
|
|
3346
|
-
priorityQueue.length > 0 ? priorityQueue.sort((a, b) => a.dist - b.dist).map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3347
|
-
"span",
|
|
3348
|
-
{
|
|
3349
|
-
className: "px-2 py-0.5 bg-orange-100 text-orange-800 text-xs rounded font-mono",
|
|
3350
|
-
children: [
|
|
3351
|
-
item.node,
|
|
3352
|
-
":",
|
|
3353
|
-
item.dist
|
|
3354
|
-
]
|
|
3355
|
-
},
|
|
3356
|
-
index
|
|
3357
|
-
)) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-gray-400", children: "empty" })
|
|
3358
|
-
] })
|
|
3359
|
-
] }),
|
|
3360
3379
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3361
3380
|
StatusPanel,
|
|
3362
3381
|
{
|
|
@@ -3512,7 +3531,7 @@ const DPVisualizerComponent = ({
|
|
|
3512
3531
|
showCode = true,
|
|
3513
3532
|
className = ""
|
|
3514
3533
|
}) => {
|
|
3515
|
-
var _a;
|
|
3534
|
+
var _a, _b, _c;
|
|
3516
3535
|
const [items] = React.useState(DEFAULT_ITEMS);
|
|
3517
3536
|
const [capacity] = React.useState(DEFAULT_CAPACITY);
|
|
3518
3537
|
const [speed, setSpeed] = React.useState(25);
|
|
@@ -3636,33 +3655,83 @@ const DPVisualizerComponent = ({
|
|
|
3636
3655
|
] })
|
|
3637
3656
|
] }) }) }),
|
|
3638
3657
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `flex gap-4 ${showCode ? "flex-col lg:flex-row" : ""}`, children: [
|
|
3639
|
-
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight:
|
|
3658
|
+
/* @__PURE__ */ jsxRuntime.jsxs(VisualizationArea, { minHeight: 450, className: "flex-1 min-w-0", children: [
|
|
3659
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-6 p-4 bg-gradient-to-r from-teal-50 to-cyan-50 rounded-xl border-2 border-teal-200", children: [
|
|
3660
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-semibold text-teal-800 mb-3", children: "DP Recurrence Formula" }),
|
|
3661
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-mono text-sm bg-white rounded-lg p-3 border border-teal-200", children: [
|
|
3662
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-gray-600 mb-2", children: [
|
|
3663
|
+
"dp[i][w] = max(",
|
|
3664
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-yellow-600 font-bold", children: " skip" }),
|
|
3665
|
+
",",
|
|
3666
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-green-600 font-bold", children: " take" }),
|
|
3667
|
+
")"
|
|
3668
|
+
] }),
|
|
3669
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4 text-xs mt-3", children: [
|
|
3670
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-yellow-50 p-2 rounded border border-yellow-200", children: [
|
|
3671
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-yellow-700 font-bold", children: "skip" }),
|
|
3672
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-600", children: " = dp[i-1][w]" }),
|
|
3673
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-500 mt-1", children: "Don't take item i" })
|
|
3674
|
+
] }),
|
|
3675
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-green-50 p-2 rounded border border-green-200", children: [
|
|
3676
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-green-700 font-bold", children: "take" }),
|
|
3677
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-600", children: " = dp[i-1][w-weight] + value" }),
|
|
3678
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-500 mt-1", children: "Take item i" })
|
|
3679
|
+
] })
|
|
3680
|
+
] })
|
|
3681
|
+
] }),
|
|
3682
|
+
currentI > 0 && currentW > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4 p-3 bg-white rounded-lg border-2 border-purple-300", children: [
|
|
3683
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-sm font-semibold text-purple-800 mb-2", children: [
|
|
3684
|
+
"Current: dp[",
|
|
3685
|
+
currentI,
|
|
3686
|
+
"][",
|
|
3687
|
+
currentW,
|
|
3688
|
+
"]"
|
|
3689
|
+
] }),
|
|
3690
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-4 text-sm", children: [
|
|
3691
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-gray-600", children: [
|
|
3692
|
+
"Item ",
|
|
3693
|
+
currentI,
|
|
3694
|
+
": ",
|
|
3695
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-mono", children: [
|
|
3696
|
+
"w=",
|
|
3697
|
+
(_b = items[currentI - 1]) == null ? void 0 : _b.weight,
|
|
3698
|
+
", v=",
|
|
3699
|
+
(_c = items[currentI - 1]) == null ? void 0 : _c.value
|
|
3700
|
+
] })
|
|
3701
|
+
] }),
|
|
3702
|
+
decision && /* @__PURE__ */ jsxRuntime.jsx("div", { className: `px-3 py-1 rounded-full font-bold ${decision === "take" ? "bg-green-100 text-green-700" : "bg-yellow-100 text-yellow-700"}`, children: decision === "take" ? "✓ TAKE" : "✗ SKIP" })
|
|
3703
|
+
] })
|
|
3704
|
+
] })
|
|
3705
|
+
] }),
|
|
3640
3706
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-6", children: [
|
|
3641
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-
|
|
3642
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "Items:" }),
|
|
3707
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-40", children: [
|
|
3708
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "Items (i = item index):" }),
|
|
3643
3709
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-1", children: items.map((item, idx) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3644
3710
|
"div",
|
|
3645
3711
|
{
|
|
3646
|
-
className: `px-2 py-1 rounded text-xs ${idx + 1 === currentI ? "bg-purple-
|
|
3712
|
+
className: `px-2 py-1.5 rounded text-xs transition-colors ${idx + 1 === currentI ? "bg-purple-200 text-purple-900 font-bold ring-2 ring-purple-400" : idx + 1 < currentI ? "bg-blue-50 text-blue-600" : "bg-gray-100 text-gray-500"}`,
|
|
3647
3713
|
children: [
|
|
3648
|
-
"
|
|
3649
|
-
|
|
3714
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-mono", children: [
|
|
3715
|
+
"i=",
|
|
3716
|
+
idx + 1
|
|
3717
|
+
] }),
|
|
3650
3718
|
": w=",
|
|
3651
3719
|
item.weight,
|
|
3652
3720
|
", v=",
|
|
3653
|
-
item.value
|
|
3721
|
+
item.value,
|
|
3722
|
+
idx + 1 === currentI && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-1", children: "← CURRENT" })
|
|
3654
3723
|
]
|
|
3655
3724
|
},
|
|
3656
3725
|
idx
|
|
3657
3726
|
)) }),
|
|
3658
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-3 text-sm", children: [
|
|
3659
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium text-gray-700", children: "Capacity:" }),
|
|
3727
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-3 text-sm p-2 bg-gray-100 rounded", children: [
|
|
3728
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium text-gray-700", children: "Max Capacity:" }),
|
|
3660
3729
|
" ",
|
|
3661
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-900", children: capacity })
|
|
3730
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-900 font-mono", children: capacity })
|
|
3662
3731
|
] })
|
|
3663
3732
|
] }),
|
|
3664
3733
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 overflow-x-auto", children: [
|
|
3665
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "DP Table:" }),
|
|
3734
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm font-medium text-gray-700 mb-2", children: "DP Table (w = current capacity):" }),
|
|
3666
3735
|
/* @__PURE__ */ jsxRuntime.jsxs("table", { className: "text-xs border-collapse", children: [
|
|
3667
3736
|
/* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
|
|
3668
3737
|
/* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-8 p-1 text-gray-500 font-normal", children: "i\\w" }),
|