From 74fe1c1a237c2e0236ab368bcb68ae9ae321babc Mon Sep 17 00:00:00 2001 From: Harry Shoff Date: Wed, 5 Jul 2017 20:09:37 -0700 Subject: [PATCH 1/2] [gradient] add . fixes #83 --- .../vx-demo/components/tiles/gradients.js | 5 +- .../vx-demo/components/tiles/lineradial.js | 20 ++++--- packages/vx-demo/pages/gradients.js | 52 +++++++++++-------- .../src/gradients/RadialGradient.js | 52 +++++++++++++++++++ packages/vx-gradient/src/index.js | 1 + 5 files changed, 99 insertions(+), 31 deletions(-) create mode 100644 packages/vx-gradient/src/gradients/RadialGradient.js diff --git a/packages/vx-demo/components/tiles/gradients.js b/packages/vx-demo/components/tiles/gradients.js index 261fc72cf..8196dae7e 100644 --- a/packages/vx-demo/components/tiles/gradients.js +++ b/packages/vx-demo/components/tiles/gradients.js @@ -11,6 +11,7 @@ import { GradientPurpleTeal, GradientSteelPurple, GradientTealBlue, + RadialGradient, } from '@vx/gradient'; export default ({ @@ -34,7 +35,7 @@ export default ({ - + new Date(d.date); const y = d => d.close; -const capPoints = [appleStock[0]].concat([appleStock[appleStock.length - 1]]); +const capPoints = [appleStock[0]].concat([ + appleStock[appleStock.length - 1], +]); export default function LineRadialTile({ width, @@ -20,7 +22,7 @@ export default function LineRadialTile({ left: 10, right: 10, bottom: 120, - } + }, }) { if (width < 10) return null; @@ -36,7 +38,11 @@ export default function LineRadialTile({ }); return ( - + - + {yScale.ticks().map((tick, i) => { return ( @@ -54,7 +60,7 @@ export default function LineRadialTile({ stroke="#aeeef8" strokeWidth={1} fill="#aeeef8" - fillOpacity={(1 / (i + 1)) - ((1 / i) * .2)} + fillOpacity={1 / (i + 1) - 1 / i * 0.2} strokeOpacity={0.2} /> @@ -95,4 +101,4 @@ export default function LineRadialTile({ ); -} \ No newline at end of file +} diff --git a/packages/vx-demo/pages/gradients.js b/packages/vx-demo/pages/gradients.js index 028280f65..a3122e8df 100644 --- a/packages/vx-demo/pages/gradients.js +++ b/packages/vx-demo/pages/gradients.js @@ -24,34 +24,41 @@ import { GradientPurpleRed, GradientPurpleTeal, GradientSteelPurple, - GradientTealBlue + GradientTealBlue, + RadialGradient, } from '@vx/gradient'; export default ({ width, height, + margin = { + top: 0, + left: 0, + right: 0, + bottom: 80, + }, }) => { const w = width / 4; - const h = (height - 80) / 2; + const h = (height - margin.bottom) / 2; return ( - - - - - - - - - - + + + + + + + + + + @@ -62,7 +69,7 @@ export default ({ height={h} fill={\`url(#OrangeRed)\`} rx={14} - stroke='#ffffff' + stroke="#ffffff" strokeWidth={8} /> ); -}`} +}; +`} ); }; diff --git a/packages/vx-gradient/src/gradients/RadialGradient.js b/packages/vx-gradient/src/gradients/RadialGradient.js new file mode 100644 index 000000000..80df00553 --- /dev/null +++ b/packages/vx-gradient/src/gradients/RadialGradient.js @@ -0,0 +1,52 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +RadialGradient.propTypes = { + id: PropTypes.string.isRequired, + from: PropTypes.string, + to: PropTypes.string, + fromOffset: PropTypes.string, + fromOpacity: PropTypes.number, + toOffset: PropTypes.string, + toOpacity: PropTypes.number, + rotate: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + transform: PropTypes.string, +}; + +export default function RadialGradient({ + children, + id, + from, + to, + fromOffset = '0%', + fromOpacity = 1, + toOffset = '100%', + toOpacity = 1, + rotate, + transform, + ...restProps +}) { + return ( + + + {!!children && children} + {!children && + } + {!children && + } + + + ); +} diff --git a/packages/vx-gradient/src/index.js b/packages/vx-gradient/src/index.js index 9847a95dd..136504a70 100644 --- a/packages/vx-gradient/src/index.js +++ b/packages/vx-gradient/src/index.js @@ -1,4 +1,5 @@ export { default as LinearGradient } from './gradients/LinearGradient'; +export { default as RadialGradient } from './gradients/RadialGradient'; export { default as GradientDarkgreenGreen } from './gradients/DarkgreenGreen'; export { default as GradientLightgreenGreen } from './gradients/LightgreenGreen'; export { default as GradientOrangeRed } from './gradients/OrangeRed'; From 79aab76dc05b7f1c08e8640999a6eaf078ed98c7 Mon Sep 17 00:00:00 2001 From: Harry Shoff Date: Wed, 5 Jul 2017 20:18:05 -0700 Subject: [PATCH 2/2] [gradient] add initial tests --- packages/vx-gradient/test/LinearGradient.test.js | 7 +++++++ packages/vx-gradient/test/RadialGradient.test.js | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100644 packages/vx-gradient/test/LinearGradient.test.js create mode 100644 packages/vx-gradient/test/RadialGradient.test.js diff --git a/packages/vx-gradient/test/LinearGradient.test.js b/packages/vx-gradient/test/LinearGradient.test.js new file mode 100644 index 000000000..5fde78503 --- /dev/null +++ b/packages/vx-gradient/test/LinearGradient.test.js @@ -0,0 +1,7 @@ +import { LinearGradient } from '../src'; + +describe('', () => { + it('should be defined', () => { + expect(LinearGradient).toBeDefined(); + }); +}); diff --git a/packages/vx-gradient/test/RadialGradient.test.js b/packages/vx-gradient/test/RadialGradient.test.js new file mode 100644 index 000000000..2c2662985 --- /dev/null +++ b/packages/vx-gradient/test/RadialGradient.test.js @@ -0,0 +1,7 @@ +import { RadialGradient } from '../src'; + +describe('', () => { + it('should be defined', () => { + expect(RadialGradient).toBeDefined(); + }); +});