Make all charts responsive

This commit is contained in:
Evan Fiordeliso 2025-07-15 12:06:01 -04:00
parent 6bbce670a1
commit 104533e0bb
5 changed files with 7 additions and 17 deletions

View File

@ -46,7 +46,6 @@ const PieChart = z.object({
unit: z.optional(z.string()),
unitPlural: z.optional(z.string()),
groups: z.optional(z.array(PieGroupingSchema)),
responsive: z.optional(z.boolean()),
color: z.optional(PieChartColorSchema),
});
@ -58,7 +57,6 @@ const BarChart = z.object({
topN: z.optional(z.number()),
unit: z.optional(z.string()),
unitPlural: z.optional(z.string()),
responsive: z.optional(z.boolean()),
color: z.optional(color),
});
@ -70,7 +68,6 @@ const LineChart = z.object({
secondProperty: z.optional(z.keyof(BookMetadataSchema)),
secondUnit: z.optional(z.string()),
secondUnitPlural: z.optional(z.string()),
responsive: z.optional(z.boolean()),
});
const BooksAndPagesChart = z.object({

View File

@ -138,15 +138,11 @@
<div
class="chart bar"
class:horizontal={chart.horizontal}
class:responsive={chart.responsive}
>
<Bar {...chart} />
</div>
{:else if chart.type === "pie"}
<div
class="chart pie"
class:responsive={chart.responsive}
>
<div class="chart pie">
<Pie {...chart} />
</div>
{:else if chart.type === "books-and-pages"}
@ -197,7 +193,7 @@
margin: 0 auto 1rem;
}
&.bar.responsive {
&.bar.horizontal {
height: 35rem;
}
}

View File

@ -12,7 +12,6 @@
topN?: number;
unit?: string;
unitPlural?: string;
responsive?: boolean;
color?: "rainbow" | ColorName;
};
@ -23,7 +22,6 @@
topN,
unit,
unitPlural,
responsive,
color,
}: Props = $props();
@ -107,8 +105,8 @@
},
options: {
indexAxis: horizontal ? "y" : "x",
responsive,
maintainAspectRatio: !responsive,
responsive: true,
maintainAspectRatio: !horizontal,
plugins: {
tooltip: {
yAlign: horizontal ? "center" : "bottom",

View File

@ -99,6 +99,7 @@
datasets,
},
options: {
responsive: true,
scales: {
y: {
type: "linear",

View File

@ -14,12 +14,10 @@
groups?: PieGrouping[];
unit?: string;
unitPlural?: string;
responsive?: boolean;
color?: PieChartColor;
};
const { property, groups, unit, unitPlural, responsive, color }: Props =
$props();
const { property, groups, unit, unitPlural, color }: Props = $props();
const store = createPropertyStore(property);
@ -114,7 +112,7 @@
return {
type: "pie",
data: { labels, datasets: [{ data, backgroundColor }] },
options: { responsive },
options: { responsive: true },
} as ChartConfiguration;
});
</script>