@@ -116,6 +116,9 @@ CGTeaFrame::CGTeaFrame(const wxString& title, const wxPoint& pos, const wxSize&
116
116
auto *menuLayout = new wxMenu;
117
117
menuLayout->Append (i, " Force-directed drawing" , " Force-directed drawing" );
118
118
Connect (i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (CGTeaFrame::Layout));
119
+ i++;
120
+ menuLayout->Append (i, " &Fit Width" , " Fit Graph to Width" );
121
+ Connect (i, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (CGTeaFrame::OnFitWidth));
119
122
auto menuHelp = new wxMenu;
120
123
menuHelp->Append (wxID_ABOUT);
121
124
wxMenuBar *menuBar = new wxMenuBar;
@@ -171,6 +174,7 @@ void CGTeaFrame::Generate(wxCommandEvent& event) {
171
174
172
175
void CGTeaFrame::Layout (wxCommandEvent& event) {
173
176
int id = event.GetId ();
177
+ cout << id;
174
178
// currentGraph = availableGenerators[id]->generate_with_force_directed(10,0,500,500);
175
179
std::vector<cgtea_geometry::Point> pos = compute_force_directed (10 , 10 , 300 , 300 , currentGraph);
176
180
int i = 0 ;
@@ -181,6 +185,44 @@ void CGTeaFrame::Layout(wxCommandEvent& event) {
181
185
Refresh ();
182
186
}
183
187
188
+ void CGTeaFrame::OnFitWidth (wxCommandEvent& event)
189
+ {
190
+ // Get the current graph bounds
191
+ double minX = std::numeric_limits<double >::max ();
192
+ double maxX = std::numeric_limits<double >::lowest ();
193
+ double minY = std::numeric_limits<double >::max ();
194
+ double maxY = std::numeric_limits<double >::lowest ();
195
+
196
+ for_each_v_const (currentGraph, [&](Ver v) {
197
+ const cgtea_geometry::Point pos = boost::get (boost::vertex_distance, currentGraph, v);
198
+ minX = std::min (minX, pos.x );
199
+ maxX = std::max (maxX, pos.x );
200
+ minY = std::min (minY, pos.y );
201
+ maxY = std::max (maxY, pos.y );
202
+ });
203
+
204
+ // Get the panel width
205
+ // auto panelSize = this->GetClientSize();
206
+ auto panelSize = this ->GetSizer ()->GetItem (1 )->GetSize ();
207
+ // auto panelSize = this->GetSizer()->GetItemById(0)->GetSize();
208
+ cout << this ->GetSizer ()->GetItemCount ();
209
+ cout << panelSize.GetWidth () << endl;
210
+ cout << panelSize.GetHeight () << endl;
211
+ double padding = 20 ; // Leave some space for vertices on the edges
212
+ double scaleX = (panelSize.GetWidth () - 2 * padding) / (maxX - minX);
213
+ double scaleY = (panelSize.GetHeight () - 2 * padding) / (maxY - minY);
214
+
215
+ // Scale and center all vertices
216
+ for_each_v (currentGraph, [&](const Ver v) {
217
+ cgtea_geometry::Point pos = boost::get (boost::vertex_distance, currentGraph, v);
218
+ pos.x = (pos.x - minX) * scaleX + padding;
219
+ pos.y = (pos.y - minY) * scaleY + padding;
220
+ boost::put (boost::vertex_distance, currentGraph, v, pos);
221
+ });
222
+ Refresh ();
223
+ }
224
+
225
+
184
226
void CGTeaFrame::Report (wxCommandEvent& event) {
185
227
int id = event.GetId ();
186
228
std::string report_results = availableReports[id - availableGenerators.size () - 1 ]->report (currentGraph);
0 commit comments