ScatterView.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. var echarts = require("../../echarts");
  20. var SymbolDraw = require("../helper/SymbolDraw");
  21. var LargeSymbolDraw = require("../helper/LargeSymbolDraw");
  22. var pointsLayout = require("../../layout/points");
  23. /*
  24. * Licensed to the Apache Software Foundation (ASF) under one
  25. * or more contributor license agreements. See the NOTICE file
  26. * distributed with this work for additional information
  27. * regarding copyright ownership. The ASF licenses this file
  28. * to you under the Apache License, Version 2.0 (the
  29. * "License"); you may not use this file except in compliance
  30. * with the License. You may obtain a copy of the License at
  31. *
  32. * http://www.apache.org/licenses/LICENSE-2.0
  33. *
  34. * Unless required by applicable law or agreed to in writing,
  35. * software distributed under the License is distributed on an
  36. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37. * KIND, either express or implied. See the License for the
  38. * specific language governing permissions and limitations
  39. * under the License.
  40. */
  41. echarts.extendChartView({
  42. type: 'scatter',
  43. render: function (seriesModel, ecModel, api) {
  44. var data = seriesModel.getData();
  45. var symbolDraw = this._updateSymbolDraw(data, seriesModel);
  46. symbolDraw.updateData(data, {
  47. // TODO
  48. // If this parameter should be a shape or a bounding volume
  49. // shape will be more general.
  50. // But bounding volume like bounding rect will be much faster in the contain calculation
  51. clipShape: this._getClipShape(seriesModel)
  52. });
  53. this._finished = true;
  54. },
  55. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  56. var data = seriesModel.getData();
  57. var symbolDraw = this._updateSymbolDraw(data, seriesModel);
  58. symbolDraw.incrementalPrepareUpdate(data);
  59. this._finished = false;
  60. },
  61. incrementalRender: function (taskParams, seriesModel, ecModel) {
  62. this._symbolDraw.incrementalUpdate(taskParams, seriesModel.getData(), {
  63. clipShape: this._getClipShape(seriesModel)
  64. });
  65. this._finished = taskParams.end === seriesModel.getData().count();
  66. },
  67. updateTransform: function (seriesModel, ecModel, api) {
  68. var data = seriesModel.getData(); // Must mark group dirty and make sure the incremental layer will be cleared
  69. // PENDING
  70. this.group.dirty();
  71. if (!this._finished || data.count() > 1e4 || !this._symbolDraw.isPersistent()) {
  72. return {
  73. update: true
  74. };
  75. } else {
  76. var res = pointsLayout().reset(seriesModel);
  77. if (res.progress) {
  78. res.progress({
  79. start: 0,
  80. end: data.count()
  81. }, data);
  82. }
  83. this._symbolDraw.updateLayout(data);
  84. }
  85. },
  86. _getClipShape: function (seriesModel) {
  87. var coordSys = seriesModel.coordinateSystem;
  88. var clipArea = coordSys && coordSys.getArea && coordSys.getArea();
  89. return seriesModel.get('clip', true) ? clipArea : null;
  90. },
  91. _updateSymbolDraw: function (data, seriesModel) {
  92. var symbolDraw = this._symbolDraw;
  93. var pipelineContext = seriesModel.pipelineContext;
  94. var isLargeDraw = pipelineContext.large;
  95. if (!symbolDraw || isLargeDraw !== this._isLargeDraw) {
  96. symbolDraw && symbolDraw.remove();
  97. symbolDraw = this._symbolDraw = isLargeDraw ? new LargeSymbolDraw() : new SymbolDraw();
  98. this._isLargeDraw = isLargeDraw;
  99. this.group.removeAll();
  100. }
  101. this.group.add(symbolDraw.group);
  102. return symbolDraw;
  103. },
  104. remove: function (ecModel, api) {
  105. this._symbolDraw && this._symbolDraw.remove(true);
  106. this._symbolDraw = null;
  107. },
  108. dispose: function () {}
  109. });