UNPKG

scichart

Version:

Fast WebGL JavaScript Charting Library and Framework

99 lines (98 loc) 4.32 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.HtmlTextAnnotation = void 0; var constants_1 = require("./constants"); var HtmlCustomAnnotation_1 = require("./HtmlCustomAnnotation"); var IAnnotation_1 = require("./IAnnotation"); /** * A HtmlTextAnnotation presents text information over the chart at specific {@link X1}, {@link Y1} coordinates */ var HtmlTextAnnotation = /** @class */ (function (_super) { __extends(HtmlTextAnnotation, _super); /** * Creates an instance of the {@link TextAnnotation} * @param options The {@link ITextAnnotationOptions} which contain optional parameters */ function HtmlTextAnnotation(options) { var _this = this; var _a, _b; _this = _super.call(this, options) || this; _this.type = IAnnotation_1.EAnnotationType.HtmlTextAnnotation; _this.textProperty = null; _this.text = (_a = options === null || options === void 0 ? void 0 : options.text) !== null && _a !== void 0 ? _a : _this.textProperty; _this.textContainerStyle = (_b = options === null || options === void 0 ? void 0 : options.textContainerStyle) !== null && _b !== void 0 ? _b : _this.textContainerStyleProperty; return _this; } Object.defineProperty(HtmlTextAnnotation.prototype, "text", { /** * text provided by the user */ get: function () { return this.textProperty; }, set: function (text) { if (this.textProperty !== text) { this.textProperty = text; this.setText(this.textProperty); this.notifyPropertyChanged(constants_1.PROPERTY.TEXT_STYLE); } }, enumerable: false, configurable: true }); Object.defineProperty(HtmlTextAnnotation.prototype, "textContainerStyle", { /** * text provided by the user */ get: function () { return this.textContainerStyleProperty; }, set: function (value) { if (this.textContainerStyleProperty !== value) { this.textContainerStyleProperty = value; this.setStyle(this.textContainerStyle); this.notifyPropertyChanged(constants_1.PROPERTY.TEXT); } }, enumerable: false, configurable: true }); HtmlTextAnnotation.prototype.toJSON = function () { var json = _super.prototype.toJSON.call(this); var options = { textContainerStyle: this.textContainerStyle, text: this.text }; Object.assign(json.options, options); return json; }; HtmlTextAnnotation.prototype.setText = function (text) { this.htmlElement.innerText = text; }; HtmlTextAnnotation.prototype.setStyle = function (style) { var _this = this; Object.entries(style).forEach(function (_a) { var property = _a[0], value = _a[1]; // https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration/setProperty#propertyname var hyphenatedStylePropertyName = property.replace(/[A-Z]/g, function (m) { return "-" + m.toLowerCase(); }); _this.htmlElement.style.setProperty(hyphenatedStylePropertyName, value); }); }; return HtmlTextAnnotation; }(HtmlCustomAnnotation_1.HtmlCustomAnnotation)); exports.HtmlTextAnnotation = HtmlTextAnnotation;