simpleLayout.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. var _util = require("zrender/lib/core/util");
  20. var each = _util.each;
  21. var _simpleLayoutHelper = require("./simpleLayoutHelper");
  22. var simpleLayout = _simpleLayoutHelper.simpleLayout;
  23. var simpleLayoutEdge = _simpleLayoutHelper.simpleLayoutEdge;
  24. /*
  25. * Licensed to the Apache Software Foundation (ASF) under one
  26. * or more contributor license agreements. See the NOTICE file
  27. * distributed with this work for additional information
  28. * regarding copyright ownership. The ASF licenses this file
  29. * to you under the Apache License, Version 2.0 (the
  30. * "License"); you may not use this file except in compliance
  31. * with the License. You may obtain a copy of the License at
  32. *
  33. * http://www.apache.org/licenses/LICENSE-2.0
  34. *
  35. * Unless required by applicable law or agreed to in writing,
  36. * software distributed under the License is distributed on an
  37. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38. * KIND, either express or implied. See the License for the
  39. * specific language governing permissions and limitations
  40. * under the License.
  41. */
  42. function _default(ecModel, api) {
  43. ecModel.eachSeriesByType('graph', function (seriesModel) {
  44. var layout = seriesModel.get('layout');
  45. var coordSys = seriesModel.coordinateSystem;
  46. if (coordSys && coordSys.type !== 'view') {
  47. var data = seriesModel.getData();
  48. var dimensions = [];
  49. each(coordSys.dimensions, function (coordDim) {
  50. dimensions = dimensions.concat(data.mapDimension(coordDim, true));
  51. });
  52. for (var dataIndex = 0; dataIndex < data.count(); dataIndex++) {
  53. var value = [];
  54. var hasValue = false;
  55. for (var i = 0; i < dimensions.length; i++) {
  56. var val = data.get(dimensions[i], dataIndex);
  57. if (!isNaN(val)) {
  58. hasValue = true;
  59. }
  60. value.push(val);
  61. }
  62. if (hasValue) {
  63. data.setItemLayout(dataIndex, coordSys.dataToPoint(value));
  64. } else {
  65. // Also {Array.<number>}, not undefined to avoid if...else... statement
  66. data.setItemLayout(dataIndex, [NaN, NaN]);
  67. }
  68. }
  69. simpleLayoutEdge(data.graph, seriesModel);
  70. } else if (!layout || layout === 'none') {
  71. simpleLayout(seriesModel);
  72. }
  73. });
  74. }
  75. module.exports = _default;