tooltip.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * DevExtreme (viz/funnel/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 noop = require("../../core/utils/common").noop;
  11. function getCoords(figureCoords, renderer) {
  12. var offset = renderer.getRootOffset();
  13. return [(figureCoords[0] + figureCoords[2]) / 2 + offset.left, (figureCoords[1] + figureCoords[5]) / 2 + offset.top]
  14. }
  15. exports.plugin = {
  16. name: "funnel-tooltip",
  17. init: noop,
  18. dispose: noop,
  19. extenders: {
  20. _buildNodes: function() {
  21. this.hideTooltip()
  22. },
  23. _change_TILING: function() {
  24. if (this._tooltipIndex >= 0) {
  25. this._moveTooltip(this._items[this._tooltipIndex])
  26. }
  27. }
  28. },
  29. members: {
  30. hideTooltip: function() {
  31. if (this._tooltipIndex >= 0) {
  32. this._tooltipIndex = -1;
  33. this._tooltip.hide()
  34. }
  35. },
  36. _moveTooltip: function(item, coords) {
  37. var xy = coords || item.coords && getCoords(item.coords, this._renderer) || [-1e3, -1e3];
  38. this._tooltip.move(xy[0], xy[1], 0)
  39. },
  40. _showTooltip: function(index, coords) {
  41. var that = this;
  42. var tooltip = that._tooltip;
  43. var item = that._items[index];
  44. var state = that._tooltipIndex === index || tooltip.show({
  45. value: item.value,
  46. valueText: tooltip.formatValue(item.value),
  47. percentText: tooltip.formatValue(item.percent, "percent"),
  48. percent: item.percent,
  49. item: item
  50. }, {
  51. x: 0,
  52. y: 0,
  53. offset: 0
  54. }, {
  55. item: item
  56. });
  57. if (state) {
  58. that._moveTooltip(item, coords)
  59. } else {
  60. tooltip.hide()
  61. }
  62. that._tooltipIndex = state ? index : -1
  63. }
  64. },
  65. customize: function(constructor) {
  66. constructor.addPlugin(require("../core/tooltip").plugin)
  67. }
  68. };