11defmodule Matplotex.Figure.Areal.PlotOptions do
22 @ moduledoc false
3+ alias Matplotex.Colorscheme.Colormap
34 alias Matplotex.Figure
45 alias Matplotex.Figure.TwoD
56 alias Matplotex.Figure.RcParams
@@ -15,11 +16,11 @@ defmodule Matplotex.Figure.Areal.PlotOptions do
1516 :region_legend ,
1617 :region_color_bar
1718 ]
19+ @ default_cmap :viridis
1820
1921 @ spec set_options_in_figure ( Figure . t ( ) , keyword ( ) ) :: Figure . t ( )
2022 def set_options_in_figure ( % Figure { } = figure , opts ) do
2123 opts = sanitize ( opts )
22-
2324 figure
2425 |> cast_figure ( opts )
2526 |> cast_axes ( opts )
@@ -31,11 +32,14 @@ defmodule Matplotex.Figure.Areal.PlotOptions do
3132 end
3233
3334 defp cast_axes ( % Figure { axes: axes } = figure , opts ) do
35+
3436 opts = Keyword . delete ( opts , :label )
37+ cmap = Keyword . get ( opts , :cmap )
38+ colors = Keyword . get ( opts , :colors )
3539
3640 % Figure {
3741 figure
38- | axes: axes |> struct ( opts ) |> cast_two_d_structs ( opts )
42+ | axes: axes |> struct ( opts ) |> cast_two_d_structs ( opts ) |> update_cmap ( cmap , colors )
3943 }
4044 end
4145
@@ -58,4 +62,14 @@ defmodule Matplotex.Figure.Areal.PlotOptions do
5862 defp sanitize ( opts ) do
5963 Keyword . drop ( opts , @ immutable_keys )
6064 end
65+ defp update_cmap ( axes , nil , colors ) when is_list ( colors ) do
66+
67+ % { axes | cmap: Colormap . fetch_cmap ( @ default_cmap ) }
68+ end
69+
70+ defp update_cmap ( axes , cmap , colors ) when is_list ( colors ) do
71+ % { axes | cmap: Colormap . fetch_cmap ( cmap ) }
72+ end
73+
74+ defp update_cmap ( figure , _ , _ ) , do: figure
6175end
0 commit comments