igniteui-react-charts
Version:
Ignite UI React charting components for building rich data visualizations using TypeScript APIs.
472 lines (470 loc) • 18.2 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 } from "tslib";
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ReactRenderer, ReactWrapper } from "igniteui-react-core";
import { TypeRegistrar } from "igniteui-react-core";
import { DataPieChart } from './DataPieChart';
import { DataPieChartType_$type } from './DataPieChartType';
import { CategoryTransitionInMode_$type } from './CategoryTransitionInMode';
import { TransitionInSpeedType_$type } from './TransitionInSpeedType';
import { ensureEnum, ensureBool, NamePatcher } from "igniteui-react-core";
import { DataChartStylingDefaults } from './DataChartStylingDefaults';
import { DataSeriesType } from "igniteui-react-core";
import { IgrDataContext } from "igniteui-react-core";
import { IgrProportionalCategoryAngleAxis } from './igr-proportional-category-angle-axis';
import { IgrNumericRadiusAxis } from './igr-numeric-radius-axis';
import { IgrDataPieBaseChart } from './igr-data-pie-base-chart';
/**
* Represents a DataPie chart control that can plot DataPie data
*/
var IgrDataPieChart = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgrDataPieChart, _super);
function IgrDataPieChart(props) {
var _this = _super.call(this, props) || this;
_this._dataSource = null;
_this._defaultTooltips = null;
_this._uniqueTooltipId = 0;
if (_this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this));
}
_this._getMainRef = _this._getMainRef.bind(_this);
_this._tooltipRef = _this._tooltipRef.bind(_this);
_this._activeTooltipElements = new Map();
_this._activeTooltips = new Map();
_this._currentTooltips = [];
if (document) {
_this._container = document.createElement("div");
_this._container.style.display = "block";
_this._container.style.width = "100%";
_this._container.style.height = "100%";
}
var root;
root = _this._container;
if (_this._container != null) {
root = _this._container;
}
var ren = new ReactRenderer(root, document, true, DataChartStylingDefaults);
_this._wrapper = ren;
var chart = _this.i;
_this._chart = chart;
if (chart.angleAxis) {
var x = new IgrProportionalCategoryAngleAxis(null);
x._provideRenderer(ren);
x._implementation = chart.angleAxis;
chart.angleAxis.externalObject = x;
}
if (chart.valueAxis) {
var y = new IgrNumericRadiusAxis(null);
y._provideRenderer(ren);
y._implementation = chart.valueAxis;
chart.valueAxis.externalObject = y;
}
chart.provideContainer(ren);
_this.bindData();
chart.notifyResized();
ren.addSizeWatcher(function () {
_this._chart.notifyResized();
});
_this._initialized = true;
return _this;
}
Object.defineProperty(IgrDataPieChart.prototype, "height", {
get: function () {
return this._height;
},
set: function (value) {
this._height = value;
if (this._elRef) {
this._elRef.style.height = value;
this._chart.notifyResized();
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataPieChart.prototype, "width", {
get: function () {
return this._width;
},
set: function (value) {
this._width = value;
if (this._elRef) {
this._elRef.style.width = value;
this._chart.notifyResized();
}
},
enumerable: false,
configurable: true
});
IgrDataPieChart.prototype._tooltipRef = function (t) {
//console.log(t);
if (t === null) {
return;
}
if (t.currentOwner &&
t.currentOwner.tooltipTemplate) {
t.template = t.currentOwner.tooltipTemplate;
}
this._activeTooltips.set(t.currentOwner, t);
};
IgrDataPieChart.prototype._getMainRef = function (ref) {
this._elRef = ref;
};
IgrDataPieChart.prototype.render = function () {
// if (!this._childrenDiffer(this.props.children)) {
// let div = React.createElement("div", {
// ref: (ref) => {
// this._elRef = ref;
// },
// children: this.props.children
// });
// return div;
// } else {
var children = [];
if (this._currentTooltips && this._currentTooltips.length > 0) {
for (var i = 0; i < this._currentTooltips.length; i++) {
var t = this._currentTooltips[i];
if (this._activeTooltipElements.has(t)) {
children.push(this._activeTooltipElements.get(t));
}
else {
if (!TypeRegistrar.isRegistered("IgrTooltipContainer")) {
continue;
}
var Tooltip = TypeRegistrar.get("IgrTooltipContainer");
var tEle = React.createElement(Tooltip, {
ref: this._tooltipRef,
key: this._currentTooltips[i].key,
owner: this._currentTooltips[i]
});
var portal = ReactDOM.createPortal(tEle, t, this._currentTooltips[i].key);
this._activeTooltipElements.set(t, portal);
children.push(portal);
}
}
}
var div = React.createElement("div", {
className: "ig-data-pie-chart igr-data-pie-chart",
ref: this._getMainRef,
children: children
});
return div;
//}
};
IgrDataPieChart.prototype.componentDidMount = function () {
_super.prototype.componentDidMount.call(this);
this._elRef.style.width = this._width ? this._width : "";
this._elRef.style.height = this._height ? this._height : "";
this._elRef.appendChild(this._container);
this._chart.notifyResized();
this.initializeContent();
};
IgrDataPieChart.prototype.componentWillUnmount = function () {
};
IgrDataPieChart.prototype.destroy = function () {
this._chart.destroy();
this._wrapper.destroy();
};
IgrDataPieChart.prototype.createImplementation = function () {
return new DataPieChart();
};
Object.defineProperty(IgrDataPieChart.prototype, "i", {
get: function () {
return this._implementation;
},
enumerable: false,
configurable: true
});
IgrDataPieChart.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);
}
};
IgrDataPieChart.prototype.createSeries = function (type) {
switch (type) {
case DataSeriesType.Pie:
return this.createSeriesComponent('IgrRadialPieSeries');
case DataSeriesType.ItemToolTipLayer:
return this.createSeriesComponent('IgrItemToolTipLayer');
case DataSeriesType.CategoryToolTipLayer:
return this.createSeriesComponent('IgrCategoryToolTipLayer');
case DataSeriesType.CrosshairLayer:
return this.createSeriesComponent('IgrCrosshairLayer');
case DataSeriesType.FinalValueLayer:
return this.createSeriesComponent('IgrFinalValueLayer');
case DataSeriesType.CalloutLayer:
return this.createSeriesComponent('IgrCalloutLayer');
case DataSeriesType.CategoryHighlightLayer:
return this.createSeriesComponent('IgrCategoryHighlightLayer');
case DataSeriesType.CategoryItemHighlightLayer:
return this.createSeriesComponent('IgrCategoryItemHighlightLayer');
case DataSeriesType.DataToolTipLayer:
return this.createSeriesComponent('IgrDataToolTipLayer');
case DataSeriesType.ValueLayer:
return this.createSeriesComponent('IgrValueLayer');
default:
return this.createSeriesComponent('IgrRadialPieSeries');
}
};
Object.defineProperty(IgrDataPieChart.prototype, "dataSource", {
get: function () {
return this._dataSource;
},
set: function (value) {
this._dataSource = value;
this.bindData();
},
enumerable: false,
configurable: true
});
IgrDataPieChart.prototype.bindData = function () {
if (this._chart != null && this._chart !== undefined) {
this._chart.itemsSource = this._dataSource;
}
};
IgrDataPieChart.prototype.initializeContent = function () {
if (TypeRegistrar.isRegistered("IgrDataChartDefaultTooltips")) {
var d = TypeRegistrar.create("IgrDataChartDefaultTooltips");
this._defaultTooltips = d;
this._onDefaultTooltipsReady(d);
//this._container.appendChild(cr.location.nativeElement);
}
// supports angular themes or custom properties set in CSS
this._styling(this._elRef, this);
this._chart.notifyResized();
};
IgrDataPieChart.prototype.createTooltip = function () {
// if (!TypeRegistrar.isRegistered("IgrTooltipContainer")) {
// return null;
// }
// let Tooltip = TypeRegistrar.get("IgrTooltipContainer");
var wrapper = this._wrapper.createElement("div");
var ele = wrapper.getNativeElement();
ele.key = "__tooltip_" + this._uniqueTooltipId;
this._uniqueTooltipId++;
this._currentTooltips = this._currentTooltips.slice(0);
this._currentTooltips.push(ele);
//let element = React.createElement(Tooltip, );
//let portal = ReactDOM.createPortal(element, ele);
var self = this;
ele.updateToolTip = function (c, isSubContent) {
if (c.externalObject) {
c = c.externalObject;
}
else {
var ext = new IgrDataContext();
ext._implementation = c;
c = ext;
}
if (!isSubContent) {
if (ele.parentElement != self._container) {
if (ele.parentElement != null) {
ele.parentElement.removeChild(ele);
}
self._container.appendChild(ele);
}
}
else {
c.isSubContent = true;
}
if (self._activeTooltips.has(ele)) {
var t = self._activeTooltips.get(ele);
if (t.template === null &&
ele.tooltipTemplate !== null) {
t.template = ele.tooltipTemplate;
}
t.dataContext = c;
}
ele.style.display = "block";
return true;
};
ele.hideToolTip = function () {
ele.style.display = "none";
};
ele.style.display = "none";
this._updateTooltipState();
return ele;
};
IgrDataPieChart.prototype._ensureTooltipCreated = function (series) {
var _this = this;
series._ensureTooltipCreated(function () { return _this.createTooltip(); }, function (ele) {
var wrapper = new ReactWrapper(ele, _this._wrapper);
wrapper.updateToolTip = ele.updateToolTip;
wrapper.hideToolTip = ele.hideToolTip;
if (_this._activeTooltips.has(ele)) {
var tCont = _this._activeTooltips.get(ele);
tCont.template = ele.tooltipTemplate;
}
return wrapper;
});
};
IgrDataPieChart.prototype._createXAxis = function () {
var x = new IgrProportionalCategoryAngleAxis(null);
x._provideRenderer(this._wrapper);
return x.i;
};
IgrDataPieChart.prototype._createYAxis = function () {
var y = new IgrNumericRadiusAxis(null);
y.provideRenderer(this._wrapper);
return y.i;
};
IgrDataPieChart.prototype._ensureDefaultTooltip = function (series) {
if (this._defaultTooltips == null) {
return;
}
this._defaultTooltips["ensureDefaultTooltip"](series);
};
IgrDataPieChart.prototype._onDefaultTooltipsReady = function (cr) {
if (this.i.dataChart) {
var currSeries = this.i.dataChart.series;
for (var i = 0; i < currSeries.count; i++) {
if (currSeries.item(i).externalObject.showDefaultTooltip) {
this._ensureDefaultTooltip(currSeries.item(i).externalObject);
}
}
}
};
IgrDataPieChart.prototype._updateTooltipState = function () {
if (this._initialized) {
this.setState({ tooltips: this._currentTooltips });
}
};
Object.defineProperty(IgrDataPieChart.prototype, "transitionInDuration", {
/**
* Gets or sets the duration used for animating series plots when the chart is loading into view
*/
get: function () {
return this.i.amo;
},
set: function (v) {
this.i.amo = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataPieChart.prototype, "transitionOutDuration", {
/**
* Gets or sets the duration used for animating series plots when the series is leaving view
*/
get: function () {
return this.i.amp;
},
set: function (v) {
this.i.amp = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataPieChart.prototype, "transitionInEasingFunction", {
/**
* Gets or sets the easing function used for animating series plots when the chart is loading into view
* This can be set to one of the known values "linear" or "cubic," or it can be set to an easing function which takes a single numeric parameter and returns a number.
*/
get: function () {
return this.i.ami;
},
set: function (v) {
this.i.ami = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataPieChart.prototype, "transitionOutEasingFunction", {
/**
* Gets or sets the easing function used for animating series plots when the chart is loading into view
* This can be set to one of the known values "linear" or "cubic," or it can be set to an easing function which takes a single numeric parameter and returns a number.
*/
get: function () {
return this.i.amj;
},
set: function (v) {
this.i.amj = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataPieChart.prototype, "domainType", {
/**
* Gets the domain type of this chart
*/
get: function () {
return this.i.cc;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataPieChart.prototype, "chartType", {
/**
* Gets or sets the type of chart series to generate from the data.
*/
get: function () {
return this.i.amd;
},
set: function (v) {
this.i.amd = ensureEnum(DataPieChartType_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataPieChart.prototype, "isTransitionInEnabled", {
/**
* Gets or sets whether animation of series plots is enabled when the chart is loading into view
*/
get: function () {
return this.i.aml;
},
set: function (v) {
this.i.aml = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataPieChart.prototype, "transitionInMode", {
/**
* Gets or sets the method that determines how to animate series plots when the chart is loading into view
*/
get: function () {
return this.i.amb;
},
set: function (v) {
this.i.amb = ensureEnum(CategoryTransitionInMode_$type, v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrDataPieChart.prototype, "transitionInSpeedType", {
/**
* Gets or sets the arrival speed used for animating series plots when the chart is loading into view
*/
get: function () {
return this.i.amf;
},
set: function (v) {
this.i.amf = ensureEnum(TransitionInSpeedType_$type, v);
},
enumerable: false,
configurable: true
});
/**
* Export serialized visual data.
*/
IgrDataPieChart.prototype.exportSerializedVisualData = function () {
var iv = this.i.amr();
return (iv);
};
return IgrDataPieChart;
}(IgrDataPieBaseChart));
export { IgrDataPieChart };