Skip to content

Commit 94e0834

Browse files
authored
DEV: Sentiment follow-up updates (#1172)
### ✨ What's new? - [X] show sentiment counts by color on doughnut without needing to hover - [X] minor UI padding adjustments - [X] hide filters that are not allowed to be adjusted in selected chart view - [X] fix z-index issues with drill-down filters
1 parent 1ce25c5 commit 94e0834

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

assets/javascripts/discourse/components/admin-report-sentiment-analysis.gjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { and } from "truth-helpers";
1010
import DButton from "discourse/components/d-button";
1111
import HorizontalOverflowNav from "discourse/components/horizontal-overflow-nav";
1212
import PostList from "discourse/components/post-list";
13+
import bodyClass from "discourse/helpers/body-class";
1314
import dIcon from "discourse/helpers/d-icon";
1415
import replaceEmoji from "discourse/helpers/replace-emoji";
1516
import { ajax } from "discourse/lib/ajax";
@@ -318,6 +319,7 @@ export default class AdminReportSentimentAnalysis extends Component {
318319
{{/unless}}
319320

320321
{{#if (and this.selectedChart this.showingSelectedChart)}}
322+
{{bodyClass "showing-sentiment-analysis-chart"}}
321323
<div class="admin-report-sentiment-analysis__selected-chart">
322324
<div class="admin-report-sentiment-analysis__selected-chart-actions">
323325
<DButton

assets/javascripts/discourse/components/doughnut-chart.gjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,40 @@ export default class DoughnutChart extends Component {
6262
ctx.save();
6363
},
6464
},
65+
{
66+
// Custom plugin to draw labels inside the doughnut chart
67+
id: "doughnutLabels",
68+
afterDraw(chart) {
69+
const ctx = chart.ctx;
70+
const dataset = chart.data.datasets[0];
71+
const meta = chart.getDatasetMeta(0);
72+
const cssFontSize =
73+
getComputedStyle(document.documentElement).getPropertyValue(
74+
"--font-down-2"
75+
) || "1.3em";
76+
const cssFontFamily =
77+
getComputedStyle(document.documentElement).getPropertyValue(
78+
"--font-family"
79+
) || "sans-serif";
80+
81+
ctx.font = `${cssFontSize.trim()} ${cssFontFamily.trim()}`;
82+
ctx.fillStyle = "#fafafa";
83+
ctx.textAlign = "center";
84+
ctx.textBaseline = "middle";
85+
86+
meta.data.forEach((element, index) => {
87+
const { x, y } = element.tooltipPosition();
88+
const value = dataset.data[index];
89+
const nonZeroCount = dataset.data.filter((v) => v > 0).length;
90+
91+
if (value === 0 || nonZeroCount === 1) {
92+
return;
93+
}
94+
95+
ctx.fillText(value, x, y);
96+
});
97+
},
98+
},
6599
],
66100
};
67101
}

assets/stylesheets/modules/sentiment/common/dashboard.scss

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
display: none;
4545
}
4646

47+
.control:last-child {
48+
align-self: flex-end;
49+
50+
input {
51+
}
52+
}
53+
4754
.control:has(.export-csv-btn) {
4855
display: none;
4956
}
@@ -63,10 +70,12 @@
6370
@include report-container-box();
6471
flex: 2;
6572
display: flex;
66-
gap: 1rem;
67-
justify-content: space-around;
73+
gap: 2rem 1rem;
74+
justify-content: space-evenly;
6875
align-items: center;
6976
flex-flow: row wrap;
77+
padding-inline: 0;
78+
padding-block: 1.5rem;
7079

7180
.admin-report-doughnut {
7281
padding: 0.25rem;
@@ -87,7 +96,7 @@
8796

8897
&:hover {
8998
box-shadow: var(--shadow-card);
90-
transform: translateY(-1rem);
99+
transform: translateY(-0.5rem);
91100
cursor: pointer;
92101
}
93102
}
@@ -219,6 +228,20 @@
219228
position: sticky;
220229
top: 0;
221230
padding-top: 1rem;
222-
z-index: z("header");
231+
z-index: z("timeline");
232+
}
233+
}
234+
235+
.showing-sentiment-analysis-chart
236+
.admin-report.sentiment-analysis
237+
.body
238+
.filters {
239+
// Hide elements 2 - 6 when showing selected chart
240+
// as they're not supported being changed in this view
241+
.control:first-of-type {
242+
flex: unset;
243+
}
244+
.control:nth-of-type(n + 2):nth-of-type(-n + 6) {
245+
display: none;
223246
}
224247
}

0 commit comments

Comments
 (0)