api.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**
  2. * DevExtreme (viz/tree_map/api.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 proto = require("./tree_map.base").prototype;
  11. var nodeProto = require("./node").prototype;
  12. var _extend = require("../../core/utils/extend").extend;
  13. proto._eventsMap.onNodesInitialized = {
  14. name: "nodesInitialized"
  15. };
  16. proto._eventsMap.onNodesRendering = {
  17. name: "nodesRendering"
  18. };
  19. proto._createProxyType = function() {
  20. var that = this;
  21. var nodes;
  22. Proxy.prototype = {
  23. constructor: Proxy,
  24. getParent: function() {
  25. return nodes[this._id].parent.proxy || null
  26. },
  27. getChild: function(index) {
  28. var _nodes = nodes[this._id].nodes;
  29. return _nodes ? _nodes[index].proxy : null
  30. },
  31. getChildrenCount: function() {
  32. var _nodes = nodes[this._id].nodes;
  33. return _nodes ? _nodes.length : 0
  34. },
  35. getAllChildren: function() {
  36. var _nodes = nodes[this._id].nodes;
  37. var i;
  38. var ii = _nodes && _nodes.length;
  39. var list = [];
  40. for (i = 0; i < ii; ++i) {
  41. list.push(_nodes[i].proxy)
  42. }
  43. return list
  44. },
  45. getAllNodes: function() {
  46. var list = [];
  47. collectNodes(nodes[this._id], list);
  48. return list
  49. },
  50. isLeaf: function() {
  51. return !nodes[this._id].isNode()
  52. },
  53. isActive: function() {
  54. return nodes[this._id].isActive()
  55. },
  56. value: function(arg) {
  57. var node = nodes[this._id];
  58. var result;
  59. if (void 0 !== arg) {
  60. updateValue(node, arg > 0 ? Number(arg) : 0);
  61. change(node, ["TILING"]);
  62. result = this
  63. } else {
  64. result = node.value
  65. }
  66. return result
  67. },
  68. label: function(arg) {
  69. var node = nodes[this._id];
  70. var result;
  71. if (void 0 !== arg) {
  72. node.customLabel = arg ? String(arg) : null;
  73. change(node, ["LABELS"]);
  74. result = this
  75. } else {
  76. result = node.customLabel || node.label
  77. }
  78. return result
  79. },
  80. customize: function(settings) {
  81. var node = nodes[this._id];
  82. if (settings) {
  83. node._custom = node._custom || {};
  84. _extend(true, node._custom, settings);
  85. node._partialState = node._partialLabelState = null
  86. }
  87. change(node, ["TILES", "LABELS"]);
  88. return this
  89. },
  90. resetCustomization: function() {
  91. var node = nodes[this._id];
  92. node._custom = node._partialState = node._partialLabelState = null;
  93. change(node, ["TILES", "LABELS"]);
  94. return this
  95. }
  96. };
  97. that._extendProxyType(Proxy.prototype);
  98. function Proxy(node) {
  99. var that = this;
  100. node.proxy = that;
  101. that._id = node._id;
  102. that.level = node.level;
  103. that.index = node.index;
  104. that.data = node.data
  105. }
  106. that._handlers.beginBuildNodes = function() {
  107. nodes = that._nodes;
  108. new Proxy(that._root)
  109. };
  110. that._handlers.buildNode = function(node) {
  111. new Proxy(node)
  112. };
  113. that._handlers.endBuildNodes = function() {
  114. that._eventTrigger("nodesInitialized", {
  115. root: that._root.proxy
  116. })
  117. }
  118. };
  119. function change(node, codes) {
  120. var ctx = node.ctx;
  121. ctx.suspend();
  122. ctx.change(codes);
  123. ctx.resume()
  124. }
  125. function collectNodes(node, list) {
  126. var nodes = node.nodes;
  127. var i;
  128. var ii = nodes && nodes.length;
  129. for (i = 0; i < ii; ++i) {
  130. list.push(nodes[i].proxy);
  131. collectNodes(nodes[i], list)
  132. }
  133. }
  134. function updateValue(node, value) {
  135. var delta = value - node.value;
  136. while (node) {
  137. node.value += delta;
  138. node = node.parent
  139. }
  140. }
  141. proto._extendProxyType = require("../../core/utils/common").noop;
  142. var _resetNodes = proto._resetNodes;
  143. proto._resetNodes = function() {
  144. _resetNodes.call(this);
  145. this._eventTrigger("nodesRendering", {
  146. node: this._topNode.proxy
  147. })
  148. };
  149. var _updateStyles = nodeProto.updateStyles;
  150. nodeProto.updateStyles = function() {
  151. var that = this;
  152. _updateStyles.call(that);
  153. if (that._custom) {
  154. that._partialState = !that.ctx.forceReset && that._partialState || that.ctx.calculateState(that._custom);
  155. _extend(true, that.state, that._partialState)
  156. }
  157. };
  158. var _updateLabelStyle = nodeProto.updateLabelStyle;
  159. nodeProto.updateLabelStyle = function() {
  160. var that = this;
  161. var custom = that._custom;
  162. _updateLabelStyle.call(that);
  163. if (custom && custom.label) {
  164. that._partialLabelState = !that.ctx.forceReset && that._partialLabelState || calculatePartialLabelState(that, custom.label);
  165. that.labelState = _extend(true, {}, that.labelState, that._partialLabelState)
  166. }
  167. };
  168. function calculatePartialLabelState(node, settings) {
  169. var state = node.ctx.calculateLabelState(settings);
  170. if ("visible" in settings) {
  171. state.visible = !!settings.visible
  172. }
  173. return state
  174. }
  175. proto.getRootNode = function() {
  176. return this._root.proxy
  177. };
  178. proto.resetNodes = function() {
  179. var context = this._context;
  180. context.suspend();
  181. context.change(["NODES_CREATE"]);
  182. context.resume();
  183. return this
  184. };