tooltip.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * DevExtreme (viz/sankey/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. Object.defineProperty(exports, "__esModule", {
  11. value: true
  12. });
  13. exports.setTooltipCustomOptions = setTooltipCustomOptions;
  14. var _extend = require("../../core/utils/extend").extend;
  15. var isFunction = require("../../core/utils/type").isFunction;
  16. var defaultCustomizeLinkTooltip = function(info) {
  17. return {
  18. html: "<strong>".concat(info.source, " > ").concat(info.target, "</strong><br/>Weight: ").concat(info.weight)
  19. }
  20. };
  21. var defaultCustomizeNodeTooltip = function(info) {
  22. return {
  23. html: "<strong>".concat(info.title, "</strong><br/>Incoming weight: ").concat(info.weightIn, "<br/>Outgoing weight: ").concat(info.weightOut)
  24. }
  25. };
  26. var generateCustomCallback = function(customCallback, defaultCallback) {
  27. return function(objectInfo) {
  28. var res = isFunction(customCallback) ? customCallback.call(objectInfo, objectInfo) : {};
  29. var hasOwnProperty = Object.prototype.hasOwnProperty.bind(res);
  30. if (!hasOwnProperty("html") && !hasOwnProperty("text")) {
  31. res = _extend(res, defaultCallback.call(objectInfo, objectInfo))
  32. }
  33. return res
  34. }
  35. };
  36. function setTooltipCustomOptions(sankey) {
  37. sankey.prototype._setTooltipOptions = function() {
  38. var tooltip = this._tooltip;
  39. var options = tooltip && this._getOption("tooltip");
  40. tooltip && tooltip.update(_extend({}, options, {
  41. customizeTooltip: function(args) {
  42. if ("node" === args.type) {
  43. return generateCustomCallback(options.customizeNodeTooltip, defaultCustomizeNodeTooltip)(args.info)
  44. } else {
  45. if ("link" === args.type) {
  46. return generateCustomCallback(options.customizeLinkTooltip, defaultCustomizeLinkTooltip)(args.info)
  47. }
  48. }
  49. return {}
  50. },
  51. enabled: options.enabled
  52. }))
  53. };
  54. sankey.prototype.hideTooltip = function() {
  55. this._tooltip && this._tooltip.hide()
  56. }
  57. }