Skip to content

Commit 19763db

Browse files
muehlhauskMutagene
andauthored
Add statically typed color representation (#171)
Co-authored-by: Kevin Schneider <[email protected]>
1 parent a1211d1 commit 19763db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1087
-471
lines changed

docs/1_3_shapes.fsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ multiple shapes at once.
4747

4848
open Plotly.NET.LayoutObjects
4949

50-
let s1 = Shape.init (StyleParam.ShapeType.Rectangle,2.,4.,3.,4.,Opacity=0.3,Fillcolor="#d3d3d3")
51-
let s2 = Shape.init (StyleParam.ShapeType.Rectangle,5.,7.,3.,4.,Opacity=0.3,Fillcolor="#d3d3d3")
50+
let s1 = Shape.init (StyleParam.ShapeType.Rectangle,2.,4.,3.,4.,Opacity=0.3,Fillcolor= Color.fromHex "#d3d3d3")
51+
let s2 = Shape.init (StyleParam.ShapeType.Rectangle,5.,7.,3.,4.,Opacity=0.3,Fillcolor= Color.fromHex "#d3d3d3")
5252

5353
let shapes =
5454
Chart.Line(x,y',Name="line")

docs/1_4_annotations.fsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ multiple annotations at once.
4949
open Plotly.NET.LayoutObjects
5050

5151
let a1 = Annotation.init (X=2.,Y=4.,Text = "Hi there!")
52-
let a2 = Annotation.init (X=5.,Y=7.,Text="I am another annotation!",BGColor="white",BorderColor="black")
52+
let a2 = Annotation.init (X=5.,Y=7.,Text="I am another annotation!",BGColor= Color.fromString "white",BorderColor= Color.fromString "black")
5353

5454
let annotations =
5555
Chart.Line(x,y',Name="line")

docs/2_3_range-plots.fsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ let range1 =
5252
Chart.Range(
5353
x,y,yUpper,yLower,
5454
StyleParam.Mode.Lines_Markers,
55-
Color="grey",
56-
RangeColor="lightblue")
55+
Color = Color.fromString "grey",
56+
RangeColor = Color.fromString "lightblue")
5757

5858
(*** condition: ipynb ***)
5959
#if IPYNB

docs/2_6_table.fsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ let table2 =
7979
//sets cell row colors
8080
//ColorCells=[["#deebf7";"lightgrey"]],
8181
//sets font of header
82-
FontHeader = Font.init(FontFamily.Courier_New, Size=12., Color="white"),
82+
FontHeader = Font.init(FontFamily.Courier_New, Size=12., Color=Color.fromString "white"),
8383
//sets the height of the header
8484
HeightHeader= 30.,
8585
//sets lines of header
86-
LineHeader = Line.init(2.,"black"),
86+
LineHeader = Line.init(2.,Color.fromString "black"),
8787
ColumnWidth = [70;50;100;70],
8888
//defines order of columns
8989
ColumnOrder = [1;2;3;4]
@@ -120,8 +120,8 @@ let mapColor min max value =
120120
let proportion =
121121
(255. * (value - min) / (max - min))
122122
|> int
123-
Colors.fromRgb 255 (255 - proportion) proportion
124-
|> Colors.toWebColor
123+
ARGB.fromRGB 255 (255 - proportion) proportion
124+
|> ARGB.toWebHex
125125

126126
//Assign a color to every cell seperately. Matrix must be transposed for correct orientation.
127127
let cellcolor =
@@ -196,7 +196,7 @@ let cellcolors =
196196
|> Seq.map (fun x -> Seq.append x (seq ["white"]))
197197

198198
let font = Font.init(FontFamily.Consolas,Size=14.)
199-
let line = Line.init(0.,"white")
199+
let line = Line.init(0.,Color.fromString "white")
200200
let chartwidth = 50. + 10. * float elementsPerRow
201201

202202
let table4 =

docs/4_5_splom.fsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Until that is fixed, consider creating splom plot programatically using `Chart.G
5252
*)
5353

5454
let splom1 =
55-
Chart.Splom(data,Color="blue")
55+
Chart.Splom(data,Color=Color.fromString "blue")
5656

5757
(*** condition: ipynb ***)
5858
#if IPYNB

docs/5_0_geo-vs-mapbox.fsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ let myGeo =
7272
Geo.init(
7373
Resolution=StyleParam.GeoResolution.R50,
7474
ShowCoastLines=true,
75-
CoastLineColor="RebeccaPurple",
75+
CoastLineColor=Color.fromString "RebeccaPurple",
7676
ShowLand=true,
77-
LandColor="LightGreen",
77+
LandColor=Color.fromString "LightGreen",
7878
ShowOcean=true,
79-
OceanColor="LightBlue",
79+
OceanColor=Color.fromString "LightBlue",
8080
ShowLakes=true,
81-
LakeColor="Blue",
81+
LakeColor=Color.fromString "Blue",
8282
ShowRivers=true,
83-
RiverColor="Blue"
83+
RiverColor=Color.fromString "Blue"
8484
)
8585

8686
let moreFeaturesBaseMap =
@@ -114,7 +114,7 @@ let countryGeo =
114114
Visible=false,
115115
Resolution=StyleParam.GeoResolution.R50,
116116
ShowCountries=true,
117-
CountryColor="RebeccaPurple"
117+
CountryColor=Color.fromString "RebeccaPurple"
118118
)
119119

120120

docs/5_1_geo-plots.fsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let pointGeo =
6464
|> Chart.withGeoStyle(
6565
Scope=StyleParam.GeoScope.NorthAmerica,
6666
Projection=GeoProjection.init(StyleParam.GeoProjectionType.AzimuthalEqualArea),
67-
CountryColor = "lightgrey"
67+
CountryColor = Color.fromString "lightgrey"
6868
)
6969
|> Chart.withMarginSize(0,0,0,0)
7070

@@ -106,7 +106,7 @@ let flights =
106106
Chart.LineGeo(
107107
[startCoords; endCoords],
108108
Opacity = opacityVals.[i],
109-
Color = "red"
109+
Color = Color.fromString "red"
110110
)
111111
)
112112
|> Chart.combine
@@ -115,7 +115,7 @@ let flights =
115115
Scope=StyleParam.GeoScope.NorthAmerica,
116116
Projection=GeoProjection.init(StyleParam.GeoProjectionType.AzimuthalEqualArea),
117117
ShowLand=true,
118-
LandColor = "lightgrey"
118+
LandColor = Color.fromString "lightgrey"
119119
)
120120
|> Chart.withMarginSize(0,0,50,0)
121121
|> Chart.withTitle "Feb. 2011 American Airline flights"

docs/5_2_choropleth-map.fsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ let choroplethMap2 =
124124
Projection=GeoProjection.init(projectionType=StyleParam.GeoProjectionType.Mollweide),
125125
ShowLakes=true,
126126
ShowOcean=true,
127-
OceanColor="lightblue",
127+
OceanColor=Color.fromString "lightblue",
128128
ShowRivers=true)
129129
|> Chart.withColorBarStyle (Title.init("Alcohol consumption[l/y]"),Length=0.5)
130130

@@ -244,7 +244,7 @@ let choroplethGeoJSON =
244244
Scope=StyleParam.GeoScope.NorthAmerica,
245245
Projection=GeoProjection.init(StyleParam.GeoProjectionType.AzimuthalEqualArea),
246246
ShowLand=true,
247-
LandColor = "lightgrey"
247+
LandColor = Color.fromString "lightgrey"
248248
)
249249
)
250250
|> Chart.withSize (800.,800.)

docs/6_1_mapbox-plots.fsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ let flights =
103103
Chart.LineMapbox(
104104
[startCoords; endCoords],
105105
Opacity = opacityVals.[i],
106-
Color = "red"
106+
Color = Color.fromString "red"
107107
)
108108
)
109109
|> Chart.combine

docs/7_1_funnel.fsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ open Plotly.NET
4545
open Plotly.NET.TraceObjects
4646

4747
// Customize the connector lines used to connect the funnel bars
48-
let connectorLine = Line.init (Color="royalblue", Dash=StyleParam.DrawingStyle.Dot, Width=3.)
48+
let connectorLine = Line.init (Color=Color.fromString "royalblue", Dash=StyleParam.DrawingStyle.Dot, Width=3.)
4949
let connector = FunnelConnector.init(Line=connectorLine)
5050

5151
// Customize the outline of the funnel bars
52-
let line = Line.init(Width=2.,Color="3E4E88")
52+
let line = Line.init(Width=2.,Color=Color.fromHex "3E4E88")
5353

5454
// create a funnel chart using custom connectors and outlines
5555
let funnel =
56-
Chart.Funnel (x,y,Color="59D4E8", Line=line, Connector=connector)
56+
Chart.Funnel (x,y,Color=Color.fromHex "59D4E8", Line=line, Connector=connector)
5757
|> Chart.withMarginSize(Left=100)
5858

5959
(*** condition: ipynb ***)

docs/7_2_funnel_area.fsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ to visualizing funnel data.
4444

4545
open Plotly.NET
4646

47-
let line = Line.init (Color="purple", Width=3.)
47+
let line = Line.init (Color=Color.fromString "purple", Width=3.)
4848

4949
let funnelArea =
5050
Chart.FunnelArea(Values=values, Text=text, Line=line)

docs/8_0_polar_line-scatter-plots.fsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ You can for example change the line style using `Chart.withLineStyle`
7575

7676
let linePolar =
7777
Chart.LinePolar(radial,theta)
78-
|> Chart.withLineStyle(Color="purple",Dash=StyleParam.DrawingStyle.DashDot)
78+
|> Chart.withLineStyle(Color=Color.fromString "purple",Dash=StyleParam.DrawingStyle.DashDot)
7979

8080
(*** condition: ipynb ***)
8181
#if IPYNB

docs/8_2_styling_polar_layouts.fsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ let styledPolar2 =
9797
styledPolar
9898
|> Chart.withAngularAxis(
9999
AngularAxis.init(
100-
Color="darkblue"
100+
Color=Color.fromString "darkblue"
101101
)
102102
)
103103
|> Chart.withRadialAxis(
104104
RadialAxis.init(
105105
Title = Title.init("Hi, i am the radial axis"),
106-
Color="darkblue",
106+
Color=Color.fromString "darkblue",
107107
SeparateThousands = true
108108
)
109109
)

docs/9_0_parallel-categories.fsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let dims =
4545
let parcats =
4646
Chart.ParallelCategories(
4747
dims,
48-
Color=[0.;1.;0.;1.;0.;0.;0.],
48+
Color = Color.fromColorScaleValues [0.;1.;0.;1.;0.;0.;0.],
4949
Colorscale = StyleParam.Colorscale.Blackbody
5050
)
5151

docs/9_1_parallel-coords.fsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ the position of the vertex on the i-th axis corresponds to the i-th coordinate o
5353
*)
5454

5555
let parcoords1 =
56-
Chart.ParallelCoord(data,Color="blue")
56+
Chart.ParallelCoord(data,Color=Color.fromString "blue")
5757

5858
(*** condition: ipynb ***)
5959
#if IPYNB
@@ -83,7 +83,7 @@ let parcoords =
8383
let dyn = Trace("parcoords")
8484

8585
dyn?dimensions <- v
86-
dyn?line <- Line.init(Color = "blue")
86+
dyn?line <- Line.init(Color=Color.fromString "blue")
8787

8888
dyn
8989
|> GenericChart.ofTraceObject

src/Plotly.NET/ChartAPI/Chart2D.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -602,15 +602,15 @@ module Chart2D =
602602
Trace2DStyle.Scatter(X = x,Y = lower, Mode=StyleParam.Mode.Lines, ?FillColor=RangeColor) )
603603
|> TraceStyle.TraceInfo(?Name = Some lowerName, Showlegend=false)
604604
|> TraceStyle.Line(Width=0.)
605-
|> TraceStyle.Marker(Color=if RangeColor.IsSome then RangeColor.Value else "rgba(0,0,0,0.5)")
605+
|> TraceStyle.Marker(Color=if RangeColor.IsSome then RangeColor.Value else (Plotly.NET.Color.fromString "rgba(0,0,0,0.5)"))
606606
|> TraceStyle.TextLabel(?Text=LowerLabels,?Textposition=TextPosition,?Textfont=TextFont)
607607

608608
let upper =
609609
Trace2D.initScatter (
610610
Trace2DStyle.Scatter(X = x,Y = upper, Mode=StyleParam.Mode.Lines, ?FillColor=RangeColor, Fill=StyleParam.Fill.ToNext_y) )
611611
|> TraceStyle.TraceInfo(?Name = Some upperName, Showlegend=false)
612612
|> TraceStyle.Line(Width=0.)
613-
|> TraceStyle.Marker(Color=if RangeColor.IsSome then RangeColor.Value else "rgba(0,0,0,0.5)")
613+
|> TraceStyle.Marker(Color=if RangeColor.IsSome then RangeColor.Value else (Plotly.NET.Color.fromString "rgba(0,0,0,0.5)"))
614614
|> TraceStyle.TextLabel(?Text=UpperLabels,?Textposition=TextPosition,?Textfont=TextFont)
615615

616616
GenericChart.MultiChart ([lower;upper;trace],Layout(),Config(), DisplayOptions())

src/Plotly.NET/ChartAPI/ChartDomain.fs

+24-24
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ module ChartDomain =
2121
[<Optional;DefaultParameterValue(null)>] ?Labels:seq<'IConvertible>,
2222
[<Optional;DefaultParameterValue(null)>] ?Name,
2323
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
24-
[<Optional;DefaultParameterValue(null)>] ?Colors,
24+
[<Optional;DefaultParameterValue(null)>] ?Color,
2525
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
2626
[<Optional;DefaultParameterValue(null)>] ?TextFont,
2727
[<Optional;DefaultParameterValue(null)>] ?Hoverinfo,
2828
[<Optional;DefaultParameterValue(null)>] ?Textinfo,
2929
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
3030
TraceDomain.initPie (TraceDomainStyle.Pie(Values=values,?Labels=Labels,?Textinfo=Textinfo))
3131
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity,?Hoverinfo=Hoverinfo)
32-
|> TraceStyle.Marker(?Colors=Colors)
32+
|> TraceStyle.Marker(?Color=Color)
3333
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
3434
|> GenericChart.ofTraceObject
3535

@@ -38,22 +38,22 @@ module ChartDomain =
3838
static member Pie(data:seq<#IConvertible*#IConvertible>,
3939
[<Optional;DefaultParameterValue(null)>] ?Name,
4040
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
41-
[<Optional;DefaultParameterValue(null)>] ?Colors,
41+
[<Optional;DefaultParameterValue(null)>] ?Color,
4242
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
4343
[<Optional;DefaultParameterValue(null)>] ?TextFont,
4444
[<Optional;DefaultParameterValue(null)>] ?Hoverinfo,
4545
[<Optional;DefaultParameterValue(null)>] ?Textinfo,
4646
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
4747
let values,labels = Seq.unzip data
48-
Chart.Pie(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Colors=Colors,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)
48+
Chart.Pie(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Color=Color,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)
4949

5050

5151
/// Shows how proportions of data, shown as pie-shaped pieces, contribute to the data as a whole.
5252
static member Doughnut(values,
5353
[<Optional;DefaultParameterValue(null)>] ?Labels,
5454
[<Optional;DefaultParameterValue(null)>] ?Name,
5555
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
56-
[<Optional;DefaultParameterValue(null)>] ?Colors,
56+
[<Optional;DefaultParameterValue(null)>] ?Color,
5757
[<Optional;DefaultParameterValue(null)>] ?Hole,
5858
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
5959
[<Optional;DefaultParameterValue(null)>] ?TextFont,
@@ -63,7 +63,7 @@ module ChartDomain =
6363
let hole' = if Hole.IsSome then Hole.Value else 0.4
6464
TraceDomain.initPie (TraceDomainStyle.Pie(Values=values,?Labels=Labels,?Textinfo=Textinfo,Hole=hole'))
6565
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity,?Hoverinfo=Hoverinfo)
66-
|> TraceStyle.Marker(?Colors=Colors)
66+
|> TraceStyle.Marker(?Color=Color)
6767
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
6868
|> GenericChart.ofTraceObject
6969

@@ -72,15 +72,15 @@ module ChartDomain =
7272
static member Doughnut(data:seq<#IConvertible*#IConvertible>,
7373
[<Optional;DefaultParameterValue(null)>] ?Name,
7474
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
75-
[<Optional;DefaultParameterValue(null)>] ?Colors,
75+
[<Optional;DefaultParameterValue(null)>] ?Color,
7676
[<Optional;DefaultParameterValue(null)>] ?Hole,
7777
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
7878
[<Optional;DefaultParameterValue(null)>] ?TextFont,
7979
[<Optional;DefaultParameterValue(null)>] ?Hoverinfo,
8080
[<Optional;DefaultParameterValue(null)>] ?Textinfo,
8181
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
8282
let values,labels = Seq.unzip data
83-
Chart.Doughnut(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Colors=Colors,?Hole=Hole,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)
83+
Chart.Doughnut(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Color=Color,?Hole=Hole,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)
8484

8585

8686

@@ -194,12 +194,12 @@ module ChartDomain =
194194
///Colors: Sets the color of each sector of this trace. If not specified, the default trace color set is used to pick the sector colors.
195195
static member Sunburst(labels,parents,
196196
[<Optional;DefaultParameterValue(null)>]?Ids,
197-
[<Optional;DefaultParameterValue(null)>]?Values ,
198-
[<Optional;DefaultParameterValue(null)>]?Text ,
199-
[<Optional;DefaultParameterValue(null)>]?Branchvalues ,
200-
[<Optional;DefaultParameterValue(null)>]?Level ,
201-
[<Optional;DefaultParameterValue(null)>]?Maxdepth ,
202-
[<Optional;DefaultParameterValue(null)>]?Colors: seq<string>,
197+
[<Optional;DefaultParameterValue(null)>]?Values,
198+
[<Optional;DefaultParameterValue(null)>]?Text,
199+
[<Optional;DefaultParameterValue(null)>]?Branchvalues,
200+
[<Optional;DefaultParameterValue(null)>]?Level,
201+
[<Optional;DefaultParameterValue(null)>]?Maxdepth,
202+
[<Optional;DefaultParameterValue(null)>]?Color,
203203
[<Optional;DefaultParameterValue(null)>]?ColorBar:ColorBar
204204
) =
205205
TraceDomain.initSunburst(
@@ -214,7 +214,7 @@ module ChartDomain =
214214
?Maxdepth = Maxdepth
215215
)
216216
)
217-
|> TraceStyle.Marker(?Colors=Colors,?ColorBar=ColorBar)
217+
|> TraceStyle.Marker(?Color=Color,?ColorBar=ColorBar)
218218
|> GenericChart.ofTraceObject
219219

220220

@@ -243,14 +243,14 @@ module ChartDomain =
243243
///Colors: Sets the color of each sector of this trace. If not specified, the default trace color set is used to pick the sector colors.
244244
static member Treemap(labels,parents,
245245
[<Optional;DefaultParameterValue(null)>]?Ids,
246-
[<Optional;DefaultParameterValue(null)>]?Values ,
247-
[<Optional;DefaultParameterValue(null)>]?Text ,
248-
[<Optional;DefaultParameterValue(null)>]?Branchvalues ,
249-
[<Optional;DefaultParameterValue(null)>]?Tiling ,
250-
[<Optional;DefaultParameterValue(null)>]?PathBar ,
251-
[<Optional;DefaultParameterValue(null)>]?Level ,
252-
[<Optional;DefaultParameterValue(null)>]?Maxdepth ,
253-
[<Optional;DefaultParameterValue(null)>]?Colors: seq<string>,
246+
[<Optional;DefaultParameterValue(null)>]?Values,
247+
[<Optional;DefaultParameterValue(null)>]?Text,
248+
[<Optional;DefaultParameterValue(null)>]?Branchvalues,
249+
[<Optional;DefaultParameterValue(null)>]?Tiling,
250+
[<Optional;DefaultParameterValue(null)>]?PathBar,
251+
[<Optional;DefaultParameterValue(null)>]?Level,
252+
[<Optional;DefaultParameterValue(null)>]?Maxdepth,
253+
[<Optional;DefaultParameterValue(null)>]?Color,
254254
[<Optional;DefaultParameterValue(null)>]?ColorBar:ColorBar
255255
) =
256256
TraceDomain.initTreemap(
@@ -267,7 +267,7 @@ module ChartDomain =
267267
?Maxdepth = Maxdepth
268268
)
269269
)
270-
|> TraceStyle.Marker(?Colors=Colors,?ColorBar=ColorBar)
270+
|> TraceStyle.Marker(?Color=Color,?ColorBar=ColorBar)
271271
|> GenericChart.ofTraceObject
272272

273273

0 commit comments

Comments
 (0)