igniteui-angular-core
Version:
Ignite UI Angular Core logic used in multiple UI components.
1,022 lines (1,021 loc) • 33.5 kB
JavaScript
/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { __extends } from "tslib";
import { Base, runOn, Point_$type, markType } from "./type";
import { List$1 } from "./List$1";
import { LabelCollisionPlacementPositions_$type } from "./LabelCollisionPlacementPositions";
import { QuadTree } from "./QuadTree";
import { LinkedList$1 } from "./LinkedList$1";
import { LabelCollisionInfo } from "./LabelCollisionInfo";
import { QuadTreeBoundingBox } from "./QuadTreeBoundingBox";
import { Random } from "./Random";
import { HashSet$1 } from "./HashSet$1";
import { GeometryUtil } from "./GeometryUtil";
import { truncate, isNaN_ } from "./number";
/**
* @hidden
*/
var LabelCollisionManager = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(LabelCollisionManager, _super);
function LabelCollisionManager(a, b, c, d, e, f, g, h, i, j, k) {
var _this = _super.call(this) || this;
_this.l = false;
_this.a = new Array(8);
_this.y = null;
_this.labelsMoved = null;
_this.j = null;
_this.h = null;
_this.g = 0;
_this.e = null;
_this.x = null;
_this.ad = 0;
_this.ak = 0;
_this.aj = 0;
_this.a5 = null;
_this.ae = 0;
_this.ac = 0;
_this.v = new LinkedList$1(LabelCollisionInfo.$);
_this.ag = 0;
_this.w = new List$1(LabelCollisionInfo.$, 0);
_this.n = false;
_this.m = false;
_this.ai = 0;
_this.af = 0;
_this.z = 0;
_this.aa = 0;
_this.ah = 0;
_this.o = false;
_this.k = false;
_this.b = null;
_this.ap = null;
_this.an = null;
_this.l = k != null;
_this.a5 = c;
_this.ae = a;
_this.ac = b;
_this.h = new QuadTree(a, b, 8, 8);
_this.g = f;
_this.e = d;
_this.x = new List$1(LabelCollisionPlacementPositions_$type, 0);
_this.x.add(0);
_this.x.add(5);
_this.x.add(7);
_this.x.add(2);
_this.x.add(3);
_this.x.add(6);
_this.x.add(1);
_this.x.add(4);
var l = 0;
for (var m = 0; m < g.length; m++) {
if (_this.x.contains(g[m])) {
_this.x.remove(g[m]);
_this.x.insert(l, g[m]);
l++;
}
}
if (k != null) {
_this.y = new List$1(LabelCollisionPlacementPositions_$type, 0);
for (var n = 0; n < _this.a.length; n++) {
_this.a[n] = false;
}
for (var o = 0; o < k.length; o++) {
_this.a[k[o]] = true;
_this.y.add(k[o]);
}
_this.b = k;
}
else {
_this.y = new List$1(LabelCollisionPlacementPositions_$type, 0);
_this.y.add(0);
_this.y.add(5);
_this.y.add(7);
_this.y.add(2);
_this.y.add(3);
_this.y.add(6);
_this.y.add(1);
_this.y.add(4);
var p = 0;
for (var q = 0; q < g.length; q++) {
if (_this.y.contains(g[q])) {
_this.y.remove(g[q]);
_this.y.insert(p, g[q]);
p++;
}
}
}
_this.ad = e;
_this.ak = h;
_this.aj = i;
_this.k = j;
return _this;
}
LabelCollisionManager.prototype.i = function (a, b, c, d, e) {
var f = 0;
var g = 0;
switch (b) {
case 0:
f = a.o;
g = (((a.p - a.m) - a.k) - this.ad - d);
break;
case 4:
f = (((a.o - a.n) - a.l) - this.ad) - c;
g = (((a.p - a.m) - a.k) - this.ad) - d;
break;
case 5:
f = (((a.o + a.n) + a.l) + this.ad) + c;
g = (((a.p - a.m) - a.k) - this.ad) - d;
break;
case 1:
f = (((a.o - a.n) - a.l) - this.ad) - c;
g = a.p;
break;
case 2:
f = (((a.o + a.n) + a.l) + this.ad) + c;
g = a.p;
break;
case 3:
f = a.o;
g = (((a.p + a.m) + a.k) + this.ad) + d;
break;
case 6:
f = (((a.o - a.n) - a.l) - this.ad) - c;
g = (((a.p + a.m) + a.k) + this.ad) + d;
break;
case 7:
f = (((a.o + a.n) + a.l) + this.ad) + c;
g = (((a.p + a.m) + a.k) + this.ad) - d;
break;
}
var h = new QuadTreeBoundingBox();
h.b = f;
h.c = g;
h.e = a.l;
h.d = a.k;
h.g = a;
if (this.s(h) && !e) {
return null;
}
return h;
};
LabelCollisionManager.prototype.s = function (a) {
var b = a.b - a.e;
var c = a.b + a.e;
var d = a.c - a.d;
var e = a.c + a.d;
var f = this.a5;
if (b < f.left || c > f.right || d < f.top || e > f.bottom) {
return true;
}
return false;
};
LabelCollisionManager.prototype.ax = function (a, b, c, d, e) {
this.aw(a, b, c, d, e);
};
LabelCollisionManager.prototype.aw = function (a, b, c, d, e) {
this.h.d(a);
a.b = b;
a.c = c;
a.e = d;
a.d = e;
this.h.c(a);
};
LabelCollisionManager.prototype.a1 = function (a) {
this.h.d(a);
};
LabelCollisionManager.prototype.aq = function (a) {
this.ag++;
this.v.f(a);
a.e = this.v.d;
if (a.c == null) {
a.c = new QuadTreeBoundingBox();
a.c.b = a.o;
a.c.c = a.p;
a.c.e = a.n;
a.c.d = a.m;
a.c.g = a;
this.h.c(a.c);
}
};
LabelCollisionManager.prototype.a2 = function (a) {
if (a.c != null) {
this.h.d(a.c);
a.c = null;
}
if (a.b != null) {
this.h.d(a.b);
a.b = null;
}
if (a.e != null) {
this.v.h(a.e);
a.e = null;
}
this.ag--;
};
LabelCollisionManager.prototype.az = function (a) {
if (a.c != null && a.c.b == a.o && a.c.c == a.p) {
return;
}
if (a.c != null) {
this.h.d(a.c);
}
var b = NaN;
var c = NaN;
if (a.c == null) {
a.c = new QuadTreeBoundingBox();
a.c.g = a;
}
else {
if (a.b != null) {
b = a.b.b - a.c.b;
c = a.b.c - a.c.c;
}
}
a.c.b = a.o;
a.c.c = a.p;
a.c.e = a.n;
a.c.d = a.m;
this.h.c(a.c);
if (a.b != null) {
this.h.d(a.b);
if (!isNaN_(b)) {
a.b = new QuadTreeBoundingBox();
a.b.b = a.c.b + b;
a.b.c = a.c.c + c;
a.b.g = a;
a.b.e = a.l;
a.b.d = a.k;
a.g = a.b.b;
a.h = a.b.c;
this.h.c(a.b);
}
else {
a.b = this.i(a, a.a, 0, 0, true);
a.g = a.b.b;
a.h = a.b.c;
this.h.c(a.b);
}
}
};
LabelCollisionManager.prototype.ay = function (a) {
this.h.d(a.b);
a.b.b = a.g;
a.b.c = a.h;
a.b.e = a.l;
a.b.d = a.k;
this.h.c(a.b);
};
LabelCollisionManager.prototype.a4 = function () {
this.m = false;
{
var a = this.v.c;
while (a != null) {
if (a.c.b != null) {
this.h.d(a.c.b);
a.c.b = null;
if (a.c.f != null) {
a.c.f.clear();
}
}
a = a.a;
}
this.ah = 0;
}
this.af = 0;
this.z = 0.4;
this.aa = 0.4;
var b = truncate(Math.ceil((this.aj / 150) * this.ak));
this.ai = b;
this.at();
};
LabelCollisionManager.prototype.as = function () {
this.w.clear();
};
LabelCollisionManager.prototype.ar = function () {
this.m = true;
};
LabelCollisionManager.prototype.av = function () {
this.n = false;
if (this.m) {
return;
}
this.at();
};
LabelCollisionManager.prototype.at = function () {
this.w.clear();
this.a0(false);
if (this.g == 0) {
for (var a = 0; a < this.ak; a++) {
this.aa = this.z * (this.ai - this.af) / this.ai;
this.au();
this.af++;
if (this.af > this.ai) {
if (this.j != null) {
this.j();
}
return;
}
}
if (this.labelsMoved != null) {
this.labelsMoved(this.w);
}
if (this.ah > 0) {
if (!this.n) {
this.n = true;
this.e.executeDelayed(runOn(this, this.av), 150);
}
}
else {
if (this.j != null) {
this.j();
}
}
}
else {
if (this.g == 2) {
var b = this.v.c;
this.h.k();
while (b != null) {
var c = b.c;
if (c.b != null) {
this.h.d(c.b);
c.b = null;
c.d = false;
c.f = null;
}
b = b.a;
}
this.ah = 0;
this.a0(true);
}
if (this.labelsMoved != null) {
this.labelsMoved(this.w);
}
}
};
LabelCollisionManager.prototype.au = function () {
var a = truncate(Math.round((this.ag - 1) * LabelCollisionManager.ao.nextDouble()));
var b = 0;
var c = this.v.c;
var d = this.ab(null);
var e = 30;
var f = 60;
while (c != null) {
var g = c.c;
var h = 0;
var i = 0;
if (this.k) {
h = LabelCollisionManager.ao.nextDouble() * g.l * 2;
i = LabelCollisionManager.ao.nextDouble() * g.k * 2;
}
if (b == a) {
var j = truncate(Math.round((this.y.count - 1) * LabelCollisionManager.ao.nextDouble()));
while (this.y._inner[j] == g.a) {
j = truncate(Math.round((this.y.count - 1) * LabelCollisionManager.ao.nextDouble()));
}
var k = g.b;
var l = this.i(g, this.y._inner[j], h, i, false);
var m = 0;
while (l == null) {
if (m >= e) {
h = 0;
i = 0;
}
if (m >= f) {
break;
}
j = truncate(Math.round((this.y.count - 1) * LabelCollisionManager.ao.nextDouble()));
l = this.i(g, this.y._inner[j], h, i, false);
m++;
}
g.b = l;
if (k != null) {
this.h.d(k);
}
if (l != null) {
this.h.c(l);
var n = this.ab(g);
var o = d > n;
if (!o) {
var p = Math.exp(-(n - d) / this.aa);
if (LabelCollisionManager.ao.nextDouble() < p) {
o = true;
}
}
if (!o && k != null) {
this.h.d(l);
this.h.c(k);
g.b = k;
if (!this.o) {
this.ab(g);
}
}
else {
g.a = this.y._inner[j];
g.g = g.b.b;
g.h = g.b.c;
this.w.add(g);
}
}
else {
if (!this.o) {
this.ab(g);
}
g.d = false;
this.w.add(g);
}
break;
}
b++;
c = c.a;
}
};
LabelCollisionManager.prototype.ab = function (a) {
if (this.o) {
var b = 0;
var c = this.v.c;
while (c != null) {
var d = c.c;
var e = d.d;
d.d = false;
if (d.b != null) {
var f = this.h.e(d.b);
for (var g = 0; g < f.count; g++) {
var h = f._inner[g].l.c;
while (h != null) {
var i = h.c;
if (i.g == d) {
h = h.a;
continue;
}
if (d.b.a(i)) {
d.d = true;
b += d.b.f(i);
}
h = h.a;
}
}
if (d.d != e) {
this.w.add(d);
}
}
c = c.a;
}
return b;
}
else {
if (a != null) {
var j = new HashSet$1(LabelCollisionInfo.$, 0);
var k = new HashSet$1(LabelCollisionInfo.$, 0);
var l = new HashSet$1(LabelCollisionInfo.$, 0);
var m = new List$1(LabelCollisionInfo.$, 0);
if (a.f != null) {
for (var n = 0; n < a.f.count; n++) {
j.add_1(a.f._inner[n]);
k.add_1(a.f._inner[n]);
}
}
var o = a.d;
a.d = false;
if (a.b != null) {
var p = this.h.e(a.b);
for (var q = 0; q < p.count; q++) {
var r = p._inner[q].l.c;
while (r != null) {
var s = r.c;
if (s.g == a) {
r = r.a;
continue;
}
if (a.b.a(s) && !l.contains(s.g)) {
a.d = true;
l.add_1(s.g);
m.add(s.g);
}
r = r.a;
}
}
p = this.h.e(a.c);
for (var t = 0; t < p.count; t++) {
var u = p._inner[t].l.c;
while (u != null) {
var v = u.c;
if (v.g == a) {
u = u.a;
continue;
}
if (this.p(a.c, v)) {
u = u.a;
continue;
}
if (a.c.a(v) && !l.contains(v.g)) {
a.d = true;
l.add_1(v.g);
m.add(v.g);
}
u = u.a;
}
}
if (a.d != o) {
this.w.add(a);
}
if (a.f != null) {
for (var w = a.f.count - 1; w >= 0; w--) {
if (!l.contains(a.f._inner[w])) {
var x = a.f._inner[w];
var y = x.f.remove(a);
a.f.removeAt(w);
if (x.f.count == 0 && y) {
this.ah--;
}
var z = j.remove(x);
if (j.count == 0 && z) {
this.ah--;
}
}
}
}
for (var aa = 0; aa < m.count; aa++) {
var ab = m._inner[aa];
if (!j.contains(ab)) {
if (a.f == null) {
a.f = new List$1(LabelCollisionInfo.$, 0);
}
a.f.add(ab);
if (j.count == 0) {
this.ah++;
}
j.add_1(ab);
if (ab.f == null) {
ab.f = new List$1(LabelCollisionInfo.$, 0);
}
if (ab.f.count == 0) {
this.ah++;
}
ab.f.add(a);
}
}
}
}
return this.ah;
}
};
LabelCollisionManager.prototype.p = function (a, b) {
if (a.g.c == a && b.g.c == b) {
return true;
}
return false;
};
Object.defineProperty(LabelCollisionManager.prototype, "al", {
get: function () {
return this.ah;
},
enumerable: false,
configurable: true
});
LabelCollisionManager.prototype.a3 = function (a, b, c) {
this.a5 = c;
var d = new QuadTree(a, b, this.h.i, this.h.f);
var e = this.v.c;
while (e != null) {
d.c(e.c.c);
if (e.c.b != null) {
d.c(e.c.b);
}
e = e.a;
}
this.h = d;
this.ae = a;
this.ac = b;
};
LabelCollisionManager.prototype.u = function () {
var a = this.v.c;
while (a != null) {
a.c.d = false;
if (a.c.b != null) {
if (this.s(a.c.b)) {
return true;
}
}
a = a.a;
}
return false;
};
LabelCollisionManager.prototype.q = function () {
var a = this.v.c;
var b = this.y;
while (a != null) {
if (a.c.b != null) {
if (this.s(a.c.b)) {
var c = a.c;
for (var d = 0; d < b.count; d++) {
var e = this.i(c, b._inner[d], 0, 0, false);
if (e != null) {
return true;
}
}
}
}
a = a.a;
}
return false;
};
LabelCollisionManager.prototype.am = function () {
var a = this.v.c;
while (a != null) {
a.c.d = false;
a = a.a;
}
a = this.v.c;
while (a != null) {
var b = a.c.b;
var c = a.c.c;
var d = this.h.e(c);
for (var e = 0; e < d.count; e++) {
var f = d._inner[e].l.c;
while (f != null) {
var g = f.c;
if (this.p(c, g)) {
f = f.a;
continue;
}
if (c.a(g)) {
var h = f.c.g;
if (h != a.c) {
h.d = true;
a.c.d = true;
}
}
f = f.a;
}
}
if (b == null) {
return -1;
}
d = this.h.e(b);
for (var i = 0; i < d.count; i++) {
var j = d._inner[i].l.c;
while (j != null) {
var k = j.c;
if (b.a(k)) {
var l = j.c.g;
if (l != a.c) {
l.d = true;
a.c.d = true;
}
}
j = j.a;
}
}
a = a.a;
}
var m = 0;
a = this.v.c;
while (a != null) {
if (a.c.d) {
m++;
}
a = a.a;
}
return m;
};
LabelCollisionManager.prototype.a0 = function (a) {
var b = this.v.c;
while (b != null) {
var c = b.c;
if (c.b == null || a) {
var d = false;
if (a) {
var e = this.h.a(c.o, c.p, 1.5);
var f = this.c(e);
if (f != null) {
for (var g = 0; g < f.length; g++) {
var h = f[g];
var i = this.i(c, h, 0, 0, false);
if (i == null) {
continue;
}
var j = this.h.e(i);
d = true;
for (var k = 0; k < j.count; k++) {
var l = j._inner[k].l.c;
while (l != null) {
var m = l.c;
if (i.a(m)) {
d = false;
break;
}
l = l.a;
}
}
if (d) {
c.b = i;
c.a = h;
c.g = c.b.b;
c.h = c.b.c;
this.h.c(c.b);
this.w.add(c);
break;
}
}
}
}
if (!d) {
d = this.t(c, false);
}
if (!d) {
if (c.b == null) {
this.t(c, true);
}
}
}
b = b.a;
}
};
LabelCollisionManager.prototype.t = function (a, b) {
var c = this.y;
var d = false;
if (!d) {
for (var e = 0; e < c.count; e++) {
var f = this.i(a, c._inner[e], 0, 0, b);
if (f == null) {
continue;
}
d = !this.r(f, a);
var g = a.c;
if (g == null) {
g = new QuadTreeBoundingBox();
g.g = a;
g.b = a.o;
g.c = a.p;
g.e = a.n;
g.d = a.m;
this.h.c(g);
a.c = g;
}
var h = this.r(g, a);
d = d && !h;
if (d) {
a.b = f;
a.a = c._inner[e];
a.g = a.b.b;
a.h = a.b.c;
this.h.c(a.b);
this.w.add(a);
break;
}
}
}
if (!d) {
var i = Number.POSITIVE_INFINITY;
var j = 0;
var k = null;
for (var l = 0; l < c.count; l++) {
var m = 0;
var n = null;
var o = new HashSet$1(LabelCollisionInfo.$, 0);
if (!this.o) {
n = new List$1(LabelCollisionInfo.$, 0);
}
var p = this.i(a, c._inner[l], 0, 0, b);
if (p == null) {
continue;
}
var q = this.h.e(p);
for (var r = 0; r < q.count; r++) {
var s = q._inner[r].l.c;
while (s != null) {
var t = s.c;
if (p.a(t)) {
m += p.f(t);
if (!this.o) {
if (!o.contains(t.g)) {
n.add(t.g);
o.add_1(t.g);
}
}
}
s = s.a;
}
}
var u = a.c;
if (u == null) {
u = new QuadTreeBoundingBox();
u.g = a;
u.b = a.o;
u.c = a.p;
u.e = a.n;
u.d = a.m;
}
q = this.h.e(u);
for (var v = 0; v < q.count; v++) {
var w = q._inner[v].l.c;
while (w != null) {
var x = w.c;
if (w.c.g == a) {
w = w.a;
continue;
}
if (this.p(u, x)) {
w = w.a;
continue;
}
if (u.a(x)) {
if (!this.o) {
if (!o.contains(x.g)) {
n.add(x.g);
o.add_1(x.g);
}
}
}
w = w.a;
}
}
if (m < i) {
var y = this.i(a, c._inner[l], 0, 0, b);
if (y != null) {
i = m;
j = l;
if (!this.o) {
k = n;
}
}
}
}
var z = this.i(a, c._inner[j], 0, 0, b);
a.d = true;
if (!this.o) {
if (a.f != null && a.f.count > 0) {
this.ah--;
for (var aa = a.f.count - 1; aa >= 0; aa--) {
var ab = a.f._inner[aa];
if (ab.f != null) {
ab.f.remove(a);
if (ab.f.count == 0) {
this.ah--;
}
}
}
}
if (k == null) {
a.d = false;
this.w.add(a);
return false;
}
a.f = k;
if (k.count > 0) {
this.ah++;
}
for (var ac = 0; ac < k.count; ac++) {
var ad = k._inner[ac];
if (ad.f == null) {
ad.f = new List$1(LabelCollisionInfo.$, 0);
}
if (!ad.f.contains(a)) {
if (ad.f.count == 0) {
this.ah++;
}
ad.f.add(a);
}
}
}
a.b = z;
a.a = c._inner[j];
a.g = a.b.b;
a.h = a.b.c;
this.h.c(a.b);
this.w.add(a);
}
return d;
};
LabelCollisionManager.prototype.r = function (a, b) {
var c = false;
var d = this.h.e(a);
for (var e = 0; e < d.count; e++) {
var f = d._inner[e].l.c;
while (f != null) {
if (f.c.g == b) {
f = f.a;
continue;
}
var g = f.c;
if (this.p(a, g)) {
f = f.a;
continue;
}
if (a.a(g)) {
c = true;
break;
}
f = f.a;
}
}
return c;
};
LabelCollisionManager.prototype.c = function (a) {
var b = new Array(3);
var c = GeometryUtil.f({ $type: Point_$type, x: 0, y: 0 }, { $type: Point_$type, x: a.a, y: a.b });
c = c * 180 / Math.PI;
c = GeometryUtil.i(c);
if ((c >= 0 && c <= 22.5) || (c >= 337.5 && c <= 360)) {
b[0] = 2;
b[1] = 5;
b[2] = 7;
}
if (c >= 22.5 && c <= 67.5) {
b[0] = 2;
b[1] = 7;
b[2] = 3;
}
if (c >= 67.5 && c <= 112.5) {
b[0] = 7;
b[1] = 3;
b[2] = 6;
}
if (c >= 112.5 && c <= 157.5) {
b[0] = 3;
b[1] = 6;
b[2] = 1;
}
if (c >= 157.5 && c <= 202.5) {
b[0] = 6;
b[1] = 1;
b[2] = 4;
}
if (c >= 202.5 && c <= 247.5) {
b[0] = 1;
b[1] = 4;
b[2] = 0;
}
if (c >= 247.5 && c <= 292.5) {
b[0] = 4;
b[1] = 0;
b[2] = 5;
}
if (c >= 292.5 && c <= 337.5) {
b[0] = 0;
b[1] = 5;
b[2] = 2;
}
if (this.l) {
var d = 0;
for (var e = 0; e < b.length; e++) {
if (this.a[b[e]]) {
d++;
}
}
if (d == 0) {
return null;
}
var f = 0;
var g = new Array(d);
for (var h = 0; h < b.length; h++) {
if (this.a[b[h]]) {
g[f] = b[h];
f++;
}
}
b = g;
}
return b;
};
LabelCollisionManager.prototype.f = function (a, b) {
var c = false;
var d = null;
var e = new QuadTreeBoundingBox();
e.b = a.x;
e.c = a.y;
e.e = 5;
e.d = 5;
var f = this.h.e(e);
for (var g = 0; g < f.count; g++) {
var h = f._inner[g].l.c;
while (h != null) {
var i = h.c;
if (i.g.c == i) {
h = h.a;
continue;
}
if (e.a(i)) {
d = i;
c = true;
break;
}
h = h.a;
}
}
if (c) {
return d.g;
}
else {
return null;
}
};
LabelCollisionManager.$t = markType(LabelCollisionManager, 'LabelCollisionManager');
LabelCollisionManager.ao = new Random(0);
return LabelCollisionManager;
}(Base));
export { LabelCollisionManager };