igniteui-webcomponents-charts
Version:
Ignite UI Web Components charting components for building rich data visualizations using TypeScript APIs.
632 lines (623 loc) • 24.9 kB
JavaScript
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";
let IgcDoughnutChartComponent = /*@__PURE__*/ (() => {
class IgcDoughnutChartComponent extends IgcHTMLElement {
set height(value) {
this._height = value;
this.style.height = value;
this.notifyResized();
}
get height() {
return this._height;
}
set width(value) {
this._width = value;
this.style.width = value;
this.notifyResized();
}
get width() {
return this._width;
}
constructor() {
super();
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, (c) => c.i, (i) => {
i.owner = this;
// (<any>i)._provideRenderer(this._dataSource);
if (this.parentElement) {
i._styling(this, this, this);
}
this._ensureDefaultTooltip(i);
this._ensureTooltipCreated(i);
}, (i) => {
//(<any>i)._provideRenderer(null);
});
chart.provideContainer(this._renderer);
let mut = new MutationObserver((list) => {
for (var mutation of list) {
if (mutation.type == 'childList') {
this.updateContentChildren();
}
}
});
mut.observe(this, {
childList: true
});
this._renderer.addSizeWatcher(() => {
this._chart.notifyResized();
});
}
ngOnDestroy() {
this._chart.destroy();
this._wrapper.destroy();
}
onImplementationCreated() {
}
createImplementation() {
return new XamDoughnutChart();
}
get i() {
return this._implementation;
}
createSeriesComponent(type) {
if (TypeRegistrar.isRegistered(type)) {
let 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);
}
}
updateContentChildren() {
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();
}
}
disconnectedCallback() {
this._disconnected = true;
if (this.i) {
this.i.onDetachedFromUI();
}
}
connectedCallback() {
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 (let i = 0; i < this.actualSeries.length; i++) {
let s = this.actualSeries[i];
s._styling(this, this, this);
}
this.updateContentChildren();
this.afterContentInit();
}
afterContentInit() {
if (TypeRegistrar.isRegistered("IgcDoughnutChartDefaultTooltipsComponent")) {
let cr = TypeRegistrar.create("IgcDoughnutChartDefaultTooltipsComponent");
this._defaultTooltips = cr;
cr.onContentReady = () => {
this._onDefaultTooltipsReady(cr);
};
}
this.i.notifyResized();
}
/**
* A collection or manually added series for the chart.
*/
get series() {
if (this._series === null) {
let coll = new IgcRingSeriesCollection();
let inner = coll._innerColl;
inner.addListener((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;
}
_ensureTooltipCreated(series) {
series._ensureTooltipCreated(() => this.createTooltip(), (ele) => {
let wrapper = new WebComponentWrapper(ele, this._renderer);
wrapper.updateToolTip = ele.updateToolTip;
wrapper.hideToolTip = ele.hideToolTip;
return wrapper;
});
}
_ensureDefaultTooltip(series) {
if (this._defaultTooltips == null) {
return;
}
this._defaultTooltips["ensureDefaultTooltip"](series);
}
_onDefaultTooltipsReady(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]);
}
}
}
}
createTooltip() {
if (!TypeRegistrar.isRegistered("IgcTooltipContainerComponent")) {
return null;
}
let cr = TypeRegistrar.create("IgcTooltipContainerComponent");
let ele = cr;
let self = this;
ele.updateToolTip = function (c) {
if (c.externalObject) {
c = c.externalObject;
}
else {
let 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;
}
_enqueueSetAttribute(attrName, attrValue) {
this._queuedSetAttributes.push({ attrName: attrName, attrValue: attrValue });
}
_flushQueuedAttributes() {
this._settingAttributes = true;
for (let i = 0; i < this._queuedSetAttributes.length; i++) {
this.setAttribute(this._queuedSetAttributes[i].attrName, this._queuedSetAttributes[i].attrValue);
}
this._settingAttributes = false;
this._queuedSetAttributes.length = 0;
}
_a(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;
}
static get observedAttributes() {
if (IgcDoughnutChartComponent._observedAttributesIgcDoughnutChartComponent == null) {
let names = getAllPropertyNames(IgcDoughnutChartComponent);
for (let i = 0; i < names.length; i++) {
names[i] = toSpinal(names[i]);
}
IgcDoughnutChartComponent._observedAttributesIgcDoughnutChartComponent = names;
}
return IgcDoughnutChartComponent._observedAttributesIgcDoughnutChartComponent;
}
attributeChangedCallback(name, oldValue, newValue) {
if (this._settingAttributes) {
return;
}
let setName = fromSpinal(name);
this._updatingFromAttribute = true;
this[setName] = newValue;
this._updatingFromAttribute = false;
}
static register() {
if (!IgcDoughnutChartComponent._isElementRegistered) {
IgcDoughnutChartComponent._isElementRegistered = true;
RegisterElementHelper.registerElement(IgcDoughnutChartComponent.htmlTagName, IgcDoughnutChartComponent);
}
}
/**
* Gets or sets whether the slices can be selected.
*/
get allowSliceSelection() {
return this.i.aw;
}
set allowSliceSelection(v) {
this.i.aw = ensureBool(v);
this._a("allowSliceSelection", this.i.aw);
}
/**
* Gets or sets whether all surface interactions with the plot area should be disabled.
*/
get isSurfaceInteractionDisabled() {
return this.i.ax;
}
set isSurfaceInteractionDisabled(v) {
this.i.ax = ensureBool(v);
this._a("isSurfaceInteractionDisabled", this.i.ax);
}
/**
* Gets or sets whether the slices can be exploded.
*/
get allowSliceExplosion() {
return this.i.av;
}
set allowSliceExplosion(v) {
this.i.av = ensureBool(v);
this._a("allowSliceExplosion", this.i.av);
}
/**
* Gets or sets the inner extent of the doughnut chart. It is percent from the outer ring's radius.
*/
get innerExtent() {
return this.i.a3;
}
set innerExtent(v) {
this.i.a3 = +v;
this._a("innerExtent", this.i.a3);
}
/**
* Gets or sets the fill brush.
*/
get selectedSliceFill() {
return this.i.cg ? this.i.cg.fill : null;
}
set selectedSliceFill(v) {
this.ensureSelectedStyle();
this.i.cg.fill = v;
}
/**
* Gets or sets the stroke brush.
*/
get selectedSliceStroke() {
return this.i.cg ? this.i.cg.stroke : null;
}
set selectedSliceStroke(v) {
this.ensureSelectedStyle();
this.i.cg.stroke = v;
}
/**
* Gets or sets the stroke thickness.
*/
get selectedSliceStrokeThickness() {
return this.i.cg ? this.i.cg.strokeThickness : NaN;
}
set selectedSliceStrokeThickness(v) {
this.ensureSelectedStyle();
this.i.cg.strokeThickness = +v;
this._a("selectedSliceStrokeThickness", this.i.cg.strokeThickness);
}
/**
* Gets or sets the opacity.
*/
get selectedSliceOpacity() {
return this.i.cg ? this.i.cg.opacity : NaN;
}
set selectedSliceOpacity(v) {
this.ensureSelectedStyle();
this.i.cg.opacity = +v;
this._a("selectedSliceOpacity", this.i.cg.opacity);
}
ensureSelectedStyle() {
if (this.i.cg) {
return;
}
this.i.cg = new Style();
}
/**
* 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 pixelScalingRatio() {
return this.i.a4;
}
set pixelScalingRatio(v) {
this.i.a4 = +v;
this._a("pixelScalingRatio", this.i.a4);
}
/**
* 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 actualPixelScalingRatio() {
return this.i.a1;
}
set actualPixelScalingRatio(v) {
this.i.a1 = +v;
this._a("actualPixelScalingRatio", this.i.a1);
}
findByName(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;
}
get hasUserValues() {
return this._hasUserValues;
}
__m(propertyName) {
if (!this._inStyling) {
this._hasUserValues.add(propertyName);
}
}
_styling(container, component, parent) {
if (this._inStyling) {
return;
}
this._inStyling = true;
this._stylingContainer = container;
this._stylingParent = component;
let genericPrefix = "";
let typeName = this.i.$type.name;
if (typeName.indexOf("Xam") === 0) {
typeName = typeName.substring(3);
}
genericPrefix = toSpinal("DoughnutChartComponent");
let additionalPrefixes = [];
let prefix = toSpinal(typeName);
additionalPrefixes.push(prefix + "-");
let 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);
}
let basePrefix = toSpinal(typeName);
additionalPrefixes.push(basePrefix + "-");
b = b.baseType;
}
if (parent) {
let parentTypeName = parent.i.$type.name;
if (parentTypeName.indexOf("Xam") === 0) {
parentTypeName = parentTypeName.substring(3);
}
let 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.
*/
provideContainer(container) {
this.i.provideContainer(container);
}
/**
* Called when the control has been resized.
*/
notifyResized() {
this.i.notifyResized();
}
/**
* Gets the ID of the UI container.
*/
getContainerID() {
let iv = this.i.bd();
return (iv);
}
/**
* Gets the center coordinates of the doughnut chart's center presenter.
*/
getCenterCoordinates() {
let iv = this.i.cf();
return fromPoint(iv);
}
/**
* Gets the hole radius of the doughnut chart's center presenter.
*/
getHoleRadius() {
let 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.
*/
flush() {
this.i.bk();
}
/**
* Returns the chart visuals expressed as a serialized string.
*/
exportSerializedVisualData() {
let iv = this.i.bc();
return (iv);
}
notifyInsertItem(source_, index, newItem) {
this.i.bm(source_, index, newItem);
}
notifySetItem(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.
*/
notifyClearItems(source_) {
this.i.bl(source_);
}
notifyRemoveItem(source_, index, oldItem) {
this.i.bn(source_, index, oldItem);
}
/**
* Raised when the slice is clicked.
*/
get sliceClick() {
return this._sliceClick;
}
set sliceClick(ev) {
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 = (o, e) => {
let 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);
;
}
/**
* Raised when the dimensions (center point or radius) of the doughnut hole change.
*/
get holeDimensionsChanged() {
return this._holeDimensionsChanged;
}
set holeDimensionsChanged(ev) {
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 = (o, e) => {
let 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);
;
}
}
IgcDoughnutChartComponent._observedAttributesIgcDoughnutChartComponent = null;
IgcDoughnutChartComponent.htmlTagName = "igc-doughnut-chart";
IgcDoughnutChartComponent._isElementRegistered = false;
return IgcDoughnutChartComponent;
})();
export { IgcDoughnutChartComponent };