LargeLineDraw.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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"; // TODO Batch by color
  41. import * as graphic from '../../util/graphic';
  42. import IncrementalDisplayable from 'zrender/lib/graphic/IncrementalDisplayable';
  43. import * as lineContain from 'zrender/lib/contain/line';
  44. import * as quadraticContain from 'zrender/lib/contain/quadratic';
  45. import { getECData } from '../../util/innerStore';
  46. var LargeLinesPathShape =
  47. /** @class */
  48. function () {
  49. function LargeLinesPathShape() {
  50. this.polyline = false;
  51. this.curveness = 0;
  52. this.segs = [];
  53. }
  54. return LargeLinesPathShape;
  55. }();
  56. var LargeLinesPath =
  57. /** @class */
  58. function (_super) {
  59. __extends(LargeLinesPath, _super);
  60. function LargeLinesPath(opts) {
  61. return _super.call(this, opts) || this;
  62. }
  63. LargeLinesPath.prototype.getDefaultStyle = function () {
  64. return {
  65. stroke: '#000',
  66. fill: null
  67. };
  68. };
  69. LargeLinesPath.prototype.getDefaultShape = function () {
  70. return new LargeLinesPathShape();
  71. };
  72. LargeLinesPath.prototype.buildPath = function (ctx, shape) {
  73. var segs = shape.segs;
  74. var curveness = shape.curveness;
  75. if (shape.polyline) {
  76. for (var i = 0; i < segs.length;) {
  77. var count = segs[i++];
  78. if (count > 0) {
  79. ctx.moveTo(segs[i++], segs[i++]);
  80. for (var k = 1; k < count; k++) {
  81. ctx.lineTo(segs[i++], segs[i++]);
  82. }
  83. }
  84. }
  85. } else {
  86. for (var i = 0; i < segs.length;) {
  87. var x0 = segs[i++];
  88. var y0 = segs[i++];
  89. var x1 = segs[i++];
  90. var y1 = segs[i++];
  91. ctx.moveTo(x0, y0);
  92. if (curveness > 0) {
  93. var x2 = (x0 + x1) / 2 - (y0 - y1) * curveness;
  94. var y2 = (y0 + y1) / 2 - (x1 - x0) * curveness;
  95. ctx.quadraticCurveTo(x2, y2, x1, y1);
  96. } else {
  97. ctx.lineTo(x1, y1);
  98. }
  99. }
  100. }
  101. };
  102. LargeLinesPath.prototype.findDataIndex = function (x, y) {
  103. var shape = this.shape;
  104. var segs = shape.segs;
  105. var curveness = shape.curveness;
  106. var lineWidth = this.style.lineWidth;
  107. if (shape.polyline) {
  108. var dataIndex = 0;
  109. for (var i = 0; i < segs.length;) {
  110. var count = segs[i++];
  111. if (count > 0) {
  112. var x0 = segs[i++];
  113. var y0 = segs[i++];
  114. for (var k = 1; k < count; k++) {
  115. var x1 = segs[i++];
  116. var y1 = segs[i++];
  117. if (lineContain.containStroke(x0, y0, x1, y1, lineWidth, x, y)) {
  118. return dataIndex;
  119. }
  120. }
  121. }
  122. dataIndex++;
  123. }
  124. } else {
  125. var dataIndex = 0;
  126. for (var i = 0; i < segs.length;) {
  127. var x0 = segs[i++];
  128. var y0 = segs[i++];
  129. var x1 = segs[i++];
  130. var y1 = segs[i++];
  131. if (curveness > 0) {
  132. var x2 = (x0 + x1) / 2 - (y0 - y1) * curveness;
  133. var y2 = (y0 + y1) / 2 - (x1 - x0) * curveness;
  134. if (quadraticContain.containStroke(x0, y0, x2, y2, x1, y1, lineWidth, x, y)) {
  135. return dataIndex;
  136. }
  137. } else {
  138. if (lineContain.containStroke(x0, y0, x1, y1, lineWidth, x, y)) {
  139. return dataIndex;
  140. }
  141. }
  142. dataIndex++;
  143. }
  144. }
  145. return -1;
  146. };
  147. return LargeLinesPath;
  148. }(graphic.Path);
  149. var LargeLineDraw =
  150. /** @class */
  151. function () {
  152. function LargeLineDraw() {
  153. this.group = new graphic.Group();
  154. }
  155. LargeLineDraw.prototype.isPersistent = function () {
  156. return !this._incremental;
  157. };
  158. ;
  159. /**
  160. * Update symbols draw by new data
  161. */
  162. LargeLineDraw.prototype.updateData = function (data) {
  163. this.group.removeAll();
  164. var lineEl = new LargeLinesPath({
  165. rectHover: true,
  166. cursor: 'default'
  167. });
  168. lineEl.setShape({
  169. segs: data.getLayout('linesPoints')
  170. });
  171. this._setCommon(lineEl, data); // Add back
  172. this.group.add(lineEl);
  173. this._incremental = null;
  174. };
  175. ;
  176. /**
  177. * @override
  178. */
  179. LargeLineDraw.prototype.incrementalPrepareUpdate = function (data) {
  180. this.group.removeAll();
  181. this._clearIncremental();
  182. if (data.count() > 5e5) {
  183. if (!this._incremental) {
  184. this._incremental = new IncrementalDisplayable({
  185. silent: true
  186. });
  187. }
  188. this.group.add(this._incremental);
  189. } else {
  190. this._incremental = null;
  191. }
  192. };
  193. ;
  194. /**
  195. * @override
  196. */
  197. LargeLineDraw.prototype.incrementalUpdate = function (taskParams, data) {
  198. var lineEl = new LargeLinesPath();
  199. lineEl.setShape({
  200. segs: data.getLayout('linesPoints')
  201. });
  202. this._setCommon(lineEl, data, !!this._incremental);
  203. if (!this._incremental) {
  204. lineEl.rectHover = true;
  205. lineEl.cursor = 'default';
  206. lineEl.__startIndex = taskParams.start;
  207. this.group.add(lineEl);
  208. } else {
  209. this._incremental.addDisplayable(lineEl, true);
  210. }
  211. };
  212. ;
  213. /**
  214. * @override
  215. */
  216. LargeLineDraw.prototype.remove = function () {
  217. this._clearIncremental();
  218. this._incremental = null;
  219. this.group.removeAll();
  220. };
  221. ;
  222. LargeLineDraw.prototype._setCommon = function (lineEl, data, isIncremental) {
  223. var hostModel = data.hostModel;
  224. lineEl.setShape({
  225. polyline: hostModel.get('polyline'),
  226. curveness: hostModel.get(['lineStyle', 'curveness'])
  227. });
  228. lineEl.useStyle(hostModel.getModel('lineStyle').getLineStyle());
  229. lineEl.style.strokeNoScale = true;
  230. var style = data.getVisual('style');
  231. if (style && style.stroke) {
  232. lineEl.setStyle('stroke', style.stroke);
  233. }
  234. lineEl.setStyle('fill', null);
  235. if (!isIncremental) {
  236. var ecData_1 = getECData(lineEl); // Enable tooltip
  237. // PENDING May have performance issue when path is extremely large
  238. ecData_1.seriesIndex = hostModel.seriesIndex;
  239. lineEl.on('mousemove', function (e) {
  240. ecData_1.dataIndex = null;
  241. var dataIndex = lineEl.findDataIndex(e.offsetX, e.offsetY);
  242. if (dataIndex > 0) {
  243. // Provide dataIndex for tooltip
  244. ecData_1.dataIndex = dataIndex + lineEl.__startIndex;
  245. }
  246. });
  247. }
  248. };
  249. ;
  250. LargeLineDraw.prototype._clearIncremental = function () {
  251. var incremental = this._incremental;
  252. if (incremental) {
  253. incremental.clearDisplaybles();
  254. }
  255. };
  256. ;
  257. return LargeLineDraw;
  258. }();
  259. export default LargeLineDraw;