LineDraw.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 * as graphic from '../../util/graphic';
  41. import LineGroup from './Line';
  42. import { getLabelStatesModels } from '../../label/labelStyle';
  43. var LineDraw =
  44. /** @class */
  45. function () {
  46. function LineDraw(LineCtor) {
  47. this.group = new graphic.Group();
  48. this._LineCtor = LineCtor || LineGroup;
  49. }
  50. LineDraw.prototype.isPersistent = function () {
  51. return true;
  52. };
  53. ;
  54. LineDraw.prototype.updateData = function (lineData) {
  55. var _this = this;
  56. var lineDraw = this;
  57. var group = lineDraw.group;
  58. var oldLineData = lineDraw._lineData;
  59. lineDraw._lineData = lineData; // There is no oldLineData only when first rendering or switching from
  60. // stream mode to normal mode, where previous elements should be removed.
  61. if (!oldLineData) {
  62. group.removeAll();
  63. }
  64. var seriesScope = makeSeriesScope(lineData);
  65. lineData.diff(oldLineData).add(function (idx) {
  66. _this._doAdd(lineData, idx, seriesScope);
  67. }).update(function (newIdx, oldIdx) {
  68. _this._doUpdate(oldLineData, lineData, oldIdx, newIdx, seriesScope);
  69. }).remove(function (idx) {
  70. group.remove(oldLineData.getItemGraphicEl(idx));
  71. }).execute();
  72. };
  73. ;
  74. LineDraw.prototype.updateLayout = function () {
  75. var lineData = this._lineData; // Do not support update layout in incremental mode.
  76. if (!lineData) {
  77. return;
  78. }
  79. lineData.eachItemGraphicEl(function (el, idx) {
  80. el.updateLayout(lineData, idx);
  81. }, this);
  82. };
  83. ;
  84. LineDraw.prototype.incrementalPrepareUpdate = function (lineData) {
  85. this._seriesScope = makeSeriesScope(lineData);
  86. this._lineData = null;
  87. this.group.removeAll();
  88. };
  89. ;
  90. LineDraw.prototype.incrementalUpdate = function (taskParams, lineData) {
  91. function updateIncrementalAndHover(el) {
  92. if (!el.isGroup && !isEffectObject(el)) {
  93. el.incremental = true;
  94. el.ensureState('emphasis').hoverLayer = true;
  95. }
  96. }
  97. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  98. var itemLayout = lineData.getItemLayout(idx);
  99. if (lineNeedsDraw(itemLayout)) {
  100. var el = new this._LineCtor(lineData, idx, this._seriesScope);
  101. el.traverse(updateIncrementalAndHover);
  102. this.group.add(el);
  103. lineData.setItemGraphicEl(idx, el);
  104. }
  105. }
  106. };
  107. ;
  108. LineDraw.prototype.remove = function () {
  109. this.group.removeAll();
  110. };
  111. ;
  112. LineDraw.prototype._doAdd = function (lineData, idx, seriesScope) {
  113. var itemLayout = lineData.getItemLayout(idx);
  114. if (!lineNeedsDraw(itemLayout)) {
  115. return;
  116. }
  117. var el = new this._LineCtor(lineData, idx, seriesScope);
  118. lineData.setItemGraphicEl(idx, el);
  119. this.group.add(el);
  120. };
  121. LineDraw.prototype._doUpdate = function (oldLineData, newLineData, oldIdx, newIdx, seriesScope) {
  122. var itemEl = oldLineData.getItemGraphicEl(oldIdx);
  123. if (!lineNeedsDraw(newLineData.getItemLayout(newIdx))) {
  124. this.group.remove(itemEl);
  125. return;
  126. }
  127. if (!itemEl) {
  128. itemEl = new this._LineCtor(newLineData, newIdx, seriesScope);
  129. } else {
  130. itemEl.updateData(newLineData, newIdx, seriesScope);
  131. }
  132. newLineData.setItemGraphicEl(newIdx, itemEl);
  133. this.group.add(itemEl);
  134. };
  135. return LineDraw;
  136. }();
  137. function isEffectObject(el) {
  138. return el.animators && el.animators.length > 0;
  139. }
  140. function makeSeriesScope(lineData) {
  141. var hostModel = lineData.hostModel;
  142. return {
  143. lineStyle: hostModel.getModel('lineStyle').getLineStyle(),
  144. emphasisLineStyle: hostModel.getModel(['emphasis', 'lineStyle']).getLineStyle(),
  145. blurLineStyle: hostModel.getModel(['blur', 'lineStyle']).getLineStyle(),
  146. selectLineStyle: hostModel.getModel(['select', 'lineStyle']).getLineStyle(),
  147. labelStatesModels: getLabelStatesModels(hostModel)
  148. };
  149. }
  150. function isPointNaN(pt) {
  151. return isNaN(pt[0]) || isNaN(pt[1]);
  152. }
  153. function lineNeedsDraw(pts) {
  154. return !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  155. }
  156. export default LineDraw;