hover.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * DevExtreme (viz/tree_map/hover.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 expand = require("../core/helpers").expand;
  13. var common = require("./common");
  14. var _parseScalar = require("../core/utils").parseScalar;
  15. var _buildRectAppearance = common.buildRectAppearance;
  16. var STATE_CODE = 1;
  17. require("./api");
  18. require("./states");
  19. proto._eventsMap.onHoverChanged = {
  20. name: "hoverChanged"
  21. };
  22. expand(proto._handlers, "calculateAdditionalStates", function(states, options) {
  23. states[1] = options.hoverStyle ? _buildRectAppearance(options.hoverStyle) : {}
  24. });
  25. require("./tree_map.base").addChange({
  26. code: "HOVER_ENABLED",
  27. handler: function() {
  28. var hoverEnabled = _parseScalar(this._getOption("hoverEnabled", true), true);
  29. if (!hoverEnabled) {
  30. this.clearHover()
  31. }
  32. this._hoverEnabled = hoverEnabled
  33. },
  34. isThemeDependent: true,
  35. isOptionChange: true,
  36. option: "hoverEnabled"
  37. });
  38. nodeProto.statesMap[1] = 1;
  39. nodeProto.additionalStates.push(1);
  40. expand(proto, "_extendProxyType", function(proto) {
  41. var that = this;
  42. proto.setHover = function() {
  43. that._hoverNode(this._id)
  44. };
  45. proto.isHovered = function() {
  46. return that._hoverIndex === this._id
  47. }
  48. });
  49. expand(proto, "_onNodesCreated", function() {
  50. this._hoverIndex = -1
  51. });
  52. expand(proto, "_changeGroupSettings", function() {
  53. var that = this;
  54. that._groupHoverEnabled = _parseScalar(that._getOption("group").hoverEnabled, true);
  55. if (!that._groupHoverEnabled) {
  56. that.clearHover()
  57. }
  58. });
  59. proto._applyHoverState = function(index, state) {
  60. setNodeStateRecursive(this._nodes[index], STATE_CODE, state);
  61. this._eventTrigger("hoverChanged", {
  62. node: this._nodes[index].proxy
  63. })
  64. };
  65. function setNodeStateRecursive(node, code, state) {
  66. var nodes = node.isNode() && node.nodes;
  67. var i;
  68. var ii = nodes && nodes.length;
  69. node.setState(code, state);
  70. for (i = 0; i < ii; ++i) {
  71. setNodeStateRecursive(nodes[i], code, state)
  72. }
  73. }
  74. proto._hoverNode = function(index) {
  75. var that = this;
  76. var currentIndex = that._hoverIndex;
  77. if (that._hoverEnabled && currentIndex !== index) {
  78. if (!that._groupHoverEnabled && index >= 0 && that._nodes[index].isNode()) {
  79. that.clearHover();
  80. return
  81. }
  82. that._context.suspend();
  83. that._hoverIndex = -1;
  84. if (currentIndex >= 0) {
  85. that._applyHoverState(currentIndex, false)
  86. }
  87. that._hoverIndex = index;
  88. if (index >= 0) {
  89. that._applyHoverState(index, true)
  90. }
  91. that._context.resume()
  92. }
  93. };
  94. proto.clearHover = function() {
  95. this._hoverNode(-1)
  96. };