ContinuousModel.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import VisualMapModel from './VisualMapModel.js';
  43. import * as numberUtil from '../../util/number.js';
  44. import { inheritDefaultOption } from '../../util/component.js';
  45. // Constant
  46. var DEFAULT_BAR_BOUND = [20, 140];
  47. var ContinuousModel = /** @class */function (_super) {
  48. __extends(ContinuousModel, _super);
  49. function ContinuousModel() {
  50. var _this = _super !== null && _super.apply(this, arguments) || this;
  51. _this.type = ContinuousModel.type;
  52. return _this;
  53. }
  54. /**
  55. * @override
  56. */
  57. ContinuousModel.prototype.optionUpdated = function (newOption, isInit) {
  58. _super.prototype.optionUpdated.apply(this, arguments);
  59. this.resetExtent();
  60. this.resetVisual(function (mappingOption) {
  61. mappingOption.mappingMethod = 'linear';
  62. mappingOption.dataExtent = this.getExtent();
  63. });
  64. this._resetRange();
  65. };
  66. /**
  67. * @protected
  68. * @override
  69. */
  70. ContinuousModel.prototype.resetItemSize = function () {
  71. _super.prototype.resetItemSize.apply(this, arguments);
  72. var itemSize = this.itemSize;
  73. (itemSize[0] == null || isNaN(itemSize[0])) && (itemSize[0] = DEFAULT_BAR_BOUND[0]);
  74. (itemSize[1] == null || isNaN(itemSize[1])) && (itemSize[1] = DEFAULT_BAR_BOUND[1]);
  75. };
  76. /**
  77. * @private
  78. */
  79. ContinuousModel.prototype._resetRange = function () {
  80. var dataExtent = this.getExtent();
  81. var range = this.option.range;
  82. if (!range || range.auto) {
  83. // `range` should always be array (so we don't use other
  84. // value like 'auto') for user-friend. (consider getOption).
  85. dataExtent.auto = 1;
  86. this.option.range = dataExtent;
  87. } else if (zrUtil.isArray(range)) {
  88. if (range[0] > range[1]) {
  89. range.reverse();
  90. }
  91. range[0] = Math.max(range[0], dataExtent[0]);
  92. range[1] = Math.min(range[1], dataExtent[1]);
  93. }
  94. };
  95. /**
  96. * @protected
  97. * @override
  98. */
  99. ContinuousModel.prototype.completeVisualOption = function () {
  100. _super.prototype.completeVisualOption.apply(this, arguments);
  101. zrUtil.each(this.stateList, function (state) {
  102. var symbolSize = this.option.controller[state].symbolSize;
  103. if (symbolSize && symbolSize[0] !== symbolSize[1]) {
  104. symbolSize[0] = symbolSize[1] / 3; // For good looking.
  105. }
  106. }, this);
  107. };
  108. /**
  109. * @override
  110. */
  111. ContinuousModel.prototype.setSelected = function (selected) {
  112. this.option.range = selected.slice();
  113. this._resetRange();
  114. };
  115. /**
  116. * @public
  117. */
  118. ContinuousModel.prototype.getSelected = function () {
  119. var dataExtent = this.getExtent();
  120. var dataInterval = numberUtil.asc((this.get('range') || []).slice());
  121. // Clamp
  122. dataInterval[0] > dataExtent[1] && (dataInterval[0] = dataExtent[1]);
  123. dataInterval[1] > dataExtent[1] && (dataInterval[1] = dataExtent[1]);
  124. dataInterval[0] < dataExtent[0] && (dataInterval[0] = dataExtent[0]);
  125. dataInterval[1] < dataExtent[0] && (dataInterval[1] = dataExtent[0]);
  126. return dataInterval;
  127. };
  128. /**
  129. * @override
  130. */
  131. ContinuousModel.prototype.getValueState = function (value) {
  132. var range = this.option.range;
  133. var dataExtent = this.getExtent();
  134. // When range[0] === dataExtent[0], any value larger than dataExtent[0] maps to 'inRange'.
  135. // range[1] is processed likewise.
  136. return (range[0] <= dataExtent[0] || range[0] <= value) && (range[1] >= dataExtent[1] || value <= range[1]) ? 'inRange' : 'outOfRange';
  137. };
  138. ContinuousModel.prototype.findTargetDataIndices = function (range) {
  139. var result = [];
  140. this.eachTargetSeries(function (seriesModel) {
  141. var dataIndices = [];
  142. var data = seriesModel.getData();
  143. data.each(this.getDataDimensionIndex(data), function (value, dataIndex) {
  144. range[0] <= value && value <= range[1] && dataIndices.push(dataIndex);
  145. }, this);
  146. result.push({
  147. seriesId: seriesModel.id,
  148. dataIndex: dataIndices
  149. });
  150. }, this);
  151. return result;
  152. };
  153. /**
  154. * @implement
  155. */
  156. ContinuousModel.prototype.getVisualMeta = function (getColorVisual) {
  157. var oVals = getColorStopValues(this, 'outOfRange', this.getExtent());
  158. var iVals = getColorStopValues(this, 'inRange', this.option.range.slice());
  159. var stops = [];
  160. function setStop(value, valueState) {
  161. stops.push({
  162. value: value,
  163. color: getColorVisual(value, valueState)
  164. });
  165. }
  166. // Format to: outOfRange -- inRange -- outOfRange.
  167. var iIdx = 0;
  168. var oIdx = 0;
  169. var iLen = iVals.length;
  170. var oLen = oVals.length;
  171. for (; oIdx < oLen && (!iVals.length || oVals[oIdx] <= iVals[0]); oIdx++) {
  172. // If oVal[oIdx] === iVals[iIdx], oVal[oIdx] should be ignored.
  173. if (oVals[oIdx] < iVals[iIdx]) {
  174. setStop(oVals[oIdx], 'outOfRange');
  175. }
  176. }
  177. for (var first = 1; iIdx < iLen; iIdx++, first = 0) {
  178. // If range is full, value beyond min, max will be clamped.
  179. // make a singularity
  180. first && stops.length && setStop(iVals[iIdx], 'outOfRange');
  181. setStop(iVals[iIdx], 'inRange');
  182. }
  183. for (var first = 1; oIdx < oLen; oIdx++) {
  184. if (!iVals.length || iVals[iVals.length - 1] < oVals[oIdx]) {
  185. // make a singularity
  186. if (first) {
  187. stops.length && setStop(stops[stops.length - 1].value, 'outOfRange');
  188. first = 0;
  189. }
  190. setStop(oVals[oIdx], 'outOfRange');
  191. }
  192. }
  193. var stopsLen = stops.length;
  194. return {
  195. stops: stops,
  196. outerColors: [stopsLen ? stops[0].color : 'transparent', stopsLen ? stops[stopsLen - 1].color : 'transparent']
  197. };
  198. };
  199. ContinuousModel.type = 'visualMap.continuous';
  200. ContinuousModel.defaultOption = inheritDefaultOption(VisualMapModel.defaultOption, {
  201. align: 'auto',
  202. calculable: false,
  203. hoverLink: true,
  204. realtime: true,
  205. handleIcon: 'path://M-11.39,9.77h0a3.5,3.5,0,0,1-3.5,3.5h-22a3.5,3.5,0,0,1-3.5-3.5h0a3.5,3.5,0,0,1,3.5-3.5h22A3.5,3.5,0,0,1-11.39,9.77Z',
  206. handleSize: '120%',
  207. handleStyle: {
  208. borderColor: '#fff',
  209. borderWidth: 1
  210. },
  211. indicatorIcon: 'circle',
  212. indicatorSize: '50%',
  213. indicatorStyle: {
  214. borderColor: '#fff',
  215. borderWidth: 2,
  216. shadowBlur: 2,
  217. shadowOffsetX: 1,
  218. shadowOffsetY: 1,
  219. shadowColor: 'rgba(0,0,0,0.2)'
  220. }
  221. // emphasis: {
  222. // handleStyle: {
  223. // shadowBlur: 3,
  224. // shadowOffsetX: 1,
  225. // shadowOffsetY: 1,
  226. // shadowColor: 'rgba(0,0,0,0.2)'
  227. // }
  228. // }
  229. });
  230. return ContinuousModel;
  231. }(VisualMapModel);
  232. function getColorStopValues(visualMapModel, valueState, dataExtent) {
  233. if (dataExtent[0] === dataExtent[1]) {
  234. return dataExtent.slice();
  235. }
  236. // When using colorHue mapping, it is not linear color any more.
  237. // Moreover, canvas gradient seems not to be accurate linear.
  238. // FIXME
  239. // Should be arbitrary value 100? or based on pixel size?
  240. var count = 200;
  241. var step = (dataExtent[1] - dataExtent[0]) / count;
  242. var value = dataExtent[0];
  243. var stopValues = [];
  244. for (var i = 0; i <= count && value < dataExtent[1]; i++) {
  245. stopValues.push(value);
  246. value += step;
  247. }
  248. stopValues.push(dataExtent[1]);
  249. return stopValues;
  250. }
  251. export default ContinuousModel;