LinesView.js 6.9 KB

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