toHtml method
A conversion of this data frame to an html table.
Implementation
String toHtml({
Iterable<String>? columns,
Map<String, int> fixedPlaces = const {},
}) {
columns = columns ?? [...numericColumns.keys, ...categoricColumns.keys];
if (columns.any((column) =>
!numericColumns.containsKey(column) &&
!categoricColumns.containsKey(column))) {
throw PackhorseError.badArgument("Bad column name in $columns.");
}
final table = toListOfMaps(),
row = (Iterable<String> cells) =>
" <tr><td>${cells.join("</td><td>")}</td></tr>",
sb = StringBuffer("\n")
..writeln('<div class="packhorse">\n<table>\n <thead>')
..writeln(" <tr><th>${columns.join("</th><th>")}</th></tr>")
..writeln(" </thead>\n <tbody>");
for (final r in table) {
sb.writeln(row(columns.map((key) => r[key]!
.replaceAll('"', "")
.replaceAll("<", "<")
.replaceAll(">", ">"))));
}
sb.writeln(" </tbody>\n</table>\n</div>");
return sb.toString();
}