igniteui-react-charts
Version:
Ignite UI React charting components for building rich data visualizations using TypeScript APIs.
837 lines (836 loc) • 27.8 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, __values } from "tslib";
import { Base, typeCast, runOn, fromEnum, markType, INotifyPropertyChanged_$type, PropertyChangedEventArgs } from "igniteui-react-core";
import { DomWrapper_$type } from "igniteui-react-core";
import { Dictionary$2 } from "igniteui-react-core";
import { RenderingContext } from "igniteui-react-core";
import { LegendItemHelper } from "igniteui-react-core";
import { ContentControl } from "igniteui-react-core";
import { ILegendContext_$type } from "igniteui-react-core";
import { DataTemplatePassInfo } from "igniteui-react-core";
import { DataTemplateMeasureInfo } from "igniteui-react-core";
import { DataTemplateRenderInfo } from "igniteui-react-core";
import { CanvasViewRenderer } from "igniteui-react-core";
import { Size } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { FontUtil } from "igniteui-react-core";
import { isNaN_ } from "igniteui-react-core";
import { IChartLegend_$type } from "igniteui-react-core";
import { ObservableCollection$1 } from "igniteui-react-core";
import { UIElement } from "igniteui-react-core";
import { LegendSizeChangedEventArgs } from "./LegendSizeChangedEventArgs";
import { ILegendSeries_$type } from "igniteui-react-core";
import { PropertyUpdatedEventArgs } from "igniteui-react-core";
import { LegendMouseButtonEventArgs } from "./LegendMouseButtonEventArgs";
import { LegendMouseEventArgs } from "./LegendMouseEventArgs";
import { LegendVisualData } from "./LegendVisualData";
import { MouseButtonEventArgs } from "igniteui-react-core";
import { MouseEventArgs } from "igniteui-react-core";
import { RectData } from "igniteui-react-core";
import { AppearanceHelper } from "igniteui-react-core";
import { LegendItemVisualData } from "./LegendItemVisualData";
import { stringIsNullOrEmpty } from "igniteui-react-core";
/**
* @hidden
*/
var LegendBaseViewManager = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(LegendBaseViewManager, _super);
function LegendBaseViewManager(a) {
var _this = _super.call(this) || this;
_this.a = null;
_this.l = null;
_this.g = null;
_this.d = false;
_this.f = null;
_this.m = null;
_this.c = null;
_this.a = a;
_this.f = new Dictionary$2(Base.$, DomWrapper_$type, 0);
return _this;
}
LegendBaseViewManager.prototype.p = function () {
var a = LegendItemHelper.b;
if (window.devicePixelRatio != undefined && (isNaN_(a) || window.devicePixelRatio != a)) {
LegendItemHelper.b = window.devicePixelRatio;
this.a.am();
}
};
LegendBaseViewManager.prototype.u = function () {
};
LegendBaseViewManager.prototype.s = function () {
this.p();
};
LegendBaseViewManager.prototype.t = function (a) {
if (a == null) {
this.l = null;
this.g = null;
return;
}
this.g = a;
this.l = this.i();
this.l.addClass(this.a.t);
this.g.append(this.l);
};
LegendBaseViewManager.prototype.i = function () {
return this.g.createElement("table");
};
LegendBaseViewManager.prototype.h = function () {
var a = this.g.createElement("tr");
a.addClass(this.a.u);
var b = this.a.l;
if (b) {
a.setStyleProperty("display", "block");
a.setStyleProperty("float", "left");
a.setStyleProperty("margin", "0px");
a.setStyleProperty("margin-right", "8px");
}
return a;
};
LegendBaseViewManager.prototype.j = function (a) {
return this.k(a, this.l);
};
LegendBaseViewManager.prototype.k = function (a, b) {
var c = typeCast(ContentControl.$, a);
var d = this.h();
if (c != null) {
var e = typeCast(ILegendContext_$type, c.content);
if (e != null && c.ah != null) {
var f = new DataTemplatePassInfo();
f.context = d;
f.passID = "LegendItem";
var g = new DataTemplateMeasureInfo();
g.passInfo = f;
g.width = NaN;
g.height = NaN;
g.data = e;
g.context = d;
var h = new DataTemplateRenderInfo();
h.passInfo = f;
if (c.ah.measure != null) {
c.ah.measure(g);
}
h.context = this.g.getSubRenderer(d);
h.availableWidth = g.width;
h.availableHeight = g.height;
h.data = e;
h.xPosition = 0;
h.yPosition = 0;
c.ah.render(h);
var i = d.findByClass(".ui-legend-item-badge");
for (var j = 0; j < i.length; j++) {
i[j].removeClass("ui-legend-item-badge").addClass(this.a.s);
}
i = d.findByClass(".ui-legend-item-text");
for (var k = 0; k < i.length; k++) {
if (this.a.l) {
i[k].setStyleProperty("white-space", "nowrap");
}
i[k].removeClass("ui-legend-item-text").addClass(this.a.v);
}
}
}
return d;
};
LegendBaseViewManager.prototype.o = function (a, b) {
var c = this.k(a, this.l);
c.listen("mouseup", runOn(this.a, this.a.af));
c.listen("mousedown", runOn(this.a, this.a.ac));
c.listen("mouseleave", runOn(this.a, this.a.ad));
c.listen("mousemove", runOn(this.a, this.a.ae));
this.f.addItem(a, c);
if ((this.l.getChildCount() == 0) || (b >= this.l.getChildCount())) {
this.l.append(c);
}
else {
var d = this.l.getChildAt(b);
d.before(c);
}
};
LegendBaseViewManager.prototype.w = function (a) {
};
LegendBaseViewManager.prototype.x = function (a) {
var _this = this;
var b;
if (((function () { var c = _this.f.tryGetValue(a, b); b = c.p1; return c.ret; })())) {
b.unlistenAll();
b.remove();
this.f.removeItem(a);
}
};
LegendBaseViewManager.prototype.n = function (visual_) {
var e_1, _a;
try {
for (var _b = __values(fromEnum(this.f)), _c = _b.next(); !_c.done; _c = _b.next()) {
var pair_ = _c.value;
if (pair_.value.getNativeElement() === visual_) {
return pair_.key;
}
;
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_1)
throw e_1.error;
}
}
return null;
};
LegendBaseViewManager.prototype.e = function (a) {
var e_2, _a;
try {
for (var _b = __values(fromEnum(this.f.keys)), _c = _b.next(); !_c.done; _c = _b.next()) {
var b = _c.value;
var c = typeCast(ContentControl.$, b);
if (c != null && c.content != null) {
var d = typeCast(ILegendContext_$type, c.content);
if (d != null && d.itemLabel == a.itemLabel && d.legendLabel == a.legendLabel && d.series == a.series && d.itemBrush == a.itemBrush) {
return true;
}
}
}
}
catch (e_2_1) {
e_2 = { error: e_2_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_2)
throw e_2.error;
}
}
return false;
};
LegendBaseViewManager.prototype.b = function (a) {
var b = this.g.rootWrapper.width();
var c = this.g.rootWrapper.height();
this.l.remove();
var d = this.g.createElement("div");
d.setStyleProperty("position", "relative");
this.m = this.g.createElement("<canvas style=\"position : absolute; top : 0; left : 0\" />");
this.m.setStyleProperty("position", "absolute");
this.m.setStyleProperty("top", "0px");
this.m.setStyleProperty("left", "0px");
this.g.append(d);
d.append(this.m);
this.c = new RenderingContext(new CanvasViewRenderer(), this.g.get2DCanvasContext(this.m));
this.m.setAttribute("width", b.toString());
this.m.setAttribute("height", c.toString());
return this.c;
};
LegendBaseViewManager.prototype.ab = function () {
return new Size(1, this.g.rootWrapper.width(), Math.max(10, this.g.rootWrapper.height() - 15));
};
LegendBaseViewManager.prototype.y = function (a, b, c, d) {
var e_3, _a;
var e = a.h();
e.beginPath();
e.moveTo(b.an._inner[0].x, b.an._inner[0].y);
for (var f = 1; f < b.an.count; f++) {
e.lineTo(b.an._inner[f].x, b.an._inner[f].y);
}
e.lineTo(b.an._inner[0].x, b.an._inner[0].y);
var g = e.createLinearGradient(d.left, d.top, d.left, d.top + d.height);
try {
for (var _b = __values(fromEnum(c.a)), _c = _b.next(); !_c.done; _c = _b.next()) {
var h = _c.value;
g.addColorStop(h.a, h.b._fill);
}
}
catch (e_3_1) {
e_3 = { error: e_3_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_3)
throw e_3.error;
}
}
e.fillStyle = g;
e.fill();
};
LegendBaseViewManager.prototype.q = function () {
};
LegendBaseViewManager.prototype.r = function () {
};
LegendBaseViewManager.prototype.v = function (a) {
var b = this.l == null ? 0 : this.l.getChildCount();
for (var c = 0; c < b; c++) {
var d = this.l.getChildAt(c);
d.setStyleProperty("display", a ? "block" : "");
d.setStyleProperty("float", a ? "left" : "");
d.setStyleProperty("margin", a ? "0px" : "");
d.setStyleProperty("margin-right", a ? "8px" : "");
d.getChildAt(1).setStyleProperty("white-space", a ? "nowrap" : "");
}
};
LegendBaseViewManager.prototype.z = function (a) {
this.l.setStyleProperty("color", a);
};
LegendBaseViewManager.prototype.aa = function (a) {
var b = FontUtil.getFontInfoFromString(this.g, a);
this.l.setStyleProperty("font-family", b.q);
this.l.setStyleProperty("font-size", b.f + "px");
this.l.setStyleProperty("font-style", b.t);
};
LegendBaseViewManager.$t = markType(LegendBaseViewManager, 'LegendBaseViewManager');
return LegendBaseViewManager;
}(Base));
export { LegendBaseViewManager };
/**
* @hidden
*/
var LegendBase = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(LegendBase, _super);
function LegendBase() {
var _this = _super.call(this) || this;
_this.ak = null;
_this.au = null;
_this._seriesOwner = null;
_this._chartOwner = null;
_this.propertyChanged = null;
_this.propertyUpdated = null;
_this.legendItemMouseLeftButtonDown = null;
_this.legendItemMouseLeftButtonUp = null;
_this.legendItemMouseEnter = null;
_this.legendItemMouseLeave = null;
_this.legendItemMouseMove = null;
_this.legendSizeChanged = null;
var a = _this.aj();
_this.ba(a);
a.al();
_this.au = new ObservableCollection$1(UIElement.$, 0);
_this.ax = "ig-chart-legend-items-list";
_this.ay = "ig-chart-legend-item";
_this.aw = "ig-chart-legend-item-badge";
_this.az = "ig-chart-legend-item-text";
return _this;
}
LegendBase.prototype.onDetachedFromUI = function () {
this.ak.ak();
};
LegendBase.prototype.onAttachedToUI = function () {
this.ak.ai();
};
LegendBase.prototype.aj = function () {
return new LegendBaseView(this);
};
LegendBase.prototype.ba = function (a) {
this.ak = a;
};
LegendBase.prototype.addChildInOrder = function (a, b) {
};
LegendBase.prototype.a1 = function (a, b) {
};
Object.defineProperty(LegendBase.prototype, "seriesOwner", {
get: function () {
return this._seriesOwner;
},
set: function (a) {
this._seriesOwner = a;
},
enumerable: false,
configurable: true
});
Object.defineProperty(LegendBase.prototype, "chartOwner", {
get: function () {
return this._chartOwner;
},
set: function (a) {
this._chartOwner = a;
},
enumerable: false,
configurable: true
});
LegendBase.prototype.get_isItemwise = function () {
return false;
};
Object.defineProperty(LegendBase.prototype, "isItemwise", {
get: function () {
return this.get_isItemwise();
},
enumerable: false,
configurable: true
});
LegendBase.prototype.get_isScale = function () {
return false;
};
Object.defineProperty(LegendBase.prototype, "isScale", {
get: function () {
return this.get_isScale();
},
enumerable: false,
configurable: true
});
LegendBase.prototype.clearLegendItemsForSeries = function (a) {
var e_4, _a, e_5, _b;
if (a == null || this.au == null || this.au.count == 0) {
return;
}
var b = new ObservableCollection$1(UIElement.$, 0);
try {
for (var _c = __values(fromEnum(this.au)), _d = _c.next(); !_d.done; _d = _c.next()) {
var c = _d.value;
var d = typeCast(ContentControl.$, c);
if (d != null && d.content != null) {
var e = typeCast(ILegendContext_$type, d.content);
if (e != null && e.series == a) {
b.add(c);
}
}
}
}
catch (e_4_1) {
e_4 = { error: e_4_1 };
}
finally {
try {
if (_d && !_d.done && (_a = _c.return))
_a.call(_c);
}
finally {
if (e_4)
throw e_4.error;
}
}
try {
for (var _e = __values(fromEnum(b)), _f = _e.next(); !_f.done; _f = _e.next()) {
var f = _f.value;
this.au.remove(f);
}
}
catch (e_5_1) {
e_5 = { error: e_5_1 };
}
finally {
try {
if (_f && !_f.done && (_b = _e.return))
_b.call(_e);
}
finally {
if (e_5)
throw e_5.error;
}
}
if (b.count > 0) {
this.a9(new LegendSizeChangedEventArgs());
}
};
LegendBase.prototype.containsChild = function (a) {
return this.au.contains(a);
};
LegendBase.prototype.removeChild = function (a) {
this.au.remove(a);
this.a9(new LegendSizeChangedEventArgs());
};
Object.defineProperty(LegendBase.prototype, "ai", {
get: function () {
if (this.seriesOwner != null) {
return this.seriesOwner;
}
else {
return this.chartOwner;
}
},
enumerable: false,
configurable: true
});
LegendBase.prototype.bb = function (a, b, c) {
if (this.propertyChanged != null) {
this.propertyChanged(this, new PropertyChangedEventArgs(a));
}
if (this.propertyUpdated != null) {
this.propertyUpdated(this, new PropertyUpdatedEventArgs(a, b, c));
}
};
LegendBase.prototype.a6 = function (a) {
if (this.legendItemMouseLeftButtonDown != null) {
this.legendItemMouseLeftButtonDown(this, a);
}
if (a.d != null) {
a.d.onLegendItemPointerDown(a.item);
}
};
LegendBase.prototype.a7 = function (a) {
if (this.legendItemMouseLeftButtonUp != null) {
this.legendItemMouseLeftButtonUp(this, a);
}
if (a.d != null) {
a.d.onLegendItemPointerUp(a.item);
}
};
LegendBase.prototype.a4 = function (a) {
if (this.legendItemMouseEnter != null) {
this.legendItemMouseEnter(this, a);
}
if (a.d != null) {
a.d.onLegendItemEnter(a.item);
}
};
LegendBase.prototype.a5 = function (a) {
if (this.legendItemMouseLeave != null) {
this.legendItemMouseLeave(this, a);
}
if (a.d != null) {
a.d.onLegendItemLeave(a.item);
}
};
LegendBase.prototype.a8 = function (a) {
if (this.legendItemMouseMove != null) {
this.legendItemMouseMove(this, a);
}
if (a.d != null) {
a.d.onLegendItemOver(a.item);
}
};
LegendBase.prototype.a9 = function (a) {
if (this.legendSizeChanged != null) {
this.legendSizeChanged(this, a);
}
};
LegendBase.prototype.provideContainer = function (a) {
this.ak.aj(a);
};
Object.defineProperty(LegendBase.prototype, "ax", {
get: function () {
return this.ak.t;
},
set: function (a) {
var b = this.ak.t;
this.ak.t = a;
if (b != a) {
this.a9(new LegendSizeChangedEventArgs());
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(LegendBase.prototype, "ay", {
get: function () {
return this.ak.u;
},
set: function (a) {
var b = this.ak.u;
this.ak.u = a;
if (b != a) {
this.a9(new LegendSizeChangedEventArgs());
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(LegendBase.prototype, "aw", {
get: function () {
return this.ak.s;
},
set: function (a) {
var b = this.ak.s;
this.ak.s = a;
if (b != a) {
this.a9(new LegendSizeChangedEventArgs());
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(LegendBase.prototype, "az", {
get: function () {
return this.ak.v;
},
set: function (a) {
var b = this.ak.v;
this.ak.v = a;
if (b != a) {
this.a9(new LegendSizeChangedEventArgs());
}
},
enumerable: false,
configurable: true
});
LegendBase.prototype.exportVisualData = function () {
return this.ak.g();
};
LegendBase.prototype.exportSerializedVisualData = function () {
var a = this.exportVisualData();
return a.serialize();
};
LegendBase.prototype.get_isFinancial = function () {
return false;
};
Object.defineProperty(LegendBase.prototype, "isFinancial", {
get: function () {
return this.get_isFinancial();
},
enumerable: false,
configurable: true
});
LegendBase.$t = markType(LegendBase, 'LegendBase', ContentControl.$, [INotifyPropertyChanged_$type, IChartLegend_$type]);
return LegendBase;
}(ContentControl));
export { LegendBase };
/**
* @hidden
*/
var LegendBaseView = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(LegendBaseView, _super);
function LegendBaseView(a) {
var _this = _super.call(this) || this;
_this.d = null;
_this.c = null;
_this.t = null;
_this.u = null;
_this.s = null;
_this.v = null;
_this.m = false;
_this.j = false;
_this.q = null;
_this.r = null;
_this.c = a;
_this.d = new LegendBaseViewManager(_this);
_this.d.p();
return _this;
}
LegendBaseView.prototype.ak = function () {
this.d.u();
};
LegendBaseView.prototype.ai = function () {
this.d.s();
};
LegendBaseView.prototype.al = function () {
};
LegendBaseView.prototype.get_k = function () {
return false;
};
Object.defineProperty(LegendBaseView.prototype, "k", {
get: function () {
return this.get_k();
},
enumerable: false,
configurable: true
});
LegendBaseView.prototype.e = function (a) {
var b;
var c;
var d;
var e = this.ab(a, b, c, d);
b = e.p1;
c = e.p2;
d = e.p3;
var f = new MouseButtonEventArgs();
var g = new LegendMouseButtonEventArgs(b, c, d, f, a);
return g;
};
LegendBaseView.prototype.f = function (a) {
var b;
var c;
var d;
var e = this.ab(a, b, c, d);
b = e.p1;
c = e.p2;
d = e.p3;
var f = new MouseEventArgs();
var g = new LegendMouseEventArgs(b, c, d, f, a);
return g;
};
LegendBaseView.prototype.ab = function (a, b, c, d) {
b = this.c.ai;
c = null;
d = null;
if (a != null) {
var e = typeCast(ContentControl.$, a);
if (e != null && e.content != null && typeCast(ILegendContext_$type, e.content) !== null) {
var f = typeCast(ILegendContext_$type, e.content);
c = typeCast(ILegendSeries_$type, f.series);
if (c != null) {
b = c.container;
}
d = f.item;
}
}
return {
p1: b,
p2: c,
p3: d
};
};
LegendBaseView.prototype.aa = function () {
};
LegendBaseView.prototype.n = function () {
return true;
};
LegendBaseView.prototype.z = function (a) {
};
LegendBaseView.prototype.an = function (a) {
};
LegendBaseView.prototype.aj = function (a) {
this.d.t(a);
};
LegendBaseView.prototype.ao = function (a) {
this.d.x(a);
};
LegendBaseView.prototype.y = function (a) {
var b = this.c.au.indexOf(a);
this.d.o(a, b);
};
LegendBaseView.prototype.ag = function () {
this.d.q();
};
LegendBaseView.prototype.ah = function () {
this.d.r();
};
Object.defineProperty(LegendBaseView.prototype, "l", {
get: function () {
return this.j;
},
set: function (a) {
this.j = a;
this.d.v(this.j);
},
enumerable: false,
configurable: true
});
Object.defineProperty(LegendBaseView.prototype, "w", {
get: function () {
return this.q;
},
set: function (a) {
this.q = a;
this.d.z(this.q);
},
enumerable: false,
configurable: true
});
Object.defineProperty(LegendBaseView.prototype, "x", {
get: function () {
return this.r;
},
set: function (a) {
this.r = a;
this.d.aa(this.r);
},
enumerable: false,
configurable: true
});
LegendBaseView.prototype.am = function () {
this.d.p();
};
LegendBaseView.prototype.o = function (e_) {
var ev_ = e_.originalEvent;
return ev_.currentTarget;
};
LegendBaseView.prototype.p = function (e_) {
return this.d.n(this.o(e_));
};
LegendBaseView.prototype.ae = function (a) {
if (!this.m) {
this.c.a4(this.f(this.p(a)));
}
this.m = true;
};
LegendBaseView.prototype.ad = function (a) {
if (this.m) {
this.c.a5(this.f(this.p(a)));
}
this.m = false;
};
LegendBaseView.prototype.ac = function (a) {
this.c.a6(this.e(this.p(a)));
};
LegendBaseView.prototype.af = function (a) {
this.c.a7(this.e(this.p(a)));
};
LegendBaseView.prototype.i = function (a) {
var b = a.querySelectorAll("span *");
var c = Rect.empty;
for (var e = 0; e < b.length; e++) {
var d = b[e];
if (stringIsNullOrEmpty(d.getText())) {
continue;
}
var f = new Rect(0, d.getOffset().left, d.getOffset().top, d.width(), d.height());
f.union(c);
c = f;
}
return RectData.b(c);
};
LegendBaseView.prototype.h = function (a) {
var b = a.querySelectorAll("canvas");
var c = b.length > 0 ? b[0] : null;
return c != null ? new RectData(c.getOffset().left, c.getOffset().top, c.width(), c.height()) : null;
};
LegendBaseView.prototype.a = function (a) {
if (this.c == null || this.c.au == null || this.c.au.count <= a) {
return null;
}
var b = this.c.au._inner[a];
if (b == null) {
return null;
}
var c = b.content;
if (c == null) {
return null;
}
var d = c.actualItemBrush != null ? c.actualItemBrush : c.itemBrush;
return AppearanceHelper.b(d);
};
LegendBaseView.prototype.b = function (a) {
if (this.c == null || this.c.au == null || this.c.au.count <= a) {
return null;
}
var b = this.c.au._inner[a];
if (b == null) {
return null;
}
var c = b.content;
if (c == null) {
return null;
}
var d = c.outline;
return AppearanceHelper.b(d);
};
LegendBaseView.prototype.g = function () {
var a = new LegendVisualData();
var b = this.d.l;
var c = b.getChildCount();
for (var d = 0; d < c; d++) {
var e = new LegendItemVisualData();
var f = b.getChildAt(d);
e.label = f.getText();
e.label = e.label != null ? e.label.trim() : null;
e.bounds = new RectData(f.getOffset().left, f.getOffset().top, f.width(), f.height());
e.labelBounds = this.i(f);
e.badgeBounds = this.h(f);
e.appearance.fill = this.a(d);
e.appearance.stroke = this.b(d);
a.items.add(e);
}
for (var g = 0; g < this.c.au.count; g++) {
a.items._inner[g].appearance.fill = this.a(g);
a.items._inner[g].appearance.stroke = this.b(g);
}
return a;
};
LegendBaseView.$t = markType(LegendBaseView, 'LegendBaseView');
return LegendBaseView;
}(Base));
export { LegendBaseView };