createView.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 { createBoxLayoutReference, getLayoutRect, applyPreserveAspect } from '../../util/layout.js';
  41. import * as bbox from 'zrender/lib/core/bbox.js';
  42. import { extend } from 'zrender/lib/core/util.js';
  43. import { injectCoordSysByOption } from '../../core/CoordinateSystem.js';
  44. import { createViewCoordSysSimply } from '../../component/helper/roamHelper.js';
  45. function getViewRect(seriesModel, api, aspect) {
  46. var layoutRef = createBoxLayoutReference(seriesModel, api);
  47. var option = extend(seriesModel.getBoxLayoutParams(), {
  48. aspect: aspect
  49. });
  50. var viewRect = getLayoutRect(option, layoutRef.refContainer);
  51. return applyPreserveAspect(seriesModel, viewRect, aspect);
  52. }
  53. export default function createViewCoordSys(ecModel, api) {
  54. var viewList = [];
  55. ecModel.eachSeriesByType('graph', function (seriesModel) {
  56. injectCoordSysByOption({
  57. targetModel: seriesModel,
  58. coordSysType: 'view',
  59. coordSysProvider: createViewCoordSys,
  60. isDefaultDataCoordSys: true
  61. });
  62. function createViewCoordSys() {
  63. var data = seriesModel.getData();
  64. var positions = data.mapArray(function (idx) {
  65. var itemModel = data.getItemModel(idx);
  66. return [+itemModel.get('x'), +itemModel.get('y')];
  67. });
  68. var min = [];
  69. var max = [];
  70. bbox.fromPoints(positions, min, max);
  71. // If width or height is 0
  72. if (max[0] - min[0] === 0) {
  73. max[0] += 1;
  74. min[0] -= 1;
  75. }
  76. if (max[1] - min[1] === 0) {
  77. max[1] += 1;
  78. min[1] -= 1;
  79. }
  80. var aspect = (max[0] - min[0]) / (max[1] - min[1]);
  81. // FIXME If get view rect after data processed?
  82. var viewRect = getViewRect(seriesModel, api, aspect);
  83. // Position may be NaN (e.g., in force layout), use view rect instead
  84. if (isNaN(aspect)) {
  85. min = [viewRect.x, viewRect.y];
  86. max = [viewRect.x + viewRect.width, viewRect.y + viewRect.height];
  87. }
  88. var bbWidth = max[0] - min[0];
  89. var bbHeight = max[1] - min[1];
  90. var viewCoordSys = createViewCoordSysSimply(seriesModel, api, min[0], min[1], bbWidth, bbHeight, viewRect);
  91. viewList.push(viewCoordSys);
  92. return viewCoordSys;
  93. }
  94. });
  95. return viewList;
  96. }