feat: add radar labels

This commit is contained in:
Mathias Schopmans
2024-02-22 09:17:31 +01:00
committed by Mathias Schopmans
parent dd4e5d1de5
commit 36c2c84473
4 changed files with 46 additions and 5 deletions

View File

@@ -9,10 +9,16 @@
max-width: 100%; max-width: 100%;
height: auto; height: auto;
margin: 0 auto; margin: 0 auto;
fill: currentColor;
}
.ringLabels {
text-transform: uppercase;
} }
@media (max-width: 767px) { @media (max-width: 767px) {
.labels { .labels,
.ringLabels {
display: none; display: none;
} }
} }

View File

@@ -1,5 +1,5 @@
import Link from "next/link"; import Link from "next/link";
import React, { FC } from "react"; import React, { FC, Fragment } from "react";
import styles from "./Radar.module.css"; import styles from "./Radar.module.css";
@@ -115,6 +115,37 @@ export const Radar: FC<RadarProps> = ({
); );
}; };
const renderRingLabels = () => {
return rings.map((ring, index) => {
const outerRadius = ring.radius || 1;
const innerRadius = rings[index - 1]?.radius || 0;
const position = ((outerRadius + innerRadius) / 2) * center;
return (
<Fragment key={ring.id}>
<text
x={center + position}
y={center}
textAnchor="middle"
dominantBaseline="middle"
fontSize="12"
>
{ring.title}
</text>
<text
x={center - position}
y={center}
textAnchor="middle"
dominantBaseline="middle"
fontSize="12"
>
{ring.title}
</text>
</Fragment>
);
});
};
return ( return (
<div className={styles.radar}> <div className={styles.radar}>
<svg <svg
@@ -138,7 +169,8 @@ export const Radar: FC<RadarProps> = ({
))} ))}
</g> </g>
))} ))}
<g>{items.map((item) => renderItem(item))}</g> <g className={styles.items}>{items.map((item) => renderItem(item))}</g>
<g className={styles.ringLabels}>{renderRingLabels()}</g>
</svg> </svg>
<div className={styles.labels}> <div className={styles.labels}>
{quadrants.map((quadrant) => ( {quadrants.map((quadrant) => (

View File

@@ -22,11 +22,13 @@
.list { .list {
} }
@media (min-width: 768px) { @media (min-width: 480px) {
.ring { .ring {
--cols: 2; --cols: 2;
} }
}
@media (min-width: 768px) {
.isSmall .ring { .isSmall .ring {
--cols: 4; --cols: 4;
} }

View File

@@ -67,7 +67,7 @@ h1,
h2, h2,
h3, h3,
h4 { h4 {
line-height: 1.1em; line-height: 1.2em;
margin-bottom: 1em; margin-bottom: 1em;
font-weight: 700; font-weight: 700;
} }
@@ -77,6 +77,7 @@ h1 {
} }
h2 { h2 {
font-weight: 400;
font-size: 26px; font-size: 26px;
} }