CurrStatVDP/Diagram-Canvas/DiagramStoveDll/Diagram.min.js
2021-05-18 09:14:14 +05:00

1 line
13 KiB
JavaScript

function Rectangle(n, i, e, r) { function o(t) { t = parseFloat(t); return isNaN(t) || t < 0 ? 0 : t } this.X = function (t) { if (void 0 === t) return n; n = o(t) }, this.Y = function (t) { if (void 0 === t) return i; i = o(t) }, this.W = function (t) { if (void 0 === t) return e; e = o(t) }, this.H = function (t) { if (void 0 === t) return r; r = o(t) }, this.RectParam = function (t, n, i, e) { this.X(t), this.Y(n), this.W(i), this.H(e) }, this.Rect = function (t) { if (void 0 === t) return this; this.RectParam(t.X(), t.Y(), t.W(), t.H()) }, void 0 === n ? n = 0 : this.X(n), void 0 === i ? i = 0 : this.Y(i), void 0 === e ? e = 0 : this.W(e), void 0 === r ? r = 0 : this.H(r) } function PercentColumn(t, n, i, e) { var r = new Rectangle(t, n, i, e), o = new Rectangle, s = !1, a = 0, l = "#000"; this.X = function (t) { if (void 0 === t) return r.X(); r.X(t) }, this.Y = function (t) { if (void 0 === t) return r.Y(); r.Y(t) }, this.W = function (t) { if (void 0 === t) return r.W(); r.W(t) }, this.H = function (t) { if (void 0 === t) return r.H(); r.H(t) }, this.Percent = function (t) { if (void 0 === t) return a; t = parseFloat(t), t = isNaN(t) || t < 0 ? 0 : 100 < t ? 100 : t; a = t }, this.Color = function (t) { if (void 0 === t) return l; t = t.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i); l = null === t ? "#000000" : t[0] }, this.RectParam = function (t, n, i, e) { r.RectParam(t, n, i, e) }, this.Rect = function (t) { if (void 0 === t) return r; r.Rect(t) }, this.Rotate = function (t) { if (void 0 === t) return s; s = "boolean" == typeof t && t }, this.Print = function (t) { var n; n = (s ? r.W() : r.H()) * a / 100, o.RectParam(r.X(), s ? r.Y() : r.Y() + r.H() - n, s ? n : r.W(), s ? r.H() : n), t.fillStyle = l, t.strokeStyle = l, t.fillRect(o.X(), o.Y(), o.W(), o.H()), t.strokeRect(r.X(), r.Y(), r.W(), r.H()) }, this.PrintText = function (t) { t.save(), t.translate(r.X() + r.W() / 2, r.Y() + r.H() / 2), s || t.rotate(3 * Math.PI / 2), t.fillStyle = "#888", t.textAlign = "center", t.textBaseline = "middle", t.font = s ? (r.H() - 10 < 0 ? 0 : r.H() - 10) + "px Arial" : (r.W() - 10 < 0 ? 0 : r.W() - 10) + "px Arial", t.fillText(Math.floor(100 * a) / 100 + "%", 0, 0), t.restore() } } function ProcessColumn(t, n, i, e) { var s = new Rectangle(t, n, i, e), a = [], l = [], r = 0, o = -1, f = !1; function u(t, n) { var i = parseInt(t), n = parseFloat(n); if (!isNaN(i)) { for (; i >= l.length;)l.push(1); l[i] = isNaN(n) || n <= 0 ? 1 : n } } function c() { for (var t = 0, n = 0; n < l.length; n++)t += l[n]; return t } function h() { var t = (t = (f ? s.W() : s.H()) - (1 + a.length)) < 0 ? 0 : t; return c() <= 0 ? 0 : t / c() } function d() { for (var t = 0; t < a.length; t++)a[t].Percent(t < o ? 100 : t == o ? r : 0) } function p() { for (var t = s.X() + 1, n = s.Y() + 1, i = 0; i < a.length; i++) { var e = f ? i : a.length - (i + 1), r = f ? l[e] * h() : s.W() - 2, o = f ? s.H() - 2 : l[e] * h(); a[e].RectParam(t, n, r, o), t = f ? t + 1 + r : t, n = f ? n : n + 1 + o } } this.X = function (t) { if (void 0 === t) return s().X(); s().X(t) }, this.Y = function (t) { if (void 0 === t) return s().Y(); s().Y(t) }, this.W = function (t) { if (void 0 === t) return s().W(); s().W(t) }, this.H = function (t) { if (void 0 === t) return s().H(); s().H(t) }, this.Percent = function (t) { if (void 0 === t) return r; t = parseFloat(t); r = isNaN(t) || t < 0 ? 0 : 100 < t ? 100 : t }, this.Status = function (t) { if (void 0 === t) return o; t = parseInt(t); o = isNaN(t) || t < -1 || 0 === a.length ? -1 : t >= a.length ? a.length - 1 : t }, this.RectParam = function (t, n, i, e) { s.RectParam(t, n, i, e) }, this.Rect = function (t) { if (void 0 === t) return s; s.Rect(t) }, this.Rotate = function (t) { if (void 0 === t) return f; f = "boolean" == typeof t && t; for (var n = 0; n < a.length; n++)a[n].Rotate(f) }, this.StatCount = function () { return a.length }, this.AddRStat = function (t, n, i) { t = parseInt(t); isNaN(t) || t < 0 || t - 1 > a.length ? (a.push(new PercentColumn), t = a.length - 1) : a.splice(t, 0, new PercentColumn), a[t].Color(i), u(t, n) }, this.ChangeRStat = function (t, n, i) { t = parseInt(t); !isNaN(t) && 0 <= t && t < a.length && (a[t].Color(i), u(t, n)) }, this.DelRStat = function (t) { t = parseInt(t); !isNaN(t) && 0 <= t && t < a.length ? (a.splice(t, 1), l.splice(t, 1)) : 0 < a.length && (a.pop(), l.pop()) }, this.BuildDefault = function () { for (var t = [57, 49, 49, 71, 28, 49, 21, 171, 114, 103], n = ["#0ff", "#00f", "#f00", "#0f0", "#0ff", "#00f", "#8500b6", "#f00", "#f0f", "#0f0"]; 0 < a.length;)this.DelRStat(); for (var i = 0; i < t.length; i++)this.AddRStat(i, t[i], n[i]) }, this.Print = function (t) { this.Rotate(f), d(), p(), t.clearRect(s.X(), s.Y(), s.W(), s.H()), t.fillStyle = "#ddd", t.fillRect(s.X(), s.Y(), s.W(), s.H()); for (var n = 0; n < a.length; n++)n <= o && a[n].Print(t); t.strokeStyle = "#000", t.strokeRect(s.X(), s.Y(), s.W(), s.H()) }, this.PrintText = function (t) { this.Rotate(f), d(), p(), t.save(), t.translate(s.X() + s.W() / 2, s.Y() + s.H() / 2), f || t.rotate(3 * Math.PI / 2), t.fillStyle = "#888", t.textAlign = "center", t.textBaseline = "middle", t.font = f ? (s.H() - 10 < 0 ? 0 : s.H() - 10) + "px Arial" : (s.W() - 10 < 0 ? 0 : s.W() - 10) + "px Arial", t.fillText(Math.floor(100 * r) / 100 + "% " + (o + 1) + "/" + a.length, 0, 0), t.restore() } } function BlinkStatus(t, n, i, e) { var r = new Rectangle(t, n, i, e), o = [], s = 0, a = !1; this.X = function (t) { if (void 0 === t) return r().X(); r().X(t) }, this.Y = function (t) { if (void 0 === t) return r().Y(); r().Y(t) }, this.W = function (t) { if (void 0 === t) return r().W(); r().W(t) }, this.H = function (t) { if (void 0 === t) return r().H(); r().H(t) }, this.Status = function (t) { if (void 0 === t) return s; t = parseInt(t); s = isNaN(t) || t < -1 ? -1 : t >= o.length ? o.length - 1 : t }, this.StatCount = function () { return o.length }, this.RectParam = function (t, n, i, e) { r.RectParam(t, n, i, e) }, this.Rect = function (t) { if (void 0 === t) return r; r.Rect(t) }, this.Rotate = function (t) { if (void 0 === t) return a; a = "boolean" == typeof t && t }, this.AddStatus = function (t, n) { void 0 === n && (n = "#000"); n = null === (n = n.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i)) ? "#000000" : n[0], t = parseInt(t); isNaN(t) || t < 0 || t > o.length - 1 ? o.push(n) : o.splice(t, 0, n) }, this.ChangeStatus = function (t, n) { void 0 === n && (n = "#000"); n = null === (n = n.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i)) ? "#000000" : n[0], t = parseInt(t); !isNaN(t) && 0 <= t && t < o.length && o.splice(t, 1, n) }, this.DelStatus = function (t) { t = parseInt(t); !isNaN(t) && 0 <= t && t < o.length ? o.splice(t, 1) : 0 < o.length && o.pop() }, this.BuildDefault = function () { for (var t = ["#00f", "#f00", "#0f0"], n = 0; n < t.length; n++)this.AddStatus(0, t[n]) }, this.Print = function (t) { t.fillStyle = 0 <= s && s < o.length ? o[s] : "#ddd", t.fillRect(r.X(), r.Y(), r.W(), r.H()), t.strokeStyle = "#000", t.strokeRect(r.X(), r.Y(), r.W(), r.H()) }, this.PrintText = function (t) { t.save(), t.translate(r.X() + r.W() / 2, r.Y() + r.H() / 2), a && t.rotate(3 * Math.PI / 2), t.fillStyle = "#888", t.textAlign = "center", t.textBaseline = "middle", t.font = a ? (r.W() - 2 < 0 ? 0 : r.W() - 2) + "px Arial" : (r.H() - 2 < 0 ? 0 : r.H() - 2) + "px Arial", t.fillText(s + 1 + "/" + o.length, 0, 0), t.restore() } } function NumberColumn(t, n, i, e, r) { var o = new Rectangle(t, n, i, e), s = !0, a = !1; this.X = function (t) { if (void 0 === t) return o().X(); o().X(t) }, this.Y = function (t) { if (void 0 === t) return o().Y(); o().Y(t) }, this.W = function (t) { if (void 0 === t) return o().W(); o().W(t) }, this.H = function (t) { if (void 0 === t) return o().H(); o().H(t) }, this.RectParam = function (t, n, i, e) { o.RectParam(t, n, i, e) }, this.Rect = function (t) { if (void 0 === t) return o; o.Rect(t) }, this.Number = function (t) { if (void 0 === t) return r; t = parseInt(t); r = isNaN(t) || t < 0 ? 0 : t }, this.Number(r), this.Prostoy = function (t) { if (void 0 === t) return s; s = "boolean" == typeof t && t }, this.Rotate = function (t) { if (void 0 === t) return a; a = "boolean" == typeof t && t }, this.Print = function (t) { t.fillStyle = s ? "#ff8000" : "#ff0", t.fillRect(o.X(), o.Y(), o.W(), o.H()), t.strokeStyle = "#000", t.strokeRect(o.X(), o.Y(), o.W(), o.H()), t.save(), t.translate(o.X() + o.W() / 2, o.Y() + o.H() / 2), a && t.rotate(3 * Math.PI / 2), t.fillStyle = "#000", t.textAlign = "center", t.textBaseline = "middle"; var n = (n = o.H() < o.W() ? o.H() - 3 : o.W() - 3) < 0 ? 0 : n; t.font = n + "px Arial", t.fillText(r, 0, 0), t.restore() } } function Diagram(t, n, i, e) { var o = 1e3, H = new Rectangle(t, n, i, e), P = [], W = [], N = [], s = [], a = [], l = !1, f = -1, m = !1; function u(t) { for (var n, i = null == t ? new Date : t, e = !1, r = 0; r < P.length; r++)s[r] != a[r] && (n = a[r] - s[r], s[r], n = 100 * (i - s[r]) / n, P[r].Percent(n), N[r].Prostoy(100 <= n), e = e || n < 100); l = l && e, i.setMilliseconds(i.getMilliseconds() + o), l && (f = null == t ? setTimeout(u, o) : setTimeout(u, o, i)) } this.minBoardW = function () { return (stW + 1) * (P.length + 1) + 5 * P.length }, this.minBoardH = function () { return 4 * (stH + 1) + szHP + szHB + szHN }, this.X = function (t) { if (void 0 === t) return H().X(); H().X(t) }, this.Y = function (t) { if (void 0 === t) return H().Y(); H().Y(t) }, this.W = function (t) { if (void 0 === t) return H().W(); H().W(t) }, this.H = function (t) { if (void 0 === t) return H().H(); H().H(t) }, this.RectParam = function (t, n, i, e) { H.RectParam(t, n, i, e) }, this.Rect = function (t) { if (void 0 === t) return H; H.Rect(t) }, this.ProcCount = function () { return P.length }, this.AddProc = function (t, n, i, e) { var r = parseInt(t), r = isNaN(r) || r < 0 || r >= P.length ? -1 : r, t = new Date; -1 == r ? (P.push(n), W.push(i), N.push(e), s.push(t), a.push(t)) : (P.splice(r, 0, n), W.splice(r, 0, i), N.splice(r, 0, e), s.splice(r, 0, t), a.splice(r, 0, t)) }, this.ChangeProc = function (t, n, i, e) { var r = parseInt(t), r = isNaN(r) || r < 0 || r >= P.length ? -1 : r, t = new Date; -1 != r && (P.splice(r, 1, n), W.splice(r, 1, i), N.splice(r, 1, e), s.splice(r, 1, t), a.splice(r, 1, t)) }, this.DelStove = function (t) { 0 != P.length && (t = parseInt(t), -1 == (t = isNaN(t) || t < 0 || t >= P.length ? -1 : t) ? (P.pop(), W.pop(), N.pop(), s.pop(), a.pop()) : (P.splice(t, 1), W.splice(t, 1), N.splice(t, 1), s.splice(t, 1), a.splice(t, 1))) }, this.StartDate = function (t, n) { t = parseInt(t); -1 != (t = isNaN(t) || t < 0 || t >= s.length ? -1 : t) && (s[t] = n) }, this.EndDate = function (t, n) { t = parseInt(t); -1 != (t = isNaN(t) || t < 0 || t >= s.length ? -1 : t) && (a[t] = n) }, this.ChangeStatProc = function (t, n, i) { t = parseInt(t); !isNaN(t) && 0 <= t && t < P.length && (P[t].Status(n), P[t].Percent(i)) }, this.ChangeStatBlink = function (t, n) { t = parseInt(t); !isNaN(t) && -1 <= t && t < W.length && W[t].Status(n) }, this.ChangeStatNumb = function (t, n) { t = parseInt(t); !isNaN(t) && 0 <= t && t < N.length && N[t].Prostoy(n) }, this.Rotate = function (t) { if (void 0 === t) return m; m = "boolean" == typeof t && t; for (var n = 0; n < P.length; n++)P[n].Rotate(m), N[n].Rotate(m), W[n].Rotate(m) }, this.BuildDefault = function () { for (; P.length < 48;) { P.push(new ProcessColumn(0, 0, 0, 0)), P[P.length - 1].BuildDefault(), W.push(new BlinkStatus(0, 0, 0, 0)), W[P.length - 1].BuildDefault(), N.push(new NumberColumn(0, 0, 0, 0, P.length)); var t = new Date; s.push(t), a.push(t) } }, this.Rebuild = function () { for (var t = H.X() + 2 + 1, n = H.Y() + 2 + 1, i = H.W() - 3 * (P.length + 1), e = H.H() - 3 * (P.length + 1), r = 0; r < P.length; r++) { var o, s = 0, a = 0, l = 0, f = 0, u = 0, c = 0, h = 0, d = 0, p = 0, v = 0, g = 0, R = 0; m ? (c = u = f = n, e -= o = (o = Math.ceil(e / (P.length - r))) < 4 ? 4 : o, R = g = v = o, d = 10, p = 17, l = (a = (s = t) + (h = (h = H.W() - 12 - 10 - 17) < 40 ? 40 : h) + 3) + 10 + 3, s = (a = (l = t) + p + 3) + 10 + 3) : (l = a = s = t, i -= o = (o = Math.ceil(i / (P.length - r))) < 4 ? 4 : o, p = d = h = o, g = 10, R = 17, c = (u = (f = n) + (v = (v = H.H() - 12 - 10 - 17) < 40 ? 40 : v) + 3) + 10 + 3), P[r].RectParam(s, f, h, v), W[r].RectParam(a, u, d, g), N[r].RectParam(l, c, p, R), m ? n += v + 2 + 1 : t += h + 2 + 1 } }, this.Print = function (t) { u(), this.Rotate(m), this.Rebuild(), t.clearRect(H.X(), H.Y(), H.W(), H.H()), t.fillStyle = "#ddd", t.fillRect(H.X(), H.Y(), H.W(), H.H()); for (var n = 0; n < P.length; n++)P[n].Print(t), W[n].Print(t), N[n].Print(t); t.strokeStyle = "#333", t.strokeRect(H.X(), H.Y(), H.W(), H.H()) }, this.PrintText = function (t) { for (var n = 0; n < P.length; n++)P[n].PrintText(t), W[n].PrintText(t) }, this.Cycle = function (t, n) { if (null == t || "boolean" != typeof t) return l; t && (this.CheckDate(), clearTimeout(f), l = !0, u(n)) }, this.CheckDate = function () { for (var t, n = 0; n < P.length; n++)s[n] > a[n] && (t = s[n], s[n] = a[n], a[n] = t) } }