tooltip.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * DevExtreme (viz/tree_map/tooltip.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 expand = require("../core/helpers").expand;
  12. require("./api");
  13. expand(proto, "_extendProxyType", function(proto) {
  14. var that = this;
  15. proto.showTooltip = function(coords) {
  16. that._showTooltip(this._id, coords)
  17. }
  18. });
  19. expand(proto, "_onNodesCreated", function() {
  20. if (this._tooltipIndex >= 0) {
  21. this._tooltip.hide()
  22. }
  23. this._tooltipIndex = -1
  24. });
  25. expand(proto, "_onTilingPerformed", function() {
  26. if (this._tooltipIndex >= 0) {
  27. this._moveTooltip(this._nodes[this._tooltipIndex])
  28. }
  29. });
  30. function getCoords(rect, renderer) {
  31. var offset = renderer.getRootOffset();
  32. return [(rect[0] + rect[2]) / 2 + offset.left, (rect[1] + rect[3]) / 2 + offset.top]
  33. }
  34. proto._showTooltip = function(index, coords) {
  35. var that = this;
  36. var tooltip = that._tooltip;
  37. var node = that._nodes[index];
  38. var state = that._tooltipIndex === index || tooltip.show({
  39. value: node.value,
  40. valueText: tooltip.formatValue(node.value),
  41. node: node.proxy
  42. }, {
  43. x: 0,
  44. y: 0,
  45. offset: 0
  46. }, {
  47. node: node.proxy
  48. });
  49. if (state) {
  50. that._moveTooltip(node, coords)
  51. } else {
  52. tooltip.hide()
  53. }
  54. that._tooltipIndex = state ? index : -1
  55. };
  56. proto._moveTooltip = function(node, coords) {
  57. var xy = coords || node.rect && getCoords(node.rect, this._renderer) || [-1e3, -1e3];
  58. this._tooltip.move(xy[0], xy[1], 0)
  59. };
  60. proto.hideTooltip = function() {
  61. if (this._tooltipIndex >= 0) {
  62. this._tooltipIndex = -1;
  63. this._tooltip.hide()
  64. }
  65. };
  66. require("./tree_map.base").addPlugin(require("../core/tooltip").plugin);