2021-05-18 09:14:14 +05:00
|
|
|
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)
|