mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
import grouping and sorting with Prettier plugin
This commit is contained in:
+28
-12
@@ -3,11 +3,11 @@ function round(n: number) {
|
||||
}
|
||||
|
||||
function polarToCartesian(radius: number, angleInDegrees: number) {
|
||||
var radians = (angleInDegrees - 90) * Math.PI / 180;
|
||||
var radians = ((angleInDegrees - 90) * Math.PI) / 180;
|
||||
|
||||
return {
|
||||
x: round(radius + (radius * Math.cos(radians))),
|
||||
y: round(radius + (radius * Math.sin(radians)))
|
||||
x: round(radius + radius * Math.cos(radians)),
|
||||
y: round(radius + radius * Math.sin(radians)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,8 +21,17 @@ function getDAttribute(radius: number, startAngle: number, endAngle: number) {
|
||||
|
||||
const largeArcFlag = endAngle - startAngle <= 180 ? 0 : 1;
|
||||
const d = [
|
||||
"M", start.x, start.y,
|
||||
"A", radius, radius, 0, largeArcFlag, 1, end.x, end.y
|
||||
"M",
|
||||
start.x,
|
||||
start.y,
|
||||
"A",
|
||||
radius,
|
||||
radius,
|
||||
0,
|
||||
largeArcFlag,
|
||||
1,
|
||||
end.x,
|
||||
end.y,
|
||||
];
|
||||
|
||||
if (isCircle) {
|
||||
@@ -37,32 +46,39 @@ function path(d: string, colour: string) {
|
||||
return `<path d='${d}' style="fill: ${colour}" />`;
|
||||
}
|
||||
|
||||
function svg(className: string, width: number, content: string ) {
|
||||
function svg(className: string, width: number, content: string) {
|
||||
return `<svg class="${className}" viewBox="0 0 ${width} ${width}"><g class='pie'>${content}</g></svg>`;
|
||||
}
|
||||
|
||||
type PieSlice = {
|
||||
value: number;
|
||||
colour: string;
|
||||
}
|
||||
};
|
||||
|
||||
export function generatePieSVG(className: string, radius: number, values: PieSlice[]) {
|
||||
export function generatePieSVG(
|
||||
className: string,
|
||||
radius: number,
|
||||
values: PieSlice[],
|
||||
) {
|
||||
type Sector = {
|
||||
colour: string;
|
||||
degrees: number;
|
||||
from?: number;
|
||||
to?: number;
|
||||
}
|
||||
};
|
||||
|
||||
const total = values.reduce((a, b) => a + b.value, 0);
|
||||
const data: Sector[] = values.map(({ value, colour }) => ({ colour, degrees: value / total * 360 }));
|
||||
const data: Sector[] = values.map(({ value, colour }) => ({
|
||||
colour,
|
||||
degrees: (value / total) * 360,
|
||||
}));
|
||||
|
||||
const paths = data.reduce<[number, string][]>((prev, value, i) => {
|
||||
const from = i === 0 ? 0 : prev[i - 1][0];
|
||||
const to = from + value.degrees;
|
||||
|
||||
return [...prev, [to, path(getDAttribute(radius, from, to ), value.colour)]];
|
||||
return [...prev, [to, path(getDAttribute(radius, from, to), value.colour)]];
|
||||
}, []);
|
||||
|
||||
return svg(className, radius * 2, paths.map(([to, path]) => path) .join(''));
|
||||
return svg(className, radius * 2, paths.map(([to, path]) => path).join(""));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { LatLngLiteral } from "leaflet";
|
||||
|
||||
import { TournamentFormProps } from "@/types";
|
||||
import formatDate from "@/utils/formatDate";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user