igniteui-react-charts
Version:
Ignite UI React charting components for building rich data visualizations using TypeScript APIs.
205 lines (201 loc) • 7.17 kB
JavaScript
import * as React from 'react';
import { isValidProp, getModifiedProps, toSpinal, initializePropertiesFromCss, NamePatcher } from "igniteui-react-core";
import { FontDefaults } from "igniteui-react-core";
export const LegendBaseStyles = [`
:host {
display: block;
}
.ig-legend {
border: none;
border: var(--legend-border, none);
overflow: auto;
overflow: var(--legend-item-overflow, auto);
}
.ig-chart-legend-item-text {
vertical-align: middle;
vertical-align: var(--legend-item-vertical-align, middle);
}
.ig-chart-legend-items-list
{
padding: 5px;
padding: var(--legend-item-padding, 5px);
margin: 0px;
margin: var(--legend-item-margin, 0px);
background-color: transparent;
background-color: var(--legend-list-background-color, transparent);
font: ${FontDefaults.legendLabelsFontSize}px ${FontDefaults.legendLabelsFontFamily};
font: var(--legend-item-font, ${FontDefaults.legendLabelsFontSize}px ${FontDefaults.legendLabelsFontFamily});
color: ${FontDefaults.legendLabelsBrush.fill};
color: var(--text-color, ${FontDefaults.legendLabelsBrush.fill});
}
.ig-chart-legend-item-badge, .ui-chart-legend-item-badge, canvas
{
vertical-align: middle;
vertical-align: var(--legend-item-badge-vertical-align, middle);
}
.ig-chart-legend-item
{
background-color: transparent;
background-color: var(--legend-item-background-color, transparent);
}
`];
/**
* Represents the base class for a legend in IgxDataChartComponent.
*/
export let IgrLegendBase = /*@__PURE__*/ (() => {
class IgrLegendBase extends React.Component {
get i() {
return this._implementation;
}
onImplementationCreated() {
}
constructor(props) {
super(props);
this._zoneRunner = null;
this.__p = null;
this._hasUserValues = new Set();
this._stylingContainer = null;
this._stylingParent = null;
this._inStyling = false;
IgrLegendBase.ensureCss();
if (this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(this));
}
this._implementation = this.createImplementation();
this._implementation.externalObject = this;
this.onImplementationCreated();
if (document) {
//introduce styles globally for now.
}
}
static ensureCss() {
if (!document) {
return;
}
if (IgrLegendBase._checked.has(document)) {
return;
}
for (let i = 0; i < document.head.children.length; i++) {
let child = document.head.children[i];
if (child.tagName &&
child.tagName.toLowerCase() == "style" && child.hasAttribute("data-ig-legend-style")) {
return;
}
}
let style = document.createElement("style");
style.textContent = LegendBaseStyles[0];
style.setAttribute('data-ig-legend-style', 'true');
document.head.appendChild(style);
IgrLegendBase._checked.set(document, true);
}
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;
}
/**
* Gets if the legend is item-wise.
*/
get isItemwise() {
return this.i.isItemwise;
}
/**
* Gets if the legend is a financial legend.
*/
get isFinancial() {
return this.i.isFinancial;
}
findByName(name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(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("LegendBase");
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;
}
/**
* Use to force the Legend to check for differences in text content.
*/
flushTextContentChangedCheck() {
this.i.flushTextContentChangedCheck();
}
/**
* Returns the legend visuals expressed as a serialized string.
*/
exportSerializedVisualData() {
let iv = this.i.exportSerializedVisualData();
return (iv);
}
}
IgrLegendBase._checked = /*@__PURE__*/ new WeakMap();
return IgrLegendBase;
})();