Skip to content

Commit

Permalink
[gradient] add rotate, transform, children, opacity support
Browse files Browse the repository at this point in the history
  • Loading branch information
hshoff committed Jun 30, 2017
1 parent f15508a commit dc542da
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 18 deletions.
12 changes: 4 additions & 8 deletions packages/vx-demo/components/tiles/bars.js
Expand Up @@ -17,11 +17,7 @@ function round(value, precision) {
const x = d => d.letter;
const y = d => +d.frequency * 100;

export default ({
width,
height,
events = false,
}) => {
export default ({ width, height, events = false }) => {
if (width < 10) return null;

// bounds
Expand Down Expand Up @@ -62,9 +58,9 @@ export default ({
y={yMax - barHeight}
fill="rgba(23, 233, 217, .5)"
data={{ x: x(d), y: y(d) }}
onClick={(data) => (event) => {
onClick={data => event => {
if (!events) return;
alert(`clicked: ${JSON.stringify(data)}`)
alert(`clicked: ${JSON.stringify(data)}`);
}}
/>
</Group>
Expand All @@ -73,4 +69,4 @@ export default ({
</Group>
</svg>
);
}
};
5 changes: 3 additions & 2 deletions packages/vx-gradient/package.json
Expand Up @@ -29,7 +29,8 @@
},
"homepage": "https://github.com/hshoff/vx#readme",
"dependencies": {
"classnames": "^2.2.5"
"classnames": "^2.2.5",
"prop-types": "^15.5.7"
},
"devDependencies": {
"babel-jest": "^20.0.3",
Expand All @@ -47,4 +48,4 @@
"publishConfig": {
"access": "public"
}
}
}
65 changes: 58 additions & 7 deletions packages/vx-gradient/src/gradients/LinearGradient.js
@@ -1,18 +1,69 @@
import React from 'react';
import PropTypes from 'prop-types';

export default ({
LinearGradient.propTypes = {
id: PropTypes.string.isRequired,
from: PropTypes.string,
to: PropTypes.string,
x1: PropTypes.string,
y1: PropTypes.string,
y2: 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 LinearGradient({
children,
id,
from,
to,
fromOffset = "0%",
toOffset = "100%",
x1,
y1,
x2,
y2,
fromOffset = '0%',
fromOpacity = 1,
toOffset = '100%',
toOpacity = 1,
rotate,
transform,
vertical = true,
...restProps
}) => {
}) {
if (vertical && !x1 && !x2 && !y1 && !y2) {
x1 = '0';
x2 = '0';
y1 = '0';
y2 = '1';
}
return (
<defs>
<linearGradient id={id} x1="0%" y1="0%" x2="0%" y2="100%" {...restProps}>
<stop offset={fromOffset} stopColor={from} />
<stop offset={toOffset} stopColor={to} />
<linearGradient
id={id}
x1={x1}
y1={y1}
x2={x2}
y2={y2}
gradientTransform={rotate ? `rotate(${rotate})` : transform}
{...restProps}
>
{!!children && children}
{!children &&
<stop
offset={fromOffset}
stopColor={from}
stopOpacity={fromOpacity}
/>}
{!children &&
<stop
offset={toOffset}
stopColor={to}
stopOpacity={toOpacity}
/>}
</linearGradient>
</defs>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/vx-legend/src/legends/Legend.js
Expand Up @@ -25,7 +25,7 @@ Legend.propTypes = {
direction: PropTypes.string,
itemDirection: PropTypes.string,
fill: PropTypes.func,
shape: PropTypes.func,
shape: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
labelFormat: PropTypes.func,
labelTransform: PropTypes.func,
};
Expand Down

0 comments on commit dc542da

Please sign in to comment.