| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- /**
- * DevExtreme (viz/gauges/linear_gauge.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 _each = require("../../core/utils/iterator").each;
- var _max = Math.max;
- var _min = Math.min;
- var _round = Math.round;
- var registerComponent = require("../../core/component_registrator");
- var extend = require("../../core/utils/extend").extend;
- var objectUtils = require("../../core/utils/object");
- var dxBaseGauge = require("./base_gauge").dxBaseGauge;
- var dxGauge = require("./common").dxGauge;
- var _normalizeEnum = require("../core/utils").normalizeEnum;
- var linearIndicatorsModule = require("./linear_indicators");
- var createIndicatorCreator = require("./common").createIndicatorCreator;
- var LinearRangeContainer = require("./linear_range_container");
- var dxLinearGauge = dxGauge.inherit({
- _rootClass: "dxg-linear-gauge",
- _factoryMethods: {
- rangeContainer: "createLinearRangeContainer",
- indicator: "createLinearIndicator"
- },
- _gridSpacingFactor: 25,
- _scaleTypes: {
- type: "xyAxes",
- drawingType: "linear"
- },
- _getTicksOrientation: function(scaleOptions) {
- return scaleOptions.isHorizontal ? scaleOptions.verticalOrientation : scaleOptions.horizontalOrientation
- },
- _getThemeManagerOptions: function() {
- var options = this.callBase.apply(this, arguments);
- options.subTheme = "_linear";
- return options
- },
- _updateScaleTickIndent: function(scaleOptions) {
- var indentFromTick = scaleOptions.label.indentFromTick;
- var length = scaleOptions.tick.length;
- var textParams = this._scale.measureLabels(extend({}, this._canvas));
- var verticalTextCorrection = scaleOptions.isHorizontal ? textParams.height + textParams.y : 0;
- var isIndentPositive = indentFromTick > 0;
- var orientation;
- var textCorrection;
- var tickCorrection;
- if (scaleOptions.isHorizontal) {
- orientation = isIndentPositive ? {
- center: .5,
- top: 0,
- bottom: 1
- } : {
- center: .5,
- top: 1,
- bottom: 0
- };
- tickCorrection = length * orientation[scaleOptions.verticalOrientation];
- textCorrection = textParams.y
- } else {
- orientation = isIndentPositive ? {
- center: .5,
- left: 0,
- right: 1
- } : {
- center: .5,
- left: 1,
- right: 0
- };
- tickCorrection = length * orientation[scaleOptions.horizontalOrientation];
- textCorrection = -textParams.width
- }
- scaleOptions.label.indentFromAxis = -indentFromTick + (isIndentPositive ? -tickCorrection + textCorrection : tickCorrection - verticalTextCorrection);
- this._scale.updateOptions(scaleOptions)
- },
- _shiftScale: function(layout, scaleOptions) {
- var that = this;
- var canvas = extend({}, that._canvas);
- var isHorizontal = scaleOptions.isHorizontal;
- var scale = that._scale;
- canvas[isHorizontal ? "left" : "top"] = that._area[isHorizontal ? "startCoord" : "endCoord"];
- canvas[isHorizontal ? "right" : "bottom"] = canvas[isHorizontal ? "width" : "height"] - that._area[isHorizontal ? "endCoord" : "startCoord"];
- scale.draw(canvas);
- scale.shift({
- left: -layout.x,
- top: -layout.y
- })
- },
- _setupCodomain: function() {
- var that = this;
- var geometry = that.option("geometry") || {};
- var vertical = "vertical" === _normalizeEnum(geometry.orientation);
- var initialStartCoord = -100;
- var initialEndCoord = 100;
- that._area = {
- vertical: vertical,
- x: 0,
- y: 0,
- startCoord: initialStartCoord,
- endCoord: initialEndCoord
- };
- that._rangeContainer.vertical = vertical;
- that._translator.setCodomain(initialStartCoord, initialEndCoord)
- },
- _getScaleLayoutValue: function() {
- return this._area[this._area.vertical ? "x" : "y"]
- },
- _getTicksCoefficients: function(options) {
- var coefs = {
- inner: 0,
- outer: 1
- };
- if (this._area.vertical) {
- if ("left" === options.horizontalOrientation) {
- coefs.inner = 1;
- coefs.outer = 0
- } else {
- if ("center" === options.horizontalOrientation) {
- coefs.inner = coefs.outer = .5
- }
- }
- } else {
- if ("top" === options.verticalOrientation) {
- coefs.inner = 1;
- coefs.outer = 0
- } else {
- if ("center" === options.verticalOrientation) {
- coefs.inner = coefs.outer = .5
- }
- }
- }
- return coefs
- },
- _correctScaleIndents: function(result, indentFromTick, textParams) {
- var vertical = this._area.vertical;
- if (indentFromTick >= 0) {
- result.max += indentFromTick + textParams[vertical ? "width" : "height"]
- } else {
- result.min -= -indentFromTick + textParams[vertical ? "width" : "height"]
- }
- result.indent = textParams[vertical ? "height" : "width"] / 2
- },
- _measureMainElements: function(elements, scaleMeasurement) {
- var that = this;
- var x = that._area.x;
- var y = that._area.y;
- var minBound = 1e3;
- var maxBound = 0;
- var indent = 0;
- var scale = that._scale;
- _each(elements.concat(scale), function(_, element) {
- var bounds = element.measure ? element.measure({
- x: x + element.getOffset(),
- y: y + element.getOffset()
- }) : scaleMeasurement;
- void 0 !== bounds.max && (maxBound = _max(maxBound, bounds.max));
- void 0 !== bounds.min && (minBound = _min(minBound, bounds.min));
- bounds.indent > 0 && (indent = _max(indent, bounds.indent))
- });
- return {
- minBound: minBound,
- maxBound: maxBound,
- indent: indent
- }
- },
- _applyMainLayout: function(elements, scaleMeasurement) {
- var that = this;
- var measurements = that._measureMainElements(elements, scaleMeasurement);
- var area = that._area;
- var rect;
- var offset;
- if (area.vertical) {
- rect = selectRectBySizes(that._innerRect, {
- width: measurements.maxBound - measurements.minBound
- });
- offset = (rect.left + rect.right) / 2 - (measurements.minBound + measurements.maxBound) / 2;
- area.startCoord = rect.bottom - measurements.indent;
- area.endCoord = rect.top + measurements.indent;
- area.x = _round(area.x + offset)
- } else {
- rect = selectRectBySizes(that._innerRect, {
- height: measurements.maxBound - measurements.minBound
- });
- offset = (rect.top + rect.bottom) / 2 - (measurements.minBound + measurements.maxBound) / 2;
- area.startCoord = rect.left + measurements.indent;
- area.endCoord = rect.right - measurements.indent;
- area.y = _round(area.y + offset)
- }
- that._translator.setCodomain(area.startCoord, area.endCoord);
- that._innerRect = rect
- },
- _getElementLayout: function(offset) {
- return {
- x: _round(this._area.x + offset),
- y: _round(this._area.y + offset)
- }
- },
- _getApproximateScreenRange: function() {
- var that = this;
- var area = that._area;
- var s = area.vertical ? that._canvas.height : that._canvas.width;
- s > area.totalSize && (s = area.totalSize);
- s = .8 * s;
- return s
- },
- _getDefaultSize: function() {
- var geometry = this.option("geometry") || {};
- if ("vertical" === geometry.orientation) {
- return {
- width: 100,
- height: 300
- }
- } else {
- return {
- width: 300,
- height: 100
- }
- }
- },
- _factory: objectUtils.clone(dxBaseGauge.prototype._factory)
- });
- function selectRectBySizes(srcRect, sizes, margins) {
- var rect = extend({}, srcRect);
- var step;
- margins = margins || {};
- if (sizes) {
- rect.left += margins.left || 0;
- rect.right -= margins.right || 0;
- rect.top += margins.top || 0;
- rect.bottom -= margins.bottom || 0;
- if (sizes.width > 0) {
- step = (rect.right - rect.left - sizes.width) / 2;
- if (step > 0) {
- rect.left += step;
- rect.right -= step
- }
- }
- if (sizes.height > 0) {
- step = (rect.bottom - rect.top - sizes.height) / 2;
- if (step > 0) {
- rect.top += step;
- rect.bottom -= step
- }
- }
- }
- return rect
- }
- var indicators = dxLinearGauge.prototype._factory.indicators = {};
- dxLinearGauge.prototype._factory.createIndicator = createIndicatorCreator(indicators);
- indicators._default = linearIndicatorsModule._default;
- indicators.rectangle = linearIndicatorsModule.rectangle;
- indicators.rhombus = linearIndicatorsModule.rhombus;
- indicators.circle = linearIndicatorsModule.circle;
- indicators.trianglemarker = linearIndicatorsModule.trianglemarker;
- indicators.textcloud = linearIndicatorsModule.textcloud;
- indicators.rangebar = linearIndicatorsModule.rangebar;
- dxLinearGauge.prototype._factory.RangeContainer = LinearRangeContainer;
- registerComponent("dxLinearGauge", dxLinearGauge);
- module.exports = dxLinearGauge;
|