Skip to content

Commit 3fd898e

Browse files
committed
finish Waterfall chart
1 parent e11b740 commit 3fd898e

File tree

5 files changed

+347
-105
lines changed

5 files changed

+347
-105
lines changed

src/Plotly.NET/ChartAPI/Chart2D.fs

Lines changed: 158 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,110 +1050,185 @@ module Chart2D =
10501050
|> GenericChart.mapLayout (Layout.style (FunnelMode = StyleParam.FunnelMode.Stack))
10511051

10521052
/// Creates a waterfall chart. Waterfall charts are special bar charts that help visualizing the cumulative effect of sequentially introduced positive or negative values
1053-
///
1054-
/// Parameters:
1055-
///
1056-
/// x : Sets the x coordinates.
1057-
///
1058-
/// y : Sets the y coordinates.
1059-
///
1060-
/// Base : Sets where the bar base is drawn (in position axis units).
1061-
///
1062-
/// Width : Sets the bar width (in position axis units).
1063-
///
1064-
/// Measure : An array containing types of values. By default the values are considered as 'relative'. However; it is possible to use 'total' to compute the sums. Also 'absolute' could be applied to reset the computed total or to declare an initial value where needed.
1065-
///
1066-
/// Orientation : Sets the orientation of the bars. With "v" ("h"), the value of the each bar spans along the vertical (horizontal).
1067-
///
1068-
/// Connector : Sets the styling of the connector lines
1069-
///
1070-
/// AlignmentGroup : Set several traces linked to the same position axis or matching axes to the same alignmentgroup. This controls whether bars compute their positional range dependently or independently.
1071-
///
1072-
/// OffsetGroup : Set several traces linked to the same position axis or matching axes to the same offsetgroup where bars of the same position coordinate will line up.
1073-
///
1074-
/// Offset : Shifts the position where the bar is drawn (in position axis units). In "group" barmode, traces that set "offset" will be excluded and drawn in "overlay" mode instead.
10751053
[<Extension>]
10761054
static member Waterfall
10771055
(
1078-
x : #IConvertible seq,
1079-
y : #IConvertible seq,
1080-
[<Optional;DefaultParameterValue(null)>]?Base : IConvertible ,
1081-
[<Optional;DefaultParameterValue(null)>]?Width : float ,
1082-
[<Optional;DefaultParameterValue(null)>]?Measure : StyleParam.WaterfallMeasure seq,
1083-
[<Optional;DefaultParameterValue(null)>]?Orientation : StyleParam.Orientation,
1084-
[<Optional;DefaultParameterValue(null)>]?Connector : WaterfallConnector ,
1085-
[<Optional;DefaultParameterValue(null)>]?AlignmentGroup : string,
1086-
[<Optional;DefaultParameterValue(null)>]?OffsetGroup : string,
1087-
[<Optional;DefaultParameterValue(null)>]?Offset,
1088-
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
1056+
x: seq<#IConvertible>,
1057+
y: seq<#IConvertible>,
1058+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
1059+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
1060+
[<Optional;DefaultParameterValue(null)>] ?IncreasingColor : Color,
1061+
[<Optional;DefaultParameterValue(null)>] ?Increasing : FinanceMarker,
1062+
[<Optional;DefaultParameterValue(null)>] ?DecreasingColor : Color,
1063+
[<Optional;DefaultParameterValue(null)>] ?Decreasing : FinanceMarker,
1064+
[<Optional;DefaultParameterValue(null)>] ?TotalsColor : Color,
1065+
[<Optional;DefaultParameterValue(null)>] ?Totals : FinanceMarker,
1066+
[<Optional;DefaultParameterValue(null)>] ?Base : float,
1067+
[<Optional;DefaultParameterValue(null)>] ?Width : float,
1068+
[<Optional;DefaultParameterValue(null)>] ?MultiWidth : seq<float>,
1069+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
1070+
[<Optional;DefaultParameterValue(null)>] ?Text : #IConvertible,
1071+
[<Optional;DefaultParameterValue(null)>] ?MultiText : seq<#IConvertible>,
1072+
[<Optional;DefaultParameterValue(null)>] ?TextPosition : StyleParam.TextPosition,
1073+
[<Optional;DefaultParameterValue(null)>] ?MultiTextPosition : seq<StyleParam.TextPosition>,
1074+
[<Optional;DefaultParameterValue(null)>] ?TextFont : Font,
1075+
[<Optional;DefaultParameterValue(null)>] ?Marker : Marker,
1076+
[<Optional;DefaultParameterValue(null)>] ?Connector : WaterfallConnector,
1077+
[<Optional;DefaultParameterValue(null)>] ?Measure : StyleParam.WaterfallMeasure seq,
1078+
[<Optional;DefaultParameterValue(null)>] ?AlignmentGroup : string,
1079+
[<Optional;DefaultParameterValue(null)>] ?OffsetGroup : string,
1080+
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
10891081
) =
10901082

