generated from tpl/obsidian-sample-plugin
Make all charts responsive
This commit is contained in:
parent
6bbce670a1
commit
104533e0bb
|
@ -46,7 +46,6 @@ const PieChart = z.object({
|
||||||
unit: z.optional(z.string()),
|
unit: z.optional(z.string()),
|
||||||
unitPlural: z.optional(z.string()),
|
unitPlural: z.optional(z.string()),
|
||||||
groups: z.optional(z.array(PieGroupingSchema)),
|
groups: z.optional(z.array(PieGroupingSchema)),
|
||||||
responsive: z.optional(z.boolean()),
|
|
||||||
color: z.optional(PieChartColorSchema),
|
color: z.optional(PieChartColorSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -58,7 +57,6 @@ const BarChart = z.object({
|
||||||
topN: z.optional(z.number()),
|
topN: z.optional(z.number()),
|
||||||
unit: z.optional(z.string()),
|
unit: z.optional(z.string()),
|
||||||
unitPlural: z.optional(z.string()),
|
unitPlural: z.optional(z.string()),
|
||||||
responsive: z.optional(z.boolean()),
|
|
||||||
color: z.optional(color),
|
color: z.optional(color),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -70,7 +68,6 @@ const LineChart = z.object({
|
||||||
secondProperty: z.optional(z.keyof(BookMetadataSchema)),
|
secondProperty: z.optional(z.keyof(BookMetadataSchema)),
|
||||||
secondUnit: z.optional(z.string()),
|
secondUnit: z.optional(z.string()),
|
||||||
secondUnitPlural: z.optional(z.string()),
|
secondUnitPlural: z.optional(z.string()),
|
||||||
responsive: z.optional(z.boolean()),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const BooksAndPagesChart = z.object({
|
const BooksAndPagesChart = z.object({
|
||||||
|
|
|
@ -138,15 +138,11 @@
|
||||||
<div
|
<div
|
||||||
class="chart bar"
|
class="chart bar"
|
||||||
class:horizontal={chart.horizontal}
|
class:horizontal={chart.horizontal}
|
||||||
class:responsive={chart.responsive}
|
|
||||||
>
|
>
|
||||||
<Bar {...chart} />
|
<Bar {...chart} />
|
||||||
</div>
|
</div>
|
||||||
{:else if chart.type === "pie"}
|
{:else if chart.type === "pie"}
|
||||||
<div
|
<div class="chart pie">
|
||||||
class="chart pie"
|
|
||||||
class:responsive={chart.responsive}
|
|
||||||
>
|
|
||||||
<Pie {...chart} />
|
<Pie {...chart} />
|
||||||
</div>
|
</div>
|
||||||
{:else if chart.type === "books-and-pages"}
|
{:else if chart.type === "books-and-pages"}
|
||||||
|
@ -197,7 +193,7 @@
|
||||||
margin: 0 auto 1rem;
|
margin: 0 auto 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.bar.responsive {
|
&.bar.horizontal {
|
||||||
height: 35rem;
|
height: 35rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
topN?: number;
|
topN?: number;
|
||||||
unit?: string;
|
unit?: string;
|
||||||
unitPlural?: string;
|
unitPlural?: string;
|
||||||
responsive?: boolean;
|
|
||||||
color?: "rainbow" | ColorName;
|
color?: "rainbow" | ColorName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,7 +22,6 @@
|
||||||
topN,
|
topN,
|
||||||
unit,
|
unit,
|
||||||
unitPlural,
|
unitPlural,
|
||||||
responsive,
|
|
||||||
color,
|
color,
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
|
@ -107,8 +105,8 @@
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
indexAxis: horizontal ? "y" : "x",
|
indexAxis: horizontal ? "y" : "x",
|
||||||
responsive,
|
responsive: true,
|
||||||
maintainAspectRatio: !responsive,
|
maintainAspectRatio: !horizontal,
|
||||||
plugins: {
|
plugins: {
|
||||||
tooltip: {
|
tooltip: {
|
||||||
yAlign: horizontal ? "center" : "bottom",
|
yAlign: horizontal ? "center" : "bottom",
|
||||||
|
|
|
@ -99,6 +99,7 @@
|
||||||
datasets,
|
datasets,
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
|
responsive: true,
|
||||||
scales: {
|
scales: {
|
||||||
y: {
|
y: {
|
||||||
type: "linear",
|
type: "linear",
|
||||||
|
|
|
@ -14,12 +14,10 @@
|
||||||
groups?: PieGrouping[];
|
groups?: PieGrouping[];
|
||||||
unit?: string;
|
unit?: string;
|
||||||
unitPlural?: string;
|
unitPlural?: string;
|
||||||
responsive?: boolean;
|
|
||||||
color?: PieChartColor;
|
color?: PieChartColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
const { property, groups, unit, unitPlural, responsive, color }: Props =
|
const { property, groups, unit, unitPlural, color }: Props = $props();
|
||||||
$props();
|
|
||||||
|
|
||||||
const store = createPropertyStore(property);
|
const store = createPropertyStore(property);
|
||||||
|
|
||||||
|
@ -114,7 +112,7 @@
|
||||||
return {
|
return {
|
||||||
type: "pie",
|
type: "pie",
|
||||||
data: { labels, datasets: [{ data, backgroundColor }] },
|
data: { labels, datasets: [{ data, backgroundColor }] },
|
||||||
options: { responsive },
|
options: { responsive: true },
|
||||||
} as ChartConfiguration;
|
} as ChartConfiguration;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue