UNPKG

igniteui-react-charts

Version:

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

128 lines (127 loc) 3.31 kB
import * as React from 'react'; import { IgrLegendBase } from './igr-legend-base'; import { Legend } from "./Legend"; import { LegendOrientation_$type } from './LegendOrientation'; import { ReactRenderer } from "igniteui-react-core"; import { DataChartStylingDefaults } from './DataChartStylingDefaults'; import { ensureEnum } from "igniteui-react-core"; /** * Represents a legend in a IgxDataChartComponent control. * * The `Legend` helps end-user identify visuals of chart series with contextual information related to the data plotted in the chart control. * * ```ts * <IgrDataChart * dataSource={this.data} * ref={this.onChartRef} width="100%" height="400px"> * <IgrCategoryXAxis name="xAxis" label="Country" /> * <IgrNumericYAxis name="yAxis" minimumValue={0} /> * * <IgrLegend ref={this.onLegendRef} * orientation="Horizontal" /> * ``` * * ```ts * public onChartRef(chart: IgrDataChart) { * this.chart = chart; * if (this.legend) { * this.chart.legend = this.legend; * } * } * * public onLegendRef(legend: IgrLegend) { * this.legend = legend; * if (this.chart) { * this.chart.legend = this.legend; * } * } * ``` */ export class IgrLegend extends IgrLegendBase { render() { let div = React.createElement("div", { className: "ig-legend igr-legend", ref: this._getMainRef }); return div; } _getMainRef(div) { this._elRef = div; } componentDidMount() { super.componentDidMount(); this.initializeContent(); } initializeContent() { this._elRef.appendChild(this.container.getNativeElement()); } constructor(props) { super(props); 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; this.i.provideContainer(ren); } destroy() { this._wrapper.destroy(); this.i.provideContainer(null); } createImplementation() { return new Legend(); } get i() { return this._implementation; } /** * Gets or sets the current Legend object's orientation. * * ```ts * <IgrLegend ref={this.onLegendRef} * orientation="Horizontal" /> * ``` */ get orientation() { return this.i.bg; } set orientation(v) { this.i.bg = ensureEnum(LegendOrientation_$type, v); } /** * Gets or sets color of text * * ```ts * <IgrLegend ref={this.onLegendRef} * textColor= "red" /> * ``` */ get textColor() { return this.i.bm; } set textColor(v) { this.i.bm = v; } /** * Gets or sets style of text. * * ```ts * <IgrLegend ref={this.onLegendRef} * textStyle= "9pt Verdana" /> * ``` */ get textStyle() { return this.i.bn; } set textStyle(v) { this.i.bn = v; } }