Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statically typed color representation #171

Merged
merged 10 commits into from
Sep 4, 2021
Merged
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
4 changes: 2 additions & 2 deletions docs/1_3_shapes.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ multiple shapes at once.

open Plotly.NET.LayoutObjects

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

let shapes =
Chart.Line(x,y',Name="line")
Expand Down
2 changes: 1 addition & 1 deletion docs/1_4_annotations.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ multiple annotations at once.
open Plotly.NET.LayoutObjects

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

let annotations =
Chart.Line(x,y',Name="line")
Expand Down
4 changes: 2 additions & 2 deletions docs/2_3_range-plots.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ let range1 =
Chart.Range(
x,y,yUpper,yLower,
StyleParam.Mode.Lines_Markers,
Color="grey",
RangeColor="lightblue")
Color = Color.fromString "grey",
RangeColor = Color.fromString "lightblue")

(*** condition: ipynb ***)
#if IPYNB
Expand Down
10 changes: 5 additions & 5 deletions docs/2_6_table.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ let table2 =
//sets cell row colors
//ColorCells=[["#deebf7";"lightgrey"]],
//sets font of header
FontHeader = Font.init(FontFamily.Courier_New, Size=12., Color="white"),
FontHeader = Font.init(FontFamily.Courier_New, Size=12., Color=Color.fromString "white"),
//sets the height of the header
HeightHeader= 30.,
//sets lines of header
LineHeader = Line.init(2.,"black"),
LineHeader = Line.init(2.,Color.fromString "black"),
ColumnWidth = [70;50;100;70],
//defines order of columns
ColumnOrder = [1;2;3;4]
Expand Down Expand Up @@ -120,8 +120,8 @@ let mapColor min max value =
let proportion =
(255. * (value - min) / (max - min))
|> int
Colors.fromRgb 255 (255 - proportion) proportion
|> Colors.toWebColor
ARGB.fromRGB 255 (255 - proportion) proportion
|> ARGB.toWebHex

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

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

let table4 =
Expand Down
2 changes: 1 addition & 1 deletion docs/4_5_splom.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Until that is fixed, consider creating splom plot programatically using `Chart.G
*)

let splom1 =
Chart.Splom(data,Color="blue")
Chart.Splom(data,Color=Color.fromString "blue")

(*** condition: ipynb ***)
#if IPYNB
Expand Down
12 changes: 6 additions & 6 deletions docs/5_0_geo-vs-mapbox.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ let myGeo =
Geo.init(
Resolution=StyleParam.GeoResolution.R50,
ShowCoastLines=true,
CoastLineColor="RebeccaPurple",
CoastLineColor=Color.fromString "RebeccaPurple",
ShowLand=true,
LandColor="LightGreen",
LandColor=Color.fromString "LightGreen",
ShowOcean=true,
OceanColor="LightBlue",
OceanColor=Color.fromString "LightBlue",
ShowLakes=true,
LakeColor="Blue",
LakeColor=Color.fromString "Blue",
ShowRivers=true,
RiverColor="Blue"
RiverColor=Color.fromString "Blue"
)

let moreFeaturesBaseMap =
Expand Down Expand Up @@ -114,7 +114,7 @@ let countryGeo =
Visible=false,
Resolution=StyleParam.GeoResolution.R50,
ShowCountries=true,
CountryColor="RebeccaPurple"
CountryColor=Color.fromString "RebeccaPurple"
)


Expand Down
6 changes: 3 additions & 3 deletions docs/5_1_geo-plots.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let pointGeo =
|> Chart.withGeoStyle(
Scope=StyleParam.GeoScope.NorthAmerica,
Projection=GeoProjection.init(StyleParam.GeoProjectionType.AzimuthalEqualArea),
CountryColor = "lightgrey"
CountryColor = Color.fromString "lightgrey"
)
|> Chart.withMarginSize(0,0,0,0)

Expand Down Expand Up @@ -106,7 +106,7 @@ let flights =
Chart.LineGeo(
[startCoords; endCoords],
Opacity = opacityVals.[i],
Color = "red"
Color = Color.fromString "red"
)
)
|> Chart.combine
Expand All @@ -115,7 +115,7 @@ let flights =
Scope=StyleParam.GeoScope.NorthAmerica,
Projection=GeoProjection.init(StyleParam.GeoProjectionType.AzimuthalEqualArea),
ShowLand=true,
LandColor = "lightgrey"
LandColor = Color.fromString "lightgrey"
)
|> Chart.withMarginSize(0,0,50,0)
|> Chart.withTitle "Feb. 2011 American Airline flights"
Expand Down
4 changes: 2 additions & 2 deletions docs/5_2_choropleth-map.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ let choroplethMap2 =
Projection=GeoProjection.init(projectionType=StyleParam.GeoProjectionType.Mollweide),
ShowLakes=true,
ShowOcean=true,
OceanColor="lightblue",
OceanColor=Color.fromString "lightblue",
ShowRivers=true)
|> Chart.withColorBarStyle (Title.init("Alcohol consumption[l/y]"),Length=0.5)

Expand Down Expand Up @@ -244,7 +244,7 @@ let choroplethGeoJSON =
Scope=StyleParam.GeoScope.NorthAmerica,
Projection=GeoProjection.init(StyleParam.GeoProjectionType.AzimuthalEqualArea),
ShowLand=true,
LandColor = "lightgrey"
LandColor = Color.fromString "lightgrey"
)
)
|> Chart.withSize (800.,800.)
Expand Down
2 changes: 1 addition & 1 deletion docs/6_1_mapbox-plots.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ let flights =
Chart.LineMapbox(
[startCoords; endCoords],
Opacity = opacityVals.[i],
Color = "red"
Color = Color.fromString "red"
)
)
|> Chart.combine
Expand Down
6 changes: 3 additions & 3 deletions docs/7_1_funnel.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ open Plotly.NET
open Plotly.NET.TraceObjects

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

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

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

(*** condition: ipynb ***)
Expand Down
2 changes: 1 addition & 1 deletion docs/7_2_funnel_area.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ to visualizing funnel data.

open Plotly.NET

let line = Line.init (Color="purple", Width=3.)
let line = Line.init (Color=Color.fromString "purple", Width=3.)

let funnelArea =
Chart.FunnelArea(Values=values, Text=text, Line=line)
Expand Down
2 changes: 1 addition & 1 deletion docs/8_0_polar_line-scatter-plots.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ You can for example change the line style using `Chart.withLineStyle`

let linePolar =
Chart.LinePolar(radial,theta)
|> Chart.withLineStyle(Color="purple",Dash=StyleParam.DrawingStyle.DashDot)
|> Chart.withLineStyle(Color=Color.fromString "purple",Dash=StyleParam.DrawingStyle.DashDot)

(*** condition: ipynb ***)
#if IPYNB
Expand Down
4 changes: 2 additions & 2 deletions docs/8_2_styling_polar_layouts.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ let styledPolar2 =
styledPolar
|> Chart.withAngularAxis(
AngularAxis.init(
Color="darkblue"
Color=Color.fromString "darkblue"
)
)
|> Chart.withRadialAxis(
RadialAxis.init(
Title = Title.init("Hi, i am the radial axis"),
Color="darkblue",
Color=Color.fromString "darkblue",
SeparateThousands = true
)
)
Expand Down
2 changes: 1 addition & 1 deletion docs/9_0_parallel-categories.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let dims =
let parcats =
Chart.ParallelCategories(
dims,
Color=[0.;1.;0.;1.;0.;0.;0.],
Color = Color.fromColorScaleValues [0.;1.;0.;1.;0.;0.;0.],
Colorscale = StyleParam.Colorscale.Blackbody
)

Expand Down
4 changes: 2 additions & 2 deletions docs/9_1_parallel-coords.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ the position of the vertex on the i-th axis corresponds to the i-th coordinate o
*)

let parcoords1 =
Chart.ParallelCoord(data,Color="blue")
Chart.ParallelCoord(data,Color=Color.fromString "blue")

(*** condition: ipynb ***)
#if IPYNB
Expand Down Expand Up @@ -83,7 +83,7 @@ let parcoords =
let dyn = Trace("parcoords")

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

dyn
|> GenericChart.ofTraceObject
Expand Down
4 changes: 2 additions & 2 deletions src/Plotly.NET/ChartAPI/Chart2D.fs
Original file line number Diff line number Diff line change
Expand Up @@ -602,15 +602,15 @@ module Chart2D =
Trace2DStyle.Scatter(X = x,Y = lower, Mode=StyleParam.Mode.Lines, ?FillColor=RangeColor) )
|> TraceStyle.TraceInfo(?Name = Some lowerName, Showlegend=false)
|> TraceStyle.Line(Width=0.)
|> TraceStyle.Marker(Color=if RangeColor.IsSome then RangeColor.Value else "rgba(0,0,0,0.5)")
|> TraceStyle.Marker(Color=if RangeColor.IsSome then RangeColor.Value else (Plotly.NET.Color.fromString "rgba(0,0,0,0.5)"))
|> TraceStyle.TextLabel(?Text=LowerLabels,?Textposition=TextPosition,?Textfont=TextFont)

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

GenericChart.MultiChart ([lower;upper;trace],Layout(),Config(), DisplayOptions())
Expand Down
48 changes: 24 additions & 24 deletions src/Plotly.NET/ChartAPI/ChartDomain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ module ChartDomain =
[<Optional;DefaultParameterValue(null)>] ?Labels:seq<'IConvertible>,
[<Optional;DefaultParameterValue(null)>] ?Name,
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
[<Optional;DefaultParameterValue(null)>] ?Colors,
[<Optional;DefaultParameterValue(null)>] ?Color,
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
[<Optional;DefaultParameterValue(null)>] ?TextFont,
[<Optional;DefaultParameterValue(null)>] ?Hoverinfo,
[<Optional;DefaultParameterValue(null)>] ?Textinfo,
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
TraceDomain.initPie (TraceDomainStyle.Pie(Values=values,?Labels=Labels,?Textinfo=Textinfo))
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity,?Hoverinfo=Hoverinfo)
|> TraceStyle.Marker(?Colors=Colors)
|> TraceStyle.Marker(?Color=Color)
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
|> GenericChart.ofTraceObject

Expand All @@ -38,22 +38,22 @@ module ChartDomain =
static member Pie(data:seq<#IConvertible*#IConvertible>,
[<Optional;DefaultParameterValue(null)>] ?Name,
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
[<Optional;DefaultParameterValue(null)>] ?Colors,
[<Optional;DefaultParameterValue(null)>] ?Color,
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
[<Optional;DefaultParameterValue(null)>] ?TextFont,
[<Optional;DefaultParameterValue(null)>] ?Hoverinfo,
[<Optional;DefaultParameterValue(null)>] ?Textinfo,
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
let values,labels = Seq.unzip data
Chart.Pie(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Colors=Colors,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)
Chart.Pie(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Color=Color,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)


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

Expand All @@ -72,15 +72,15 @@ module ChartDomain =
static member Doughnut(data:seq<#IConvertible*#IConvertible>,
[<Optional;DefaultParameterValue(null)>] ?Name,
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
[<Optional;DefaultParameterValue(null)>] ?Colors,
[<Optional;DefaultParameterValue(null)>] ?Color,
[<Optional;DefaultParameterValue(null)>] ?Hole,
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
[<Optional;DefaultParameterValue(null)>] ?TextFont,
[<Optional;DefaultParameterValue(null)>] ?Hoverinfo,
[<Optional;DefaultParameterValue(null)>] ?Textinfo,
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
let values,labels = Seq.unzip data
Chart.Doughnut(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Colors=Colors,?Hole=Hole,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)
Chart.Doughnut(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Color=Color,?Hole=Hole,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)



Expand Down Expand Up @@ -194,12 +194,12 @@ module ChartDomain =
///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.
static member Sunburst(labels,parents,
[<Optional;DefaultParameterValue(null)>]?Ids,
[<Optional;DefaultParameterValue(null)>]?Values ,
[<Optional;DefaultParameterValue(null)>]?Text ,
[<Optional;DefaultParameterValue(null)>]?Branchvalues ,
[<Optional;DefaultParameterValue(null)>]?Level ,
[<Optional;DefaultParameterValue(null)>]?Maxdepth ,
[<Optional;DefaultParameterValue(null)>]?Colors: seq<string>,
[<Optional;DefaultParameterValue(null)>]?Values,
[<Optional;DefaultParameterValue(null)>]?Text,
[<Optional;DefaultParameterValue(null)>]?Branchvalues,
[<Optional;DefaultParameterValue(null)>]?Level,
[<Optional;DefaultParameterValue(null)>]?Maxdepth,
[<Optional;DefaultParameterValue(null)>]?Color,
[<Optional;DefaultParameterValue(null)>]?ColorBar:ColorBar
) =
TraceDomain.initSunburst(
Expand All @@ -214,7 +214,7 @@ module ChartDomain =
?Maxdepth = Maxdepth
)
)
|> TraceStyle.Marker(?Colors=Colors,?ColorBar=ColorBar)
|> TraceStyle.Marker(?Color=Color,?ColorBar=ColorBar)
|> GenericChart.ofTraceObject


Expand Down Expand Up @@ -243,14 +243,14 @@ module ChartDomain =
///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.
static member Treemap(labels,parents,
[<Optional;DefaultParameterValue(null)>]?Ids,
[<Optional;DefaultParameterValue(null)>]?Values ,
[<Optional;DefaultParameterValue(null)>]?Text ,
[<Optional;DefaultParameterValue(null)>]?Branchvalues ,
[<Optional;DefaultParameterValue(null)>]?Tiling ,
[<Optional;DefaultParameterValue(null)>]?PathBar ,
[<Optional;DefaultParameterValue(null)>]?Level ,
[<Optional;DefaultParameterValue(null)>]?Maxdepth ,
[<Optional;DefaultParameterValue(null)>]?Colors: seq<string>,
[<Optional;DefaultParameterValue(null)>]?Values,
[<Optional;DefaultParameterValue(null)>]?Text,
[<Optional;DefaultParameterValue(null)>]?Branchvalues,
[<Optional;DefaultParameterValue(null)>]?Tiling,
[<Optional;DefaultParameterValue(null)>]?PathBar,
[<Optional;DefaultParameterValue(null)>]?Level,
[<Optional;DefaultParameterValue(null)>]?Maxdepth,
[<Optional;DefaultParameterValue(null)>]?Color,
[<Optional;DefaultParameterValue(null)>]?ColorBar:ColorBar
) =
TraceDomain.initTreemap(
Expand All @@ -267,7 +267,7 @@ module ChartDomain =
?Maxdepth = Maxdepth
)
)
|> TraceStyle.Marker(?Colors=Colors,?ColorBar=ColorBar)
|> TraceStyle.Marker(?Color=Color,?ColorBar=ColorBar)
|> GenericChart.ofTraceObject


Expand Down
Loading