igniteui-react-charts
Version:
Ignite UI React charting components for building rich data visualizations using TypeScript APIs.
123 lines (122 loc) • 3.69 kB
JavaScript
import * as React from 'react';
import { ReactRenderer } from "igniteui-react-core";
import { TypeRegistrar } from "igniteui-react-core";
import { IgrPieChartBase } from './igr-pie-chart-base';
import { DataChartStylingDefaults } from './DataChartStylingDefaults';
import { XamPieChart } from './XamPieChart';
import { NamePatcher } from "igniteui-react-core";
export class IgrPieChart extends IgrPieChartBase {
set height(value) {
this._height = value;
if (this._elRef) {
this._elRef.style.height = value;
this._chart.notifyContainerResized();
}
}
get height() {
return this._height;
}
set width(value) {
this._width = value;
if (this._elRef) {
this._elRef.style.width = value;
this._chart.notifyContainerResized();
}
}
get width() {
return this._width;
}
_getMainRef(ref) {
this._elRef = ref;
}
render() {
let div = React.createElement("div", {
className: "ig-pie-chart igr-pie-chart",
ref: this._getMainRef
});
return div;
}
constructor(props) {
super(props);
this._dataSource = null;
if (this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this));
}
this._getMainRef = this._getMainRef.bind(this);
let container;
if (document) {
container = document.createElement("div");
container.style.display = "block";
container.style.width = "100%";
container.style.height = "100%";
}
var root;
root = container;
var ren = new ReactRenderer(root, document, true, DataChartStylingDefaults);
this.container = ren.getWrapper(container);
this._wrapper = ren;
var chart = this.i;
this._chart = chart;
chart.provideContainer(ren);
this.bindData();
chart.notifyContainerResized();
ren.addSizeWatcher(() => {
this._chart.notifyContainerResized();
});
}
destroy() {
this._chart.destroy();
this._wrapper.destroy();
}
componentDidMount() {
super.componentDidMount();
this._elRef.style.width = this._width ? this._width : "";
this._elRef.style.height = this._height ? this._height : "";
this._elRef.appendChild(this.container.getNativeElement());
this._styling(this._elRef, this);
this._chart.notifyContainerResized();
}
componentWillUnmount() {
}
createImplementation() {
return new XamPieChart();
}
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);
}
}
set dataSource(value) {
this._dataSource = value;
this.bindData();
}
get dataSource() {
return this._dataSource;
}
bindData() {
if (this._chart != null && this._chart !== undefined) {
this._chart.itemsSource = this._dataSource;
}
}
/**
* Gets or sets the legend used for the current chart.
*/
get legend() {
if (this.i.legend != null)
return this.i.legend.externalObject;
}
set legend(v) {
if (v != undefined && v != null)
this.i.legend = v.i;
}
}