2016-05-31 06:07:02 +08:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-06-05 07:09:50 +08:00
|
|
|
import ShapeHelpers from '../helpers.js';
|
2016-05-31 06:07:02 +08:00
|
|
|
|
|
|
|
export default class EllipseDrawComponent extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
2016-06-05 07:09:50 +08:00
|
|
|
getCoordinates() {
|
|
|
|
//rx - horizontal radius
|
|
|
|
//ry - vertical radius
|
|
|
|
//cx and cy - coordinates of the ellipse's center
|
|
|
|
let rx;
|
|
|
|
let ry;
|
|
|
|
let cx;
|
|
|
|
let cy;
|
|
|
|
|
|
|
|
//x1 and y1 - coordinates of the ellipse's top left corner
|
|
|
|
//x2 and y2 - coordinates of the ellipse's bottom right corner
|
|
|
|
const x1 = this.props.shape.points[0];
|
|
|
|
const y1 = this.props.shape.points[1];
|
|
|
|
const x2 = this.props.shape.points[2];
|
|
|
|
const y2 = this.props.shape.points[3];
|
|
|
|
|
|
|
|
rx = (x2 - x1) / 2;
|
|
|
|
ry = (y2 - y1) / 2;
|
|
|
|
cx = (rx + x1) * this.props.slideWidth / 100;
|
|
|
|
cy = (ry + y1) * this.props.slideHeight / 100;
|
|
|
|
rx = Math.abs(rx / 100 * this.props.slideWidth);
|
|
|
|
ry = Math.abs(ry / 100 * this.props.slideHeight);
|
|
|
|
|
|
|
|
return {
|
|
|
|
cx: cx,
|
|
|
|
cy: cy,
|
|
|
|
rx: rx,
|
|
|
|
ry: ry,
|
2016-05-31 06:07:02 +08:00
|
|
|
};
|
2016-06-05 07:09:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let results = this.getCoordinates();
|
2016-05-31 06:07:02 +08:00
|
|
|
return (
|
|
|
|
<ellipse
|
2016-06-05 07:09:50 +08:00
|
|
|
cx={results.cx}
|
|
|
|
cy={results.cy}
|
|
|
|
rx={results.rx}
|
|
|
|
ry={results.ry}
|
|
|
|
fill="none"
|
|
|
|
stroke={ShapeHelpers.formatColor(this.props.shape.color)}
|
|
|
|
strokeWidth={
|
|
|
|
ShapeHelpers.getStrokeWidth(
|
|
|
|
this.props.shape.thickness,
|
|
|
|
this.props.widthRatio,
|
|
|
|
this.props.heightRatio
|
|
|
|
)
|
|
|
|
}
|
|
|
|
style={this.props.style}
|
2016-05-31 06:07:02 +08:00
|
|
|
>
|
|
|
|
</ellipse>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-06-05 07:09:50 +08:00
|
|
|
|
|
|
|
EllipseDrawComponent.defaultProps = {
|
|
|
|
style: {
|
|
|
|
WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)',
|
|
|
|
},
|
|
|
|
};
|