igniteui-angular-charts
Version:
Ignite UI Angular charting components for building rich data visualizations for modern web apps.
665 lines (664 loc) • 22.3 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 { Base, typeCast, runOn, fromEnum, markType, INotifyPropertyChanged_$type, PropertyChangedEventArgs } from "igniteui-angular-core";
import { DomWrapper_$type } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { RenderingContext } from "igniteui-angular-core";
import { LegendItemHelper } from "igniteui-angular-core";
import { ContentControl } from "igniteui-angular-core";
import { ILegendContext_$type } from "igniteui-angular-core";
import { DataTemplatePassInfo } from "igniteui-angular-core";
import { DataTemplateMeasureInfo } from "igniteui-angular-core";
import { DataTemplateRenderInfo } from "igniteui-angular-core";
import { CanvasViewRenderer } from "igniteui-angular-core";
import { Size } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { FontUtil } from "igniteui-angular-core";
import { isNaN_ } from "igniteui-angular-core";
import { IChartLegend_$type } from "igniteui-angular-core";
import { ObservableCollection$1 } from "igniteui-angular-core";
import { UIElement } from "igniteui-angular-core";
import { ILegendSeries_$type } from "igniteui-angular-core";
import { PropertyUpdatedEventArgs } from "igniteui-angular-core";
import { LegendMouseButtonEventArgs } from "./LegendMouseButtonEventArgs";
import { LegendMouseEventArgs } from "./LegendMouseEventArgs";
import { LegendVisualData } from "./LegendVisualData";
import { MouseButtonEventArgs } from "igniteui-angular-core";
import { MouseEventArgs } from "igniteui-angular-core";
import { RectData } from "igniteui-angular-core";
import { AppearanceHelper } from "igniteui-angular-core";
import { LegendItemVisualData } from "./LegendItemVisualData";
import { stringIsNullOrEmpty } from "igniteui-angular-core";
/**
* @hidden
*/
export let LegendBaseViewManager = /*@__PURE__*/ (() => {
class LegendBaseViewManager extends Base {
constructor(a) {
super();
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);
}
p() {
let a = LegendItemHelper.b;
if (window.devicePixelRatio != undefined && (isNaN_(a) || window.devicePixelRatio != a)) {
LegendItemHelper.b = window.devicePixelRatio;
this.a.am();
}
}
u() {
}
s() {
this.p();
}
t(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);
}
i() {
return this.g.createElement("table");
}
h() {
let a = this.g.createElement("tr");
a.addClass(this.a.u);
let 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;
}
j(a) {
return this.k(a, this.l);
}
k(a, b) {
let c = typeCast(ContentControl.$, a);
let d = this.h();
if (c != null) {
let e = typeCast(ILegendContext_$type, c.content);
if (e != null && c.ah != null) {
let f = new DataTemplatePassInfo();
f.context = d;
f.passID = "LegendItem";
let g = new DataTemplateMeasureInfo();
g.passInfo = f;
g.width = NaN;
g.height = NaN;
g.data = e;
g.context = d;
let 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);
let i = d.findByClass(".ui-legend-item-badge");
for (let 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 (let 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;
}
o(a, b) {
let 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 {
let d = this.l.getChildAt(b);
d.before(c);
}
}
w(a) {
}
x(a) {
let b;
if (((() => { let c = this.f.tryGetValue(a, b); b = c.p1; return c.ret; })())) {
b.unlistenAll();
b.remove();
this.f.removeItem(a);
}
}
n(visual_) {
for (let pair_ of fromEnum(this.f)) {
if (pair_.value.getNativeElement() === visual_) {
return pair_.key;
}
;
}
return null;
}
e(a) {
for (let b of fromEnum(this.f.keys)) {
let c = typeCast(ContentControl.$, b);
if (c != null && c.content != null) {
let 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;
}
}
}
return false;
}
b(a) {
let b = this.g.rootWrapper.width();
let c = this.g.rootWrapper.height();
this.l.remove();
let 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;
}
ab() {
return new Size(1, this.g.rootWrapper.width(), Math.max(10, this.g.rootWrapper.height() - 15));
}
y(a, b, c, d) {
let e = a.h();
e.beginPath();
e.moveTo(b.an._inner[0].x, b.an._inner[0].y);
for (let 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);
let g = e.createLinearGradient(d.left, d.top, d.left, d.top + d.height);
for (let h of fromEnum(c.a)) {
g.addColorStop(h.a, h.b._fill);
}
e.fillStyle = g;
e.fill();
}
q() {
}
r() {
}
v(a) {
let b = this.l == null ? 0 : this.l.getChildCount();
for (let c = 0; c < b; c++) {
let 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" : "");
}
}
z(a) {
this.l.setStyleProperty("color", a);
}
aa(a) {
let 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;
})();
/**
* @hidden
*/
export let LegendBase = /*@__PURE__*/ (() => {
class LegendBase extends ContentControl {
constructor() {
super();
this.ak = null;
this.at = 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;
let a = this.aj();
this.a8(a);
a.al();
this.at = new ObservableCollection$1(UIElement.$, 0);
this.aw = "ig-chart-legend-items-list";
this.ax = "ig-chart-legend-item";
this.av = "ig-chart-legend-item-badge";
this.ay = "ig-chart-legend-item-text";
}
onDetachedFromUI() {
this.ak.ak();
}
onAttachedToUI() {
this.ak.ai();
}
aj() {
return new LegendBaseView(this);
}
a8(a) {
this.ak = a;
}
addChildInOrder(a, b) {
}
a0(a, b) {
}
get seriesOwner() {
return this._seriesOwner;
}
set seriesOwner(a) {
this._seriesOwner = a;
}
get chartOwner() {
return this._chartOwner;
}
set chartOwner(a) {
this._chartOwner = a;
}
get_isItemwise() {
return false;
}
get isItemwise() {
return this.get_isItemwise();
}
get_isScale() {
return false;
}
get isScale() {
return this.get_isScale();
}
clearLegendItemsForSeries(a) {
if (a == null || this.at == null || this.at.count == 0) {
return;
}
let b = new ObservableCollection$1(UIElement.$, 0);
for (let c of fromEnum(this.at)) {
let d = typeCast(ContentControl.$, c);
if (d != null && d.content != null) {
let e = typeCast(ILegendContext_$type, d.content);
if (e != null && e.series == a) {
b.add(c);
}
}
}
for (let f of fromEnum(b)) {
this.at.remove(f);
}
}
containsChild(a) {
return this.at.contains(a);
}
removeChild(a) {
this.at.remove(a);
}
get ai() {
if (this.seriesOwner != null) {
return this.seriesOwner;
}
else {
return this.chartOwner;
}
}
a9(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));
}
}
a5(a) {
if (this.legendItemMouseLeftButtonDown != null) {
this.legendItemMouseLeftButtonDown(this, a);
}
if (a.d != null) {
a.d.onLegendItemPointerDown(a.item);
}
}
a6(a) {
if (this.legendItemMouseLeftButtonUp != null) {
this.legendItemMouseLeftButtonUp(this, a);
}
if (a.d != null) {
a.d.onLegendItemPointerUp(a.item);
}
}
a3(a) {
if (this.legendItemMouseEnter != null) {
this.legendItemMouseEnter(this, a);
}
if (a.d != null) {
a.d.onLegendItemEnter(a.item);
}
}
a4(a) {
if (this.legendItemMouseLeave != null) {
this.legendItemMouseLeave(this, a);
}
if (a.d != null) {
a.d.onLegendItemLeave(a.item);
}
}
a7(a) {
if (this.legendItemMouseMove != null) {
this.legendItemMouseMove(this, a);
}
if (a.d != null) {
a.d.onLegendItemOver(a.item);
}
}
provideContainer(a) {
this.ak.aj(a);
}
get aw() {
return this.ak.t;
}
set aw(a) {
this.ak.t = a;
}
get ax() {
return this.ak.u;
}
set ax(a) {
this.ak.u = a;
}
get av() {
return this.ak.s;
}
set av(a) {
this.ak.s = a;
}
get ay() {
return this.ak.v;
}
set ay(a) {
this.ak.v = a;
}
exportVisualData() {
return this.ak.g();
}
exportSerializedVisualData() {
let a = this.exportVisualData();
return a.serialize();
}
get_isFinancial() {
return false;
}
get isFinancial() {
return this.get_isFinancial();
}
}
LegendBase.$t = markType(LegendBase, 'LegendBase', ContentControl.$, [INotifyPropertyChanged_$type, IChartLegend_$type]);
return LegendBase;
})();
/**
* @hidden
*/
export let LegendBaseView = /*@__PURE__*/ (() => {
class LegendBaseView extends Base {
constructor(a) {
super();
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();
}
ak() {
this.d.u();
}
ai() {
this.d.s();
}
al() {
}
get_k() {
return false;
}
get k() {
return this.get_k();
}
e(a) {
let b;
let c;
let d;
let e = this.ab(a, b, c, d);
b = e.p1;
c = e.p2;
d = e.p3;
let f = new MouseButtonEventArgs();
let g = new LegendMouseButtonEventArgs(b, c, d, f, a);
return g;
}
f(a) {
let b;
let c;
let d;
let e = this.ab(a, b, c, d);
b = e.p1;
c = e.p2;
d = e.p3;
let f = new MouseEventArgs();
let g = new LegendMouseEventArgs(b, c, d, f, a);
return g;
}
ab(a, b, c, d) {
b = this.c.ai;
c = null;
d = null;
if (a != null) {
let e = typeCast(ContentControl.$, a);
if (e != null && e.content != null && typeCast(ILegendContext_$type, e.content) !== null) {
let 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
};
}
aa() {
}
n() {
return true;
}
z(a) {
}
an(a) {
}
aj(a) {
this.d.t(a);
}
ao(a) {
this.d.x(a);
}
y(a) {
let b = this.c.at.indexOf(a);
this.d.o(a, b);
}
ag() {
this.d.q();
}
ah() {
this.d.r();
}
get l() {
return this.j;
}
set l(a) {
this.j = a;
this.d.v(this.j);
}
get w() {
return this.q;
}
set w(a) {
this.q = a;
this.d.z(this.q);
}
get x() {
return this.r;
}
set x(a) {
this.r = a;
this.d.aa(this.r);
}
am() {
this.d.p();
}
o(e_) {
let ev_ = e_.originalEvent;
return ev_.currentTarget;
}
p(e_) {
return this.d.n(this.o(e_));
}
ae(a) {
if (!this.m) {
this.c.a3(this.f(this.p(a)));
}
this.m = true;
}
ad(a) {
if (this.m) {
this.c.a4(this.f(this.p(a)));
}
this.m = false;
}
ac(a) {
this.c.a5(this.e(this.p(a)));
}
af(a) {
this.c.a6(this.e(this.p(a)));
}
i(a) {
let b = a.querySelectorAll("span *");
let c = Rect.empty;
for (let e = 0; e < b.length; e++) {
let d = b[e];
if (stringIsNullOrEmpty(d.getText())) {
continue;
}
let f = new Rect(0, d.getOffset().left, d.getOffset().top, d.width(), d.height());
f.union(c);
c = f;
}
return RectData.b(c);
}
h(a) {
let b = a.querySelectorAll("canvas");
let c = b.length > 0 ? b[0] : null;
return c != null ? new RectData(c.getOffset().left, c.getOffset().top, c.width(), c.height()) : null;
}
a(a) {
if (this.c == null || this.c.at == null || this.c.at.count <= a) {
return null;
}
let b = this.c.at._inner[a];
if (b == null) {
return null;
}
let c = b.content;
if (c == null) {
return null;
}
let d = c.actualItemBrush != null ? c.actualItemBrush : c.itemBrush;
return AppearanceHelper.b(d);
}
b(a) {
if (this.c == null || this.c.at == null || this.c.at.count <= a) {
return null;
}
let b = this.c.at._inner[a];
if (b == null) {
return null;
}
let c = b.content;
if (c == null) {
return null;
}
let d = c.outline;
return AppearanceHelper.b(d);
}
g() {
let a = new LegendVisualData();
let b = this.d.l;
let c = b.getChildCount();
for (let d = 0; d < c; d++) {
let e = new LegendItemVisualData();
let 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 (let g = 0; g < this.c.at.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;
})();