feat: prevent overlapping of blips

This commit is contained in:
Mathias Schopmans
2024-02-28 16:27:28 +01:00
committed by Mathias Schopmans
parent 13591b9672
commit 535c9e8a8f
5 changed files with 114 additions and 26 deletions

View File

@@ -86,29 +86,8 @@ const _Chart: FC<ChartProps> = ({
const ring = rings.find((r) => r.id === item.ring);
const quadrant = quadrants.find((q) => q.id === item.quadrant);
if (!ring || !quadrant) return null; // If no ring or quadrant, don't render item
const [x, y] = item.position;
const padding = 15; // Padding in pixels
const paddingAngle = 10; // Padding in degrees
// Random factors to determine position within the ring
const [randomRadius, randomAngleFactor] = item.random || [
Math.sqrt(Math.random()),
Math.random(),
];
const innerRadius =
(rings[rings.indexOf(ring) - 1]?.radius || 0) + padding / center; // Add inner padding
const outerRadius = (ring.radius || 1) - padding / center; // Subtract outer padding
const ringWidth = (outerRadius - innerRadius) * center; // Width of the ring in the SVG
// Calculate the position within the ring
const itemRadius = innerRadius * center + randomRadius * ringWidth;
// Calculate the angle with padding offset, avoiding the exact edges
const startAngle = startAngles[quadrant.position - 1] + paddingAngle;
const endAngle = startAngle + 90 - 2 * paddingAngle; // Subtract padding from both sides
const itemAngle = startAngle + (endAngle - startAngle) * randomAngleFactor;
// Convert polar coordinates to cartesian for the item's position
const { x, y } = polarToCartesian(itemRadius, itemAngle);
return (
<Link
key={item.id}

View File

@@ -24,7 +24,7 @@ export interface Item {
tags: string[];
release: Release;
revisions?: Revision[];
random?: [radius: number, angle: number];
position: [x: number, y: number];
}
export interface Ring {

View File

@@ -5,6 +5,7 @@ import { Radar } from "@/components/Radar/Radar";
import { Tags } from "@/components/Tags/Tags";
import {
getAppName,
getChartConfig,
getItems,
getQuadrants,
getReleases,
@@ -17,6 +18,7 @@ const Home: CustomPage = () => {
const router = useRouter();
const tag = router.query.tag as string | undefined;
const appName = getAppName();
const chartConfig = getChartConfig();
const version = getReleases().length;
const rings = getRings();
const quadrants = getQuadrants();
@@ -33,7 +35,12 @@ const Home: CustomPage = () => {
Version #{version}
</span>
</h1>
<Radar quadrants={quadrants} rings={rings} items={items} />
<Radar
size={chartConfig.size}
quadrants={quadrants}
rings={rings}
items={items}
/>
<Tags tags={tags} activeTag={tag} />
<QuadrantList items={items} />
</>