UNPKG

igniteui-react-charts

Version:

Ignite UI React charting components for building rich data visualizations using TypeScript APIs.

692 lines (691 loc) 22.6 kB
/* 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-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 */ 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 = /*@__PURE__*/ markType(LegendBaseViewManager, 'LegendBaseViewManager'); return LegendBaseViewManager; })(); /** * @hidden */ export let LegendBase = /*@__PURE__*/ (() => { class LegendBase extends ContentControl { onDetachedFromUI() { this.ak.ak(); } onAttachedToUI() { this.ak.ai(); } aj() { return new LegendBaseView(this); } ba(a) { this.ak = a; } constructor() { super(); 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; let 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"; } addChildInOrder(a, b) { } a1(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.au == null || this.au.count == 0) { return; } let b = new ObservableCollection$1(UIElement.$, 0); for (let c of fromEnum(this.au)) { 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.au.remove(f); } if (b.count > 0) { this.a9(new LegendSizeChangedEventArgs()); } } containsChild(a) { return this.au.contains(a); } removeChild(a) { this.au.remove(a); this.a9(new LegendSizeChangedEventArgs()); } get ai() { if (this.seriesOwner != null) { return this.seriesOwner; } else { return this.chartOwner; } } bb(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)); } } a6(a) { if (this.legendItemMouseLeftButtonDown != null) { this.legendItemMouseLeftButtonDown(this, a); } if (a.d != null) { a.d.onLegendItemPointerDown(a.item); } } a7(a) { if (this.legendItemMouseLeftButtonUp != null) { this.legendItemMouseLeftButtonUp(this, a); } if (a.d != null) { a.d.onLegendItemPointerUp(a.item); } } a4(a) { if (this.legendItemMouseEnter != null) { this.legendItemMouseEnter(this, a); } if (a.d != null) { a.d.onLegendItemEnter(a.item); } } a5(a) { if (this.legendItemMouseLeave != null) { this.legendItemMouseLeave(this, a); } if (a.d != null) { a.d.onLegendItemLeave(a.item); } } a8(a) { if (this.legendItemMouseMove != null) { this.legendItemMouseMove(this, a); } if (a.d != null) { a.d.onLegendItemOver(a.item); } } a9(a) { if (this.legendSizeChanged != null) { this.legendSizeChanged(this, a); } } provideContainer(a) { this.ak.aj(a); } get ax() { return this.ak.t; } set ax(a) { let b = this.ak.t; this.ak.t = a; if (b != a) { this.a9(new LegendSizeChangedEventArgs()); } } get ay() { return this.ak.u; } set ay(a) { let b = this.ak.u; this.ak.u = a; if (b != a) { this.a9(new LegendSizeChangedEventArgs()); } } get aw() { return this.ak.s; } set aw(a) { let b = this.ak.s; this.ak.s = a; if (b != a) { this.a9(new LegendSizeChangedEventArgs()); } } get az() { return this.ak.v; } set az(a) { let b = this.ak.v; this.ak.v = a; if (b != a) { this.a9(new LegendSizeChangedEventArgs()); } } 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 = /*@__PURE__*/ 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.au.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.a4(this.f(this.p(a))); } this.m = true; } ad(a) { if (this.m) { this.c.a5(this.f(this.p(a))); } this.m = false; } ac(a) { this.c.a6(this.e(this.p(a))); } af(a) { this.c.a7(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.au == null || this.c.au.count <= a) { return null; } let b = this.c.au._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.au == null || this.c.au.count <= a) { return null; } let b = this.c.au._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.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 = /*@__PURE__*/ markType(LegendBaseView, 'LegendBaseView'); return LegendBaseView; })();