common.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /**
  2. * DevExtreme (viz/gauges/common.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var dxBaseGauge = require("./base_gauge").dxBaseGauge;
  11. var typeUtils = require("../../core/utils/type");
  12. var each = require("../../core/utils/iterator").each;
  13. var extend = require("../../core/utils/extend").extend;
  14. var _isDefined = typeUtils.isDefined;
  15. var _isArray = Array.isArray;
  16. var _isNumber = typeUtils.isNumeric;
  17. var axisModule = require("../axes/base_axis");
  18. var _map = require("../core/utils").map;
  19. var _normalizeEnum = require("../core/utils").normalizeEnum;
  20. var _compareArrays = require("./base_gauge").compareArrays;
  21. var _isFinite = isFinite;
  22. var _Number = Number;
  23. var _min = Math.min;
  24. var _max = Math.max;
  25. var _extend = extend;
  26. var _each = each;
  27. var _noop = require("../../core/utils/common").noop;
  28. var SHIFT_ANGLE = 90;
  29. var OPTION_VALUE = "value";
  30. var OPTION_SUBVALUES = "subvalues";
  31. var DEFAULT_MINOR_AXIS_DIVISION_FACTOR = 5;
  32. var DEFAULT_NUMBER_MULTIPLIERS = [1, 2, 5];
  33. function processValue(value, fallbackValue) {
  34. if (null === value) {
  35. return value
  36. }
  37. return _isFinite(value) ? _Number(value) : fallbackValue
  38. }
  39. function parseArrayOfNumbers(arg) {
  40. return _isArray(arg) ? arg : _isNumber(arg) ? [arg] : null
  41. }
  42. exports.dxGauge = dxBaseGauge.inherit({
  43. _initCore: function() {
  44. var that = this;
  45. var renderer = that._renderer;
  46. that._setupValue(that.option(OPTION_VALUE));
  47. that.__subvalues = parseArrayOfNumbers(that.option(OPTION_SUBVALUES));
  48. that._setupSubvalues(that.__subvalues);
  49. selectMode(that);
  50. that.callBase.apply(that, arguments);
  51. that._rangeContainer = new that._factory.RangeContainer({
  52. renderer: renderer,
  53. container: renderer.root,
  54. translator: that._translator,
  55. themeManager: that._themeManager
  56. });
  57. that._initScale()
  58. },
  59. _fontFields: ["scale.label.font", "valueIndicators.rangebar.text.font", "valueIndicators.textcloud.text.font", "indicator.text.font"],
  60. _initScale: function() {
  61. var that = this;
  62. that._scaleGroup = that._renderer.g().attr({
  63. "class": "dxg-scale"
  64. }).linkOn(that._renderer.root, "scale");
  65. that._scale = new axisModule.Axis({
  66. incidentOccurred: that._incidentOccurred,
  67. renderer: that._renderer,
  68. axesContainerGroup: that._scaleGroup,
  69. axisType: that._scaleTypes.type,
  70. drawingType: that._scaleTypes.drawingType,
  71. widgetClass: "dxg"
  72. })
  73. },
  74. _disposeCore: function() {
  75. var that = this;
  76. that.callBase.apply(that, arguments);
  77. that._scale.dispose();
  78. that._scaleGroup.linkOff();
  79. that._rangeContainer.dispose();
  80. that._disposeValueIndicators();
  81. that._scale = that._scaleGroup = that._rangeContainer = null
  82. },
  83. _disposeValueIndicators: function() {
  84. var that = this;
  85. that._valueIndicator && that._valueIndicator.dispose();
  86. that._subvalueIndicatorsSet && that._subvalueIndicatorsSet.dispose();
  87. that._valueIndicator = that._subvalueIndicatorsSet = null
  88. },
  89. _setupDomainCore: function() {
  90. var that = this;
  91. var scaleOption = that.option("scale") || {};
  92. var startValue = that.option("startValue");
  93. var endValue = that.option("endValue");
  94. startValue = _isNumber(startValue) ? _Number(startValue) : _isNumber(scaleOption.startValue) ? _Number(scaleOption.startValue) : 0;
  95. endValue = _isNumber(endValue) ? _Number(endValue) : _isNumber(scaleOption.endValue) ? _Number(scaleOption.endValue) : 100;
  96. that._baseValue = startValue < endValue ? startValue : endValue;
  97. that._translator.setDomain(startValue, endValue)
  98. },
  99. _cleanContent: function() {
  100. var that = this;
  101. that._rangeContainer.clean();
  102. that._cleanValueIndicators()
  103. },
  104. _measureScale: function(scaleOptions) {
  105. var that = this;
  106. var majorTick = scaleOptions.tick;
  107. var majorTickEnabled = majorTick.visible && majorTick.length > 0 && majorTick.width > 0;
  108. var minorTick = scaleOptions.minorTick;
  109. var minorTickEnabled = minorTick.visible && minorTick.length > 0 && minorTick.width > 0;
  110. var label = scaleOptions.label;
  111. var indentFromTick = Number(label.indentFromTick);
  112. if (!majorTickEnabled && !minorTickEnabled && !label.visible) {
  113. return {}
  114. }
  115. var textParams = that._scale.measureLabels(extend({}, that._canvas));
  116. var layoutValue = that._getScaleLayoutValue();
  117. var result = {
  118. min: layoutValue,
  119. max: layoutValue
  120. };
  121. var coefs = that._getTicksCoefficients(scaleOptions);
  122. var innerCoef = coefs.inner;
  123. var outerCoef = coefs.outer;
  124. if (majorTickEnabled) {
  125. result.min = _min(result.min, layoutValue - innerCoef * majorTick.length);
  126. result.max = _max(result.max, layoutValue + outerCoef * majorTick.length)
  127. }
  128. if (minorTickEnabled) {
  129. result.min = _min(result.min, layoutValue - innerCoef * minorTick.length);
  130. result.max = _max(result.max, layoutValue + outerCoef * minorTick.length)
  131. }
  132. label.visible && that._correctScaleIndents(result, indentFromTick, textParams);
  133. return result
  134. },
  135. _renderContent: function() {
  136. var that = this;
  137. var scaleOptions = that._prepareScaleSettings();
  138. that._rangeContainer.render(_extend(that._getOption("rangeContainer"), {
  139. vertical: that._area.vertical
  140. }));
  141. that._renderScale(scaleOptions);
  142. var elements = _map([that._rangeContainer].concat(that._prepareValueIndicators()), function(element) {
  143. return element && element.enabled ? element : null
  144. });
  145. that._applyMainLayout(elements, that._measureScale(scaleOptions));
  146. _each(elements, function(_, element) {
  147. element.resize(that._getElementLayout(element.getOffset()))
  148. });
  149. that._shiftScale(that._getElementLayout(0), scaleOptions);
  150. that._beginValueChanging();
  151. that._updateActiveElements();
  152. that._endValueChanging()
  153. },
  154. _prepareScaleSettings: function() {
  155. var that = this;
  156. var userOptions = that.option("scale");
  157. var scaleOptions = extend(true, {}, that._themeManager.theme("scale"), userOptions);
  158. scaleOptions.label.indentFromAxis = 0;
  159. scaleOptions.isHorizontal = !that._area.vertical;
  160. scaleOptions.forceUserTickInterval |= _isDefined(userOptions) && _isDefined(userOptions.tickInterval) && !_isDefined(userOptions.scaleDivisionFactor);
  161. scaleOptions.axisDivisionFactor = scaleOptions.scaleDivisionFactor || that._gridSpacingFactor;
  162. scaleOptions.minorAxisDivisionFactor = scaleOptions.minorScaleDivisionFactor || DEFAULT_MINOR_AXIS_DIVISION_FACTOR;
  163. scaleOptions.numberMultipliers = DEFAULT_NUMBER_MULTIPLIERS;
  164. scaleOptions.tickOrientation = that._getTicksOrientation(scaleOptions);
  165. if (scaleOptions.label.useRangeColors) {
  166. scaleOptions.label.customizeColor = function() {
  167. return that._rangeContainer.getColorForValue(this.value)
  168. }
  169. }
  170. return scaleOptions
  171. },
  172. _renderScale: function(scaleOptions) {
  173. var that = this;
  174. var bounds = that._translator.getDomain();
  175. var startValue = bounds[0];
  176. var endValue = bounds[1];
  177. var angles = that._translator.getCodomain();
  178. var invert = startValue > endValue;
  179. var min = _min(startValue, endValue);
  180. var max = _max(startValue, endValue);
  181. scaleOptions.min = min;
  182. scaleOptions.max = max;
  183. scaleOptions.startAngle = SHIFT_ANGLE - angles[0];
  184. scaleOptions.endAngle = SHIFT_ANGLE - angles[1];
  185. scaleOptions.skipViewportExtending = true;
  186. that._scale.updateOptions(scaleOptions);
  187. that._scale.setBusinessRange({
  188. axisType: "continuous",
  189. dataType: "numeric",
  190. min: min,
  191. max: max,
  192. invert: invert
  193. });
  194. that._updateScaleTickIndent(scaleOptions);
  195. that._scaleGroup.linkAppend();
  196. that._scale.draw(extend({}, that._canvas))
  197. },
  198. _updateIndicatorSettings: function(settings) {
  199. var that = this;
  200. settings.currentValue = settings.baseValue = _isFinite(that._translator.translate(settings.baseValue)) ? _Number(settings.baseValue) : that._baseValue;
  201. settings.vertical = that._area.vertical;
  202. if (settings.text && !settings.text.format) {
  203. settings.text.format = that._defaultFormatOptions
  204. }
  205. },
  206. _prepareIndicatorSettings: function(options, defaultTypeField) {
  207. var that = this;
  208. var theme = that._themeManager.theme("valueIndicators");
  209. var type = _normalizeEnum(options.type || that._themeManager.theme(defaultTypeField));
  210. var settings = _extend(true, {}, theme._default, theme[type], options);
  211. settings.type = type;
  212. settings.animation = that._animationSettings;
  213. settings.containerBackgroundColor = that._containerBackgroundColor;
  214. that._updateIndicatorSettings(settings);
  215. return settings
  216. },
  217. _cleanValueIndicators: function() {
  218. this._valueIndicator && this._valueIndicator.clean();
  219. this._subvalueIndicatorsSet && this._subvalueIndicatorsSet.clean()
  220. },
  221. _prepareValueIndicators: function() {
  222. var that = this;
  223. that._prepareValueIndicator();
  224. null !== that.__subvalues && that._prepareSubvalueIndicators();
  225. return [that._valueIndicator, that._subvalueIndicatorsSet]
  226. },
  227. _updateActiveElements: function() {
  228. this._updateValueIndicator();
  229. this._updateSubvalueIndicators()
  230. },
  231. _prepareValueIndicator: function() {
  232. var that = this;
  233. var target = that._valueIndicator;
  234. var settings = that._prepareIndicatorSettings(that.option("valueIndicator") || {}, "valueIndicatorType");
  235. if (target && target.type !== settings.type) {
  236. target.dispose();
  237. target = null
  238. }
  239. if (!target) {
  240. target = that._valueIndicator = that._createIndicator(settings.type, that._renderer.root, "dxg-value-indicator", "value-indicator")
  241. }
  242. target.render(settings)
  243. },
  244. _createSubvalueIndicatorsSet: function() {
  245. var that = this;
  246. var root = that._renderer.root;
  247. return new ValueIndicatorsSet({
  248. createIndicator: function(type, i) {
  249. return that._createIndicator(type, root, "dxg-subvalue-indicator", "subvalue-indicator", i)
  250. },
  251. createPalette: function(palette) {
  252. return that._themeManager.createPalette(palette)
  253. }
  254. })
  255. },
  256. _prepareSubvalueIndicators: function() {
  257. var that = this;
  258. var target = that._subvalueIndicatorsSet;
  259. var settings = that._prepareIndicatorSettings(that.option("subvalueIndicator") || {}, "subvalueIndicatorType");
  260. if (!target) {
  261. target = that._subvalueIndicatorsSet = that._createSubvalueIndicatorsSet()
  262. }
  263. var isRecreate = settings.type !== target.type;
  264. target.type = settings.type;
  265. var dummy = that._createIndicator(settings.type, that._renderer.root);
  266. if (dummy) {
  267. dummy.dispose();
  268. target.render(settings, isRecreate)
  269. }
  270. },
  271. _setupValue: function(value) {
  272. this.__value = processValue(value, this.__value)
  273. },
  274. _setupSubvalues: function(subvalues) {
  275. var vals = void 0 === subvalues ? this.__subvalues : parseArrayOfNumbers(subvalues);
  276. var i;
  277. var ii;
  278. var list;
  279. if (null === vals) {
  280. return
  281. }
  282. for (i = 0, ii = vals.length, list = []; i < ii; ++i) {
  283. list.push(processValue(vals[i], this.__subvalues[i]))
  284. }
  285. this.__subvalues = list
  286. },
  287. _updateValueIndicator: function() {
  288. var that = this;
  289. that._valueIndicator && that._valueIndicator.value(that.__value, that._noAnimation)
  290. },
  291. _updateSubvalueIndicators: function() {
  292. var that = this;
  293. that._subvalueIndicatorsSet && that._subvalueIndicatorsSet.values(that.__subvalues, that._noAnimation)
  294. },
  295. value: function(arg) {
  296. if (void 0 !== arg) {
  297. this._changeValue(arg);
  298. return this
  299. }
  300. return this.__value
  301. },
  302. subvalues: function(arg) {
  303. if (void 0 !== arg) {
  304. this._changeSubvalues(arg);
  305. return this
  306. }
  307. return null !== this.__subvalues ? this.__subvalues.slice() : void 0
  308. },
  309. _changeValue: function(value) {
  310. var that = this;
  311. that._setupValue(value);
  312. that._beginValueChanging();
  313. that._updateValueIndicator();
  314. if (that.__value !== that.option(OPTION_VALUE)) {
  315. that.option(OPTION_VALUE, that.__value)
  316. }
  317. that._endValueChanging()
  318. },
  319. _changeSubvalues: function(subvalues) {
  320. var that = this;
  321. if (null !== that.__subvalues) {
  322. that._setupSubvalues(subvalues);
  323. that._beginValueChanging();
  324. that._updateSubvalueIndicators();
  325. that._endValueChanging()
  326. } else {
  327. that.__subvalues = parseArrayOfNumbers(subvalues);
  328. that._setContentSize();
  329. that._renderContent()
  330. }
  331. if (!_compareArrays(that.__subvalues, that.option(OPTION_SUBVALUES))) {
  332. that.option(OPTION_SUBVALUES, that.__subvalues)
  333. }
  334. },
  335. _optionChangesMap: {
  336. scale: "DOMAIN",
  337. rangeContainer: "MOSTLY_TOTAL",
  338. valueIndicator: "MOSTLY_TOTAL",
  339. subvalueIndicator: "MOSTLY_TOTAL",
  340. containerBackgroundColor: "MOSTLY_TOTAL",
  341. value: "VALUE",
  342. subvalues: "SUBVALUES",
  343. valueIndicators: "MOSTLY_TOTAL"
  344. },
  345. _customChangesOrder: ["VALUE", "SUBVALUES"],
  346. _change_VALUE: function() {
  347. this._changeValue(this.option(OPTION_VALUE))
  348. },
  349. _change_SUBVALUES: function() {
  350. this._changeSubvalues(this.option(OPTION_SUBVALUES))
  351. },
  352. _applyMainLayout: null,
  353. _getElementLayout: null,
  354. _createIndicator: function(type, owner, className, trackerType, trackerIndex, _strict) {
  355. var that = this;
  356. var indicator = that._factory.createIndicator({
  357. renderer: that._renderer,
  358. translator: that._translator,
  359. owner: owner,
  360. tracker: that._tracker,
  361. className: className
  362. }, type, _strict);
  363. if (indicator) {
  364. indicator.type = type;
  365. indicator._trackerInfo = {
  366. type: trackerType,
  367. index: trackerIndex
  368. }
  369. }
  370. return indicator
  371. },
  372. _getApproximateScreenRange: null
  373. });
  374. function valueGetter(arg) {
  375. return arg ? arg.value : null
  376. }
  377. function setupValues(that, fieldName, optionItems) {
  378. var currentValues = that[fieldName];
  379. var newValues = _isArray(optionItems) ? _map(optionItems, valueGetter) : [];
  380. var i = 0;
  381. var ii = newValues.length;
  382. var list = [];
  383. for (; i < ii; ++i) {
  384. list.push(processValue(newValues[i], currentValues[i]))
  385. }
  386. that[fieldName] = list
  387. }
  388. function selectMode(gauge) {
  389. if (void 0 === gauge.option(OPTION_VALUE) && void 0 === gauge.option(OPTION_SUBVALUES)) {
  390. if (void 0 !== gauge.option("valueIndicators")) {
  391. disableDefaultMode(gauge);
  392. selectHardMode(gauge)
  393. }
  394. }
  395. }
  396. function disableDefaultMode(that) {
  397. that.value = that.subvalues = _noop;
  398. that._setupValue = that._setupSubvalues = that._updateValueIndicator = that._updateSubvalueIndicators = null
  399. }
  400. function selectHardMode(that) {
  401. that._indicatorValues = [];
  402. setupValues(that, "_indicatorValues", that.option("valueIndicators"));
  403. that._valueIndicators = [];
  404. var _applyMostlyTotalChange = that._applyMostlyTotalChange;
  405. that._applyMostlyTotalChange = function() {
  406. setupValues(this, "_indicatorValues", this.option("valueIndicators"));
  407. _applyMostlyTotalChange.call(this)
  408. };
  409. that._updateActiveElements = updateActiveElements_hardMode;
  410. that._prepareValueIndicators = prepareValueIndicators_hardMode;
  411. that._disposeValueIndicators = disposeValueIndicators_hardMode;
  412. that._cleanValueIndicators = cleanValueIndicators_hardMode;
  413. that.indicatorValue = indicatorValue_hardMode
  414. }
  415. function updateActiveElements_hardMode() {
  416. var that = this;
  417. _each(that._valueIndicators, function(_, valueIndicator) {
  418. valueIndicator.value(that._indicatorValues[valueIndicator.index], that._noAnimation)
  419. })
  420. }
  421. function prepareValueIndicators_hardMode() {
  422. var that = this;
  423. var valueIndicators = that._valueIndicators || [];
  424. var userOptions = that.option("valueIndicators");
  425. var optionList = [];
  426. var i = 0;
  427. var ii;
  428. for (ii = _isArray(userOptions) ? userOptions.length : 0; i < ii; ++i) {
  429. optionList.push(userOptions[i])
  430. }
  431. for (ii = valueIndicators.length; i < ii; ++i) {
  432. optionList.push(null)
  433. }
  434. var newValueIndicators = [];
  435. _each(optionList, function(i, userSettings) {
  436. var valueIndicator = valueIndicators[i];
  437. if (!userSettings) {
  438. valueIndicator && valueIndicator.dispose();
  439. return
  440. }
  441. var settings = that._prepareIndicatorSettings(userSettings, "valueIndicatorType");
  442. if (valueIndicator && valueIndicator.type !== settings.type) {
  443. valueIndicator.dispose();
  444. valueIndicator = null
  445. }
  446. if (!valueIndicator) {
  447. valueIndicator = that._createIndicator(settings.type, that._renderer.root, "dxg-value-indicator", "value-indicator", i, true)
  448. }
  449. if (valueIndicator) {
  450. valueIndicator.index = i;
  451. valueIndicator.render(settings);
  452. newValueIndicators.push(valueIndicator)
  453. }
  454. });
  455. that._valueIndicators = newValueIndicators;
  456. return that._valueIndicators
  457. }
  458. function disposeValueIndicators_hardMode() {
  459. _each(this._valueIndicators, function(_, valueIndicator) {
  460. valueIndicator.dispose()
  461. });
  462. this._valueIndicators = null
  463. }
  464. function cleanValueIndicators_hardMode() {
  465. _each(this._valueIndicators, function(_, valueIndicator) {
  466. valueIndicator.clean()
  467. })
  468. }
  469. function indicatorValue_hardMode(index, value) {
  470. return accessPointerValue(this, this._valueIndicators, this._indicatorValues, index, value)
  471. }
  472. function accessPointerValue(that, pointers, values, index, value) {
  473. if (void 0 !== value) {
  474. if (void 0 !== values[index]) {
  475. values[index] = processValue(value, values[index]);
  476. pointers[index] && pointers[index].value(values[index])
  477. }
  478. return that
  479. } else {
  480. return values[index]
  481. }
  482. }
  483. function ValueIndicatorsSet(parameters) {
  484. this._parameters = parameters;
  485. this._indicators = []
  486. }
  487. ValueIndicatorsSet.prototype = {
  488. constructor: ValueIndicatorsSet,
  489. dispose: function() {
  490. var that = this;
  491. _each(that._indicators, function(_, indicator) {
  492. indicator.dispose()
  493. });
  494. that._parameters = that._options = that._indicators = that._colorPalette = that._palette = null;
  495. return that
  496. },
  497. clean: function() {
  498. var that = this;
  499. that._sample && that._sample.clean().dispose();
  500. _each(that._indicators, function(_, indicator) {
  501. indicator.clean()
  502. });
  503. that._sample = that._options = that._palette = null;
  504. return that
  505. },
  506. render: function(options, isRecreate) {
  507. var that = this;
  508. that._options = options;
  509. that._sample = that._parameters.createIndicator(that.type);
  510. that._sample.render(options);
  511. that.enabled = that._sample.enabled;
  512. that._palette = _isDefined(options.palette) ? that._parameters.createPalette(options.palette) : null;
  513. if (that.enabled) {
  514. that._generatePalette(that._indicators.length);
  515. that._indicators = _map(that._indicators, function(indicator, i) {
  516. if (isRecreate) {
  517. indicator.dispose();
  518. indicator = that._parameters.createIndicator(that.type, i)
  519. }
  520. indicator.render(that._getIndicatorOptions(i));
  521. return indicator
  522. })
  523. }
  524. return that
  525. },
  526. getOffset: function() {
  527. return this._sample.getOffset()
  528. },
  529. resize: function(layout) {
  530. var that = this;
  531. that._layout = layout;
  532. _each(that._indicators, function(_, indicator) {
  533. indicator.resize(layout)
  534. });
  535. return that
  536. },
  537. measure: function(layout) {
  538. return this._sample.measure(layout)
  539. },
  540. _getIndicatorOptions: function(index) {
  541. var result = this._options;
  542. if (this._colorPalette) {
  543. result = _extend({}, result, {
  544. color: this._colorPalette[index]
  545. })
  546. }
  547. return result
  548. },
  549. _generatePalette: function(count) {
  550. var that = this;
  551. var colors = null;
  552. if (that._palette) {
  553. that._palette.reset();
  554. colors = that._palette.generateColors(count, {
  555. repeat: true
  556. })
  557. }
  558. that._colorPalette = colors
  559. },
  560. _adjustIndicatorsCount: function(count) {
  561. var that = this;
  562. var indicators = that._indicators;
  563. var i;
  564. var ii;
  565. var indicator;
  566. var indicatorsLen = indicators.length;
  567. if (indicatorsLen > count) {
  568. for (i = count, ii = indicatorsLen; i < ii; ++i) {
  569. indicators[i].clean().dispose()
  570. }
  571. that._indicators = indicators.slice(0, count);
  572. that._generatePalette(indicators.length)
  573. } else {
  574. if (indicatorsLen < count) {
  575. that._generatePalette(count);
  576. for (i = indicatorsLen, ii = count; i < ii; ++i) {
  577. indicator = that._parameters.createIndicator(that.type, i);
  578. indicator.render(that._getIndicatorOptions(i)).resize(that._layout);
  579. indicators.push(indicator)
  580. }
  581. }
  582. }
  583. },
  584. values: function(arg, _noAnimation) {
  585. var that = this;
  586. if (!that.enabled) {
  587. return
  588. }
  589. if (void 0 !== arg) {
  590. if (!_isArray(arg)) {
  591. arg = _isFinite(arg) ? [Number(arg)] : null
  592. }
  593. if (arg) {
  594. that._adjustIndicatorsCount(arg.length);
  595. _each(that._indicators, function(i, indicator) {
  596. indicator.value(arg[i], _noAnimation)
  597. })
  598. }
  599. return that
  600. }
  601. return _map(that._indicators, function(indicator) {
  602. return indicator.value()
  603. })
  604. }
  605. };
  606. exports.createIndicatorCreator = function(indicators) {
  607. return function(parameters, type, _strict) {
  608. var indicatorType = indicators[_normalizeEnum(type)] || !_strict && indicators._default;
  609. return indicatorType ? new indicatorType(parameters) : null
  610. }
  611. };