react-pert 1.0.0-beta.1 → 1.0.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 +241 -61
- package/dist/index.d.ts +160 -18
- package/dist/index.js +582 -132
- package/dist/index.umd.cjs +11 -1
- package/dist/main.css +1 -0
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,165 +1,168 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { jsx as
|
|
5
|
-
import { createContext as
|
|
6
|
-
const
|
|
7
|
-
let
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.initialData =
|
|
1
|
+
import './main.css';var J = Object.defineProperty;
|
|
2
|
+
var W = (r, t, s) => t in r ? J(r, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[t] = s;
|
|
3
|
+
var x = (r, t, s) => W(r, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
+
import { jsx as h, jsxs as L, Fragment as Z } from "react/jsx-runtime";
|
|
5
|
+
import b, { createContext as j, useContext as C, useState as D, useCallback as F, useMemo as P, useRef as K, useEffect as q } from "react";
|
|
6
|
+
const N = () => Math.random().toString(36).substring(7);
|
|
7
|
+
let G = class {
|
|
8
|
+
constructor(t) {
|
|
9
|
+
x(this, "levels");
|
|
10
|
+
x(this, "tasksMap");
|
|
11
|
+
x(this, "initialData");
|
|
12
|
+
x(this, "links");
|
|
13
|
+
x(this, "criticalPaths");
|
|
14
|
+
x(this, "lastTaskKey");
|
|
15
|
+
x(this, "startTaskKey");
|
|
16
|
+
x(this, "projectDuration");
|
|
17
|
+
this.initialData = t, this.tasksMap = /* @__PURE__ */ new Map(), this.lastTaskKey = `Finish-${N()}`, this.startTaskKey = `Start-${N()}`, this.links = [], this.criticalPaths = [], this.levels = /* @__PURE__ */ new Map(), this.projectDuration = 0;
|
|
18
18
|
}
|
|
19
19
|
convertDataToMap() {
|
|
20
20
|
this.tasksMap = /* @__PURE__ */ new Map(), this.tasksMap.set(this.startTaskKey, {
|
|
21
21
|
key: this.startTaskKey,
|
|
22
22
|
duration: 0,
|
|
23
23
|
text: "Start"
|
|
24
|
-
}), this.initialData.forEach((
|
|
25
|
-
if (this.tasksMap.has(
|
|
24
|
+
}), this.initialData.forEach((t, s) => {
|
|
25
|
+
if (this.tasksMap.has(t.key)) throw Error(`Duplicate keys found ${t.key}`);
|
|
26
26
|
this.tasksMap.set(
|
|
27
|
-
|
|
28
|
-
!
|
|
27
|
+
t.key,
|
|
28
|
+
!t.dependsOn || t.dependsOn.length === 0 ? { ...t, dependsOn: [this.startTaskKey], index: s } : { ...t, index: s }
|
|
29
29
|
);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
calculatePERT() {
|
|
33
|
-
this.convertDataToMap(), this.calcLevels()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.levels[t].forEach((a) => {
|
|
37
|
-
this.calculateEarlyTimes(a);
|
|
33
|
+
this.convertDataToMap(), this.calcLevels(), this.levels.forEach((s) => {
|
|
34
|
+
s.forEach((e) => {
|
|
35
|
+
this.calculateEarlyTimes(e);
|
|
38
36
|
});
|
|
39
37
|
});
|
|
40
|
-
let
|
|
41
|
-
(
|
|
38
|
+
let t = Array.from(this.tasksMap.values()).reduce(
|
|
39
|
+
(s, e) => s.earlyFinish > e.earlyFinish ? s : e
|
|
42
40
|
);
|
|
43
|
-
|
|
41
|
+
t.lateFinish = t.earlyFinish, t.critical = !0, this.tasksMap.set(this.lastTaskKey, {
|
|
44
42
|
key: this.lastTaskKey,
|
|
45
43
|
text: "Finish",
|
|
46
|
-
dependsOn: [
|
|
44
|
+
dependsOn: [t.key],
|
|
47
45
|
duration: 0,
|
|
48
|
-
earlyStart:
|
|
49
|
-
earlyFinish:
|
|
50
|
-
lateFinish:
|
|
51
|
-
lateStart:
|
|
52
|
-
level:
|
|
46
|
+
earlyStart: t.earlyFinish,
|
|
47
|
+
earlyFinish: t.earlyFinish,
|
|
48
|
+
lateFinish: t.earlyFinish,
|
|
49
|
+
lateStart: t.earlyFinish,
|
|
50
|
+
level: this.levels.size,
|
|
53
51
|
critical: !0,
|
|
54
52
|
freeFloat: 0,
|
|
55
53
|
totalFloat: 0,
|
|
56
54
|
index: this.tasksMap.size - 1
|
|
57
|
-
}), this.levels[
|
|
58
|
-
for (
|
|
59
|
-
|
|
60
|
-
this.calculateLateTimes(
|
|
55
|
+
}), this.levels.set(this.levels.size, [this.lastTaskKey]), this.projectDuration = t.lateFinish;
|
|
56
|
+
for (const [, s] of [...this.levels.entries()].reverse())
|
|
57
|
+
s.forEach((e) => {
|
|
58
|
+
this.calculateLateTimes(e, t.lateFinish);
|
|
61
59
|
});
|
|
62
|
-
|
|
63
|
-
this.levels
|
|
64
|
-
|
|
60
|
+
this.levels.forEach((s, e) => {
|
|
61
|
+
this.levels.set(
|
|
62
|
+
e,
|
|
63
|
+
s.sort((n, i) => this.tasksMap.get(n).index - this.tasksMap.get(i).index)
|
|
65
64
|
);
|
|
66
|
-
})
|
|
65
|
+
});
|
|
67
66
|
}
|
|
68
|
-
getSuccessors(
|
|
67
|
+
getSuccessors(t) {
|
|
69
68
|
return Array.from(this.tasksMap.values()).filter(
|
|
70
|
-
(s) => s.dependsOn && s.dependsOn.includes(
|
|
69
|
+
(s) => s.dependsOn && s.dependsOn.includes(t.key)
|
|
71
70
|
);
|
|
72
71
|
}
|
|
73
|
-
calculateEarlyTimes(
|
|
74
|
-
const s = this.tasksMap.get(
|
|
72
|
+
calculateEarlyTimes(t) {
|
|
73
|
+
const s = this.tasksMap.get(t);
|
|
75
74
|
if (!s.dependsOn)
|
|
76
75
|
s.earlyStart = 0;
|
|
77
76
|
else {
|
|
78
|
-
let
|
|
79
|
-
s.dependsOn.forEach((
|
|
80
|
-
const i = this.tasksMap.get(
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
let e = 0;
|
|
78
|
+
s.dependsOn.forEach((n) => {
|
|
79
|
+
const i = this.tasksMap.get(n);
|
|
80
|
+
e = Math.max(
|
|
81
|
+
e,
|
|
83
82
|
i.earlyStart + i.duration
|
|
84
83
|
);
|
|
85
|
-
}), s.earlyStart =
|
|
84
|
+
}), s.earlyStart = e;
|
|
86
85
|
}
|
|
87
86
|
s.earlyFinish = s.earlyStart + s.duration;
|
|
88
87
|
}
|
|
89
|
-
calculateLateTimes(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
calculateLateTimes(t, s) {
|
|
89
|
+
var o;
|
|
90
|
+
const e = this.tasksMap.get(t), n = this.getSuccessors(e);
|
|
91
|
+
n.length === 0 && ((o = this.tasksMap.get(this.lastTaskKey).dependsOn) == null || o.push(t));
|
|
92
|
+
let i = n.length === 0 ? s : Math.min(...n.map((l) => l.lateFinish - l.duration));
|
|
93
|
+
e.lateFinish = i, e.lateStart = e.lateFinish - e.duration, e.critical = e.earlyFinish === e.lateFinish, e.critical ? (e.freeFloat = 0, e.totalFloat = 0) : (e.freeFloat = (n.length === 0 ? s : Math.min(...n.map((l) => l.earlyStart))) - e.earlyFinish, e.totalFloat = e.lateFinish - e.earlyFinish);
|
|
93
94
|
}
|
|
94
95
|
calcLevels() {
|
|
95
|
-
this.levels
|
|
96
|
-
let
|
|
97
|
-
const s = (
|
|
98
|
-
if (
|
|
96
|
+
this.levels.clear();
|
|
97
|
+
let t = [];
|
|
98
|
+
const s = (e) => {
|
|
99
|
+
if (t.includes(e.key))
|
|
99
100
|
throw new Error("Circular dependency detected");
|
|
100
|
-
if (!
|
|
101
|
-
|
|
101
|
+
if (!e.dependsOn || e.dependsOn.length === 0)
|
|
102
|
+
e.level = 0;
|
|
102
103
|
else {
|
|
103
|
-
let
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
if (!
|
|
107
|
-
throw new Error(`Task with KEY '${
|
|
108
|
-
|
|
109
|
-
}),
|
|
104
|
+
let i = 0;
|
|
105
|
+
e.dependsOn.forEach((o) => {
|
|
106
|
+
const l = this.tasksMap.get(o);
|
|
107
|
+
if (!l)
|
|
108
|
+
throw new Error(`Task with KEY '${o}' was not found.`);
|
|
109
|
+
l.level === void 0 && (t.push(e.key), s(l)), i = Math.max(i, l.level + 1);
|
|
110
|
+
}), e.level = i;
|
|
110
111
|
}
|
|
111
|
-
this.levels
|
|
112
|
+
this.levels.has(e.level) || this.levels.set(e.level, []);
|
|
113
|
+
const n = this.levels.get(e.level);
|
|
114
|
+
n.includes(e.key) || n.push(e.key);
|
|
112
115
|
};
|
|
113
|
-
this.tasksMap.forEach((
|
|
114
|
-
e = [], s(
|
|
116
|
+
this.tasksMap.forEach((e) => {
|
|
117
|
+
e.level === void 0 && (t = [], s(e));
|
|
115
118
|
});
|
|
116
119
|
}
|
|
117
120
|
calcNodeLinks() {
|
|
118
|
-
const
|
|
119
|
-
this.tasksMap.forEach((
|
|
120
|
-
|
|
121
|
-
s.push(i),
|
|
121
|
+
const t = [], s = [];
|
|
122
|
+
this.tasksMap.forEach((e, n) => {
|
|
123
|
+
e.dependsOn ? e.dependsOn.forEach((i) => {
|
|
124
|
+
s.push(i), t.push({
|
|
122
125
|
from: i,
|
|
123
|
-
to:
|
|
124
|
-
critical:
|
|
126
|
+
to: e.key,
|
|
127
|
+
critical: e.critical && this.tasksMap.get(i).critical
|
|
125
128
|
});
|
|
126
|
-
}) :
|
|
129
|
+
}) : n !== this.startTaskKey && t.push({
|
|
127
130
|
from: this.startTaskKey,
|
|
128
|
-
to:
|
|
129
|
-
critical:
|
|
131
|
+
to: e.key,
|
|
132
|
+
critical: e.critical
|
|
130
133
|
});
|
|
131
|
-
}), this.tasksMap.forEach((
|
|
132
|
-
!s.includes(
|
|
133
|
-
from:
|
|
134
|
+
}), this.tasksMap.forEach((e) => {
|
|
135
|
+
!s.includes(e.key) && e.key !== this.lastTaskKey && t.push({
|
|
136
|
+
from: e.key,
|
|
134
137
|
to: this.lastTaskKey,
|
|
135
|
-
critical:
|
|
138
|
+
critical: e.critical
|
|
136
139
|
});
|
|
137
|
-
}), this.links =
|
|
140
|
+
}), this.links = t;
|
|
138
141
|
}
|
|
139
142
|
calcCriticalPaths() {
|
|
140
143
|
this.calcNodeLinks();
|
|
141
|
-
const
|
|
144
|
+
const t = [];
|
|
142
145
|
this.links.filter(
|
|
143
|
-
(
|
|
144
|
-
).forEach((
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
(
|
|
146
|
+
(e) => e.critical && e.from === this.startTaskKey && e.to !== this.lastTaskKey
|
|
147
|
+
).forEach((e) => {
|
|
148
|
+
const n = [e], i = (o) => {
|
|
149
|
+
const l = this.links.filter(
|
|
150
|
+
(a) => a.critical && a.from === o.to && a.to !== this.lastTaskKey
|
|
148
151
|
);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
text: this.tasksMap.get(
|
|
152
|
-
key:
|
|
152
|
+
l.length === 0 ? t.push(
|
|
153
|
+
n.map((a) => ({
|
|
154
|
+
text: this.tasksMap.get(a.to).text,
|
|
155
|
+
key: a.to
|
|
153
156
|
}))
|
|
154
|
-
) :
|
|
155
|
-
|
|
157
|
+
) : l.forEach((a) => {
|
|
158
|
+
n.push(a), i(a), n.pop();
|
|
156
159
|
});
|
|
157
160
|
};
|
|
158
|
-
i(
|
|
159
|
-
}), this.criticalPaths =
|
|
161
|
+
i(e);
|
|
162
|
+
}), this.criticalPaths = t;
|
|
160
163
|
}
|
|
161
164
|
getTasks() {
|
|
162
|
-
return this.calculatePERT(), this.
|
|
165
|
+
return this.calculatePERT(), this.tasksMap;
|
|
163
166
|
}
|
|
164
167
|
getCriticalPaths() {
|
|
165
168
|
return this.criticalPaths.length === 0 && this.calcCriticalPaths(), this.criticalPaths;
|
|
@@ -170,47 +173,494 @@ let g = class {
|
|
|
170
173
|
getNodeLinks() {
|
|
171
174
|
return this.links;
|
|
172
175
|
}
|
|
176
|
+
getProjectDuration() {
|
|
177
|
+
return this.projectDuration;
|
|
178
|
+
}
|
|
173
179
|
solve() {
|
|
174
180
|
return {
|
|
175
181
|
tasks: this.getTasks(),
|
|
176
182
|
levels: this.getLevels(),
|
|
177
183
|
criticalPaths: this.getCriticalPaths(),
|
|
178
|
-
links: this.getNodeLinks()
|
|
184
|
+
links: this.getNodeLinks(),
|
|
185
|
+
projectDuration: this.getProjectDuration()
|
|
179
186
|
};
|
|
180
187
|
}
|
|
181
188
|
};
|
|
182
|
-
const
|
|
183
|
-
tasks:
|
|
184
|
-
levels:
|
|
189
|
+
const I = {
|
|
190
|
+
tasks: /* @__PURE__ */ new Map(),
|
|
191
|
+
levels: /* @__PURE__ */ new Map(),
|
|
185
192
|
links: [],
|
|
186
|
-
criticalPaths: []
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
criticalPaths: [],
|
|
194
|
+
projectDuration: 0
|
|
195
|
+
}, A = j(null), B = j(null), U = (r) => ({ children: t }) => {
|
|
196
|
+
const [s, e] = D(I), [n, i] = D(null), o = F((l) => {
|
|
197
|
+
try {
|
|
198
|
+
const a = new G(l).solve();
|
|
199
|
+
e(a), i(null);
|
|
200
|
+
} catch (a) {
|
|
201
|
+
console.error(a), e(I), i(a.message);
|
|
202
|
+
}
|
|
203
|
+
}, []);
|
|
204
|
+
return /* @__PURE__ */ h(
|
|
205
|
+
r.Provider,
|
|
206
|
+
{
|
|
207
|
+
value: {
|
|
208
|
+
pertData: s,
|
|
209
|
+
calculatePertResults: o,
|
|
210
|
+
error: n
|
|
211
|
+
},
|
|
212
|
+
children: t
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
}, Ft = U(A), Q = U(B), Lt = (r = { bounds: !0 }) => {
|
|
216
|
+
const t = C(A);
|
|
217
|
+
if (!t)
|
|
196
218
|
throw new Error("usePertData must be used within a PertProvider");
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
219
|
+
const s = Array.from(t.pertData.tasks.values()), e = r != null && r.bounds ? s.slice(1, -1).map((n) => {
|
|
220
|
+
var i;
|
|
221
|
+
return {
|
|
222
|
+
...n,
|
|
223
|
+
dependsOn: (i = n.dependsOn) != null && i.includes(s[0].key) ? [] : n.dependsOn
|
|
224
|
+
};
|
|
225
|
+
}) : s;
|
|
226
|
+
return {
|
|
227
|
+
...t.pertData,
|
|
228
|
+
tasks: e,
|
|
229
|
+
error: t.error,
|
|
230
|
+
projectDuration: t.pertData.projectDuration
|
|
231
|
+
};
|
|
232
|
+
}, Y = () => {
|
|
233
|
+
const r = C(A);
|
|
234
|
+
if (!r) {
|
|
235
|
+
const t = C(B);
|
|
236
|
+
if (!t)
|
|
237
|
+
throw new Error(
|
|
238
|
+
"usePertData must be used within a PertProvider or InternalPertProvider"
|
|
239
|
+
);
|
|
240
|
+
return t;
|
|
241
|
+
}
|
|
242
|
+
return r;
|
|
243
|
+
}, z = "_arrows_62ntr_1", tt = "_arrow_62ntr_1", et = "_critical_62ntr_8", st = "_onHover_62ntr_13", rt = "_onSelect_62ntr_17", nt = "_hover_62ntr_24", it = "_visible_62ntr_25", $ = {
|
|
244
|
+
arrows: z,
|
|
245
|
+
arrow: tt,
|
|
246
|
+
critical: et,
|
|
247
|
+
onHover: st,
|
|
248
|
+
onSelect: rt,
|
|
249
|
+
hover: nt,
|
|
250
|
+
visible: it
|
|
251
|
+
}, lt = ({
|
|
252
|
+
arrows: r,
|
|
253
|
+
taskSize: t,
|
|
254
|
+
levels: s,
|
|
255
|
+
size: e,
|
|
256
|
+
gap: n,
|
|
257
|
+
tasks: i,
|
|
258
|
+
selectedTask: o,
|
|
259
|
+
hoveredTask: l,
|
|
260
|
+
arrowStyles: a
|
|
261
|
+
}) => {
|
|
262
|
+
const c = (u, f) => o === u || o === f || l === u || l === f, y = (u, f = !1) => {
|
|
263
|
+
const d = i.get(u), v = d.level, k = s.get(v).findIndex((R) => R === u), m = s.get(v).length, p = m * t + (m - 1) * n.y, E = (e.height - p) / 2 + t / 2, w = v * (t + n.x) + (f ? t * (3 / 2) : t / 2), T = k * (t + n.y) + E;
|
|
264
|
+
return { x: w, y: T, level: v, task: d };
|
|
265
|
+
}, g = `${$.arrows} ${o ? $.onSelect : ""} ${l ? $.onHover : ""}`;
|
|
266
|
+
return /* @__PURE__ */ h("g", { className: g, children: r.map((u, f) => {
|
|
267
|
+
const {
|
|
268
|
+
x: d,
|
|
269
|
+
y: v,
|
|
270
|
+
level: k,
|
|
271
|
+
task: m
|
|
272
|
+
} = y(u.from, !0), {
|
|
273
|
+
x: p,
|
|
274
|
+
y: E,
|
|
275
|
+
level: w,
|
|
276
|
+
task: T
|
|
277
|
+
} = y(u.to), R = `${$.arrow} ${c(m.key, T.key) ? $.visible : ""} ${u.critical ? $.critical : ""}`;
|
|
278
|
+
return /* @__PURE__ */ h(
|
|
279
|
+
"path",
|
|
280
|
+
{
|
|
281
|
+
className: R,
|
|
282
|
+
d: `M ${d} ${v} C ${d + 20 * (w - k) + (p - d) / 1.2} ${v} ${d + 20 * (w - k) + (p - d) / 4} ${E} ${p} ${E}`,
|
|
283
|
+
style: a
|
|
284
|
+
},
|
|
285
|
+
f
|
|
286
|
+
);
|
|
287
|
+
}) });
|
|
288
|
+
}, at = "_tasks_1slwh_1", ot = "_task_1slwh_1", ct = "_critical_1slwh_22", ht = "_selected_1slwh_35", dt = "_visible_1slwh_44", S = {
|
|
289
|
+
tasks: at,
|
|
290
|
+
task: ot,
|
|
291
|
+
critical: ct,
|
|
292
|
+
selected: ht,
|
|
293
|
+
visible: dt
|
|
294
|
+
}, ut = ({ task: r, x: t, y: s, dimensions: e }) => {
|
|
295
|
+
const { halfRadius: n, twoThirdsRadius: i } = e;
|
|
296
|
+
return /* @__PURE__ */ L(Z, { children: [
|
|
297
|
+
/* @__PURE__ */ h("text", { x: t - n, y: s - i, fill: "black", children: r.earlyStart }),
|
|
298
|
+
/* @__PURE__ */ h("text", { x: t + n, y: s - i, fill: "black", children: r.earlyFinish }),
|
|
299
|
+
/* @__PURE__ */ h("text", { x: t - n, y: s + i, fill: "black", children: r.lateStart }),
|
|
300
|
+
/* @__PURE__ */ h("text", { x: t + n, y: s + i, fill: "black", children: r.lateFinish })
|
|
301
|
+
] });
|
|
302
|
+
}, ft = ({
|
|
303
|
+
task: r,
|
|
304
|
+
x: t,
|
|
305
|
+
y: s,
|
|
306
|
+
dimensions: e,
|
|
307
|
+
onHover: n,
|
|
308
|
+
onTaskClick: i,
|
|
309
|
+
isVisible: o,
|
|
310
|
+
isSelected: l,
|
|
311
|
+
taskStyles: a
|
|
312
|
+
}) => {
|
|
313
|
+
const { radius: c } = e, y = P(
|
|
314
|
+
() => `
|
|
315
|
+
M ${t - c} ${s - c / 3}
|
|
316
|
+
L ${t + c} ${s - c / 3}
|
|
317
|
+
M ${t - c} ${s + c / 3}
|
|
318
|
+
L ${t + c} ${s + c / 3}
|
|
319
|
+
M ${t} ${s + c / 3}
|
|
320
|
+
L ${t} ${s + c}
|
|
321
|
+
M ${t} ${s - c}
|
|
322
|
+
L ${t} ${s - c / 3}
|
|
323
|
+
`,
|
|
324
|
+
[t, s, c]
|
|
325
|
+
);
|
|
326
|
+
return /* @__PURE__ */ L(
|
|
327
|
+
"g",
|
|
328
|
+
{
|
|
329
|
+
className: `${S.task} ${l ? S.selected : ""} ${o ? S.visible : ""} ${r.critical ? S.critical : ""}`,
|
|
330
|
+
onMouseEnter: () => n(r.key, !0),
|
|
331
|
+
onMouseLeave: () => n(r.key, !1),
|
|
332
|
+
onClick: () => i(r.key),
|
|
333
|
+
style: a,
|
|
334
|
+
children: [
|
|
335
|
+
/* @__PURE__ */ h(
|
|
336
|
+
"rect",
|
|
337
|
+
{
|
|
338
|
+
x: t - c,
|
|
339
|
+
y: s - c,
|
|
340
|
+
rx: "20",
|
|
341
|
+
ry: "20",
|
|
342
|
+
width: c * 2,
|
|
343
|
+
height: c * 2
|
|
344
|
+
}
|
|
345
|
+
),
|
|
346
|
+
/* @__PURE__ */ h("text", { x: t, y: s, children: r.text }),
|
|
347
|
+
/* @__PURE__ */ h(ut, { task: r, x: t, y: s, dimensions: e }),
|
|
348
|
+
/* @__PURE__ */ h("path", { d: y, fill: "none" })
|
|
349
|
+
]
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
}, yt = b.memo(ft), vt = ({
|
|
353
|
+
level: r,
|
|
354
|
+
keyList: t,
|
|
355
|
+
tasks: s,
|
|
356
|
+
taskSize: e,
|
|
357
|
+
gap: n,
|
|
358
|
+
offset: i,
|
|
359
|
+
dimensions: o,
|
|
360
|
+
selectedTask: l,
|
|
361
|
+
onHover: a,
|
|
362
|
+
onTaskClick: c,
|
|
363
|
+
taskStyles: y
|
|
364
|
+
}) => /* @__PURE__ */ h("g", { children: t.map((g, u) => {
|
|
365
|
+
var p, E, w;
|
|
366
|
+
const f = s.get(g);
|
|
367
|
+
if (!f) return null;
|
|
368
|
+
const d = r * e + e + n.x * r, v = u * (e + n.y) + i, k = !!(l && ((p = f.dependsOn) != null && p.includes(l) || (w = (E = s.get(l)) == null ? void 0 : E.dependsOn) != null && w.includes(f.key))), m = f.key === l;
|
|
369
|
+
return /* @__PURE__ */ h(
|
|
370
|
+
yt,
|
|
371
|
+
{
|
|
372
|
+
task: f,
|
|
373
|
+
x: d,
|
|
374
|
+
y: v,
|
|
375
|
+
dimensions: o,
|
|
376
|
+
onHover: a,
|
|
377
|
+
onTaskClick: c,
|
|
378
|
+
isSelected: m,
|
|
379
|
+
isVisible: k,
|
|
380
|
+
taskStyles: y
|
|
381
|
+
},
|
|
382
|
+
f.key
|
|
383
|
+
);
|
|
384
|
+
}) }), kt = b.memo(vt), gt = ({
|
|
385
|
+
tasks: r,
|
|
386
|
+
levels: t,
|
|
387
|
+
taskSize: s,
|
|
388
|
+
size: e,
|
|
389
|
+
gap: n,
|
|
390
|
+
selectedTask: i,
|
|
391
|
+
setHoveredTask: o,
|
|
392
|
+
taskStyles: l
|
|
393
|
+
}) => {
|
|
394
|
+
const a = P(
|
|
395
|
+
() => ({
|
|
396
|
+
radius: s / 2,
|
|
397
|
+
halfRadius: s / 4,
|
|
398
|
+
twoThirdsRadius: s / 6 * 2
|
|
399
|
+
}),
|
|
400
|
+
[s]
|
|
401
|
+
), c = F(
|
|
402
|
+
(u, f) => {
|
|
403
|
+
o(f ? u : null);
|
|
404
|
+
},
|
|
405
|
+
[o]
|
|
406
|
+
), y = F(
|
|
407
|
+
(u) => {
|
|
408
|
+
_t(i !== u ? u : null);
|
|
409
|
+
},
|
|
410
|
+
[i]
|
|
411
|
+
), g = P(() => Array.from(t.entries()).map(([u, f]) => {
|
|
412
|
+
const d = f.length * s + (f.length - 1) * n.y, v = (e.height - d) / 2 + a.radius;
|
|
413
|
+
return /* @__PURE__ */ h(
|
|
414
|
+
kt,
|
|
415
|
+
{
|
|
416
|
+
level: u,
|
|
417
|
+
keyList: f,
|
|
418
|
+
tasks: r,
|
|
419
|
+
taskSize: s,
|
|
420
|
+
gap: n,
|
|
421
|
+
offset: v,
|
|
422
|
+
dimensions: a,
|
|
423
|
+
selectedTask: i,
|
|
424
|
+
onHover: c,
|
|
425
|
+
onTaskClick: y,
|
|
426
|
+
taskStyles: l
|
|
427
|
+
},
|
|
428
|
+
u
|
|
429
|
+
);
|
|
430
|
+
}), [
|
|
431
|
+
t,
|
|
432
|
+
r,
|
|
433
|
+
s,
|
|
434
|
+
n,
|
|
435
|
+
e.height,
|
|
436
|
+
a,
|
|
437
|
+
i,
|
|
438
|
+
c,
|
|
439
|
+
y,
|
|
440
|
+
l
|
|
441
|
+
]);
|
|
442
|
+
return /* @__PURE__ */ h("g", { className: S.tasks, children: g });
|
|
443
|
+
}, mt = b.memo(gt), pt = {
|
|
444
|
+
width: 300,
|
|
445
|
+
height: 200
|
|
446
|
+
}, Tt = {
|
|
447
|
+
display: "block",
|
|
448
|
+
boxSizing: "border-box",
|
|
449
|
+
transition: "width 0.3s ease, height 0.3s ease"
|
|
450
|
+
}, M = {
|
|
451
|
+
CRITICAL: "#ff9147",
|
|
452
|
+
TASK_BG: "#aaaeff",
|
|
453
|
+
CHART_BG: "#fff",
|
|
454
|
+
GRID: "#00000030",
|
|
455
|
+
TEXT: "#000",
|
|
456
|
+
SELECTED: "#6868ff",
|
|
457
|
+
STROKE: "#615f77"
|
|
458
|
+
}, O = {
|
|
459
|
+
BORDER: 1,
|
|
460
|
+
HOVER_BORDER: 2,
|
|
461
|
+
SELECTED_BORDER: 3
|
|
203
462
|
};
|
|
204
|
-
function
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
463
|
+
function Et({ size: r, taskSize: t, strokeColor: s }) {
|
|
464
|
+
const e = Math.ceil(r.height / t) + 1, n = Math.ceil(r.width / t) + 1, i = (o, l, a) => Array.from({ length: o }, (c, y) => {
|
|
465
|
+
const g = y * t;
|
|
466
|
+
return /* @__PURE__ */ h(
|
|
467
|
+
"line",
|
|
468
|
+
{
|
|
469
|
+
x1: l ? g : 0,
|
|
470
|
+
y1: l ? 0 : g,
|
|
471
|
+
x2: l ? g : a,
|
|
472
|
+
y2: l ? a : g,
|
|
473
|
+
style: {
|
|
474
|
+
stroke: s ?? M.GRID
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
y
|
|
478
|
+
);
|
|
479
|
+
});
|
|
480
|
+
return /* @__PURE__ */ L("g", { children: [
|
|
481
|
+
/* @__PURE__ */ h("g", { children: i(e, !1, r.width) }),
|
|
482
|
+
/* @__PURE__ */ h("g", { children: i(n, !0, r.height) })
|
|
483
|
+
] });
|
|
211
484
|
}
|
|
485
|
+
const wt = ({
|
|
486
|
+
size: r,
|
|
487
|
+
pertData: t,
|
|
488
|
+
selectedTask: s,
|
|
489
|
+
setHoveredTask: e,
|
|
490
|
+
hoveredTask: n,
|
|
491
|
+
styles: {
|
|
492
|
+
fontSize: i,
|
|
493
|
+
taskSize: o,
|
|
494
|
+
gap: l,
|
|
495
|
+
disableGrid: a,
|
|
496
|
+
taskBackground: c,
|
|
497
|
+
selectedBorderColor: y,
|
|
498
|
+
borderColor: g,
|
|
499
|
+
criticalColor: u,
|
|
500
|
+
arrowColor: f,
|
|
501
|
+
arrowWidth: d,
|
|
502
|
+
chartBackground: v,
|
|
503
|
+
textColor: k,
|
|
504
|
+
fontFamily: m,
|
|
505
|
+
borderWidth: p,
|
|
506
|
+
hoverBorderWidth: E,
|
|
507
|
+
selectedBorderWidth: w,
|
|
508
|
+
gridColor: T
|
|
509
|
+
}
|
|
510
|
+
}) => {
|
|
511
|
+
const R = {
|
|
512
|
+
"--task-bg": c ?? M.TASK_BG,
|
|
513
|
+
"--task-bg-critical": u ?? M.CRITICAL,
|
|
514
|
+
"--task-stroke-color": g ?? M.STROKE,
|
|
515
|
+
"--task-stroke-width": p ?? O.BORDER,
|
|
516
|
+
"--task-stroke-hover-width": E ?? O.HOVER_BORDER,
|
|
517
|
+
"--task-selected-stroke-width": w ?? O.SELECTED_BORDER,
|
|
518
|
+
"--task-selected-stroke-color": y ?? M.SELECTED,
|
|
519
|
+
"--task-text-color": k ?? M.TEXT,
|
|
520
|
+
"--task-font-family": m ?? "inherit"
|
|
521
|
+
}, X = {
|
|
522
|
+
"--arrow-stroke-color": f ?? M.STROKE,
|
|
523
|
+
"--arrow-critical-stroke-color": u ?? M.CRITICAL,
|
|
524
|
+
"--arrow-stroke-width": d ?? 2
|
|
525
|
+
}, V = {
|
|
526
|
+
...Tt,
|
|
527
|
+
fontSize: i,
|
|
528
|
+
backgroundColor: v
|
|
529
|
+
};
|
|
530
|
+
return /* @__PURE__ */ h(
|
|
531
|
+
"svg",
|
|
532
|
+
{
|
|
533
|
+
width: r.width,
|
|
534
|
+
height: r.height,
|
|
535
|
+
viewBox: `0 0 ${r.width} ${r.height}`,
|
|
536
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
537
|
+
style: V,
|
|
538
|
+
dominantBaseline: "central",
|
|
539
|
+
textAnchor: "middle",
|
|
540
|
+
children: /* @__PURE__ */ L("g", { className: "content", children: [
|
|
541
|
+
!a && /* @__PURE__ */ h(Et, { size: r, taskSize: o, strokeColor: T }),
|
|
542
|
+
/* @__PURE__ */ h(
|
|
543
|
+
lt,
|
|
544
|
+
{
|
|
545
|
+
gap: l,
|
|
546
|
+
arrows: t.links,
|
|
547
|
+
taskSize: o,
|
|
548
|
+
size: r,
|
|
549
|
+
levels: t.levels,
|
|
550
|
+
tasks: t.tasks,
|
|
551
|
+
selectedTask: s,
|
|
552
|
+
hoveredTask: n,
|
|
553
|
+
arrowStyles: X
|
|
554
|
+
}
|
|
555
|
+
),
|
|
556
|
+
/* @__PURE__ */ h(
|
|
557
|
+
mt,
|
|
558
|
+
{
|
|
559
|
+
gap: l,
|
|
560
|
+
size: r,
|
|
561
|
+
taskSize: o,
|
|
562
|
+
tasks: t.tasks,
|
|
563
|
+
levels: t.levels,
|
|
564
|
+
selectedTask: s,
|
|
565
|
+
setHoveredTask: e,
|
|
566
|
+
taskStyles: R
|
|
567
|
+
}
|
|
568
|
+
)
|
|
569
|
+
] })
|
|
570
|
+
}
|
|
571
|
+
);
|
|
572
|
+
};
|
|
573
|
+
function xt({ error: r }) {
|
|
574
|
+
return /* @__PURE__ */ h(
|
|
575
|
+
"div",
|
|
576
|
+
{
|
|
577
|
+
style: {
|
|
578
|
+
display: "flex",
|
|
579
|
+
justifyContent: "center",
|
|
580
|
+
alignItems: "center",
|
|
581
|
+
fontSize: "1.5rem",
|
|
582
|
+
padding: "3rem"
|
|
583
|
+
},
|
|
584
|
+
children: r
|
|
585
|
+
}
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
const Mt = ({
|
|
589
|
+
taskSize: r,
|
|
590
|
+
gap: t
|
|
591
|
+
}) => {
|
|
592
|
+
const { pertData: s } = Y();
|
|
593
|
+
return P(() => {
|
|
594
|
+
const e = Array.from(s.levels.values());
|
|
595
|
+
if (!e.length)
|
|
596
|
+
return { width: 0, height: 0 };
|
|
597
|
+
const n = Math.max(...e.map((i) => i.length));
|
|
598
|
+
return {
|
|
599
|
+
width: (e.length + 1) * r + (e.length - 1) * t.x,
|
|
600
|
+
height: (n + 1) * r + (n - 1) * t.y
|
|
601
|
+
};
|
|
602
|
+
}, [s.levels, r, t]);
|
|
603
|
+
}, H = {
|
|
604
|
+
sm: "0.75rem",
|
|
605
|
+
md: "1rem",
|
|
606
|
+
lg: "1.25rem",
|
|
607
|
+
xl: "1.5rem",
|
|
608
|
+
"2xl": "1.75rem",
|
|
609
|
+
"3xl": "2rem",
|
|
610
|
+
default: "1rem",
|
|
611
|
+
min: "0.75rem",
|
|
612
|
+
max: "2rem"
|
|
613
|
+
};
|
|
614
|
+
let _ = null;
|
|
615
|
+
const _t = (r) => {
|
|
616
|
+
if (_) {
|
|
617
|
+
if (!r)
|
|
618
|
+
_.setter(null);
|
|
619
|
+
else if (_.getTask) {
|
|
620
|
+
const t = _.getTask(r);
|
|
621
|
+
t && _.onSelect && _.onSelect(t), _.setter(r);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}, $t = ({ tasks: r, onSelect: t, styles: s }) => {
|
|
625
|
+
const { pertData: e, calculatePertResults: n, error: i } = Y(), o = K(), [l, a] = D(null), [c, y] = D(null), g = (T) => e.tasks.get(T);
|
|
626
|
+
_ = { setter: K(a).current, getTask: g, onSelect: t }, q(() => {
|
|
627
|
+
const T = JSON.stringify(r);
|
|
628
|
+
o.current !== T && (n(r), o.current = T);
|
|
629
|
+
}, [r, n]);
|
|
630
|
+
const f = F((T) => {
|
|
631
|
+
y(T);
|
|
632
|
+
}, []), { gap: d, taskSize: v, fontSize: k } = s, m = Math.max(v ?? 100, 70), p = P(
|
|
633
|
+
() => ({
|
|
634
|
+
x: Math.max(m, (d == null ? void 0 : d.x) ?? 0),
|
|
635
|
+
y: Math.max(m, (d == null ? void 0 : d.y) ?? 0)
|
|
636
|
+
}),
|
|
637
|
+
[d == null ? void 0 : d.x, d == null ? void 0 : d.y, m]
|
|
638
|
+
), E = Mt({ taskSize: m, gap: p }), w = P(() => k ? typeof k == "number" ? `${k}px` : H[k] || k : H.default, [k]);
|
|
639
|
+
return i ? /* @__PURE__ */ h(xt, { error: i }) : /* @__PURE__ */ h(
|
|
640
|
+
wt,
|
|
641
|
+
{
|
|
642
|
+
size: i ? pt : E,
|
|
643
|
+
pertData: e,
|
|
644
|
+
selectedTask: l,
|
|
645
|
+
hoveredTask: c,
|
|
646
|
+
setHoveredTask: f,
|
|
647
|
+
styles: { ...s, fontSize: w, taskSize: m, gap: p }
|
|
648
|
+
}
|
|
649
|
+
);
|
|
650
|
+
}, Ot = ({ styles: r, ...t }) => /* @__PURE__ */ h(Q, { children: /* @__PURE__ */ h(
|
|
651
|
+
"div",
|
|
652
|
+
{
|
|
653
|
+
style: {
|
|
654
|
+
width: "fit-content",
|
|
655
|
+
height: "fit-content",
|
|
656
|
+
boxSizing: "border-box"
|
|
657
|
+
},
|
|
658
|
+
children: /* @__PURE__ */ h($t, { ...t, styles: r ?? {} })
|
|
659
|
+
}
|
|
660
|
+
) });
|
|
212
661
|
export {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
662
|
+
Ot as Pert,
|
|
663
|
+
Ft as PertProvider,
|
|
664
|
+
_t as setSelectedTask,
|
|
665
|
+
Lt as usePert
|
|
216
666
|
};
|