Skip to content

Commit

Permalink
feat: highlight sankey chart when hovering dashboard tiles
Browse files Browse the repository at this point in the history
closes #68
  • Loading branch information
simonwep committed Jan 14, 2025
1 parent c43426c commit a8b6f9b
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 20 deletions.
7 changes: 5 additions & 2 deletions src/app/pages/dashboard/overview/Overview.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<template>
<div :class="$style.overview">
<SummaryPanels />
<SummaryPanels @hovered-panel="highlight = $event" />
<AsyncComponent
:properties="{ highlight }"
:show="media !== 'mobile'"
:class="$style.chart"
:import="() => import('./widgets/charts/DistributionChart.vue')"
Expand All @@ -11,10 +12,12 @@

<script lang="ts" setup>
import AsyncComponent from '@components/misc/async-component/AsyncComponent.vue';
import { useMediaQuery } from '../../../../composables/useMediaQuery';
import { useMediaQuery } from '@composables';
import SummaryPanels from './widgets/header-panels/SummaryPanels.vue';
import { ref } from 'vue';
const media = useMediaQuery();
const highlight = ref<string>();
</script>

<style lang="scss" module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SankeyChart from './sankey-chart/SankeyChart.vue';
const props = defineProps<{
class?: ClassNames;
highlight?: 'income' | 'expenses';
}>();
const classes = computed(() => props.class);
Expand Down Expand Up @@ -54,13 +55,15 @@ const data = computed((): SankeyChartConfig => {
labels.push({
id: group.id,
name: `${group.name} (${format(total)})`,
color: color(60 + 60 * (total / totalIncome))
color: color(60 + 60 * (total / totalIncome)),
muted: props.highlight === 'expenses'
});
links.push({
target: income.id,
source: group.id,
value: total
value: total,
muted: props.highlight === 'expenses'
});
for (let i = 0; i < group.budgets.length; i++) {
Expand All @@ -71,13 +74,15 @@ const data = computed((): SankeyChartConfig => {
labels.push({
id: budget.id,
name: `${budget.name} (${format(total)})`,
color: color(60 + 60 * (total / totalIncome))
color: color(60 + 60 * (total / totalIncome)),
muted: props.highlight === 'expenses'
});
links.push({
target: group.id,
source: budget.id,
value: total
value: total,
muted: props.highlight === 'expenses'
});
}
}
Expand All @@ -93,13 +98,15 @@ const data = computed((): SankeyChartConfig => {
labels.push({
id: group.id,
name: `${group.name} (${format(total)})`,
color: color(60 * (1 - total / totalExpenses))
color: color(60 * (1 - total / totalExpenses)),
muted: props.highlight === 'income'
});
links.push({
target: group.id,
source: income.id,
value: total
value: total,
muted: props.highlight === 'income'
});
for (let i = 0; i < group.budgets.length; i++) {
Expand All @@ -111,13 +118,15 @@ const data = computed((): SankeyChartConfig => {
id: budget.id,
name: `${budget.name} (${format(total)})`,
color: color(60 * (1 - total / totalExpenses)),
align: 'left'
align: 'left',
muted: props.highlight === 'income'
});
links.push({
target: budget.id,
source: group.id,
value: total
value: total,
muted: props.highlight === 'income'
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ export interface SankeyChartLink {
source: string;
target: string;
value: number;
muted?: boolean;
}

export interface SankeyChartLabel {
id: string;
name: string;
color: string;
muted?: boolean;
align?: 'left' | 'right';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const classes = computed(() => props.class);
const options = computed(
(): EChartsOption => ({
animation: false,
silent: true,
series: {
type: 'sankey',
label: {
Expand All @@ -65,20 +66,27 @@ const options = computed(
nodeWidth: 7,
left: 0,
right: 0,
links: props.data.links,
links: props.data.links.map((v) => ({
...v,
animation: true,
lineStyle: { opacity: v.muted ? 0.05 : 0.25 }
})),
data: props.data.labels.map((v) => ({
name: v.name,
id: v.id,
itemStyle: { color: v.color },
itemStyle: {
color: v.color,
opacity: v.muted ? 0.25 : 1
},
label:
v.align === 'left'
? {
align: 'right',
opacity: v.muted ? 0.65 : 1,
padding: [0, 20, 0, 0]
}
: undefined
})),
silent: true
: { opacity: v.muted ? 0.65 : 1 }
}))
}
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const element = computed(() => (props.to ? Link : 'div'));
width: 100%;
height: 100%;
background: v-bind('theme.light.base');
transition: background var(--transition-m);
transition: background var(--transition-s);
&.clickable:hover {
background: v-bind('theme.light.dimmed');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
<script lang="ts" setup>
import EChart from '@components/charts/echart/EChart.vue';
import { ClassNames } from '@utils';
import { GridComponentOption, LineSeriesOption } from 'echarts';
import { LineChart } from 'echarts/charts';
import { GridComponent } from 'echarts/components';
import { GridComponentOption, GridComponent } from 'echarts/components';
import { LineChart, LineSeriesOption } from 'echarts/charts';
import * as echarts from 'echarts/core';
import { SVGRenderer } from 'echarts/renderers';
import { computed } from 'vue';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type HoveredPanel = 'income' | 'expenses';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
to="/income"
:tooltip="t('page.dashboard.jumpToIncome', { year: state.activeYear })"
:title="t('page.dashboard.income')"
@pointerenter="emit('hoveredPanel', 'income')"
@pointerleave="emit('hoveredPanel')"
@pointercancel="emit('hoveredPanel')"
/>

<SummaryPanel
Expand All @@ -15,6 +18,9 @@
:values="expenses"
color="warning"
:title="t('page.dashboard.expenses')"
@pointerenter="emit('hoveredPanel', 'expenses')"
@pointerleave="emit('hoveredPanel')"
@pointercancel="emit('hoveredPanel')"
/>

<SummaryPanel
Expand Down Expand Up @@ -50,6 +56,11 @@ import { aggregate, ClassNames, subtract, sum } from '@utils';
import { computed, ref, useCssModule } from 'vue';
import { useI18n } from 'vue-i18n';
import SummaryPanel from './SummaryPanel.vue';
import { HoveredPanel } from '@app/pages/dashboard/overview/widgets/header-panels/SummaryPanels.types.ts';
const emit = defineEmits<{
hoveredPanel: (panel?: HoveredPanel) => void;
}>();
const props = defineProps<{
class?: ClassNames;
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/dashboard/summary/Summary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useDataStore } from '@store/state';
import { totals } from '@store/state/utils/budgets';
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useMediaQuery } from '../../../../composables/useMediaQuery';
import { useMediaQuery } from '@composables';
import GroupsSummaryTable from './widgets/tables/GroupsSummaryTable.vue';
import TotalsSummaryTable from './widgets/tables/TotalsSummaryTable.vue';
Expand Down

0 comments on commit a8b6f9b

Please sign in to comment.