From e2c5fc23f1d0757a0726c02de26fbbe2e4fa73d9 Mon Sep 17 00:00:00 2001 From: scuti Date: Thu, 28 Nov 2024 16:34:43 -0800 Subject: [PATCH] bar chart for polls - tweaked for long labels --- pleroma-comments.css | 106 +++++++++++++++++++++++++++++++++++++++++++ pleroma-comments.lua | 11 +++-- 2 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 pleroma-comments.css diff --git a/pleroma-comments.css b/pleroma-comments.css new file mode 100644 index 0000000..6184af8 --- /dev/null +++ b/pleroma-comments.css @@ -0,0 +1,106 @@ + +.pleroma-comment blockquote { + border-left: 3px solid red; + padding-left:1%; +} + +.pleroma-comment h3 > a { + text-decoration:none; +} + +.pleroma-comment > figure { + display:flex; + align-items:center; +} +.pleroma-comment > figure img { + height:5em; + margin-right: 1em; +} + +/* meta information about post */ +.pleroma-comment p, .pleroma-comment .chart { + margin-left: 5%; +} + +/* usernames can either be figcaption or the first paragraph in the element */ + +.pleroma-comment + p, .pleroma-comment figcaption { + font-weight:bold; +} +.pleroma-comment p > a, .pleroma-comment figcaption > a { + font-weight:normal; + text-decoration:none; +} + +.pleroma-comment .card { + border: 1px solid #ccc; + border-radius: 8px; + overflow: hidden; + width: 300px; /* Adjust as needed */ + margin: 1%; + margin-left:10%; +/* box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); */ +} +.pleroma-comment .card-title { + font-size: 1.5em; + margin: 3%; +} +.pleroma-comment .card-description { + font-size: 1em; + margin:5%; +} +.pleroma-comment .card-image { + width: 100%; + height: auto; +} +.pleroma-comment .card-link { + display: block; + text-align: center; + padding: 10px; + text-decoration: none; + border-radius: 5px; + margin: 10px; +} + +.pleroma-comment .chart { +/* border:1px solid red; */ + display: flex; + flex-direction: column; + width: 45%; + white-space:normal; + overflow:hidden; +} + +.pleroma-comment .bar-container { + display: flex; + align-items: center; + margin: 1% 0; +} + +.pleroma-comment .bar { + padding-top: 0.5em; + padding-bottom:0.5em; + padding-left:1em; + margin-right:1em; + white-space: nowrap; /* Prevent text wrapping for the bar width */ +} + +.pleroma-comment .bar-text { + word-wrap: break-word; /* Allow word wrap */ + overflow-wrap: break-word; + white-space: normal; /* Allow normal wrapping */ +} + +/* colors */ + +.pleroma-comment .bar { + background-color: #8da5aa; +} + +/*.pleroma-comment .card-link { + background-color: #36dcff; + color: white; +} +.pleroma-comment .card-link:hover { + background-color: #8da5aa; +}*/ diff --git a/pleroma-comments.lua b/pleroma-comments.lua index 14271d2..fcd105e 100644 --- a/pleroma-comments.lua +++ b/pleroma-comments.lua @@ -136,8 +136,13 @@ function write_comments(pleroma_posts, instance, show_avatars) end local bar_chart = {"
"} local bar_template = [[ -
- $label$ +
+
+ $pct$% +
+
+ $label$ +
]] local total_votes = math.floor(poll["votes_count"]) @@ -146,7 +151,7 @@ function write_comments(pleroma_posts, instance, show_avatars) local percentage = (v["votes_count"]/total_votes) * 100 local rounded = math.floor(0.5 + percentage) local vars = { - label = rounded .. "% " .. v["title"], + label = v["title"], pct = rounded } local bar = bar_template:gsub("%$(%w+)%$", vars)