igniteui-react-charts
Version:
Ignite UI React charting components for building rich data visualizations using TypeScript APIs.
317 lines (316 loc) • 14.3 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 * as React from 'react';
import { TypeRegistrar } from "igniteui-react-core";
function hasOpen(series) {
return series.openMemberPath;
}
function getOpenValue(series, item) {
return getItemValue(series, item, "openMemberPath");
}
function hasHigh(series) {
return series.highMemberPath;
}
function getHighValue(series, item) {
return getItemValue(series, item, "highMemberPath");
}
function hasLow(series) {
return series.lowMemberPath;
}
function getLowValue(series, item) {
return getItemValue(series, item, "lowMemberPath");
}
function hasClose(series) {
return series.closeMemberPath;
}
function getCloseValue(series, item) {
return getItemValue(series, item, "closeMemberPath");
}
function hasVolume(series) {
return series.volumeMemberPath;
}
function getVolumeValue(series, item) {
return getItemValue(series, item, "volumeMemberPath");
}
function getAnchoredValue(series, item) {
return getItemValue(series, item, "valueMemberPath");
}
function getXValue(series, item) {
return getItemValue(series, item, "xMemberPath");
}
function getYValue(series, item) {
return getItemValue(series, item, "yMemberPath");
}
function hasRadius(series) {
return series.radiusMemberPath !== undefined;
}
function getRadiusValue(series, item) {
return getItemValue(series, item, "radiusMemberPath");
}
function getAngleValue(series, item) {
return getItemValue(series, item, "angleMemberPath");
}
function hasValue(series) {
return series.valueMemberPath;
}
function getBrush(series) {
return series.safeActualBrush;
}
function hasXY(series, item) {
return series.xMemberPath && series.yMemberPath && item[series.xMemberPath] && item[series.yMemberPath];
}
function hasColor(series) {
return series.colorMemberPath;
}
function getColorValue(series, item) {
return getItemValue(series, item, "colorMemberPath");
}
function getItemValue(series, item, memberPath) {
return series.getItemValue(item, memberPath);
}
function asAny(item) {
return item;
}
function format(value) {
if (value == undefined || value == null) {
return "";
}
if (value.getTime) {
return shortDate(value);
}
return value.toString();
}
function shortDate(item) {
if (item == undefined || item == null) {
return "";
}
return item.toLocaleDateString() + " " + item.toLocaleTimeString();
}
var AnchoredCategoryTooltip = function (props) {
if (!props.dataContext) {
return null;
}
if (!props.dataContext.item) {
return null;
}
var anc = props.dataContext.series;
if (anc === null) {
return null;
}
var s = anc;
var catAxis = null;
if (anc.isVertical) {
catAxis = anc.yAxis;
}
else {
catAxis = anc.xAxis;
}
if (catAxis == null) {
return null;
}
var item = props.dataContext.item;
return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } }, catAxis.isDateTime && React.createElement("span", null, shortDate(catAxis.getItemValue(asAny(props.dataContext.item), "dateTimeMemberPath"))), catAxis.isDateTime && React.createElement("br", null), (!catAxis.isDateTime && catAxis.label) && React.createElement("span", null, format(asAny(item)[catAxis.label])), (!catAxis.isDateTime && catAxis.label) && React.createElement("br", null), React.createElement("span", { style: { color: getBrush(s) } }, s.title, ": "), React.createElement("span", { className: "ui-tooltip-priority" }, getAnchoredValue(s, item))));
};
var ScatterTooltip = function (props) {
if (!props.dataContext) {
return null;
}
if (!props.dataContext.item) {
return null;
}
var ss = props.dataContext.series;
if (ss === null) {
return null;
}
var s = ss;
var item = props.dataContext.item;
if (hasRadius(s)) {
return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } }, React.createElement("span", { style: { color: getBrush(s) } }, s.title), React.createElement("br", null), React.createElement("span", { className: "ui-tooltip-priority" }, "(", getXValue(s, item), ", ", getYValue(s, item), "), ", s.actualRadiusLabel, ": ", getRadiusValue(s, item))));
}
return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } }, React.createElement("span", { style: { color: getBrush(s) } }, s.title), React.createElement("br", null), React.createElement("span", { className: "ui-tooltip-priority" }, "x: ", getXValue(s, item)), React.createElement("br", null), React.createElement("span", { className: "ui-tooltip-priority" }, "y: ", getYValue(s, item))));
};
var FinancialTooltip = function (props) {
if (!props.dataContext) {
return null;
}
if (!props.dataContext.item) {
return null;
}
var fin = props.dataContext.series;
if (fin === null) {
return null;
}
var s = fin;
var catAxis = fin.xAxis;
if (catAxis == null) {
return null;
}
var item = props.dataContext.item;
var itemLabel = props.dataContext.itemLabel;
return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } }, catAxis.isDateTime && React.createElement("span", null, " ", itemLabel, " "), catAxis.isDateTime && React.createElement("br", null), (!catAxis.isDateTime && catAxis.label) && React.createElement("span", null, format(catAxis.getItemValue(asAny(item), "label"))), (!catAxis.isDateTime && catAxis.label) && React.createElement("br", null), React.createElement("span", { style: { color: getBrush(s) } }, s.title, ": "), React.createElement("table", null, React.createElement("tbody", null, hasOpen(s) ? React.createElement("tr", null, React.createElement("td", null, s.actualOpenLabel, ": "), React.createElement("td", null, getOpenValue(s, item))) : null, hasHigh(s) ? React.createElement("tr", null, React.createElement("td", null, s.actualHighLabel, ": "), React.createElement("td", null, getHighValue(s, item))) : null, hasLow(s) ? React.createElement("tr", null, React.createElement("td", null, s.actualLowLabel, ": "), React.createElement("td", null, getLowValue(s, item))) : null, hasClose(s) ? React.createElement("tr", null, React.createElement("td", null, s.actualCloseLabel, ": "), React.createElement("td", null, getCloseValue(s, item))) : null, hasVolume(s) ? React.createElement("tr", null, React.createElement("td", null, s.actualVolumeLabel, ": "), React.createElement("td", null, getVolumeValue(s, item))) : null))));
};
var PolarTooltip = function (props) {
if (!props.dataContext) {
return null;
}
if (!props.dataContext.item) {
return null;
}
var ss = props.dataContext.series;
if (ss === null) {
return null;
}
var s = ss;
var item = props.dataContext.item;
return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } }, React.createElement("span", { className: "ui-tooltip-priority" }, getAngleValue(s, item)), React.createElement("br", null), React.createElement("span", { style: { color: getBrush(s) } }, s.title, ": "), React.createElement("span", { className: "ui-tooltip-priority" }, getRadiusValue(s, item))));
};
var RadialTooltip = function (props) {
if (!props.dataContext) {
return null;
}
if (!props.dataContext.item) {
return null;
}
var ss = props.dataContext.series;
if (ss === null) {
return null;
}
var angleAxis = ss.angleAxis;
if (angleAxis == null) {
return null;
}
var s = ss;
var item = props.dataContext.item;
var axisLabel = angleAxis.label;
return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } }, axisLabel && React.createElement("span", { className: "ui-tooltip-priority" }, format(angleAxis.getItemValue(asAny(item), "label"))), axisLabel && React.createElement("br", null), React.createElement("span", { style: { color: getBrush(s) } }, s.title, ": "), React.createElement("span", { className: "ui-tooltip-priority" }, getAnchoredValue(s, item))));
};
var RangeCategoryTooltip = function (props) {
if (!props.dataContext) {
return null;
}
if (!props.dataContext.item) {
return null;
}
var anc = props.dataContext.series;
if (anc === null) {
return null;
}
var s = anc;
var catAxis = anc.xAxis;
if (catAxis == null) {
return null;
}
var item = props.dataContext.item;
return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } }, catAxis.isDateTime && React.createElement("span", null, shortDate(catAxis.getItemValue(asAny(props.dataContext.item), "dateTimeMemberPath"))), catAxis.isDateTime && React.createElement("br", null), (!catAxis.isDateTime && catAxis.label) && React.createElement("span", null, format(catAxis.getItemValue(asAny(item), "label"))), (!catAxis.isDateTime && catAxis.label) && React.createElement("br", null), React.createElement("span", { style: { color: getBrush(s) } }, s.title, ": "), React.createElement("span", { className: "ui-tooltip-priority" }, getLowValue(s, item), " - "), React.createElement("span", { className: "ui-tooltip-priority" }, getHighValue(s, item))));
};
var ShapeTooltip = function (props) {
if (!props.dataContext) {
return null;
}
if (!props.dataContext.item) {
return null;
}
var ss = props.dataContext.series;
if (ss === null) {
return null;
}
var s = ss;
var item = props.dataContext.item;
var showXY = hasXY(s, item);
return (React.createElement("div", { className: 'ui-chart-default-tooltip-content', style: { whiteSpace: "nowrap" } }, React.createElement("span", { style: { color: getBrush(s) } }, s.title), showXY && React.createElement("br", null), showXY && React.createElement("span", null, "(", getXValue(s, item), ", ", getYValue(s, item), ") "), hasColor(s) && React.createElement("br", null), hasColor(s) && React.createElement("span", null, s.actualValueLabel, ": ", getColorValue(s, item)), hasValue(s) && React.createElement("br", null), hasValue(s) && React.createElement("span", null, s.ActualValueLabel, ": ", item)));
};
var IgrDataChartDefaultTooltips = /** @class */ /*@__PURE__*/ (function () {
function IgrDataChartDefaultTooltips() {
this.anchoredCategoryTooltip = AnchoredCategoryTooltip;
this.financialTooltip = FinancialTooltip;
this.polarTooltip = PolarTooltip;
this.radialTooltip = RadialTooltip;
this.rangeCategoryTooltip = RangeCategoryTooltip;
this.scatterTooltip = ScatterTooltip;
this.shapeTooltip = ShapeTooltip;
}
IgrDataChartDefaultTooltips.prototype.ensureDefaultTooltip = function (series) {
if (series.isPolar) {
if (series.showDefaultTooltip) {
series.tooltipTemplate = this.polarTooltip;
}
else {
if (series.tooltipTemplate === this.polarTooltip) {
series.tooltipTemplate = null;
}
}
}
else if (series.isRadial) {
if (series.showDefaultTooltip) {
series.tooltipTemplate = this.radialTooltip;
}
else {
if (series.tooltipTemplate === this.radialTooltip) {
series.tooltipTemplate = null;
}
}
}
else if (series.isShape) {
if (series.showDefaultTooltip) {
series.tooltipTemplate = this.shapeTooltip;
}
else {
if (series.tooltipTemplate === this.shapeTooltip) {
series.tooltipTemplate = null;
}
}
}
else if (series.isScatter) {
if (series.showDefaultTooltip) {
series.tooltipTemplate = this.scatterTooltip;
}
else {
if (series.tooltipTemplate === this.scatterTooltip) {
series.tooltipTemplate = null;
}
}
}
else if (series.isCategory &&
!series.isFinancial) {
if (!series.isRange) {
if (series.showDefaultTooltip) {
series.tooltipTemplate = this.anchoredCategoryTooltip;
}
else {
if (series.tooltipTemplate === this.anchoredCategoryTooltip) {
series.tooltipTemplate = null;
}
}
}
else {
if (series.showDefaultTooltip) {
series.tooltipTemplate = this.rangeCategoryTooltip;
}
else {
if (series.tooltipTemplate === this.rangeCategoryTooltip) {
series.tooltipTemplate = null;
}
}
}
}
else if (series.isFinancial) {
if (series.showDefaultTooltip) {
series.tooltipTemplate = this.financialTooltip;
}
else {
if (series.tooltipTemplate === this.financialTooltip) {
series.tooltipTemplate = null;
}
}
}
};
IgrDataChartDefaultTooltips.register = function () {
TypeRegistrar.registerCons("IgrDataChartDefaultTooltips", IgrDataChartDefaultTooltips);
};
return IgrDataChartDefaultTooltips;
}());
export { IgrDataChartDefaultTooltips };