10911083
let useDefaults = defaultArg UseDefaults true
10921084

1085+
let increasing = Increasing |> Option.defaultValue (FinanceMarker.init()) |> FinanceMarker.style(?MarkerColor = IncreasingColor)
1086+
let decreasing = Decreasing |> Option.defaultValue (FinanceMarker.init()) |> FinanceMarker.style(?MarkerColor = DecreasingColor)
1087+
let totals = Totals |> Option.defaultValue (FinanceMarker.init()) |> FinanceMarker.style(?MarkerColor = TotalsColor)
1088+
10931089
Trace2D.initWaterfall(
1094-
Trace2DStyle.Waterfall(x,y,
1095-
?Base = Base ,
1096-
?Width = Width ,
1097-
?Measure = Measure ,
1098-
?Orientation = Orientation ,
1099-
?Connector = Connector ,
1100-
?AlignmentGroup = AlignmentGroup,
1101-
?OffsetGroup = OffsetGroup ,
1102-
?Offset = Offset
1090+
Trace2DStyle.Waterfall(
1091+
X = x,
1092+
Y = y,
1093+
?Name = Name ,
1094+
?ShowLegend = ShowLegend ,
1095+
Increasing = increasing ,
1096+
Decreasing = decreasing ,
1097+
Totals = totals ,
1098+
?Base = Base ,
1099+
?Width = Width ,
1100+
?MultiWidth = MultiWidth ,
1101+
?Opacity = Opacity ,
1102+
?Text = Text ,
1103+
?MultiText = MultiText ,
1104+
?TextPosition = TextPosition ,
1105+
?MultiTextPosition = MultiTextPosition ,
1106+
?TextFont = TextFont ,
1107+
?Connector = Connector ,
1108+
?Measure = Measure ,
1109+
?AlignmentGroup = AlignmentGroup ,
1110+
?OffsetGroup = OffsetGroup
11031111
)
11041112
)
11051113
|> GenericChart.ofTraceObject useDefaults
11061114

11071115

11081116
/// Creates a waterfall chart. Waterfall charts are special bar charts that help visualizing the cumulative effect of sequentially introduced positive or negative values
1109-
///
1110-
/// Parameters:
1111-
///
1112-
/// xyMeasures : triple sequence containing x coordinates, y coordinates, and the type of measure used for each bar.
1113-
///
1114-
/// Base : Sets where the bar base is drawn (in position axis units).
1115-
///
1116-
/// Width : Sets the bar width (in position axis units).
1117-
///
1118-
/// Orientation : Sets the orientation of the bars. With "v" ("h"), the value of the each bar spans along the vertical (horizontal).
1119-
///
1120-
/// Connector : Sets the styling of the connector lines
1121-
///
1122-
/// AlignmentGroup : Set several traces linked to the same position axis or matching axes to the same alignmentgroup. This controls whether bars compute their positional range dependently or independently.
1123-
///
1124-
/// OffsetGroup : Set several traces linked to the same position axis or matching axes to the same offsetgroup where bars of the same position coordinate will line up.
1125-
///
1126-
/// Offset : Shifts the position where the bar is drawn (in position axis units). In "group" barmode, traces that set "offset" will be excluded and drawn in "overlay" mode instead.
11271117
[<Extension>]
11281118
static member Waterfall
11291119
(
1130-
xyMeasure: (#IConvertible*#IConvertible*StyleParam.WaterfallMeasure) seq,
1131-
[<Optional;DefaultParameterValue(null)>]?Base : IConvertible ,
1132-
[<Optional;DefaultParameterValue(null)>]?Width : float ,
1133-
[<Optional;DefaultParameterValue(null)>]?Orientation : StyleParam.Orientation,
1134-
[<Optional;DefaultParameterValue(null)>]?Connector : WaterfallConnector ,
1135-
[<Optional;DefaultParameterValue(null)>]?AlignmentGroup : string,
1136-
[<Optional;DefaultParameterValue(null)>]?OffsetGroup : string,
1137-
[<Optional;DefaultParameterValue(null)>]?Offset,
1138-
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
1120+
xy: seq<#IConvertible*#IConvertible>,
1121+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
1122+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
1123+
[<Optional;DefaultParameterValue(null)>] ?IncreasingColor : Color,
1124+
[<Optional;DefaultParameterValue(null)>] ?Increasing : FinanceMarker,
1125+
[<Optional;DefaultParameterValue(null)>] ?DecreasingColor : Color,
1126+
[<Optional;DefaultParameterValue(null)>] ?Decreasing : FinanceMarker,
1127+
[<Optional;DefaultParameterValue(null)>] ?TotalsColor : Color,
1128+
[<Optional;DefaultParameterValue(null)>] ?Totals : FinanceMarker,
1129+
[<Optional;DefaultParameterValue(null)>] ?Base : float,
1130+
[<Optional;DefaultParameterValue(null)>] ?Width : float,
1131+
[<Optional;DefaultParameterValue(null)>] ?MultiWidth : seq<float>,
1132+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
1133+
[<Optional;DefaultParameterValue(null)>] ?Text : #IConvertible,
1134+
[<Optional;DefaultParameterValue(null)>] ?MultiText : seq<#IConvertible>,
1135+
[<Optional;DefaultParameterValue(null)>] ?TextPosition : StyleParam.TextPosition,
1136+
[<Optional;DefaultParameterValue(null)>] ?MultiTextPosition : seq<StyleParam.TextPosition>,
1137+
[<Optional;DefaultParameterValue(null)>] ?TextFont : Font,
1138+
[<Optional;DefaultParameterValue(null)>] ?Marker : Marker,
1139+
[<Optional;DefaultParameterValue(null)>] ?Connector : WaterfallConnector,
1140+
[<Optional;DefaultParameterValue(null)>] ?Measure : StyleParam.WaterfallMeasure seq,
1141+
[<Optional;DefaultParameterValue(null)>] ?AlignmentGroup : string,
1142+
[<Optional;DefaultParameterValue(null)>] ?OffsetGroup : string,
1143+
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
11391144
) =
11401145

1141-
let useDefaults = defaultArg UseDefaults true
1146+
let x,y = Seq.unzip xy
11421147

1143-
let x,y,measure = Seq.unzip3 xyMeasure
1144-
Trace2D.initWaterfall(
1145-
Trace2DStyle.Waterfall(x,y,
1146-
?Base = Base ,
1147-
?Width = Width ,
1148-
?Measure = Some measure ,
1149-
?Orientation = Orientation ,
1150-
?Connector = Connector ,
1151-
?AlignmentGroup = AlignmentGroup,
1152-
?OffsetGroup = OffsetGroup ,
1153-
?Offset = Offset
1154-
)
1148+
Chart.Waterfall(
1149+
x,y,
1150+
?Name = Name ,
1151+
?ShowLegend = ShowLegend ,
1152+
?IncreasingColor = IncreasingColor ,
1153+
?Increasing = Increasing ,
1154+
?DecreasingColor = DecreasingColor ,
1155+
?Decreasing = Decreasing ,
1156+
?TotalsColor = TotalsColor ,
1157+
?Totals = Totals ,
1158+
?Base = Base ,
1159+
?Width = Width ,
1160+
?MultiWidth = MultiWidth ,
1161+
?Opacity = Opacity ,
1162+
?Text = Text ,
1163+
?MultiText = MultiText ,
1164+
?TextPosition = TextPosition ,
1165+
?MultiTextPosition= MultiTextPosition,
1166+
?TextFont = TextFont ,
1167+
?Marker = Marker ,
1168+
?Connector = Connector ,
1169+
?Measure = Measure ,
1170+
?AlignmentGroup = AlignmentGroup ,
1171+
?OffsetGroup = OffsetGroup ,
1172+
?UseDefaults = UseDefaults
1173+
)
1174+
1175+
/// Creates a waterfall chart. Waterfall charts are special bar charts that help visualizing the cumulative effect of sequentially introduced positive or negative values
1176+
[<Extension>]
1177+
static member Waterfall
1178+
(
1179+
xymeasures: seq<#IConvertible*#IConvertible*StyleParam.WaterfallMeasure>,
1180+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
1181+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
1182+
[<Optional;DefaultParameterValue(null)>] ?IncreasingColor : Color,
1183+
[<Optional;DefaultParameterValue(null)>] ?Increasing : FinanceMarker,
1184+
[<Optional;DefaultParameterValue(null)>] ?DecreasingColor : Color,
1185+
[<Optional;DefaultParameterValue(null)>] ?Decreasing : FinanceMarker,
1186+
[<Optional;DefaultParameterValue(null)>] ?TotalsColor : Color,
1187+
[<Optional;DefaultParameterValue(null)>] ?Totals : FinanceMarker,
1188+
[<Optional;DefaultParameterValue(null)>] ?Base : float,
1189+
[<Optional;DefaultParameterValue(null)>] ?Width : float,
1190+
[<Optional;DefaultParameterValue(null)>] ?MultiWidth : seq<float>,
1191+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
1192+
[<Optional;DefaultParameterValue(null)>] ?Text : #IConvertible,
1193+
[<Optional;DefaultParameterValue(null)>] ?MultiText : seq<#IConvertible>,
1194+
[<Optional;DefaultParameterValue(null)>] ?TextPosition : StyleParam.TextPosition,
1195+
[<Optional;DefaultParameterValue(null)>] ?MultiTextPosition : seq<StyleParam.TextPosition>,
1196+
[<Optional;DefaultParameterValue(null)>] ?TextFont : Font,
1197+
[<Optional;DefaultParameterValue(null)>] ?Marker : Marker,
1198+
[<Optional;DefaultParameterValue(null)>] ?Connector : WaterfallConnector,
1199+
[<Optional;DefaultParameterValue(null)>] ?AlignmentGroup : string,
1200+
[<Optional;DefaultParameterValue(null)>] ?OffsetGroup : string,
1201+
[<Optional;DefaultParameterValue(true)>] ?UseDefaults : bool
1202+
) =
1203+
1204+
let x,y,measure = Seq.unzip3 xymeasures
1205+
1206+
Chart.Waterfall(
1207+
x,y,
1208+
?Name = Name ,
1209+
?ShowLegend = ShowLegend ,
1210+
?IncreasingColor = IncreasingColor ,
1211+
?Increasing = Increasing ,
1212+
?DecreasingColor = DecreasingColor ,
1213+
?Decreasing = Decreasing ,
1214+
?TotalsColor = TotalsColor ,
1215+
?Totals = Totals ,
1216+
?Base = Base ,
1217+
?Width = Width ,
1218+
?MultiWidth = MultiWidth ,
1219+
?Opacity = Opacity ,
1220+
?Text = Text ,
1221+
?MultiText = MultiText ,
1222+
?TextPosition = TextPosition ,
1223+
?MultiTextPosition= MultiTextPosition,
1224+
?TextFont = TextFont ,
1225+
?Marker = Marker ,
1226+
?Connector = Connector ,
1227+
Measure = measure ,
1228+
?AlignmentGroup = AlignmentGroup ,
1229+
?OffsetGroup = OffsetGroup ,
1230+
?UseDefaults = UseDefaults
11551231
)
1156-
|> GenericChart.ofTraceObject useDefaults
11571232

11581233
/// Illustrates comparisons among individual items
11591234
[<Extension>]

src/Plotly.NET/Playground.fsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#load "Table.fs"
102102
#load "Indicator.fs"
103103
#load "Icicle.fs"
104+
#load "FinanceMarker.fs"
104105

105106
#I "Traces"
106107

@@ -170,6 +171,20 @@ open FSharpAux
170171
open System
171172
open System.IO
172173

174+
Chart.Waterfall(
175+
x = ["Sales"; "Consulting"; "Net revenue"; "Purchases"; "Other expenses"; "Profit before tax"],
176+
y = [60; 80; 0; -40; -20; 0],
177+
Measure = [
178+
StyleParam.WaterfallMeasure.Relative
179+
StyleParam.WaterfallMeasure.Relative
180+
StyleParam.WaterfallMeasure.Total
181+
StyleParam.WaterfallMeasure.Relative
182+
StyleParam.WaterfallMeasure.Relative
183+
StyleParam.WaterfallMeasure.Total
184+
]
185+
)
186+
|> Chart.show
187+
173188
Chart.Line([1,2; 3,4])
174189
|> Chart.show
175190

src/Plotly.NET/Plotly.NET.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<Compile Include="Traces\ObjectAbstractions\Table.fs" />
107107
<Compile Include="Traces\ObjectAbstractions\Indicator.fs" />
108108
<Compile Include="Traces\ObjectAbstractions\Icicle.fs" />
109+
<Compile Include="Traces\ObjectAbstractions\FinanceMarker.fs" />
109110
<Compile Include="Traces\Trace.fs" />
110111
<Compile Include="Traces\Trace2D.fs" />
111112
<Compile Include="Traces\Trace3D.fs" />

0 commit comments

Comments
 (0)