UNPKG

@syncfusion/ej2-lineargauge

Version:
1,273 lines (1,267 loc) 134 kB
import { Animation, Browser, ChildProperty, Collection, Complex, Component, Event, EventHandler, Internationalization, NotifyPropertyChanges, Property, compile, createElement, isNullOrUndefined, merge, remove, resetBlazorTemplate, updateBlazorTemplate } from '@syncfusion/ej2-base'; import { SvgRenderer, Tooltip } from '@syncfusion/ej2-svg-base'; var __extends$1 = (undefined && undefined.__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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Options for customizing the fonts. */ var Font = /** @__PURE__ @class */ (function (_super) { __extends$1(Font, _super); function Font() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$1([ Property('16px') ], Font.prototype, "size", void 0); __decorate$1([ Property('') ], Font.prototype, "color", void 0); __decorate$1([ Property('Segoe UI') ], Font.prototype, "fontFamily", void 0); __decorate$1([ Property('Regular') ], Font.prototype, "fontWeight", void 0); __decorate$1([ Property('Normal') ], Font.prototype, "fontStyle", void 0); __decorate$1([ Property(1) ], Font.prototype, "opacity", void 0); return Font; }(ChildProperty)); /** * Configures the margin of linear gauge. */ var Margin = /** @__PURE__ @class */ (function (_super) { __extends$1(Margin, _super); function Margin() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$1([ Property(10) ], Margin.prototype, "left", void 0); __decorate$1([ Property(10) ], Margin.prototype, "right", void 0); __decorate$1([ Property(10) ], Margin.prototype, "top", void 0); __decorate$1([ Property(10) ], Margin.prototype, "bottom", void 0); return Margin; }(ChildProperty)); /** * Configures the border in linear gauge. */ var Border = /** @__PURE__ @class */ (function (_super) { __extends$1(Border, _super); function Border() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$1([ Property(null) ], Border.prototype, "color", void 0); __decorate$1([ Property(0) ], Border.prototype, "width", void 0); return Border; }(ChildProperty)); /** * Options for customizing the annotation. */ var Annotation = /** @__PURE__ @class */ (function (_super) { __extends$1(Annotation, _super); function Annotation() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$1([ Property('') ], Annotation.prototype, "content", void 0); __decorate$1([ Property(0) ], Annotation.prototype, "x", void 0); __decorate$1([ Property(0) ], Annotation.prototype, "y", void 0); __decorate$1([ Property('None') ], Annotation.prototype, "verticalAlignment", void 0); __decorate$1([ Property('None') ], Annotation.prototype, "horizontalAlignment", void 0); __decorate$1([ Property('-1') ], Annotation.prototype, "zIndex", void 0); __decorate$1([ Complex({ size: '12px', color: null }, Font) ], Annotation.prototype, "font", void 0); __decorate$1([ Property(null) ], Annotation.prototype, "axisIndex", void 0); __decorate$1([ Property(null) ], Annotation.prototype, "axisValue", void 0); return Annotation; }(ChildProperty)); /** * Options for customizing the container of linear gauge. */ var Container = /** @__PURE__ @class */ (function (_super) { __extends$1(Container, _super); function Container() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$1([ Property('Normal') ], Container.prototype, "type", void 0); __decorate$1([ Property(0) ], Container.prototype, "height", void 0); __decorate$1([ Property(0) ], Container.prototype, "width", void 0); __decorate$1([ Property(10) ], Container.prototype, "roundedCornerRadius", void 0); __decorate$1([ Property('transparent') ], Container.prototype, "backgroundColor", void 0); __decorate$1([ Complex({ width: 1, color: '#bfbfbf' }, Border) ], Container.prototype, "border", void 0); __decorate$1([ Property(0) ], Container.prototype, "offset", void 0); return Container; }(ChildProperty)); /** * Options for customizing the tooltip in linear gauge. */ var TooltipSettings = /** @__PURE__ @class */ (function (_super) { __extends$1(TooltipSettings, _super); function TooltipSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$1([ Property(false) ], TooltipSettings.prototype, "enable", void 0); __decorate$1([ Property('') ], TooltipSettings.prototype, "fill", void 0); __decorate$1([ Complex({ color: '', size: '13px' }, Font) ], TooltipSettings.prototype, "textStyle", void 0); __decorate$1([ Property(null) ], TooltipSettings.prototype, "format", void 0); __decorate$1([ Property(null) ], TooltipSettings.prototype, "template", void 0); __decorate$1([ Property(true) ], TooltipSettings.prototype, "enableAnimation", void 0); __decorate$1([ Complex({}, Border) ], TooltipSettings.prototype, "border", void 0); return TooltipSettings; }(ChildProperty)); var __extends$2 = (undefined && undefined.__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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** Options for customizing the axis line. */ var Line = /** @__PURE__ @class */ (function (_super) { __extends$2(Line, _super); function Line() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$2([ Property('') ], Line.prototype, "dashArray", void 0); __decorate$2([ Property(null) ], Line.prototype, "height", void 0); __decorate$2([ Property(2) ], Line.prototype, "width", void 0); __decorate$2([ Property(null) ], Line.prototype, "color", void 0); __decorate$2([ Property(0) ], Line.prototype, "offset", void 0); return Line; }(ChildProperty)); /** * Options for customizing the axis labels appearance. */ var Label = /** @__PURE__ @class */ (function (_super) { __extends$2(Label, _super); function Label() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$2([ Complex({ size: '12px', color: null }, Font) ], Label.prototype, "font", void 0); __decorate$2([ Property(false) ], Label.prototype, "useRangeColor", void 0); __decorate$2([ Property('') ], Label.prototype, "format", void 0); __decorate$2([ Property(0) ], Label.prototype, "offset", void 0); return Label; }(ChildProperty)); /** * Options for customizing the ranges of an axis. */ var Range = /** @__PURE__ @class */ (function (_super) { __extends$2(Range, _super); function Range() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$2([ Property(0) ], Range.prototype, "start", void 0); __decorate$2([ Property(0) ], Range.prototype, "end", void 0); __decorate$2([ Property('Outside') ], Range.prototype, "position", void 0); __decorate$2([ Property('') ], Range.prototype, "color", void 0); __decorate$2([ Property(10) ], Range.prototype, "startWidth", void 0); __decorate$2([ Property(10) ], Range.prototype, "endWidth", void 0); __decorate$2([ Property(0) ], Range.prototype, "offset", void 0); __decorate$2([ Complex({ color: '#000000', width: 0 }, Border) ], Range.prototype, "border", void 0); return Range; }(ChildProperty)); /** * Options for customizing the minor tick lines. */ var Tick = /** @__PURE__ @class */ (function (_super) { __extends$2(Tick, _super); function Tick() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$2([ Property(20) ], Tick.prototype, "height", void 0); __decorate$2([ Property(2) ], Tick.prototype, "width", void 0); __decorate$2([ Property(null) ], Tick.prototype, "interval", void 0); __decorate$2([ Property(null) ], Tick.prototype, "color", void 0); __decorate$2([ Property(null) ], Tick.prototype, "offset", void 0); return Tick; }(ChildProperty)); /** * Options for customizing the pointers of an axis. */ var Pointer = /** @__PURE__ @class */ (function (_super) { __extends$2(Pointer, _super); function Pointer() { var _this = _super !== null && _super.apply(this, arguments) || this; /** @private */ _this.animationComplete = true; /** @private */ _this.currentValue = null; return _this; } __decorate$2([ Property('Marker') ], Pointer.prototype, "type", void 0); __decorate$2([ Property(null) ], Pointer.prototype, "value", void 0); __decorate$2([ Property('InvertedTriangle') ], Pointer.prototype, "markerType", void 0); __decorate$2([ Property(null) ], Pointer.prototype, "imageUrl", void 0); __decorate$2([ Complex({ color: '#808080' }, Border) ], Pointer.prototype, "border", void 0); __decorate$2([ Property(10) ], Pointer.prototype, "roundedCornerRadius", void 0); __decorate$2([ Property('Far') ], Pointer.prototype, "placement", void 0); __decorate$2([ Property(20) ], Pointer.prototype, "height", void 0); __decorate$2([ Property(20) ], Pointer.prototype, "width", void 0); __decorate$2([ Property(null) ], Pointer.prototype, "color", void 0); __decorate$2([ Property(1) ], Pointer.prototype, "opacity", void 0); __decorate$2([ Property(0) ], Pointer.prototype, "animationDuration", void 0); __decorate$2([ Property(false) ], Pointer.prototype, "enableDrag", void 0); __decorate$2([ Property(0) ], Pointer.prototype, "offset", void 0); __decorate$2([ Property(null) ], Pointer.prototype, "description", void 0); return Pointer; }(ChildProperty)); /** * Options for customizing the axis of a gauge. */ var Axis = /** @__PURE__ @class */ (function (_super) { __extends$2(Axis, _super); function Axis() { /** * Specifies the minimum value of an axis. */ var _this = _super !== null && _super.apply(this, arguments) || this; /** @private */ _this.visibleLabels = []; return _this; } __decorate$2([ Property(0) ], Axis.prototype, "minimum", void 0); __decorate$2([ Property(100) ], Axis.prototype, "maximum", void 0); __decorate$2([ Property(false) ], Axis.prototype, "isInversed", void 0); __decorate$2([ Property(false) ], Axis.prototype, "opposedPosition", void 0); __decorate$2([ Complex({}, Line) ], Axis.prototype, "line", void 0); __decorate$2([ Collection([{}], Range) ], Axis.prototype, "ranges", void 0); __decorate$2([ Collection([{}], Pointer) ], Axis.prototype, "pointers", void 0); __decorate$2([ Complex({ width: 2, height: 20 }, Tick) ], Axis.prototype, "majorTicks", void 0); __decorate$2([ Complex({ width: 1, height: 10 }, Tick) ], Axis.prototype, "minorTicks", void 0); __decorate$2([ Complex({}, Label) ], Axis.prototype, "labelStyle", void 0); return Axis; }(ChildProperty)); /** * Specifies the linear gauge constant value */ /** @private */ var loaded = 'loaded'; /** @private */ var load = 'load'; /** @private */ var animationComplete = 'animationComplete'; /** @private */ var axisLabelRender = 'axisLabelRender'; /** @private */ var tooltipRender = 'tooltipRender'; /** @private */ var annotationRender = 'annotationRender'; /** @private */ var gaugeMouseMove = 'gaugeMouseMove'; /** @private */ var gaugeMouseLeave = 'gaugeMouseLeave'; /** @private */ var gaugeMouseDown = 'gaugeMouseDown'; /** @private */ var gaugeMouseUp = 'gaugeMouseUp'; /** @private */ var valueChange = 'valueChange'; /** @private */ var resized = 'resized'; var __extends$3 = (undefined && undefined.__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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Specifies Linear-Gauge Helper methods */ /** @private */ function stringToNumber(value, containerSize) { if (value !== null && value !== undefined) { return value.indexOf('%') !== -1 ? (containerSize / 100) * parseInt(value, 10) : parseInt(value, 10); } return null; } /** * Function to measure the height and width of the text. * @param {string} text * @param {FontModel} font * @param {string} id * @returns no * @private */ function measureText(text, font) { var htmlObject = document.getElementById('gauge-measuretext'); var size; if (htmlObject === null) { htmlObject = createElement('text', { id: 'gauge-measuretext' }); document.body.appendChild(htmlObject); } htmlObject.innerHTML = text; htmlObject.style.position = 'absolute'; htmlObject.style.fontSize = font.size; htmlObject.style.fontWeight = font.fontWeight; htmlObject.style.fontStyle = font.fontStyle; htmlObject.style.fontFamily = font.fontFamily; htmlObject.style.visibility = 'hidden'; htmlObject.style.top = '-100'; htmlObject.style.left = '0'; htmlObject.style.whiteSpace = 'nowrap'; size = new Size(htmlObject.clientWidth, htmlObject.clientHeight); //remove(htmlObject); return size; } /** @private */ function withInRange(value, start, end, max, min, type) { var withIn; if (type === 'pointer') { withIn = (((value <= max) && (value >= min))); } else { withIn = (start != null && (start <= max) && (start >= min)) && (end != null && (end <= max) && (end >= min)); } return withIn; } function convertPixelToValue(parentElement, pointerElement, orientation, axis, type, location) { var elementRect = parentElement.getBoundingClientRect(); var pointerRect = pointerElement.getBoundingClientRect(); var height = (pointerElement.id.indexOf('MarkerPointer') > -1) ? (pointerRect.height / 2) : (!axis.isInversed) ? 0 : pointerRect.height; var width = (pointerElement.id.indexOf('MarkerPointer') > -1) ? (pointerRect.width / 2) : (!axis.isInversed) ? pointerRect.width : 0; var size = new Size(axis.lineBounds.width, axis.lineBounds.height); var y = (type === 'drag') ? (location.y - axis.lineBounds.y) : ((pointerRect.top + height) - elementRect.top - axis.lineBounds.y); var x = (type === 'drag') ? (location.x - axis.lineBounds.x) : ((pointerRect.left + width) - elementRect.left - axis.lineBounds.x); var newSize = (orientation === 'Vertical') ? size.height : size.width; var divideVal = (orientation === 'Vertical') ? y : x; var value = (orientation === 'Vertical') ? (axis.isInversed) ? (divideVal / newSize) : (1 - (divideVal / newSize)) : (axis.isInversed) ? (1 - (divideVal / newSize)) : (divideVal / newSize); value = value * (axis.visibleRange.delta) + axis.visibleRange.min; return value; } function getPathToRect(path, size, parentElement) { var tempDiv = document.getElementById('gauge_path'); if (tempDiv === null) { tempDiv = createElement('text', { id: 'gauge_path' }); tempDiv.style.position = 'absolute'; tempDiv.style.top = '0px'; tempDiv.style.left = '0px'; parentElement.appendChild(tempDiv); } var render = new SvgRenderer('id'); var svg = render.createSvg({ id: 'box_path', width: size.width, height: size.height }); svg.appendChild(path); tempDiv.appendChild(svg); var svgRect = path.getBBox(); remove(tempDiv); return svgRect; } /** @private */ function getElement(id) { return document.getElementById(id); } /** @private */ function removeElement(id) { var element = getElement(id); if (element) { remove(element); } } /** @private */ function isPointerDrag(axes) { var pointerEnable = false; axes.map(function (axis, index) { axis.pointers.map(function (pointer, index) { if (pointer.enableDrag) { pointerEnable = true; } }); }); return pointerEnable; } /** @private */ function valueToCoefficient(value, axis, orientation, range) { var result = (value - range.min) / range.delta; result = (orientation === 'Vertical') ? (!axis.isInversed) ? (1 - result) : result : (!axis.isInversed) ? result : (1 - result); return result; } function getFontStyle(font) { var style = ''; style = 'font-size:' + font.size + '; font-style:' + font.fontStyle + '; font-weight:' + font.fontWeight + '; font-family:' + font.fontFamily + ';opacity:' + font.opacity + '; color:' + font.color + ';'; return style; } function textFormatter(format, data, gauge) { if (isNullOrUndefined(format)) { return null; } var keys = Object.keys(data); for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { var key = keys_1[_i]; format = format.split('{' + key + '}').join(formatValue(data[key], gauge).toString()); } return format; } function formatValue(value, gauge) { var formatValue; var formatFunction; if (gauge.format && !isNaN(Number(value))) { formatFunction = gauge.intl.getNumberFormat({ format: gauge.format, useGrouping: gauge.useGroupingSeparator }); formatValue = formatFunction(Number(value)); } else { formatValue = value; } return formatValue !== null ? formatValue : ''; } /** @private */ function getLabelFormat(format) { var customLabelFormat = format && format.match('{value}') !== null; var skeleton = customLabelFormat ? '' : format; return skeleton; } /** @private */ function getTemplateFunction(template) { var templateFn = null; try { if (document.querySelectorAll(template).length) { templateFn = compile(document.querySelector(template).innerHTML.trim()); } } catch (e) { templateFn = compile(template); } return templateFn; } /** @private */ function getElementOffset(childElement, parentElement) { var width; var height; parentElement.appendChild(childElement); width = childElement.offsetWidth; height = childElement.offsetHeight; parentElement.removeChild(childElement); return new Size(width, height); } /** @private */ var VisibleRange = /** @__PURE__ @class */ (function () { function VisibleRange(min, max, interval, delta) { this.min = min; this.max = max; this.interval = interval; this.delta = delta; } return VisibleRange; }()); /** * Internal use of gauge location */ var GaugeLocation = /** @__PURE__ @class */ (function () { function GaugeLocation(x, y) { this.x = x; this.y = y; } return GaugeLocation; }()); /** * Internal class size for height and width */ var Size = /** @__PURE__ @class */ (function () { function Size(width, height) { this.width = width; this.height = height; } return Size; }()); /** @private */ var Rect = /** @__PURE__ @class */ (function () { function Rect(x, y, width, height) { this.x = x; this.y = y; this.width = width; this.height = height; } return Rect; }()); /** @private */ var CustomizeOption = /** @__PURE__ @class */ (function () { function CustomizeOption(id) { this.id = id; } return CustomizeOption; }()); /** @private */ var PathOption = /** @__PURE__ @class */ (function (_super) { __extends$3(PathOption, _super); function PathOption(id, fill, width, color, opacity, dashArray, d, transform) { if (transform === void 0) { transform = ''; } var _this = _super.call(this, id) || this; _this.opacity = opacity; _this.fill = fill; _this.stroke = color; _this['stroke-width'] = width; _this['stroke-dasharray'] = dashArray; _this.d = d; _this.transform = transform; return _this; } return PathOption; }(CustomizeOption)); /** @private */ var RectOption = /** @__PURE__ @class */ (function () { function RectOption(id, fill, border, opacity, rect, transform, dashArray) { this.opacity = opacity; this.id = id; this.y = rect.y; this.x = rect.x; this.fill = fill; this.stroke = border.color; this['stroke-width'] = border.width; this.height = rect.height; this.width = rect.width; } return RectOption; }()); /** @private */ var TextOption = /** @__PURE__ @class */ (function (_super) { __extends$3(TextOption, _super); function TextOption(id, x, y, anchor, text, transform, baseLine) { if (transform === void 0) { transform = ''; } var _this = _super.call(this, id) || this; _this.transform = ''; _this.baseLine = 'auto'; _this.x = x; _this.y = y; _this.anchor = anchor; _this.text = text; _this.transform = transform; _this.baseLine = baseLine; return _this; } return TextOption; }(CustomizeOption)); /** @private */ var VisibleLabels = /** @__PURE__ @class */ (function () { function VisibleLabels(text, value, size) { this.text = text; this.value = value; this.size = size; } return VisibleLabels; }()); /** @private */ var Align = /** @__PURE__ @class */ (function () { function Align(axisIndex, align) { this.align = align; this.axisIndex = axisIndex; } return Align; }()); /** @private */ function textElement(options, font, color, parent) { var renderOptions = {}; var htmlObject; var renderer = new SvgRenderer(''); var style = 'fill:' + color + '; font-size:' + font.size + '; font-style:' + font.fontStyle + ' ; font-weight:' + font.fontWeight + '; font-family:' + font.fontFamily + '; text-anchor:' + options.anchor + '; transform:' + options.transform + '; opacity:' + font.opacity + '; dominant-baseline:' + options.baseLine + ';'; renderOptions = { 'id': options.id, 'x': options.x, 'y': options.y, 'style': style }; htmlObject = renderer.createText(renderOptions, options.text); parent.appendChild(htmlObject); return htmlObject; } function calculateNiceInterval(min, max, size, orientation) { var delta = max - min; var currentInterval; var intervalDivs = [10, 5, 2, 1]; var desiredIntervalsCount = getActualDesiredIntervalsCount(size, orientation); var niceInterval = delta / desiredIntervalsCount; var minInterval = Math.pow(10, Math.floor(Math.log(niceInterval) / Math.log(10))); for (var _i = 0, intervalDivs_1 = intervalDivs; _i < intervalDivs_1.length; _i++) { var interval = intervalDivs_1[_i]; currentInterval = minInterval * interval; if (desiredIntervalsCount < (delta / currentInterval)) { break; } niceInterval = currentInterval; } return niceInterval; } function getActualDesiredIntervalsCount(size, orientation) { var maximumLabels = 5; var desiredIntervalsCount = (orientation === 'Horizontal' ? 0.533 : 1) * maximumLabels; desiredIntervalsCount = Math.max((size * (desiredIntervalsCount / 100)), 1); return desiredIntervalsCount; } /** @private */ function getPointer(target, gauge) { var split = []; var axisIndex; var radix = 10; var pointIndex; var axis; var pointer; split = target.id.replace(gauge.element.id, '').split('_'); axisIndex = parseInt(split[2], radix); pointIndex = parseInt(split[4], radix); axis = gauge.axes[axisIndex]; pointer = gauge.axes[axisIndex].pointers[pointIndex]; return { axis: axis, axisIndex: axisIndex, pointer: pointer, pointerIndex: pointIndex }; } /** @private */ function getRangeColor(value, ranges) { var rangeColor = null; ranges.forEach(function (range, index) { if (value >= range.start && range.end >= value) { rangeColor = range.interior; } }); return rangeColor; } /** @private */ function getRangePalette() { var palette = ['#ff5985', '#ffb133', '#fcde0b', '#27d5ff', '#50c917']; return palette; } /** @private */ function calculateShapes(location, shape, size, url, options, orientation, axis, pointer) { var path; var width = size.width; var height = size.height; var locX = location.x; var locY = location.y; var radius; switch (shape) { case 'Circle': radius = ((width + height) / 4); locX = (orientation === 'Vertical') ? (!axis.opposedPosition) ? (pointer.placement !== 'Far') ? locX - radius : locX + radius : pointer.placement === 'Near' ? locX - radius : locX + radius : locX; locY = (orientation === 'Vertical') ? locY : (!axis.opposedPosition) ? (pointer.placement === 'Far') ? locY + radius : locY - radius : (pointer.placement === 'Near') ? locY - radius : locY + radius; merge(options, { 'r': radius, 'cx': locX, 'cy': locY }); break; case 'Diamond': case 'Rectangle': locX = (orientation === 'Horizontal') ? ((locX - (width / 2))) : ((!axis.opposedPosition && pointer.placement !== 'Far') || (axis.opposedPosition && pointer.placement === 'Near')) ? locX - width : locX; locY = (orientation === 'Vertical') ? locY : (!axis.opposedPosition) ? (pointer.placement === 'Far') ? locY + (height / 2) : locY - (height / 2) : (pointer.placement === 'Near') ? locY - (height / 2) : locY + (height / 2); if (shape === 'Diamond') { path = 'M' + ' ' + locX + ' ' + locY + ' ' + 'L' + ' ' + (locX + (width / 2)) + ' ' + (locY - (height / 2)) + ' ' + 'L' + ' ' + (locX + width) + ' ' + locY + ' ' + 'L' + ' ' + (locX + (width / 2)) + ' ' + (locY + (height / 2)) + ' ' + 'L' + ' ' + locX + ' ' + locY + ' z'; } else { path = 'M' + ' ' + locX + ' ' + (locY - (height / 2)) + ' ' + 'L' + ' ' + (locX + width) + ' ' + (locY - (height / 2)) + ' ' + 'L' + ' ' + (locX + width) + ' ' + (locY + (height / 2)) + ' ' + 'L' + ' ' + locX + ' ' + (locY + (height / 2)) + ' ' + 'L' + ' ' + locX + ' ' + (locY - (height / 2)) + ' z'; } merge(options, { 'd': path }); break; case 'Triangle': if (orientation === 'Vertical') { path = 'M' + ' ' + locX + ' ' + locY + ' ' + 'L' + (locX - width) + ' ' + (locY - (height / 2)) + 'L' + (locX - width) + ' ' + (locY + (height / 2)) + ' Z'; } else { path = 'M' + ' ' + locX + ' ' + locY + ' ' + 'L' + (locX + (width / 2)) + ' ' + (locY - height) + 'L' + (locX - (width / 2)) + ' ' + (locY - height) + ' Z'; } merge(options, { 'd': path }); break; case 'InvertedTriangle': if (orientation === 'Vertical') { path = 'M' + ' ' + locX + ' ' + locY + ' ' + 'L' + (locX + width) + ' ' + (locY - (height / 2)) + 'L' + (locX + width) + ' ' + (locY + (height / 2)) + ' Z'; } else { path = 'M' + ' ' + locX + ' ' + locY + ' ' + 'L' + (locX + (width / 2)) + ' ' + (locY + height) + 'L' + (locX - (width / 2)) + ' ' + (locY + height) + ' Z'; } merge(options, { 'd': path }); break; case 'Arrow': if (orientation === 'Vertical') { path = 'M' + ' ' + locX + ' ' + locY + ' ' + 'L' + (locX - (width / 2)) + ' ' + (locY - (height / 2)) + ' ' + 'L' + (locX - (width / 2)) + ' ' + ((locY - (height / 2)) + (height / 4)) + ' ' + 'L' + (locX - width) + ' ' + ((locY - (height / 2)) + (height / 4)) + ' ' + 'L' + (locX - width) + ' ' + ((locY + (height / 2)) - (height / 4)) + ' ' + 'L' + (locX - (width / 2)) + ' ' + ((locY + (height / 2)) - (height / 4)) + ' ' + 'L' + (locX - (width / 2)) + ' ' + (locY + height / 2) + 'z'; } else { path = 'M' + ' ' + locX + ' ' + locY + ' ' + 'L' + (locX + (width / 2)) + ' ' + (locY - (height / 2)) + ' ' + 'L' + ((locX + (width / 2)) - (width / 4)) + ' ' + (locY - (height / 2)) + ' ' + 'L' + ((locX + (width / 2)) - (width / 4)) + ' ' + (locY - height) + ' ' + 'L' + ((locX - (width / 2)) + (width / 4)) + ' ' + (locY - height) + ' ' + 'L' + ((locX - (width / 2)) + (width / 4)) + ' ' + (locY - (height / 2)) + ' ' + 'L' + (locX - (width / 2)) + ' ' + (locY - (height / 2)) + 'z'; } merge(options, { 'd': path }); break; case 'InvertedArrow': if (orientation === 'Vertical') { path = 'M' + ' ' + locX + ' ' + locY + 'L' + (locX + (width / 2)) + ' ' + (locY - (height / 2)) + ' ' + 'L' + (locX + (width / 2)) + ' ' + ((locY - (height / 2)) + (height / 4)) + ' ' + 'L' + (locX + width) + ' ' + ((locY - (height / 2)) + (height / 4)) + ' ' + 'L' + (locX + width) + ' ' + ((locY + (height / 2)) - (height / 4)) + ' ' + 'L' + (locX + (width / 2)) + ' ' + ((locY + (height / 2)) - (height / 4)) + ' ' + 'L' + (locX + (width / 2)) + ' ' + (locY + height / 2) + 'z'; } else { path = 'M' + ' ' + locX + ' ' + locY + ' ' + 'L' + (locX + (width / 2)) + ' ' + (locY + (height / 2)) + ' ' + 'L' + ((locX + (width / 2)) - (width / 4)) + ' ' + (locY + (height / 2)) + ' ' + 'L' + ((locX + (width / 2)) - (width / 4)) + ' ' + (locY + height) + ' ' + 'L' + ((locX - (width / 2)) + (width / 4)) + ' ' + (locY + height) + ' ' + 'L' + ((locX - (width / 2)) + (width / 4)) + ' ' + (locY + (height / 2)) + ' ' + 'L' + (locX - (width / 2)) + ' ' + (locY + (height / 2)) + 'z'; } merge(options, { 'd': path }); break; case 'Image': merge(options, { 'href': url, 'height': height, 'width': width, x: locX - (width / 2), y: locY - (height / 2) }); break; } return options; } /** @private */ function getBox(location, boxName, orientation, size, type, containerWidth, axis, cornerRadius) { var path = ' '; var radius = cornerRadius; var x1; var y1; var rectWidth; var rectHeight; var bottomRadius; var topRadius; switch (boxName) { case 'RoundedRectangle': x1 = location.x; y1 = location.y; rectWidth = location.width; rectHeight = location.height; path = 'M' + ' ' + x1 + ' ' + (radius + y1) + ' Q ' + x1 + ' ' + y1 + ' ' + (x1 + radius) + ' ' + y1 + ' '; path += 'L' + ' ' + (x1 + rectWidth - radius) + ' ' + y1 + ' Q ' + (x1 + rectWidth) + ' ' + y1 + ' ' + (x1 + rectWidth) + ' ' + (y1 + radius) + ' '; path += 'L ' + (x1 + rectWidth) + ' ' + (y1 + rectHeight - radius) + ' Q ' + (x1 + rectWidth) + ' ' + (y1 + rectHeight) + ' ' + (x1 + rectWidth - radius) + ' ' + (y1 + rectHeight) + ' '; path += ' L ' + (x1 + radius) + ' ' + (y1 + rectHeight) + ' Q ' + x1 + ' ' + (y1 + rectHeight) + ' ' + x1 + ' ' + (y1 + rectHeight - radius) + ' '; path += 'L' + ' ' + x1 + ' ' + (radius + y1) + ' ' + 'z'; break; case 'Thermometer': var width = (orientation === 'Vertical') ? location.width : location.height; bottomRadius = width + ((width / 2) / Math.PI); topRadius = width / 2; if (orientation === 'Vertical') { var addValue = ((containerWidth + ((containerWidth / 2) / Math.PI)) - bottomRadius); var y1_1 = (type === 'bar') ? location.y + addValue : location.y; var locY = (type === 'bar') ? location.y + (topRadius - (topRadius / Math.PI)) : location.y; var locHeight = location.height; path = 'M' + location.x + ' ' + (y1_1 + locHeight) + ' A ' + bottomRadius + ' ' + bottomRadius + ', 0, 1, 0, ' + (location.x + location.width) + ' ' + (y1_1 + locHeight) + ' L ' + (location.x + location.width) + ' ' + locY + ' A ' + topRadius + ' ' + topRadius + ', 0, 1, 0, ' + location.x + ' ' + locY + ' z '; } else { var x1_1 = (type === 'bar' && !axis.isInversed) ? location.x - ((containerWidth + ((containerWidth / 2) / Math.PI)) - bottomRadius) : location.x; var locWidth = (type === 'bar') ? (location.width - (topRadius - ((topRadius / Math.PI)))) : location.width; path = 'M' + x1_1 + ' ' + (location.y) + ' A ' + bottomRadius + ' ' + bottomRadius + ', 0, 1, 0, ' + x1_1 + ' ' + (location.y + location.height) + ' L ' + ((type === 'bar' ? location.x : x1_1) + locWidth) + ' ' + (location.y + location.height) + ' A ' + topRadius + ' ' + topRadius + ', 0, 1, 0, ' + ((type === 'bar' ? location.x : x1_1) + locWidth) + ' ' + (location.y) + ' z '; } break; } return path; } /** * @private * To calculate the overall axis bounds for gauge. */ var AxisLayoutPanel = /** @__PURE__ @class */ (function () { function AxisLayoutPanel(gauge) { this.gauge = gauge; } /** * To calculate the axis bounds */ AxisLayoutPanel.prototype.calculateAxesBounds = function () { var axis; var bounds; this.gauge.nearSizes = []; this.gauge.farSizes = []; var x; var y; var width; var height; var axisPadding = 8; var containerRect = this.gauge.containerBounds; this.checkThermometer(); for (var i = 0; i < this.gauge.axes.length; i++) { axis = this.gauge.axes[i]; axis.checkAlign = new Align(i, ((!axis.opposedPosition) ? 'Near' : 'Far')); (!axis.opposedPosition) ? this.gauge.nearSizes.push(1) : this.gauge.farSizes.push(1); this.calculateLineBounds(axis, i); this.calculateTickBounds(axis, i); this.calculateLabelBounds(axis, i); if (axis.pointers.length > 0) { this.calculatePointerBounds(axis, i); } if (axis.ranges.length > 0) { this.calculateRangesBounds(axis, i); } bounds = axis.labelBounds; if (this.gauge.orientation === 'Vertical') { x = (!axis.opposedPosition) ? bounds.x - axisPadding : axis.lineBounds.x; y = axis.lineBounds.y; height = axis.lineBounds.height; width = Math.abs((!axis.opposedPosition) ? (axis.lineBounds.x - x) : ((bounds.x + bounds.width + axisPadding) - x)); } else { y = (!axis.opposedPosition) ? bounds.y - bounds.height - axisPadding : axis.lineBounds.y; x = axis.lineBounds.x; width = axis.lineBounds.width; height = Math.abs((!axis.opposedPosition) ? Math.abs(axis.lineBounds.y - y) : (bounds.y + axisPadding) - y); } axis.bounds = new Rect(x, y, width, height); } }; /** * Calculate axis line bounds * @param axis * @param axisIndex */ AxisLayoutPanel.prototype.calculateLineBounds = function (axis, axisIndex) { var x; var y; var width; var height; var index; var prevAxis; var lineHeight = axis.line.height; var orientation = this.gauge.orientation; var containerRect = this.gauge.containerBounds; lineHeight = (axis.line.width > 0) ? lineHeight : null; if (orientation === 'Vertical') { y = (isNullOrUndefined(lineHeight)) ? containerRect.y : containerRect.y + ((containerRect.height / 2) - (lineHeight / 2)); width = axis.line.width; height = (isNullOrUndefined(lineHeight)) ? containerRect.height : lineHeight; } else { x = (isNullOrUndefined(lineHeight)) ? containerRect.x : containerRect.x + ((containerRect.width / 2) - (lineHeight / 2)); height = axis.line.width; width = (isNullOrUndefined(lineHeight)) ? containerRect.width : lineHeight; } index = this.checkPreviousAxes(axis, axisIndex); if (isNullOrUndefined(index)) { if (orientation === 'Vertical') { x = (!axis.opposedPosition ? containerRect.x : containerRect.x + containerRect.width) + axis.line.offset; } else { y = (!axis.opposedPosition ? containerRect.y : containerRect.y + containerRect.height) + axis.line.offset; } } else { prevAxis = this.gauge.axes[index]; if (orientation === 'Vertical') { x = ((!axis.opposedPosition) ? prevAxis.bounds.x : (prevAxis.bounds.x + prevAxis.bounds.width)) + axis.line.offset; } else { y = ((!axis.opposedPosition) ? prevAxis.bounds.y : (prevAxis.bounds.y + prevAxis.bounds.height)) + axis.line.offset; } } axis.lineBounds = new Rect(x, y, width, height); }; /** * Calculate axis tick bounds * @param axis * @param axisIndex */ AxisLayoutPanel.prototype.calculateTickBounds = function (axis, axisIndex) { var x; var y; var major; var minor; var min = Math.min(axis.minimum, axis.maximum); var max = Math.max(axis.minimum, axis.maximum); min = (min === max) ? max - 1 : min; var interval = axis.majorTicks.interval; var bounds = axis.lineBounds; major = axis.majorTicks; minor = axis.minorTicks; axis.majorInterval = major.interval; axis.minorInterval = minor.interval; var size = (this.gauge.orientation === 'Vertical' ? bounds.height : bounds.width); var lineSize = (this.gauge.orientation === 'Vertical' ? bounds.width : bounds.height) / 2; axis.majorInterval = isNullOrUndefined(axis.majorInterval) ? calculateNiceInterval(min, max, size, this.gauge.orientation) : major.interval; axis.visibleRange = new VisibleRange(min, max, axis.majorInterval, (max - min)); axis.minorInterval = (isNullOrUndefined(axis.minorInterval)) ? axis.majorInterval / 2 : axis.minorInterval; if (this.gauge.orientation === 'Vertical') { x = (!axis.opposedPosition ? (bounds.x - lineSize - major.height) : bounds.x + lineSize) + major.offset; axis.majorTickBounds = new Rect(x, bounds.y, major.height, bounds.height); x = (!axis.opposedPosition ? (bounds.x - lineSize - minor.height) : bounds.x + lineSize) + minor.offset; axis.minorTickBounds = new Rect(x, bounds.y, minor.height, bounds.height); } else { y = (!axis.opposedPosition ? (bounds.y - lineSize - major.height) : bounds.y + lineSize) + major.offset; axis.majorTickBounds = new Rect(bounds.x, y, bounds.width, major.height); y = (!axis.opposedPosition ? (bounds.y - lineSize - minor.height) : bounds.y + lineSize) + minor.offset; axis.minorTickBounds = new Rect(bounds.x, y, bounds.width, minor.height); } }; /** * To Calculate axis label bounds * @param axis * @param axisIndex */ AxisLayoutPanel.prototype.calculateLabelBounds = function (axis, axisIndex) { var x; var y; var width; var height; var padding = 5; var bounds = axis.majorTickBounds; var offset = axis.labelStyle.offset; this.calculateVisibleLabels(axis); width = axis.maxLabelSize.width; height = axis.maxLabelSize.height / 2; if (this.gauge.orientation === 'Vertical') { x = (!axis.opposedPosition ? (bounds.x - width - padding) : (bounds.x + bounds.width + padding)) + offset; y = axis.lineBounds.y; } else { y = (!axis.opposedPosition ? (bounds.y - padding) : ((bounds.y + bounds.height + padding) + height)) + offset; x = axis.lineBounds.x; } axis.labelBounds = new Rect(x, y, width, height); }; /** * Calculate pointer bounds * @param axis * @param axisIndex */ AxisLayoutPanel.prototype.calculatePointerBounds = function (axis, axisIndex) { var pointer; var range = axis.visibleRange; var orientation = this.gauge.orientation; var line = axis.lineBounds; var label = axis.labelBounds; var minimumValue = Math.min(range.min, range.max); var maximumValue = Math.max(range.min, range.max); for (var i = 0; i < axis.pointers.length; i++) { pointer = axis.pointers[i]; pointer.currentValue = pointer.value !== null ? pointer.value < minimumValue ? minimumValue : pointer.value > maximumValue ? maximumValue : pointer.value : minimumValue; if (pointer.width > 0 && withInRange(pointer.currentValue, null, null, range.max, range.min, 'pointer')) { this['calculate' + pointer.type + 'Bounds'](axisIndex, axis, i, pointer); } } }; /** * Calculate marker pointer bounds * @param axisIndex * @param axis * @param pointerIndex * @param pointer */ AxisLayoutPanel.prototype.calculateMarkerBounds = function (axisIndex, axis, pointerIndex, pointer) { var x; var y; var line = axis.lineBounds; var offset = pointer.offset; var range = axis.visibleRange; var placement = pointer.placement; var tick = axis.majorTickBounds; var label = axis.labelBounds; var border = pointer.border.width; if (this.gauge.orientation === 'Vertical') { x = (!axis.opposedPosition) ? (placement === 'Near') ? label.x : (placement === 'Center') ? tick.x : line.x : placement === 'Far' ? label.x + label.width : (placement === 'Center' ? tick.x + tick.width : line.x); x = !axis.opposedPosition ? ((pointer.placement === 'Far' ? x + border : x - border) + (offset)) : ((pointer.placement === 'Near' ? x - border : x + border) + (offset)); y = ((valueToCoefficient(pointer.currentValue, axis, this.gauge.orientation, range) * line.height) + line.y); } else { y = (!axis.opposedPosition) ? (placement === 'Near') ? label.y - label.height : (placement === 'Center') ? tick.y : line.y : (placement === 'Far') ? label.y : (placement === 'Center') ? tick.y + tick.height : line.y; y = !axis.opposedPosition ? ((pointer.placement === 'Far' ? y + border : y - border) + (offset)) : ((pointer.placement === 'Near' ? y - border : y + border) + (offset)); x = ((valueToCoefficient(pointer.currentValue, axis, this.gauge.orientation, range) * line.width) + line.x); } pointer.bounds = new Rect(x, y, pointer.width, pointer.height); }; /** * Calculate bar pointer bounds * @param axisIndex * @param axis * @param pointerIndex * @param pointer */ AxisLayoutPanel.prototype.calculateBarBounds = function (axisIndex, axis, pointerIndex, pointer) { var x1; var x2; var y1; var y2; var height; var width; var line = axis.lineBounds; var padding = 10; var range = axis.visibleRange; var orientation = this.gauge.orientation; var offset = pointer.offset; var container = this.gauge.containerBounds; if (orientation === 'Vertical') { x1 = (container.width > 0) ? container.x + ((container.width / 2) - (pointer.width / 2)) : (!axis.opposedPosition) ? (line.x + padding) : (line.x - pointer.width - padding); x1 += (offset); y1 = ((valueToCoefficient(pointer.currentValue, axis, orientation, range) * line.height) + line.y); y2 = ((valueToCoefficient(range.min, axis, orientation, range) * line.height) + line.y); height = Math.abs(y2 - y1); y1 = (!axis.isInversed) ? y1 : y2; width = pointer.width; } else { x1 = ((valueToCoefficient(range.min, axis, orientation, range) * line.width) + line.x); y1 = (container.height > 0) ? (container.y + (container.height / 2) - (pointer.height) / 2) : (!axis.opposedPosition) ? (line.y + padding) : (line.y - pointer.height - padding); y1 += (offset); height = pointer.height; x2 = ((valueToCoefficient(pointer.currentValue, axis, orientation, range) * line.width) + line.x); width = Math.abs(x2 - x1); x1 = (!axis.isInversed) ? x1 : x2; } pointer.bounds = new Rect(x1, y1, width, height); }; /** * Calculate ranges bounds * @param axis * @param axisIndex */ AxisLayoutPanel.prototype.calculateRangesBounds = function (axis, axisIndex) { var range; var start; var end; var line = axis.lineBounds; var visibleRange = axis.visibleRange; var orientation = this.gauge.orientation; var startVal; var endVal; var pointX; var pointY; var width; var height; var position; var startWidth; var endWidth; var colors; for (var i = 0; i < axis.ranges.length; i++) { range = axis.ranges[i]; if (withInRange(null, range.start, range.end, visibleRange.max, visibleRange.min, 'range')) { start = Math.min(range.start, range.end); end = Math.max(range.start, range.end); position = range.position; startWidth = range.startWidth; endWidth = range.e