LinesSeries.js 11 KB

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