createView.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. // FIXME Where to create the simple view coordinate system
  41. import View from '../../coord/View.js';
  42. import { getLayoutRect } from '../../util/layout.js';
  43. import * as bbox from 'zrender/lib/core/bbox.js';
  44. import { extend } from 'zrender/lib/core/util.js';
  45. function getViewRect(seriesModel, api, aspect) {
  46. var option = extend(seriesModel.getBoxLayoutParams(), {
  47. aspect: aspect
  48. });
  49. return getLayoutRect(option, {
  50. width: api.getWidth(),
  51. height: api.getHeight()
  52. });
  53. }
  54. export default function createViewCoordSys(ecModel, api) {
  55. var viewList = [];
  56. ecModel.eachSeriesByType('graph', function (seriesModel) {
  57. var coordSysType = seriesModel.get('coordinateSystem');
  58. if (!coordSysType || coordSysType === 'view') {
  59. var data_1 = seriesModel.getData();
  60. var positions = data_1.mapArray(function (idx) {
  61. var itemModel = data_1.getItemModel(idx);
  62. return [+itemModel.get('x'), +itemModel.get('y')];
  63. });
  64. var min = [];
  65. var max = [];
  66. bbox.fromPoints(positions, min, max); // If width or height is 0
  67. if (max[0] - min[0] === 0) {
  68. max[0] += 1;
  69. min[0] -= 1;
  70. }
  71. if (max[1] - min[1] === 0) {
  72. max[1] += 1;
  73. min[1] -= 1;
  74. }
  75. var aspect = (max[0] - min[0]) / (max[1] - min[1]); // FIXME If get view rect after data processed?
  76. var viewRect = getViewRect(seriesModel, api, aspect); // Position may be NaN, use view rect instead
  77. if (isNaN(aspect)) {
  78. min = [viewRect.x, viewRect.y];
  79. max = [viewRect.x + viewRect.width, viewRect.y + viewRect.height];
  80. }
  81. var bbWidth = max[0] - min[0];
  82. var bbHeight = max[1] - min[1];
  83. var viewWidth = viewRect.width;
  84. var viewHeight = viewRect.height;
  85. var viewCoordSys = seriesModel.coordinateSystem = new View();
  86. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  87. viewCoordSys.setBoundingRect(min[0], min[1], bbWidth, bbHeight);
  88. viewCoordSys.setViewRect(viewRect.x, viewRect.y, viewWidth, viewHeight); // Update roam info
  89. viewCoordSys.setCenter(seriesModel.get('center'), api);
  90. viewCoordSys.setZoom(seriesModel.get('zoom'));
  91. viewList.push(viewCoordSys);
  92. }
  93. });
  94. return viewList;
  95. }