createView.js 4.1 KB

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