UNPKG

igniteui-react-charts

Version:

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

685 lines (683 loc) 20.1 kB
import * as React from 'react'; import { delegateCombine, delegateRemove, TypeRegistrar } from "igniteui-react-core"; import { LabelsPosition_$type } from "./LabelsPosition"; import { Visibility_$type } from "igniteui-react-core"; import { Style } from "igniteui-react-core"; import { LeaderLineType_$type } from "./LeaderLineType"; import { OthersCategoryType_$type } from "igniteui-react-core"; import { IgrPropertyUpdatedEventArgs } from "igniteui-react-core"; import { ensureEnum, arrayFindByName, toBrushCollection, fromBrushCollection, isValidProp, getModifiedProps, ensureBool, toSpinal, initializePropertiesFromCss, NamePatcher, brushToString, stringToBrush } from "igniteui-react-core"; /** * Represents a * IgxDoughnutChartComponent base series. */ export class IgrRingSeriesBase extends React.Component { createImplementation() { return null; } set dataSource(value) { this._dataSource = value; this.bindData(); } get dataSource() { return this._dataSource; } bindData() { if (this.i != null && this.i !== undefined) { this.i.itemsSource = this._dataSource; } } get i() { return this._implementation; } onImplementationCreated() { } constructor(props) { super(props); this._dataSource = null; this._tooltipTemplate = null; this._tooltipContent = null; this._tooltipContainerTemplate = null; this._showDefaultTooltip = false; this.__p = null; this._hasUserValues = new Set(); this._stylingContainer = null; this._stylingParent = null; this._inStyling = false; this._propertyUpdated = null; this._propertyUpdated_wrapped = null; if (this._styling) { NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this)); } this._implementation = this.createImplementation(); this._implementation.externalObject = this; this.onImplementationCreated(); } componentDidMount() { for (const p of Object.keys(this.props)) { if (isValidProp(this, p)) { { this[p] = this.props[p]; } } } } shouldComponentUpdate(nextProps, nextState) { const mod = getModifiedProps(this.props, nextProps); for (const p of Object.keys(mod)) { if (isValidProp(this, p)) { this[p] = mod[p]; } } return true; } render() { return null; } static _createFromInternal(internal) { if (!internal) { return null; } if (!internal.$type) { return null; } let name = internal.$type.name; let externalName = "Igr" + name; if (!TypeRegistrar.isRegistered(externalName)) { return null; } return TypeRegistrar.create(externalName); } 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; } set tooltipTemplate(value) { this._tooltipTemplate = value; if (value == null) { if (this._tooltipContent !== null) { //this._tooltipContent.destroy(); this._tooltipContent = null; } } if (this._tooltipContent != null) { this._tooltipContent.template = this._tooltipTemplate; } else { if (this.owner != null) { this.owner._ensureTooltipCreated(this); } } } get tooltipTemplate() { return this._tooltipTemplate; } set tooltipContainerTemplate(value) { this._tooltipContainerTemplate = value; if (this._tooltipContent != null) { this._tooltipContent.instance.containerTemplate = this._tooltipContainerTemplate; } } get tooltipContainerTemplate() { return this._tooltipContainerTemplate; } _ensureTooltipCreated(createTooltip, createWrapper) { if (this._tooltipTemplate == null) { this.i.toolTip = null; } if (this._tooltipContent == null && this._tooltipTemplate != null) { let tooltip = createTooltip(); if (tooltip == null) { return; } this._tooltipContent = tooltip; tooltip.tooltipTemplate = this._tooltipTemplate; this.i.toolTip = createWrapper(tooltip); } } _ensureTooltipDestroyed() { if (this._tooltipContent !== null) { //this._tooltipContent.destroy(); this._tooltipContent = null; } } /** * Gets or sets whether default tooltip will be shown. */ get showDefaultTooltip() { return this._showDefaultTooltip; } set showDefaultTooltip(v) { this._showDefaultTooltip = ensureBool(v); } sychronizeCollections() { } /** * Gets or Sets the property name that contains the values. */ get valueMemberPath() { return this.i.cs; } set valueMemberPath(v) { this.i.cs = v; } /** * Gets or sets the property name that contains the labels. */ get labelMemberPath() { return this.i.bp; } set labelMemberPath(v) { this.i.bp = v; } /** * Gets or sets the property name that contains the legend labels. */ get legendLabelMemberPath() { return this.i.b3; } set legendLabelMemberPath(v) { this.i.b3 = v; } /** * Gets or sets the position of chart labels. */ get labelsPosition() { return this.i.an; } set labelsPosition(v) { this.i.an = ensureEnum(LabelsPosition_$type, v); } /** * Gets or sets whether the leader lines are visible. */ get leaderLineVisibility() { return this.i.en; } set leaderLineVisibility(v) { this.i.en = ensureEnum(Visibility_$type, v); } /** * Gets or sets the fill brush. */ get leaderLineFill() { return this.i.ei ? this.i.ei.fill : null; } set leaderLineFill(v) { this.ensureLeaderLineStyle(); this.i.ei.fill = v; } /** * Gets or sets the stroke brush. */ get leaderLineStroke() { return this.i.ei ? this.i.ei.stroke : null; } set leaderLineStroke(v) { this.ensureLeaderLineStyle(); this.i.ei.stroke = v; } /** * Gets or sets the stroke thickness. */ get leaderLineStrokeThickness() { return this.i.ei ? this.i.ei.strokeThickness : NaN; } set leaderLineStrokeThickness(v) { this.ensureLeaderLineStyle(); this.i.ei.strokeThickness = +v; } /** * Gets or sets the opacity. */ get leaderLineOpacity() { return this.i.ei ? this.i.ei.opacity : NaN; } set leaderLineOpacity(v) { this.ensureLeaderLineStyle(); this.i.ei.opacity = +v; } ensureLeaderLineStyle() { if (this.i.ei) { return; } this.i.ei = new Style(); } /** * Gets or sets what type of leader lines will be used for the outside end labels. */ get leaderLineType() { return this.i.ao; } set leaderLineType(v) { this.i.ao = ensureEnum(LeaderLineType_$type, v); } /** * Gets or sets the margin between a label and its leader line. The default is 6 pixels. */ get leaderLineMargin() { return this.i.a7; } set leaderLineMargin(v) { this.i.a7 = +v; } /** * Gets or sets the threshold value that determines if slices are grouped into the Others slice. */ get othersCategoryThreshold() { return this.i.a8; } set othersCategoryThreshold(v) { this.i.a8 = +v; } /** * Gets or sets whether to use numeric or percent-based threshold value. */ get othersCategoryType() { return this.i.ap; } set othersCategoryType(v) { this.i.ap = ensureEnum(OthersCategoryType_$type, v); } /** * Gets or sets the label of the Others slice. */ get othersCategoryText() { return this.i.ca; } set othersCategoryText(v) { this.i.ca = v; } /** * Sets or gets a function which takes an object that produces a formatted label for displaying in the chart. */ get formatLabel() { return this.i.aq; } set formatLabel(v) { this.i.aq = v; } /** * Sets or gets a function which takes an object that produces a formatted label for displaying in the chart's legend. */ get formatLegendLabel() { return this.i.ar; } set formatLegendLabel(v) { this.i.ar = v; } /** * Gets or sets the label format string to use for the label. */ get labelFormat() { return this.i.bl; } set labelFormat(v) { this.i.bl = v; } /** * Gets or sets the format specifiers to use with the LabelFormat string. */ get labelFormatSpecifiers() { return this.i.ag; } set labelFormatSpecifiers(v) { if (v && !Array.isArray(v) && typeof (v) == "string") { const re = /\s*(?:,|\s|$)\s*/gm; v = v.split(re); } this.i.ag = v; } /** * Gets or sets the label format string to use for the label. */ get othersLabelFormat() { return this.i.ce; } set othersLabelFormat(v) { this.i.ce = v; } /** * Gets or sets the format specifiers to use with the OthersLabelFormat string. */ get othersLabelFormatSpecifiers() { return this.i.aj; } set othersLabelFormatSpecifiers(v) { if (v && !Array.isArray(v) && typeof (v) == "string") { const re = /\s*(?:,|\s|$)\s*/gm; v = v.split(re); } this.i.aj = v; } /** * Gets or sets the label format string to use for the label. */ get legendLabelFormat() { return this.i.b0; } set legendLabelFormat(v) { this.i.b0 = v; } /** * Gets or sets the format specifiers to use with the LegendLabelFormat string. */ get legendLabelFormatSpecifiers() { return this.i.ah; } set legendLabelFormatSpecifiers(v) { if (v && !Array.isArray(v) && typeof (v) == "string") { const re = /\s*(?:,|\s|$)\s*/gm; v = v.split(re); } this.i.ah = v; } /** * Gets or sets the label format string to use for the label. */ get legendOthersLabelFormat() { return this.i.b5; } set legendOthersLabelFormat(v) { this.i.b5 = v; } /** * Gets or sets the format specifiers to use with the LegendOthersLabelFormat string. */ get legendOthersLabelFormatSpecifiers() { return this.i.ai; } set legendOthersLabelFormatSpecifiers(v) { if (v && !Array.isArray(v) && typeof (v) == "string") { const re = /\s*(?:,|\s|$)\s*/gm; v = v.split(re); } this.i.ai = v; } /** * Gets or sets the pixel amount by which the labels are offset from the edge of the slices. */ get labelExtent() { return this.i.a6; } set labelExtent(v) { this.i.a6 = +v; } /** * Gets or sets the starting angle of the chart. * The default zero value is equivalent to 3 o'clock. */ get startAngle() { return this.i.ba; } set startAngle(v) { this.i.ba = +v; } /** * Gets or sets the fill brush. */ get othersCategoryFill() { return this.i.ej ? this.i.ej.fill : null; } set othersCategoryFill(v) { this.ensureOthersCategoryStyle(); this.i.ej.fill = v; } /** * Gets or sets the stroke brush. */ get othersCategoryStroke() { return this.i.ej ? this.i.ej.stroke : null; } set othersCategoryStroke(v) { this.ensureOthersCategoryStyle(); this.i.ej.stroke = v; } /** * Gets or sets the stroke thickness. */ get othersCategoryStrokeThickness() { return this.i.ej ? this.i.ej.strokeThickness : NaN; } set othersCategoryStrokeThickness(v) { this.ensureOthersCategoryStyle(); this.i.ej.strokeThickness = +v; } /** * Gets or sets the opacity. */ get othersCategoryOpacity() { return this.i.ej ? this.i.ej.opacity : NaN; } set othersCategoryOpacity(v) { this.ensureOthersCategoryStyle(); this.i.ej.opacity = +v; } ensureOthersCategoryStyle() { if (this.i.ej) { return; } this.i.ej = new Style(); } /** * Gets or sets the fill brush. */ get selectedSliceFill() { return this.i.ek ? this.i.ek.fill : null; } set selectedSliceFill(v) { this.ensureSelectedStyle(); this.i.ek.fill = v; } /** * Gets or sets the stroke brush. */ get selectedSliceStroke() { return this.i.ek ? this.i.ek.stroke : null; } set selectedSliceStroke(v) { this.ensureSelectedStyle(); this.i.ek.stroke = v; } /** * Gets or sets the stroke thickness. */ get selectedSliceStrokeThickness() { return this.i.ek ? this.i.ek.strokeThickness : NaN; } set selectedSliceStrokeThickness(v) { this.ensureSelectedStyle(); this.i.ek.strokeThickness = +v; } /** * Gets or sets the opacity. */ get selectedSliceOpacity() { return this.i.ek ? this.i.ek.opacity : NaN; } set selectedSliceOpacity(v) { this.ensureSelectedStyle(); this.i.ek.opacity = +v; } ensureSelectedStyle() { if (this.i.ek) { return; } this.i.ek = new Style(); } /** * Gets or sets the palette of brushes to use for coloring the slices. */ get brushes() { return fromBrushCollection(this.i.ak); } set brushes(v) { this.i.ak = toBrushCollection(v); } /** * Gets or sets the palette of brushes to use for outlines on the slices. */ get outlines() { return fromBrushCollection(this.i.al); } set outlines(v) { this.i.al = toBrushCollection(v); } /** * Gets or sets the color for labels rendered outside of the pie chart. */ get labelOuterColor() { return brushToString(this.i.eg); } set labelOuterColor(v) { this.i.eg = stringToBrush(v); } /** * Gets or sets the color for labels rendered inside of the pie chart. */ get labelInnerColor() { return brushToString(this.i.ef); } set labelInnerColor(v) { this.i.ef = stringToBrush(v); } /** * Gets or sets the text style to use for labels. */ get textStyle() { return this.i.co; } set textStyle(v) { this.i.co = v; } /** * Gets or sets whether all surface interactions with the plot area should be disabled. */ get isSurfaceInteractionDisabled() { return this.i.a3; } set isSurfaceInteractionDisabled(v) { this.i.a3 = ensureBool(v); } /** * Gets or sets the scaling factor of the chart's radius. Value between 0 and 1. */ get radiusFactor() { return this.i.a9; } set radiusFactor(v) { this.i.a9 = +v; } findByName(name) { if (this.findEphemera) { if (name && name.indexOf("@@e:") == 0) { return this.findEphemera(name); } } if (this.legend && this.legend.name && this.legend.name == name) { return this.legend; } if (this.labelFormatSpecifiers != null && arrayFindByName(this.labelFormatSpecifiers, name)) { return arrayFindByName(this.labelFormatSpecifiers, name); } if (this.othersLabelFormatSpecifiers != null && arrayFindByName(this.othersLabelFormatSpecifiers, name)) { return arrayFindByName(this.othersLabelFormatSpecifiers, name); } if (this.legendLabelFormatSpecifiers != null && arrayFindByName(this.legendLabelFormatSpecifiers, name)) { return arrayFindByName(this.legendLabelFormatSpecifiers, name); } if (this.legendOthersLabelFormatSpecifiers != null && arrayFindByName(this.legendOthersLabelFormatSpecifiers, name)) { return arrayFindByName(this.legendOthersLabelFormatSpecifiers, 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("RingSeriesBase"); 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.c5(container); } /** * Event raised when a property (including "effective" and non-dependency property) value changes. */ get propertyUpdated() { return this._propertyUpdated; } set propertyUpdated(ev) { if (this._propertyUpdated_wrapped !== null) { this.i.propertyUpdated = delegateRemove(this.i.propertyUpdated, this._propertyUpdated_wrapped); this._propertyUpdated_wrapped = null; this._propertyUpdated = null; } this._propertyUpdated = ev; this._propertyUpdated_wrapped = (o, e) => { let outerArgs = new IgrPropertyUpdatedEventArgs(); outerArgs._provideImplementation(e); if (this.beforePropertyUpdated) { this.beforePropertyUpdated(this, outerArgs); } if (this._propertyUpdated) { this._propertyUpdated(this, outerArgs); } }; this.i.propertyUpdated = delegateCombine(this.i.propertyUpdated, this._propertyUpdated_wrapped); ; } }