@@ -13,7 +13,7 @@ This example shows how to create tables in F#.
13
13
open FSharp.Plotly
14
14
open FSharp.Plotly .StyleParam
15
15
16
- let header = [ " RowIndex" ; " A" ; " simple" ; " table" ]
16
+ let header = [ " <b> RowIndex</b> " ; " A" ; " simple" ; " table" ]
17
17
let rows =
18
18
[
19
19
[ " 0" ; " I" ; " am" ; " a" ]
@@ -40,16 +40,19 @@ let table2 =
40
40
rows,
41
41
//sets global header alignment
42
42
AlignHeader= [ HorizontalAlign.Center],
43
- //sets alignment for each column separately (The last alignment is applied to all potential following columns)
43
+ //sets alignment for each column separately
44
+ //(The last alignment is applied to all potential following columns)
44
45
AlignCells= [ HorizontalAlign.Left; HorizontalAlign.Center; HorizontalAlign.Right],
45
46
//sets global header color
46
47
ColorHeader= " #45546a" ,
47
- //sets single header color to each header column
48
+ //sets specific header color to each header column
48
49
//ColorHeader=["#45546a";"#deebf7";"#45546a";"#deebf7"],
49
50
//sets global cell color
50
51
//ColorRows="#deebf7",
51
- //sets single header color to each header column
52
+ //sets cell column colors
52
53
ColorCells=[ " #deebf7" ; " lightgrey" ; " #deebf7" ; " lightgrey" ],
54
+ //sets cell row colors
55
+ //ColorCells=[["#deebf7";"lightgrey"]],
53
56
//sets font of header
54
57
FontHeader= Font.init( FontFamily.Courier_ New, Size= 12 , Color= " white" ),
55
58
//sets the height of the header
@@ -67,10 +70,114 @@ table2 |> Chart.Show
67
70
(*** include-value:table2 ***)
68
71
69
72
(**
70
- FastA Representation
73
+ Value dependent cell coloring:
74
+ *)
75
+
76
+ let header2 = [ " Identifier" ; " T0" ; " T1" ; " T2" ; " T3" ]
77
+ let rowvalues =
78
+ [
79
+ [ 10001. ; 0.2 ; 2.0 ; 4.0 ; 5.0 ]
80
+ [ 10002. ; 2.1 ; 2.0 ; 1.8 ; 2.1 ]
81
+ [ 10003. ; 4.5 ; 3.0 ; 2.0 ; 2.5 ]
82
+ [ 10004. ; 0.0 ; 0.1 ; 0.3 ; 0.2 ]
83
+ [ 10005. ; 1.0 ; 1.6 ; 1.8 ; 2.2 ]
84
+ [ 10006. ; 1.0 ; 0.8 ; 1.5 ; 0.7 ]
85
+ [ 10007. ; 2.0 ; 2.0 ; 2.1 ; 1.9 ]
86
+ ]
87
+ |> Seq.sortBy ( fun x -> x.[ 1 ])
88
+
89
+ //map color from value to hex representation
90
+ let mapColor min max value =
91
+ let percentage = ( value - min) / ( max - min)
92
+ Colors.fromRgb 255 ( 255 - ( int ( 255. * percentage))) ( int ( 255. * percentage))
93
+ |> Colors.toWebColor
94
+
95
+ //assign a color to every cell seperately. Matrix must be transposed for correct orientation
96
+ let cellcolor =
97
+ rowvalues
98
+ |> Seq.map ( fun row ->
99
+ row
100
+ |> Seq.mapi ( fun index value ->
101
+ if index = 0 then " white"
102
+ else mapColor 0. 5. value
103
+ )
104
+ )
105
+ |> Seq.transpose
106
+
107
+ let table3 = Chart.Table( header2, rowvalues, ColorCells= cellcolor)
108
+
109
+ (***do-not-eval***)
110
+ table3 |> Chart.Show
111
+
112
+
113
+ (*** include-value:table3 ***)
114
+
115
+
116
+ (**
117
+ Sequence representation
71
118
72
119
*)
73
120
121
+ let sequence =
122
+ [
123
+ " ATGAGACGTCGAGACTGATAGACGTCGATAGACGTCGATAGACCG"
124
+ " ATAGACTCGTGATAGACGTCGATAGACGTCGATAGAGTATAGACC"
125
+ " GTGATAGACGTCGAGAAGACGTCGATAGACGTCGATAGACGTCGA"
126
+ " TAGAGATAGACGTCGATAGACCGTATAGAAGACGTCGATAGATAG"
127
+ " ACGTCGATAGACCGTAGACGTCGATAGACGTCGATAGACCGT"
128
+ ]
129
+ |> String.concat " "
130
+
131
+ let elementsperrow = 60
132
+
133
+ let headers =
134
+ [ 0 .. elementsperrow]
135
+ |> Seq.map ( fun x ->
136
+ if x% 10 = 0 && x <> 0 then " |"
137
+ else " "
138
+ )
139
+
140
+ let cells =
141
+ sequence
142
+ |> Seq.chunkBySize elementsperrow
143
+ |> Seq.mapi ( fun i x -> Seq.append [ string ( i * elementsperrow)] ( Seq.map string x))
144
+
145
+ let cellcolors =
146
+ cells
147
+ |> Seq.map ( fun row ->
148
+ row
149
+ |> Seq.map ( fun nucleotid ->
150
+ match nucleotid with
151
+ //colors taken from DRuMS
152
+ //(http://biomodel.uah.es/en/model4/dna/atgc.htm)
153
+ | " A" -> " #5050FF"
154
+ | " T" -> " #E6E600"
155
+ | " G" -> " #00C000"
156
+ | " C" -> " #E00000"
157
+ | " U" -> " #B48100"
158
+ | _ -> " white"
159
+ )
160
+ )
161
+ |> Seq.transpose
162
+ |> Seq.map ( fun x -> Seq.append x ( seq [ " white" ]))
163
+
164
+ let font = Font.init( FontFamily.Consolas, Size= 14 )
165
+ let line = Line.init( 0 , " white" )
166
+ let chartwidth = 50. + 10. * float elementsperrow
167
+
168
+ let table4 =
169
+ Chart.Table(
170
+ headers, cells, LineCells= line, LineHeader= line, HeightCells= 20 ,
171
+ FontHeader= font, FontCells= font, ColumnWidth=[ 50 ; 10 ],
172
+ AlignCells=[ HorizontalAlign.Right; HorizontalAlign.Center], ColorCells= cellcolors)
173
+ |> Chart.withSize( chartwidth, nan)
174
+ |> Chart.withTitle " Sequence A"
175
+
176
+
177
+ (***do-not-eval***)
178
+ table4 |> Chart.Show
179
+
74
180
181
+ (*** include-value:table4 ***)
75
182
76
183
0 commit comments