Skip to content

Commit ed542b1

Browse files
committed
Use Color type instead of string for custom color scales
1 parent 466efdc commit ed542b1

File tree

6 files changed

+137
-106
lines changed

6 files changed

+137
-106
lines changed

src/Plotly.NET/CommonAbstractions/StyleParams.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ module StyleParam =
716716
/// The colorscale must be a collection containing a mapping of a normalized value (between 0.0 and 1.0) to it's color. At minimum, a mapping for the lowest (0.0) and highest (1.0) values are required.
717717
[<RequireQualifiedAccess>]
718718
type Colorscale =
719-
| Custom of seq<float * string>
719+
| Custom of seq<float * Color>
720720
| RdBu
721721
| Earth
722722
| Blackbody
@@ -733,9 +733,15 @@ module StyleParam =
733733
| Rainbow
734734
| Viridis
735735
| Cividis
736+
736737
static member convert =
737738
function
738-
| Custom (cScale) -> cScale |> Seq.map (fun (v, color) -> [| box v; box color |]) |> Array.ofSeq |> box
739+
| Custom (cScale) ->
740+
if Seq.length cScale < 2 then
741+
failwith
742+
"Color scale did not contain enough values. At minimum, a mapping for the lowest (0.0) and highest (1.0) values are required"
743+
744+
cScale |> Seq.map (fun (v, color) -> [| box v; box color |]) |> Array.ofSeq |> box
739745
| RdBu -> box "RdBu"
740746
| Earth -> box "Earth"
741747
| Blackbody -> box "Blackbody"

src/Plotly.NET/Plotly.NET.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
<None Include="..\..\docs\img\logo.png" Pack="true" PackagePath="\" />
3636
<Compile Include="AssemblyInfo.fs" />
3737
<Compile Include="InternalUtils.fs" />
38-
<Compile Include="CommonAbstractions\StyleParams.fs" />
3938
<Compile Include="CommonAbstractions\ColorKeyword.fs" />
4039
<Compile Include="CommonAbstractions\Colors.fs" />
40+
<Compile Include="CommonAbstractions\StyleParams.fs" />
4141
<Compile Include="CommonAbstractions\TickFormatStop.fs" />
4242
<Compile Include="CommonAbstractions\Frame.fs" />
4343
<Compile Include="CommonAbstractions\Font.fs" />

0 commit comments

Comments
 (0)