Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/PlotUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module PlotUtils
using SnoopPrecompile
using ColorSchemes
using Reexport
using DelimitedFiles
using Printf
using Dates

Expand Down
22 changes: 22 additions & 0 deletions src/color_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down