Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
VEBER Philippe
codepi
Commits
fd4cf9de
Commit
fd4cf9de
authored
Dec 20, 2020
by
Philippe Veber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tk/Dataframe: slightly more flexible API for html rendering
parent
f3da8080
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
lib/tk/dataframe.ml
lib/tk/dataframe.ml
+7
-4
lib/tk/dataframe.mli
lib/tk/dataframe.mli
+4
-4
No files found.
lib/tk/dataframe.ml
View file @
fd4cf9de
...
...
@@ -140,12 +140,15 @@ let from_file ?(header = `Read_in_file) path =
let
cols
=
List
.
zip_exn
labels
cols
in
Ok
{
nrows
;
ncols
;
cols
}
let
to_html
?
(
cell_renderers
=
[]
)
d
=
type
html_formatter
=
int
->
string
->
Html_types
.
td_content
Tyxml
.
Html
.
elt
let
to_html
?
(
formatters
=
[]
)
d
=
let
open
Tyxml
.
Html
in
let
default_cell
s
=
txt
s
in
let
default_cell
_
s
=
txt
s
in
let
cols
=
List
.
map
d
.
cols
~
f
:
(
fun
(
label
,
col
)
->
let
cell_renderer
=
List
.
Assoc
.
find
cell_render
ers
~
equal
:
String
.
equal
label
List
.
Assoc
.
find
formatt
ers
~
equal
:
String
.
equal
label
|>
Option
.
value
~
default
:
default_cell
in
label
,
cell_renderer
,
col
...
...
@@ -167,7 +170,7 @@ let to_html ?(cell_renderers = []) d =
|
String_opts
t
->
Option
.
value
~
default
t
.
(
i
)
in
let
row
i
=
List
.
map
cols
~
f
:
(
fun
(
_
,
renderer
,
col
)
->
td
[
renderer
(
elem
col
i
)])
List
.
map
cols
~
f
:
(
fun
(
_
,
renderer
,
col
)
->
td
[
renderer
i
(
elem
col
i
)])
|>
tr
in
table
~
thead
(
List
.
init
(
nrows
d
)
~
f
:
row
)
lib/tk/dataframe.mli
View file @
fd4cf9de
...
...
@@ -24,10 +24,10 @@ val from_file :
string
->
(
t
,
[
>
`Msg
of
string
])
result
type
html_formatter
=
int
->
string
->
Html_types
.
td_content
Tyxml
.
Html
.
elt
val
to_html
:
?
cell_renderers
:
(
string
*
(
string
->
[
<
Html_types
.
td_content
>
`PCDATA
]
Tyxml
.
Html
.
elt
))
list
->
?
formatters
:
(
string
*
html_formatter
)
list
->
t
->
[
>
Html_types
.
table
]
Tyxml
.
Html
.
elt
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment