jitterLayout.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 { needFixJitter, fixJitter } from '../../util/jitter.js';
  41. import createRenderPlanner from '../helper/createRenderPlanner.js';
  42. import { COORD_SYS_TYPE_CARTESIAN_2D } from '../../coord/cartesian/GridModel.js';
  43. import { COORD_SYS_TYPE_SINGLE } from '../../coord/single/AxisModel.js';
  44. import { validateUpstreamOutputRange } from '../../util/model.js';
  45. export default function jitterLayout() {
  46. return {
  47. seriesType: 'scatter',
  48. plan: createRenderPlanner(),
  49. reset: function (seriesModel) {
  50. var coordSys = seriesModel.coordinateSystem;
  51. if (!coordSys || coordSys.type !== COORD_SYS_TYPE_CARTESIAN_2D && coordSys.type !== COORD_SYS_TYPE_SINGLE) {
  52. return;
  53. }
  54. var baseAxis = coordSys.getBaseAxis && coordSys.getBaseAxis();
  55. var hasJitter = baseAxis && needFixJitter(seriesModel, baseAxis);
  56. if (!hasJitter) {
  57. return;
  58. }
  59. var dim = baseAxis.dim;
  60. var orient = baseAxis.orient;
  61. var isSingleY = orient === 'horizontal' && baseAxis.type !== 'category' || orient === 'vertical' && baseAxis.type === 'category';
  62. var jitterOnY = dim === 'y' || dim === 'single' && isSingleY;
  63. var jitterOnX = dim === 'x' || dim === 'single' && !isSingleY;
  64. if (!jitterOnY && !jitterOnX) {
  65. return;
  66. }
  67. return {
  68. progress: function (params, data) {
  69. var points = data.getLayout('points');
  70. var hasPoints = !!points;
  71. if (process.env.NODE_ENV !== 'production') {
  72. hasPoints && validateUpstreamOutputRange(data.getLayout('pointsRange'), params);
  73. }
  74. for (var i = params.start; i < params.end; i++) {
  75. var offset = hasPoints ? (i - params.start) * 2 : -1;
  76. var layout = hasPoints ? [points[offset], points[offset + 1]] : data.getItemLayout(i);
  77. if (!layout) {
  78. continue;
  79. }
  80. var rawSize = data.getItemVisual(i, 'symbolSize');
  81. var size = rawSize instanceof Array ? (rawSize[1] + rawSize[0]) / 2 : rawSize;
  82. if (jitterOnY) {
  83. // x is fixed, and y is floating
  84. var jittered = fixJitter(baseAxis, layout[0], layout[1], size / 2);
  85. if (hasPoints) {
  86. points[offset + 1] = jittered;
  87. } else {
  88. layout[1] = jittered;
  89. }
  90. } else if (jitterOnX) {
  91. // y is fixed, and x is floating
  92. var jittered = fixJitter(baseAxis, layout[1], layout[0], size / 2);
  93. if (hasPoints) {
  94. points[offset] = jittered;
  95. } else {
  96. layout[0] = jittered;
  97. }
  98. }
  99. }
  100. }
  101. };
  102. }
  103. };
  104. }