Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit 00ea2d6

Browse files
committed
Merge pull request #30 from sebmarkbage/update
Add some higher order shapes and bump versions
2 parents 584eac9 + b9e60d8 commit 00ea2d6

File tree

8 files changed

+394
-3
lines changed

8 files changed

+394
-3
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-art",
33
"description": "React ART is a JavaScript library for drawing vector graphics using React. It provides declarative and reactive bindings to the ART library. Using the same declarative API you can render the output to either Canvas, SVG or VML (IE8).",
4-
"version": "0.12.0-alpha",
4+
"version": "0.12.0",
55
"keywords": [
66
"react",
77
"art",
@@ -21,11 +21,12 @@
2121
"art": "~0.9.0"
2222
},
2323
"peerDependencies": {
24-
"react": "^0.11.1"
24+
"react": "^0.12.0"
2525
},
2626
"devDependencies": {
2727
"jest": "~0.1.37",
28-
"react-tools": "^0.10.0"
28+
"react": "^0.12.0",
29+
"react-tools": "^0.12.0"
2930
},
3031
"engines": {
3132
"node": ">=0.10.0"

shapes/circle.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright 2013-2014 Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
module.exports = require('../src/Circle.art');

shapes/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright 2013-2014 Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
var Circle = require('../src/Circle.art');
11+
var Rectangle = require('../src/Rectangle.art');
12+
var Wedge = require('../src/Wedge.art');
13+
14+
module.exports = {
15+
Circle: Circle,
16+
Rectangle: Rectangle,
17+
Wedge: Wedge
18+
};

shapes/rectangle.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright 2013-2014 Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
module.exports = require('../src/Rectangle.art');

shapes/wedge.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright 2013-2014 Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
module.exports = require('../src/Wedge.art');

src/Circle.art.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright 2013-2014 Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule Circle.art
10+
* @typechecks
11+
*
12+
* Example usage:
13+
* <Circle
14+
* radius={10}
15+
* stroke="green"
16+
* strokeWidth={3}
17+
* fill="blue"
18+
* />
19+
*
20+
*/
21+
22+
var React = require('React');
23+
var ReactART = require('ReactART');
24+
25+
var Props = React.PropTypes;
26+
var Shape = ReactART.Shape;
27+
var Path = ReactART.Path;
28+
29+
/**
30+
* Circle is a React component for drawing circles. Like other ReactART
31+
* components, it must be used in a <Surface>.
32+
*/
33+
var Circle = React.createClass({
34+
35+
propTypes: {
36+
radius: Props.number.isRequired
37+
},
38+
39+
render: function() {
40+
var radius = this.props.radius;
41+
42+
var path = Path().moveTo(0, -radius)
43+
.arc(0, radius * 2, radius)
44+
.arc(0, radius * -2, radius)
45+
.close();
46+
return <Shape {...this.props} d={path} />;
47+
}
48+
49+
});
50+
51+
module.exports = Circle;

src/Rectangle.art.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* Copyright 2013-2014 Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @providesModule Rectangle.art
10+
* @typechecks
11+
*
12+
* Example usage:
13+
* <Rectangle
14+
* width={50}
15+
* height={50}
16+
* stroke="green"
17+
* fill="blue"
18+
* />
19+
*
20+
* Additional optional properties:
21+
* (Number) radius
22+
* (Number) radiusTopLeft
23+
* (Number) radiusTopRight
24+
* (Number) radiusBottomLeft
25+
* (Number) radiusBottomRight
26+
*
27+
*/
28+
29+
var React = require('React');
30+
var ReactART = require('ReactART');
31+
32+
var Props = React.PropTypes;
33+
var Shape = ReactART.Shape;
34+
var Path = ReactART.Path;
35+
36+
/**
37+
* Rectangle is a React component for drawing rectangles. Like other ReactART
38+
* components, it must be used in a <Surface>.
39+
*/
40+
var Rectangle = React.createClass({
41+
42+
propTypes: {
43+
width: Props.number.isRequired,
44+
height: Props.number.isRequired,
45+
radius: Props.number,
46+
radiusTopLeft: Props.number,
47+
radiusTopRight: Props.number,
48+
radiusBottomRight: Props.number,
49+
radiusBottomLeft: Props.number
50+
},
51+
52+
render: function() {
53+
var width = this.props.width;
54+
var height = this.props.height;
55+
var radius = this.props.radius ? this.props.radius : 0;
56+
57+
// if unspecified, radius(Top|Bottom)(Left|Right) defaults to the radius
58+
// property
59+
var tl = this.props.radiusTopLeft ? this.props.radiusTopLeft : radius;
60+
var tr = this.props.radiusTopRight ? this.props.radiusTopRight : radius;
61+
var br = this.props.radiusBottomRight ?
62+
this.props.radiusBottomRight : radius;
63+
var bl = this.props.radiusBottomLeft ? this.props.radiusBottomLeft : radius;
64+
65+
var path = Path();
66+
67+
// for negative width/height, offset the rectangle in the negative x/y
68+
// direction. for negative radius, just default to 0.
69+
if (width < 0) {
70+
path.move(width, 0);
71+
width = -width;
72+
}
73+
if (height < 0) {
74+
path.move(0, height);
75+
height = -height;
76+
}
77+
if (tl < 0) { tl = 0; }
78+
if (tr < 0) { tr = 0; }
79+
if (br < 0) { br = 0; }
80+
if (bl < 0) { bl = 0; }
81+
82+
// disable border radius if it doesn't fit within the specified
83+
// width/height
84+
if (tl + tr > width) { tl = 0; tr = 0; }
85+
if (bl + br > width) { bl = 0; br = 0; }
86+
if (tl + bl > height) { tl = 0; bl = 0; }
87+
if (tr + br > height) { tr = 0; br = 0; }
88+
89+
path.move(0, tl);
90+
91+
if (tl > 0) { path.arc(tl, -tl); }
92+
path.line(width - (tr + tl), 0);
93+
94+
if (tr > 0) { path.arc(tr, tr); }
95+
path.line(0, height - (tr + br));
96+
97+
if (br > 0) { path.arc(-br, br); }
98+
path.line(- width + (br + bl), 0);
99+
100+
if (bl > 0) { path.arc(-bl, -bl); }
101+
path.line(0, - height + (bl + tl));
102+
103+
return <Shape {...this.props} d={path} />;
104+
}
105+
106+
});
107+
108+
module.exports = Rectangle;

0 commit comments

Comments
 (0)