press-tooltip.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. var Util = require('../../util/common');
  3. module.exports = {
  4. _bindPress: function _bindPress() {
  5. var chart = this.chart,
  6. hammer = this.hammer,
  7. el = this.el,
  8. pressThreshold = this.pressThreshold,
  9. pressTime = this.pressTime;
  10. var tooltipController = chart.get('tooltipController');
  11. if (tooltipController && tooltipController.enable) {
  12. chart.set('_closeTooltip', true); // 用于交互的特殊标示量
  13. if (hammer) {
  14. hammer.get('press').set({
  15. threshold: pressThreshold,
  16. time: pressTime
  17. });
  18. hammer.on('press', Util.wrapBehavior(this, '_handlePress'));
  19. } else {
  20. Util.addEventListener(el, 'press', Util.wrapBehavior(this, '_handlePress'));
  21. }
  22. }
  23. },
  24. reset: function reset() {
  25. var chart = this.chart;
  26. var tooltipController = chart.get('tooltipController');
  27. if (tooltipController) {
  28. this.pressed = false;
  29. !tooltipController.cfg.alwaysShow && chart.hideTooltip();
  30. chart.set('_closeTooltip', true); // 用于交互的特殊标示量
  31. }
  32. },
  33. _handlePress: function _handlePress(e) {
  34. this.pressed = true;
  35. var center = e.center || e.touches[0];
  36. this.chart.set('_closeTooltip', false); // 用于交互的特殊标示量
  37. this.chart.showTooltip(center);
  38. }
  39. };