simpleLayoutHelper.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 vec2 = require("zrender/lib/core/vector");
  20. var zrUtil = require("zrender/lib/core/util");
  21. var _multipleGraphEdgeHelper = require("../helper/multipleGraphEdgeHelper");
  22. var getCurvenessForEdge = _multipleGraphEdgeHelper.getCurvenessForEdge;
  23. /*
  24. * Licensed to the Apache Software Foundation (ASF) under one
  25. * or more contributor license agreements. See the NOTICE file
  26. * distributed with this work for additional information
  27. * regarding copyright ownership. The ASF licenses this file
  28. * to you under the Apache License, Version 2.0 (the
  29. * "License"); you may not use this file except in compliance
  30. * with the License. You may obtain a copy of the License at
  31. *
  32. * http://www.apache.org/licenses/LICENSE-2.0
  33. *
  34. * Unless required by applicable law or agreed to in writing,
  35. * software distributed under the License is distributed on an
  36. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37. * KIND, either express or implied. See the License for the
  38. * specific language governing permissions and limitations
  39. * under the License.
  40. */
  41. function simpleLayout(seriesModel) {
  42. var coordSys = seriesModel.coordinateSystem;
  43. if (coordSys && coordSys.type !== 'view') {
  44. return;
  45. }
  46. var graph = seriesModel.getGraph();
  47. graph.eachNode(function (node) {
  48. var model = node.getModel();
  49. node.setLayout([+model.get('x'), +model.get('y')]);
  50. });
  51. simpleLayoutEdge(graph, seriesModel);
  52. }
  53. function simpleLayoutEdge(graph, seriesModel) {
  54. graph.eachEdge(function (edge, index) {
  55. var curveness = zrUtil.retrieve3(edge.getModel().get('lineStyle.curveness'), -getCurvenessForEdge(edge, seriesModel, index, true), 0);
  56. var p1 = vec2.clone(edge.node1.getLayout());
  57. var p2 = vec2.clone(edge.node2.getLayout());
  58. var points = [p1, p2];
  59. if (+curveness) {
  60. points.push([(p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * curveness, (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * curveness]);
  61. }
  62. edge.setLayout(points);
  63. });
  64. }
  65. exports.simpleLayout = simpleLayout;
  66. exports.simpleLayoutEdge = simpleLayoutEdge;