Skip to content

Commit 0e2af14

Browse files
committed
Save as pdf for CairoMakie
1 parent a4fa28c commit 0e2af14

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

examples/rectangular_wing.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ using LinearAlgebra
22
using VortexStepMethod
33

44
PLOT = true
5+
SAVE_ALL = false
56
USE_TEX = false
7+
OUTPUT_DIR = joinpath(dirname(@__DIR__), "output")
68

79
# Step 1: Define wing parameters
810
n_panels = 20 # Number of panels
@@ -60,8 +62,8 @@ PLOT && plot_geometry(
6062
body_aero,
6163
"Rectangular_wing_geometry";
6264
data_type=".pdf",
63-
save_path=".",
64-
is_save=false,
65+
save_path=OUTPUT_DIR,
66+
is_save=false || SAVE_ALL,
6567
is_show=true,
6668
use_tex=USE_TEX
6769
)
@@ -74,6 +76,8 @@ PLOT && plot_distribution(
7476
[results_vsm, results_llt],
7577
["VSM", "LLT"],
7678
title="Spanwise Distributions",
79+
save_path=OUTPUT_DIR,
80+
is_save=false || SAVE_ALL,
7781
use_tex=USE_TEX
7882
)
7983

@@ -87,6 +91,8 @@ PLOT && plot_polars(
8791
angle_type="angle_of_attack",
8892
v_a,
8993
title="Rectangular Wing Polars",
94+
save_path=OUTPUT_DIR,
95+
is_save=false || SAVE_ALL,
9096
use_tex=USE_TEX
9197
)
9298
nothing

ext/VortexStepMethodControlPlotsExt.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ function VortexStepMethod.save_plot(fig, save_path, title; data_type=".pdf")
5656
isnothing(save_path) && throw(ArgumentError("save_path should be provided"))
5757

5858
!isdir(save_path) && mkpath(save_path)
59-
full_path = joinpath(save_path, title * data_type)
59+
sanitized_title = replace(String(title), ' ' => '_')
60+
full_path = joinpath(save_path, sanitized_title * data_type)
6061

6162
@debug "Attempting to save figure to: $full_path"
6263
@debug "Current working directory: $(pwd())"

ext/VortexStepMethodMakieExt.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ function VortexStepMethod.save_plot(fig::Makie.Figure, save_path, title; data_ty
257257
isnothing(save_path) && throw(ArgumentError("save_path should be provided"))
258258

259259
!isdir(save_path) && mkpath(save_path)
260-
full_path = joinpath(save_path, title * data_type)
261-
fallback_path = joinpath(save_path, title * ".png")
260+
sanitized_title = replace(String(title), ' ' => '_')
261+
full_path = joinpath(save_path, sanitized_title * data_type)
262+
fallback_path = joinpath(save_path, sanitized_title * ".png")
262263

263264
@debug "Attempting to save figure to: $full_path"
264265
@debug "Current working directory: $(pwd())"
@@ -504,7 +505,7 @@ end
504505

505506
"""
506507
plot_distribution(y_coordinates_list, results_list, label_list;
507-
title="spanwise_distribution", data_type=".png",
508+
title="spanwise_distribution", data_type=nothing,
508509
save_path=nothing, is_save=false, is_show=true, use_tex=false)
509510
510511
Plot spanwise distributions of aerodynamic properties using Makie.
@@ -516,15 +517,15 @@ Plot spanwise distributions of aerodynamic properties using Makie.
516517
517518
# Keyword arguments
518519
- `title`: Plot title (default: "spanwise_distribution")
519-
- `data_type`: File extension (default: ".png", also supports ".jpeg")
520+
- `data_type`: File extension (default: `nothing`; delegated to `save_plot` backend-aware default)
520521
- `save_path`: Path to save plots (default: nothing)
521522
- `is_save`: Whether to save (default: false)
522523
- `is_show`: Whether to display (default: true)
523524
- `use_tex`: Ignored for Makie (default: false)
524525
"""
525526
function VortexStepMethod.plot_distribution(y_coordinates_list, results_list, label_list;
526527
title="spanwise_distribution",
527-
data_type=".png",
528+
data_type=nothing,
528529
save_path=nothing,
529530
is_save=false,
530531
is_show=true,
@@ -659,7 +660,7 @@ Generate polar data for aerodynamic analysis over a range of angles.
659660
literature_path_list=String[],
660661
angle_range=range(0, 20, 2), angle_type="angle_of_attack",
661662
angle_of_attack=0.0, side_slip=0.0, v_a=10.0,
662-
title="polar", data_type=".png", save_path=nothing,
663+
title="polar", data_type=nothing, save_path=nothing,
663664
is_save=true, is_show=true, use_tex=false)
664665
665666
Plot polar data comparing different solvers using Makie.
@@ -677,7 +678,7 @@ Plot polar data comparing different solvers using Makie.
677678
- `side_slip`: Side slip angle [°] (default: 0.0)
678679
- `v_a`: Wind speed [m/s] (default: 10.0)
679680
- `title`: Plot title
680-
- `data_type`: File extension (default: ".png", also supports ".jpeg")
681+
- `data_type`: File extension (default: `nothing`; delegated to `save_plot` backend-aware default)
681682
- `save_path`: Path to save (default: nothing)
682683
- `is_save`: Whether to save (default: true)
683684
- `is_show`: Whether to display (default: true)
@@ -695,7 +696,7 @@ function VortexStepMethod.plot_polars(
695696
side_slip=0.0,
696697
v_a=10.0,
697698
title="polar",
698-
data_type=".png",
699+
data_type=nothing,
699700
save_path=nothing,
700701
is_save=true,
701702
is_show=true,

0 commit comments

Comments
 (0)