parallel.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var echarts = require("../echarts");
  2. var zrUtil = require("zrender/lib/core/util");
  3. var throttleUtil = require("../util/throttle");
  4. var parallelPreprocessor = require("../coord/parallel/parallelPreprocessor");
  5. require("../coord/parallel/parallelCreator");
  6. require("../coord/parallel/ParallelModel");
  7. require("./parallelAxis");
  8. var CLICK_THRESHOLD = 5; // > 4
  9. // Parallel view
  10. echarts.extendComponentView({
  11. type: 'parallel',
  12. render: function (parallelModel, ecModel, api) {
  13. this._model = parallelModel;
  14. this._api = api;
  15. if (!this._handlers) {
  16. this._handlers = {};
  17. zrUtil.each(handlers, function (handler, eventName) {
  18. api.getZr().on(eventName, this._handlers[eventName] = zrUtil.bind(handler, this));
  19. }, this);
  20. }
  21. throttleUtil.createOrUpdate(this, '_throttledDispatchExpand', parallelModel.get('axisExpandRate'), 'fixRate');
  22. },
  23. dispose: function (ecModel, api) {
  24. zrUtil.each(this._handlers, function (handler, eventName) {
  25. api.getZr().off(eventName, handler);
  26. });
  27. this._handlers = null;
  28. },
  29. /**
  30. * @param {Object} [opt] If null, cancle the last action triggering for debounce.
  31. */
  32. _throttledDispatchExpand: function (opt) {
  33. this._dispatchExpand(opt);
  34. },
  35. _dispatchExpand: function (opt) {
  36. opt && this._api.dispatchAction(zrUtil.extend({
  37. type: 'parallelAxisExpand'
  38. }, opt));
  39. }
  40. });
  41. var handlers = {
  42. mousedown: function (e) {
  43. if (checkTrigger(this, 'click')) {
  44. this._mouseDownPoint = [e.offsetX, e.offsetY];
  45. }
  46. },
  47. mouseup: function (e) {
  48. var mouseDownPoint = this._mouseDownPoint;
  49. if (checkTrigger(this, 'click') && mouseDownPoint) {
  50. var point = [e.offsetX, e.offsetY];
  51. var dist = Math.pow(mouseDownPoint[0] - point[0], 2) + Math.pow(mouseDownPoint[1] - point[1], 2);
  52. if (dist > CLICK_THRESHOLD) {
  53. return;
  54. }
  55. var result = this._model.coordinateSystem.getSlidedAxisExpandWindow([e.offsetX, e.offsetY]);
  56. result.behavior !== 'none' && this._dispatchExpand({
  57. axisExpandWindow: result.axisExpandWindow
  58. });
  59. }
  60. this._mouseDownPoint = null;
  61. },
  62. mousemove: function (e) {
  63. // Should do nothing when brushing.
  64. if (this._mouseDownPoint || !checkTrigger(this, 'mousemove')) {
  65. return;
  66. }
  67. var model = this._model;
  68. var result = model.coordinateSystem.getSlidedAxisExpandWindow([e.offsetX, e.offsetY]);
  69. var behavior = result.behavior;
  70. behavior === 'jump' && this._throttledDispatchExpand.debounceNextCall(model.get('axisExpandDebounce'));
  71. this._throttledDispatchExpand(behavior === 'none' ? null // Cancle the last trigger, in case that mouse slide out of the area quickly.
  72. : {
  73. axisExpandWindow: result.axisExpandWindow,
  74. // Jumping uses animation, and sliding suppresses animation.
  75. animation: behavior === 'jump' ? null : false
  76. });
  77. }
  78. };
  79. function checkTrigger(view, triggerOn) {
  80. var model = view._model;
  81. return model.get('axisExpandable') && model.get('axisExpandTriggerOn') === triggerOn;
  82. }
  83. echarts.registerPreprocessor(parallelPreprocessor);