LinesView.js 7.0 KB

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