LinesView.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 LineDraw from '../helper/LineDraw.js';
  42. import EffectLine from '../helper/EffectLine.js';
  43. import Line from '../helper/Line.js';
  44. import Polyline from '../helper/Polyline.js';
  45. import EffectPolyline from '../helper/EffectPolyline.js';
  46. import LargeLineDraw from '../helper/LargeLineDraw.js';
  47. import linesLayout from './linesLayout.js';
  48. import { createClipPath } from '../helper/createClipPathFromCoordSys.js';
  49. import ChartView from '../../view/Chart.js';
  50. import { getIncrementalId } from '../../util/model.js';
  51. import { getCurrentCanvasPainter } from '../../util/graphic.js';
  52. var LinesView = /** @class */function (_super) {
  53. __extends(LinesView, _super);
  54. function LinesView() {
  55. var _this = _super !== null && _super.apply(this, arguments) || this;
  56. _this.type = LinesView.type;
  57. return _this;
  58. }
  59. LinesView.prototype.render = function (seriesModel, ecModel, api) {
  60. var data = seriesModel.getData();
  61. var lineDraw = this._updateLineDraw(data, seriesModel);
  62. var zlevel = seriesModel.get('zlevel');
  63. var trailLength = seriesModel.get(['effect', 'trailLength']);
  64. var zr = api.getZr();
  65. // Avoid the drag cause ghost shadow
  66. // FIXME Better way ?
  67. // SVG doesn't support
  68. var isCanvas = !!getCurrentCanvasPainter(api);
  69. if (isCanvas) {
  70. zr.painter.getLayer(zlevel).clear(true);
  71. }
  72. // Config layer with motion blur
  73. if (this._lastZlevel != null && isCanvas) {
  74. zr.configLayer(this._lastZlevel, {
  75. motionBlur: false
  76. });
  77. }
  78. if (this._showEffect(seriesModel) && trailLength > 0) {
  79. if (isCanvas) {
  80. zr.configLayer(zlevel, {
  81. motionBlur: true,
  82. lastFrameAlpha: Math.max(Math.min(trailLength / 10 + 0.9, 1), 0)
  83. });
  84. } else if (process.env.NODE_ENV !== 'production') {
  85. console.warn('SVG render mode doesn\'t support lines with trail effect');
  86. }
  87. }
  88. lineDraw.updateData(data);
  89. var clipPath = seriesModel.get('clip', true) && createClipPath(seriesModel.coordinateSystem, false, seriesModel);
  90. if (clipPath) {
  91. this.group.setClipPath(clipPath);
  92. } else {
  93. this.group.removeClipPath();
  94. }
  95. this._lastZlevel = zlevel;
  96. this._finished = true;
  97. };
  98. LinesView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
  99. var data = seriesModel.getData();
  100. var lineDraw = this._updateLineDraw(data, seriesModel);
  101. lineDraw.incrementalPrepareUpdate(data);
  102. this._clearLayer(api);
  103. this._finished = false;
  104. };
  105. LinesView.prototype.incrementalRender = function (taskParams, seriesModel, ecModel) {
  106. this._lineDraw.incrementalUpdate(taskParams, seriesModel.getData(), getIncrementalId(seriesModel));
  107. this._finished = taskParams.end === seriesModel.getData().count();
  108. };
  109. LinesView.prototype.eachRendered = function (cb) {
  110. this._lineDraw && this._lineDraw.eachRendered(cb);
  111. };
  112. LinesView.prototype.updateTransform = function (seriesModel, ecModel, api) {
  113. var data = seriesModel.getData();
  114. var lineDraw = this._lineDraw;
  115. if (!this._finished || !lineDraw
  116. // TODO Don't have to do update in large mode. Only do it when there are millions of data.
  117. || !lineDraw.updateLayout) {
  118. return {
  119. update: true
  120. };
  121. } else {
  122. // TODO Use same logic with ScatterView.
  123. // Manually update layout
  124. var res = linesLayout.reset(seriesModel, ecModel, api);
  125. if (res.progress) {
  126. res.progress({
  127. start: 0,
  128. end: data.count(),
  129. count: data.count()
  130. }, data);
  131. }
  132. lineDraw.updateLayout();
  133. this._clearLayer(api);
  134. }
  135. };
  136. LinesView.prototype._updateLineDraw = function (data, seriesModel) {
  137. var lineDraw = this._lineDraw;
  138. var hasEffect = this._showEffect(seriesModel);
  139. var isPolyline = !!seriesModel.get('polyline');
  140. var pipelineContext = seriesModel.pipelineContext;
  141. var isLargeDraw = pipelineContext.large;
  142. if (process.env.NODE_ENV !== 'production') {
  143. if (hasEffect && isLargeDraw) {
  144. console.warn('Large lines not support effect');
  145. }
  146. }
  147. if (!lineDraw || hasEffect !== this._hasEffet || isPolyline !== this._isPolyline || isLargeDraw !== this._isLargeDraw) {
  148. if (lineDraw) {
  149. lineDraw.remove();
  150. }
  151. lineDraw = this._lineDraw = isLargeDraw ? new LargeLineDraw() : new LineDraw(isPolyline ? hasEffect ? EffectPolyline : Polyline : hasEffect ? EffectLine : Line);
  152. this._hasEffet = hasEffect;
  153. this._isPolyline = isPolyline;
  154. this._isLargeDraw = isLargeDraw;
  155. }
  156. this.group.add(lineDraw.group);
  157. return lineDraw;
  158. };
  159. LinesView.prototype._showEffect = function (seriesModel) {
  160. return !!seriesModel.get(['effect', 'show']);
  161. };
  162. LinesView.prototype._clearLayer = function (api) {
  163. // Not use motion when dragging or zooming
  164. var painter = getCurrentCanvasPainter(api);
  165. if (painter && this._lastZlevel != null) {
  166. painter.getLayer(this._lastZlevel).clear(true);
  167. }
  168. };
  169. LinesView.prototype.remove = function (ecModel, api) {
  170. this._lineDraw && this._lineDraw.remove();
  171. this._lineDraw = null;
  172. // Clear motion when lineDraw is removed
  173. this._clearLayer(api);
  174. };
  175. LinesView.prototype.dispose = function (ecModel, api) {
  176. this.remove(ecModel, api);
  177. };
  178. LinesView.type = 'lines';
  179. return LinesView;
  180. }(ChartView);
  181. export default LinesView;