diff --git a/packages/vx-demo/src/components/Gallery.tsx b/packages/vx-demo/src/components/Gallery.tsx index 195631bb4..8dd98e101 100644 --- a/packages/vx-demo/src/components/Gallery.tsx +++ b/packages/vx-demo/src/components/Gallery.tsx @@ -27,7 +27,7 @@ import BarStackHorizontal, { background as horizontalBarstackBackground, purple3 as horiztonalBarstackTextColor, } from '../docs-v2/examples/vx-barstack-horizontal/Example'; -import Heatmap from './tiles/Heatmap'; +import Heatmaps from '../docs-v2/examples/vx-heatmap/Example'; import LineRadial from '../docs-v2/examples/vx-shape-line-radial/Example'; import Pies from '../docs-v2/examples/vx-shape-pie/Example'; import Trees from './tiles/Trees'; @@ -346,7 +346,9 @@ export default function Gallery() {
- {({ width, height }) => } + {({ width, height }) => ( + + )}
diff --git a/packages/vx-demo/src/components/tiles/Heatmap.tsx b/packages/vx-demo/src/docs-v2/examples/vx-heatmap/Example.tsx similarity index 90% rename from packages/vx-demo/src/components/tiles/Heatmap.tsx rename to packages/vx-demo/src/docs-v2/examples/vx-heatmap/Example.tsx index 51bd390d0..4d80b6180 100644 --- a/packages/vx-demo/src/components/tiles/Heatmap.tsx +++ b/packages/vx-demo/src/docs-v2/examples/vx-heatmap/Example.tsx @@ -3,7 +3,6 @@ import { Group } from '@vx/group'; import genBins, { Bin, Bins } from '@vx/mock-data/lib/generators/genBins'; import { scaleLinear } from '@vx/scale'; import { HeatmapCircle, HeatmapRect } from '@vx/heatmap'; -import { ShowProvidedProps } from '../../types'; const hot1 = '#77312f'; const hot2 = '#f33d15'; @@ -48,26 +47,26 @@ const opacityScale = scaleLinear({ domain: [0, colorMax], }); +type Props = { + width: number; + height: number; + margin?: { top: number; right: number; bottom: number; left: number }; + separation?: number; + events?: boolean; +}; + +const defaultMargin = { top: 10, left: 20, right: 20, bottom: 110 }; + export default ({ width, height, events = false, - margin = { - top: 10, - left: 20, - right: 20, - bottom: 110, - }, + margin = defaultMargin, separation = 20, -}: ShowProvidedProps & { separation?: number }) => { - if (width < 10) return null; - +}: Props) => { // bounds - let size = width; - if (size > margin.left + margin.right) { - size = width - margin.left - margin.right - separation; - } - + const size = + width > margin.left + margin.right ? width - margin.left - margin.right - separation : width; const xMax = size / 2; const yMax = height - margin.bottom - margin.top; @@ -78,7 +77,7 @@ export default ({ xScale.range([0, xMax]); yScale.range([yMax, 0]); - return ( + return width < 10 ? null : ( diff --git a/packages/vx-demo/src/docs-v2/examples/vx-heatmap/index.tsx b/packages/vx-demo/src/docs-v2/examples/vx-heatmap/index.tsx new file mode 100644 index 000000000..3313ec317 --- /dev/null +++ b/packages/vx-demo/src/docs-v2/examples/vx-heatmap/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-heatmap/package.json b/packages/vx-demo/src/docs-v2/examples/vx-heatmap/package.json new file mode 100644 index 000000000..58bef6462 --- /dev/null +++ b/packages/vx-demo/src/docs-v2/examples/vx-heatmap/package.json @@ -0,0 +1,27 @@ +{ + "name": "@vx/demo-heatmap", + "description": "Standalone vx heatmap demo.", + "main": "index.tsx", + "dependencies": { + "@babel/runtime": "^7.8.4", + "@types/react": "^16", + "@types/react-dom": "^16", + "@vx/group": "latest", + "@vx/heatmap": "latest", + "@vx/mock-data": "latest", + "@vx/responsive": "latest", + "@vx/scale": "latest", + + "react": "^16", + "react-dom": "^16", + "react-scripts-ts": "3.1.0", + "typescript": "^3" + }, + "keywords": [ + "visualization", + "d3", + "react", + "vx", + "heatmap" + ] +} diff --git a/packages/vx-demo/src/docs-v2/examples/vx-heatmap/sandbox-styles.css b/packages/vx-demo/src/docs-v2/examples/vx-heatmap/sandbox-styles.css new file mode 100644 index 000000000..b91993723 --- /dev/null +++ b/packages/vx-demo/src/docs-v2/examples/vx-heatmap/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/Heatmaps.tsx b/packages/vx-demo/src/pages/Heatmaps.tsx index 38194c842..69ea8b013 100644 --- a/packages/vx-demo/src/pages/Heatmaps.tsx +++ b/packages/vx-demo/src/pages/Heatmaps.tsx @@ -1,7 +1,7 @@ import React from 'react'; import Show from '../components/Show'; -import Heatmap from '../components/tiles/Heatmap'; -import HeatmapSource from '!!raw-loader!../components/tiles/Heatmap'; +import Heatmaps from '../docs-v2/examples/vx-heatmap/Example'; +import HeatmapsSource from '!!raw-loader!../docs-v2/examples/vx-heatmap/Example'; export default () => { return ( @@ -13,10 +13,11 @@ export default () => { right: 30, bottom: 80, }} - component={Heatmap} + component={Heatmaps} title="Heatmaps" + codeSandboxDirectoryName="vx-heatmap" > - {HeatmapSource} + {HeatmapsSource} ); };