parallel.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. var echarts = require("../echarts");
  20. var zrUtil = require("zrender/lib/core/util");
  21. var throttleUtil = require("../util/throttle");
  22. var parallelPreprocessor = require("../coord/parallel/parallelPreprocessor");
  23. require("../coord/parallel/parallelCreator");
  24. require("../coord/parallel/ParallelModel");
  25. require("./parallelAxis");
  26. /*
  27. * Licensed to the Apache Software Foundation (ASF) under one
  28. * or more contributor license agreements. See the NOTICE file
  29. * distributed with this work for additional information
  30. * regarding copyright ownership. The ASF licenses this file
  31. * to you under the Apache License, Version 2.0 (the
  32. * "License"); you may not use this file except in compliance
  33. * with the License. You may obtain a copy of the License at
  34. *
  35. * http://www.apache.org/licenses/LICENSE-2.0
  36. *
  37. * Unless required by applicable law or agreed to in writing,
  38. * software distributed under the License is distributed on an
  39. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40. * KIND, either express or implied. See the License for the
  41. * specific language governing permissions and limitations
  42. * under the License.
  43. */
  44. var CLICK_THRESHOLD = 5; // > 4
  45. // Parallel view
  46. echarts.extendComponentView({
  47. type: 'parallel',
  48. render: function (parallelModel, ecModel, api) {
  49. this._model = parallelModel;
  50. this._api = api;
  51. if (!this._handlers) {
  52. this._handlers = {};
  53. zrUtil.each(handlers, function (handler, eventName) {
  54. api.getZr().on(eventName, this._handlers[eventName] = zrUtil.bind(handler, this));
  55. }, this);
  56. }
  57. throttleUtil.createOrUpdate(this, '_throttledDispatchExpand', parallelModel.get('axisExpandRate'), 'fixRate');
  58. },
  59. dispose: function (ecModel, api) {
  60. zrUtil.each(this._handlers, function (handler, eventName) {
  61. api.getZr().off(eventName, handler);
  62. });
  63. this._handlers = null;
  64. },
  65. /**
  66. * @param {Object} [opt] If null, cancle the last action triggering for debounce.
  67. */
  68. _throttledDispatchExpand: function (opt) {
  69. this._dispatchExpand(opt);
  70. },
  71. _dispatchExpand: function (opt) {
  72. opt && this._api.dispatchAction(zrUtil.extend({
  73. type: 'parallelAxisExpand'
  74. }, opt));
  75. }
  76. });
  77. var handlers = {
  78. mousedown: function (e) {
  79. if (checkTrigger(this, 'click')) {
  80. this._mouseDownPoint = [e.offsetX, e.offsetY];
  81. }
  82. },
  83. mouseup: function (e) {
  84. var mouseDownPoint = this._mouseDownPoint;
  85. if (checkTrigger(this, 'click') && mouseDownPoint) {
  86. var point = [e.offsetX, e.offsetY];
  87. var dist = Math.pow(mouseDownPoint[0] - point[0], 2) + Math.pow(mouseDownPoint[1] - point[1], 2);
  88. if (dist > CLICK_THRESHOLD) {
  89. return;
  90. }
  91. var result = this._model.coordinateSystem.getSlidedAxisExpandWindow([e.offsetX, e.offsetY]);
  92. result.behavior !== 'none' && this._dispatchExpand({
  93. axisExpandWindow: result.axisExpandWindow
  94. });
  95. }
  96. this._mouseDownPoint = null;
  97. },
  98. mousemove: function (e) {
  99. // Should do nothing when brushing.
  100. if (this._mouseDownPoint || !checkTrigger(this, 'mousemove')) {
  101. return;
  102. }
  103. var model = this._model;
  104. var result = model.coordinateSystem.getSlidedAxisExpandWindow([e.offsetX, e.offsetY]);
  105. var behavior = result.behavior;
  106. behavior === 'jump' && this._throttledDispatchExpand.debounceNextCall(model.get('axisExpandDebounce'));
  107. this._throttledDispatchExpand(behavior === 'none' ? null // Cancle the last trigger, in case that mouse slide out of the area quickly.
  108. : {
  109. axisExpandWindow: result.axisExpandWindow,
  110. // Jumping uses animation, and sliding suppresses animation.
  111. animation: behavior === 'jump' ? null : false
  112. });
  113. }
  114. };
  115. function checkTrigger(view, triggerOn) {
  116. var model = view._model;
  117. return model.get('axisExpandable') && model.get('axisExpandTriggerOn') === triggerOn;
  118. }
  119. echarts.registerPreprocessor(parallelPreprocessor);