dyng
DynamicGraphLayout
initial_placement.h
1 /*
2  Copyright 2020 František Bráblík
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 #pragma once
17 
18 #include <cmath>
19 #include <algorithm> // std::min
20 
21 namespace dyng {
22 
32 public:
33  template<typename Graph>
34  void operator()(Graph& graph, float canvas_width, float canvas_height) {
35  float radius = std::min(canvas_width, canvas_height) * 0.333f;
36  float angle = 2.0f * 3.14159f / graph.nodes().size();
37  for (unsigned i = 0; i < graph.nodes().size(); ++i) {
38  graph.nodes()[i].pos().x = std::cos(i * angle) * radius;
39  graph.nodes()[i].pos().y = std::sin(i * angle) * radius;
40  }
41  }
42 };
43 
44 } // namespace dyng
dyng::initial_placement
Definition: initial_placement.h:31
dyng::graph::nodes
const std::vector< NodeType > & nodes() const
Returns const reference to the vector of all nodes in the graph.
Definition: graph.h:96
dyng::graph
Templated class for representing a static graph and its layout.
Definition: graph.h:40