2017-06-04 10:40:14 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-07-27 20:35:55 +08:00
|
|
|
import AnnotationHelpers from '../helpers.js';
|
2016-05-31 06:07:02 +08:00
|
|
|
|
|
|
|
export default class EllipseDrawComponent extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
2017-05-10 04:34:46 +08:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2017-08-17 10:24:59 +08:00
|
|
|
return this.props.version != nextProps.version;
|
2017-05-10 04:34:46 +08:00
|
|
|
}
|
|
|
|
|
2016-06-05 07:09:50 +08:00
|
|
|
getCoordinates() {
|
2017-06-03 03:25:02 +08:00
|
|
|
// x1 and y1 - coordinates of the ellipse's top left corner
|
|
|
|
// x2 and y2 - coordinates of the ellipse's bottom right corner
|
2017-07-27 20:35:55 +08:00
|
|
|
const x1 = this.props.annotation.points[0];
|
|
|
|
const y1 = this.props.annotation.points[1];
|
|
|
|
const x2 = this.props.annotation.points[2];
|
|
|
|
const y2 = this.props.annotation.points[3];
|
2016-06-05 07:09:50 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
// rx - horizontal radius
|
|
|
|
// ry - vertical radius
|
|
|
|
// cx and cy - coordinates of the ellipse's center
|
2016-06-25 05:30:37 +08:00
|
|
|
let rx = (x2 - x1) / 2;
|
|
|
|
let ry = (y2 - y1) / 2;
|
2017-06-03 03:25:02 +08:00
|
|
|
const cx = (rx + x1) * this.props.slideWidth / 100;
|
|
|
|
const cy = (ry + y1) * this.props.slideHeight / 100;
|
2016-06-05 07:09:50 +08:00
|
|
|
rx = Math.abs(rx / 100 * this.props.slideWidth);
|
|
|
|
ry = Math.abs(ry / 100 * this.props.slideHeight);
|
|
|
|
|
|
|
|
return {
|
2017-06-03 03:25:02 +08:00
|
|
|
cx,
|
|
|
|
cy,
|
|
|
|
rx,
|
|
|
|
ry,
|
2016-05-31 06:07:02 +08:00
|
|
|
};
|
2016-06-05 07:09:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-06-03 03:25:02 +08:00
|
|
|
const 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"
|
2017-07-27 20:35:55 +08:00
|
|
|
stroke={AnnotationHelpers.formatColor(this.props.annotation.color)}
|
2017-08-17 10:24:59 +08:00
|
|
|
strokeWidth={AnnotationHelpers.getStrokeWidth(this.props.annotation.thickness, this.props.slideWidth)}
|
2016-06-05 07:09:50 +08:00
|
|
|
style={this.props.style}
|
2017-06-03 03:25:02 +08:00
|
|
|
/>
|
2016-05-31 06:07:02 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-06-05 07:09:50 +08:00
|
|
|
|
|
|
|
EllipseDrawComponent.defaultProps = {
|
|
|
|
style: {
|
|
|
|
WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)',
|
|
|
|
},
|
|
|
|
};
|