Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 7c4ccfe

Browse files
committed
DEV: Revert sizing and make header sticky
1 parent 1fd3f7e commit 7c4ccfe

File tree

3 files changed

+22
-65
lines changed

3 files changed

+22
-65
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ export default class AdminReportSentimentAnalysis extends Component {
310310
@data={{data.scores}}
311311
@totalScore={{data.total_score}}
312312
@doughnutTitle={{data.title}}
313+
@displayLegend={{true}}
313314
/>
314315
</div>
315316
{{/each}}
@@ -342,9 +343,7 @@ export default class AdminReportSentimentAnalysis extends Component {
342343
@data={{this.selectedChart.scores}}
343344
@totalScore={{this.selectedChart.total_score}}
344345
@doughnutTitle={{this.selectedChart.title}}
345-
@skipCanvasResize={{true}}
346346
@displayLegend={{true}}
347-
@radius={{100}}
348347
/>
349348

350349
</div>

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

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,8 @@ import Chart from "admin/components/chart";
88
export default class DoughnutChart extends Component {
99
@tracked canvasSize = null;
1010

11-
calculateRadius(postCount) {
12-
const minPosts = 0;
13-
const maxPosts = 100;
14-
const minRadius = 30;
15-
const maxRadius = 100;
16-
const clampedPostCount = Math.min(Math.max(postCount, minPosts), maxPosts);
17-
return (
18-
minRadius +
19-
((clampedPostCount - minPosts) / (maxPosts - minPosts)) *
20-
(maxRadius - minRadius)
21-
);
22-
}
23-
24-
getRadius() {
25-
if (this.args.radius) {
26-
return this.args.radius;
27-
} else if (isDevelopment()) {
28-
return this.calculateRadius(Math.floor(Math.random() * (100 + 1)));
29-
} else {
30-
return this.calculateRadius(this.args.totalScore);
31-
}
32-
}
33-
3411
get config() {
3512
const totalScore = this.args.totalScore || "";
36-
const skipCanvasResize = this.args.skipCanvasResize || false;
37-
const radius = this.getRadius();
38-
39-
const paddingTop = 30;
40-
const paddingBottom = 0;
41-
const canvasSize = 2 * radius + paddingTop + paddingBottom;
42-
this.canvasSize = canvasSize;
4313

4414
return {
4515
type: "doughnut",
@@ -49,22 +19,14 @@ export default class DoughnutChart extends Component {
4919
{
5020
data: this.args.data,
5121
backgroundColor: this.args.colors,
52-
cutout: "70%",
53-
radius,
22+
cutout: "50%",
23+
radius: 100,
5424
},
5525
],
5626
},
5727
options: {
5828
responsive: true,
5929
maintainAspectRatio: false,
60-
layout: {
61-
padding: {
62-
top: paddingTop,
63-
left: 0,
64-
right: 0,
65-
bottom: 0,
66-
},
67-
},
6830
plugins: {
6931
legend: {
7032
display: this.args.displayLegend || false,
@@ -103,29 +65,13 @@ export default class DoughnutChart extends Component {
10365
ctx.save();
10466
},
10567
},
106-
{
107-
id: "resizeCanvas",
108-
afterDraw: function (chart) {
109-
if (skipCanvasResize) {
110-
return;
111-
}
112-
const size = `${canvasSize}px`;
113-
chart.canvas.style.width = size;
114-
chart.canvas.style.height = size;
115-
116-
chart.resize();
117-
},
118-
},
11968
],
12069
};
12170
}
12271

12372
<template>
12473
{{#if this.config}}
125-
<h3
126-
class="doughnut-chart-title"
127-
style={{htmlSafe (concat "max-width: " this.canvasSize "px")}}
128-
>{{@doughnutTitle}}</h3>
74+
<h3 class="doughnut-chart-title">{{@doughnutTitle}}</h3>
12975
<Chart @chartConfig={{this.config}} class="admin-report-doughnut" />
13076
{{/if}}
13177
</template>

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
@include report-container-box();
6464
flex: 2;
6565
display: flex;
66+
gap: 1rem;
67+
justify-content: space-around;
68+
align-items: center;
6669
flex-flow: row wrap;
6770

6871
.admin-report-doughnut {
@@ -77,15 +80,13 @@
7780

7881
.doughnut-chart-title {
7982
@include ellipsis;
80-
position: absolute;
81-
top: 3%;
82-
left: 50%;
83-
transform: translateX(-50%);
84-
font-size: var(--font-0);
85-
z-index: 999;
83+
margin: 0 auto;
84+
margin-top: 1rem;
85+
text-align: center;
8686
}
8787

8888
&:hover {
89+
box-shadow: var(--shadow-card);
8990
transform: translateY(-1rem);
9091
cursor: pointer;
9192
}
@@ -136,6 +137,7 @@
136137
flex-flow: column nowrap;
137138
overflow-y: auto;
138139
height: 100%;
140+
padding-top: 0;
139141

140142
&__filters {
141143
border-bottom: 1px solid var(--primary-low);
@@ -210,3 +212,13 @@
210212
}
211213
}
212214
}
215+
216+
.admin-reports.admin-contents .sentiment-analysis {
217+
.horizontal-overflow-nav {
218+
background: var(--secondary);
219+
position: sticky;
220+
top: 0;
221+
padding-top: 1rem;
222+
z-index: z("header");
223+
}
224+
}

0 commit comments

Comments
 (0)