linesLayout.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 createRenderPlanner = require("../helper/createRenderPlanner");
  20. /*
  21. * Licensed to the Apache Software Foundation (ASF) under one
  22. * or more contributor license agreements. See the NOTICE file
  23. * distributed with this work for additional information
  24. * regarding copyright ownership. The ASF licenses this file
  25. * to you under the Apache License, Version 2.0 (the
  26. * "License"); you may not use this file except in compliance
  27. * with the License. You may obtain a copy of the License at
  28. *
  29. * http://www.apache.org/licenses/LICENSE-2.0
  30. *
  31. * Unless required by applicable law or agreed to in writing,
  32. * software distributed under the License is distributed on an
  33. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34. * KIND, either express or implied. See the License for the
  35. * specific language governing permissions and limitations
  36. * under the License.
  37. */
  38. /* global Float32Array */
  39. var _default = {
  40. seriesType: 'lines',
  41. plan: createRenderPlanner(),
  42. reset: function (seriesModel) {
  43. var coordSys = seriesModel.coordinateSystem;
  44. var isPolyline = seriesModel.get('polyline');
  45. var isLarge = seriesModel.pipelineContext.large;
  46. function progress(params, lineData) {
  47. var lineCoords = [];
  48. if (isLarge) {
  49. var points;
  50. var segCount = params.end - params.start;
  51. if (isPolyline) {
  52. var totalCoordsCount = 0;
  53. for (var i = params.start; i < params.end; i++) {
  54. totalCoordsCount += seriesModel.getLineCoordsCount(i);
  55. }
  56. points = new Float32Array(segCount + totalCoordsCount * 2);
  57. } else {
  58. points = new Float32Array(segCount * 4);
  59. }
  60. var offset = 0;
  61. var pt = [];
  62. for (var i = params.start; i < params.end; i++) {
  63. var len = seriesModel.getLineCoords(i, lineCoords);
  64. if (isPolyline) {
  65. points[offset++] = len;
  66. }
  67. for (var k = 0; k < len; k++) {
  68. pt = coordSys.dataToPoint(lineCoords[k], false, pt);
  69. points[offset++] = pt[0];
  70. points[offset++] = pt[1];
  71. }
  72. }
  73. lineData.setLayout('linesPoints', points);
  74. } else {
  75. for (var i = params.start; i < params.end; i++) {
  76. var itemModel = lineData.getItemModel(i);
  77. var len = seriesModel.getLineCoords(i, lineCoords);
  78. var pts = [];
  79. if (isPolyline) {
  80. for (var j = 0; j < len; j++) {
  81. pts.push(coordSys.dataToPoint(lineCoords[j]));
  82. }
  83. } else {
  84. pts[0] = coordSys.dataToPoint(lineCoords[0]);
  85. pts[1] = coordSys.dataToPoint(lineCoords[1]);
  86. var curveness = itemModel.get('lineStyle.curveness');
  87. if (+curveness) {
  88. pts[2] = [(pts[0][0] + pts[1][0]) / 2 - (pts[0][1] - pts[1][1]) * curveness, (pts[0][1] + pts[1][1]) / 2 - (pts[1][0] - pts[0][0]) * curveness];
  89. }
  90. }
  91. lineData.setItemLayout(i, pts);
  92. }
  93. }
  94. }
  95. return {
  96. progress: progress
  97. };
  98. }
  99. };
  100. module.exports = _default;