Slight tweak to dragging behavior

pull/2829/head
Luke Morris 2018-02-20 15:36:22 -08:00
parent abbd713202
commit b37c87331b
1 changed files with 24 additions and 19 deletions

View File

@ -7,21 +7,8 @@ import AnnotationTooltip from 'shared/components/AnnotationTooltip'
class AnnotationPoint extends React.Component { class AnnotationPoint extends React.Component {
state = { state = {
isDragging: false,
isMouseOver: false, isMouseOver: false,
} isDragging: false,
handleStartDrag = () => {
const {mode} = this.props
if (mode !== EDITING) {
return
}
this.setState({isDragging: true})
}
handleStopDrag = () => {
this.setState({isDragging: false})
} }
handleMouseEnter = () => { handleMouseEnter = () => {
@ -37,13 +24,26 @@ class AnnotationPoint extends React.Component {
this.setState({isDragging: false, isMouseOver: false}) this.setState({isDragging: false, isMouseOver: false})
} }
handleDragStart = () => {
this.setState({isDragging: true})
}
handleDragStop = () => {
this.setState({isDragging: false})
}
handleDrag = e => { handleDrag = e => {
if (!this.state.isDragging) { if (this.props.mode !== EDITING) {
return return
} }
const {pageX} = e const {pageX} = e
const {annotation, dygraph, onUpdateAnnotation} = this.props const {annotation, dygraph, onUpdateAnnotation} = this.props
if (pageX === 0) {
return
}
const {startTime} = annotation const {startTime} = annotation
const {left} = dygraph.graphDiv.getBoundingClientRect() const {left} = dygraph.graphDiv.getBoundingClientRect()
const [startX, endX] = dygraph.xAxisRange() const [startX, endX] = dygraph.xAxisRange()
@ -72,7 +72,11 @@ class AnnotationPoint extends React.Component {
newTime = startX newTime = startX
} }
onUpdateAnnotation({...annotation, startTime: `${newTime}`}) onUpdateAnnotation({
...annotation,
startTime: `${newTime}`,
endTime: `${newTime}`,
})
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
@ -99,9 +103,10 @@ class AnnotationPoint extends React.Component {
> >
<div <div
style={style.clickArea(isDragging, isEditing)} style={style.clickArea(isDragging, isEditing)}
onMouseMove={this.handleDrag} draggable={true}
onMouseDown={this.handleStartDrag} onDrag={this.handleDrag}
onMouseUp={this.handleStopDrag} onDragStart={this.handleDragStart}
onDragEnd={this.handleDragStop}
onMouseEnter={this.handleMouseEnter} onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave} onMouseLeave={this.handleMouseLeave}
/> />