From dc3084cbffd52141b4b18446c6ed52d09a739e5f Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Wed, 6 May 2020 16:22:25 -0700 Subject: [PATCH] new(vx-demo): convert Radar to codesandbox --- packages/vx-demo/src/components/Gallery.tsx | 9 ++- .../examples/vx-radar/Example.tsx} | 67 +++++++++---------- .../src/docs-v2/examples/vx-radar/index.tsx | 11 +++ .../docs-v2/examples/vx-radar/package.json | 27 ++++++++ .../examples/vx-radar/sandbox-styles.css | 8 +++ packages/vx-demo/src/pages/Radar.tsx | 11 ++- 6 files changed, 90 insertions(+), 43 deletions(-) rename packages/vx-demo/src/{components/tiles/Radar.tsx => docs-v2/examples/vx-radar/Example.tsx} (71%) create mode 100644 packages/vx-demo/src/docs-v2/examples/vx-radar/index.tsx create mode 100644 packages/vx-demo/src/docs-v2/examples/vx-radar/package.json create mode 100644 packages/vx-demo/src/docs-v2/examples/vx-radar/sandbox-styles.css diff --git a/packages/vx-demo/src/components/Gallery.tsx b/packages/vx-demo/src/components/Gallery.tsx index 903833ab4..e1b7e4d05 100644 --- a/packages/vx-demo/src/components/Gallery.tsx +++ b/packages/vx-demo/src/components/Gallery.tsx @@ -38,7 +38,10 @@ import Streamgraph, { import Pack from './tiles/Pack'; import Patterns from '../docs-v2/examples/vx-pattern/Example'; import Treemap from './tiles/Treemap'; -import Radar from './tiles/Radar'; +import Radar, { + bg as radarBackground, + pumpkin as radarColor, +} from '../docs-v2/examples/vx-radar/Example'; import Responsive from '../docs-v2/examples/vx-responsive/Example'; import DragI from '../docs-v2/examples/vx-drag-i/Example'; import DragII from '../docs-v2/examples/vx-drag-ii/Example'; @@ -672,7 +675,7 @@ export default function Gallery() {
@@ -683,7 +686,7 @@ export default function Gallery() {
Radar
diff --git a/packages/vx-demo/src/components/tiles/Radar.tsx b/packages/vx-demo/src/docs-v2/examples/vx-radar/Example.tsx similarity index 71% rename from packages/vx-demo/src/components/tiles/Radar.tsx rename to packages/vx-demo/src/docs-v2/examples/vx-radar/Example.tsx index fcf3e71d8..6d46d9fd0 100644 --- a/packages/vx-demo/src/components/tiles/Radar.tsx +++ b/packages/vx-demo/src/docs-v2/examples/vx-radar/Example.tsx @@ -4,12 +4,11 @@ import letterFrequency, { LetterFrequency } from '@vx/mock-data/lib/mocks/letter import { scaleLinear } from '@vx/scale'; import { Point } from '@vx/point'; import { Line, LineRadial } from '@vx/shape'; -import { ShowProvidedProps } from '../../types'; const orange = '#ff9933'; -const pumpkin = '#f5810c'; +export const pumpkin = '#f5810c'; const silver = '#d9d9d9'; -const bg = '#FAF7E9'; +export const bg = '#FAF7E9'; const degrees = 360; const data = letterFrequency.slice(2, 12); @@ -48,24 +47,21 @@ function genPolygonPoints( return { points, pointString }; } -export default ({ - width, - height, - levels = 5, - margin = { - top: 40, - left: 80, - right: 80, - bottom: 80, - }, -}: ShowProvidedProps & { levels?: number }) => { - if (width < 10) return null; +const defaultMargin = { top: 40, left: 80, right: 80, bottom: 80 }; +type Props = { + width: number; + height: number; + margin?: { top: number; right: number; bottom: number; left: number }; + levels?: number; +}; + +export default function Example({ width, height, levels = 5, margin = defaultMargin }: Props) { const xMax = width - margin.left - margin.right; const yMax = height - margin.top - margin.bottom; const radius = Math.min(xMax, yMax) / 2; - const radiusScale = scaleLinear({ + const radialScale = scaleLinear({ range: [0, Math.PI * 2], domain: [degrees, 0], }); @@ -80,29 +76,26 @@ export default ({ const polygonPoints = genPolygonPoints(data, yScale, y); const zeroPoint = new Point({ x: 0, y: 0 }); - return ( + return width < 10 ? null : ( - {[...new Array(levels)].map((_, i) => { - const r = ((i + 1) * radius) / levels; - return ( - radiusScale(d.angle)} - radius={r} - fill="none" - stroke={silver} - strokeWidth={2} - strokeOpacity={0.8} - strokeLinecap="round" - /> - ); - })} - {[...new Array(data.length)].map((_, i) => { - return ; - })} + {[...new Array(levels)].map((_, i) => ( + radialScale(d.angle)} + radius={((i + 1) * radius) / levels} + fill="none" + stroke={silver} + strokeWidth={2} + strokeOpacity={0.8} + strokeLinecap="round" + /> + ))} + {[...new Array(data.length)].map((_, i) => ( + + ))} ); -}; +} diff --git a/packages/vx-demo/src/docs-v2/examples/vx-radar/index.tsx b/packages/vx-demo/src/docs-v2/examples/vx-radar/index.tsx new file mode 100644 index 000000000..3313ec317 --- /dev/null +++ b/packages/vx-demo/src/docs-v2/examples/vx-radar/index.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import { render } from 'react-dom'; +import ParentSize from '@vx/responsive/lib/components/ParentSize'; + +import Example from './Example'; +import './sandbox-styles.css'; + +render( + {({ width, height }) => }, + document.getElementById('root'), +); diff --git a/packages/vx-demo/src/docs-v2/examples/vx-radar/package.json b/packages/vx-demo/src/docs-v2/examples/vx-radar/package.json new file mode 100644 index 000000000..d1b28d4d2 --- /dev/null +++ b/packages/vx-demo/src/docs-v2/examples/vx-radar/package.json @@ -0,0 +1,27 @@ +{ + "name": "@vx/demo-radar", + "description": "Standalone vx radar chart demo.", + "main": "index.tsx", + "dependencies": { + "@babel/runtime": "^7.8.4", + "@types/react": "^16", + "@types/react-dom": "^16", + "@vx/group": "latest", + "@vx/mock-data": "latest", + "@vx/responsive": "latest", + "@vx/point": "latest", + "@vx/scale": "latest", + "@vx/shape": "latest", + "react": "^16", + "react-dom": "^16", + "react-scripts-ts": "3.1.0", + "typescript": "^3" + }, + "keywords": [ + "visualization", + "d3", + "react", + "vx", + "radar" + ] +} diff --git a/packages/vx-demo/src/docs-v2/examples/vx-radar/sandbox-styles.css b/packages/vx-demo/src/docs-v2/examples/vx-radar/sandbox-styles.css new file mode 100644 index 000000000..b91993723 --- /dev/null +++ b/packages/vx-demo/src/docs-v2/examples/vx-radar/sandbox-styles.css @@ -0,0 +1,8 @@ +html, +body, +#root { + height: 100%; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, + 'Open Sans', 'Helvetica Neue', sans-serif; + line-height: 2em; +} diff --git a/packages/vx-demo/src/pages/Radar.tsx b/packages/vx-demo/src/pages/Radar.tsx index 34d5c5d2f..127c947d7 100644 --- a/packages/vx-demo/src/pages/Radar.tsx +++ b/packages/vx-demo/src/pages/Radar.tsx @@ -1,11 +1,16 @@ import React from 'react'; import Show from '../components/Show'; -import Radar from '../components/tiles/Radar'; -import RadarSource from '!!raw-loader!../components/tiles/Radar'; +import Radar from '../docs-v2/examples/vx-radar/Example'; +import RadarSource from '!!raw-loader!../docs-v2/examples/vx-radar/Example'; export default () => { return ( - + {RadarSource} );