]> git.scottworley.com Git - tablify/blobdiff - src/lib.rs
Refactor: Collect to Vec and join(" ")
[tablify] / src / lib.rs
index 2e9bfcc72adc364faf9bab51051b9988333cd302..e636bb23a1596b3cdecfaad5228ff3323f6de5a1 100644 (file)
@@ -9,20 +9,18 @@ const HEADER: &str = "<!DOCTYPE html>
   <meta charset=\"utf-8\">
   <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
   <style>
   <meta charset=\"utf-8\">
   <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
   <style>
+    td { text-align: center; }
     /* h/t https://wabain.github.io/2019/10/13/css-rotated-table-header.html */
     th, td { white-space: nowrap; }
     th { text-align: left; font-weight: normal; }
     table { border-collapse: collapse }
     /* h/t https://wabain.github.io/2019/10/13/css-rotated-table-header.html */
     th, td { white-space: nowrap; }
     th { text-align: left; font-weight: normal; }
     table { border-collapse: collapse }
-    tr.key > th { height: 8em; vertical-align: bottom; line-height: 1 }
+    tr.key > th { height: 10em; vertical-align: bottom; line-height: 1 }
     tr.key > th > div { width: 1em; }
     tr.key > th > div > div { width: 5em; transform-origin: bottom left; transform: translateX(1em) rotate(-65deg) }
     td { border: thin solid gray; }
     tr.key > th > div { width: 1em; }
     tr.key > th > div > div { width: 5em; transform-origin: bottom left; transform: translateX(1em) rotate(-65deg) }
     td { border: thin solid gray; }
-    td.numeric { text-align: right; }
     td.yes { border: thin solid gray; background-color: #ddd; }
     td.yes { border: thin solid gray; background-color: #ddd; }
-    td.spacer { border: none; }
     /* h/t https://stackoverflow.com/questions/5687035/css-bolding-some-text-without-changing-its-containers-size/46452396#46452396 */
     .highlight { text-shadow: -0.06ex 0 black, 0.06ex 0 black; }
     /* h/t https://stackoverflow.com/questions/5687035/css-bolding-some-text-without-changing-its-containers-size/46452396#46452396 */
     .highlight { text-shadow: -0.06ex 0 black, 0.06ex 0 black; }
-    img { height: 1.2em; }
   </style>
   <script>
     function highlight(id)       { const e = document.getElementById(id); if (e) { e.classList.add(   \"highlight\"); } }
   </style>
   <script>
     function highlight(id)       { const e = document.getElementById(id); if (e) { e.classList.add(   \"highlight\"); } }
@@ -140,7 +138,7 @@ fn column_counts(rows: &[RowInput]) -> Vec<(usize, String)> {
         .into_iter()
         .map(|(col, n)| (n, col))
         .collect();
         .into_iter()
         .map(|(col, n)| (n, col))
         .collect();
-    counts.sort();
+    counts.sort_unstable_by(|(an, acol), (bn, bcol)| bn.cmp(an).then(acol.cmp(bcol)));
     counts
 }
 fn column_order(rows: &[RowInput]) -> Vec<String> {
     counts
 }
 fn column_order(rows: &[RowInput]) -> Vec<String> {
@@ -152,8 +150,8 @@ fn column_order(rows: &[RowInput]) -> Vec<String> {
 
 fn render_instance(entry: &Entry) -> String {
     match &entry.instance {
 
 fn render_instance(entry: &Entry) -> String {
     match &entry.instance {
-        None => String::from("✓ "),
-        Some(instance) => String::from(instance) + " ",
+        None => String::from("✓"),
+        Some(instance) => String::from(instance),
     }
 }
 
     }
 }
 
@@ -171,9 +169,10 @@ fn render_cell(col: &str, row: &RowInput) -> String {
         entries
             .iter()
             .map(|i| render_instance(i))
         entries
             .iter()
             .map(|i| render_instance(i))
-            .collect::<String>()
+            .collect::<Vec<_>>()
+            .join(" ")
     };
     };
-    format!("<td class=\"{class}\" onmouseover=\"h2('{row_label}','{col}')\" onmouseout=\"ch2('{row_label}','{col}')\">{}</td>", contents.trim())
+    format!("<td class=\"{class}\" onmouseover=\"h2('{row_label}','{col}')\" onmouseout=\"ch2('{row_label}','{col}')\">{contents}</td>")
 }
 
 fn render_row(columns: &[String], row: &RowInput) -> String {
 }
 
 fn render_row(columns: &[String], row: &RowInput) -> String {
@@ -356,7 +355,7 @@ mod tests {
                     .collect::<Result<Vec<_>, _>>()
                     .unwrap()
             ),
                     .collect::<Result<Vec<_>, _>>()
                     .unwrap()
             ),
-            vec![(1, String::from("bar")), (2, String::from("baz"))]
+            vec![(2, String::from("baz")), (1, String::from("bar"))]
         );
         assert_eq!(
             column_counts(
         );
         assert_eq!(
             column_counts(
@@ -364,7 +363,7 @@ mod tests {
                     .collect::<Result<Vec<_>, _>>()
                     .unwrap()
             ),
                     .collect::<Result<Vec<_>, _>>()
                     .unwrap()
             ),
-            vec![(1, String::from("bar")), (2, String::from("baz"))]
+            vec![(2, String::from("baz")), (1, String::from("bar"))]
         );
         assert_eq!(
             column_counts(
         );
         assert_eq!(
             column_counts(
@@ -372,7 +371,7 @@ mod tests {
                     .collect::<Result<Vec<_>, _>>()
                     .unwrap()
             ),
                     .collect::<Result<Vec<_>, _>>()
                     .unwrap()
             ),
-            vec![(1, String::from("bar")), (2, String::from("baz"))]
+            vec![(2, String::from("baz")), (1, String::from("bar"))]
         );
     }
 
         );
     }