createView.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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);
  67. // If width or height is 0
  68. if (max[0] - min[0] === 0) {
  69. max[0] += 1;
  70. min[0] -= 1;
  71. }
  72. if (max[1] - min[1] === 0) {
  73. max[1] += 1;
  74. min[1] -= 1;
  75. }
  76. var aspect = (max[0] - min[0]) / (max[1] - min[1]);
  77. // FIXME If get view rect after data processed?
  78. var viewRect = getViewRect(seriesModel, api, aspect);
  79. // Position may be NaN, use view rect instead
  80. if (isNaN(aspect)) {
  81. min = [viewRect.x, viewRect.y];
  82. max = [viewRect.x + viewRect.width, viewRect.y + viewRect.height];
  83. }
  84. var bbWidth = max[0] - min[0];
  85. var bbHeight = max[1] - min[1];
  86. var viewWidth = viewRect.width;
  87. var viewHeight = viewRect.height;
  88. var viewCoordSys = seriesModel.coordinateSystem = new View();
  89. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  90. viewCoordSys.setBoundingRect(min[0], min[1], bbWidth, bbHeight);
  91. viewCoordSys.setViewRect(viewRect.x, viewRect.y, viewWidth, viewHeight);
  92. // Update roam info
  93. viewCoordSys.setCenter(seriesModel.get('center'), api);
  94. viewCoordSys.setZoom(seriesModel.get('zoom'));
  95. viewList.push(viewCoordSys);
  96. }
  97. });
  98. return viewList;
  99. }