mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-06 09:20:14 +00:00
UX: Improvements to sentiment analysis report (#1150)
This update improves some of the UI around sentiment analysis reports: 1. Improve titles so it is above and truncated when long 2. Change doughnut to only show total count 3. Ensures sentiment posts have dates 4. Ensure expand post doesn't appear on short posts
This commit is contained in:
parent
0018475987
commit
9aafca03f5
@ -41,6 +41,7 @@ module DiscourseAi
|
|||||||
p.cooked as post_cooked,
|
p.cooked as post_cooked,
|
||||||
p.user_id,
|
p.user_id,
|
||||||
p.post_number,
|
p.post_number,
|
||||||
|
p.created_at AS created_at,
|
||||||
u.username,
|
u.username,
|
||||||
u.name,
|
u.name,
|
||||||
u.uploaded_avatar_id,
|
u.uploaded_avatar_id,
|
||||||
|
@ -11,7 +11,8 @@ class AiSentimentPostSerializer < ApplicationSerializer
|
|||||||
:excerpt,
|
:excerpt,
|
||||||
:sentiment,
|
:sentiment,
|
||||||
:truncated,
|
:truncated,
|
||||||
:category
|
:category,
|
||||||
|
:created_at
|
||||||
|
|
||||||
def avatar_template
|
def avatar_template
|
||||||
User.avatar_template(object.username, object.uploaded_avatar_id)
|
User.avatar_template(object.username, object.uploaded_avatar_id)
|
||||||
@ -22,7 +23,7 @@ class AiSentimentPostSerializer < ApplicationSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def truncated
|
def truncated
|
||||||
true
|
object.post_cooked.length > SiteSetting.post_excerpt_maxlength
|
||||||
end
|
end
|
||||||
|
|
||||||
def category
|
def category
|
||||||
|
@ -250,7 +250,8 @@ export default class AdminReportSentimentAnalysis extends Component {
|
|||||||
@labels={{@model.labels}}
|
@labels={{@model.labels}}
|
||||||
@colors={{this.colors}}
|
@colors={{this.colors}}
|
||||||
@data={{data.scores}}
|
@data={{data.scores}}
|
||||||
@doughnutTitle={{this.doughnutTitle data}}
|
@totalScore={{data.total_score}}
|
||||||
|
@doughnutTitle={{data.title}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
@ -265,15 +266,13 @@ export default class AdminReportSentimentAnalysis extends Component {
|
|||||||
class="btn-flat"
|
class="btn-flat"
|
||||||
@action={{this.backToAllCharts}}
|
@action={{this.backToAllCharts}}
|
||||||
/>
|
/>
|
||||||
<h3 class="admin-report-sentiment-analysis-details__title">
|
|
||||||
{{this.selectedChart.title}}
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<DoughnutChart
|
<DoughnutChart
|
||||||
@labels={{@model.labels}}
|
@labels={{@model.labels}}
|
||||||
@colors={{this.colors}}
|
@colors={{this.colors}}
|
||||||
@data={{this.selectedChart.scores}}
|
@data={{this.selectedChart.scores}}
|
||||||
@doughnutTitle={{this.doughnutTitle this.selectedChart}}
|
@totalScore={{this.selectedChart.total_score}}
|
||||||
|
@doughnutTitle={{this.selectedChart.title}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="admin-report-sentiment-analysis-details">
|
<div class="admin-report-sentiment-analysis-details">
|
||||||
|
@ -3,7 +3,7 @@ import Chart from "admin/components/chart";
|
|||||||
|
|
||||||
export default class DoughnutChart extends Component {
|
export default class DoughnutChart extends Component {
|
||||||
get config() {
|
get config() {
|
||||||
const doughnutTitle = this.args.doughnutTitle || "";
|
const totalScore = this.args.totalScore || "";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: "doughnut",
|
type: "doughnut",
|
||||||
@ -30,11 +30,11 @@ export default class DoughnutChart extends Component {
|
|||||||
afterDraw: function (chart) {
|
afterDraw: function (chart) {
|
||||||
const cssVarColor =
|
const cssVarColor =
|
||||||
getComputedStyle(document.documentElement).getPropertyValue(
|
getComputedStyle(document.documentElement).getPropertyValue(
|
||||||
"--primary"
|
"--primary-high"
|
||||||
) || "#000";
|
) || "#000";
|
||||||
const cssFontSize =
|
const cssFontSize =
|
||||||
getComputedStyle(document.documentElement).getPropertyValue(
|
getComputedStyle(document.documentElement).getPropertyValue(
|
||||||
"--font-down-2"
|
"--font-up-4"
|
||||||
) || "1.3em";
|
) || "1.3em";
|
||||||
const cssFontFamily =
|
const cssFontFamily =
|
||||||
getComputedStyle(document.documentElement).getPropertyValue(
|
getComputedStyle(document.documentElement).getPropertyValue(
|
||||||
@ -49,9 +49,9 @@ export default class DoughnutChart extends Component {
|
|||||||
ctx.textAlign = "center";
|
ctx.textAlign = "center";
|
||||||
ctx.textBaseline = "middle";
|
ctx.textBaseline = "middle";
|
||||||
ctx.fillStyle = cssVarColor.trim();
|
ctx.fillStyle = cssVarColor.trim();
|
||||||
ctx.font = `${cssFontSize.trim()} ${cssFontFamily.trim()}`;
|
ctx.font = `bold ${cssFontSize.trim()} ${cssFontFamily.trim()}`;
|
||||||
|
|
||||||
ctx.fillText(doughnutTitle, centerX, centerY);
|
ctx.fillText(totalScore, centerX, centerY);
|
||||||
ctx.save();
|
ctx.save();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -61,6 +61,7 @@ export default class DoughnutChart extends Component {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
{{#if this.config}}
|
{{#if this.config}}
|
||||||
|
<h3 class="doughnut-chart-title">{{@doughnutTitle}}</h3>
|
||||||
<Chart @chartConfig={{this.config}} class="admin-report-doughnut" />
|
<Chart @chartConfig={{this.config}} class="admin-report-doughnut" />
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</template>
|
</template>
|
||||||
|
@ -75,6 +75,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&__chart-wrapper {
|
&__chart-wrapper {
|
||||||
|
width: auto;
|
||||||
|
.doughnut-chart-title {
|
||||||
|
@include ellipsis;
|
||||||
|
margin: 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
max-width: 300px;
|
||||||
|
}
|
||||||
transition: transform 0.25s ease, box-shadow 0.25s ease;
|
transition: transform 0.25s ease, box-shadow 0.25s ease;
|
||||||
border-radius: var(--d-border-radius);
|
border-radius: var(--d-border-radius);
|
||||||
|
|
||||||
@ -89,6 +97,17 @@
|
|||||||
border: 1px solid var(--primary-low);
|
border: 1px solid var(--primary-low);
|
||||||
border-radius: var(--d-border-radius);
|
border-radius: var(--d-border-radius);
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
|
|
||||||
|
.doughnut-chart-title {
|
||||||
|
font-size: var(--font-up-2);
|
||||||
|
margin: 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
margin-top: 0.3rem;
|
||||||
|
padding-top: 2rem;
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
border-top: 1px solid var(--primary-low);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,17 +138,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__title {
|
|
||||||
font-size: var(--font-up-2);
|
|
||||||
margin: 0 auto;
|
|
||||||
text-align: center;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
margin-top: 0.3rem;
|
|
||||||
padding-top: 2rem;
|
|
||||||
padding-bottom: 1rem;
|
|
||||||
border-top: 1px solid var(--primary-low);
|
|
||||||
}
|
|
||||||
|
|
||||||
&__scores {
|
&__scores {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column wrap;
|
flex-flow: column wrap;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user