LinesSeries.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. /* global Uint32Array, Float64Array, Float32Array */
  42. import SeriesModel from '../../model/Series.js';
  43. import SeriesData from '../../data/SeriesData.js';
  44. import { concatArray, mergeAll, map, isNumber } from 'zrender/lib/core/util.js';
  45. import CoordinateSystem from '../../core/CoordinateSystem.js';
  46. import { createTooltipMarkup } from '../../component/tooltip/tooltipMarkup.js';
  47. var Uint32Arr = typeof Uint32Array === 'undefined' ? Array : Uint32Array;
  48. var Float64Arr = typeof Float64Array === 'undefined' ? Array : Float64Array;
  49. function compatEc2(seriesOpt) {
  50. var data = seriesOpt.data;
  51. if (data && data[0] && data[0][0] && data[0][0].coord) {
  52. if (process.env.NODE_ENV !== 'production') {
  53. console.warn('Lines data configuration has been changed to' + ' { coords:[[1,2],[2,3]] }');
  54. }
  55. seriesOpt.data = map(data, function (itemOpt) {
  56. var coords = [itemOpt[0].coord, itemOpt[1].coord];
  57. var target = {
  58. coords: coords
  59. };
  60. if (itemOpt[0].name) {
  61. target.fromName = itemOpt[0].name;
  62. }
  63. if (itemOpt[1].name) {
  64. target.toName = itemOpt[1].name;
  65. }
  66. return mergeAll([target, itemOpt[0], itemOpt[1]]);
  67. });
  68. }
  69. }
  70. var LinesSeriesModel = /** @class */function (_super) {
  71. __extends(LinesSeriesModel, _super);
  72. function LinesSeriesModel() {
  73. var _this = _super !== null && _super.apply(this, arguments) || this;
  74. _this.type = LinesSeriesModel.type;
  75. _this.visualStyleAccessPath = 'lineStyle';
  76. _this.visualDrawType = 'stroke';
  77. return _this;
  78. }
  79. LinesSeriesModel.prototype.init = function (option) {
  80. // The input data may be null/undefined.
  81. option.data = option.data || [];
  82. // Not using preprocessor because mergeOption may not have series.type
  83. compatEc2(option);
  84. var result = this._processFlatCoordsArray(option.data);
  85. this._flatCoords = result.flatCoords;
  86. this._flatCoordsOffset = result.flatCoordsOffset;
  87. if (result.flatCoords) {
  88. option.data = new Float32Array(result.count);
  89. }
  90. _super.prototype.init.apply(this, arguments);
  91. };
  92. LinesSeriesModel.prototype.mergeOption = function (option) {
  93. compatEc2(option);
  94. if (option.data) {
  95. // Only update when have option data to merge.
  96. var result = this._processFlatCoordsArray(option.data);
  97. this._flatCoords = result.flatCoords;
  98. this._flatCoordsOffset = result.flatCoordsOffset;
  99. if (result.flatCoords) {
  100. option.data = new Float32Array(result.count);
  101. }
  102. }
  103. _super.prototype.mergeOption.apply(this, arguments);
  104. };
  105. LinesSeriesModel.prototype.appendData = function (params) {
  106. var result = this._processFlatCoordsArray(params.data);
  107. if (result.flatCoords) {
  108. if (!this._flatCoords) {
  109. this._flatCoords = result.flatCoords;
  110. this._flatCoordsOffset = result.flatCoordsOffset;
  111. } else {
  112. this._flatCoords = concatArray(this._flatCoords, result.flatCoords);
  113. this._flatCoordsOffset = concatArray(this._flatCoordsOffset, result.flatCoordsOffset);
  114. }
  115. params.data = new Float32Array(result.count);
  116. }
  117. this.getRawData().appendData(params.data);
  118. };
  119. LinesSeriesModel.prototype._getCoordsFromItemModel = function (idx) {
  120. var itemModel = this.getData().getItemModel(idx);
  121. var coords = itemModel.option instanceof Array ? itemModel.option : itemModel.getShallow('coords');
  122. if (process.env.NODE_ENV !== 'production') {
  123. if (!(coords instanceof Array && coords.length > 0 && coords[0] instanceof Array)) {
  124. throw new Error('Invalid coords ' + JSON.stringify(coords) + '. Lines must have 2d coords array in data item.');
  125. }
  126. }
  127. return coords;
  128. };
  129. LinesSeriesModel.prototype.getLineCoordsCount = function (idx) {
  130. if (this._flatCoordsOffset) {
  131. return this._flatCoordsOffset[idx * 2 + 1];
  132. } else {
  133. return this._getCoordsFromItemModel(idx).length;
  134. }
  135. };
  136. LinesSeriesModel.prototype.getLineCoords = function (idx, out) {
  137. if (this._flatCoordsOffset) {
  138. var offset = this._flatCoordsOffset[idx * 2];
  139. var len = this._flatCoordsOffset[idx * 2 + 1];
  140. for (var i = 0; i < len; i++) {
  141. out[i] = out[i] || [];
  142. out[i][0] = this._flatCoords[offset + i * 2];
  143. out[i][1] = this._flatCoords[offset + i * 2 + 1];
  144. }
  145. return len;
  146. } else {
  147. var coords = this._getCoordsFromItemModel(idx);
  148. for (var i = 0; i < coords.length; i++) {
  149. out[i] = out[i] || [];
  150. out[i][0] = coords[i][0];
  151. out[i][1] = coords[i][1];
  152. }
  153. return coords.length;
  154. }
  155. };
  156. LinesSeriesModel.prototype._processFlatCoordsArray = function (data) {
  157. var startOffset = 0;
  158. if (this._flatCoords) {
  159. startOffset = this._flatCoords.length;
  160. }
  161. // Stored as a typed array. In format
  162. // Points Count(2) | x | y | x | y | Points Count(3) | x | y | x | y | x | y |
  163. if (isNumber(data[0])) {
  164. var len = data.length;
  165. // Store offset and len of each segment
  166. var coordsOffsetAndLenStorage = new Uint32Arr(len);
  167. var coordsStorage = new Float64Arr(len);
  168. var coordsCursor = 0;
  169. var offsetCursor = 0;
  170. var dataCount = 0;
  171. for (var i = 0; i < len;) {
  172. dataCount++;
  173. var count = data[i++];
  174. // Offset
  175. coordsOffsetAndLenStorage[offsetCursor++] = coordsCursor + startOffset;
  176. // Len
  177. coordsOffsetAndLenStorage[offsetCursor++] = count;
  178. for (var k = 0; k < count; k++) {
  179. var x = data[i++];
  180. var y = data[i++];
  181. coordsStorage[coordsCursor++] = x;
  182. coordsStorage[coordsCursor++] = y;
  183. if (i > len) {
  184. if (process.env.NODE_ENV !== 'production') {
  185. throw new Error('Invalid data format.');
  186. }
  187. }
  188. }
  189. }
  190. return {
  191. flatCoordsOffset: new Uint32Array(coordsOffsetAndLenStorage.buffer, 0, offsetCursor),
  192. flatCoords: coordsStorage,
  193. count: dataCount
  194. };
  195. }
  196. return {
  197. flatCoordsOffset: null,
  198. flatCoords: null,
  199. count: data.length
  200. };
  201. };
  202. LinesSeriesModel.prototype.getInitialData = function (option, ecModel) {
  203. if (process.env.NODE_ENV !== 'production') {
  204. var CoordSys = CoordinateSystem.get(option.coordinateSystem);
  205. if (!CoordSys) {
  206. throw new Error('Unknown coordinate system ' + option.coordinateSystem);
  207. }
  208. }
  209. var lineData = new SeriesData(['value'], this);
  210. lineData.hasItemOption = false;
  211. lineData.initData(option.data, [], function (dataItem, dimName, dataIndex, dimIndex) {
  212. // dataItem is simply coords
  213. if (dataItem instanceof Array) {
  214. return NaN;
  215. } else {
  216. lineData.hasItemOption = true;
  217. var value = dataItem.value;
  218. if (value != null) {
  219. return value instanceof Array ? value[dimIndex] : value;
  220. }
  221. }
  222. });
  223. return lineData;
  224. };
  225. LinesSeriesModel.prototype.formatTooltip = function (dataIndex, multipleSeries, dataType) {
  226. var data = this.getData();
  227. var itemModel = data.getItemModel(dataIndex);
  228. var name = itemModel.get('name');
  229. if (name) {
  230. return name;
  231. }
  232. var fromName = itemModel.get('fromName');
  233. var toName = itemModel.get('toName');
  234. var nameArr = [];
  235. fromName != null && nameArr.push(fromName);
  236. toName != null && nameArr.push(toName);
  237. return createTooltipMarkup('nameValue', {
  238. name: nameArr.join(' > ')
  239. });
  240. };
  241. LinesSeriesModel.prototype.preventIncremental = function () {
  242. return !!this.get(['effect', 'show']);
  243. };
  244. LinesSeriesModel.prototype.getProgressive = function () {
  245. var progressive = this.option.progressive;
  246. if (progressive == null) {
  247. return this.option.large ? 1e4 : this.get('progressive');
  248. }
  249. return progressive;
  250. };
  251. LinesSeriesModel.prototype.getProgressiveThreshold = function () {
  252. var progressiveThreshold = this.option.progressiveThreshold;
  253. if (progressiveThreshold == null) {
  254. return this.option.large ? 2e4 : this.get('progressiveThreshold');
  255. }
  256. return progressiveThreshold;
  257. };
  258. LinesSeriesModel.prototype.getZLevelKey = function () {
  259. var effectModel = this.getModel('effect');
  260. var trailLength = effectModel.get('trailLength');
  261. return this.getData().count() > this.getProgressiveThreshold()
  262. // Each progressive series has individual key.
  263. ? this.id : effectModel.get('show') && trailLength > 0 ? trailLength + '' : '';
  264. };
  265. LinesSeriesModel.type = 'series.lines';
  266. LinesSeriesModel.dependencies = ['grid', 'polar', 'geo', 'calendar'];
  267. LinesSeriesModel.defaultOption = {
  268. coordinateSystem: 'geo',
  269. // zlevel: 0,
  270. z: 2,
  271. legendHoverLink: true,
  272. // Cartesian coordinate system
  273. xAxisIndex: 0,
  274. yAxisIndex: 0,
  275. symbol: ['none', 'none'],
  276. symbolSize: [10, 10],
  277. // Geo coordinate system
  278. geoIndex: 0,
  279. effect: {
  280. show: false,
  281. period: 4,
  282. constantSpeed: 0,
  283. symbol: 'circle',
  284. symbolSize: 3,
  285. loop: true,
  286. trailLength: 0.2
  287. },
  288. large: false,
  289. // Available when large is true
  290. largeThreshold: 2000,
  291. polyline: false,
  292. clip: true,
  293. label: {
  294. show: false,
  295. position: 'end'
  296. // distance: 5,
  297. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  298. },
  299. lineStyle: {
  300. opacity: 0.5
  301. }
  302. };
  303. return LinesSeriesModel;
  304. }(SeriesModel);
  305. export default LinesSeriesModel;