AxisModel.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 zrUtil = require("zrender/lib/core/util");
  20. var ComponentModel = require("../../model/Component");
  21. var makeStyleMapper = require("../../model/mixin/makeStyleMapper");
  22. var axisModelCreator = require("../axisModelCreator");
  23. var numberUtil = require("../../util/number");
  24. var axisModelCommonMixin = require("../axisModelCommonMixin");
  25. /*
  26. * Licensed to the Apache Software Foundation (ASF) under one
  27. * or more contributor license agreements. See the NOTICE file
  28. * distributed with this work for additional information
  29. * regarding copyright ownership. The ASF licenses this file
  30. * to you under the Apache License, Version 2.0 (the
  31. * "License"); you may not use this file except in compliance
  32. * with the License. You may obtain a copy of the License at
  33. *
  34. * http://www.apache.org/licenses/LICENSE-2.0
  35. *
  36. * Unless required by applicable law or agreed to in writing,
  37. * software distributed under the License is distributed on an
  38. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39. * KIND, either express or implied. See the License for the
  40. * specific language governing permissions and limitations
  41. * under the License.
  42. */
  43. var AxisModel = ComponentModel.extend({
  44. type: 'baseParallelAxis',
  45. /**
  46. * @type {module:echarts/coord/parallel/Axis}
  47. */
  48. axis: null,
  49. /**
  50. * @type {Array.<Array.<number>}
  51. * @readOnly
  52. */
  53. activeIntervals: [],
  54. /**
  55. * @return {Object}
  56. */
  57. getAreaSelectStyle: function () {
  58. return makeStyleMapper([['fill', 'color'], ['lineWidth', 'borderWidth'], ['stroke', 'borderColor'], ['width', 'width'], ['opacity', 'opacity']])(this.getModel('areaSelectStyle'));
  59. },
  60. /**
  61. * The code of this feature is put on AxisModel but not ParallelAxis,
  62. * because axisModel can be alive after echarts updating but instance of
  63. * ParallelAxis having been disposed. this._activeInterval should be kept
  64. * when action dispatched (i.e. legend click).
  65. *
  66. * @param {Array.<Array<number>>} intervals interval.length === 0
  67. * means set all active.
  68. * @public
  69. */
  70. setActiveIntervals: function (intervals) {
  71. var activeIntervals = this.activeIntervals = zrUtil.clone(intervals); // Normalize
  72. if (activeIntervals) {
  73. for (var i = activeIntervals.length - 1; i >= 0; i--) {
  74. numberUtil.asc(activeIntervals[i]);
  75. }
  76. }
  77. },
  78. /**
  79. * @param {number|string} [value] When attempting to detect 'no activeIntervals set',
  80. * value can not be input.
  81. * @return {string} 'normal': no activeIntervals set,
  82. * 'active',
  83. * 'inactive'.
  84. * @public
  85. */
  86. getActiveState: function (value) {
  87. var activeIntervals = this.activeIntervals;
  88. if (!activeIntervals.length) {
  89. return 'normal';
  90. }
  91. if (value == null || isNaN(value)) {
  92. return 'inactive';
  93. } // Simple optimization
  94. if (activeIntervals.length === 1) {
  95. var interval = activeIntervals[0];
  96. if (interval[0] <= value && value <= interval[1]) {
  97. return 'active';
  98. }
  99. } else {
  100. for (var i = 0, len = activeIntervals.length; i < len; i++) {
  101. if (activeIntervals[i][0] <= value && value <= activeIntervals[i][1]) {
  102. return 'active';
  103. }
  104. }
  105. }
  106. return 'inactive';
  107. }
  108. });
  109. var defaultOption = {
  110. type: 'value',
  111. /**
  112. * @type {Array.<number>}
  113. */
  114. dim: null,
  115. // 0, 1, 2, ...
  116. // parallelIndex: null,
  117. areaSelectStyle: {
  118. width: 20,
  119. borderWidth: 1,
  120. borderColor: 'rgba(160,197,232)',
  121. color: 'rgba(160,197,232)',
  122. opacity: 0.3
  123. },
  124. realtime: true,
  125. // Whether realtime update view when select.
  126. z: 10
  127. };
  128. zrUtil.merge(AxisModel.prototype, axisModelCommonMixin);
  129. function getAxisType(axisName, option) {
  130. return option.type || (option.data ? 'category' : 'value');
  131. }
  132. axisModelCreator('parallel', AxisModel, getAxisType, defaultOption);
  133. var _default = AxisModel;
  134. module.exports = _default;