| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555 |
- /**
- * DevExtreme (viz/gauges/linear_indicators.js)
- * Version: 19.1.16
- * Build date: Tue Oct 18 2022
- *
- * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
- * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
- */
- "use strict";
- var baseIndicatorsModule = require("./base_indicators");
- var BaseIndicator = baseIndicatorsModule.BaseIndicator;
- var BaseTextCloudMarker = baseIndicatorsModule.BaseTextCloudMarker;
- var BaseRangeBar = baseIndicatorsModule.BaseRangeBar;
- var _Number = Number;
- var _normalizeEnum = require("../core/utils").normalizeEnum;
- var SimpleIndicator = BaseIndicator.inherit({
- _move: function() {
- var that = this;
- var delta = that._actualPosition - that._zeroPosition;
- that._rootElement.move(that.vertical ? 0 : delta, that.vertical ? delta : 0);
- that._trackerElement && that._trackerElement.move(that.vertical ? 0 : delta, that.vertical ? delta : 0)
- },
- _isEnabled: function() {
- this.vertical = this._options.vertical;
- return this._options.length > 0 && this._options.width > 0
- },
- _isVisible: function() {
- return true
- },
- _getTrackerSettings: function() {
- var options = this._options;
- var x1;
- var x2;
- var y1;
- var y2;
- var width = options.width / 2;
- var length = options.length / 2;
- var p = this._zeroPosition;
- width > 10 || (width = 10);
- length > 10 || (length = 10);
- if (this.vertical) {
- x1 = options.x - length;
- x2 = options.x + length;
- y1 = p + width;
- y2 = p - width
- } else {
- x1 = p - width;
- x2 = p + width;
- y1 = options.y + length;
- y2 = options.y - length
- }
- return {
- points: [x1, y1, x1, y2, x2, y2, x2, y1]
- }
- },
- _render: function() {
- var that = this;
- that._zeroPosition = that._translator.getCodomainStart()
- },
- _clear: function() {
- delete this._element
- },
- measure: function(layout) {
- var p = this.vertical ? layout.x : layout.y;
- return {
- min: p - this._options.length / 2,
- max: p + this._options.length / 2
- }
- },
- getTooltipParameters: function() {
- var that = this;
- var options = that._options;
- var p = that._actualPosition;
- var parameters = {
- x: p,
- y: p,
- value: that._currentValue,
- color: options.color,
- offset: options.width / 2
- };
- that.vertical ? parameters.x = options.x : parameters.y = options.y;
- return parameters
- }
- });
- var rectangle = SimpleIndicator.inherit({
- _render: function() {
- var that = this;
- var options = that._options;
- var x1;
- var x2;
- var y1;
- var y2;
- that.callBase();
- var p = that._zeroPosition;
- if (that.vertical) {
- x1 = options.x - options.length / 2;
- x2 = options.x + options.length / 2;
- y1 = p + options.width / 2;
- y2 = p - options.width / 2
- } else {
- x1 = p - options.width / 2;
- x2 = p + options.width / 2;
- y1 = options.y + options.length / 2;
- y2 = options.y - options.length / 2
- }
- that._element = that._element || that._renderer.path([], "area").append(that._rootElement);
- that._element.attr({
- points: [x1, y1, x1, y2, x2, y2, x2, y1]
- })
- }
- });
- var rhombus = SimpleIndicator.inherit({
- _render: function() {
- var that = this;
- var options = that._options;
- var x;
- var y;
- var dx;
- var dy;
- that.callBase();
- if (that.vertical) {
- x = options.x;
- y = that._zeroPosition;
- dx = options.length / 2 || 0;
- dy = options.width / 2 || 0
- } else {
- x = that._zeroPosition;
- y = options.y;
- dx = options.width / 2 || 0;
- dy = options.length / 2 || 0
- }
- that._element = that._element || that._renderer.path([], "area").append(that._rootElement);
- that._element.attr({
- points: [x - dx, y, x, y - dy, x + dx, y, x, y + dy]
- })
- }
- });
- var circle = SimpleIndicator.inherit({
- _render: function() {
- var that = this;
- var options = that._options;
- var x;
- var y;
- that.callBase();
- if (that.vertical) {
- x = options.x;
- y = that._zeroPosition
- } else {
- x = that._zeroPosition;
- y = options.y
- }
- var r = options.length / 2 || 0;
- that._element = that._element || that._renderer.circle().append(that._rootElement);
- that._element.attr({
- cx: x,
- cy: y,
- r: r
- })
- }
- });
- var triangleMarker = SimpleIndicator.inherit({
- _isEnabled: function() {
- var that = this;
- that.vertical = that._options.vertical;
- that._inverted = that.vertical ? "right" === _normalizeEnum(that._options.horizontalOrientation) : "bottom" === _normalizeEnum(that._options.verticalOrientation);
- return that._options.length > 0 && that._options.width > 0
- },
- _isVisible: function() {
- return true
- },
- _render: function() {
- var that = this;
- var options = that._options;
- var x1;
- var x2;
- var y1;
- var y2;
- var settings = {
- stroke: "none",
- "stroke-width": 0,
- "stroke-linecap": "square"
- };
- that.callBase();
- if (that.vertical) {
- x1 = options.x;
- y1 = that._zeroPosition;
- x2 = x1 + _Number(that._inverted ? options.length : -options.length);
- settings.points = [x1, y1, x2, y1 - options.width / 2, x2, y1 + options.width / 2]
- } else {
- y1 = options.y;
- x1 = that._zeroPosition;
- y2 = y1 + _Number(that._inverted ? options.length : -options.length);
- settings.points = [x1, y1, x1 - options.width / 2, y2, x1 + options.width / 2, y2]
- }
- if (options.space > 0) {
- settings["stroke-width"] = Math.min(options.space, options.width / 4) || 0;
- settings.stroke = settings["stroke-width"] > 0 ? options.containerBackgroundColor || "none" : "none"
- }
- that._element = that._element || that._renderer.path([], "area").append(that._rootElement);
- that._element.attr(settings).sharp()
- },
- _getTrackerSettings: function() {
- var that = this;
- var options = that._options;
- var width = options.width / 2;
- var length = _Number(options.length);
- var x1;
- var x2;
- var y1;
- var y2;
- var result;
- width > 10 || (width = 10);
- length > 20 || (length = 20);
- if (that.vertical) {
- x1 = x2 = options.x;
- x2 = x1 + (that._inverted ? length : -length);
- y1 = that._zeroPosition + width;
- y2 = that._zeroPosition - width;
- result = [x1, y1, x2, y1, x2, y2, x1, y2]
- } else {
- y1 = options.y;
- y2 = y1 + (that._inverted ? length : -length);
- x1 = that._zeroPosition - width;
- x2 = that._zeroPosition + width;
- result = [x1, y1, x1, y2, x2, y2, x2, y1]
- }
- return {
- points: result
- }
- },
- measure: function(layout) {
- var that = this;
- var length = _Number(that._options.length);
- var minBound;
- var maxBound;
- if (that.vertical) {
- minBound = maxBound = layout.x;
- if (that._inverted) {
- maxBound = minBound + length
- } else {
- minBound = maxBound - length
- }
- } else {
- minBound = maxBound = layout.y;
- if (that._inverted) {
- maxBound = minBound + length
- } else {
- minBound = maxBound - length
- }
- }
- return {
- min: minBound,
- max: maxBound,
- indent: that._options.width / 2
- }
- },
- getTooltipParameters: function() {
- var that = this;
- var options = that._options;
- var s = (that._inverted ? options.length : -options.length) / 2;
- var parameters = that.callBase();
- that.vertical ? parameters.x += s : parameters.y += s;
- parameters.offset = options.length / 2;
- return parameters
- }
- });
- var textCloud = BaseTextCloudMarker.inherit({
- _isEnabled: function() {
- var that = this;
- that.vertical = that._options.vertical;
- that._inverted = that.vertical ? "right" === _normalizeEnum(that._options.horizontalOrientation) : "bottom" === _normalizeEnum(that._options.verticalOrientation);
- return true
- },
- _isVisible: function() {
- return true
- },
- _getTextCloudOptions: function() {
- var that = this;
- var x = that._actualPosition;
- var y = that._actualPosition;
- var type;
- if (that.vertical) {
- x = that._options.x;
- type = that._inverted ? "top-left" : "top-right"
- } else {
- y = that._options.y;
- type = that._inverted ? "right-top" : "right-bottom"
- }
- return {
- x: x,
- y: y,
- type: type
- }
- },
- measure: function(layout) {
- var that = this;
- var minBound;
- var maxBound;
- var arrowLength = _Number(that._options.arrowLength) || 0;
- var indent;
- that._measureText();
- if (that.vertical) {
- indent = that._textFullHeight;
- if (that._inverted) {
- minBound = layout.x;
- maxBound = layout.x + arrowLength + that._textFullWidth
- } else {
- minBound = layout.x - arrowLength - that._textFullWidth;
- maxBound = layout.x
- }
- } else {
- indent = that._textFullWidth;
- if (that._inverted) {
- minBound = layout.y;
- maxBound = layout.y + arrowLength + that._textFullHeight
- } else {
- minBound = layout.y - arrowLength - that._textFullHeight;
- maxBound = layout.y
- }
- }
- return {
- min: minBound,
- max: maxBound,
- indent: indent
- }
- }
- });
- var rangeBar = BaseRangeBar.inherit({
- _isEnabled: function() {
- var that = this;
- that.vertical = that._options.vertical;
- that._inverted = that.vertical ? "right" === _normalizeEnum(that._options.horizontalOrientation) : "bottom" === _normalizeEnum(that._options.verticalOrientation);
- return that._options.size > 0
- },
- _isVisible: function() {
- return true
- },
- _createBarItem: function() {
- return this._renderer.path([], "area").append(this._rootElement)
- },
- _createTracker: function() {
- return this._renderer.path([], "area")
- },
- _setBarSides: function() {
- var that = this;
- var options = that._options;
- var size = _Number(options.size);
- var minSide;
- var maxSide;
- if (that.vertical) {
- if (that._inverted) {
- minSide = options.x;
- maxSide = options.x + size
- } else {
- minSide = options.x - size;
- maxSide = options.x
- }
- } else {
- if (that._inverted) {
- minSide = options.y;
- maxSide = options.y + size
- } else {
- minSide = options.y - size;
- maxSide = options.y
- }
- }
- that._minSide = minSide;
- that._maxSide = maxSide;
- that._minBound = minSide;
- that._maxBound = maxSide
- },
- _getSpace: function() {
- var options = this._options;
- return options.space > 0 ? _Number(options.space) : 0
- },
- _isTextVisible: function() {
- var textOptions = this._options.text || {};
- return textOptions.indent > 0 || textOptions.indent < 0
- },
- _getTextAlign: function() {
- return this.vertical ? this._options.text.indent > 0 ? "left" : "right" : "center"
- },
- _setTextItemsSides: function() {
- var that = this;
- var indent = _Number(that._options.text.indent);
- if (indent > 0) {
- that._lineStart = that._maxSide;
- that._lineEnd = that._maxSide + indent;
- that._textPosition = that._lineEnd + (that.vertical ? 2 : that._textHeight / 2);
- that._maxBound = that._textPosition + (that.vertical ? that._textWidth : that._textHeight / 2)
- } else {
- if (indent < 0) {
- that._lineStart = that._minSide;
- that._lineEnd = that._minSide + indent;
- that._textPosition = that._lineEnd - (that.vertical ? 2 : that._textHeight / 2);
- that._minBound = that._textPosition - (that.vertical ? that._textWidth : that._textHeight / 2)
- }
- }
- },
- _getPositions: function() {
- var that = this;
- var startPosition = that._startPosition;
- var endPosition = that._endPosition;
- var space = that._space;
- var basePosition = that._basePosition;
- var actualPosition = that._actualPosition;
- var mainPosition1;
- var mainPosition2;
- var backPosition1;
- var backPosition2;
- if (startPosition < endPosition) {
- if (basePosition < actualPosition) {
- mainPosition1 = basePosition;
- mainPosition2 = actualPosition
- } else {
- mainPosition1 = actualPosition;
- mainPosition2 = basePosition
- }
- backPosition1 = mainPosition1 - space;
- backPosition2 = mainPosition2 + space
- } else {
- if (basePosition > actualPosition) {
- mainPosition1 = basePosition;
- mainPosition2 = actualPosition
- } else {
- mainPosition1 = actualPosition;
- mainPosition2 = basePosition
- }
- backPosition1 = mainPosition1 + space;
- backPosition2 = mainPosition2 - space
- }
- return {
- start: startPosition,
- end: endPosition,
- main1: mainPosition1,
- main2: mainPosition2,
- back1: backPosition1,
- back2: backPosition2
- }
- },
- _buildItemSettings: function(from, to) {
- var that = this;
- var side1 = that._minSide;
- var side2 = that._maxSide;
- var points = that.vertical ? [side1, from, side1, to, side2, to, side2, from] : [from, side1, from, side2, to, side2, to, side1];
- return {
- points: points
- }
- },
- _updateTextPosition: function() {
- var that = this;
- that._text.attr(that.vertical ? {
- x: that._textPosition,
- y: that._actualPosition + that._textVerticalOffset
- } : {
- x: that._actualPosition,
- y: that._textPosition + that._textVerticalOffset
- })
- },
- _updateLinePosition: function() {
- var that = this;
- var actualPosition = that._actualPosition;
- var side1;
- var side2;
- var points;
- if (that.vertical) {
- if (that._basePosition >= actualPosition) {
- side1 = actualPosition;
- side2 = actualPosition + 2
- } else {
- side1 = actualPosition - 2;
- side2 = actualPosition
- }
- points = [that._lineStart, side1, that._lineStart, side2, that._lineEnd, side2, that._lineEnd, side1]
- } else {
- if (that._basePosition <= actualPosition) {
- side1 = actualPosition - 2;
- side2 = actualPosition
- } else {
- side1 = actualPosition;
- side2 = actualPosition + 2
- }
- points = [side1, that._lineStart, side1, that._lineEnd, side2, that._lineEnd, side2, that._lineStart]
- }
- that._line.attr({
- points: points
- }).sharp()
- },
- _getTooltipPosition: function() {
- var that = this;
- var crossCenter = (that._minSide + that._maxSide) / 2;
- var alongCenter = (that._basePosition + that._actualPosition) / 2;
- return that.vertical ? {
- x: crossCenter,
- y: alongCenter
- } : {
- x: alongCenter,
- y: crossCenter
- }
- },
- measure: function(layout) {
- var that = this;
- var size = _Number(that._options.size);
- var textIndent = _Number(that._options.text.indent);
- var minBound;
- var maxBound;
- var indent;
- that._measureText();
- if (that.vertical) {
- minBound = maxBound = layout.x;
- if (that._inverted) {
- maxBound += size
- } else {
- minBound -= size
- }
- if (that._hasText) {
- indent = that._textHeight / 2;
- if (textIndent > 0) {
- maxBound += textIndent + that._textWidth
- }
- if (textIndent < 0) {
- minBound += textIndent - that._textWidth
- }
- }
- } else {
- minBound = maxBound = layout.y;
- if (that._inverted) {
- maxBound += size
- } else {
- minBound -= size
- }
- if (that._hasText) {
- indent = that._textWidth / 2;
- if (textIndent > 0) {
- maxBound += textIndent + that._textHeight
- }
- if (textIndent < 0) {
- minBound += textIndent - that._textHeight
- }
- }
- }
- return {
- min: minBound,
- max: maxBound,
- indent: indent
- }
- }
- });
- exports._default = rangeBar;
- exports.rectangle = rectangle;
- exports.rhombus = rhombus;
- exports.circle = circle;
- exports.trianglemarker = triangleMarker;
- exports.textcloud = textCloud;
- exports.rangebar = rangeBar;
|