Skip to content

Commit ea626ac

Browse files
committed
Add bar chart to Emojis page
1 parent 53e98ed commit ea626ac

File tree

8 files changed

+100
-5
lines changed

8 files changed

+100
-5
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<script lang="ts">
2+
import { BarChart } from 'layerchart';
3+
import '../styles/metrics-bar-chart.css';
4+
import type { DataPoint } from '../types';
5+
6+
let {
7+
data,
8+
x = 'key',
9+
y = 'value'
10+
}: { data: DataPoint[]; x?: string; y?: string; color?: string } = $props();
11+
</script>
12+
13+
{#if data.length > 0}
14+
<article class="metrics-bar-chart">
15+
<BarChart
16+
{data}
17+
{x}
18+
{y}
19+
bandPadding={0.3}
20+
props={{
21+
bars: {
22+
radius: 4
23+
},
24+
yAxis: {
25+
ticks: 5
26+
},
27+
tooltip: {
28+
root: {
29+
classes: { root: 'layerchart-tooltip' }
30+
},
31+
item: {
32+
label: ''
33+
}
34+
}
35+
}}
36+
/>
37+
</article>
38+
{/if}

desktop-app/src/routes/+layout.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import 'carbon-components-svelte/css/all.css';
44
import type { ThemeProps } from 'carbon-components-svelte/src/Theme/Theme.svelte';
55
import Header from '../components/Header.svelte';
6+
import '../styles/colors.css';
67
import '../styles/layout.css';
78
import '../styles/utility-classes.css';
89
const { children } = $props();

desktop-app/src/routes/message-totals/+page.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
const label = row[metricCol.id];
2525
return typeof label === 'string' && columnNamePattern.test(label);
2626
})
27-
.map((row) => ({
28-
key: columnNameFormatter(String(row[metricCol.id])),
29-
value: Number(row[totalCol.id])
30-
}))
27+
.map((row) => {
28+
return {
29+
key: columnNameFormatter(String(row[metricCol.id])),
30+
value: Number(row[totalCol.id])
31+
};
32+
})
3133
.filter((dataPoint) => dataPoint.value > 0)
3234
.sort((a, b) => b.value - a.value);
3335
}
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
<script lang="ts">
2+
import MetricBarChart from '../../components/MetricBarChart.svelte';
23
import ResultGrid from '../../components/ResultGrid.svelte';
4+
import type { DataPoint, GridColumn } from '../../types';
5+
6+
function getChartData({
7+
rows,
8+
columns
9+
}: {
10+
rows: Array<Record<string, unknown>>;
11+
columns: GridColumn[];
12+
}): DataPoint[] {
13+
if (!columns.length || !rows.length) return [];
14+
15+
// Emojis result usually matches "Emoji" and "Count"
16+
let keyCol = columns.find((c) => /Emoji/i.test(c.header));
17+
let valueCol = columns.find((c) => /Count|Total/i.test(c.header));
18+
19+
// Fallback: Use first and second columns if named columns not found
20+
if (!keyCol && columns.length > 0) keyCol = columns[0];
21+
if (!valueCol && columns.length > 1) valueCol = columns[1];
22+
23+
if (!keyCol || !valueCol) return [];
24+
25+
return rows
26+
.map((row) => {
27+
return {
28+
key: String(row[keyCol!.id]),
29+
value: Number(row[valueCol!.id])
30+
};
31+
})
32+
.sort((a, b) => b.value - a.value);
33+
}
334
</script>
435

536
<ResultGrid
637
title="Most Frequent Emojis"
738
description="See which emojis are used most frequently in your conversation."
839
command={['most_frequent_emojis']}
9-
/>
40+
>
41+
{#snippet charts(rows, columns)}
42+
<MetricBarChart data={getChartData({ rows, columns })} />
43+
{/snippet}
44+
</ResultGrid>

desktop-app/src/styles/colors.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:root {
2+
/* Define colors as lists of HSL components */
3+
--color-primary: 219 99% 53%;
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.metrics-bar-chart {
2+
height: 300px;
3+
width: 100%;
4+
position: relative;
5+
/* Allow tooltip to overflow if necessary, but chart usually clips */
6+
}

desktop-app/src/styles/result-grid.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@
2424
display: flex;
2525
justify-content: center;
2626
align-items: center;
27+
width: 50%;
28+
margin: 0 auto;
2729
margin-top: -0.5em;
30+
fill: none;
31+
}
32+
.result-grid-charts text {
33+
fill: #fff;
2834
}

desktop-app/src/styles/utility-classes.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@
8383
.dark\:bg-surface-300\/90 {
8484
background-color: rgba(48, 48, 48, 0.9);
8585
}
86+
.fill-transparent {
87+
fill: transparent;
88+
}

0 commit comments

Comments
 (0)