diff --git a/Project.toml b/Project.toml index 0698ea8..e12703b 100644 --- a/Project.toml +++ b/Project.toml @@ -6,6 +6,7 @@ version = "1.3.4" ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" diff --git a/src/PlotUtils.jl b/src/PlotUtils.jl index 1ab7a44..2ed4d07 100644 --- a/src/PlotUtils.jl +++ b/src/PlotUtils.jl @@ -3,6 +3,7 @@ module PlotUtils using SnoopPrecompile using ColorSchemes using Reexport +using DelimitedFiles using Printf using Dates diff --git a/src/color_utils.jl b/src/color_utils.jl index aca4640..e63ffb4 100644 --- a/src/color_utils.jl +++ b/src/color_utils.jl @@ -35,6 +35,28 @@ function generate_colorscheme( ColorScheme(colors) end +# -------------------------------------------------------------- +# Methods to save colorschemes to CSV +function cgrad_to_csv(file::AbstractString, cgrad::ColorGradient) + values = cgrad.values + colors = cgrad.colors.colors + + reds = Colors.red.(colors) + greens = Colors.green.(colors) + blues = Colors.blue.(colors) + alphas = Colors.alpha.(colors) + + csv_matrix = hcat(values, reds, greens, blues, alphas) + csv_matrix_with_headers = vcat(["Value" "Red" "Green" "Blue" "Alpha"], csv_matrix) + + DelimitedFiles.writedlm(file, csv_matrix_with_headers, ',') +end + +function csv_to_cgrad(file::AbstractString) + data_cells, header_cells = DelimitedFiles.readdlm(file, ',', Float64, '\n'; header = true) + return cgrad(RGBA{Float64}.(data_cells[:, 2], data_cells[:, 3], data_cells[:, 4], data_cells[:, 5]), data_cells[:, 1]) +end + # ---------------------------------------------------------------------------------- function getpctrange(n::Integer)