points.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 _util = require("zrender/lib/core/util");
  20. var map = _util.map;
  21. var createRenderPlanner = require("../chart/helper/createRenderPlanner");
  22. var _dataStackHelper = require("../data/helper/dataStackHelper");
  23. var isDimensionStacked = _dataStackHelper.isDimensionStacked;
  24. /*
  25. * Licensed to the Apache Software Foundation (ASF) under one
  26. * or more contributor license agreements. See the NOTICE file
  27. * distributed with this work for additional information
  28. * regarding copyright ownership. The ASF licenses this file
  29. * to you under the Apache License, Version 2.0 (the
  30. * "License"); you may not use this file except in compliance
  31. * with the License. You may obtain a copy of the License at
  32. *
  33. * http://www.apache.org/licenses/LICENSE-2.0
  34. *
  35. * Unless required by applicable law or agreed to in writing,
  36. * software distributed under the License is distributed on an
  37. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38. * KIND, either express or implied. See the License for the
  39. * specific language governing permissions and limitations
  40. * under the License.
  41. */
  42. /* global Float32Array */
  43. function _default(seriesType) {
  44. return {
  45. seriesType: seriesType,
  46. plan: createRenderPlanner(),
  47. reset: function (seriesModel) {
  48. var data = seriesModel.getData();
  49. var coordSys = seriesModel.coordinateSystem;
  50. var pipelineContext = seriesModel.pipelineContext;
  51. var isLargeRender = pipelineContext.large;
  52. if (!coordSys) {
  53. return;
  54. }
  55. var dims = map(coordSys.dimensions, function (dim) {
  56. return data.mapDimension(dim);
  57. }).slice(0, 2);
  58. var dimLen = dims.length;
  59. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  60. if (isDimensionStacked(data, dims[0]
  61. /*, dims[1]*/
  62. )) {
  63. dims[0] = stackResultDim;
  64. }
  65. if (isDimensionStacked(data, dims[1]
  66. /*, dims[0]*/
  67. )) {
  68. dims[1] = stackResultDim;
  69. }
  70. function progress(params, data) {
  71. var segCount = params.end - params.start;
  72. var points = isLargeRender && new Float32Array(segCount * dimLen);
  73. for (var i = params.start, offset = 0, tmpIn = [], tmpOut = []; i < params.end; i++) {
  74. var point;
  75. if (dimLen === 1) {
  76. var x = data.get(dims[0], i);
  77. point = !isNaN(x) && coordSys.dataToPoint(x, null, tmpOut);
  78. } else {
  79. var x = tmpIn[0] = data.get(dims[0], i);
  80. var y = tmpIn[1] = data.get(dims[1], i); // Also {Array.<number>}, not undefined to avoid if...else... statement
  81. point = !isNaN(x) && !isNaN(y) && coordSys.dataToPoint(tmpIn, null, tmpOut);
  82. }
  83. if (isLargeRender) {
  84. points[offset++] = point ? point[0] : NaN;
  85. points[offset++] = point ? point[1] : NaN;
  86. } else {
  87. data.setItemLayout(i, point && point.slice() || [NaN, NaN]);
  88. }
  89. }
  90. isLargeRender && data.setLayout('symbolPoints', points);
  91. }
  92. return dimLen && {
  93. progress: progress
  94. };
  95. }
  96. };
  97. }
  98. module.exports = _default;