From face4ce2d0e2316c9ed62b2eba9260a17e39572f Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Wed, 13 Nov 2024 12:59:05 +0200 Subject: Backup --- src/components/RadarChart.astro | 147 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/components/RadarChart.astro (limited to 'src/components') diff --git a/src/components/RadarChart.astro b/src/components/RadarChart.astro new file mode 100644 index 0000000..60f2cf7 --- /dev/null +++ b/src/components/RadarChart.astro @@ -0,0 +1,147 @@ +--- + +// const { data } = Astro.props; + +const data = [ + { name: 'React', total: 9 }, + { name: 'GraphQL', total: 2 }, + { name: 'JavaScript', total: 5 }, + { name: 'SVG', total: 5 }, + { name: 'TypeScript', total: 7 }, + { name: 'Tailwind', total: 7 }, + { name: 'React Query', total: 2 }, + { name: 'Next.js', total: 3 }, + { name: 'Hmm', total: 5 }, +] + +const chartSize = 400; +const chartCenter = chartSize / 2; + +const colors = ['#58e6d9', '#ff6090', '#4871e3', '#ffc107', '#8bc34a', '#00FF00']; +const chartData = data.sort((a, b) => b.total - a.total).slice(0, colors.length); +const pointPadding = 10; +const max = chartData.reduce((max, current) => (current.total > max ? current.total : max), 0); +const rings = [...Array(6).keys()]; + +const getX = (angle, value) => Math.cos(angle - Math.PI / 2) * value; +const getY = (angle, value) => Math.sin(angle - Math.PI / 2) * value; + +const axes = chartData.map((_, index) => { + const angle = (Math.PI * 2 * index) / chartData.length; + const x = getX(angle, chartSize / 2); + const y = getY(angle, chartSize / 2); + const points = [ + [0, 0], + [x, y], + ] + .map((point) => point[0] + ',' + point[1]) + .join(' '); + return { + points: points, + }; +}); + +const properties = chartData.map((item, index) => { + const { name, total } = item; + const clamp = Number(total / (max + pointPadding)); + const angle = (Math.PI * 2 * index) / chartData.length; + const x = getX(angle, (clamp * chartSize) / 2); + const y = getY(angle, (clamp * chartSize) / 2); + return { name: name, total: total, x: x, y: y }; +}); + +const shape = + properties.reduce((items, item, index) => { + const { x, y } = item; + const string = `${index === 0 ? 'M' : 'L'}${x},${y}`; + return items + string; + }, '') + 'z'; + +const bgColor = "bg-blue-500" +const borderColor = "border-gray-100" +const strokeColor = 'stroke-gray-200' +const shapeClass = 'stroke-gray-900 fill-gray-900/[0.5]' +--- + +
+
+ + + { + rings.map((_, index) => { + return ( + + ); + }) + } + { + axes.map((axis) => { + const { points } = axis; + return ; + }) + } + + { + properties.map((property, index) => { + const { x, y } = property; + + return ( + + + + + + + Hello + + + ); + }) + } + + +
+

Top 6 Tags

+

Calculated using Astro Content Collections.

+
    + { + properties.map((property, index) => { + const { name, total } = property; + + return ( +
  • +
    + + + + {name} +
    + {`x${total}`} +
  • + ); + }) + } +
+
+
+
-- cgit v1.3.1