Skip to content

Switch to area charts for analytics #3716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/frontend/src/components/ui/charts/Chart.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const chartOptions = computed(() => {
toolbar: {
show: false,
},
stacked: props.stacked,
stacked: props.type === "line" ? false : props.stacked,
stackType: props.percentStacked ? "100%" : "normal",
zoom: {
autoScaleYaxis: true,
Expand Down
24 changes: 20 additions & 4 deletions apps/frontend/src/components/ui/charts/ChartDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
</span>
</h2>
<div class="chart-controls__buttons">
<Button v-tooltip="'Cycle chart type'" icon-only @click="cycleChartType">
<ChartAreaIcon v-if="cosmetics.analyticsChartType === 'area'" />
<ChartLineIcon v-else />
</Button>
<Button v-tooltip="'Toggle project colors'" icon-only @click="onToggleColors">
<PaletteIcon />
</Button>
Expand All @@ -102,8 +106,9 @@
<Chart
v-if="analytics.formattedData.value.downloads && selectedChart === 'downloads'"
ref="downloadsChart"
type="line"
:type="cosmetics.analyticsChartType"
name="Download data"
stacked="true"
:hide-legend="true"
:data="analytics.formattedData.value.downloads.chart.data"
:labels="analytics.formattedData.value.downloads.chart.labels"
Expand All @@ -117,8 +122,9 @@
<Chart
v-if="analytics.formattedData.value.views && selectedChart === 'views'"
ref="viewsChart"
type="line"
:type="cosmetics.analyticsChartType"
name="View data"
stacked="true"
:hide-legend="true"
:data="analytics.formattedData.value.views.chart.data"
:labels="analytics.formattedData.value.views.chart.labels"
Expand All @@ -132,8 +138,9 @@
<Chart
v-if="analytics.formattedData.value.revenue && selectedChart === 'revenue'"
ref="revenueChart"
type="line"
:type="cosmetics.analyticsChartType"
name="Revenue data"
stacked="true"
:hide-legend="true"
:data="analytics.formattedData.value.revenue.chart.data"
:labels="analytics.formattedData.value.revenue.chart.labels"
Expand Down Expand Up @@ -306,7 +313,7 @@
<script setup lang="ts">
import { Button, Card, DropdownSelect } from "@modrinth/ui";
import { formatMoney, formatNumber, formatCategoryHeader } from "@modrinth/utils";
import { UpdatedIcon, DownloadIcon } from "@modrinth/assets";
import { UpdatedIcon, DownloadIcon, ChartLineIcon, ChartAreaIcon } from "@modrinth/assets";
import dayjs from "dayjs";
import { computed } from "vue";

Expand All @@ -316,8 +323,10 @@ import { UiChartsCompactChart as CompactChart, UiChartsChart as Chart } from "#c

import PaletteIcon from "~/assets/icons/palette.svg?component";

const data = useNuxtApp();
const router = useNativeRouter();
const theme = useTheme();
const cosmetics = useCosmetics();

const props = withDefaults(
defineProps<{
Expand Down Expand Up @@ -411,6 +420,13 @@ const isUsingProjectColors = computed({
},
});

function cycleChartType() {
cosmetics.value.analyticsChartType = data.$cycleValue(cosmetics.value.analyticsChartType, [
"area",
"line",
]);
}

const startDate = ref(dayjs().startOf("day"));
const endDate = ref(dayjs().endOf("day"));
const timeResolution = ref(30);
Expand Down
6 changes: 6 additions & 0 deletions apps/frontend/src/plugins/cosmetics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type DisplayLocation =
| "user"
| "collection";

export type ChartType = "area" | "line";

export interface Cosmetics {
rightSearchLayout: boolean;
leftContentLayout: boolean;
Expand All @@ -22,6 +24,8 @@ export interface Cosmetics {
preferredDarkTheme: DarkTheme;
searchDisplayMode: Record<DisplayLocation, DisplayMode>;
hideStagingBanner: boolean;
analyticsChartType: ChartType;
analyticsProjectColors: boolean;
}

export default defineNuxtPlugin({
Expand Down Expand Up @@ -51,6 +55,8 @@ export default defineNuxtPlugin({
user: "list",
collection: "list",
},
analyticsChartType: "line",
analyticsProjectColors: true,
hideStagingBanner: false,
}),
});
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/utils/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const getDefaultColor = (value) => {
return defaultColors[value % defaultColors.length];
};

export const intToRgba = (color, projectId = "Unknown", theme = "dark", alpha = "1") => {
export const intToRgba = (color, projectId = "Unknown", theme = "dark") => {
const hash = hashProjectId(projectId);

if (!color || color === 0) {
Expand Down Expand Up @@ -110,7 +110,7 @@ export const intToRgba = (color, projectId = "Unknown", theme = "dark", alpha =
g = Math.min(255, Math.max(0, g));
b = Math.min(255, Math.max(0, b));

return `rgba(${r}, ${g}, ${b}, ${alpha})`;
return `rgb(${r}, ${g}, ${b})`;
};

const emptyAnalytics = {
Expand Down
1 change: 1 addition & 0 deletions packages/assets/icons/chart-area.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/assets/icons/chart-line.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import _BracesIcon from './icons/braces.svg?component'
import _CalendarIcon from './icons/calendar.svg?component'
import _CardIcon from './icons/card.svg?component'
import _ChartIcon from './icons/chart.svg?component'
import _ChartAreaIcon from './icons/chart-area.svg?component'
import _ChartLineIcon from './icons/chart-line.svg?component'
import _CheckIcon from './icons/check.svg?component'
import _CheckCheckIcon from './icons/check-check.svg?component'
import _CheckCircleIcon from './icons/check-circle.svg?component'
Expand Down Expand Up @@ -276,6 +278,8 @@ export const BoxImportIcon = _BoxImportIcon
export const BracesIcon = _BracesIcon
export const CalendarIcon = _CalendarIcon
export const ChartIcon = _ChartIcon
export const ChartAreaIcon = _ChartAreaIcon
export const ChartLineIcon = _ChartLineIcon
export const CheckIcon = _CheckIcon
export const CheckCheckIcon = _CheckCheckIcon
export const CheckCircleIcon = _CheckCircleIcon
Expand Down