2016-05-31 06:07:02 +08:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-06-09 01:13:25 +08:00
|
|
|
import ShapeHelpers from '../helpers.js';
|
2016-05-31 06:07:02 +08:00
|
|
|
|
|
|
|
export default class TriangleDrawComponent extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
2016-06-09 01:13:25 +08:00
|
|
|
getCoordinates() {
|
|
|
|
let xTop;
|
|
|
|
let yTop;
|
|
|
|
let xBottomLeft;
|
|
|
|
let yBottomLeft;
|
|
|
|
let xBottomRight;
|
|
|
|
let yBottomRight;
|
|
|
|
let path = '';
|
|
|
|
|
|
|
|
//points[0] and points[1] are x and y coordinates of the top left corner of the shape obj
|
|
|
|
//points[2] and points[3] are x and y coordinates of the bottom right corner of the shape obj
|
|
|
|
xBottomLeft = this.props.shape.points[0];
|
|
|
|
yBottomLeft = this.props.shape.points[3];
|
|
|
|
xBottomRight = this.props.shape.points[2];
|
|
|
|
yBottomRight = this.props.shape.points[3];
|
|
|
|
xTop = ((xBottomRight - xBottomLeft) / 2) + xBottomLeft;
|
|
|
|
yTop = this.props.shape.points[1];
|
|
|
|
|
|
|
|
path = path + 'M' + (xTop / 100 * this.props.slideWidth) +
|
|
|
|
',' + (yTop / 100 * this.props.slideHeight) +
|
|
|
|
',' + (xBottomLeft / 100 * this.props.slideWidth) +
|
|
|
|
',' + (yBottomLeft / 100 * this.props.slideHeight) +
|
|
|
|
',' + (xBottomRight / 100 * this.props.slideWidth) +
|
|
|
|
',' + (yBottomRight / 100 * this.props.slideHeight) +
|
|
|
|
'Z';
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2016-05-31 06:07:02 +08:00
|
|
|
render() {
|
2016-06-09 01:13:25 +08:00
|
|
|
let path = this.getCoordinates();
|
2016-05-31 06:07:02 +08:00
|
|
|
return (
|
|
|
|
<path
|
2016-06-09 01:13:25 +08:00
|
|
|
style={this.props.style}
|
|
|
|
fill="none"
|
|
|
|
stroke={ShapeHelpers.formatColor(this.props.shape.color)}
|
|
|
|
d={path}
|
|
|
|
strokeWidth={this.props.shape.thickness}
|
|
|
|
strokeLinejoin="round"
|
2016-05-31 06:07:02 +08:00
|
|
|
>
|
|
|
|
</path>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-06-09 01:13:25 +08:00
|
|
|
|
|
|
|
TriangleDrawComponent.defaultProps = {
|
|
|
|
style: {
|
|
|
|
WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)',
|
|
|
|
},
|
|
|
|
};
|