ContinuousModel.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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'; // Constant
  45. var DEFAULT_BAR_BOUND = [20, 140];
  46. var ContinuousModel =
  47. /** @class */
  48. function (_super) {
  49. __extends(ContinuousModel, _super);
  50. function ContinuousModel() {
  51. var _this = _super !== null && _super.apply(this, arguments) || this;
  52. _this.type = ContinuousModel.type;
  53. return _this;
  54. }
  55. /**
  56. * @override
  57. */
  58. ContinuousModel.prototype.optionUpdated = function (newOption, isInit) {
  59. _super.prototype.optionUpdated.apply(this, arguments);
  60. this.resetExtent();
  61. this.resetVisual(function (mappingOption) {
  62. mappingOption.mappingMethod = 'linear';
  63. mappingOption.dataExtent = this.getExtent();
  64. });
  65. this._resetRange();
  66. };
  67. /**
  68. * @protected
  69. * @override
  70. */
  71. ContinuousModel.prototype.resetItemSize = function () {
  72. _super.prototype.resetItemSize.apply(this, arguments);
  73. var itemSize = this.itemSize;
  74. (itemSize[0] == null || isNaN(itemSize[0])) && (itemSize[0] = DEFAULT_BAR_BOUND[0]);
  75. (itemSize[1] == null || isNaN(itemSize[1])) && (itemSize[1] = DEFAULT_BAR_BOUND[1]);
  76. };
  77. /**
  78. * @private
  79. */
  80. ContinuousModel.prototype._resetRange = function () {
  81. var dataExtent = this.getExtent();
  82. var range = this.option.range;
  83. if (!range || range.auto) {
  84. // `range` should always be array (so we don't use other
  85. // value like 'auto') for user-friend. (consider getOption).
  86. dataExtent.auto = 1;
  87. this.option.range = dataExtent;
  88. } else if (zrUtil.isArray(range)) {
  89. if (range[0] > range[1]) {
  90. range.reverse();
  91. }
  92. range[0] = Math.max(range[0], dataExtent[0]);
  93. range[1] = Math.min(range[1], dataExtent[1]);
  94. }
  95. };
  96. /**
  97. * @protected
  98. * @override
  99. */
  100. ContinuousModel.prototype.completeVisualOption = function () {
  101. _super.prototype.completeVisualOption.apply(this, arguments);
  102. zrUtil.each(this.stateList, function (state) {
  103. var symbolSize = this.option.controller[state].symbolSize;
  104. if (symbolSize && symbolSize[0] !== symbolSize[1]) {
  105. symbolSize[0] = symbolSize[1] / 3; // For good looking.
  106. }
  107. }, this);
  108. };
  109. /**
  110. * @override
  111. */
  112. ContinuousModel.prototype.setSelected = function (selected) {
  113. this.option.range = selected.slice();
  114. this._resetRange();
  115. };
  116. /**
  117. * @public
  118. */
  119. ContinuousModel.prototype.getSelected = function () {
  120. var dataExtent = this.getExtent();
  121. var dataInterval = numberUtil.asc((this.get('range') || []).slice()); // 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(); // When range[0] === dataExtent[0], any value larger than dataExtent[0] maps to 'inRange'.
  134. // range[1] is processed likewise.
  135. return (range[0] <= dataExtent[0] || range[0] <= value) && (range[1] >= dataExtent[1] || value <= range[1]) ? 'inRange' : 'outOfRange';
  136. };
  137. ContinuousModel.prototype.findTargetDataIndices = function (range) {
  138. var result = [];
  139. this.eachTargetSeries(function (seriesModel) {
  140. var dataIndices = [];
  141. var data = seriesModel.getData();
  142. data.each(this.getDataDimensionIndex(data), function (value, dataIndex) {
  143. range[0] <= value && value <= range[1] && dataIndices.push(dataIndex);
  144. }, this);
  145. result.push({
  146. seriesId: seriesModel.id,
  147. dataIndex: dataIndices
  148. });
  149. }, this);
  150. return result;
  151. };
  152. /**
  153. * @implement
  154. */
  155. ContinuousModel.prototype.getVisualMeta = function (getColorVisual) {
  156. var oVals = getColorStopValues(this, 'outOfRange', this.getExtent());
  157. var iVals = getColorStopValues(this, 'inRange', this.option.range.slice());
  158. var stops = [];
  159. function setStop(value, valueState) {
  160. stops.push({
  161. value: value,
  162. color: getColorVisual(value, valueState)
  163. });
  164. } // Format to: outOfRange -- inRange -- outOfRange.
  165. var iIdx = 0;
  166. var oIdx = 0;
  167. var iLen = iVals.length;
  168. var oLen = oVals.length;
  169. for (; oIdx < oLen && (!iVals.length || oVals[oIdx] <= iVals[0]); oIdx++) {
  170. // If oVal[oIdx] === iVals[iIdx], oVal[oIdx] should be ignored.
  171. if (oVals[oIdx] < iVals[iIdx]) {
  172. setStop(oVals[oIdx], 'outOfRange');
  173. }
  174. }
  175. for (var first = 1; iIdx < iLen; iIdx++, first = 0) {
  176. // If range is full, value beyond min, max will be clamped.
  177. // make a singularity
  178. first && stops.length && setStop(iVals[iIdx], 'outOfRange');
  179. setStop(iVals[iIdx], 'inRange');
  180. }
  181. for (var first = 1; oIdx < oLen; oIdx++) {
  182. if (!iVals.length || iVals[iVals.length - 1] < oVals[oIdx]) {
  183. // make a singularity
  184. if (first) {
  185. stops.length && setStop(stops[stops.length - 1].value, 'outOfRange');
  186. first = 0;
  187. }
  188. setStop(oVals[oIdx], 'outOfRange');
  189. }
  190. }
  191. var stopsLen = stops.length;
  192. return {
  193. stops: stops,
  194. outerColors: [stopsLen ? stops[0].color : 'transparent', stopsLen ? stops[stopsLen - 1].color : 'transparent']
  195. };
  196. };
  197. ContinuousModel.type = 'visualMap.continuous';
  198. ContinuousModel.defaultOption = inheritDefaultOption(VisualMapModel.defaultOption, {
  199. align: 'auto',
  200. calculable: false,
  201. hoverLink: true,
  202. realtime: true,
  203. 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',
  204. handleSize: '120%',
  205. handleStyle: {
  206. borderColor: '#fff',
  207. borderWidth: 1
  208. },
  209. indicatorIcon: 'circle',
  210. indicatorSize: '50%',
  211. indicatorStyle: {
  212. borderColor: '#fff',
  213. borderWidth: 2,
  214. shadowBlur: 2,
  215. shadowOffsetX: 1,
  216. shadowOffsetY: 1,
  217. shadowColor: 'rgba(0,0,0,0.2)'
  218. } // emphasis: {
  219. // handleStyle: {
  220. // shadowBlur: 3,
  221. // shadowOffsetX: 1,
  222. // shadowOffsetY: 1,
  223. // shadowColor: 'rgba(0,0,0,0.2)'
  224. // }
  225. // }
  226. });
  227. return ContinuousModel;
  228. }(VisualMapModel);
  229. function getColorStopValues(visualMapModel, valueState, dataExtent) {
  230. if (dataExtent[0] === dataExtent[1]) {
  231. return dataExtent.slice();
  232. } // When using colorHue mapping, it is not linear color any more.
  233. // Moreover, canvas gradient seems not to be accurate linear.
  234. // FIXME
  235. // Should be arbitrary value 100? or based on pixel size?
  236. var count = 200;
  237. var step = (dataExtent[1] - dataExtent[0]) / count;
  238. var value = dataExtent[0];
  239. var stopValues = [];
  240. for (var i = 0; i <= count && value < dataExtent[1]; i++) {
  241. stopValues.push(value);
  242. value += step;
  243. }
  244. stopValues.push(dataExtent[1]);
  245. return stopValues;
  246. }
  247. export default ContinuousModel;