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 TriangleDrawComponent 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-09 01:13:25 +08:00
|
|
|
getCoordinates() {
|
|
|
|
let path = '';
|
|
|
|
|
2017-07-27 20:35:55 +08:00
|
|
|
// points[0] and points[1] are x and y coordinates of the top left corner of the annotation obj
|
|
|
|
// points[2] and points[3] are x and y coordinates of the bottom right corner of the annotation obj
|
|
|
|
const xBottomLeft = this.props.annotation.points[0];
|
|
|
|
const yBottomLeft = this.props.annotation.points[3];
|
|
|
|
const xBottomRight = this.props.annotation.points[2];
|
|
|
|
const yBottomRight = this.props.annotation.points[3];
|
2017-06-03 03:25:02 +08:00
|
|
|
const xTop = ((xBottomRight - xBottomLeft) / 2) + xBottomLeft;
|
2017-07-27 20:35:55 +08:00
|
|
|
const yTop = this.props.annotation.points[1];
|
2016-06-09 01:13:25 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
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`;
|
2016-06-09 01:13:25 +08:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2016-05-31 06:07:02 +08:00
|
|
|
render() {
|
2017-06-03 03:25:02 +08:00
|
|
|
const 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"
|
2017-07-27 20:35:55 +08:00
|
|
|
stroke={AnnotationHelpers.formatColor(this.props.annotation.color)}
|
2016-06-09 01:13:25 +08:00
|
|
|
d={path}
|
2017-08-17 10:24:59 +08:00
|
|
|
strokeWidth={AnnotationHelpers.getStrokeWidth(this.props.annotation.thickness, this.props.slideWidth)}
|
2016-06-09 01:13:25 +08:00
|
|
|
strokeLinejoin="round"
|
2017-06-03 03:25:02 +08:00
|
|
|
/>
|
2016-05-31 06:07:02 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-06-09 01:13:25 +08:00
|
|
|
|
|
|
|
TriangleDrawComponent.defaultProps = {
|
|
|
|
style: {
|
|
|
|
WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)',
|
|
|
|
},
|
|
|
|
};
|