igniteui-angular-charts
Version:
Ignite UI Angular charting components for building rich data visualizations for modern web apps.
775 lines (774 loc) • 27.9 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 { CategoryAxisBase } from "./CategoryAxisBase";
import { IZoomableCategoryAxis_$type } from "./IZoomableCategoryAxis";
import { Base, Number_$type, typeCast, Array_$type, markType, markDep, TypeRegistrar } from "igniteui-angular-core";
import { DependencyProperty } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { HorizontalAxisLabelPanel } from "./HorizontalAxisLabelPanel";
import { Rect } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { NumericScaler } from "./NumericScaler";
import { LinearCategorySnapper } from "./LinearCategorySnapper";
import { NumericYAxis } from "./NumericYAxis";
import { LabelPosition } from "./LabelPosition";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { MathUtil } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-core";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
import { AxisDefaults } from "./AxisDefaults";
/**
* @hidden
*/
var CategoryXAxis = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(CategoryXAxis, _super);
function CategoryXAxis() {
var _this = _super.call(this) || this;
_this.mz = 1;
_this.my = 1;
_this.m2 = null;
_this.mp = 0;
_this.mq = 0;
_this.k2 = new List$1(Number_$type, 0);
_this.ab = CategoryXAxis.$;
return _this;
}
CategoryXAxis.prototype.a4 = function () {
return new CategoryXAxisView(this);
};
CategoryXAxis.prototype.hv = function (a) {
_super.prototype.hv.call(this, a);
this.mm = a;
};
Object.defineProperty(CategoryXAxis.prototype, "m1", {
get: function () {
return this.mz;
},
set: function (a) {
this.mz = a;
},
enumerable: false,
configurable: true
});
Object.defineProperty(CategoryXAxis.prototype, "m0", {
get: function () {
return this.my;
},
set: function (a) {
this.my = a;
},
enumerable: false,
configurable: true
});
CategoryXAxis.prototype.av = function () {
if (this.c6) {
return (TypeRegistrar.create('HorizontalSmartAxisLabelPanel'));
}
else {
return new HorizontalAxisLabelPanel();
}
};
CategoryXAxis.prototype.getCategorySize = function (a, b, c) {
var d = this.kf(b, c);
return d.width / (this.lj * a.width);
};
CategoryXAxis.prototype.k8 = function (a, b, c) {
var d = this.lf(a, b, c);
var e = 0;
if (!isNaN_(this.le)) {
e = Math.min(this.le, 1);
}
else {
e = 0;
}
;
var f = 1 - 0.5 * d;
var g = this.ll == 0 ? 1 : this.ll;
var h = this.getCategorySize(a, b, c) * f / (g - (g - 1) * e);
return h;
};
CategoryXAxis.prototype.getGroupCenter = function (a, b, c, d) {
var e = 0.5;
if (this.ll > 1) {
var f = this.lf(b, c, d);
var g = 0;
if (!isNaN_(this.le)) {
g = Math.min(this.le, 1);
}
var h = 1 - 0.5 * f;
var i = h / (this.ll - (this.ll - 1) * g);
var j = (h - i) / (this.ll - 1);
e = 0.25 * f + 0.5 * i + a * j;
}
return this.getCategorySize(b, c, d) * e;
};
CategoryXAxis.prototype.d6 = function () {
return this.mw;
};
CategoryXAxis.prototype.nc = function (a) {
var b = this.bi != null ? this.bi.v4 : Rect.empty;
b = b.copy();
var c = this.kh;
var d = this.ke();
var e = new Rect(0, 0, 0, 1, 1);
var f = new ScalerParams(0, e, e, this.ch, d);
var g = !b.isEmpty && !c.isEmpty && this.kv != null ? this.kv.indexOf(a) : -1;
var h = g > -1 ? this.el(g, f) : NaN;
if (!isNaN_(h) && this.bi.fg) {
if (!isNaN_(h)) {
if (h < b.left + 0.1 * b.width) {
h = h + 0.4 * b.width;
b.x = h - 0.5 * b.width;
}
if (h > b.right - 0.1 * b.width) {
h = h - 0.4 * b.width;
b.x = h - 0.5 * b.width;
}
}
this.bi.ry(b, false, true);
}
};
CategoryXAxis.prototype.el = function (a, b) {
if (!b.c.isEmpty) {
var c = this.mv(a, NumericScaler.ac, b.c, this.categoryMode);
c = (c - b.d.left) / b.d.width;
c = b.d.left + b.d.width * (c - b.e.left) / b.e.width;
return c;
}
return this.mv(a, b.e, b.d, this.categoryMode);
};
CategoryXAxis.prototype.ml = function (a) {
if (typeCast(List$1.$.specialize(Array_$type), a) !== null) {
return a.asArray();
}
return null;
};
CategoryXAxis.prototype.hp = function (a, b, c, d, e) {
var f;
var g = e.e;
var h = e.d;
var i = e.c;
var j = e.a;
var k = !i.isEmpty;
var l = this.categoryMode == 0 ? this.lj - 1 : this.lj;
if (l < 0) {
l = 0;
}
var m = i.left;
var n = i.width;
var o = g.left;
var p = g.width;
var q = h.left;
var r = h.width;
var s = 0;
var t = 1;
var u = this.ml(a);
var v = false;
if (u != null) {
v = true;
}
var w;
for (var x = 0; x < b.count; x++) {
w = b.item(x);
for (var y = c; y < d; y++) {
if (v) {
f = u[y];
}
else {
f = a.item(y);
}
if (k) {
var z = l >= 1 ? (f[w]) / (l) : l == 0 ? 0.5 : NaN;
if (j) {
z = 1 - z;
}
z = m + n * (z - s) / t;
z = (z - q) / r;
var aa = q + r * (z - o) / p;
f[w] = aa;
}
else {
var ab = l >= 1 ? (f[w]) / (l) : l == 0 ? 0.5 : NaN;
if (j) {
ab = 1 - ab;
}
ab = q + r * (ab - o) / p;
f[w] = ab;
}
}
}
};
CategoryXAxis.prototype.em = function (a, b, c) {
if (!b.c.isEmpty) {
var d = this.mv(a, NumericScaler.ac, b.c, c);
d = (d - b.d.left) / b.d.width;
d = b.d.left + b.d.width * (d - b.e.left) / b.e.width;
return d;
}
return this.mv(a, b.e, b.d, c);
};
CategoryXAxis.prototype.mv = function (a, b, c, d) {
var e = d == 0 ? this.lj - 1 : this.lj;
if (e < 0) {
e = 0;
}
var f = e >= 1 ? (a) / (e) : e == 0 ? 0.5 : NaN;
if (this.ci) {
f = 1 - f;
}
return c.left + c.width * (f - b.left) / b.width;
};
CategoryXAxis.prototype.eo = function (a, b) {
if (!b.c.isEmpty) {
var c = b.e.left + b.e.width * (a - b.d.left) / b.d.width;
c = (c * b.d.width) + b.d.left;
c = this.getUnscaledValue3(c, NumericScaler.ac, b.c, this.categoryMode);
return c;
}
return this.getUnscaledValue3(a, b.e, b.d, this.categoryMode);
};
CategoryXAxis.prototype.ep = function (a, b, c) {
if (!b.c.isEmpty) {
var d = b.e.left + b.e.width * (a - b.d.left) / b.d.width;
d = (d * b.d.width) + b.d.left;
d = this.getUnscaledValue3(d, NumericScaler.ac, b.c, c);
return d;
}
return this.getUnscaledValue3(a, b.e, b.d, c);
};
CategoryXAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
var e = b.left + (a - c.left) * b.width / c.width;
if (this.ci) {
e = 1 - e;
}
var f = d == 0 ? this.lj - 1 : this.lj;
if (f < 0) {
f = 0;
}
return e * f;
};
CategoryXAxis.prototype.nd = function (a, b) {
if (isNaN_(a) || isNaN_(b) || this.kv == null || this.kv.count == 0) {
return;
}
var c = a / this.kv.count;
var d = (b + 1) / this.kv.count;
this.bi.wl = new Rect(0, c, this.bi.wl.y, d - c, this.bi.wl.height);
};
CategoryXAxis.prototype.ic = function (a) {
_super.prototype.ic.call(this, a);
var b = this.bi != null ? this.bi.v4 : Rect.empty;
var c = this.kh;
var d = this.kc();
var e = this.kb();
var f = new ScalerParams(0, b, c, this.ch, d);
var g = this.a5.a4();
var h = this.a5.a7();
var i = this.a5.a5();
var j = this.a5.a6();
var k = this.a5.e();
var l = this.a5.f();
var m = this.a5.g();
var n = this.kv;
var o = this.mn();
this.ip();
this.hk(g);
this.hk(h);
this.hk(i);
this.hk(j);
this.dd.clear();
this.de.clear();
this.k2.clear();
this.a5.az(this, b, c);
if (b.isEmpty || c.isEmpty) {
this.br.count = 0;
this.bq.count = 0;
this.bp.count = 0;
}
if (this.br.count == 0 && this.bq.count == 0 && this.a5.l()) {
this.a5.ad();
}
if (this.az != null) {
this.az.registerAxis(this);
}
if (this.itemsSource == null || o == null || n.count == 0) {
this.br.count = 0;
this.bq.count = 0;
this.bp.count = 0;
this.a5.ad();
return;
}
if (!b.isEmpty && !c.isEmpty) {
var p = this.eo(e.left, f);
var q = this.eo(e.right, f);
var r = 0;
var s = false;
if (this.c4) {
var t = Math.abs(q - p);
r = Math.ceil(t) + 1;
if (this.ch) {
if (Math.abs(q - Math.floor(q)) < Math.abs(p - Math.ceil(p))) {
s = true;
}
}
else {
if (Math.abs(q - Math.ceil(q)) < Math.abs(p - Math.floor(p))) {
s = true;
}
}
}
if (this.ch) {
p = Math.ceil(p);
q = Math.floor(q);
}
else {
p = Math.floor(p);
q = Math.ceil(q);
}
if (this.c4) {
if (Math.abs(q - p) < r) {
if (this.ch) {
if (s) {
q--;
}
else {
p++;
}
}
else {
if (s) {
q++;
}
else {
p--;
}
}
}
}
var u = c.bottom;
var v = u - c.top;
if (this.aj != null) {
var w = typeCast(NumericYAxis.$, this.aj);
if (w != null) {
var x = this.ii(u, v, b, c, d, c.top, c.bottom);
u = x.p0;
v = x.p1;
}
}
this.ht(g, u, c, k, true);
this.a5.au(v);
var y = Math.min(p, q);
var z = Math.max(p, q);
var aa = e.width;
if (this.c4) {
var ab = this.el(y, f);
var ac = this.el(z, f);
if (ab != ac) {
aa = Math.abs(ac - ab);
}
}
var ad = new LinearCategorySnapper(1, y, z, aa, this.mw, this.categoryMode, this.e0());
var ae = ad.g;
ae = this.d3(ae, this.mo(), b, c, d);
if (ad.g != ae) {
ad = new LinearCategorySnapper(1, y, z, aa, ae, this.categoryMode, this.e0());
}
var af = Math.floor((y - 0) / ad.g);
var ag = Math.ceil((z - 0) / ad.g);
this.mr = ad.g;
if (!isNaN_(af) && !isNaN_(ag)) {
var ah = truncate(af);
var ai = truncate(ag);
var aj = this.mu(0 + ah * ad.g, f);
var ak = this.el(ad.g, f);
var al = Math.abs(ak - this.el(0, f));
this.a5.av(ak);
var am = truncate(Math.ceil(e.right));
var an = truncate(Math.floor(e.left));
var ao = this.mx;
var ap = ao > 0 && ao < ad.g;
var aq = c.right;
var ar = this.k2;
var as = ad.g;
var at = truncate(as);
var au = this.ll;
var av = this.ch;
var aw = this.categoryMode;
this.m2 = null;
for (var ax = ah; ax <= ai; ++ax) {
var ay = this.mu(0 + (ax + 1) * ad.g, f);
if (aj <= aq) {
if (ax % 2 == 0) {
this.ir(h, aj, ay, c);
}
this.iq(i, aj, c, l, false);
ar.add(aj);
}
if (this.categoryMode != 0 && this.ll != 0 && this.cy) {
if (ap) {
var az = al * this.mx;
if (this.ch) {
var a0 = aj;
while (a0 - az > ay) {
a0 -= az;
if (Math.abs(a0 - ay) < 0.0001) {
break;
}
this.iq(j, a0, c, m, false);
}
}
else {
var a1 = aj;
while (a1 + az < ay) {
a1 += az;
if (Math.abs(a1 - ay) < 0.0001) {
break;
}
this.iq(j, a1, c, m, false);
}
}
this.ms = this.mx;
}
else {
for (var a2 = 0; a2 < truncate(ad.g); a2++) {
for (var a3 = 0; a3 < this.ll; a3++) {
var a4 = this.getGroupCenter(a3, b, c, d);
if (this.ch) {
a4 = -a4;
}
var a5 = this.el(a2 + ax * ad.g, f) + a4;
this.iq(j, a5, c, m, false);
}
}
this.ms = 0.5;
}
}
var a6 = this.mt(ax * as, aj, aw == 0, f);
var a7 = truncate(Math.round(a6));
if (a7 >= an && a7 <= am) {
var a8 = 0;
if (as >= 1) {
a8 = ax * truncate(Math.floor(as));
}
else {
if ((ax * as) * 2 % 2 == 0) {
a8 = truncate(Math.floor(ax * as));
}
else {
a8 = -1;
}
}
if (o != null && a8 < n.count && a8 >= 0) {
var a9 = o.getItem(a8);
var ba = this.f1(a9);
this.m2 = a9;
if (!isNaN_(a6) && !isInfinity(a6) && ba != null) {
if ((typeof ba === 'string') && Base.equalsStatic(ba, "")) {
}
else {
this.dd.add1(ba);
this.de.add(new LabelPosition(a6));
}
}
}
}
aj = ay;
}
}
this.m2 = null;
if ((this.az == null || this.az.visibility == 0) && this.aj != null) {
if (this.az != null && (this.az.location == 4 || this.az.location == 5)) {
this.bi.n3();
}
}
this.a5.a0(this.dd, this.de);
this.l9();
}
};
CategoryXAxis.prototype.c3 = function () {
if (this.cq && this.c4) {
this.bc = this.bb();
}
if (this.kv == null) {
return false;
}
var a = false;
var b = this.kv.count;
if (b != this.m0) {
var c = new AxisRangeChangedEventArgs(0, 1, 1, this.m0, b);
this.m0 = b;
this.h6(c);
a = true;
}
this.nf();
this.ne();
return a;
};
CategoryXAxis.prototype.getWindowZoomFromCategories = function (a) {
var b = MathUtil.a(a) && a > 0;
var c = this.kv.count;
if (c > 0 && b) {
var d = this.bi.wk.width;
var e = isNaN_(d) || isInfinity(d);
if (e) {
return NaN;
}
var f = new Rect(0, 0, 0, 1, 1);
var g = this.bi.wk;
var h = this.getCategorySize(f, g, g);
var i = isNaN_(h) || isInfinity(h);
if (i) {
return NaN;
}
var j = h * a / d;
if (j >= 0 && j <= 1) {
return j;
}
}
return NaN;
};
CategoryXAxis.prototype.getWindowZoomFromItemSpan = function (a) {
var b = MathUtil.a(a) && a > 0;
var c = this.kv.count;
if (c > 0 && b) {
var d = this.bi.wk.width;
var e = isNaN_(d) || isInfinity(d);
if (e) {
return NaN;
}
var f = new Rect(0, 0, 0, 1, 1);
var g = this.bi.wk;
var h = this.k8(f, g, g);
var i = a / h;
var j = Math.min(1, 1 / i);
if (j > 0 && j <= 1) {
return j;
}
}
return NaN;
};
CategoryXAxis.prototype.nf = function () {
if (this.kv == null || this.bi == null) {
return;
}
var a = !isNaN_(this.bi.it) && !isNaN_(this.bi.iv);
if (a) {
return;
}
if (!isNaN_(this.zoomMaximumItemSpan) && !isInfinity(this.zoomMaximumItemSpan)) {
var b = this.getWindowZoomFromItemSpan(this.zoomMaximumItemSpan);
if (!isNaN_(b) && !isInfinity(b)) {
this.bi.hm = b;
}
}
else if (!isNaN_(this.zoomMaximumCategoryRange) && !isInfinity(this.zoomMaximumCategoryRange)) {
var c = this.getWindowZoomFromCategories(this.zoomMaximumCategoryRange);
if (!isNaN_(c) && !isInfinity(c)) {
this.bi.hm = c;
}
}
};
CategoryXAxis.prototype.ne = function () {
if (this.kv == null || this.bi == null) {
return;
}
var a = NaN;
var b = NaN;
var c = this.bi.hs();
var d = this.bi.ht();
var e = false;
if (MathUtil.a(this.zoomToItemSpan) && this.zoomToItemSpan > 0) {
e = true;
c = this.getWindowZoomFromItemSpan(this.zoomToItemSpan);
c = Math.max(c, this.bi.hm);
}
else if (MathUtil.a(this.zoomToCategoryRange) && this.zoomToCategoryRange > 0 && this.zoomToCategoryRange <= this.lk) {
e = true;
c = this.getWindowZoomFromCategories(this.zoomToCategoryRange);
c = Math.max(c, this.bi.hm);
}
if (MathUtil.a(this.zoomToCategoryStart) && this.zoomToCategoryStart >= 0 && this.zoomToCategoryStart < this.lk) {
e = true;
a = this.getWindowZoomFromCategories(this.zoomToCategoryStart);
var f = c + a - 1;
var g = c - f;
if (f > 0 && g > this.bi.hm) {
c = g;
c = Math.max(c, this.bi.hm);
}
}
if (e) {
this.bi.rw(a, b, c, d);
}
};
CategoryXAxis.prototype.hz = function (a, b, c, d) {
_super.prototype.hz.call(this, a, b, c, d);
switch (b) {
case CategoryXAxis.$$p[0]:
case CategoryXAxis.$$p[1]:
this.nf();
break;
case CategoryXAxis.$$p[2]:
case CategoryXAxis.$$p[3]:
case CategoryXAxis.$$p[4]:
this.ne();
break;
}
};
Object.defineProperty(CategoryXAxis.prototype, "mw", {
get: function () {
return this.c(CategoryXAxis.ng);
},
set: function (a) {
this.h(CategoryXAxis.ng, a);
},
enumerable: false,
configurable: true
});
CategoryXAxis.prototype.mo = function () {
return !isNaN_(this.mw);
};
Object.defineProperty(CategoryXAxis.prototype, "mr", {
get: function () {
return this.mp;
},
set: function (a) {
if (this.mr != a) {
var b = this.mp;
this.mp = a;
this.h5("ActualInterval", b, this.mr);
}
},
enumerable: false,
configurable: true
});
CategoryXAxis.prototype.ex = function () {
return this.mr;
};
Object.defineProperty(CategoryXAxis.prototype, "mx", {
get: function () {
return this.c(CategoryXAxis.nh);
},
set: function (a) {
this.h(CategoryXAxis.nh, a);
},
enumerable: false,
configurable: true
});
Object.defineProperty(CategoryXAxis.prototype, "ms", {
get: function () {
return this.mq;
},
set: function (a) {
if (this.ms != a) {
var b = this.mq;
this.mq = a;
this.h5("ActualMinorInterval", b, this.ms);
}
},
enumerable: false,
configurable: true
});
CategoryXAxis.prototype.ky = function (a) {
if (a == null) {
return false;
}
var b = this.be();
if (b == null) {
return false;
}
return b.synchronizeHorizontally;
};
CategoryXAxis.prototype.get_a2 = function () {
return 0;
};
Object.defineProperty(CategoryXAxis.prototype, "a2", {
get: function () {
return this.get_a2();
},
enumerable: false,
configurable: true
});
CategoryXAxis.prototype.mn = function () {
return this.kv;
};
CategoryXAxis.prototype.mu = function (a, b) {
return this.el(a, b);
};
CategoryXAxis.prototype.mt = function (a, b, c, d) {
if (!c) {
var e = this.mu(a + 1, d);
return (b + e) / 2;
}
return b;
};
Object.defineProperty(CategoryXAxis.prototype, "isVertical", {
get: function () {
return this.cp;
},
enumerable: false,
configurable: true
});
CategoryXAxis.prototype.j$d = function (a, b) {
return this.eo.apply(this, arguments);
};
CategoryXAxis.prototype.j$c = function (a, b) {
return this.el.apply(this, arguments);
};
CategoryXAxis.prototype.j$e = function (a, b, c, d, e) {
this.hp.apply(this, arguments);
};
CategoryXAxis.prototype.j$f = function (a, b, c, d) {
this.hq.apply(this, arguments);
};
CategoryXAxis.prototype.j$g = function (a, b, c, d) {
this.hr.apply(this, arguments);
};
Object.defineProperty(CategoryXAxis.prototype, "j$b", {
get: function () {
return this.ch;
},
enumerable: false,
configurable: true
});
CategoryXAxis.prototype.j$a = function () {
return this.ag.apply(this, arguments);
};
CategoryXAxis.$t = markType(CategoryXAxis, 'CategoryXAxis', CategoryAxisBase.$, [IZoomableCategoryAxis_$type]);
CategoryXAxis.ng = DependencyProperty.i("Interval", Number_$type, CategoryXAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
a.h5("Interval", b.oldValue, b.newValue);
a.ib(false);
}));
CategoryXAxis.nh = DependencyProperty.i("MinorInterval", Number_$type, CategoryXAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
(typeCast(CategoryXAxis.$, a)).h5("MinorInterval", b.oldValue, b.newValue);
(typeCast(CategoryXAxis.$, a)).ib(false);
}));
CategoryXAxis.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryXAxis, 'h5', ['ZoomMaximumCategoryRange::ni', [1, NaN], 'ZoomMaximumItemSpan::nj', [1, NaN], 'ZoomToCategoryRange::nk', [1, NaN], 'ZoomToCategoryStart::nl', [1, NaN], 'ZoomToItemSpan::nm', [1, NaN]]);
return CategoryXAxis;
}(CategoryAxisBase));
export { CategoryXAxis };
/**
* @hidden
*/
var CategoryXAxisView = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(CategoryXAxisView, _super);
function CategoryXAxisView(a) {
var _this = _super.call(this, a) || this;
_this.bm = null;
_this.bm = a;
return _this;
}
CategoryXAxisView.prototype.al = function () {
_super.prototype.al.call(this);
this.a.fj = AxisDefaults.f;
};
CategoryXAxisView.$t = markType(CategoryXAxisView, 'CategoryXAxisView', CategoryAxisBaseView.$);
return CategoryXAxisView;
}(CategoryAxisBaseView));
export { CategoryXAxisView };