Skip to content

Instantly share code, notes, and snippets.

@brianfoody
brianfoody / SvgRadarChart.tsx
Last active August 24, 2023 08:23
SVG Radar Chart in React Native
import React, { useMemo } from "react";
import { View } from "react-native";
import { degToRadians } from "src/components/OrbitLogo";
import Svg, { Circle, Line, Polygon } from "react-native-svg";
import times from "lodash.times";
type RadarData = {
value: number;
label: string;
};
@brianfoody
brianfoody / Polygon Radar Chart
Last active May 30, 2020 03:30
Polygon Radar Chart
<Polygon
stroke={"#50E2C2"}
strokeWidth={1.2}
fill={"#50E2C2"}
fillOpacity={0.9}
points={`${radarData.map((r, i) => {
const edgePoint = calculateEdgePoint(i * 60, r.value / 100);
return `${edgePoint[0]},${edgePoint[1]}`;
})}`}
/>
const calculateEdgePointFn = (center: number, radius: number) => (
degree: number,
scale: number = 1
): Point => {
const degreeInRadians = degToRadians(degree);
const degreeInRadiansY = degToRadians(svgY(degree));
return [
center + Math.cos(degreeInRadians) * radius * scale,
center + Math.sin(degreeInRadiansY) * radius * scale
];
const radarData = [
{ label: "Acceleration", value: 86 },
{ label: "Agility", value: 58 },
{ label: "Clutch", value: 60 },
{ label: "Speed", value: 85 },
{ label: "Stamina", value: 60 },
{ label: "Strength", value: 90 }
];
@brianfoody
brianfoody / Slicing Pizza
Last active May 30, 2020 03:46
Slicing Pizza
{times(3).map(i => (
<Line
key={`crosshair_${i}`}
x1={calculateEdgePoint(i * 60)[0]}
y1={calculateEdgePoint(i * 60)[1]}
x2={calculateEdgePoint(i * 60 + 180)[0]}
y2={calculateEdgePoint(i * 60 + 180)[1]}
stroke="black"
strokeOpacity="0.2"
strokeWidth="0.5"
{times(3).map(i => (
<Circle
key={`circle_outline_${i}`}
cx={viewBoxCenter}
cy={viewBoxCenter}
r={(i + 1) * radius * 0.25}
stroke="black"
strokeOpacity="0.2"
strokeWidth="0.5"
fill="transparent"
const edgePointCalculatorFor = (center: number, radius: number) => (degree: number): Point => {
const degreeInRadians = degToRadians(degree);
return [
center + Math.cos(degreeInRadians) * radius,
center + Math.sin(degreeInRadians) * radius
];
};
const calculateEdgePoint = edgePointCalculatorFor(60, 50);
const eightyDegreesAlongCircle = calculateEdgePoint(80)
@brianfoody
brianfoody / Edge Point
Last active May 29, 2020 12:29
Circle Edge Point
const calcEdgePoint = (center: number, radius: number, degree: number): Point => {
const degreeInRadians = degToRadians(degree);
return [
center + Math.cos(degreeInRadians) * radius,
center + Math.sin(degreeInRadians) * radius
];
};
@brianfoody
brianfoody / greengrass-cdk.ts
Created April 25, 2020 07:35 — forked from t04glovern/greengrass-cdk.ts
Example of Greengrass Core deployment with AWS CDK
import cdk = require('@aws-cdk/core');
import greengrass = require('@aws-cdk/aws-greengrass');
import lambda = require('@aws-cdk/aws-lambda');
import { CfnCustomResource } from '@aws-cdk/aws-cloudformation';
import { PolicyStatement, Role, ServicePrincipal, CompositePrincipal } from '@aws-cdk/aws-iam';
import { group_deployment_reset_code } from '../lib/code/group_deployment_reset';
import { thing_vendor_code } from '../lib/code/thing_vendor';
@brianfoody
brianfoody / MultiRegionServerlessCDK.ts
Last active February 29, 2020 11:53
Multi-region serverless application with AWS CDK
import {
RestApi,
CfnAuthorizer,
DomainName,
EndpointType,
CfnBasePathMapping
} from "@aws-cdk/aws-apigateway";
import { Certificate, ValidationMethod } from "@aws-cdk/aws-certificatemanager";
import { Construct } from "@aws-cdk/core";
import {