UNPKG

igniteui-webcomponents-charts

Version:

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

730 lines (721 loc) 28.4 kB
import { __extends, __values } from "tslib"; import { WebComponentRenderer, WebComponentWrapper } from "igniteui-webcomponents-core"; import { TypeRegistrar, delegateCombine, delegateRemove } from "igniteui-webcomponents-core"; import { DataChartStylingDefaults } from './DataChartStylingDefaults'; import { XamDoughnutChart } from './XamDoughnutChart'; import { ensureBool, fromPoint, CollectionAdapter, initializePropertiesFromCss, NamePatcher, toSpinal, fromSpinal, getAllPropertyNames } from "igniteui-webcomponents-core"; import { Style } from "igniteui-webcomponents-core"; import { IgcSliceClickEventArgs } from "./igc-slice-click-event-args"; import { IgcHoleDimensionsChangedEventArgs } from "./igc-hole-dimensions-changed-event-args"; import { IgcRingSeriesBaseComponent } from "./igc-ring-series-base-component"; import { NotifyCollectionChangedAction } from "igniteui-webcomponents-core"; import { IgcRingSeriesCollection } from "./igc-ring-series-collection"; import { IgcPieSliceDataContext } from "./igc-pie-slice-data-context"; import { RegisterElementHelper } from "igniteui-webcomponents-core"; import { IgcHTMLElement } from "igniteui-webcomponents-core"; /** * Represents concentric circles divided on arcs depending on data. */ var IgcDoughnutChartComponent = /** @class */ /*@__PURE__*/ (function (_super) { __extends(IgcDoughnutChartComponent, _super); function IgcDoughnutChartComponent() { var _this = _super.call(this) || this; _this.contentSeries = []; _this._seriesAdapter = null; _this._disconnected = false; /** * The series actually present in the chart. Do not directly modify this array. * This array's contents can be modified by causing Angular to reproject the child content. * Or adding and removing series from the manual series collection on the series property. */ _this.actualSeries = []; _this._series = null; _this._defaultTooltips = null; _this._settingAttributes = false; _this._attached = false; _this._queuedSetAttributes = []; _this._updatingFromAttribute = false; _this.__p = null; _this._hasUserValues = new Set(); _this._stylingContainer = null; _this._stylingParent = null; _this._inStyling = false; _this._sliceClick = null; _this._sliceClick_wrapped = null; _this._holeDimensionsChanged = null; _this._holeDimensionsChanged_wrapped = null; if (_this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this)); } _this._renderer = new WebComponentRenderer(_this, document, true, DataChartStylingDefaults); _this._implementation = _this.createImplementation(); _this._implementation.externalObject = _this; _this.onImplementationCreated(); _this.container = _this._renderer.createElement("div"); _this._renderer.updateRoot(_this.container); //this._renderer.rootWrapper.append(this._container); _this.container.setStyleProperty("display", "block"); _this.container.setStyleProperty("width", "100%"); _this.container.setStyleProperty("height", "100%"); var root; root = _this.container; if (_this.container != null) { root = _this.container; } _this._wrapper = _this._renderer; var chart = _this.i; _this._chart = chart; _this._seriesAdapter = new CollectionAdapter(_this.contentSeries, _this.i.series, _this.actualSeries, function (c) { return c.i; }, function (i) { i.owner = _this; // (<any>i)._provideRenderer(this._dataSource); if (_this.parentElement) { i._styling(_this, _this, _this); } _this._ensureDefaultTooltip(i); _this._ensureTooltipCreated(i); }, function (i) { //(<any>i)._provideRenderer(null); }); chart.provideContainer(_this._renderer); var mut = new MutationObserver(function (list) { var e_1, _b; try { for (var list_1 = __values(list), list_1_1 = list_1.next(); !list_1_1.done; list_1_1 = list_1.next()) { var mutation = list_1_1.value; if (mutation.type == 'childList') { _this.updateContentChildren(); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (list_1_1 && !list_1_1.done && (_b = list_1.return)) _b.call(list_1); } finally { if (e_1) throw e_1.error; } } }); mut.observe(_this, { childList: true }); _this._renderer.addSizeWatcher(function () { _this._chart.notifyResized(); }); return _this; } Object.defineProperty(IgcDoughnutChartComponent.prototype, "height", { get: function () { return this._height; }, set: function (value) { this._height = value; this.style.height = value; this.notifyResized(); }, enumerable: false, configurable: true }); Object.defineProperty(IgcDoughnutChartComponent.prototype, "width", { get: function () { return this._width; }, set: function (value) { this._width = value; this.style.width = value; this.notifyResized(); }, enumerable: false, configurable: true }); IgcDoughnutChartComponent.prototype.ngOnDestroy = function () { this._chart.destroy(); this._wrapper.destroy(); }; IgcDoughnutChartComponent.prototype.onImplementationCreated = function () { }; IgcDoughnutChartComponent.prototype.createImplementation = function () { return new XamDoughnutChart(); }; Object.defineProperty(IgcDoughnutChartComponent.prototype, "i", { get: function () { return this._implementation; }, enumerable: false, configurable: true }); IgcDoughnutChartComponent.prototype.createSeriesComponent = function (type) { if (TypeRegistrar.isRegistered(type)) { var s = TypeRegistrar.create(type); s.owner = this; s._provideRenderer(this._wrapper); return s; } else { //we shouldn't get here, hopefully. throw Error("series type not loaded: " + type); } }; IgcDoughnutChartComponent.prototype.updateContentChildren = function () { this.contentSeries.length = 0; for (var i = 0; i < this.children.length; i++) { if (this.children[i] instanceof IgcRingSeriesBaseComponent) { this.contentSeries.push(this.children[i]); } } if (this._seriesAdapter != null) { this._seriesAdapter.notifyContentChanged(); } }; IgcDoughnutChartComponent.prototype.disconnectedCallback = function () { this._disconnected = true; if (this.i) { this.i.onDetachedFromUI(); } }; IgcDoughnutChartComponent.prototype.connectedCallback = function () { if (this._disconnected) { this._disconnected = false; if (this.i) { this.i.onAttachedToUI(); } return; } this.classList.add("ig-doughnut-chart"); this.classList.add("igc-doughnut-chart"); this.appendChild(this._renderer.rootWrapper.getNativeElement()); this._attached = true; this.style.display = "block"; this.style.height = this._height; this.style.width = this._width; this._flushQueuedAttributes(); // supports themes or custom properties set in CSS this._styling(this, this); for (var i = 0; i < this.actualSeries.length; i++) { var s = this.actualSeries[i]; s._styling(this, this, this); } this.updateContentChildren(); this.afterContentInit(); }; IgcDoughnutChartComponent.prototype.afterContentInit = function () { var _this = this; if (TypeRegistrar.isRegistered("IgcDoughnutChartDefaultTooltipsComponent")) { var cr_1 = TypeRegistrar.create("IgcDoughnutChartDefaultTooltipsComponent"); this._defaultTooltips = cr_1; cr_1.onContentReady = function () { _this._onDefaultTooltipsReady(cr_1); }; } this.i.notifyResized(); }; Object.defineProperty(IgcDoughnutChartComponent.prototype, "series", { /** * A collection or manually added series for the chart. */ get: function () { var _this = this; if (this._series === null) { var coll = new IgcRingSeriesCollection(); var inner = coll._innerColl; inner.addListener(function (sender, e) { switch (e.action) { case NotifyCollectionChangedAction.Add: _this._seriesAdapter.addManualItem(e.newItems.item(0)); break; case NotifyCollectionChangedAction.Remove: _this._seriesAdapter.removeManualItemAt(e.oldStartingIndex); break; case NotifyCollectionChangedAction.Replace: _this._seriesAdapter.removeManualItemAt(e.oldStartingIndex); _this._seriesAdapter.insertManualItem(e.newStartingIndex, e.newItems.item(0)); break; case NotifyCollectionChangedAction.Reset: _this._seriesAdapter.clearManualItems(); break; } }); this._series = coll; } return this._series; }, enumerable: false, configurable: true }); IgcDoughnutChartComponent.prototype._ensureTooltipCreated = function (series) { var _this = this; series._ensureTooltipCreated(function () { return _this.createTooltip(); }, function (ele) { var wrapper = new WebComponentWrapper(ele, _this._renderer); wrapper.updateToolTip = ele.updateToolTip; wrapper.hideToolTip = ele.hideToolTip; return wrapper; }); }; IgcDoughnutChartComponent.prototype._ensureDefaultTooltip = function (series) { if (this._defaultTooltips == null) { return; } this._defaultTooltips["ensureDefaultTooltip"](series); }; IgcDoughnutChartComponent.prototype._onDefaultTooltipsReady = function (cr) { if (this.actualSeries && this.actualSeries.length > 0) { var currSeries = this.actualSeries; for (var i = 0; i < currSeries.length; i++) { if (currSeries[i].showDefaultTooltip) { this._ensureDefaultTooltip(currSeries[i]); } } } }; IgcDoughnutChartComponent.prototype.createTooltip = function () { if (!TypeRegistrar.isRegistered("IgcTooltipContainerComponent")) { return null; } var cr = TypeRegistrar.create("IgcTooltipContainerComponent"); var ele = cr; var self = this; ele.updateToolTip = function (c) { if (c.externalObject) { c = c.externalObject; } else { var ext = new IgcPieSliceDataContext(); ext._implementation = c; c = ext; } if (ele.parentElement != self.container.getNativeElement()) { if (ele.parentElement != null) { ele.parentElement.removeChild(ele); } self.container.getNativeElement().appendChild(ele); } cr.instance.context = c; if (c.series.showDefaultTooltip) { var tooltipContainers = ele.getElementsByClassName("ui-tooltip-container"); if (tooltipContainers.length > 0) tooltipContainers[0].style.borderColor = c.i.slice.background.fill; } ele.style.display = "block"; return true; }; ele.hideToolTip = function () { ele.style.display = "none"; }; ele.style.display = "none"; return cr; }; IgcDoughnutChartComponent.prototype._enqueueSetAttribute = function (attrName, attrValue) { this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue }); }; IgcDoughnutChartComponent.prototype._flushQueuedAttributes = function () { this._settingAttributes = true; for (var i = 0; i < this._queuedSetAttributes.length; i++) { this.setAttribute(this._queuedSetAttributes[i].attrName, this._queuedSetAttributes[i].attrValue); } this._settingAttributes = false; this._queuedSetAttributes.length = 0; }; IgcDoughnutChartComponent.prototype._a = function (attrName, attrValue) { if (this._updatingFromAttribute) { return; } if (attrValue) { attrValue = attrValue.toString(); } this._settingAttributes = true; attrName = toSpinal(attrName); if (this._attached) { this.setAttribute(attrName, attrValue); } else { this._enqueueSetAttribute(attrName, attrValue); } this._settingAttributes = false; }; Object.defineProperty(IgcDoughnutChartComponent, "observedAttributes", { get: function () { if (IgcDoughnutChartComponent._observedAttributesIgcDoughnutChartComponent == null) { var names = getAllPropertyNames(IgcDoughnutChartComponent); for (var i = 0; i < names.length; i++) { names[i] = toSpinal(names[i]); } IgcDoughnutChartComponent._observedAttributesIgcDoughnutChartComponent = names; } return IgcDoughnutChartComponent._observedAttributesIgcDoughnutChartComponent; }, enumerable: false, configurable: true }); IgcDoughnutChartComponent.prototype.attributeChangedCallback = function (name, oldValue, newValue) { if (this._settingAttributes) { return; } var setName = fromSpinal(name); this._updatingFromAttribute = true; this[setName] = newValue; this._updatingFromAttribute = false; }; IgcDoughnutChartComponent.register = function () { if (!IgcDoughnutChartComponent._isElementRegistered) { IgcDoughnutChartComponent._isElementRegistered = true; RegisterElementHelper.registerElement(IgcDoughnutChartComponent.htmlTagName, IgcDoughnutChartComponent); } }; Object.defineProperty(IgcDoughnutChartComponent.prototype, "allowSliceSelection", { /** * Gets or sets whether the slices can be selected. */ get: function () { return this.i.aw; }, set: function (v) { this.i.aw = ensureBool(v); this._a("allowSliceSelection", this.i.aw); }, enumerable: false, configurable: true }); Object.defineProperty(IgcDoughnutChartComponent.prototype, "isSurfaceInteractionDisabled", { /** * Gets or sets whether all surface interactions with the plot area should be disabled. */ get: function () { return this.i.ax; }, set: function (v) { this.i.ax = ensureBool(v); this._a("isSurfaceInteractionDisabled", this.i.ax); }, enumerable: false, configurable: true }); Object.defineProperty(IgcDoughnutChartComponent.prototype, "allowSliceExplosion", { /** * Gets or sets whether the slices can be exploded. */ get: function () { return this.i.av; }, set: function (v) { this.i.av = ensureBool(v); this._a("allowSliceExplosion", this.i.av); }, enumerable: false, configurable: true }); Object.defineProperty(IgcDoughnutChartComponent.prototype, "innerExtent", { /** * Gets or sets the inner extent of the doughnut chart. It is percent from the outer ring's radius. */ get: function () { return this.i.a3; }, set: function (v) { this.i.a3 = +v; this._a("innerExtent", this.i.a3); }, enumerable: false, configurable: true }); Object.defineProperty(IgcDoughnutChartComponent.prototype, "selectedSliceFill", { /** * Gets or sets the fill brush. */ get: function () { return this.i.cg ? this.i.cg.fill : null; }, set: function (v) { this.ensureSelectedStyle(); this.i.cg.fill = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgcDoughnutChartComponent.prototype, "selectedSliceStroke", { /** * Gets or sets the stroke brush. */ get: function () { return this.i.cg ? this.i.cg.stroke : null; }, set: function (v) { this.ensureSelectedStyle(); this.i.cg.stroke = v; }, enumerable: false, configurable: true }); Object.defineProperty(IgcDoughnutChartComponent.prototype, "selectedSliceStrokeThickness", { /** * Gets or sets the stroke thickness. */ get: function () { return this.i.cg ? this.i.cg.strokeThickness : NaN; }, set: function (v) { this.ensureSelectedStyle(); this.i.cg.strokeThickness = +v; this._a("selectedSliceStrokeThickness", this.i.cg.strokeThickness); }, enumerable: false, configurable: true }); Object.defineProperty(IgcDoughnutChartComponent.prototype, "selectedSliceOpacity", { /** * Gets or sets the opacity. */ get: function () { return this.i.cg ? this.i.cg.opacity : NaN; }, set: function (v) { this.ensureSelectedStyle(); this.i.cg.opacity = +v; this._a("selectedSliceOpacity", this.i.cg.opacity); }, enumerable: false, configurable: true }); IgcDoughnutChartComponent.prototype.ensureSelectedStyle = function () { if (this.i.cg) { return; } this.i.cg = new Style(); }; Object.defineProperty(IgcDoughnutChartComponent.prototype, "pixelScalingRatio", { /** * Gets or sets the scaling value used to affect the pixel density of the control. * A higher scaling ratio will produce crisper visuals at the expense of memory. Lower values will cause the control * to appear blurry. */ get: function () { return this.i.a4; }, set: function (v) { this.i.a4 = +v; this._a("pixelScalingRatio", this.i.a4); }, enumerable: false, configurable: true }); Object.defineProperty(IgcDoughnutChartComponent.prototype, "actualPixelScalingRatio", { /** * Resolved pixel scaling ratio. Unless explicitly overridden by the * IgxDoughnutChart.PixelScalingRatioComponent property, * this one returns the default ratio enforced by device. High resolution devices will initialize this property * to a higher value. */ get: function () { return this.i.a1; }, set: function (v) { this.i.a1 = +v; this._a("actualPixelScalingRatio", this.i.a1); }, enumerable: false, configurable: true }); IgcDoughnutChartComponent.prototype.findByName = function (name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } if (this.series != null && this.series.findByName && this.series.findByName(name)) { return this.series.findByName(name); } return null; }; Object.defineProperty(IgcDoughnutChartComponent.prototype, "hasUserValues", { get: function () { return this._hasUserValues; }, enumerable: false, configurable: true }); IgcDoughnutChartComponent.prototype.__m = function (propertyName) { if (!this._inStyling) { this._hasUserValues.add(propertyName); } }; IgcDoughnutChartComponent.prototype._styling = function (container, component, parent) { if (this._inStyling) { return; } this._inStyling = true; this._stylingContainer = container; this._stylingParent = component; var genericPrefix = ""; var typeName = this.i.$type.name; if (typeName.indexOf("Xam") === 0) { typeName = typeName.substring(3); } genericPrefix = toSpinal("DoughnutChartComponent"); var additionalPrefixes = []; var prefix = toSpinal(typeName); additionalPrefixes.push(prefix + "-"); var b = this.i.$type.baseType; while (b && b.name != "Object" && b.name != "Base" && b.name != "Control" && b.Name != "DependencyObject" && b.Name != "FrameworkElement") { typeName = b.name; if (typeName.indexOf("Xam") === 0) { typeName = typeName.substring(3); } var basePrefix = toSpinal(typeName); additionalPrefixes.push(basePrefix + "-"); b = b.baseType; } if (parent) { var parentTypeName = parent.i.$type.name; if (parentTypeName.indexOf("Xam") === 0) { parentTypeName = parentTypeName.substring(3); } var parentPrefix = toSpinal(parentTypeName); additionalPrefixes.push(parentPrefix + "-" + genericPrefix + "-"); additionalPrefixes.push(parentPrefix + "-" + prefix + "-"); } initializePropertiesFromCss(container, this, genericPrefix + "-", this.hasUserValues, false, additionalPrefixes); if (this._otherStyling) { this._otherStyling(container, component, parent); } this._inStyling = false; }; /** * Called by the UI framework to provide a UI container for rendering this control. * @param container * The UI container element. */ IgcDoughnutChartComponent.prototype.provideContainer = function (container) { this.i.provideContainer(container); }; /** * Called when the control has been resized. */ IgcDoughnutChartComponent.prototype.notifyResized = function () { this.i.notifyResized(); }; /** * Gets the ID of the UI container. */ IgcDoughnutChartComponent.prototype.getContainerID = function () { var iv = this.i.bd(); return (iv); }; /** * Gets the center coordinates of the doughnut chart's center presenter. */ IgcDoughnutChartComponent.prototype.getCenterCoordinates = function () { var iv = this.i.cf(); return fromPoint(iv); }; /** * Gets the hole radius of the doughnut chart's center presenter. */ IgcDoughnutChartComponent.prototype.getHoleRadius = function () { var iv = this.i.a2(); return (iv); }; /** * Use to force the doughnut chart to finish any deferred work before printing or evaluating its visual. * This should only be called if the visual of the doughnut chart needs to be synchronously saved or evaluated. * Calling this method too often will hinder the performance of the doughnut chart. */ IgcDoughnutChartComponent.prototype.flush = function () { this.i.bk(); }; /** * Returns the chart visuals expressed as a serialized string. */ IgcDoughnutChartComponent.prototype.exportSerializedVisualData = function () { var iv = this.i.bc(); return (iv); }; IgcDoughnutChartComponent.prototype.notifyInsertItem = function (source_, index, newItem) { this.i.bm(source_, index, newItem); }; IgcDoughnutChartComponent.prototype.notifySetItem = function (source_, index, oldItem, newItem) { this.i.bp(source_, index, oldItem, newItem); }; /** * Used to manually notify the chart that the data source has reset or cleared its items. */ IgcDoughnutChartComponent.prototype.notifyClearItems = function (source_) { this.i.bl(source_); }; IgcDoughnutChartComponent.prototype.notifyRemoveItem = function (source_, index, oldItem) { this.i.bn(source_, index, oldItem); }; Object.defineProperty(IgcDoughnutChartComponent.prototype, "sliceClick", { /** * Raised when the slice is clicked. */ get: function () { return this._sliceClick; }, set: function (ev) { var _this = this; if (this._sliceClick_wrapped !== null) { this.i.sliceClick = delegateRemove(this.i.sliceClick, this._sliceClick_wrapped); this._sliceClick_wrapped = null; this._sliceClick = null; } this._sliceClick = ev; this._sliceClick_wrapped = function (o, e) { var outerArgs = new IgcSliceClickEventArgs(); outerArgs._provideImplementation(e); if (_this.beforeSliceClick) { _this.beforeSliceClick(_this, outerArgs); } if (_this._sliceClick) { _this._sliceClick(_this, outerArgs); } }; this.i.sliceClick = delegateCombine(this.i.sliceClick, this._sliceClick_wrapped); ; }, enumerable: false, configurable: true }); Object.defineProperty(IgcDoughnutChartComponent.prototype, "holeDimensionsChanged", { /** * Raised when the dimensions (center point or radius) of the doughnut hole change. */ get: function () { return this._holeDimensionsChanged; }, set: function (ev) { var _this = this; if (this._holeDimensionsChanged_wrapped !== null) { this.i.holeDimensionsChanged = delegateRemove(this.i.holeDimensionsChanged, this._holeDimensionsChanged_wrapped); this._holeDimensionsChanged_wrapped = null; this._holeDimensionsChanged = null; } this._holeDimensionsChanged = ev; this._holeDimensionsChanged_wrapped = function (o, e) { var outerArgs = new IgcHoleDimensionsChangedEventArgs(); outerArgs._provideImplementation(e); if (_this.beforeHoleDimensionsChanged) { _this.beforeHoleDimensionsChanged(_this, outerArgs); } if (_this._holeDimensionsChanged) { _this._holeDimensionsChanged(_this, outerArgs); } }; this.i.holeDimensionsChanged = delegateCombine(this.i.holeDimensionsChanged, this._holeDimensionsChanged_wrapped); ; }, enumerable: false, configurable: true }); IgcDoughnutChartComponent._observedAttributesIgcDoughnutChartComponent = null; IgcDoughnutChartComponent.htmlTagName = "igc-doughnut-chart"; IgcDoughnutChartComponent._isElementRegistered = false; return IgcDoughnutChartComponent; }(IgcHTMLElement)); export { IgcDoughnutChartComponent };